Showing results for 
Search instead for 
Did you mean: 

semi variable coefficients in a non linear curve fit

Go to solution

Dear all,


I am using a Lev-Mar non linear curve fit vi to fit a custom function to my data. The function is a set of Gaussian functions and an offset. Say I want to constrain the width of one or more of the Gaussian curves in the function. I can do this by changing the values in the equation in the model description in the block diagram but how do I do this easily through the front panel?


These width values will not be floated in the fit.



0 Kudos
Message 1 of 8



By width, are you refering to the width of the peak (i.e. one that can be described by something like half-width full maximum) or are you referring to the range of the fit?  If the latter, then you simply have range inputs and take a subarray of the data that is limited by your range inputs.


Cheers, Matt

Message 2 of 8

Thanks Matt, that was fast!


Sorry, by width I meant half width half maximum of the Gaussians in the function. I'd like to keep this constant during the fit but also change it easily between fits.


Is this possible?

0 Kudos
Message 3 of 8

FWHM for a gaussian is proportional to sigma, so you should be able to specify FWHM as a constraint on sigma.  If you use the constrained nonlinear curve, simply use the same number for both the upper and lower limit (for the sigma parameters) and Lev-Mar will hold these parameters constant throughout the fit.



Message 4 of 8

Are you generating the data or are you merely analyzing some input from some other system?  The FWHM is a function of the input data itself.  If you are generating data, then obviously you can affect this.  I have attached a VI for generating random Gaussian peaks.  I am not certain if this is what you are looking for, but like I said, if you are merely analyzing the peaks, then the data determines the FWHM.



Message 5 of 8

Thanks for the ideas.


Jim, that sounds like it would work! Unfortunately I had a look and couldn't find that vi... I'm using LV 8.2... should I have it, or is there another way?


Matt, cheers, I have different data coming in with different widths. I know what the widths are and want to hold them fixed. If I let LV fit to them, the data is not great (quite noisy) so the 'correct' width isn't chosen which distorts the amplitude, area, etc... which I need. Oh and I couldn't open the attachment, my problem with my old version of LV.



0 Kudos
Message 6 of 8
Accepted by DJ Ham

Unfortunately the constrained version was added in LabVIEW 8.5.  You could use the "data" variant to pass the constrained sigma value to the model, and fit the location and amplitude values. This means your initial guess input to Lev-Mar should not include the sigma values.  Wire the fixed sigma value to the "data" input.  Then in your model function take the data input (variant type), cast it to a double precision value, and insert into the appropriate locations in your model formula.



Message 7 of 8

Thanks Jim, you found the solution! I appreciate it.

0 Kudos
Message 8 of 8