Using baseline with CurveFit and FuncFit
raponzoni
I have to fit several graphs and used to do it by MultipeakFit 2.0, where I always use the linear baseline during fitting.
However, since I have loads of data, I created a procedure to do batch fitting for me and it is working fine apart from the baseline.
I am fitting gaussian functions, and I realised that CurveFit and FuncFit use a constant baseline (called as offset) between the points I am fitting. Is there any way to set linear baseline instead of constant?
Here is part of the code, where the fitting is:
Make /O/N=4 root:Fitting_Results_717:W_coef //Creating the suggestion parameters for fitting
Wave W_coef=W_coef
W_coef[0]=0 //offset
W_coef[1]=13.2 // peak height
W_coef[2]=716.32 // centre
W_coef[3]=10.05 //width
CurveFit /Q/W=2 gauss kwCWave=W_coef wSpectrum[StartP,EndP] /X=wWavenumber //StartP and EndP are the range points for fitting
Wave W_coef=W_coef
W_coef[0]=0 //offset
W_coef[1]=13.2 // peak height
W_coef[2]=716.32 // centre
W_coef[3]=10.05 //width
CurveFit /Q/W=2 gauss kwCWave=W_coef wSpectrum[StartP,EndP] /X=wWavenumber //StartP and EndP are the range points for fitting
Thanks in advance for suggestions!
1) Write a user-defined fit function that implements the sum of a linear baseline and a Gaussian peak.
2) Use the Sum-of-Fit-Functions feature: DisplayHelpTopic "Fitting Sums of Fit Functions".
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
February 5, 2015 at 09:45 am - Permalink
I think suggestion 1 seems to be better, since I will be using the linear baseline during the fitting, which would be closer to what I can do using Multipeak Fitting 2.0. Correct me if I'm wrong.
I was reading about user-defined fit-functions in the manual, but didn't come across mix of different functions (linear and gaussian) in the fitting. Do you have any reading suggestions?
Cheers
February 6, 2015 at 02:40 am - Permalink
Wave w
Variable xx
//CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
//CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
//CurveFitDialog/ Equation:
//CurveFitDialog/ f(xx) = a + b*xx + Amp*exp(-((xx-x0)/width)^2)
//CurveFitDialog/ End of Equation
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ xx
//CurveFitDialog/ Coefficients 5
//CurveFitDialog/ w[0] = a
//CurveFitDialog/ w[1] = b
//CurveFitDialog/ w[2] = Amp
//CurveFitDialog/ w[3] = x0
//CurveFitDialog/ w[4] = width
return w[0] + w[1]*xx + w[2]*exp(-((xx-w[3])/w[4])^2)
End
Both methods fit both the baseline and the peak shape together at the same time. The sum-of-fit-functions technique is simply a way to have Igor do the combining of the functions instead of making you write it. In fact, Multipeak Fit 2 uses the sum-of-fit-functions technique, constructing a command string with a one element for the baseline, and one element for each peak function, one per peak.
For your case, you could write a FuncFit command that uses a sum of the built-in line function and the built-in Gauss function. That would save you the trouble of writing the combined user-defined fit function, but at the expense of coming up with a moderately complicated FuncFit command.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
February 6, 2015 at 10:18 am - Permalink
One more doubt, is it possible to return the chi square of the fittings? In this case, would it be one for each one of the waves fitted?
Cheers
February 10, 2015 at 03:14 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
February 10, 2015 at 09:26 am - Permalink