Re: Lev-Mar fit: linear baseline + 4 gauss

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

duplicate post

Similar Messages

  • Lev-Mar fit: linear baseline + 4 gauss

    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.
    Attachments:
    Fit_felix.vi ‏73 KB
    data.txt ‏31 KB

    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.
    I would arrange the parameters in a better order (you need to change the calling VI too!)
    You don't need the partial derivatives. To fit experimental data, numeric derivatives are sufficient and the fitting routines will calculate them automatically. Just don't connect the partial derivatives output.
    There is way too much duplicate code, one gaussian should be enough, simply loop over all components. (Imagine you want 2 or 20 gaussians at a later point? Imagine you want a slightly different formula: you would need to make the same change in n places.)
    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)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    quad gauss 1MOD.vi ‏15 KB
    QuadGauss.png ‏9 KB

  • Lev-mar fitting in diadem

    Hi,
    I'm completely new to DIAdem.  I'm surprised that - from what I can see - there's no Levenberg-Marquardt (or equivalent) fitting routine for parametric fitting to nonlinear functions.  Is this right?  How can I give DIAdem this functionality?  Is Xmath an option for accomplishing this task?
    Nick
    "You keep using that word. I do not think it means what you think it means." - Inigo Montoya

    Hi Nick,
    It is possible to call LV DLLs from a GPI-DLL, you just need to have the LV runtime engine on that computer and also put one other file in the Windows System directory-- but I forget now which it was.  I did this 4 or 5 years ago with a Bessel Function from LabVIEW.  The GPI-DLL framework is extensive, and it's easy to get lost in it, but if you can run the GPI-DLL wizard, the boiler-plate code is super easy to create.  And if you can find the right callback function, you only need to add about 10 lines of code to call an external LV DLL.  Don't rely on the heap for memory, though, or you will limit the array size you can process-- use MAlloc just like you would in a normal C++ program.
    I don't think I remember anything else,
    Brad Turpin
    Product Support Engineer
    National Instruments

  • Varying Lev-Mar init. conditions causes wide change in fit coeficients.

    Hey, I'm trying to use the advanced Lev-Mar fit vi to fit an exponential decay with an offset. I noticed that when I vary the initial condition for the time constant by 5% I get significant changes in my fit coeficient for the same parameter. However, when I multiply my input Y values by 10^4, the fit coeficients are more robust and change little with initial conditions that vary more than 10%. Also, the values now seem to match well with values I obtain when I perform the same fit in the Origin plotting program. Why is this? All my values are in double precision so I don't see how this could be a precision issue.

    The Lev-Mar has a well-known "bug" in the termination condition IF you fail to wire the "standard Deviation Input". In this case, the standard deviation is taken as 1, which is fine except for the case where your y-data is very small (e.g. all in microvolts or nanovolts). In this case, the function is considered converged after one iteration using the initial guesses.
    You have two options:
    (1) (not recommended) Edit the Lev-MAR.vi and make the diagram constant in the bottom center much smaller.
    (2) (RECOMMENDED!) Always wire a "standard deviation input array". In your case, just create an array with equal size as your data, initialized with numbers corresponding to the noise in your data. It does not need to be accurate, you could just take it as e.g. 10E-4 to 10e-6 times your y-range (y-max minus y-min).
    LabVIEW Champion . Do more with less code and in less time .

  • Please help on this Lev-Mar problem

    Hi,
    I have two acquisition data sources that need
    to be fitted. Then the fitted parameters are
    passed along with data for further processing.
    As the data is heardware generated, I made a
    similar 'signal generator' to present very closely
    the problem.
    ===Please see the attached vi file===
    As you can see, these two Lev-Mar's function
    / derivatives are obviously different. We can edit
    the fuction / derivative node. But the problem
    is that when one is edited, the other changes too.
    Anyways, we can NOT have two different functions.
    My question is: How to have two different function
    / Deveritives here?
    By the way, how to replace the MatLab box into
    function node in my attached example?
    I can 'wire' the out
    put to next if it's a
    function node. It says the type of variables are
    different (output is a real instead of array).
    Attachments:
    Lev-Mar-Question2.vi ‏99 KB

    You have a few options for multiple function/derivatives.
    1. If you can express the model functions using the formula string syntax, then you might consider using the "Levenberg Marquardt.vi". Unfortunately the Levenberg-Marquardt.vi does not allow the specification of the derivative of the model function and always uses numerical derivatives. It is also somewhat slower than the "Nonlinear Lev-Mar Fit.vi".
    2. You could also save a copy of the "Nonlinear Lev-Mar Fit.vi" using a different name, and also the "Lev-Mar ABX.vi" and "Target Fnc & Deriv Nonlin.vi" with different names. Then you would have a different set of VIs to implement the curve fitting on two different models. This is ugly, but would work.
    3. You could modify the "Nonlinear Lev-Mar
    Fit.vi", "Lev-Mar ABX.vi", and "Target Fnc & Deriv Nonlin.vi" to accept/pass VI references. The "Target Fnc & Deriv Nonlin.vi" would then perform a call by reference to a VI that you wrote implementing the current model function.
    To replace the Matlab script node place the formula node inside a for-loop. The for-loop will auto-index the x and t arrays, and auto-build the y-array.

  • Lev-Mar template missing

    I am trying to fit A*sin(w*t+phi) to some noisy data (amplitude, frequency, and phase are all to be detrmined from the matched sine). When I looked at the Lev-Mar fitting VIs I could not locate the template for the LM model function and gradient VI template mentioned in the Help file. labview\vi.lib\gmath\opti.llb\numerical is empty. (Help says this template should be there). The figure in the help file shows a cluster called Output Control as an input to the VI, but does not specify the elements of the control. I also could not find a way to put the formula into the String Formula version. Is there a listing of the available functions and syntax? The help did not seem to lead me to it.
    LV8.0.1 on Mac OS X
    Maybe it is just too late on Friday afternoon.
    Lynn

    Sarah, Christian,
    I had looked at that link and several others. I was hoping to find some reference where someone had made some practical suggestions reagrding optimizing the initial guesses, or at least some clues as to how to go about it.
    My data has a frequency range of about 2.5:1 so I was hoping I could just set the initial guess at the middle of the range. In my testing an initial guess 20% above or below the actual frequency resultis in erroneous values about 80-90% of runs with noise at 10% of signal amplitude which is better than the real data. With initial amplitude and phase equal to the data parameters and initial frequency guess at 1.2 times the actual I recorded two runs with the fit frequency at 99.9%. Eight others produced: 160%, 180%, 210%, 160%, 160%, 130%, 60%, and 160%. With the initial frequency at 80%, the results were somewhat worse.
    My suspicion is that because the partial derivatives of the model equation are also sines and cosines, the algorithm tends to find some kind of local minimum and converges to that even though it is a really poor fit.
    Here is my modified Lev-mar VI and the simple sine model VI (LV8). The default values are fairly typical of the data sets we will be getting.
    Thanks for the help.
    Lynn
    Attachments:
    Nonlinear Fit Lev-Mar.Berry.vi ‏41 KB
    simple sine model.vi ‏21 KB

  • Curve Fit of ODE, should I use Lev-Mar or Constrained Nonlinear Optimization?

    I wanna do a curve fitting of differential equations, following is the equations:
    dx/dt = u*x-a*x
    ds/dt = b*u*x+c*x
    dp/dt = d*u*x+e*x+f*p
    and u = um*s/(km+s+s^2/ki)
    I've tried "nonlinear curve fit( Lev-Mar)", but I met difficulties when writing the f(x,a) of Lev-Mar.
    Then I tried "Constrained Nonlinear Optimization", I found that the example "Estimate Nonlinear Spring Constant.vi"
    in the "labview\examples\math\curvefit.llb" was similar to the fitting I tried to do, but there was only one parameter
    need to estimate in this example,but what I need is to estimate 3 parameters.
    However,I modified the example to my equations, it failed again.
    How can I achieve this? is it possible to do this fit only using Labview VIs or need Matlab Script Node?
    Any help will be appreciated.

    I forgot to mention that in the equations above,  a,b,c,d,e,f is constant,
    and the data of x,s,p corresponding with the data of time is already known,
    and which parameters I wanna identify is um,km,and ki
    帖子被myafu在12-22-2006 01:33 AM时编辑过了

  • Problem: Fitting Lev-Mar with Error Function

    Hi everyone,
    I have very little experience with LabVIEW and I'm trying for the first time to do some NonLinear Curve fit for some data I have.
    I've searched in forums for almost a day and couldn't find what I need. The problems are:
    1) I need to fit a function of the following type: P = Po/2 - Po/2*erf(sqrt(2)*(x-xo)/w) , where Po, xo and w are my parameters.
    But in my error2.vi I cannot link my y=sqrt(2)*(x-xo)/w  variable of the erf function to the input, because the erf.vi does not accept 1D array as input and doesn't give that as output as well. The output thing is another problem, since the input of F(x,a) needs to be a 1D array.
    2) I read about the Lev-Mar NonLinear CurveFit VI and I think I got what needs to be done. However, a I was having problems in wiring my Static VI Reference to the F(x,a) input in the Lev-Mar VI and it didn't give me a broken wire only when I made de Reference a "Strictly Typed VI Reference". What does that mean? Why did it only work with that?
    I know these are some pretty basic doubts, but I've been trying to understand it for quite some time and couldn't get this done.
    Thanks.
    PS* The fitting function (subvi) is the error2.vi file.
    Solved!
    Go to Solution.
    Attachments:
    error2.vi ‏13 KB
    FittingGaussianKnife.vi ‏15 KB

    Try this. Seem to work  just fine (LabVIEW 2013).
    (don't try to graph the best parameters, graph the best fit output!)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    FittingGaussianKnife_MODCA.vi ‏17 KB
    error2_MODCA.vi ‏14 KB
    erfit.png ‏40 KB

  • Lorentz fit of a curve with Lev-Mar

    Hello everybody! I am trying to set of data to a Lorentz curve to calculate a Q value (resonance.) I found a program on a thread from this forum that appears to work with the sample data set from the thread. However, when I try to run the program using my data set with known fitted coefficients as the initial guesses, we get an error in the Lev-Mar sub-VI -- something like “the input matrix is singular”. There’s a screenshot of my data in in the attached zip folder, as well as the text file containing my data.
    My data curves down (reaching a minimum) instead of up, as in the sample data set, but it seems like that should be accounted for by the different initial guesses. I am thinking that something else is going on; hopefully it is something simple that I am just missing. Any help y'all can provide would be greatly appreciated!
    Thank you!
    Attachments:
    Lorentz Fit.zip ‏1992 KB

    Hello Lynn,
    Yes, there are quite a few potential peaks in that data set. The peak you identified was the one that we are trying to fit (The peak should be trimmed by the cursors.) We used origin to fit that same peak in order to get the initial guesses for the coefficients in the screenshot. When it runs, we get the error message: "Error -20041 occured at NI_Gmath.lvlib: Nonlinear Curve Fit LM.vi:2 Possible reason(s): Analysis: The system of equations cannot be solved because the input matrix is singular." 
    Thanks!
    -Garrison

  • How to constrain parameters in Lev-Mar?

    It's a common case for non-linear fitting.
    How can it be done in LabView's Lev-Mar?
    Thanks.

    The provided LabVIEW implementation does not contain options for parameter bounds.
    One solution would be to re-parametrize your code in terms of unconstrained variables that cause a constraint on your original parameters.
    Some transformations for one-sided or two-sided parameter bounds are given here:
    http://www.id.unizh.ch/software/unix/statmath/sas/sasdoc/stat/chap19/sect41.htm
    The link also lists references with more details.
    LabVIEW Champion . Do more with less code and in less time .

  • A confusing lev-mar error

    I am trying to fit a Lorentzian to some acquired data using the lev-mar function, and it returns the error "wrong model equation". I know for a fact that the data has a lorentzian shape because I wrote a little vi to fit it manually using the exact same equation. Does anyone have a suggestion as to what to do next, or at least what the "wrong model equation" error really means? Thank you.
    JPC

    The error refers to a syntax issue with the "model description" input.
    This input is a cluster of three strings: model, which is the actual equation (Ex: a+b*x+c*x^2); paramters, which are the solvable variables (a, b, & c in the previous ex.) inputted as an array of strings; and the independent variable (x).
    All 3 parts of the model must match exactly (e.g. you can't have 3 variables in the model and 1 in the parameters, and if you designate x as the independent variable, there must be an x in the model equation).
    Additionally, the model equation follows standard LabVIEW formula node syntax, except there are no input variables designated ("y=x+1" won't work but "x+1" will) and you don't need a semi-colon terminator.
    Let me know how it goes,
    ~j5
    2006 Ultimate LabVIEW G-eek.

  • Curvefit of the reflectivi​ty with Lev-Mar

    Hello,
    I am a beginner with Labview and I need your help, I recuper the data of the reflectivity from the spectrometer (3648 points) and I am going to make the fitting to extract information about the thickness and refractive indices n and k (k in the general case it will be zero because the materials used are oxides and I work in the visible range.
    I want to use the model of Lev-Mar but I have the problem with the model, i have used the formula node to write the eqaution of the reflectivity, and currently I am block.
    Data.txt
    column1 = Lambda
    column 2 : Reflectivity
    the substrate is Pyrex  ; n= 1,47
    the thin film is Ti-Nb, the index is like that of the titane(Antase) : ñ = 2,561 + i2,488
    Thank you very much.
    Nb: i know my english is so bad
    Attachments:
    fit1.png ‏36 KB
    fit2.png ‏30 KB
    Data.txt ‏51 KB

    Thank you very much Lynn,
    I did what you told me to do and it works a better,
    I would like to know if you can help me, I have the values of the reflectivity R as a function of the wavelength (lambda) but the indices " n "  and " k " are also a function of lambda.
    R = (n,k,d,lambda )   and  the dispersion equation n(lambda) and k(lambda)
    With the curvefit Lev-Mar is possible to define these parameter ? if you have ideas that will be cool

  • Lev mar parameter min value

    When I use the Lev Mar curve fit, I get an error that says at least one of my input parameters is NaN or Inf.  There is a place in my fitting equation where I divide by the parameter and take the square root, so if it was either zero or negative, this would not work.
    Is there a way that I could force Lev Mar to not choose values of 1 or zero for this parameter?  My initial guess is very small (on the order of 10^-4), but this parameter is time, so it should not be negative or zero anyways.

    What is your LabVIEW version? The function has been renamed to "nonlinear curve fit" many versions ago.
    There is a constrained nonlinear curve fit that lets you set parameter bounds. Use that instead.
    Can you show us your code and some typical data? If you calculate the model with your paramter guesses, does it look anything like the data?
    LabVIEW Champion . Do more with less code and in less time .

  • Ajustement de courbe (Fitt) Lev-Mar

    Bonjour/Bonsoir
    Je veux faire un ajustement de courbe en utilisant le modèle de Mar-Lev pour des mesures de la Réflectivité en fonction de la longeur d'onde mais j'ai pas réussi à le faire;
    Les valeurs de "n" et "k"  varient en fonction de la longueur d'onde mais la je les ai pris fixes, es ce qu'il y a une possibilité de prendre les paramètres comme étant des tableaux ??.
    Les valeurs de "ns" et "ks"  je peux les considérer fixes mais comment faire pour changer leurs valeursr dans la formule ( Utilisation d'une variable globale ???)
    je voudrais savoir aussi es ce que c'est mieux d'utiliser Lev-Mar : VI ou chaine de formule.
    Je sais pas s'il manque d'autres informations .
    merci pour votre aide.
    Cordialement.
    Pièces jointes :
    1NI.png ‏37 KB
    2NI.png ‏62 KB

    Bonjour,
    "Les valeurs de "n" et "k"  varient en fonction de la longueur d'onde mais la je les ai pris fixes, es ce qu'il y a une possibilité de prendre les paramètres comme étant des tableaux ??."
    --> oui, tout est possible. seulement je ne vois pas où sont ces paramètres dans le code, donc c'est dur.
    Les valeurs de "ns" et "ks"  je peux les considérer fixes mais comment faire pour changer leurs valeursr dans la formule ( Utilisation d'une variable globale ???)
    --> si je comprends, ils sont fixes mais tu veux pouvoir contrôler leur valeur depuis "l'extérieur". Dans ce cas, variable globale ou variable globale fonctionnelle (=VGF). Tu trouveras des exemples facilement pour les VGF
    "je voudrais savoir aussi es ce que c'est mieux d'utiliser Lev-Mar : VI ou chaine de formule."
    --> à toi de voir selon tes exigences et tes critères. La formule est peut-être plus performantes en terme de temps d'exécution, mais le code tient plus de place dans le diagramme, il est peut-être moins lisible. Moi je prendrais la formule, car ça s'exécute plus vite et on sait exactement quel calcul est fait.
    Francis M | Voir mon profil
    Certified LabVIEW Developer

  • Lev Mar parameters for Gaussian fit

    I am trying to analyse a Gaussian profile using the Lev-Ma r fit provided with LabVIEW. My problem is that I don't know the proper format for the function descriptions to use and get an error when using the fit. Has anyone done this in the past, and can help with the formating of the inputs to the fit.
    Thanks
    Eugene Lorman

    lorman wrote:
    > I am trying to analyse a Gaussian profile using the Lev-Ma r fit
    > provided with LabVIEW. My problem is that I don't know the proper
    > format for the function descriptions to use and get an error when
    > using the fit. Has anyone done this in the past, and can help with
    > the formating of the inputs to the fit.
    >
    > Thanks
    >
    > Eugene Lorman
    Eugence,
    I've been doing similar stuff myself, and found this link very helpful:
    http://www.originalcode.com/occdl.html
    Page down through and you'll find a downloadable VI that does
    peak fitting on a gaussian.
    HTH
    dave Langstaff
    Remove "spamkill." when replying to this message

Maybe you are looking for