Fit an exponential function to time-series data

12 visualizzazioni (ultimi 30 giorni)
Hi All,
I have a time series data and I would like to fit an exponential curve using the following expression to the data points and estimate the relaxation time B
The dataset can be found here.
I saw some examples of curve fitting here https://in.mathworks.com/help/matlab/math/example-curve-fitting-via-optimization.html . However it is not clear to me how to fit the above function and estimate B. Could someone please help me with this? I would like to find time scale at which C reaches 100 % of C0, C0 = 7.5.
Side note, I've the optimization toolbox and curve fitting tool box installed.

Risposte (1)

Mathieu NOE
Mathieu NOE il 13 Apr 2021
hello
this is the poor man solution without any toolbox
data was stored in txt file
your B = -1/b_sol from my code below
a_sol = 8.3470
b_sol = -0.7241
c_sol = 0.3345
d_sol = -0.8432
numericData = importdata('data.txt');
start = 25; % use data only starting at this index
x = numericData(start:end,1);
y2fit = numericData(start:end,2);
% exponential fit method
% code is giving good results with template equation : % y = a.*(1-exp(b.*(x-c))) + d;
f = @(a,b,c,d,x) a.*(1-exp(b.*(x-c))) + d;
obj_fun = @(params) norm(f(params(1), params(2), params(3), params(4),x)-y2fit);
sol = fminsearch(obj_fun, [y2fit(end)-y2fit(1),0,0,y2fit(1)]);
a_sol = sol(1)
b_sol = sol(2)
c_sol = sol(3)
d_sol = sol(4)
y_fit = f(a_sol, b_sol,c_sol ,d_sol, x);
figure
plot(x,y2fit,'r',x,y_fit,'-.k');
legend('data','exp fit');
  3 Commenti
Deepa Maheshvare
Deepa Maheshvare il 13 Apr 2021
Modificato: Deepa Maheshvare il 13 Apr 2021
@Mathieu NOE 1/0.72 gives 1.38s. I am not sure how to releate this to the time scale at which steady state is achieved. Because from the plot, I find that steady-state is reached after 5seconds. Could you please offer some explanation on this too?
Mathieu NOE
Mathieu NOE il 13 Apr 2021
hello again
1/ you see that my fit function has not exactly the same form as yours
I used x as the time variable and the "b" are used differently :
my function : y = a.*(1-exp(b.*(x-c))) + d ;
your function : = a.*(1-exp(-x/B)) ;
we don't care about c and d here , and it's quite obvious now that : B (your formula) = -1/b (mine, and solution in the code once the fit is done , is b_sol);
2/ B is a decay rate - see definition here : Exponential decay - Wikipedia
a very often used relationship : to reach 95% of the asymptote, it takes t = 3 x decay rate = 3 * 1.38 = 4.14 s
theoretically, you never reach 100% (the asymptote) , you can only get very close

Accedi per commentare.

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by