You want to fit an exponential envelope function to the curve, essentially a least upper bound function. So the exponential mode would be something of the form...
If you know that the lower asymptote is exactly 1, then your model would be
We might estimate those coefficients by a simple log transformation, or we could use a nonlinear estimation. I'll show the log transformation. First, I'll create a damped sine wave curve as an example.
x = 0:100;
y = 1 + sin(x - pi/3).*exp(-0.2*x);
First, use only those points that fall above 1. So assuming vectors of points x and y...
ind = (y > 1);
x1 = x(ind);
% and transform y by a log transformation
y1 = log(y(ind) - 1);
A = [ones(numel(x1),1),x1(:)];
% estimate the model coeffs = lsqlin(A,y1(:),-A,-y1(:),[],[],[],[],[],optimset('algorithm','active-set','display','off'));
coeffs =
-0.00091842
-0.19999
Don't forget that when we logged the model, we transformed the coefficient b. We need to exponentiate
b = exp(coeffs(1))
b =
0.99908
c = coeffs(2);
% now plot the data and the curve
plot(x,y,'ro',x,1 + b*exp(c*x),'b-)
I used lsqlin from the optimization toolbox to do the fit. The fundamental ideas in this solution were:
- Transform the problem to linearity.
- Solve the linear least squares problem, such that all residuals had the proper sign.
If you don't know the lower asymptote for the curve, then you would need to use a nonlinear optimization tool for the fit. The constraints would be such that the necessary optimizer would be fmincon.
Best Answer