Shifting an array to create a time delay within a function.

11 visualizaciones (últimos 30 días)
I am doing a project that involves modelling the cardiovascular system. I have a function that generates the system of differential equations that make up the model, and this function is fed into the ode23t solver. In the model, the ventricles and atria are controlled by separate 'activation functions'. These are time functions that control when the chambers contract. An important feature of the model is that the atria contract before the ventricles. Therefore, I want the atrial activation function to depend on one time array and the ventricular activation function to depend on another, shfted time array. This is how I am trying to implement it in the function:
function dx1=CVS(t1,x1)
% set-up (excluded here for brevity)
%set timing variables
HR = 70; % heart rate (bpm)
HR_s = HR/60; % heart rate (bps)
T = 1/HR_s; % period of cardiac cycle (s)
T_max_a = 0.125; % time to end systole for atria (s)
T_max_v = 0.2; % time to end systole for ventricles (s)
tm1 = mod(t1,T);
tf1 = 5;
tau_a = 0.025; % time constant of relaxation for atria (s)
tau_v = 0.03; % time constant of relaxation for ventricles (s)
%calculate AV delay in terms of increments in the t1 array
AV_delay = 0.16; %AV delay (s)
interval_length_s = tf1; %length of interval (s)
t_per_s = length(t1)/interval_length_s; %increments in t1 per second
shift_t = ceil(AV_delay*t_per_s); %AV delay in terms of t1 increments
%delay tm
n = shift_t;
tm2 = circshift(tm1,n);
if n>0
tm2(1:n) = 0;
else
tm2(end+n+1:end) = 0;
end
%activation function for atria
if tm1 < 1.5*T_max_a
a1 = 0.5*(1 + sin((pi*tm1/T_max_a) - (pi/2)));
else
a1 = 0.5*exp(-(tm1 - 1.5*T_max_a)/tau_a);
end
%activation function for ventricles
if tm2 < 1.5*T_max_v
b1 = 0.5*(1 + sin((pi*tm2/T_max_v) - (pi/2)));
else
b1 = 0.5*exp(-(tm2 - 1.5*T_max_v)/tau_v);
end
end
And this is where the function is called:
t01 = 0;
tf1 = 5;
interval1 = t01:0.01:tf1;
%initial conditions
x01 = [75.6 69 65 118.6 72.7 61.2 408 79.8];
[t1,x1]=ode23t(@CVS, interval1, x01);
I have tested this outside the function and it works as expected. However, the activation functions inside the function do not behave in the correct way.
Is there a way to implement this kind of time shift inside the function?
Any help is appreciated.

Respuesta aceptada

Torsten
Torsten el 10 de Oct. de 2023
Use dde23 instead of ode23t.
  3 comentarios
Torsten
Torsten el 10 de Oct. de 2023
I would like to shift this function 16ms forward:
Maybe
tm1 = mod(t1+0.016,tc1);
%impulse fxn
if tm1 < 1.5*T_es
a1 = 0.5*(1 + sin((pi*tm1/T_es) - (pi/2)));
else
a1 = 0.5*exp(-(tm1 - 1.5*T_es)/tau);
end
?
Hannah Goldblatt
Hannah Goldblatt el 11 de Oct. de 2023
This seems to be working, thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Condensed Matter & Materials Physics en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by