Section: Optimization and Curve Fitting
gausfit
routine has the following syntax
[mu,sigma,dc,gain,yhat] = gausfit(t,y,w,mug,sigmag,dcg,gaing).
where the required inputs are
t
- the values of the independant variable (e.g., time samples)
y
- the values of the dependant variable (e.g., f(t))
w
- the weights to use in the fitting (set to ones if omitted)
mug
- initial estimate of the mean
sigmag
- initial estimate of the sigma (standard deviation)
dcg
- initial estimate of the DC value
gaing
- initial estimate of the gain
yhat=gain*exp((t-mu).^2/(2*sigma^2))+dc
.
The outputs are
mu
- the mean of the fit
sigma
- the sigma of the fit
dc
- the dc term of the fit
gain
- the gain of the gaussian fit
yhat
- the output samples (the Gaussian fits)
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
.
--> 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