Hardware in the Loop Implementation of the Oscillator-based Heart Model: a Framework for Testing Medical Devices

: The hardware in the loop technologies allow to simulate physical models in combination with real devices in order to validate the behavior of the latter under different conditions, not easily reproducible in the real world. They are widely used in various industrial applications. In this work we want to extend the methodology to medical devices. These must interact with the patient to obtain the desired clinical result, however, during the development and validation phase of medical devices, the patient cannot be involved in the testing process. In this article the hardware in the loop methodology is proposed starting from a mathematical model of the heart, based on oscillators, that can be used to validate pacemakers or other medical devices.


Introduction
The development and validation of electronic devices, requires to perform a series of tests organized to solicit inputs and outputs with signals very similar to those of the real world.In recent years, hardware in the loop (HIL) [1][2][3][4] methodologies have been added to traditional testing technologies.These are based on the joint simulation of a physical model with a real device through appropriate interfaces [4,5].The idea is to have a model of the real world or part of it that is simulated in real time by appropriate hardware simulators that interact with the system under test through analog or digital peripherals.These methodologies, born mainly for the aerospace and power electronics sector, are also extending to other electronic devices, especially for critical applications.Think for example of medical therapy devices that must interact with a person or part of a person [6][7][8].During the development and validation phase of medical devices, the patient cannot be involved in the design process for several reasons including the fact that the pathology to be resolved must be induced in the patient just when the device is being tested, which is not easy to implement.Having a model that allows to simulate the desired pathologies when and how you want is of great support to the developer of the biomedical device control system.The idea of this article (in Figure 1 the main idea of the paper is shown) is to create a framework for testing biomedical devices that must interact with the human heart.The starting point is the development and implementation of a heart model, as realistic as possible, on which some pathologies can be reproduced.The starting point is the consideration that the human heart is a remarkably engineered oscillator that acts as a variable speed biomechanical pump [9][10][11][12][13].Acting on the parameters of the oscillator it is possible to change the characteristic of the generated signal, enabling the simulation of different heart conditions (it could be controlled to exhibit tachycardia, bradycardia and atrial fibrillation) and also to take into account the variability due to the population characteristics [14].The proposed model is structured in two different parts: the first one describes the electrical conduction system of the heart, through the sino-atrial node (SN), the atrioventricular node (AV) and the His-Purkinje fibers (HP), the second part is focused on the resulting ECG.The electrical conduction system of the heart is described using the delay differential equations, where the time derivatives at the current time depend on the solution and possibly its derivatives at previous times: instead of a simple initial condition, an initial history function needs to be specified.The value of the variables of the equations will determine four currents, that will be added in the equations of the four waves constituting the ECG, that is described using complex ordinary differential equations (ODEs).Then, an analysis of the effect of the variation of parameters is done.The goal is to reproduce some cardiac diseases, in particular tachycardia, bradycardia and atrial fibrillation.This part of the the model is constituted by an experimental work: an accurate analysis of the individual parameters in the electrical conduction system of the heart is done, to understand how they affect the shape of the ECG.The main findings are used to reproduce atrial fibrillation, tachycardia and bradycardia.The proposed model is implemented in a HIL simulator to run both in physiological and pathological condition.The main application of this model is the validation of the pacemakers.Pacemakers normally have sensors to detect events directly in the heart tissue, such as atrial sense and ventricular sense.Using the information from the sensor, the pacemaker decides whether and when to generate a stimulus to the heart [15,16].The test of device is done in physiological and pathological conditions: if the heart is simulated affected by bradycardia, the pacemaker produces the spikes and restores the normal rhythm; otherwise, if the rhythm of the simulated heart is physiological, the pacemaker is silent.The paper it is organized as follows: in Section 2 the physiology of the heart is described and the main equations are reported; in the Section 3 an analysis of the effect of the model parameters on reproducing the diseases is presented; in the Section 4 the hardware in the loop implementation is described and it is applied in Section 5 to the validation of a pacemaker.Finally the conclusions are synthesized in Section 6 .

