# Pacemaker design and modeling electrical conduction in the heart

## Overview

This tutorial presents the modeling of pacemakers and the electrical conduction system of the human heart as timed automata in Collimator. A large part of the models and theory presented in this tutorial is taken from references [1,2,3], particularly the graduate course [3].

## Electrical conduction system of the heart

The electrical conduction system of the heart (see figure below) is a complex network of specialized cells and tissues that work together to coordinate the contraction of the heart muscle and pump blood to the rest of the body. It consists of three main parts:

1. the Sinoatrial (SA) node,
2. the Atrioventricular (AV) node, and
3. the specialized conduction pathways known as the bundle of His and the Purkinje fibers.

The SA node is located in the upper part of the right atrium and serves as the heart's natural pacemaker. It produces electrical signals that travel through the atria, causing them to contract and pump blood into the ventricles.

The AV node is located in the center of the heart between the atria and the ventricles. It receives the electrical signals from the SA node and slows them down, allowing the atria time to contract and pump blood into the ventricles before the ventricles contract and pump blood out to the rest of the body.

The bundle of His and the Purkinje fibers are specialized conduction pathways that carry the electrical signals from the AV node down through the ventricles, causing them to contract and pump blood out to the rest of the body.

The electrical conduction system of the heart is essential for maintaining a regular heartbeat and ensuring that the heart is able to pump blood effectively to the rest of the body. Abnormalities in the electrical conduction system can lead to arrhythmias, or abnormalities in the heart's rhythm.

Antegrade conduction refers to the normal flow of electrical signals in the heart, from the sinoatrial (SA) node to the atrioventricular (AV) node and then down through the ventricles.

In a healthy heart, the SA node is located in the upper part of the right atrium and serves as the heart's natural pacemaker. It produces electrical signals that travel through the atria and the AV node, which is located in the center of the heart between the atria and the ventricles. From there, the electrical signals travel down through the ventricles, causing them to contract and pump blood out to the rest of the body.

Antegrade conduction is essential for maintaining a regular heartbeat and ensuring that the heart is able to pump blood effectively. In some cases, however, the electrical signals may be disrupted or slowed down, leading to an irregular heartbeat or other problems with the heart's rhythm. In these cases, it may be necessary to use a pacemaker or other medical devices to help regulate the heart's rhythm.

Retrograde conduction refers to the movement of electrical signals in the opposite direction to the normal flow of electrical activity in the heart. Thus, in such cases, the electrical signals can travel from the ventricles back up to the atria. Retrograde conduction can occur in a variety of situations, such as when there is damage to the AV node or when the electrical signals are being disrupted by an arrhythmia.

Retrograde conduction can sometimes cause problems in the heart, such as palpitations or an irregular heartbeat. In some cases, it may be necessary to use a pacemaker or other medical devices to help regulate the heart's rhythm and prevent retrograde conduction.

## Pacemaker

A pacemaker is a small device that is placed in the chest or abdomen to help regulate the heart's rhythm. It uses electrical pulses to stimulate the heart to beat at a normal rate, helping to prevent or treat conditions such as arrhythmias (abnormal heart rhythms). Pacemakers are usually recommended for people who have a slow heart rate or other problems with the heart's electrical system. They can be easily implanted through a surgical procedure. The device is connected to the heart through one or more thin wires, called leads, which are passed through a vein and positioned in the heart. The pacemaker senses the electrical activity of the heart and, when necessary, sends regular electrical impulses to the heart through the leads, which help to keep the heart beating at a normal rate.

Pacemakers have two main functions: sensing and pacing

Sensing refers to the ability of the pacemaker to detect the electrical activity of the heart. The pacemaker uses sensors (electrodes) to monitor the heart's electrical activity and determine whether the heart is beating at a normal rate. If the heart's rate is too slow, the pacemaker can send electrical impulses to the heart to help regulate its rhythm.

Pacing refers to the ability of the pacemaker to send electrical impulses to the heart to help it beat at a regular pace. The pacemaker can be programmed to send electrical impulses to either the atria or the ventricles, depending on the needs of the patient.

