LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Gaussian Fit again

Since I got such good feedback on my search 1D array problem on this
group, I thought I would post this question. I am looking for a
guassian fit and from searching this group, NI's dev zone, and the
webring there is nothing to be found but others looking for the same
thing. If anyone has any suggestions about how to fit data to a
gaussian curve or has found a vi for this, I and I am sure many
others, would appreciate the heads-up. I am not sure how to approach
it as this is my first attempt at fitting data.

BTW, I have tried the labview.pica.army.mil site and its says there is
an archived copy of an attempt somewhere but the links that lead to it
are bad and any all the alterations I try don't work either. If
anyone knows the correct links, that
would be appreciated as well.

You guys are great
Heather
0 Kudos
Message 1 of 5
(3,486 Views)
H wrote:
>
> Since I got such good feedback on my search 1D array problem on this
> group, I thought I would post this question. I am looking for a
> guassian fit and from searching this group, NI's dev zone, and the
> webring there is nothing to be found but others looking for the same
> thing. If anyone has any suggestions about how to fit data to a
> gaussian curve or has found a vi for this, I and I am sure many
> others, would appreciate the heads-up. I am not sure how to approach
> it as this is my first attempt at fitting data.
>
> BTW, I have tried the labview.pica.army.mil site and its says there is
> an archived copy of an attempt somewhere but the links that lead to it
> are bad and any all the alterations I try don't work either. If
> anyone knows the correct links, that would be appreciated as well.
>
> You guys are great
> Heather

Heather,
I have done this in the past, but my VI's are not general enough to
pass on. I can explain the general approach I used: I modified the
existing Non-Linear Lev-Mar Fit VI's. This set of VI's will fit an
arbitrary analytical non-linear function. There is one sub-vi in which
you need to provide the analytical expression and the expression of its
derivatives with respect to the fit parameters. This all works fine,
except that for a function like a Gaussian, you need to supply fairly
reasonable first estimates for the initial coefficients or the fit will
quickly diverge. My data is almost always a relatively well-behaved
(but noisy) Gaussian peak, so I was able to generate estimates
relatively easily. I wrote the Gaussian equation so that the fit
parameters were explicitely the peak amplitude, position, width, and
offset. I estimated these with relatively straight-forward calculations
from the raw data. For Amplitude, smooth the data and find the maximum
value in the data array. The index of that maximum is a good first
estimate of the position. For offset, average a bunch of data well
before and well after the peak. The width is just found by searching
the array forwards and then backwards for where it exceeds half the peak
amplitude and subtracting the two indeces.
If there is a lot of demand for this, I could try polishing it up and
posting it. It would take a while, but I could be motivated to do it,
since I have another project coming up for which I need to do it anyway.

Regards,
Dave Thomson

-------------------------------------------------------------
David Thomson 303-499-1973 (voice and fax)
Original Code Consulting dthomson@originalcode.com
www.originalcode.com
National Instruments Alliance Program Member
-------------------------------------------------------------
Research Scientist 303-497-3470 (voice)
NOAA Aeronomy Laboratory 303-497-5373 (fax)
Boulder, Colorado dthomson@al.noaa.gov
-------------------------------------------------------------
0 Kudos
Message 2 of 5
(3,484 Views)
I am looking for a Gaussian curve fit vi as well. In the mean time, a fourth order polynomial fit is what I'm using. It works almost as well. Some mathematical manipulation is needed to squeeze out the Gaussian parameters. It's a bit of a pain, but it can be done if necessary.
0 Kudos
Message 3 of 5
(3,484 Views)
DrewS wrote:
>
> I am looking for a Gaussian curve fit vi as well. In the mean time, a
> fourth order polynomial fit is what I'm using. It works almost as
> well. Some mathematical manipulation is needed to squeeze out the
> Gaussian parameters. It's a bit of a pain, but it can be done if
> necessary.

Drew,
It didn't take very much effort, so I went ahead and cleaned my
Gaussian Peak Fit VI's up and posted them on my web site. You are
welcome to take a look. Go to www.originalcode.com and then Example
Code, Utilities, and Program Downloads. Keep in mind that they are
free, and worth every penny...

Regards,
Dave

-------------------------------------------------------------
David Thomson 303-499-1973 (voice and fax)
O
riginal Code Consulting dthomson@originalcode.com
www.originalcode.com
National Instruments Alliance Program Member
-------------------------------------------------------------
Research Scientist 303-497-3470 (voice)
NOAA Aeronomy Laboratory 303-497-5373 (fax)
Boulder, Colorado dthomson@al.noaa.gov
-------------------------------------------------------------
0 Kudos
Message 4 of 5
(3,484 Views)
Hi,
I had been using the basic Levenberg Marquardt vi with the function a+b*exp(-(x-c)^2/(2*d^2)) as the model description. It took typically 11 seconds to fit a Gaussian to 288 data points and a massive 27 seconds to fit 768 data points - this was even when the inital guess was the exact solution to a test sample. Would you have any idea why it wuld run so drastically slow?
By the by, your code works perfectly, fitting the same data in well under a second. Thanks for posting it.

griff
0 Kudos
Message 5 of 5
(3,457 Views)