Free Books

Fitting a Gaussian to Data

When fitting a single Gaussian to data, one can take a log and fit a parabola. In matlab, this can be carried out as in the following example:

x = -1:0.1:1;
sigma = 0.01;
y = exp(-x.*x) + sigma*randn(size(x)); % test data:
[p,s] = polyfit(x,log(y),2); % fit parabola to log
yh = exp(polyval(p,x)); % data model
norm(y-yh) % ans =  1.9230e-16 when sigma=0
In practice, it is good to avoid zeros in the data. For example, one can fit only to the middle third or so of a measured peak, restricting consideration to measured samples that are positive and ``look Gaussian'' to a reasonable extent.

Next Section:
Infinite Flatness at Infinity
Previous Section:
Gaussians Closed under Convolution