TwoPeakGaussianFit
Hello all,
I was just wondering is there any scope to do a Gaussian fit to the 2 or 3 peaks that correspond to the highest peak values among all the peaks in a waveform and extract the fit values?
Let me clear it a little bit.
My fit function is like y=A+Bx+C*exp^-((x-x0)/w)^2 and I want to fit it to the 2 or 3 highest peaks in the waveform.
Notice that I need to do it for hundreds of waveforms that reside in a single wave and extract the fit values, so I understand I need to use a loop to go through all the waveforms.
I found one scope in Igor which is for multipeak fitting and good for just one fit at once but don't think that would be conevenient to use as a loop that will read hundreds of waveforms in a single wave.
In the attached experiment, CutDFrmRealWF (y value), CutTimFrmRealT (x value) are examples of a single waveform and they are one cut from RealWaveForms and RealWavTime waves which contain hundreds of them. I want to do the fit for 2/3 highest peaks in the CutDFrmRealWF vs CutTimFrmRealT plot and iterate it for for all waveforms residing RealWaveForms and RealWavTime waves and extract the fit values.
I guess the alogorithm should be like look for all peaks in each waveform and then fit to the highest 2 or 3 peaks (whatever I choose the number) and then use a loop to do it for all waveforms. Or, is there any simple way to do it?
Thanks everybody,
Ann
Hi Ann,
I would suggest you start with the MultipeakFit functionality.
Go to analysis>packages>Multipeak Fitting> Multipeak Fitting 2 as starting point to make sure you getting what you want. You can then extend that analysis with batch fitting. I would get all the peaks for the curves and then sort out the ones you want as post process.
Look to this post for a bit more discussion https://www.wavemetrics.com/forum/general/batch-automatically-find-peaks
Andy
August 1, 2020 at 02:42 pm - Permalink
Hi Andy,
Thank you very much for your suggestion.
Actually I have thousands of files and need to do it for all files to extract the fit values. At first, I am trying to do it for a single file and then I will loop through all files, but that is my next step.
I guess batch fitting won't be a good choice in this case because I need to automate the process. So I think at first I need to know the peak positions and peak values and then do my desired fits to 2 maximum peaks among them. I am trying to use automatically peak finds procedure to spot the peak and then write down a procedure that will use the peak information to do my fits to all waveforms through a loop. So for each waveform, I need to call the auto peak find function first, then pass the information from it to the function used for Gauss fit. I am looking at it but not sure how to make it work.
Ann
August 1, 2020 at 05:50 pm - Permalink
I don't fully get what you want to extract from the fit:
a) Do you want to fit the 2-3 highest peaks relatively independently, then just get out their position, width or height value? In other words, you do not care about the rest of the data?
Or b) do you want to describe your CutDFrmRealWF data fully with a fit and then take the values from the 2-3 highest peaks after the fact?
If a) then I think you do not need do go with Multipeak Fitting. You could use the Auto-locate Peaks function included in the Multipeak Fit package to get a list of peaks in your data, then pick out the highest ones to do 2-3 individual CurveFits per set in the limited region around your peaks of interest. You could even write you own code which looks for peaks in the derivative, instead of using Auto-locate Peaks, since it seems you data is pretty free of noise. This can be looped pretty easily, but you need to define checks to make sure the algorithm does not screw up.
If b), like proposed by Andy, you can use the automated version of Multipeak Fitting. If you have loaded the package, open the help file and look for the chapter about MPF2_AutoMPFit() under Multipeak Fitting for Igor Programmers. There you can choose to run the auto-locate peaks function before doing the fit by using InitialGuessOptions=5. Then you just grab the results for each data set. This can be 100% automated if all your data looks like the example and there are no difficult hiccups (strongly increasing noise, breaks in the data, spikes etc.).
August 1, 2020 at 11:49 pm - Permalink
Hi Chozo,
Thank you very much for your guidelines.
Yes, you are right.
I am trying to do what you have mentioned in (a). I need to know the peak center positions and corresponding Y values of all the peaks in a waveform and then use the 2nd highest (or, whatever I like, 1st, 3rd, etc) peak position and corresponding Y values to do a Gaussian fit to the same 2nd highest peak in the same waveform and then extract the peak amplitude and other fit values of the fit. I will need to do it again and again when I will go through all the data files but that is my next step.
I wanted to make sure that the auto peak find algorithm (which I have adopted from the multi-peak fitting package and modified it to my use) works fine for all the waveforms residing in a wave. Unfortunately, it works fine for most of the waveforms but does not work for some waveforms (for example, for waveform 57 if you insert 56 in the prompt window) which screwed up the whole algorithm. I think it might be a bug that is responsible for it.
If you have any suggestions, I will appreciate that a lot.
Thanks,
Ann
August 2, 2020 at 03:06 pm - Permalink
Hi Ann,
depending on where want to go with this, you might be better off writing your own peak finder instead of relying on the Autopeak Finder, which has to cover a much wider scope and thus cannot pinpoint your use case as well. It is not that difficult: Just look in the (smoothed) first and second derivative of your data for zero crossings and the maxima (minima). First, you data looks more like its a sum of sine waves than a spectrum with distinct peaks, so I do not know exactly what you are after. But examining your example I found that the Autopeak Finder might have difficulties estimating the right smoothing factor and noise level. This is a limitation from not being able to assume anything from your data and just running some statistics on it. Since you are knowledgeable about your data, you could do better as mentioned above. I just hard-coded some values for the noise (=0) and smoothing (=10) in your AutomaticallyFindPeaks() function like this:
AutoFindPeaksWorker(w, wx, pBegin, pEnd, maxPeaks, minPeakPercent, 0, 10)
I think this works more or less. At least it seems to find all structures I would consider to be a peak in your data. You can play around with this more and see what works best for you. Hope that helps.
August 2, 2020 at 07:03 pm - Permalink