Code covered by the BSD License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

### Highlights from fitgaussian

3.0
3.0 | 1 rating Rate this file 10 Downloads (last 30 days) File Size: 10.3 KB File ID: #15262 Version: 1.0

# fitgaussian

### Mehmet OZTURK (view profile)

11 Jun 2007 (Updated )

fit a gaussian like curve to data

File Information
Description

FITGAUSS is a function to fit a gaussian like curve "f" to experimental data by Marquardt-Levenberg non-linear least squares minimization. The fitting function has a form of a*exp(-((x-b)/c)^2)+d*x+e. This means the curve is build up a line and a gaussian. INPUTS: "x,y" is input data. "init" is initial guess for parameteres [a b c d e]. If is empty they will be determined automatically from input data and "w" is weight vector (default is ones(size(x))). OUTPUTS: "f" is the values of fitted function. "X" is the estimated parameters. "err" is the normalized error. "it" is number of iterations. "extreme" function from Lic. on Physics Carlos Adrián Vargas Aguilera is used in this function.

Example:
x=1:100;
a=30; b=45; c=10; d=.3; e=20;
f=a*exp(-((x-b)./c).^2)+d*x+e;
fn=f+2*randn(size(f));
[F X]=fitgauss(x,fn);
X=
29.61, 45.20, 10.20, 0.31, 19.18
plot(x,fn,'.',x,F,'r')

Required Products Spline Toolbox
MATLAB release MATLAB 7.4 (R2007a)
Tags for This File   Please login to tag files.
 Please login to add a comment or rating.
Comments and Ratings (2)
29 Jan 2008 pedro silva

the required function frepmat is not provided in the .zip package

Comment only
12 Jun 2007 Dimitri Shvorob

(Wouldn't the simple Newton's method do for this problem? I have a feeling the task could be done in 2-3 lines with 'fminunc'). FEX visitors should note that what's being fitted is not the normal pdf: consider the 'dx+e' term. The author would do well to use spell-check, provide examples that actually work ('getpts'?), and avoid 'elegant' code like
a_lm=a_est+dp(1);
b_lm=b_est+dp(2);
c_lm=c_est+dp(3);
d_lm=d_est+dp(4);
e_lm=e_est+dp(5);

Updates
13 Jun 2007

Updated description an example

Contact us