Pacemakers can be programmed to sense and pace both the atria and the ventricles simultaneously or individually. A typical configuration of a pacemaker capable of sensing and pacing both the right atrium and the right ventricle is shown below. It consists of two leads: one connecting the pacemaker to tissue in the right atrium and another connecting the pacemaker to tissue in the right ventricle.

In the above configuration, a block diagram depicting the communication between the heart and the pacemaker is shown in the schematic below. The pacemaker electrodes in the atrium and the ventricle continuously gather (i.e. sense) the electrical signals at their respective locations. Analysis of these signals is interpreted by the pacemaker as discrete events A_sense! and V_sense! representing the depolarisation of the atrium and ventricle, respectively. Depolarisation implies excitation of the tissue, leading to its contraction.

The sensing and analysis of A_sense! and V_sense! events is then used by the pacemaker to deliver pacing signals A_pace! and V_pace! to the atrium and the ventricle, respectively, in order to restore normal heart rhythm. The pacing signals A_pace! and V_pace! are small electrical impulses, which will cause depolarisation of respective tissues. The precise programming of the pacemaker depends on the specific needs of the patient. For example, in bradycardia when the heart rate is too low, i.e. V_sense! events occur at significantly longer intervals, the pacemaker may send small electrical impulses V_pace! to the ventricle to keep it artificially beating at a faster rate.

## Modelling the heart

### Action potential

In cardiac electrophysiology, an action potential is the electrical activity of a heart cell (cardiomyocyte) that drives the contraction of the heart muscle. It is initiated by the movement of ions across the cell membrane through ion channels, which results in a change in the electrical potential of the cell.

A typical action potential of a myocyte is shown in the figure below. For the purposes of modelling, the action potential can be divided into three distinct phases:

1. Rest (RST) phase: In the resting state, the cell membrane is negatively charged on the inside and positively charged on the outside. This difference in charge is maintained by the movement of ions through ion channels. A cell in the rest state can be excited through an external stimulus or it may self-excite.

2. Effective Refractory Period (ERP): When the cell is stimulated in the rest state or when it self-excites, ion channels open and allow ions to flow into or out of the cell. This results in a change in the electrical potential of the cell, known as depolarisation. Post rapid depolarisation, we can consider the cell to have entered the 'effective refractory period' (ERP) for simplified modelling. The ERP is the period of time during which a cell is unable to respond to any stimulus. Thus, during ERP, even if an external stimulus is applied, the cell will not respond to the stimulus.

3. Relative Refractory Period (RRP): After ERP, the cell enters a period during which it is able to respond to a stimulus, but it requires a stronger stimulus to do so and/or the stimulus will generate a weaker reaction.

The end of RRP completes one cardiac cycle. After RRP, the cell enters the resting phase RST, and the cycle of three phases RST-ERP-RRP repeats.

### Simple model: two nodes connected by a conduction path

The simplest model for representing the electrical conduction system of the heart can be thought of as two nodes which are connected through a conduction path. This is shown in the figure below, where the first node (SA node) is connected to the second node (Right Ventricular Apex [RPA]) through a conduction path. Note that the RVA node is not a physical node in the conduction system. We are using it as an abstraction representing the tissue at the apex of the right ventricle.

In what follows, we will create timed automata models for the nodes and the conduction path. With such basic models for nodes and paths, one can add more complexity, if necessary, by adding more nodes and more conduction pathways, to add spatial granularity to the model of the electrical conduction system.

### Timed automata

Timed automata are a type of finite state machine that can model systems with both discrete and continuous behaviors. They are used to describe and analyse the behavior of systems that involve time, such as real-time systems, communication protocols, and hybrid systems.

A timed automaton consists of a finite set of states, a finite set of input and output actions, and a set of transitions between the states. Each transition is labeled with an action and a timing constraint (guard), which specifies the amount of time that must elapse before the transition can be taken. In addition to transitions, timed automata can also have clock variables, which are used to keep track of time and can be reset or compared to constants in the timing constraints.

