Get Help

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Gaussian fit to several peaks

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-30-2014
01:00 PM

08-30-2014
01:00 PM

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

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-03-2014
07:12 PM

09-03-2014
07:12 PM

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.

14 REPLIES 14

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-30-2014
01:19 PM

08-30-2014
01:19 PM

Re: Gaussian fit to several peaks

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-30-2014
02:52 PM

08-30-2014
02:52 PM

Re: Gaussian fit to several peaks

"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)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-30-2014
04:09 PM

08-30-2014
04:09 PM

Re: Gaussian fit to several peaks

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-09-2014
06:27 PM

09-09-2014
06:27 PM

Re: Gaussian fit to several peaks

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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-09-2014
06:33 PM

09-09-2014
06:33 PM

Re: Gaussian fit to several peaks

These should work.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-09-2014
06:56 PM

09-09-2014
06:56 PM

Re: Gaussian fit to several peaks

Thank you. You are Great.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-30-2014
05:32 PM

08-30-2014
05:32 PM

Re: Gaussian fit to several peaks

Look if the attached is what you are looking for.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-02-2014
08:22 PM

09-02-2014
08:22 PM

Re: Gaussian fit to several peaks

Wonderful. Thank you very much.

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

Thanks again.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-03-2014
09:55 AM

09-03-2014
09:55 AM

Re: Gaussian fit to several peaks

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-03-2014
10:59 AM

09-03-2014
10:59 AM

Re: Gaussian fit to several peaks

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-03-2014
11:37 AM

09-03-2014
11:37 AM

Re: Gaussian fit to several peaks

How did you find that?

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-03-2014
02:25 PM

09-03-2014
02:25 PM

Re: Gaussian fit to several peaks

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-03-2014
07:12 PM

09-03-2014
07:12 PM

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.

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-05-2014
02:58 PM

09-05-2014
02:58 PM

Re: Gaussian fit to several peaks

Great help. I really appreciate your attention.