LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

error in nonlinear LM fit

Solved!
Go to solution

Hi

I have (again) questions regarding the nonlinear LM fit. I took the vi gracefully posted by altenbach here :

https://forums.ni.com/t5/LabVIEW/how-can-I-extract-a-gaussian-function-out-of-a-spectrum-which/m-p/2...

 

I would like to fit a baseline + few gaussians to experimental data. I modified a little bit the previous exemple, see attached file, but I am getting an error. Any help ?

Thanks

 

 

0 Kudos
Message 1 of 22
(4,404 Views)

Hi

I am trying to fit a sum of a few Gaussians (3-4 depending on the input data) and a straight line.  The positions and amplitudes are known so I want to fit only the widths.

I am using LM fit with formula and wrote something to write the formula depending on the number of gaussians. The whole program take some X,Y data then find peak amplitude, and positions then I pass a 2D array with 3 columns : amplitudes, positions and estimated widths. However I get an error when parsing this formula. any ideas ?

see attached file with typical data

thanks

0 Kudos
Message 2 of 22
(4,399 Views)

@nitad54448 wrote:

 

I would like to fit a baseline + few gaussians to experimental data. I modified a little bit the previous exemple, see attached file, but I am getting an error. Any help ?


I have no idea why you are wiring the "weight" input with the Y data. Disconnect that and the fit will have no error.

 

(Also, why are you using the bounded version with empty arrays as bounds? Just use the plain version).

0 Kudos
Message 3 of 22
(4,368 Views)

@nitad54448 wrote:

 

I am using LM fit with formula and wrote something


You really should use the VI model, much higher performance and easier to maintain.

 

Still your obvious mistake is that you have 5 parameters, but the parameter guess array only contains three elements. These sizes must match.

0 Kudos
Message 4 of 22
(4,367 Views)

Hi again

 

I think I post an old version, I did not see the 3 parameters (silly mistake), anyway with 5 parameters in the array I get again an error. Pls check the file.

Thanks for looking

N

0 Kudos
Message 5 of 22
(4,362 Views)

Hi again

Two blunders in one day : I need to take a holiday. Indeed I removed the weight and then there is no error. However, as you can check in the vi that I posted there is no fit either. I mean the program just stops with the guess parameters.

thanks

0 Kudos
Message 6 of 22
(4,360 Views)

@nitad54448 wrote:

 

I think I post an old version, I did not see the 3 parameters (silly mistake), anyway with 5 parameters in the array I get again an error. Pls check the file.

 


The "initial parameters" input still only contains 3 elements. (The orange array wired to the top of the fitting VI)

 

Now you messed up the array with parameter names, which was correct before. So undo that! (Now it contains 8 parameter names, some in duplicate.)

0 Kudos
Message 7 of 22
(4,358 Views)

Hi

OH, got it.

In the 2D table at left I put all parameters for Gaussians (took your model, just add lines for more gaussians). Now I take the width column 1D array, I put a0 and a1 and the guess parameters are in an array of 5. I got 5 unknowns a0 to a4 in my formula.

Still get an error (version corrected_2)

Can you see something else  in error?

0 Kudos
Message 8 of 22
(4,354 Views)

OK, here's what I modified. Your 2D paramter arrays contains some extra data. It is slow, but works without error.

 

LMFormula.png

0 Kudos
Message 9 of 22
(4,351 Views)
Solution
Accepted by topic author nitad54448

@nitad54448 wrote:

 

Can you see something else  in error?


See my code above. Your "Tableau" has too many and duplicate elements (resize the indicator to see all).

Message 10 of 22
(4,348 Views)