Plateau followed by one phase decay
Afficher commentaires plus anciens
Good morning, I am trying to figure out how to compute tau constants from my data
My data could be be fitted by such plateau followed by one phase decay function:

I tried to implement it in MATLAB as follows:
x = 0:0.5:20; % time in seconds
Y0 = -0.6; % signal baseline value
Plateau = -1; % singnal plateu after trigger/stimulus, maximum change from baseline
tau = 0.6; % exponenential decay constant
K = 1/tau; % rate constant in units reciprocal of the x-axis units
X0 = 5; % trigger time
y = Plateau+(Y0-Plateau)*exp(-K*(x-X0));
figure;plot(x,y,'k');
However, I get the following result:

I would have 2 questions:
1) why cant I reproduce the one phase decay function?
2) would you know how to use the matlab funciton "fit" for such data with plateau followed by one phase decay function?
Thanks community for your kind support,
Best regards.
Réponses (2)
Like this?
x = 0:0.5:20; % time in seconds
Y0 = -0.6; % signal baseline value
Plateau = -1; % singnal plateu after trigger/stimulus, maximum change from baseline
tau = 0.6; % exponenential decay constant
K = 1/tau; % rate constant in units reciprocal of the x-axis units
X0 = 5; % trigger time
y = Y0*(x<=X0)+(Plateau+(Y0-Plateau)*exp(-K*(x-X0))).*(x>X0);
figure;plot(x,y,'k');
5 commentaires
Alan Stevens
le 26 Fév 2024
Yes, you shouold be able to get a best fit using Matlab (your graph looks like you've done a reasonable job by eye!). What parameters do you want to fit - tau, tau and X0, tau, Xo and Y0, ...?
If you upload your data, I could have a go at fitting it.
Here's a quick fit of tau and Y0. I'll leave you to tidy it up and extend it to fit X0 as well.
x = 0:0.5:20;
y = [-0.137055262721364 -0.118841612584876 -0.274602636741299 -0.117324828772196 ...
-0.173528150754918 -0.280491919000118 -0.244300356226590 -0.367583069701879 ...
-0.423274105143034 -0.529129050767333 -0.774173830727337 -0.676677606159725 ...
-0.730062482232667 -0.863905715495076 -0.831675679632950 -0.987303352625066 ...
-0.949979744575626 -0.865710605996821 -0.901728879393798 -0.877082148456042 ...
-0.944693953430828 -1.07404346760035 -0.915521627715257 -0.901789963321291 ...
-0.955365771797851 -0.941530617721837 -0.945983148775748 -1.01735658137382 ...
-0.965635004813717 -1.06321643780048 -0.956807780654745 -1.09208906741553 ...
-1.04341265165344 -1.08982901817714 -1.07984413818039 -0.934740294823467 ...
-0.960591807908718 -1.03623550995537 -0.909687220130007 -1.09290177705358 ...
-1.01208835337351];
Plateau = -1;
X0 = 2;
fn = @(x,tau,Y0)Y0*(x<=X0)+(Plateau+(Y0-Plateau)*exp(-(x-X0)/tau)).*(x>X0);
tauY0 = [1, -0.1]; % Initial guess
tauY = fminsearch(@(tauY) F(tauY,x,y), tauY0);
tau = tauY(1); Y0 = tauY(2);
yfit = fn(x,tau,Y0);
plot(x,y,'.',x,yfit), grid
xlabel('x'), ylabel('y')
text(12,-0.25,['tau = ' num2str(tau)])
text(12,-0.35,['Y0 = ' num2str(Y0)])
function Z = F(tauY,x,y)
tau = tauY(1); Y0 = tauY(2);
Plateau = -1;
X0 = 2;
yvals = zeros(1,numel(x));
for i = 1:numel(x)
t = x(i) - X0;
yvals(i) = Y0*(t<=0)+(Plateau+(Y0-Plateau)*exp(-t/tau)).*(t>0);
end
Z = norm(yvals-y);
end
Francesco
le 25 Avr 2024
Francesco
le 27 Fév 2024
0 votes
Catégories
En savoir plus sur Windows dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



