Question

How to Write a function, called multGauss, to compute the sum of multiple Gaussian (normal) profiles...

How to Write a function, called multGauss, to compute the sum of multiple Gaussian (normal) profiles in Matlab.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The Gaussian model equation  to compute sum of multiple Gaussian profiles in Matlab is given below.

     

Where

a is the amplitude,

b is the centroid (location),

c is related to the peak width,

n is the number of peaks to fit,

and 1 ≤ n ≤ 8

Now to Write a function, called multGauss in Matlab is as below.

a> function S=sumInt(n) Defining function multGauss as "S"

S=0

for i=1:n

S=S+i

end

end

b> function s = halfsum(A)

[row col] = size(A);

if row ~= col

error('Expecting a square matrix here people...');

end

s = 0;

for ii = 1:row

for jj = ii:col

s = s + A(ii,jj);

end

end

c>  

% Ask user for one integer number.

defaultValue = 45;

titleBar = 'Enter an integer value';

userPrompt = 'Enter the integer';

caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});

if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.

% Round to nearest integer in case they entered a floating point number.

integerValue = round(str2double(cell2mat(caUserInput)));

% Check for a valid integer.

if isnan(integerValue)

% They didn't enter a number.

% They clicked Cancel, or entered a character, symbols, or something else not allowed.

integerValue = defaultValue;

message = sprintf('I said it had to be an integer.\nTry replacing the user.\nI will use %d and continue.', integerValue);

uiwait(warndlg(message));

end

d>

n=500;

H1 = normrnd(14,5,n,1); % generate random numbers of normal distribution at mu and sigma

H2 = 24+ normrnd(14,5,n,1); % start from 24

H3 = 48+ normrnd(14,5,n,1);

H4 = 72+ normrnd(14,5,n,1);

H5 = 96+ normrnd(14,5,n,1);

figure

hhh = [H1 H2 H3 H4 H5];

hist(hhh,130)

edges = -20:140;

counts1 = histc(H1, edges);

counts2 = histc(H2, edges)

counts3 = histc(H3, edges);

counts4 = histc(H4, edges);

counts5 = histc(H5, edges);

% Get indexes of first overlap region.

mask = counts1>0 & counts2>0;

% Sum both histograms in that area.

sum1 = sum(counts1(mask)) + sum(counts2(mask))

% Get indexes of second overlap region.

mask = counts2>0 & counts3>0;

% Sum both histograms in that area.

sum2 = sum(counts2(mask)) + sum(counts3(mask))

% Get indexes of third overlap region.

mask = counts3>0 & counts4>0;

% Sum both histograms in that area.

sum3 = sum(counts3(mask)) + sum(counts4(mask))

% Get indexes of fourth overlap region.

mask = counts4>0 & counts5>0;

% Sum both histograms in that area.

sum4 = sum(counts4(mask)) + sum(counts5(mask))

Add a comment
Know the answer?
Add Answer to:
How to Write a function, called multGauss, to compute the sum of multiple Gaussian (normal) profiles...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT