09-28-2011 08:11 AM
Hi,
I've been working on a fit with LV. I have a set of data presenting a baseline and 4 superposed gaussian.
Using general functions:
a1 * exp (-0.5*(( x- b1 )/ c1 )^2)+
a2 * exp (-0.5*(( x- b2 )/ c2 )^2)+
a3 * exp (-0.5*(( x- b3 )/ c3 )^2)+
a4 * exp (-0.5*(( x- b4 )/ c4 )^2)+
d*x+e
where a,b,c are the parameters of the gaussian curves; d, e those of my baseline and x my variable.
If you try the VI, you'll find a solution but I'd like to improve it.
We want the parameter c1, c2, c3, c4 to be the same, lets call it "c". That way my gaussians all have the same "width" (that's what we want).
When I try to simplify those parameters to only one, the VI returs an error -20041: The system of equations cannot be solved because the input matrix is singular
I don't know how to obtain that. I guess it is quite simple but I am not use to LV.
Can you please give me a hand on this problem.
attached: VI and data (changed the extension as it seems I can't send .lvm files)
Cheers
Félix
Solved! Go to Solution.
09-28-2011 07:57 PM
Felix,
Generally the Lev_Mar VI which uses a Curve Fit Model subVI is more robust than the formual version, although not quite as easy to set up. Read the detailed Help carefully! When you have an equation which can be differntiated analytically, calculating the partial derivatives in the model subVI often avoids numerical approximation problems also.
When I put together the model VI attached below it seems to work OK with the data file you attached. Note: I used the Constrained L-M Curve Fit VI because I could not get at the non-string version of the regular L-M VI for some reason.
Lynn
09-29-2011 03:17 AM
Sounds terrific.
Thank you for your help and advice. I'll learn how to prepare subVi like this.
Cheers
Félix
10-04-2011 08:56 AM
Hi,
I've been working around my set-up and the solution you gave me is working fine.
My problem is about the fit parameters. I've seen that the fit is strongly dependant of it. Here is what I have.
A set of spectrum, taken every hour. I'd like to fit them and see the variation of the amplitude and FWHM for a selected gaussian peak. I used a feedback node and the replace array subset to "reset" my initial parameters with the best fit parameters.
But then the fit doesn't match the new spectrum. The error is even bigger and grows up.
Do you have any idea for this?
Thanks
Félix
P.S. Attached a series of spectrum
10-04-2011 06:49 PM
I do not seem to see the kind of effect that you mention. Running my program with the data you posted shows the fit varying somewhat accross the dataset, but I do not observe a growing error. When I put the Initial parameters into a shift register and connect the Best Fit Coefficients to the right terminal I see almost no difference.
I tried putting a delay in the loop so I could watch the progression, but that did not give me any clues either. It does not seem to "track" the position of the peaks.
There is an error in the notes for the quad gauss 1 VI. The code is OK, I think. The df/dbi terms should be df/db1 = a1*(x-b1)/(c*c)*exp(-0.5*(((x-b1)/c)^2)). The (c*c) needs to be in the denominator. I omitted the parentheses.
Sorry I do not have any better suggestions.
Lynn
10-05-2011 03:33 AM
Thank you for your help. This really helped me into my work.
Cheers
Félix
10-06-2011 10:59 AM
Hi Lynn,
I finally found the solution. We had this ideas of reducing the number of parameters, thus I had to change the model.
I found a connection errors and some partial derivative errors, all corrected it workd just fine.
Thank you for you help as I finish my programming work here.
Cheers,
Félix
10-06-2011 12:15 PM
Felix,
My apologies for the errors.
Glad you got it working.
Lynn
10-09-2011 04:55 PM - edited 10-09-2011 05:01 PM
@felixd wrote:
I found a connection errors and some partial derivative errors, all corrected it workd just fine.
One of the main reasons for errors is an overly complicated diagram.
Here's a quick draft that should get the job done with significantly less code. Try it. 😉
(For further speedup, you can parallelize the FOR loop above if you have multiple CPU cores)
10-10-2011 09:32 AM
I take note of the comments, thank you.
I tried with you proposition, works fine and less complicated.
Cheers