Shifting an array to create a time delay within a function.
7 views (last 30 days)
Show older comments
Hannah Goldblatt
on 10 Oct 2023
Commented: Hannah Goldblatt
on 11 Oct 2023
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.
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Condensed Matter & Materials Physics 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!



