cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Gaussian fit to several peaks

payman
13-Aquamarine

Gaussian fit to several peaks

Hello All,

My data has several peaks and I want to fit Gaussian function to each one to obtain the position of each peak's apex. Could you please let me have the idea how to do this? My program should find the peaks and fit the Gaussian to each one.

Thank you very much in advance.

Payman

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:payman)

Here is a slightly modified sheet.

1) The fit uses the fixed width FWHM now and adjusts only two parameters (position and height).

2) The data used for the fits is limited to the surrounding of the peaks, so the data of the second peak does not influence the fitting for the first peak and vice versa.

However, the peaks of the data points usually do not exactly coincide with the apex of the Gaussian shape. My goal is to find the apex of the Gaussian shape which is the "actual peak" and usually is slightly different from the peak that data points show.

The values you are searching for are exactly the first two values of the optimized parameters (position and height). So you don't even need maximize to find the max value.

Your brilliant example program force the apex of the Gaussian shape to be at the peak of the data points.

This was just done in the first example (fit1 and fit2) which actually aren't fits at all as I simply create a Gaussian with the known width at the location of the data point peak.

This worked pretty well (by visual inspection) for the second peak, but not that good for the first. So I used genfit to optimize the parameters for the Gaussian to better fit the data. This resulted in a better fit and now the peak is NOT at the position of a data point (see the magnification of the peak). In my first sheet this fitting would also change the peak width slightly while in this new one it doesn't.

In my new appraoch here, only position and height are fitted, I am doing it for both peaks (--> fit1b, fit2b) und you can immedeatly tell the postion of the peaks by looking at the optimized parameters.

1.png

2.png

View solution in original post

14 REPLIES 14
Werner_E
24-Ruby V
(To:payman)

PAYMAN RAJAI wrote:

Hello All,

My data has several peaks and I want to fit Gaussian function to each one to obtain the position of each peak's apex. Could you please let me have the idea how to do this? My program should find the peaks and fit the Gaussian to each one.

Hard to help without further information and without your sheet (maybe also hard with the data/sheet, too).

Maybe the following threads are of interest:

http://communities.ptc.com/message/234888#234888

http://communities.ptc.com/message/194351#194351

http://communities.ptc.com/message/190658#190658

payman
13-Aquamarine
(To:Werner_E)

"Sorry, I had to delet my posts beacause the attached file was not working..."

Thank you Werner,

the attached file is an example of my data set. There are two peaks and my program should find and fit the Gaussian function with known width (FWHM) to each peak. The goal is to find the exact position of the apexes.

I found an example worksheet which helped me to find the peaks (maxima). Now having the coordinates of peaks, is it possible to address mathcad to fit a function to the neighberhood of maxima points?

I have barrowed the program and inserted into my worksheet. (please see the updated file)

Werner_E
24-Ruby V
(To:payman)

You can replace the Get_Extrema() routine by the built-in routines localmax() and localmin() from the the Data Analysis Extension Pack.

Now having the coordinates of peaks, is it possible to address mathcad to fit a function to the neighberhood of maxima points?

What exactly do you mean by fitting to the neighborhood of the maxima?

And what should the fit function be - Mathcad offers some predefined and you can define your own using genfit(). Its also possible to use a solve block with minerr() to determine the coefficients and variables of your fit function.

payman
13-Aquamarine
(To:Werner_E)

Werner; Sorry for asking too many questions.

I am using mathcad 14 on my personal computer and the function localmax doesn't work here. Also Get_Extrema() routine does not detect the peak when it is at zero position. Could you please tell me what changes should be done on Get_Extrema() or how can I add localmax to Mathcad 14?

RichardJ
19-Tanzanite
(To:payman)

These should work.

payman
13-Aquamarine
(To:RichardJ)

Thank you. You are Great.

Werner_E
24-Ruby V
(To:payman)

Look if the attached is what you are looking for.

payman
13-Aquamarine
(To:Werner_E)

Wonderful. Thank you very much.

I need more time to get myself familiar with the steps.

Thanks again.

payman
13-Aquamarine
(To:payman)

I have a problem here and I need to modify my question.

My data points show 2 peaks. I know that each peak must follow a Gaussian shape with known width.

However, the peaks of the data points usually do not exactly coincide with the apex of the Gaussian shape. My goal is to find the apex of the Gaussian shape which is the "actual peak" and usually is slightly different from the peak that data points show.

Your brilliant example program force the apex of the Gaussian shape to be at the peak of the data points.

Could you please help me with this problem.

RichardJ
19-Tanzanite
(To:payman)

Your brilliant example program force the apex of the Gaussian shape to be at the peak of the data points.

No it doesn't. p.opt gives the peak location for the first Gaussian as 1.338*10^-5. That does not coincide with any data point.

payman
13-Aquamarine
(To:RichardJ)

How did you find that?

If I call the max of "fit1b" , it is at 1.39*10^-5

RichardJ
19-Tanzanite
(To:payman)

You calculated new y values at the existing x values, and then used localmax to find the highest y value. That can only ocurr at one of the existing x values. If you want to find the maximum of the Gaussian function you should use maximize. There's no point though, because the first fitted parameter from genfit is the position of the Gaussian.

Werner_E
24-Ruby V
(To:payman)

Here is a slightly modified sheet.

1) The fit uses the fixed width FWHM now and adjusts only two parameters (position and height).

2) The data used for the fits is limited to the surrounding of the peaks, so the data of the second peak does not influence the fitting for the first peak and vice versa.

However, the peaks of the data points usually do not exactly coincide with the apex of the Gaussian shape. My goal is to find the apex of the Gaussian shape which is the "actual peak" and usually is slightly different from the peak that data points show.

The values you are searching for are exactly the first two values of the optimized parameters (position and height). So you don't even need maximize to find the max value.

Your brilliant example program force the apex of the Gaussian shape to be at the peak of the data points.

This was just done in the first example (fit1 and fit2) which actually aren't fits at all as I simply create a Gaussian with the known width at the location of the data point peak.

This worked pretty well (by visual inspection) for the second peak, but not that good for the first. So I used genfit to optimize the parameters for the Gaussian to better fit the data. This resulted in a better fit and now the peak is NOT at the position of a data point (see the magnification of the peak). In my first sheet this fitting would also change the peak width slightly while in this new one it doesn't.

In my new appraoch here, only position and height are fitted, I am doing it for both peaks (--> fit1b, fit2b) und you can immedeatly tell the postion of the peaks by looking at the optimized parameters.

1.png

2.png

payman
13-Aquamarine
(To:Werner_E)

Great help. I really appreciate your attention.

Top Tags