LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Gaussian fitting - robustness

Hi all,

I'm using the Gaussian Peak Fit vi to fit to extracted frequency information in a series of images, but I'm having a lot of problems getting a stable/sensible signal out.After pre-processing the data, I'm left with something that looks very visually like a simple Gaussian:

A good fit example, where the Gaussian fits satisfactorilyA good fit example, where the Gaussian fits satisfactorilyA similar input signal, but a shifted gaussianA similar input signal, but a shifted gaussian

However, as you can see on the right - some frames will not fit to this data so nicely (this fitted Gaussian is at the minimum amplitude and maximum centre values allowed by the set parameter bounds). The fit also seems to amplify the small amounts of noise that are present in the signal - jumping back and forth between different fits.

Code Example.PNG

As you an see in the image above, I've increased the tolerance, selected least absolute residual, and constructed dynamic parameter bounds based off of the input data.

At one point, I was feeding the final values of the fit to the prior image as the initial guess (in a hope to remove the jitter previously mentioned), but this worsened the behaviour where the VI would get "stuck" providing bad estimates.

 

What I should be doing to get more robust performance out of this VI? I'm currently using LabView 2018, but am writing for 2017 as well.

0 Kudos
Message 1 of 7
(3,131 Views)

The best way to make the fit consistent is to use good initial guesses. You already have code for parameter bounds. Why not pick the middle of your bounds as your initial guess? Your current initial guess is NaN for all parameters.

-Jim

0 Kudos
Message 2 of 7
(3,100 Views)

fI you want us to troubleshhoot, please also attach the good and bad dataset shown in your picture. (Maybe both as diagram constants)

 

(The code for the gaussian fit is too opaque for me because the core is hidden inside a dll. Hard to tell where it goes off track..)

0 Kudos
Message 3 of 7
(3,091 Views)

As Jim said, the key here is that you aren't providing any initial guess.  Some pointers for generating this guess:

 

  • Peak detect vi will give you an initial amplitude and center guess.
  • FWHM is an easy calculation and will give you a good guess for standard deviation
  • For baseline guess, looking at your data 0 should be OK.  Or you can average the first x points of your data set or something similar.

 

0 Kudos
Message 4 of 7
(3,068 Views)

We cannot peak inside the code, but assuming that the bad guess gets immediately coerced into the parameter bounds, the actual guess would probably be good enough. Hard to tell....

 

0 Kudos
Message 5 of 7
(3,058 Views)

Thanks!

I previously had a construction of an initial guess - but it didn't seem to do any better than the default behaviour of the VI if I left the terminal unwired. 

One offline suggestion that I have received is that the fit was over-fitting to the flat section preceding the peak. I've since given it really simple weights (weighting each point by  local amplitude/maximum amplitude) and this seems to have improved the behaviour. 

 

If anyone is knows more, I've attached the VI with some data that produces an erroneous result, even with this weighting.

 

0 Kudos
Message 6 of 7
(3,039 Views)

One of your two data arrays has no default data saved. Could you repost your VI?

0 Kudos
Message 7 of 7
(3,022 Views)