Multiple auto-generated lorentzian/gaussian peak Fit
版本 2.0.0 (64.6 KB) 作者:
Jona Grümbel
Fits n peaks with symmetric/asymmetric lorentzian/gaussian line shapes. Output yields fit coefficients, erros and every single contribution.
varargout = multiPeakFit(M_data, nPeak, StartPointNo, Options)
This fit function uses the standard Matlab fit function provided by the curve fitting toolbox to perform a regression over data containing multiple lorentzian and/or gaussian shaped peaks by a single model function. This can be very useful for data evaluation in e.g. optical spectroscopy. There are several useful and powerful tools included in this function. The main function 'multiPeakFit.m' executes the fit to a given dataset. The two other functions are required ressources to run 'multiPeakFit.m'.
For itself, the 'multiPeak_build_LorGau_ABF.m' function is a powerful tool that creates any number of the following specified peak line shapes:
- asymmetric lorentzian:
- symmetric lorentzian:
- asymmetric gaussian: , where
- symmetric gaussian:
Any other line shape requires a complex implementation, but in general is possible. The implemented line shape functions are normalized, so that A is the peak amplitude, γ the peak FWHM, and the peak position. For asymmetric line shapes, it uses the generalized definition provided in a paper from Stancik et. al. (https://doi.org/10.1016/j.vibspec.2008.02.009), where γ is replaced by with the additional asymmetry parameter as follows:
The 'Fdbl.m' function is required to check, if a coefficient is fixed or not, means if it is a symbolic variable containing only numeric or numeric and alphabetic characters.
To run this function, one requires a directory named startpoints, containing .txt or .ascii files named 'startpoint_0001.txt' and so on. If you enter the correct directory in the source code of 'multiPeakFit.m', the function automatically loads the startpoint file. It is required to have either 1 or 3 column, where 1 olumn contains only startpoints for all parameters like
0.2;
1;
250;
10;
...
and 3 columns contain lower and upper bounds and startpoints like
0, 1, 0.2;
0, 10, 1;
200, 300, 250;
0, 100, 10;
...
Alternatively, you enter the startpoints directly as numeric array into StartPointNo function input.
The 'multiPeakFit.m' function has the following required input parameters:
- M_data = [x_data, y_data] is the n-by-2 matrix containing the data to fit.
- nPeak = [# asym. lorentz, # sym. lorentz, # asym. gauss, # sym. gauss] is a 4 element array containing each individual number of peaks with the respective line shape to fit.
- StartPointNo is the suffix number of the startpoint file or an array containing the startpoints for the fit
Additionally, you can inout custumized values for the following optional settings:
- BGType = Type of spectral background ('Const', 'Lin', 'Laser'). default: 'Const'.
- LaserParam = [nL, xL], specific Laser background params. default: [2, 0].
- OutName = 'String', for usage of the same startpoint for multiple fit with different fit_contrib output files. default = "".
- ConfAlpha = 0...1, Fitting error confidence bounds. default: 0.995.
- xEval = [xFitMin, xFitMax, lFit], bounds of x-array for fit evaluation via feval, which can be used for interpolation, and array size lFit. default: [0,0,1E4], which means an x-array from within [min(x_data), max(x_data)] and 1E4 points.
- CoeffFix = [CoeffIndx #1, CoeffIndx #2, ... , CoeffIndx #n], 1-by-n array to Fix any number n of coeficients. It contains the respective coefficient indices which are then fixed to the value given by the startpoint file or array.
- SUbst_nPeak = nPeak for the substrate model. One may includes a substrate model by entering the correct number of peaks of the substrate and the respective (fixed!) parameters in the next option. default: []
- Subst_Params = [Param #1, ..., Param #n] Here you enter all parameters for the substrate model. Fit parameters for the substrate model are a total amplitude AS applied to all peaks equally and an x-axis shift dx. default: []
- FilterEdge = ['on'/'off'] enables the inclusion of a filteredge function F(x) = 1/(1 + exp((x-xFilter)/width)), which is multiplied with the whole fit function (including background and substrate). Therefore, it has not only Position and width as parameters, but also an additional y0 parameter for the background in the filter blocking spectral region. In total there are 3 additional fit parameters for this option. default: 'off'
As output this function automatically creates a file named e.g. "fit_contrib_startpoints_0001.txt" if "startpoints_0001.txt" was used. It generates no output if the startpoints are enetered directly into StartPointNo function input. The output file contains the x_fit array and the total fit result as well as every single contribution by every peak individually, including the background contribution.
The main output can have 1 to 5 elements, wihich are siwtched automatically by nargout. For different numbers of output elements one gets (original code lines):
case 1
varargout = {Mfit}; % Mfit = [x_fit, y_fitTotal, y_fitcontr_1, ...., y_fitcontr_n, y_fitBG]
case 2
varargout = {Mfit; fitCo}; % fitCo = ordered fit coefficients (1st rwo: BG coeffs, (n+1)th row: nth peak coeffficient).
case 3
varargout = {Mfit; fitCo; fitCE}; % fitCE = [Coeff_1; Error_1; Coeff_2; Error_2; ... ; Coeff_n; Error_n].
case 4
varargout = {Mfit; fitCo; fitCE; r}; % r = adjusted correlation coefficient.
The Mfit matrix contains the total fit results and every single contribution decomposed, whic may be used for a comparative plot.
For further clarification, see example.
引用格式
Jona Grümbel (2024). Multiple auto-generated lorentzian/gaussian peak Fit (https://www.mathworks.com/matlabcentral/fileexchange/157871-multiple-auto-generated-lorentzian-gaussian-peak-fit), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2023b
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
2.0.0 | Major imporvements for better handling, more robust execution, and additional options:
|
|
|
1.0.2 | nimor bug fixes & description changes |
|
|
1.0.1 | description changes |
|
|
1.0.0 |