Help wth linear combination analysis
LJ0630
I have a spectrum (Stot) that's a linear combination of two known spectra (Sa and Sb). I would like to fit Stot , Stot = kSa + (1-k)Sb, and extract k and 1-k for Sa and Sb respectively from this fit. Need help!
Thanks in advance for the help
LJ
variable x
wave Sa=root:Sa //that is the wave where you have Sa
return Sa(x)
end
same thing for Sb.
And then you use them to define your fit function. You can use "new fit function" and it will generate the following code in your procedure window:
Wave w
Variable x
//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(x) = k*Sa(x)+(1-k)*Sb(x)
//CurveFitDialog/ End of Equation
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ x
//CurveFitDialog/ Coefficients 1
//CurveFitDialog/ w[0] = k
return w[0]*Sa_function(x)+(1-w[0])*Sb_function(x)
End
You have only one fit parameter (w[0]).
That should do it.
Julien
August 29, 2017 at 07:59 am - Permalink
August 29, 2017 at 11:02 am - Permalink
Please enclose the code between igor code tags so it displays correctly. These are "igor" and "/igor" surrounded by <>.
August 29, 2017 at 12:59 pm - Permalink
variable x
wave Sa=root:Sa
return Sa(x)
end
function Sb_function(x)
variable x
wave Sb=root:Sb
return Sb(x)
end
Function LinearCombo(w,x) : FitFunc
Wave w
Variable x
//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(x) = k*Sa(x)+(1-k)*Sb(x)
//CurveFitDialog/
//CurveFitDialog/ End of Equation
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ x
//CurveFitDialog/ Coefficients 1
//CurveFitDialog/ w[0] = k
return w[0]*Sa(x)+(1-w[0])*Sb(x)
End
August 29, 2017 at 01:19 pm - Permalink
These are not the names of the defined functions.
You should have:
Sa and Sb are the waves' names, not the functions' names.
August 29, 2017 at 02:18 pm - Permalink
August 30, 2017 at 07:02 am - Permalink
If your wave giving the x axis is monotonic (I suspect it is since you talk about wavelength) you might succeed using the following to define your functions
variable x
wave Sa=root:Sa
wave Sa_xwave=root:Sa_xwave //this is the wave where you store the x-scaling
Findlevel Sa_xwave, x
return Sa(V_levelX)
end
That said, I would strongly suggest that you resample your data using interpolation, in order to have evenly spaced data points. That is what I usually do to deal with nm/eV.
That will make things much easier.
August 30, 2017 at 07:52 am - Permalink
WAVE Sa_X, Sa
Variable pointWithFraction = BinarySearchInterp(Sa_X, xx)
return Sa[pointWithFraction]
end
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
August 30, 2017 at 09:04 am - Permalink
September 1, 2017 at 12:21 pm - Permalink
Also, I have Stot at a series of time points. Is there a way to fit more than one spectrum at a time?
September 1, 2017 at 12:30 pm - Permalink
As far as fitting lots of data sets, check out the Batch Curve Fitting package. Start with the demo: File->Example Experiments->Curve Fitting->Batch Curve Fitting Demo.
If you mean that you wish to do a single fit that includes many data sets, then you need the Global Fit package. File->Example Experiments->Curve Fitting->Global Fit Demo.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
September 1, 2017 at 03:26 pm - Permalink