Timed automata can be used to specify the behavior of a system, to verify whether a system meets certain properties (such as liveness or safety), and to synthesize controllers for a system. They are a useful formalism for modeling and analyzing real-time systems, as they allow for the specification of timing constraints and the incorporation of clock variables, which are important features in many real-time systems.

The use of timed automata for modelling the heart and pacemakers has been proposed in the scientific literature. Here we recreate the models presented in [1,2,3].

### Timed automaton for a node

Using the three phases (RST, ERP, and RRP) of a myocyte's action potential as described above, we can create a timed automaton model for a node. Note that we can use the same model for the SA node and for the RVA node and account for the differences between the atrial and ventricular tissue by using different parameters for the node model.

A schematic of the timed automaton for a node is shown below. It contains the three states: RST, ERP, and RRP. The initial state (denoted by an arrow unconnected at the other end to any state) is the RST state. The transitions between the states are denoted by directed arrows, and the text associated with the arrow specifies the guards (constraints), actions, and clock resets associated with the transition. The guards are specified in blue, while the actions and clock resets are specified in red. The variable /(x/) denotes the clock for this automaton, which decreases by unity in all the states at every clock cycle. A message issued is denoted with an exclamation point (for example, Act_path!), while a message that is listened for is denoted with a question mark (for example, Act_node?).

The three parameters associated with the automaton of a node are T_RST, T_ERP, and T_RRP, which represent the durations of the rest phase, ERP phase, and RRP phase, respectively. These can be determined through electrophysiology studies. However, for testing a variety of conditions and pacemaker performance in such conditions, we do not need precise parameter values (which will anyways vary between subjects). The important feature is for our model to be able to reproduce a variety of conditions by changing the model parameters.

Armed with the above background, the automaton schematic below becomes easy to understand:

1. From the RST state, the only other state that can be reached is the ERP state. This transition can happen under two conditions:

• A. when the clock runs out ( x <= 0, specifying the end of the RST phase), or
• B. when a stimulus is received (for example through conduction from other regions) that depolarizes the node. Such stimulus is denoted as a message Act_node?, which this automaton listens to.

Lastly, when the transition to ERP occurs, the clock is set to T_ERP, and an Act_path! message is issued. This message will be listened to by the automaton for the conduction path, which can take additional actions based on the knowledge that the node is activated and that conduction can now occur in the antegrade or retrograde direction, depending on the position of the node relative to the conduction path.

2. From the ERP state, the only transition is to the RRP state. Furthermore, this transition can only occur with the clock (initially set to T_ERP on entering this state runs out), as the cell does not react to any stimulus during ERP. When the transition to RRP occurs, we reset the clock to T_RRP.

3. From the RRP state, two transitions are possible:

• A. if a stimulus (Act_node?) is received, the cell can enter ERP, while resetting the clock and issuing an Act_path! message, or
• B. if the clock runs out, then transition to RST naturally occurs, and the clock is rest to T_RST.

In practice, for transitions to ERP, which includes issuing a message Act_path!, a temporary state is utilized. This temporary state (to_ERP) is visited for one clock cycle, during which the message Act_path! is issued. This schematic is shown below

In Collimator, timed automata can be implemented as a Python Script block or through a State Machine block. In either case, to implement the above presented node automaton, the following script can be used.

