Admin Production ni-theme
Current Publication

GaussFit

LabWindows/CVI

GaussFit

Advanced Analysis Library Only

AnalysisLibErrType GaussFit (double arrayX[], double arrayY[], double weight[], ssize_t numberOfElements, int fitMethod, double tolerance, double initialCoefficients[], double fittedData[], double *amplitude, double *center, double *standardDeviation, double *residue);

Purpose

Fits the data set (x, y) to the Gaussian model using the Least Square, Least Absolute Residual, or Bisquare method. The following equation represents the Gaussian model:

If fitMethod is LEAST_SQUARE, the function finds the amplitude, center, and standardDeviation of the Gaussian model by minimizing the residue as follows:

where n is numberOfElements
w i is the i-th element of weight
f i is the i-th element of fittedData
y i is the i-th element of arrayY
If fitMethod is LEAST_ABSOLUTE_RESIDUAL, the function finds the amplitude, center, and standardDeviation by minimizing the residue as follows:

If fitMethod is BISQUARE, the function finds the amplitude, center, and standardDeviation by using reweighted least square fitting iteratively, as shown in the following flowchart:

Parameters

Input
Name Type Description
arrayX double [] The x values of the data set (x, y).
arrayY double [] The y values of the data set (x, y). If fittedData is NULL, the best fit array overwrites arrayY.
weight double [] The weight of each data point. If weight is NULL, the function assumes all the weights are 1.
numberOfElements ssize_t The length of arrayX, arrayY, and weight.
fitMethod int The fit method. fitMethod must be one of the following values:
  • LEAST_SQUARE (0)
  • LEAST_ABSOLUTE_RESIDUAL (1)
  • BISQUARE (2)
The Least Square method is preferable if the noise in arrayY is Gaussian distributed. The Least Absolute Residual and Bisquare method are robust fitting methods. Therefore, they are preferable if there are outliers in the observations. In most cases, the Bisquare method is less sensitive to outliers than the Least Absolute Residual method.
tolerance double The stop criteria. The function adjusts the amplitude, center, and standardDeviation iteratively. If the relative difference between residue in two successive iterations is less than tolerance, the function returns the resulting coefficients. If tolerance is less than or equal to 0, the function sets tolerance to 0.0001.
initialCoefficients double [] The initial estimate of the amplitude, center, and standardDeviation. If initialCoefficients is NULL, the function calculates the initial estimate of the coefficients automatically. initialCoefficients must contain the initial guess of the amplitude, center, and standardDeviation in sequence if initialCoefficients is not equal to NULL.
Output
Name Type Description
fittedData double [] The arrayY values calculated using the fitted Gaussian model. If fittedData is NULL, the best fit array overwrites arrayY.
amplitude double The amplitude of the fitted Gaussian model.
center double The center of the fitted Gaussian model.
standardDeviation double The standard deviation of the fitted Gaussian model.
residue double The weighted mean error of the Gaussian fit. If fitMethod is LEAST_ABSOLUTE_RESIDUAL, residue is the weighted mean absolute error, as is shown in the following equation:

If fitMethod is LEAST_SQUARE or BISQUARE, residue is the weighted mean square error, as is shown in the following equation:

Return Value

Name Type Description
status AnalysisLibErrType A value that specifies the type of error that occurred. Refer to analysis.h for definitions of these constants.

Additional Information

Library: Advanced Analysis Library

Include file: analysis.h

LabWindows/CVI compatibility: LabWindows/CVI 8.0 and later