Batch Fitting

Dear all

This is my first post in this forum, however, I've been following it for while and solved a few problems just using the search.

I have to fit a lot of waves using the option Multipeak Fitting 2, sometimes it is more than 100 waves, sometimes are 1000 waves and it takes a lot of time do fit one by one (trust me.. I had to do that..). Now I have another 1000 to fit and I am pretty decided to develop a procedure to help me with that.

I know, there is a lot of results if I search for Batch Fitting but I think my case is a little bit different than the others. Let me try to give more details about it:

-The Y waves are always named as Spec-N, where N is a number that sometimes reach 1000.
-I have an unique X wave, used with all Y waves, and is always named as Xaxis.
-I always have to fit just one peak, between 1060 and 1100 on X axis.
-That only peak, is always fitted with a Lorentizian using linear baseline.

In some posts of batch fitting, people always suggest the example cited in:

DisplayHelpTopic "MPF2_DoMPFit()"

where you have to fit just one wave manually, and the procedure will use the same settings to fit the rest of them.
When I try that procedure I always have this error:

Error calling MPF2_DoMPFit:-5

I don't know what this error means, but maybe this procedure was written to work with the same amount of waves in ywavelist and xwavelist. That's my best hunch, but I am not sure.

After so many words, if anyone have some tips to share, please do!

I don't know how the results will be presented in the end, but I was expecting the fitting results (Position, Amplitude, Area, FWHM and those Sigmas) in a table.

Thanks for reading so far.


Andre
What you want to do is an intermediate to advanced programming task...

Instead of using MPF2_DoMPFit(), use MPF2_AutoMPFit(). It is all ready to do your batch multipeak fit!
Quote:
Error calling MPF2_DoMPFit:-5

I don't know what this error means, but maybe this procedure was written to work with the same amount of waves in ywavelist and xwavelist. That's my best hunch, but I am not sure.

If you look at the constant definitions above MPF2_AutoMPFit() in Multi-peak Fitting 2.0.ipf you will find the name of the error, which will give you a better idea of what went wrong. For your case:
Constant MPF2_Err_BadNumberOfFunctions = -5
So something went wrong with your list of peak functions. I don't know what because you didn't post what you tried; my guess is that you forgot that with N peaks you need N+1 functions. The first function is a baseline function, the rest are names of peak shapes. The baseline function might be "None", but it must be included.

MPF2_AutoMPFit() as you have it doesn't compute the "derived" results, it only reports the coefficients that come directly from the fit. If you need derived results (which might include area and FWHM depending on your peak shape) you need to e-mail support@wavemetrics.com and ask for my latest version.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:

Instead of using MPF2_DoMPFit(), use MPF2_AutoMPFit(). It is all ready to do your batch multipeak fit!


Thanks John for your help!

I was reading the help topics for MPF2_AutoMPFit() and I did some fittings, however, looking at the results folder I found LOCATION, FWHM and AREA. Is there any way to have the Height (amplitude) as well?

Another important thing, I need to limit the fitting region between 1060 and 1100 on X axis. Is there any way to do using MPF2_AutoMPFit() ?

Thanks again

Andre
In case you might find it useful, here is a simple example of a procedure to do a 5th order polynomial fit...It assumes you have loaded a group of waves (in this case voltage vs. time), do the fit and then save the waves in a new file in a specific location of your choice.

#pragma rtGlobals=3 // Use modern global access method and strict wave access.

Function BatchFit()
NewPath mypath "C:Users:(username):Desktop:test:"
Variable i
for(i=0; i<100; i+=1) // or any number you would like
String name1, name3, name4, myFileName

sprintf name1, "VT%03d_S1Vx_V", i // This is to put the number (i) in the string, to get the name of the next wave.
sprintf name3, "VT%03d_S1t_ms", i
sprintf name4, "fit%d", i
sprintf myFileName, "VT%03d.itx", i

Wave Vx=$name1
Wave t =$name3

Display Vx vs t
Make/N=50000/D $name4
Wave myfit=$name4
CurveFit/NTHR=0 poly 5, Vx /X=t /D
Wave W_coef
myfit = W_coef[0] + W_coef[1] *t + W_coef[2] *t*t + W_coef[3] *t*t*t + W_coef[4] *t*t*t*t
Save /P=mypath /T/M="\r\n" t,Vx, myfit as myFileName
endfor
End

Hope that helps
andreponzoni wrote:
I was reading the help topics for MPF2_AutoMPFit() and I did some fittings, however, looking at the results folder I found LOCATION, FWHM and AREA. Is there any way to have the Height (amplitude) as well?

For the benefit of others reading this thread: I have sent you, via a tech support incident, a copy of an enhanced version of the Multipeak Fit procedure file that adds the ability to compute the derived results during batch fitting. This new version will be included when we ship Igor Pro 6.35.
Quote:
Another important thing, I need to limit the fitting region between 1060 and 1100 on X axis. Is there any way to do using MPF2_AutoMPFit() ?

No, the only way to accomplish that with MPF2_AutoMPFit() is to create reduced data sets. Probably the best way to do that is with Duplicate/R=(startx, endx) if your data sets are single waves with wave scaling, or Duplicate/R=[startpoint, endpoint] if you have XY pairs.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com