'''
Inputs:
Act_node : Message signalling this node to activate (depolarise) Outputs:
node_state: State of this node
Act_path: Message signalling the antegrade conduction path to activate
'''
if time == 0:
from enum import Enum
# Model parameters
T_RST = 20 # Time period for Rest state
T_ERP = 100 # Effective Refractory period
T_RRP = 50 # Relative Refractory period
T_trans = 1 # Clock cycles when transitioning to a state and issuing a message
class State(Enum):
# The four states (the numbers assigned to states are arbitrary and useful only for plotting)
RST = 0 # Rest state
ERP = 1 # State corresponding to Effective Refractory period
RRP = 2 # State corresponding to Relative Refractory period
to_ERP = 0.5 # Temporaray state for transitioning to ERP
# Initial state and own clock
state = State.RST # Initial state for the automaton is Rest  Act_path = 0 # This variable represents the message to activate conduction path in antegrade direction
x = T_RST # Clock variable: initalised to T_RST
# Transitions from the Rest state
if state is State.RST:
if x	<= 0 or Act_node:
state = State.to_ERP
x = T_trans
Act_path = 1
# Transitions from the ERP state
elif state is State.ERP:
if x <= 0:
state = State.RRP
x = T_RRP
# Transitions from the RRP state
elif state is State.RRP:
if x	<= 0:
state = State.RST
x = T_RST
elif Act_node:
state = State.to_ERP
x = T_trans
Act_path = 1
# Transitions from the temporary state before going to ERP. elif state is State.to_ERP:
if x	<= 0:
state = State.ERP
Act_path = 0
x = T_ERP
x = x-1 # Clock decreases regardless of state node_state = state.value # Set output node_state to the state of the automaton




### Timed automaton for the conduction path

The conduction path has two main functions:

1. to facilitate the propagation of the electrical signal in both antegrade and retrograde directions, and
2. to add appropriate time delay to the signal travelling through the path.

The schematic below shows the automaton for the above functions for a conduction path that connects two nodes, referred to as node_1 and node_2. The antegrade direction path is referred to as path_1, while the retrograde direction path is referred to as path_2. The model parameters are T_cond_ANT and T_cond_RET, which represent the conduction delays in the antegrade and retrograde directions, respectively. There are five states:

1. Idle state (IDL): This is the idle state, which is effectively a waiting state before messages Act_path_1? or Act_path_2? indicating whether path_1 or path_2 have been activated are received from node_1 or node_2, respectively.
2. Antegrade conduction delay state (ANT): This state accounts for the conduction delay in the antegrade direction by an amount T_cond_ANT.
3. Retrograde conduction delay state (RET): This state accounts for the conduction delay in the retrograde direction by an amount T_cond_RET.
4. Hold state (HLD): This is a temporary state, which is visited after ANT or RET states for one clock cycle before transitioning back to the IDL state. In our models, this temporary state is necessary to avoid an infinite cycle of antegrade and retrograde conductions between the two nodes [3]. Without this temporary state, the first node's antegrade direction signal activates/excites the second node, whose retrograde direction signal activates the first node, and this cycle repeats incessantly.
5. Simultaneous propagation state (SML): This is a state that accounts for simultaneous propagation of antegrade and retrogage electrical signals in the conduction path, which results in a net cancellation of the two signals leading to a skipped heart-beat, i.e. no contraction of the heart chambers. This state is triggered from ANT or RET states when Act_path_2? (implying retrograde conduction) or Act_path_1? (implying antegrade conduction), respectively, are received.

The functioning of the above automaton is as follows. In the IDL state, when Act_path_1? (sent by the automaton for node_1) is received, the automaton transitions to ANT state while resetting the clock to T_cond_ANT. Here, two cases are possible. If Act_path_2? (sent by the automaton for node_2) is received, we have simultaneous propagation of antegrade and retrograde signals, and thus the automaton enter the SML state. Alternatively, if Act_path_2? is not received and T_cond_ANT amount of time (the conduction delay) has passed, the automaton enters the HLD state. Lastly, from both HLD and SML state, after spending one clock cycle, the automaton transitions into the IDL state.

The above working principle is identical in the retrograde direction, i.e. in the IDL state when Act_path_2? (sent by the automaton for node_2) is received, and the automaton transitions to RET state while resetting the clock to T_cond_RET.

As with the node automaton, the conduction path automaton can be implemented in Collimator as a Python Script block or through a State Machine block. In either case, to implement the above presented conduction path automaton, the following script can be used.