Physiology of the Heart: the Mathematical Model
The starting point of our work is to define a mathematical model of the heart that can be easily implemented in a realtime simulator.The heart is one of the most important organs of the body and it is one of the most studied ones.Its behaviour is the result of a smart electrical conduction system: in fact, it is usually able to guarantee a mechanical operation during all life of the individual.It can be compared to an oscillator that acts as a biomechanical pump.The process of electrical signal's conduction starts in the Sino-Atrial (SN) node, that is placed in the right atrium at the superior vena cava.When the signal propagates through the atria, it produces a contraction.Then, the electrical pulse reaches the atrioventricular node (AV), that sends the impulse down to the lower heart's chambers, the ventricles.The ventricles, in turn, contract and pump the blood.At the end of this process, the SN node sends another signal to the atria, and the cycle starts again.
The process over described is the generation of a heartbeat.The propagation of the pulse from the AV node to the ventricles is guaranteed by His Purkinje complex [17], which divides the signal in two branches: one branch goes to the left ventricle, and the other one goes to the right.After each electrical excitation (depolarization), the cardiac tissue starts a process of recovery (repolarization), to prepare the cardiac muscle for the next electrical stimulation.The development of dynamical models to produce ECG signals has been the subject of many research efforts.In this work, the method of FitzHugh-Nagumo [11,12,18] equations will be described.The reason of this choice is that this method is more complete with more details.Moreover, it is structured in two parts: the first considers the main pacemakers, SN node, AV node and HP system and the second one describes both the atrial and ventricular muscles, through a system of eight unknowns that contribute to represent the main waves of ECG.A more detailed model gives a higher possibility to identify the parameters that are present in the main diseases and to understand their origin and their localization.The model consists of: • A voltage variable that allows regenerative self-excitation through a positive feedback.It is a cubic term and it represents the non linearity of the system; • A recovery variable, that provides a negative feedback.It is slower and it is the linear part of the system.
The mathematical model of the electrical conduction system of the heart describes all three natural pacemakers by a system of modified van der Pol's equations with unidirectional time-delay velocity coupling.
The first system represents the electrical activity of SN: The second system represents the electrical activity of AV: The third system represents the electrical activity of HP: The parameters present in the equations are: • Damping coefficients for the pacemaker, a 1 = 40, a 2 = 50, a 3 = 50; • Parameters defining the amplitude of a pulse,     The second system of equations represents the ECG's waves.Using the proposed quiescent excitable FHN model the depolarization and repolarization processes in cardiac muscles are described as a system of four sets of ordinary differential equations.
• P wave: • Ta wave: • QRS complex: • T wave The parameters that are involved in the equations of ECG's waves are: The link between the two parts of the mathematical model is constituted by the terms I AT De , I AT Re , I V N De and I V N Re , that represent the ionic currents.In fact, in the second system, they assume different values depending on the signs of the unknowns of the first system.
The values of currents are: • I AT Re : • I V N Re : Total ECG is computed by combining the results of AT and VN muscles, described in the Equation ( 12) where z 0 is a constant value, equal, in this case, to 0.2.The resulting graph is shown in Figure 5: the value on x-axis indicates the time, expressed in seconds, while the value on y-axis indicates the voltage, expressed in voltss.

Analysis of the Diseases Detectable by an ECG
Testing a biomedical device mainly means testing its behaviour under physiological and pathological conditions.The model must be able to reproduce all these conditions by acting on appropriate parameters.At the same time these conditions do not happen in all people in the same way, so it is important to be able to vary the parameters according to this variability.The purpose of this section is to highlight the effect of the model's parameters on certain pathologies, chosen as examples only.Future developments may extend the study to other pathologies.The data used in the simulation are obtained by a dataset available online [19,20].It should be noted that although it is possible to reproduce exactly a certain pathology from the point of view of his ECG, we have taken care of reproducing its "rhythm".As the device you want to validate is a pacemaker whose task is to recognize the distance between peaks.In future developments you will be able to identify exactly the parameters to reproduce a certain waveform to test other types of devices.Future studies must make an accurate analysis of the individual parameters in the electrical conduction system of the hehart, and understand how they affect the shape of the ECG; this is instrumental to understanding the pathology from a medical point of view.
The simulation is done for the unknows y 1 (action potentil of SN) y 2 (action potential of AV) and y 3 (action potential of HP) in the electrical conduction system of the heart.Thanks to this parameter's analysis, it is possible to reproduce the tachycardia, the bradicardya and the atrial fibrillation.

