File: curvefit_gausfit.html

package info (click to toggle)
freemat 4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 174,756 kB
  • ctags: 67,023
  • sloc: cpp: 351,059; ansic: 255,892; sh: 40,590; makefile: 4,387; perl: 4,058; asm: 3,313; pascal: 2,718; fortran: 1,722; ada: 1,681; ml: 1,360; cs: 879; csh: 795; python: 430; sed: 162; lisp: 160; awk: 5
file content (79 lines) | stat: -rw-r--r-- 2,453 bytes parent folder | download | duplicates (2)
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>
--&gt; t = linspace(-pi,pi); 
--&gt; y = cos(t);
--&gt; [mu,sigma,dc,gain,yhat] = gausfit(t,y);
--&gt; 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>