Exponential decay, rate constant
Show older comments
Hello,
I have a small problem. I'm trying to extract the rate of bleaching from my dataset.
It's a very simple dataset, yet I cannot make it work.
Best so far worked "nomal exp" but wasn't near perfect.

I would be extremely grateful for help.
Thank you!
2 Comments
Mathieu NOE
on 5 Feb 2021
hello again
I wonder why you use the same K parameter in your function for both amplitude and decay
shoudn't it be f(x) = A * exp (- K*x) ?
Anna Baj
on 5 Feb 2021
Accepted Answer
More Answers (1)
Mathieu NOE
on 5 Feb 2021
hello
this is a plain matlab example - i am not using the curve fitting tool here
% generate some dummy noisy data
x = 0:100;
N = length(x);
tau = 10; % time scale of relaxation
x_asym = 4; % relative increase of the observable x t -> infinity
y = x_asym*(1 - exp(-x/tau)); % uncorrupted signal
sig = 0.1; % noise strength
pert1 = sig*randn(1,N);
y_noisy = y+pert1; % corrupted signal
% exponential fit method
% code is giving good results with template equation : % y = a.*(1-exp(b.*(x-c)));
f = @(a,b,c,x) a.*(1-exp(b.*(x-c)));
obj_fun = @(params) norm(f(params(1), params(2), params(3),x)-y_noisy);
sol = fminsearch(obj_fun, [y_noisy(end),0,0]);
a_sol = sol(1);
b_sol = sol(2);
c_sol = sol(3);
y_fit = f(a_sol, b_sol,c_sol, x);
figure
plot(x,y,'-+b',x,y_noisy,'r',x,y_fit,'-ok');
legend('signal','signal+noise','exp fit');
7 Comments
Mathieu NOE
on 5 Feb 2021
this code would be more adapted to a decaying exponential with four unknowns
% y = a.*(1-exp(b.*(x-c))) + d;
% generate some dummy noisy data
x = 0:100;
N = length(x);
tau = 10; % time scale of relaxation
y = 10-4*(1 - exp((-x-1)/tau)); % uncorrupted signal
sig = 0.1; % noise strength
pert1 = sig*randn(1,N);
y_noisy = y+pert1; % corrupted signal
% 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)-y_noisy);
sol = fminsearch(obj_fun, [y_noisy(end)-y_noisy(1),0,0,y_noisy(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,y,'-+b',x,y_noisy,'r',x,y_fit,'-ok');
legend('signal','signal+noise','exp fit');
Anna Baj
on 5 Feb 2021
Mathieu NOE
on 5 Feb 2021
ok
I can try on my side with your data if you wish
Anna Baj
on 5 Feb 2021
Mathieu NOE
on 8 Feb 2021
hello
here you are :
[numericData, ~, ~,] = xlsread('Bleaching.xlsx');
x = numericData(:,1);
y2fit = numericData(:,2);
% exponential fit method
% code is giving good results with template equation : % y = a.*(1-exp(b.*(x-c)));
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');
values for a,b,c,d are :
a_sol = -32.8773
b_sol = -0.0070
c_sol = 0.0047
d_sol = 152.5871
Anna Baj
on 8 Feb 2021
Mathieu NOE
on 8 Feb 2021
you're welcome !
Categories
Find more on Exploration and Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
