09-14-2011 10:52 AM
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.
Thanks!
Solved! Go to Solution.
09-14-2011 10:55 AM
DJ,
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
09-14-2011 10:58 AM
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?
09-14-2011 11:29 AM
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 fit.vi, 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.
-Jim
09-14-2011 11:32 AM
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.
Matt
09-14-2011 11:45 AM - edited 09-14-2011 11:46 AM
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.
Thanks!
09-14-2011 11:57 AM
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.
-Jim
09-15-2011 06:30 AM
Thanks Jim, you found the solution! I appreciate it.