| Description |
[FitResults,MeanFitError]=PEAKFIT(signal,center,window...)
A command-line peak fitting program for time-series signals,
written as a self-contained Matlab function in a single m-file.
Uses an non-linear optimization algorithm to decompose a complex,
overlapping-peak signal into its component parts. The objective
is to determine whether your signal can be represented as the sum of
fundamental underlying peaks shapes. Accepts signals of any length,
including those with non-integer and non-uniform x-values. Fits
Gaussian, equal-width Gaussians, exponentially-broadened Gaussian,
Lorentzian, equal-width Lorentzians, Pearson, Logistic, exponential
pulse, abd sigmoid shapes (expandable to other shapes). This is a command
line version, usable from a remote terminal. It is capable of making
multiple trial fits with sightly different starting values and taking
the one with the lowest mean fit error.
T. C. O'Haver (toh@umd.edu). Version 3.6: February, 2013. Added fixed-position
Gaussian shape (16) and fixed-position Lorentzian shape (17).
Example 1:
>> x=[0:.1:10];y=exp(-(x-5).^2);peakfit([x' y'])
Fits exp(-x)^2 with a single Gaussian peak model.
ans =
1 5 1 1.665 1.7725
Peak number Peak position Height Width Peak area
Example 2:
x=[0:.1:10];y=exp(-(x-5).^2)+.1*randn(1,length(x));peakfit([x' y'])
Like Example 1, except that random noise is added to the y data.
ans =
1 5.0279 0.9272 1.7948 1.7716
Example 3:
x=[0:.1:10];y=exp(-(x-5).^2)+.5*exp(-(x-3).^2)+.1*randn(1,length(x));
peakfit([x' y'],5,19,2,1,0,1)
Fits a noisy two-peak signal with a double Gaussian model (NumPeaks=2).
ans =
1 3.0001 0.49489 1.642 0.86504
2 4.9927 1.0016 1.6597 1.7696
Example 4:
>> x=[0:.005:1];y=humps(x);peakfit([x' y'],.3,.7,1,4,3);
Fits a portion of the humps function, 0.7 units wide and centered on
x=0.3, with a single (NumPeaks=1) Pearson function (peakshape=4)
with extra=3 (controls shape of Pearson function).
Example 5:
>> x=[0:.005:1];y=(humps(x)+humps(x-.13)).^3;smatrix=[x' y'];
>> [FitResults,MeanFitError]=peakfit(smatrix,.4,.7,2,1,0,10)
Creates a data matrix 'smatrix', fits a portion to a two-peak Gaussian
model, takes the best of 10 trials. Returns FitResults and MeanFitError.
FitResults =
1 0.4128 3.1114e+008 0.10448 3.4605e+007
2 0.3161 2.8671e+008 0.098862 3.0174e+007
MeanFitError =
0.68048
Example 6:
>> peakfit([x' y'],.4,.7,2,1,0,10,[.3 .1 .5 .1]);
As above, but specifies the first-guess position and width of the two
peaks, in the order [position1 width1 position2 width2]
Example 7:
[FitResults,LowestError,BestStart,xi,yi]=peakfit(smatrix,.4,.7,2,1,0,10)
As above, returns the vector x1 containing 100 interploated x-values for the model peaks and the matrix y1 containing the y values of each model peak at each xi. Type plot(xi,yi(1,:)) to plot peak 1 or plot(xi,yi) to plot all peaks.
For more details, see
http://terpconnect.umd.edu/~toh/spectrum/CurveFittingC.html and
http://terpconnect.umd.edu/~toh/spectrum/InteractivePeakFitter.htm |