LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fit data correctly using Gaussian function

I have some data that I would like to fit to a gaussian function, but it seems not to be using all the data?  It looks like it is only using the middle three points in the attached sample VI?  It give a much broader width that is should be.  Can someone tell me what I am doing wrong, or if there is another function that is better to fit this type of data to?  Even the Bisquare method isn't that good, and the peak of the data should be closly centered near 0.  Thanks in advance for any comments/assistance about why the Gaussian Peak Fit VI is not using the other data points to fit the function, or suggesting another function to fit the data so I can find the width. 
0 Kudos
Message 1 of 9
(13,200 Views)
I think it is fitting all the data. I put an array subset function in each of the data input array lines and changed the start index and length values. The problem may be that your data set is not very gaussian. Since you have no points between amplitude 100 and 10000, the width could probably be estimated just as accurately by using straight line segments on the rising and falling edges. That would also "look" more like your data. Is a gaussian model good for your real data?

Lynn
0 Kudos
Message 2 of 9
(13,188 Views)
Try tightening the tolerance parameter to something like 1E-8.

-Jim
0 Kudos
Message 3 of 9
(13,187 Views)

I think the main problem is the fact that your data has no gaussian shape by any reasonable criteria. A gaussian is the wrong model for you data. Period. 🙂

As they say: "You cannot fit a square hole with a round model". 😮

Message Edited by altenbach on 03-29-2007 06:38 PM

0 Kudos
Message 4 of 9
(13,181 Views)
OK, further analysis tells me that the gaussian fit VI is no good in this scenario.
 
Some observations:
  1. If the initial guess for any combination of paramters (e.g. only the standard deviation) is set to NaN, the highest point falls on the data with zero difference. Makes no sense!
  2.  If no initial guess is set to NaN, the VI returns the initial guesses as best fit, no error. (tolerance of 1e-7)
  3. Even if I set the tolerance to 1e-20, the parameters barely vary (e.g. ampltude 8000->8002)
  4. Similar odd behavior on bisquare, etc.

Anyway, I would use levenberg-Marquardt (Nonlinear Curve Fit) with a gaussian model. The result seems to be much more reasonable and the residue is better than any result with the gaussian fit above (see image). Try it!

Message Edited by altenbach on 03-29-2007 07:51 PM

0 Kudos
Message 5 of 9
(13,177 Views)
I have noticed this too and find it wholly unusable.

Luckily I have my own optimised gauss fitting routines based on the LV Lev-Mar fit (in 6.1).  They work fine.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 6 of 9
(13,156 Views)
Thanks everyone for the help.  Altenbach I was wondering if you could attach the VI with the levenberg-Marquardt method that you described.  Thanks.
0 Kudos
Message 7 of 9
(13,148 Views)
I have another question, I figured out how to use the Nonlinear fit VI from your previous post.  In addition to the Gaussian I was thinking of trying other functions too.  I am currently trying a lorenzian function, and I have having difficulties with it.  It should have 3 paramters: center, amplitude, and FWHM.  The problem is with the initial coefficients, I use 0 for the center, max value for the amplitude, and 10 for the FWHM.  For some reason I get incorrect results unlless I give the FWHM an initial value of less than 0.1, even though the final FWHM ~12?  Can someone tell me why even if I put the final FWHM value in it still doesn't work.  Thanks again for your help. 
Download All
0 Kudos
Message 8 of 9
(13,133 Views)
Your initial estimates for the amplitude is way off.
 
Try to set the parameter estimates to e.g. [200000-300000, 0, 10].
0 Kudos
Message 9 of 9
(13,101 Views)