LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Gauss fit ignores or misinterprets weights?

Solved!
Go to solution

Dear users,

 

I am confused using the Gauss Peak Fit function and it's weights input.

 

My goal is to eliminate the sharp peak in the input data (white). Now, I see that the overall tendency is a Gauss shape.

 

My first attempt was to introduce a weighting that would prefer the outer data instead of the central ones (that is "weight1 (no zero weights)" -- red V-shaped curve). Well, I've got a Gauss curve that is not so good ("Gauss1" -- red curve).

 

My next attempt was to set some weight values in the center to zero ("weights2 (some zero-weights)" -- blue dots with zeros at center time). Surprise, surprise, it has got even worse ("Gauss2"-- blue curve).

 

So, I deleted I set some values in the amplitudes to NaN -- those values which are part of the sharp peak. The results is not publishable at all.

 

As next, I deleted the 7 dots around the center completely and fitted the two wings of the input data. Then I interpolated the missing rest and came up with "Gauss3" -- the orange curve.

 

As a cherry on the top of it. I glued the original data with the interpolated Gauss3 to finally get rid of the sharp central peak.

 

My question is: Why did Gauss Peak Fit ignored my weights? According to the help, they should not be non-zero; that is all.screenshot.png

0 Kudos
Message 1 of 10
(3,222 Views)
(Sorry, cannot look at your VI, posting by phone)

What happens if you set the weight to zero?
0 Kudos
Message 2 of 10
(3,216 Views)

I agree that the gaussian fit does a poor job with weighting enabled. The code is opaque, so I cannot tell what is going on, but since there are no parameter estimates, My guess is that they give poor estimates is the center of the peak is missing. Maybe it is generally fragile code. Sorry, I don't know.

 

I strongly recommend to use the nonlinear fitting and make an explicit gaussian model. Now the fits seem to work just fine and as expected. See attached modification of your code.

 

 

Download All
Message 3 of 10
(3,193 Views)
Solution
Accepted by ghighuphu

The problem may be due to the 'parameter bounds' input to the Gaussian Peak Fit.vi.  By default the offset min and max are both 0, forcing the offset parameter to be 0.  When I changed the offset min and max for all three instances of the Gaussian Peak Fit.vi to be unconstrained (-Inf, Inf), then the fit was much better.

 

-Jim

Message 4 of 10
(3,177 Views)

Thanks Jim

0 Kudos
Message 5 of 10
(3,171 Views)

Yes, thank you, Jim, that made it work. I set the offset bounds to (0, 1e-16) and it worked, too, i.e. it ignored the sharp peak and fitted the Gaussian wings with a zero offset. Offset bounds = (0, 0) fails, though. So, there is still something fishy about the optimization, IMO.

 

Thank you, Altenbach, too!

0 Kudos
Message 6 of 10
(3,146 Views)

@ghighuphu wrote:

I set the offset bounds to (0, 1e-16) and it worked, too,


That's a strange choice for the bounds. What is the reasoning?

0 Kudos
Message 7 of 10
(3,114 Views)

I agree, there is still something not quite right.  Seems to be in our initial guess code.  A bug report has been filed to fix the problem.  In the meantime, given that the initial guess code seems to be the problem, please supply your own initial guess if you have any doubts.

 

-Jim

Message 8 of 10
(3,081 Views)

@altenbach wrote:

@ghighuphu wrote:

I set the offset bounds to (0, 1e-16) and it worked, too,


That's a strange choice for the bounds. What is the reasoning?


A small change in the input values (in our case the offset limits) makes a huge difference in the results. That makes me allert and curious. The issue seems to be explained by Jim, I check on the initial guess and report back.

0 Kudos
Message 9 of 10
(3,040 Views)

 

OK, so if any of the initial guesses is NaN, the optimiastion fails as described above.

initial guess.png

 

The guess above makes some of the Guass optimisations works well, see below.

 

Gauss optimisation with initial guesses.png

 

I am happy with the solution for now, and I am also happy that I could push some corrective actions forward 🙂

 

Thank you all! Cheers,

0 Kudos
Message 10 of 10
(3,026 Views)