'''
This automaton models the conduction path between two nodes as shown
below
node_1 	<--> Conduction path 	<--> node_2
In the above diagram, the antegrade direction is from node_1 to node_2,
direction is from node_2 to node_1.
Inputs:
Act_path_1 : Message signalling that path_1 (antegrade) is activated
Act_path_2 : Message signalling that path_2 (retrograde) is activated
Outputs:
node_state: State of this conduction node
Act_node_1: Message signalling that node_1 should activate
(depolarise)
Act_node_2: Message signalling that node_2 should activate
(depolarise)
'''
if time == 0:
from enum import Enum
T_cond_ANT = 20 # Conduction delay in antegrade direction
T_cond_RET = 20 # Conduction delay in retrograde direction
class State(Enum):
IDL = 0 # Idle state
ANT = 1 # State corresponding to conduction delay in
RET = 2 # State corresponding to conduction delay in
HLD = 3 # Hold state (temporary) before transitioning
back to Idle state
SML = 4 # State to account for simultaneous antegrade and
retrograde signal propagation in the conduction path
# Initial state and own clock
state = State.IDL # Initial state for the automaton is Idle
Act_node_1 = 0 # Message signalling that node_1 should activate
(depolarise)
Act_node_2 = 0 # Message signalling that node_2 should activate
(depolarise)
x = 0 # Clock for this automaton
# Transitions from the Idle state
if state is State.IDL:
if Act_path_1:
state = State.ANT
x = T_cond_ANT
elif Act_path_2:
state = State.RET
x = T_cond_RET
# Transitions from the state corresponding to delay in antegrade
direction
elif state is State.ANT:
if x <= 0:
state = State.HLD
x = 1
Act_node_2 = 1
elif Act_path_2:
state = state.SML
x = 1
# Transitions from the state corresponding to delay in retrograde
direction
elif state is State.RET:
if x <= 0:
state = State.HLD
x = 1
Act_node_1 = 1
elif Act_path_1:
state = state.SML
x = 1
# Transitions from the temporary Hold state before transitioning to Idle
state
elif state is State.HLD:
if x <= 0:
state = State.IDL
Act_node_1 = 0
Act_node_2 = 0
# Transitions from the Simultaneous propagation state to account for
elif state is State.SML:
if x <= 0:
state = State.IDL
x = x-1 # Clock decreases regardless of the state.
node_state = state.value # Set output node_state to the state of the
automaton.



## Creating the heart model in Collimator

With the automata models created for the nodes and the conduction path, a simple node--path- -node model for the heart can now be created. The first node can be seen as the SA node, representing atrium electrical activity, and the second node can be seen as cardiac tissue at he right ventricular apex (RVA node), representing ventricular activity.

The above scripts, including the parameters within the scripts, are used for the SA node and for the conduction path. For the RVA node, identical script to that for the SA node is used but with twice the value for the T_RST parameter (so that the primary activation mode for the RVA node is through the signal propagated from the SA node).

To add a bit more realism, we add unity delays between the node and conduction blocks. With this, our Collimator model of electrical wave propagation in the heart is shown in the figure below.

We should set the time mode of all the blocks to Discrete, and the global simulation time to 1000. By running the model, we can now visualize the output of the heart model.

The second and the third plots show the depolarization events for the atrium and ventricle, respectively, when messages to activate the respective conduction paths are issued. These are effectively A_sense! and V_sense! events that a pacemaker will be able to acquire and analyze to determine whether or not to pace the chambers. The duration between subsequent A_sense! events is determined by the SA node parameters; the duration between V_sense! events is determined by the the RVA node parameters; and the duration between A_sense! and V_sense! events is determined by the conduction path parameters which add a delay to signal propagation.

It is recommended for the reader to think about the model parameters and vary them to reproduce a variety of physiological and pathophysiological conditions.

## Modelling the pacemaker

### Pacing modes

There are several different modes of cardiac pacing, which refer to the ways in which a pacemaker can be programmed to deliver electrical impulses to the heart. The specific mode that is used depends on the specific needs of the patient and the type of arrhythmia or other condition that is being treated. Some common modes of cardiac pacing include:

