![]() |
![]() |
|
PLS_Toolbox Documentation: fitpeaks | < fir2ss | frpcr > |
fitpeaks
Purpose
Peak fitting routine.
Synopsis
[peakdefo,fval,exitflag,out,fit,res] = fitpeaks(peakdef,y,ax,options)
Description
Based on the initial guess in input peakdef, FITPEAKS estimates the peak fit (also the Jacobian and Hessian), and makes a call to LMOPTIMIZEBND to find the best fit of the peaks to the data. (See LMOPTIMIZEBND for additional information.) Results are output to peakdefo.
Information about individual peaks is stored in standard peak
structures (see PEAKSTRUCT).
Information on multiple peaks is stored in a multi-record structure. Given a
standard peak structure (peakdef)
that contains an initial guess of peak locations and widths, FITPEAKS finds new
parameters that best fits peaks to the rows of the data matrix (y). Results are output to a
standard peak structure (peakdefo).
Fields of (peakdef) required in the initial guess for each peak are (.fun), (.param), (.lb), (.penlb), (.ub), and (.penub).
INPUTS:
OPTIONAL INPUTS:
OUTPUTS:
Algorithm
Peaks are fit to the functions defined below based on the definitions in the field (peakdef.fun). The functions can be evaluated using independent functions or a wrapper function PEAKFUNCTION. See PEAKFUNCTION for more help.
For peakdef.fun = 'Gaussian' the function is
where is the
element of optional
input (ax), and
corresponds to
the peak parameters in the three-element vector (peakdef.param). Constraints that should be used are
(bounds in peakdef)
are
and
.
For peakdef.fun = 'Lorentzian' the function is
.
Constraints that should be used are (bounds in peakdef) are and
.
For peakdef.fun = 'PVoigt1' the function is
where corresponds to the peak parameters
in the four-element vector (peakdef.param).
Constraints that should be used are (bounds in peakdef) are
and
, while
. The Pseudo-Voigt peak
shape is an estimate of the Gaussian and Lorentzian peak shapes convolved.
For peakdef.fun = 'PVoigt2' the function is
where corresponds to the peak parameters
in the four-element vector (peakdef.param).
Constraints that should be used (bounds in peakdef) are
and
, while
. The Pseudo-Voigt peak
shape is an estimate of the Gaussian and Lorentzian peak shapes convolved.
A comparison of the four peaks is given in the figure below, and was generated using the following code:
ax = 0:0.1:100;
y = zeros(4,length(ax));
plot(ax,peakgaussian([2 51 8],ax),'-b', ...
ax,peaklorentzian([2 51 8],ax),'--k', ...
ax,peakpvoigt1([2 51 8 0.5],ax),':g', ...
ax,peakpvoigt2([2 51 8 0.5],ax),'-.r')
legend('Gaussian','Lorentzian','PVoigt1','PVoigt2')
Options
Examples
%Make a single known peak
ax = 0:0.1:100;
y = peakgaussian([2 51 8],ax);
%Define first estimate and peak type
peakdef = peakstruct;
peakdef.param = [0.1 43 5]; %coef, position, spread
peakdef.lb = [0 0 0.0001]; %lower bounds on param
peakdef.penlb = [1e-6 1e-6 1e-6];
peakdef.ub = [10 99.9 40]; %upper bounds on params
peakdef.penub = [1e-6 1e-6 1e-6];
%Estimate fit and plot
yint = peakfunction(peakdef,ax);
[peakdef,fval,exitflag,out] = fitpeaks(peakdef,y,ax);
yfit = peakfunction(peakdef,ax); figure
plot(ax,yint,'m',ax,y,'b',ax,yfit,'r--')
legend('Initial','Actual','Fit')
See Also
< fir2ss | frpcr > |