Tachycardia
Tachycardia is a common type of heart rhythm disorder (arrhythmia) in which the heartbeats are faster than normal while at rest.Typically, a beat is around 70-80 beats per minute (bpm) in physiological rest condition becomes higher than 100 bpm (at rest) for sinus tachycardia or bigger 200-300 bpm (at rest) in other pathological conditions.To represent sinus tachycardia on the ECG, the main parameter that has to change is the parameter that controls the rate of pulses in SN node-the parameter f 1 .The higher this parameter, the higher the frequency of heartbeats.
The simulation (Figure 6) occurs considering f 1 = 35 without any other variations to the other parameters.The resulting ECG is faster than ECG in physiological condition, but it has, however, a regular rhythm; P waves are upright, consistent, and normal in morphology.

Bradycardia
Sinus bradycardia is a regular but unusually slow heart beat (50 beats/minute or less at rest).To simulate the effect that bradycardia has on an ECG, the parameter that has to be modified is f 1 , that controls the rate of pulses in SN node: lower it will be, slower will be the trend of ECG.
The simulation (Figure 7) occurs considering f 1 = 18 without any other variations to other parameters.

Atrial Fibrillation
Atrial fibrillation (AF) is an abnormal and irregular heart rhythm in which the electrical signals are generated chaotically throughout the upper atria (chambers) of the heart: in presence of AF, the sinoatrial node in the right atrium produces impulses that are disorganized, causing a irregular conduction of ventricular impulses that generate the heartbeat.
The record of ECG of a patient affected by AF is recognizable and it has particular differences from a physiological ECG.The main sign of atrial fibrillation is the absence of P waves in the ECG: they are replaced with the so called F waves, small irregular undulations that demonstrate the alteration of the beat.The irregular conduction of impulses to the ventricles causes irregular R-R intervals.
In the proposed model, to reproduce AF, P wave is deleted.As consequence, in the system of eight equations that describes ECG, the system of P wave is composed by two zeros ( ż1 = 0, v1 = 0 in the system 4) .
The second thing to do is to make the horizontal tract irregular: f 3 , that controls the amplitude of pulsation in HP fiber, is reduced ( f 3 = 1) and the parameter a 3 , that is the damping coefficient for the pacemaker, is reduced too ( a 3 = 45), to prolong the swing.The last parameter modified is k 4 = 100, to reduce the amplitude of T wave in the ECG.The result of these modification is shown in Figure 8.