1. Single-chamber pacing: In this mode, the pacemaker delivers electrical impulses to either the atria or the ventricles, but not both. Single-chamber pacing is used to treat arrhythmias or other conditions that affect the rhythm of a single chamber of the heart.
2. Dual-chamber pacing: In this mode, the pacemaker delivers electrical impulses to both the atria and the ventricles. Dual-chamber pacing is used to treat arrhythmias or other conditions that affect the rhythm of both chambers of the heart.
3. Demand pacing: In this mode, the pacemaker delivers electrical impulses to the heart only when it is needed, based on the heart's own electrical activity. Demand pacing is used to conserve battery life and minimize the risk of overstimulating the heart.
4. Rate-responsive pacing: In this mode, the pacemaker adjusts the rate at which it delivers electrical impulses based on the patient's activity level. Rate-responsive pacing is used to help the heart maintain a consistent rate during different levels of activity.

### Nomenclature

Pacemaker modes are typically described using a standardized nomenclature that consists of a series of letters that indicate the specific features and functions of the pacemaker. The letters used in the nomenclature are typically arranged in a specific order, with the first letter indicating the chamber being paced, the second letter indicating the chamber being sensed, and the third letter indicating the mode of pacing.

Here are some common letters that are used in the nomenclature of pacemaker modes:

