I acquired experimental data that I wanted to fit. Unfortunately the fit function cannot be analytic (intermediate calculations, etc.). So my fit function is a linear combination of waves, each waves have the same scaling (x start, x end and dimension are the same). I do not see any difficulty with such fit except that I have the feeling that such kind of fit is not in the philosophy of Igor as Igor does a fit with functions. Is anyone can help me?
A fit function like this will fit a sum of two "standard" waves to your data:
Function FitLinearCombo(pw, yw, xw) : FitFunc Wave pw, yw, xw
WAVE standardA WAVE standardB
yw = pw[0]*standardA(xw) + pw[1]*standardB(xw) end
This function requires that your standards be in waves called exactly "standardA" and "standardB". Naturally, you can edit the code to use other names. The waves must have the X scaling set to the appropriate values- the code assumes they have values equally spaced in X and X scaling to reflect that. If the data you are fitting have X values that don't exactly fall on points in the standard waves, Igor will do a linear interpolation between the values in the standards (that's what indexing using round parentheses is about).
The function uses two coefficients, a mixing coefficient for each of the standards. There is no provision for a baseline offset, X offset or dilation. To add more standards than the two I have written the function for, just add more terms like the two in the function above. Increment the index in the pw wave for each term.
Copy the function from here and paste it into your Procedure window. You will find it in the list of fit functions in the Curve Fit dialog.
Thank you for your help. The function seems to work although I do not understand how. I wrote “seems” because I only used 4 waves in the fit function and for the moment this is not enough to fit correctly the data.
If I understood correctly, the name of the function can be changed. The important key word is “FitFunc” which tells Igor to send the function in the fit menu. Is that correct ?
In that menu yw is supposed to be the ordinate to be fitted and xw the corresponding abscissa. The pw is the wave containing the fit coefficients which I have to create. As you suggested, I added waves and changed their name. So the final fit function is something like pw[0]*wave0+pw[1]*wave1+pw[3]*wave3+pw[4]*wave4. How Igor is able to use a least square fit with this kind of fit function? How Igor is able to make the link with the waves? What is the maximal wave number that I can used?
So the final fit function is something like pw[0]*wave0+pw[1]*wave1+pw[3]*wave3+pw[4]*wave4.
In this type of function, the fitting routine is only adjusting the pw[i] coefficients to attempt the fit, not changing anything about the underlying waves "wave0, wave1" etc. Perhaps that's good enough for you, but I can imagine many types of situations that it's not sufficient. For example, you might want to add fitted x offsets using something like pw[0]*wave0(xw-pw[1]). This all depends highly on what your wave0, wave1 look like.
I've found the Multi Peak Fitting package to be very helpful when trying to fit multiple functions to a data set (Analysis menu - Packages - Multipeak Fitting - Multipeak Fitting 2). It's geared mostly towards fitting peaks, but it's not too hard to add your own custom non-peak functions if you need.
Wave pw, yw, xw
WAVE standardA
WAVE standardB
yw = pw[0]*standardA(xw) + pw[1]*standardB(xw)
end
This function requires that your standards be in waves called exactly "standardA" and "standardB". Naturally, you can edit the code to use other names. The waves must have the X scaling set to the appropriate values- the code assumes they have values equally spaced in X and X scaling to reflect that. If the data you are fitting have X values that don't exactly fall on points in the standard waves, Igor will do a linear interpolation between the values in the standards (that's what indexing using round parentheses is about).
The function uses two coefficients, a mixing coefficient for each of the standards. There is no provision for a baseline offset, X offset or dilation. To add more standards than the two I have written the function for, just add more terms like the two in the function above. Increment the index in the pw wave for each term.
Copy the function from here and paste it into your Procedure window. You will find it in the list of fit functions in the Curve Fit dialog.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
June 1, 2016 at 01:07 pm - Permalink
Thank you for your help. The function seems to work although I do not understand how. I wrote “seems” because I only used 4 waves in the fit function and for the moment this is not enough to fit correctly the data.
If I understood correctly, the name of the function can be changed. The important key word is “FitFunc” which tells Igor to send the function in the fit menu. Is that correct ?
In that menu yw is supposed to be the ordinate to be fitted and xw the corresponding abscissa. The pw is the wave containing the fit coefficients which I have to create. As you suggested, I added waves and changed their name. So the final fit function is something like pw[0]*wave0+pw[1]*wave1+pw[3]*wave3+pw[4]*wave4. How Igor is able to use a least square fit with this kind of fit function? How Igor is able to make the link with the waves? What is the maximal wave number that I can used?
Thank you, best regards.
June 2, 2016 at 01:30 pm - Permalink
In this type of function, the fitting routine is only adjusting the pw[i] coefficients to attempt the fit, not changing anything about the underlying waves "wave0, wave1" etc. Perhaps that's good enough for you, but I can imagine many types of situations that it's not sufficient. For example, you might want to add fitted x offsets using something like pw[0]*wave0(xw-pw[1]). This all depends highly on what your wave0, wave1 look like.
I've found the Multi Peak Fitting package to be very helpful when trying to fit multiple functions to a data set (Analysis menu - Packages - Multipeak Fitting - Multipeak Fitting 2). It's geared mostly towards fitting peaks, but it's not too hard to add your own custom non-peak functions if you need.
June 2, 2016 at 02:48 pm - Permalink
HJ
June 2, 2016 at 03:07 pm - Permalink