Setting up waves for batch MPF2 Process and ExpModGauss Help
n.black
So I've been happily using BatchCurveFit to do my data fitting by cutting up my spectra into manageable chunks and running it a few times for every peak. I've enjoyed being able to extract the peak parameters to use later and am confident in my successful peak fits because I can flick through the interface and see my fits as I go. But now I have some peaks that are slightly convoluted and I can't really avoid using MultiPeakFit. Unless there is a way to incorporate the ExpModGauss function to the Batch Curve Fit AND extract key parameters
So I'm trying to read through the help topic MultiPeakFitting for Igor Programmers and I'm trying to follow the Function MultiPeakBatchFit(datafolderName, ywavelist, xwavelist) procedure and need a little help with understanding the process and the implementation.
So Assuming all the ywaves are similar enough that fitting an initial test to get your starting coefficents is the plan:
Q1) Does the datafolder name need to be the full path in the MultiPeakFit2 data folder.
Q2) Is there a way to use a 2Dmatrix where every column is a spectrum of peaks without making a) a list of 1D ywaves and b) be able to call it successfully? I think there is a way to do this using a freewave but i'm sure how to do it because at the same time you need stringlist that can be used to find that find the correct column in the matrix.
Q3) can you instead of having a single xwave?
I initially wanted to test this function first but I am dealing with a lot of waves and this can get messy and if possible I'd like to keep everything in the 2Dmatrix.
So for the ExpModGauss peak I found fitted my test spectrum great.
But to extract the parameters like x0 position, amplitude, area and FWHM is a little complicated.
I have found that my Spectra fit nicely a Gauss and two ExpModGauss very nicely. I've been reading that MPF2 works well with peak fitting the same type of peak function multiple times but not so good at doing multiple. Surely if your initial guesses are close enough then it shouldn't matter that they are different?
Thanks for any help you can give!
Best wishes,
N
However, you can use ExpModGauss in your own fitting function. The functions that define the MPF2 peak shapes are in PeakFunctions2.ipf. The function used by MPF2 is defined in an XOP; it is called MPFXEMGPeak(). That function fits the Gauss location width and height and the exponential decay constant. There are functions in PeakFunctions2.ipf; the function GaussConvExpPeakParams() shows how the derived parameters are computed. The real amplitude and FWHM can't be found analytically, so GaussConvExpFindAmpLoc() and GaussConvExpFWHM() use numerical methods to get those values. The area depends on both.
You would write a fitting function that fits a sum of a Gaussian and two ExpModGauss peaks. You can then run that through BatchCurveFit to get the basic parameters. You will then have to post-process those results to get area and FWHM.
I think that's easier than trying to understand and modify MultiPeakBatchFit() or MPF2_AutoMPFit() to suit what you want to do.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
July 13, 2016 at 05:36 pm - Permalink
For one of my projects, I did dig into MultiPeakBatchFit() and modified it for my purposes. I was fitting a ExpModGauss + Gauss + my own customized Voigt peak, so this was worthwhile. I've attached an ipf with my code in case it's useful to you. First you use the MultiPeakFitting GUI to get a good fit on a representative data set, then save a checkpoint. My approach was to add all the 1D traces to a graph, then grab the trace list and loop through that using the peak fitting setup and guesses from the checkpoint data folder. You could modify it to instead take a 2D wave, and loop through each column by assigning each column to a working wave. I also implemented functionality to include constraints if necessary. No guarantees it'll be bug free for your application! In its current implementation, my procedure doesn't work with x waves but instead relies on the y-wave having proper scaling (start and delta values).
July 13, 2016 at 06:06 pm - Permalink
I'm looking through your code aljeenheer and it looks very comprehensive.
I still need a little bit of time to get my head around it but thanks both for your help!
To clarify, in your code you select a data folder with all your ywaves in it. How do you get the xwavelist? (i've only skimmed the code but i couldn't see how this was found) Are your ywaves already scaled to xwaves?
Finally could you recommend a helptopic for assigning a column to a working wave?
Thanks for your help!
Best,
N
July 18, 2016 at 01:25 am - Permalink
No, in my code, I select the data folder that contains the best fit obtained using the multi-peak fit GUI. The list of y waves is obtained from the top graph in my procedure. I don't use a xwavelist at all; in fact, I removed that functionality from the procedure to simplify things. Yes, my ywaves are already scaled to xwaves; this seemed like the simpler approach. The downside is that the x-scaling has to be uniform.
To assign a column to a working wave, use the [p][q] point assignment functionality. Below is an example. DisplayHelpTopic "Waveform Arithmetic and Assignment"
//First just create a 2D wave for demo purposes
make/O/N=(30,50) TwoDWave
TwoDWave=gnoise(1)
NewImage TwoDWave
//Grab a column from the 2D wave and put it in the "WorkingWave"
make/O/N=(DimSize(TwoDWave,1)) WorkingWave
WorkingWave=TwoDWave[10][p] //Column 10 for example
Display WorkingWave
end
July 18, 2016 at 10:00 am - Permalink