• A: Atrium (the upper chamber of the heart)
• V: Ventricle (the lower chamber of the heart)
• D: Demand pacing (delivers electrical impulses only when needed, based on the heart's own electrical activity)
• O: Asynchronous (constant) pacing (delivers electrical impulses at a constant rate, regardless of the heart's own electrical activity)
• R: Rate-responsive pacing (adjusts the rate of pacing based on the patient's activity level)
• I: Inhibited (stopped) pacing (prevents the delivery of electrical impulses when the natural pacemaker of the heart generates an electrical signal)

For example, a pacemaker programmed in DDD mode would be described as "dual-chamber, synchronous, demand pacing," with the first letter "D" indicating that both chambers of the heart are being paced, the second letter "D" indicating that both chambers are being sensed, and the third letter "D" indicating that the pacemaker is using demand pacing.

Most common modes of pacing in clinical practice are VVI, AAI, and DDD. Here, we will create models for VVI and DDD pacemakers.

### VVI pacemaker

VVI pacing is a mode of cardiac pacing that stands for "ventricular inhibited pacing." In this mode, the pacemaker delivers electrical impulses to a ventricle, but it is inhibited (stopped) from delivering electrical impulses when the natural pacemaker of the heart (the SA node) generates an electrical signal. VVI is designed to allow the natural pacemaker of the heart to take over and coordinate the contraction of the ventricles, while providing backup pacing if the natural pacemaker is not functioning properly.

VVI pacing is typically used in patients who have a functional SA node but have problems with the electrical conduction system of the heart. It can also be used in patients who have had a heart attack or other damage to the heart that has disrupted the normal functioning of the electrical conduction system.

As the name suggests, in VVI mode, we only sense the ventricle and also pace only the ventricle. In this sense, we are in the regime of single chamber pacing. We only consider one component of the VVI pacemaker: the lower rate interval (LRI). LRI determines the minimum rate at which the heart must keep beating. For the ventricle, this means that that after every ventricular depolarising event (i.e. V_sense!), if the next natural depolarisation event V_sense! is not received within the LRI, then the pacemaker should deliver the pacing signal V_pace! to the ventricle to force its depolarisation and thus maintain the minimum beating rate at LRI.

The automaton model for this component is shown in the figure below. The two states are LRI (for monitoring LRI) and PAC (for pacing). The model parameters are T_PACE, which represents the duration during which the V_pace! should be delivered (typically one clock cycle), and LRI_def, which represents the pacemaker setting defining the LRI that should be maintained. The automaton has two clocks: LRI, which measures (monitors) the current lower rate interval, and x. The initial state is LRI and whenever a V_sense? signal is received, the clock LRI is rest to LRI_def. Subsequently, the LRI clock decreases by unity at every clock cycle. If this clock reaches zero, this means that a natural V_sense? signal has not been received and thus the pacemaker should deliver a pacing signal V_pace!. In order to do this, the automaton transitions to the PAC state, where it stays for T_PACE period of time before transitioning back to the LRI state.

The above VVI pacemaker logic with an LRI component can be implemented in Collimator through the following Python Script block. The inputs to the automaton are the parameter LRI_def and the signal V_sense?. The output of the automaton is the signal V_pace!, and additionally (if needed for plotting, convenience, and debugging), the node state.

'''
This automaton models a VVI pacemaker with only an LRI component
Inputs:
LRI_def : The lower rate interval (LRI) setting for the pacemaker
V_sense : Message signaling that the ventricle has activated
(depolarised)
Outputs:
node_state: State of this conduction node
V_pace: Message signaling whether the pacemaker should pace (deliver
an electrical impulse to) the ventricle
'''
if time == 0:
from enum import Enum
T_pace = 1 # Clock cycles to pace for
class State(Enum):
LRI = 0 # State to monitor LRI
PAC = 1 # Temporary state for pacing
# Initial state and own clock
state = State.LRI # Initial state is LRI
LRI = LRI_def # Initial value: set LRI clock to LRI_def
V_pace = 0 # Signal to pace the ventricle, initial value:
off.
x = T_pace # Clock to keep track of pacing time
# Transitions from the state LRI
if state is State.LRI:
if V_sense:
LRI = LRI_def # Reset LRI
elif LRI <=0:
state = state.PAC # Transition to pacing state
x = T_pace
LRI = LRI_def
V_pace = 1
# Transitions from the state PAC
elif state is State.PAC:
x = x -1
if x <= 0:
V_pace = 0
state = State.LRI
LRI = LRI - 1 # LRI Clock decreases regardless of the state.
node_state = state.value # Set output node_state to the state of the
automaton.



The above pacemaker can now be combined with the heart model as shown in the figure below

With the LRI_def set to 120, the model output is shown below

Without the pacemaker, the heart would beat at an interval of 170 units of time (see results of the heart model presented above without the pacemaker). With the VVI pacemaker, we can see that the LRI component starts delivering regular pacing signals to maintain an LRI of 120 units of time.

The reader is recommended to vary with the parameters of the heart model and the VVI pacemaker to understand the pacemaker and model behaviour.

### DDD pacemaker

DDD mode is a mode of cardiac pacing that stands for "dual-chamber demand pacing." In this mode, the pacemaker senses and delivers electrical impulses to both the atria and the ventricles, but only when they are needed, based on the heart's own electrical activity. In addition to the LRI component, which maintains the minimum beating rate of the heart, we additionally consider an atrio-ventricular interval (AVI) component. AVI refers to the amount of time that elapses between the delivery (natural or paced) of an electrical impulse to the atria and the delivery of an electrical impulse to the ventricles. The AVI component of a pacemaker maintains synchronisation between the atrium and ventricular excitations. When a defined AVI (AVI_def) is specified, the pacemaker will ensure that after every A_sense! event the longest duration to the next ventricular event (V_sense! or V_pace!) does not exceed AVI_def.

Essentially, in DDD mode, the LRI component determines the beating rate of the heart and the AVI component maintains appropriate synchronisation between the atrial and ventricular contractions. A schematic of these components for a DDD mode pacemaker are shown in the figure below. The parameters are LRI_def and AVI_def, which represent the set values of LRI and AVI, and T_pace, which represents the number of clock cycles for which the pacing should be applied. This automaton listens for A_sense? and V_sense? signals, and based on their analysis, outputs A_pace! and V_pace! actions. The automaton has four states: LRI (for monitoring LRI), AVI (for monitoring AVI), APC (for atrial pacing), and VPC (for ventricular pacing). The key principles to build these components as timed automata are:

• LRI component: Whenever V_sense? signal is received, the LRI clock is reset. After such reset, if A_sense? is not received within the interval LRI_def AVI_def, then atrial pacing A_pace! is delivered.
• AVI component: The automaton enters the AVI state whenever atrial depolarisation occurs (A_sense? or A_pace!). From this state, if no V_sense? signal has been received within the interval AVI_def, then ventricular pacing V_pace! is delivered.

The above DDD pacemaker logic with LRI and AVI components can be implemented in Collimator through the following Python Script block:

'''
This automaton models a DDD pacemaker with an LRI and an AVI component
Inputs:
LRI_def : The lower rate interval (LRI) setting for the pacemaker
AVI_def : The minimum atrio-ventricular interval setting for the
pacemaker
A_sense : Message signaling that the atrium has activated
(depolarised)
V_sense : Message signaling that the ventricle has activated
(depolarised)
Outputs:
node_state: State of this conduction node
A_pace: Message signaling whether the pacemaker should pace (deliver
an electrical impulse to) the atrium
V_pace: Message signaling whether the pacemaker should pace (deliver
an electrical impulse to) the ventricle
'''
if time == 0:
from enum import Enum
T_pace = 1 # Clock cycles to pace for
class State(Enum):
LRI = 0 # State for monitoring LRI
AVI = 1 # State for monitoring AVI
APC = 2 # Temporary state for Atrial pacing
VPC = 3 # Temporary state for Ventricular pacing
# Initial state and own clock
state = State.LRI # Initial state is LRI
LRI = LRI_def # Initial value: set LRI clock to LRI_def
AVI = AVI_def # Initial value: set AVI clock to AVI_def
V_pace = 0 # Signal to pace the ventricle, initial value:
off.
A_pace = 0 # Signal to pace the atrium, initial value: off.
x = T_pace # Clock to keep track of pacing time
# Transitions from the state LRI
if state is State.LRI:
LRI = LRI - 1
if V_sense:
LRI = LRI_def # Reset LRI
elif A_sense:
AVI = AVI_def # Reset AVI
state = State.AVI
elif LRI <= AVI_def:
A_pace = 1
AVI = AVI_def
x = T_pace
state = State.APC
# Transitions from the state AVI
elif state is State.AVI:
AVI = AVI - 1
if V_sense:
LRI = LRI_def # Reset LRI
state = State.LRI
elif AVI <=0 :
LRI = LRI_def # Reset LRI
V_pace = 1
state = State.VPC
x = T_pace
# Transitions from the state VPC
elif state is State.VPC:
x = x-1
LRI = LRI - 1
if x <= 0:
V_pace = 0
state = State.LRI
# Transitions from the state APC
elif state is State.APC:
AVI = AVI - 1
x = x-1
if x <= 0:
A_pace = 0
state = State.AVI
node_state = state.value # Set output node_state to the state of the
automaton.



The complete block diagram including both the heart model and the above DDD pacemaker is shown below.

With LRI_def=120, and AVI_def=15, the model output is shown below.

From the output we observe that the DDD pacemaker (first plot) delivers regular atrial and ventricular pacing signals to maintain the minimum set LRI and AVI intervals.

Further things to try:

1. Vary the parameters of the pacemaker and heart models to observe the pacemaker function and whether it performs adequately across a variety of physiologically realistic heart parameters.

2. Consider building additional pacemaker components: for example:

• implement an Upper Rate Interval (URI) component, that would limit the pacing the ventricular pacing rate to not go above a pre-defined maximum.
• implement Post Ventricular Atrial Refractory Period (PVARP), Ventricular Refractory Period (VRP), and Post Ventricular Atrial Blanking (PVAB) [1,2]

3. Design your own pacemaker algorithm and test it with the heart model.

4. Create more complex heart models by adding more notes and conduction paths.

#### References:

[1] Jiang, Z., Pajic, M., Moarref, S., Alur, R., & Mangharam, R. (2012, March). Modeling and verification of a dual chamber implantable pacemaker. In International Conference on Tools and Algorithms for the Construction and Analysis of Systems (pp. 188-203). Springer, Berlin, Heidelberg. [link]

[2] Chen, T., Diciolla, M., Kwiatkowska, M., & Mereacre, A. (2013, April). A simulink hybrid heart model for quantitative verification of cardiac pacemakers. In Proceedings of the 16th international conference on Hybrid systems: computation and control (pp. 131-136). [link]

[3] Principles of Modeling for Cyber-Physical Systems, University of Virginia (Fall 2020). https://linklab-uva.github.io/modeling_cps/index.html