All-At-Once Fitting Functions
awirsing
I have experimental data that look either like this:
•make/o yw1=gauss(x,20,3)-gauss(x,95,4);integrate yw1;yw1+=gnoise(0.01)-1
or like this:
•make/o yw2=-gauss(x,20,3)+gauss(x,95,4);integrate yw2;yw2+=gnoise(0.01)+1
depending on the detector used.
Both data sets can be easily fitted with the following fitting function:
function square_gauss_conv1(pw,yw,xw) : FitFunc
wave pw, yw, xw
// W_coef[0] = gaussian position1, W_coef[1] = FWHM1
// W_coef[2] = gaussian position2, W_coef[3] = FWHM2
// W_coef[4] = baseline, W_coef[5] = amplitude
yw=sign(pw[2]-pw[0])*gauss(xw,pw[0],pw[1])-sign(pw[2]-pw[0])*gauss(xw,pw[2],pw[3])
Integrate yw
yw=pw[4]+pw[5]*yw
end
wave pw, yw, xw
// W_coef[0] = gaussian position1, W_coef[1] = FWHM1
// W_coef[2] = gaussian position2, W_coef[3] = FWHM2
// W_coef[4] = baseline, W_coef[5] = amplitude
yw=sign(pw[2]-pw[0])*gauss(xw,pw[0],pw[1])-sign(pw[2]-pw[0])*gauss(xw,pw[2],pw[3])
Integrate yw
yw=pw[4]+pw[5]*yw
end
using the command:
•FuncFit/NTHR=0 square_gauss_conv1 W_coef yw1 /D
and supplying appropriate fitting coefficients in W_coef.
I could make data acquisition much faster if I would not measure between the rising and the falling edge. In that case I'd need an xwave:
•make/o yw1=gauss(x,20,3)-gauss(x,95,4);integrate yw1;yw1+=gnoise(0.01)-1
•duplicate yw1 xw1; xw1=x
•DeletePoints 38,38, yw1,xw1
and the fitting command:
•FuncFit/NTHR=0 square_gauss_conv1 W_coef yw1 /X=xw1 /D
Unfortunately this does not work any longer. The amplitude parameter is not correct evaluated.
Can anybody give me a hint on this. I don't know what I am doing wrong.
integrate
operation. It says in Igor help that the X scaling of each wave is taken into account. In the fit function integrate uses the default scaling of yw, thus ignoring xw. However, you can specify a corresponding xw in integrate by using the /X flag. I presume this would work, but one is making the assumption that the fit function is linear in the 'deleted' region.March 23, 2009 at 07:50 pm - Permalink
A simple substitution of
Integrate yw
byIntegrate yw /X=xw
does not solve the problem. It gives the error While executing Integrate, the following error occurred: X data does not match Y data (length or number type). independent of fitting the a ywave with internal x scaling or supplying an additional xwave.March 24, 2009 at 01:47 am - Permalink
If you are getting a length mismatch error you could use the debugger to check that waves of equal length are being supplied to integrate.
March 24, 2009 at 03:12 am - Permalink
It was an error of the
Integrate
operation. Adding the/X
flag was successful in the end. I had to switch to trapezoidal integration (/METH=1
flag), because only this method seems to support an xwave.Another strange thing remains:
If I apply appropriate parameters by entering values in the Coefficient tab of the Curve Fitting dialog and want to test them by pressing the Graph Now button, I get the same error as mentioned above: While executing Integrate, the following error occurred: X data does not match Y data (length or number type). Fitting itself works without any error.
March 24, 2009 at 02:39 pm - Permalink
You are creating an X wave with the same number of points as the Y wave.
Also note that you aren't guaranteed to get your actual data when your fitting function is called. Especially when FuncFit is filling the 200-point wave for the /D flag, or when you use the Graph Now button, you get input to your fitting function whose only relationship to your data is that it has the same starting and ending X values. It fills in 200 equally-spaced X values between.
This is why all-at-once functions aren't the default format :)
If you would like some assistance with this, you could e-mail an Igor experiment file with data and fitting function to support@wavemetrics.com.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
March 24, 2009 at 09:53 am - Permalink