Gaussian Fitting with an Exponential Background
This example fits two poorly resolved Gaussian peaks on a decaying exponential background using a general (nonlinear) custom model.
Fit the data using this equation
where ai are the peak amplitudes, bi are the peak centroids, and ci are related to the peak widths. Because unknown coefficients are part of the exponential function arguments, the equation is nonlinear.
Load the data and open the Curve Fitting app:
load gauss3 cftool
The workspace contains two new variables:
xpeakis a vector of predictor values.
ypeakis a vector of response values.
In the Curve Fitting app, select
xpeakfor X data and
ypeakfor Y data.
Gauss2exp1for the Fit name.
Custom Equationfor the model type.
Replace the example text in the equation edit box with these terms:
The fit is poor (or incomplete) at this point because the starting points are randomly selected and no coefficients have bounds.
Specify reasonable coefficient starting points and constraints. Deducing the starting points is particularly easy for the current model because the Gaussian coefficients have a straightforward interpretation and the exponential background is well defined. Additionally, as the peak amplitudes and widths cannot be negative, constrain a1, a2, c1, and c2 to be greater than 0.
Click Fit Options.
Change the Lower bound for a1, a2, c1, and c2 to
0, as the peak amplitudes and widths cannot be negative.
Enter start points as shown for the unknown coefficients.
Unknowns Start Point
As you change fit options, the Curve Fitting app refits. Press Enter or close the Fit Options dialog box to ensure your last change is applied to the fit.
Following are the fit and residuals.