MATLAB Answers

3-term exponential fit

156 views (last 30 days)
William
William on 6 Apr 2014
Commented: Star Strider on 13 Apr 2014
Hi, I want to fit a 3-term exponential function i.e.
y = a*exp(-b*x) + c*exp(-d*x) + e*exp(-f*x)
to get coefficients b,d,f.
Matlab's curvefitting toolbox is great for 2 term fitting, but that is it's limit. Tried log fits, polyfit fit but had no luck. Any ideas?
Thanks, Will

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 6 Apr 2014
I don’t have the Curve Fitting Toolbox (Optimization and Statistics instead). This uses fminsearch:
y = @(b,x) b(1).*exp(-b(2).*x) + b(3).*exp(-b(4).*x) + b(5).*exp(-b(6).*x);
p = [3; 5; 7; 11; 13; 17]*1E-1; % Create data
x = linspace(1, 10);
yx = y(p,x) + 0.1*(rand(size(x))-0.5);
OLS = @(b) sum((y(b,x) - yx).^2); % Ordinary Least Squares cost function
opts = optimset('MaxFunEvals',50000, 'MaxIter',10000);
B = fminsearch(OLS, rand(6,1), opts); % Use ‘fminsearch’ to minimise the ‘OLS’ function
fcnfit = y(B,x); % Calculate function with estimated parameters
figure(1)
plot(x, yx, '*b')
hold on
plot(x, fcnfit, '-r')
hold off
grid

  3 Comments

Star Strider
Star Strider on 10 Apr 2014
(You just removed your comment that I’m responding to here, so I’ll keep this one around for a few minutes before removing it as well.)
If you’re certain that those are the correct coefficients, they should fit your data. See if they work as initial estimates (in place of rand(6,1) that I used.
The problem I had with that objective function is that almost any set of parameters would fit the data. They didn’t (and rarely were) close to the ones that I used to create it. How did you get the values you just posted?
William
William on 13 Apr 2014
Think I'm getting the hang of it now. I had an extra noise component in my signal that was throwing off the fit. When I take this out of the signal, and do a two term fit, the method works great.
I've attached the noisy data and the output fit I get. The noise results in the oscillation seen in the surf image, and messes up the fit.
The three terms have
b(1)=1/120*10^-3, b(2)=1/80*10^-3,b(3)=1/30*10^-3
Below shows the spread of the fits. Apologies if I haven't explained it very well, I have a feeling the noise ( with b(2)) introduces an unavoidable error.
p.s. I've nulled fit values below zero and above 200
Star Strider
Star Strider on 13 Apr 2014
The best model and fit will actually require you to go back to the differential equations that model the process you’re fitting, integrate them (analytically if possible), and fit that solution. Considering your data demonstrate an exponential-periodic behaviour, chances are that the parameters are not actually independent and in all likelihood are functionally related. I would not consider the oscillations ‘noise’ unless you know they are an artifact of your instrumentation or some such.

Sign in to comment.

More Answers (1)

John D'Errico
John D'Errico on 13 Apr 2014
Note that polyfit is meaningless in this context. You can't fit an exponential with a polynomial tool!
Next, fitting sums of exponentials is one form of an ill-posed problem. When you have too many terms in that sum (and 3 terms is starting to be a fair amount) then the problem starts to get nasty. Think of it like this, we are trying to form a linear combination of terms that all look pretty much alike! Estimation of the coefficients will generate singular (or nearly singular) matrices. If the rate parameters of several of the terms are too close, the problem will become difficult to solve using double precision arithmetic.

  1 Comment

John D'Errico
John D'Errico on 13 Apr 2014
I'll try to add an example later when I have a chance. I'll also show how the fit process can be made a bit easier using a partitioned least squares.

Sign in to comment.

Sign in to answer this question.


Translated by