3-term exponential fit

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

 采纳的回答

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 个评论

(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?
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
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.

请先登录,再进行评论。

更多回答(2 个)

John D'Errico
John D'Errico 2014-4-13

0 个投票

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 个评论

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.

请先登录,再进行评论。

Per this answer, you can do it with the following matlab code
clear all;
clc;
% get data
dx = 0.001;
x = (dx:dx:1.5)';
y = -1 + 5*exp(0.5*x) + 4*exp(-3*x) + 2*exp(-2*x);
% calculate n integrals of y and n-1 powers of x
n = 3;
iy = zeros(length(x), n);
xp = zeros(length(x), n+1);
iy(:,1) = cumtrapz(x, y);
xp(:,1) = x;
for ii=2:1:n
iy(:, ii) = cumtrapz(x, iy(:, ii-1));
xp(:, ii) = xp(:, ii-1) .* x;
end
xp(:, n+1) = ones(size(x));
% get exponentials lambdas
Y = [iy, xp];
A = pinv(Y)*y;
Ahat = [A(1:n)'; [eye(n-1), zeros(n-1, 1)]];
lambdas = eig(Ahat);
lambdas
% get exponentials multipliers
X = [ones(size(x)), exp(lambdas'.*x)];
P = pinv(X)*y;
P
% show estimate
y_est = X*P;
figure();
plot(x, y); hold on;
plot(x, y_est, 'r--');

类别

帮助中心File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by