How can I make an exponential fit with offset?

Hello, since Matlab does not provide a built-in exponential fit function with an offset I would like to create one by myself. I use the Curve Fitting Tool and enter as a custom equation: f(x) = a*exp(b*x)+c However the tool is not performing a correct fit. If I use the built-in exponential fit (2 terms) I obtain a smooth fit, where the time constant of the second term is set to zero and thereby creating the correct offset. Do I have to adjust the start values or why is the custom equation not yielding a good fit? Regards

Réponses (2)

The easy way is to create your own anonymous function:
f = @(b,x) b(1).*exp(b(2).*x) + b(3);

4 commentaires

twig27
twig27 le 26 Jan 2017
Modifié(e) : twig27 le 26 Jan 2017
okay, and how do I perform a fit with that? How would the code look like if the data to be fitted is: y_signal,x_time ?
Use fminsearch.
The Code:
y_signal = ...;
x_time = ...;
f = @(b,x) b(1).*exp(b(2).*x) + b(3);
nrmrsd = @(b) norm(y_signal - f(b,x_time)) % Residual Norm Cost Function
B0 = rand(3,1); % Choose Appropriate Initial Estimates
[B,rnrm] = fminsearch(nrmrsd, B0); % Estimate Parameters ‘B’
x_plot = linspace(min(x_time), max(x_time));
figure(1)
plot(x_time, y_signal, 'pg')
hold on
plot(x_plot, f(B,x_plot, '-r')
hold off
grid
xlabel('Time')
ylabel('Signal')
legend('Data', 'Fit', 'Location','NE')
This is how I would do it, or with nlinfit and its friends if I wanted statistics.
patrick
patrick le 24 Sep 2018
Thank you Star Strider!
Star Strider
Star Strider le 24 Sep 2018
@patrick —
My pleasure!

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 24 Sep 2018

0 votes

You can use fitnlm() in the attached test.m file.

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange

Question posée :

le 26 Jan 2017

Commenté :

le 24 Sep 2018

Community Treasure Hunt

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

Start Hunting!

Translated by