Exponential fit, without start-guess

Fits 1) f=s1+s2*exp(-t/s3) or 2) f=s1+s2*exp(-t/s3)+s4*exp(-t/s5) to numerics, without startguess
6.2K Downloads
Updated 9 Jan 2009

No License

exp2fit solves the non-linear least squares problem exact
and using it as a start guess in a least square method
in cases with noise, of the specific exponential functions:
--- caseval = 1 ----
f=s1+s2*exp(-t/s3)
--- caseval = 2 (general case, two exponentials) ----
f=s1+s2*exp(-t/s3)+s4*exp(-t/s5)
--- caseval = 3 ----
f=s1*(1-exp(-t/s2)) %i.e., constraints between s1 and s2

Syntax: s=exp2fit(t,f,caseval) gives the parameters in the fitting function specified by the choice of caseval (1,2,3). t and f are (normally) vectors of the same size, containing the data to be fitted.
s=exp2fit(t,f,caseval,lsq_val,options), using lsq_val='no' gives the analytic solution, without least square approach (faster), where options (optional or []) are produced by optimset, as used in lsqcurvefit.

This algorithm is using analytic formulas using multiple integrals. Integral estimations are used as start guess in lsqcurvefit. Note: For infinite lengths of t, and f, without noise the result is exact.

%--- Example 1: (see also help exp2fit)
t=linspace(1,4,100)*1e-9;
noise=0.02;
f=0.1+2*exp(-t/3e-9)+noise*randn(size(t));

%--- solve without startguess
s=exp2fit(t,f,1)

%--- plot and compare
fun = @(s,t) s(1)+s(2)*exp(-t/s(3));
tt=linspace(0,4*s(3),200);
ff=fun(s,tt);
figure(1), clf;plot(t,f,'.',tt,ff);

%--- Example 2, Damped Harmonic oscillator:
%--- Note: sin(x)=(exp(ix)-exp(-ix))/2i
t=linspace(1,12,100)*1e-9;
w=1e9;
f=1+3*exp(-t/5e-9).*sin(w*(t-2e-9));

%--- solve without startguess
s=exp2fit(t,f,2,'no')

%--- plot and compare
fun = @(s,t) s(1)+s(2)*exp(-t/s(3))+s(4)*exp(-t/s(5));
tt=linspace(0,20,200)*1e-9;
ff=fun(s,tt);
figure(1), clf;plot(t,f,'.',tt,real(ff));

%% By Per Sundqvist january 2009.

Cite As

Per Sundqvist (2024). Exponential fit, without start-guess (https://www.mathworks.com/matlabcentral/fileexchange/21959-exponential-fit-without-start-guess), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Linear and Nonlinear Regression in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.3.0.0

The function is generalized to handle two exponentials now: f=s1+s2*exp(-t/s3)+s4*exp(-t/s5) and also small fix and an option is included to choose if lsqcurvefit should be applied or not.

1.2.0.0

Improvement in numerical integration, giving perfect agreement also for small number of data-points. nov-08

1.0.0.0