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 .
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:
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.
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.
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.
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 are a type of finite state machine that can model systems with both discrete and continuous behaviors. They are used to describe and analyze 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].
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:
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:
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.
The conduction path has two main functions:
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:
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.
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.
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:
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:
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 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.
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 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:
The above DDD pacemaker logic with LRI and AVI components can be implemented in Collimator through the following Python Script block:
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:
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.
 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]
 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]
 Principles of Modeling for Cyber-Physical Systems, University of Virginia (Fall 2020). https://linklab-uva.github.io/modeling_cps/index.html