GAUSFIT Gaussian Curve Fit

Section: Optimization and Curve Fitting

Usage

The gausfit routine has the following syntax
  [mu,sigma,dc,gain,yhat] = gausfit(t,y,w,mug,sigmag,dcg,gaing).

where the required inputs are

The following inputs are all optional, and default values are available for each of them. The fit is of the form yhat=gain*exp((t-mu).^2/(2*sigma^2))+dc. The outputs are Because the fit is nonlinear, a good initial guess is critical to convergence of the solution. Thus, you can supply initial guesses for each of the parameters using the mug, sigmag, dcg, gaing arguments. Any arguments not supplied are estimated using a simple algorithm. In particular, the DC value is estimated by taking the minimum value from the vector y. The gain is estimated from the range of y. The mean and standard deviation are estimated using the first and second order moments of y. This function uses fitfun.

Example

Suppose we want to fit a cycle of a cosine using a Gaussian shape.
--> t = linspace(-pi,pi); 
--> y = cos(t);
--> [mu,sigma,dc,gain,yhat] = gausfit(t,y);
--> plot(t,y,'rx',t,yhat,'g-');

Which results in the following plot

inserted by FC2 system