Hardware in the Loop Model
Finally the model obtained and described above can be implemented in a hardware in the loop simulator.These simulators consist of a software model of the simulated process and a physical interface to the therapy device.Hardware-in-the-loop configuration would guarantee the veracity of the simulation thanks to an interfacing with the real world [21].The model is based on two part: the equations and a SCADA interface for varying the disease to be reproduced.The general model is shown in Figure 9.It is possible to divide the model in two main parts: the block on the left, that represents the electrical conduction system of the heart, and four blocks on the right, that are the waves of ECG.Every part has inside other blocks which interact among them to reproduce the equations of the model.Figure 10 shows a particular of the implementation of the dalayed equations.The model is linked to an external interface that allows to change the parameters reproducing heart's diseases as output signals.Every input is linked to a probe, to record the changes in the wanted parameter and to make them immediately detectable from the user.The graphical interface (GI) is needful to introduce the diseases in the simulated ECG and it allows to the operator to modulate the parameters that cause the alterations in ECG' s shape.In fact, the GI is organized in a central panel that allows to control the trend of ECG, and in three icons that constitute the possibility to introduce the three explored diseases: tachycardia, bradycardia and atrial fibrillation (Figure 11).At the center of the interface there is a scope that allows to monitor the trend of ECG: the operator, with a simple click, can control the track and find the presence or absence of some diseases.The user can, moreover, choose the time of record before enabling the trigger.In fact, after the simulation starts running, the operator can select when to start to explore the resulting ECG and the duration of the record.
There are three panels around the scope: if the user clicks on a panel, they enter the model of the selected disease and can make some variations to the parameters to accentuate or diminish the state of disease.
On the top left there is the panel of tachycardia (Figure12): entering in this sub-block it is possible, through a slider to regulate the value of f 1 to increment the rhythm of heartbeat.
On the top right there is the panel of bradycardia (Figure 13): as the previous panel it offers the possibility to modify the parameter f 1 , but this time the value can be decremented to makes slower the rhythm of heartbeats.On the bottom center there is the panel of atrial fibrillation (Figure 14), that contains the parameters coeff_Pwave, a 3 , f 3 and k 4 .The user can choose which parameters modify and can see in real time, through the scope, the effect of the made modification on the ECG's trend.The oscilloscope (and the devices in general) is linked to the hardware simulator by means of interfaces.
The waveform of the electrical signal it is visualized in the oscilloscope (Figure 15) The result is a waveform associated with the beating of the heart, with an important diagnostic value.

Application: Test of a Pacemaker
An important application of the realized project is to replace the human heart in the validation of the pacemakers.
A pacemaker is a small device that is placed in the chest or abdomen to help control abnormal heart rhythms.It is inserted in the patient through an invasive procedure, so it is very important to test it before the operation.The simulation of the heart here proposed can be a valid instrument for the test.
The model of pacemaker that will be described is the dual chambers pacemaker DDD that paces both the atrium and the ventricle, senses both chambers, and sensing can both activate or inhibit further pacing [16].
The system is projected as a close loop system.The heart and the pacemaker communicate with each other using broadcast channels.The heart generates Aget and Vget actions, representing atrial and ventricular events that the pacemaker takes as inputs (Figure 16).The pacemaker processes the signals and generates pacing actions AP and VP to the corresponding components in the heart [16].
The described model is connected to the simulated heart, considering as "Aget" the variable x 1 , one of the output of the system of SN conduction, and x 2 , the variable output of the block of AV conduction, as "Vget".
The components present inside the model are [16]: • Lower Rate Interval (LRI): This component keeps the heart rate above a minimum value.The simulation is done in two conditions: • Physiological condition: the parameter f 1 is set to its original value ( f 1 = 22); • Condition of bradycardia: the parameter f 1 is set to a value different from the original one ( f 1 = 8).

Simulation in Physiological Condition
The pacemaker is connected to a model of physiological electrical conduction system of the heart ( f 1 = 22).The output parameters are the atrial events A s , the ventricular events V s , the atrial pacing A p and the ventricular pacing V p .
The atrial events (Figure 17a) follow the events of physiological electrical conduction system of the heart in SN: there is a spike for every waveform present in the original graph; also, ventricular events reproduce the waveform of the original simulation, with a spike for every waves present in the graph of AV (Figure 17b).The delay between SN and AV is respected, as the two results can attest.The atrial pacing, A p , is silent (Figure 17c).This happens because in physiological conditions, the heart rate respects the minimum value imposed by LRI: the atrial events are detected inside this interval and the pacing is not necessary.

