1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>GAUSFIT Gaussian Curve Fit
</TITLE>
</HEAD>
<BODY>
<H2>GAUSFIT Gaussian Curve Fit
</H2>
<P>
Section: <A HREF=sec_curvefit.html> Optimization and Curve Fitting </A>
<H3>Usage</H3>
The <code>gausfit</code> routine has the following syntax
<PRE>
[mu,sigma,dc,gain,yhat] = gausfit(t,y,w,mug,sigmag,dcg,gaing).
</PRE>
<P>
where the required inputs are
<UL>
<LI> <code>t</code> - the values of the independant variable (e.g., time samples)
</LI>
<LI> <code>y</code> - the values of the dependant variable (e.g., f(t))
</LI>
</UL>
The following inputs are all optional, and default values are
available for each of them.
<UL>
<LI> <code>w</code> - the weights to use in the fitting (set to ones if omitted)
</LI>
<LI> <code>mug</code> - initial estimate of the mean
</LI>
<LI> <code>sigmag</code> - initial estimate of the sigma (standard deviation)
</LI>
<LI> <code>dcg</code> - initial estimate of the DC value
</LI>
<LI> <code>gaing</code> - initial estimate of the gain
</LI>
</UL>
The fit is of the form <code>yhat=gain*exp((t-mu).^2/(2*sigma^2))+dc</code>.
The outputs are
<UL>
<LI> <code>mu</code> - the mean of the fit
</LI>
<LI> <code>sigma</code> - the sigma of the fit
</LI>
<LI> <code>dc</code> - the dc term of the fit
</LI>
<LI> <code>gain</code> - the gain of the gaussian fit
</LI>
<LI> <code>yhat</code> - the output samples (the Gaussian fits)
</LI>
</UL>
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 <code>mug</code>, <code>sigmag</code>, <code>dcg</code>,
<code>gaing</code> 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 <code>y</code>. The gain is
estimated from the range of <code>y</code>. The mean and standard deviation
are estimated using the first and second order moments of <code>y</code>.
This function uses <code>fitfun</code>.
<H3>Example</H3>
Suppose we want to fit a cycle of a cosine using a Gaussian shape.
<PRE>
--> t = linspace(-pi,pi);
--> y = cos(t);
--> [mu,sigma,dc,gain,yhat] = gausfit(t,y);
--> plot(t,y,'rx',t,yhat,'g-');
</PRE>
<P>
Which results in the following plot
<P>
<DIV ALIGN="CENTER">
<IMG SRC="gausfit1.png">
</DIV>
<P>
</BODY>
</HTML>
|