I am wondering how to implement the multi-peak detecting and fitting in Mathematica. Following is an example of fitting the data using three peaks (such that the data ~ peak1 + peak2 + peak3).
The peak model is given and fixed (all peaks are fitted by the same model), but its particular form (which will be input) can be Gaussian or Lorentzian or some other customized functions. The number of peaks is unknown and should be detected automatically, and the fitting model must also be built accordingly. Is there a Mathematica function that can simply do this? Or if anyone can give an idea of how to do the multi-peak fitting using Mathematica.
(I am aware of fitting functions like FindFit
,NonlinearModelFit
etc., so my question is more about how to build the model and estimate the initial parameters for input of the fitting functions.)
I am expecting something like this:
PeakFit[data_, pfun_, x_]:=...
where the data
is a list of points like {{x1_,y1_}..}
, x_
specifies the variable to be used, and the peak function pfun
is a pure function whose first three parameters control the peak height, the peak width, and the central position, and the remaining (optional) parameters are for further control of the shape of the peak. For example a Gaussian model may be described as
pfun = Function[{x}, #1 Exp[-(x - #3)^2/(2 #2^2)]] &;
Given the data and the peak function, I wish PeakFit
to return a FittedModel
object containing the resulting model like pfun[A_,w_,xc_][x]+...
.