Simulation in Case of Bradycardia
The simulation in condition of disease is done in a situation of bradycardia: the parameter f 1 is set at a value lower than physiological one to make slower the rhythm of the heart.
The test is done setting the value of f 1 equal to 8. Figures 18a, 18b, 18c are the outcomes detectable through the scopes.Figure 18a shows the atrial events sensed by the pacemaker, that follow the waveform of the result in the electrical conduction system of the heart affected by bradycardia.The outcome present in Figure 18a shows as the events are less than these of Figure 17a: the frequency is lower and reproduces the lower trend of the result.The heart rate is insufficient for maintain alive the patient, that needs the application of the pacemaker.Figure 18b shows the contribute of pacing from the pacemaker, that restores the physiological rhythm.Making a comparison between the spikes that represent atrial events produced by the electrical conduction system of the heart and the atrial pacing, is possible to see how these two components are complementary: when an atrial event is present, the atrial pace is silent, while when atrial event is not sensed in LRI interval, the atrial pacing is activated.
In agreement with A p , the ventricular pacing V p respects the delay determined from the AVI: the spikes follow the events in A p with a little delay representing the time of conduction from the SN to the AV.

Closed Loop Simulation
For device testing purposes, open loop configuration would be more than sufficient.In this case, the signals are generated and it is verified that the device responds within times defined by the project specification.However, for the completeness of this work a closed loop simulation is presented.In this case, the signals generated by the pacemaker closed on the model of the heart, restarting the physiological beat.The real pacemaker detects a pathological condition and generates a signal that acts on the sino-atrial node, restoring natural peace.So it happens in the model, where the signal introduce a correction to the set of Equations ( 8)- (11), resetting the initial conditions of the controlling equations and restarting the simulation with the right pace.An example is show in Figure 19a, where the heart beat combined with artificial pacing generated by the device.
Finally in Figure 19b a closed loop simulation is shown.the pacemaker detect a condition of delayed heartbeat and generate a response to accelerate the heartbeat and make the condition physiological

Conclusion
This project is focused on the importance of have a complete model of the heart to test and validate new cardiac medical devices before they enter in the market, as they have become more and more critical for the patient safety.The innovation present in the realized model, respect to the previous simulators of the heart, is the use of hardware-in-the-loop systems for testing and design of control systems.
The advantages of using HIL simulator is that the resulting simulation will be simple, because of the graphical logic of the schematic and because of the simple design of SCADA interface, usable for physical tested thanks to its capacity to simulate signals both in physiological and pathological conditions.
The resulting model respects the requirements as it can be used to test new devices.Moreover, it verifies all requirements for modeling simpleness, fidelity and physical testbed.It is possible to consider this model a good alternative to the clinical trials and to the tests on the animals thanks to its veracity, its design user-friendly and its capacity to be personalized from the user to reproduce different heart conditions, as tachycardia, bradycardia and atrial fibrillation.

Figure 1 .
Figure 1.Main features of the proposed methodology.

Figure 2 .Figure 3 .
Figure 2. Simulation of the action potential of Sino-Atrial node SN.

Figure 4 .
Figure 4. Simulation of action potential of HP (His-Purkinje fibers).

Figure 9 .
Figure 9.General model of the Heart implemented in the hardware simulator [21].

Figure 10 .
Figure 10.Implementation of the delayed equations: inside the electrical conduction block.

Figure 12 .
Figure 12.Panel to set the tachycardia in the ECG.Physiological condition.

Figure 13 .
Figure 13.Panel to set the bradycardia in the ECG.Physiological condition.

Figure 14 .
Figure 14.Panel to set the AF in the ECG.Physiological condition.

Figure 16 .
Figure 16.System of heart and pacemaker implemented.

Figure 17 .Figure 18 .
(a) Atrial events sensed by the pacemaker in physiological case.(b) Ventricular events sensed by the pacemaker in physiological case.(c) Atrial pacing in physiological conditions.For all the graphs the x-scale represents the time in seconds, while the y-scale the signal in volts .(a) Atrial events recorded in pathological conditions T. (b) Atrial pacing in pathological conditions.(c) Ventricular pacing in pathological conditions For all the graphs the x-scale represents the time in seconds, while the y-scale the signal in volts .

Figure 19 .
(a) The beat of the heart (yellow) and the response of the pacemaker (cyan) on the same graph.It is possible to see as the pacemaker replace perfectly the missing beats in the case of low rhythm the x-scale represents the time in seconds, while the y-scale the signal in volts .(b) As for (a) but the signal measured in output of HIL hardware.