Multiple auto-generated lorentzian/gaussian peak Fit

Fits n peaks with symmetric/asymmetric lorentzian/gaussian line shapes. Output yields fit coefficients, erros and every single contribution.
146 Downloads
Aktualisiert 19. Jan 2024

Lizenz anzeigen

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;
...
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
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.
  • xLength = any positive integer, length of x-array for fit evaluation via feval. default: 1E4.
  • xEvalBound = [xFitMin, xFitMax], bounds of x-array for fit evaluation via feval, can be used for interpolation. default: [min(x_data), max(x_data)]
  • CoeffFix = [CoeffIndx #1, CoeffIndx #2, ... , CoeffIndx #n; FixVal #1, FixVal #2, ... , FixVal #n], 2-by-n matrix to Fix any number n of coeficients. 1 row contains the respective coefficient indices and the second row contains the Fix values for the coefficient, respectively.
As output this function automatically reate a file named e.g. "fit_contrib_startpoints_0001.txt" if "startpoints_0001.txt" was used. It 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.
For further clarification, see example.

Zitieren als

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. Abgerufen .

Kompatibilität der MATLAB-Version
Erstellt mit R2023b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Veröffentlicht Versionshinweise
1.0.2

nimor bug fixes & description changes

1.0.1

description changes

1.0.0