1 Introduction

Fig. 1
figure 1

Schematic view of the heart, with its distinct waveforms for the corresponding specialized cells, and a normal ECG, in which the T and P waves, PQ and ST segments, RR interval and QRS complex are represented

The physiological functioning of the cardiac system is essentially based on the electrical activity of the heart, and on this basis, the electrocardiogram (ECG) is a classic measurement that characterizes the heart functioning. In fact, the ECG allows one to analyze the heart behavior, evaluating normal and pathological rhythms. Figure 1 presents a schematic picture of an ECG measurement related to a normal cardiac cycle. P wave, QRS complex and T wave can be identified, and each of them is associated with a specific activity of heart physiology. The P wave is associated with the sinoatrial node (SA), the natural pacemaker; the QRS complex is related to the ventricular contraction, being characterized by the atrioventricular node (AV) activity; and the T wave reflects ventricular repolarization, corresponding to the His-Purkinje complex (HP) activity.

In this regard, the behavior of the cardiac system can be understood as a complex network and its mathematical modeling is a challenging topic, being the objective of different research efforts. The use of coupled nonlinear oscillators is an interesting approach for a reduced-order description. The description of the behavior of the natural pacemaker is based on the pioneering work of van der Pol and van der Mark [39], who showed the importance of considering a nonlinear dissipation represented by the classical van der Pol oscillator (vdP). Afterward, Grudziński and Żebrowski [23] proposed a modified van der Pol (mvdP) oscillator including stiffness nonlinearities.

Furthermore, concerning the description of cardiac physiology, it is essential to consider the adoption of coupled nonlinear oscillators. Dos Santos et al. [14] for instance took two asymmetrically coupled mvdP oscillators [23] into account to represent sinoatrial and atrioventricular nodes. The characterization of the ECG signal is possible by considering three-coupled oscillators, as proposed by Gois and Savi [22] who considered three heart nodes: SA, AV and HP. Once again, modified van der Pol oscillators are employed, assuming bidirectional and asymmetric time-delayed couplings. Recently, Cheffer et al. [13] improved the three-coupled oscillator model considering different coupling terms. These models are able to describe different heart rhythms, from normal to pathological behaviors. Moreover, the transitions between different rhythms can be explained by non-deterministic aspects. In this case, it is important to mention the analysis of random connections between oscillators [10,11,12].

It is noteworthy that mathematical models of heart dynamics can play a key role in the development of rhythm management devices such as artificial pacemakers and implantable cardioverter-defibrillators. In this regard, the control of cardiac rhythms has been investigated by means of different approaches. Garfinkel et al. [19, 20] presented the classical chaos control OGY method [32] on rabbit cardiac muscle. Afterward, more sophisticated chaos control methods were employed for this purpose. Ferreira et al. [17] employed time-delayed feedback control for a natural pacemaker described by the modified van der Pol oscillator [22]. A more complete analysis was developed by Ferreira et al. [18] who treated ECG signals described by the three-coupled oscillator model [22]. The results showed the possibility of avoiding critical physiological situations by promoting the stabilization of unstable periodic orbits embedded in chaotic attractors.

In addition, Lounis et al. [30] employed a high-order control method to treat a heartbeat dynamics described by the model proposed by Quiroz-Juarez et al. [35]. Khan and Nigar [27] proposed a Lyapunov-based active controller considering synchronization by means of a fractional-order chaotic system model.

The controller design represents a major challenge since it must deal with all nonlinearities inherent in the cardiac system, as well as modeling inaccuracies and external disturbances. State observers can handle the first task [21] but may not be a suitable choice for the other issues. Machine learning, in turn, can offer some appealing options to deal with it. Artificial neural networks (ANNs), for instance, have been used to identify and classify heart rhythm diseases [1, 16, 37, 40]. Due to their learning and approximation capabilities, neural networks have also been used in control applications to compensate model uncertainties and disturbances [3, 15, 26, 28].

This paper deals with the intelligent control of cardiac rhythms by means of the feedback linearization approach with an embedded artificial neural network. The boundedness and convergence properties of the control error are proven by means of the Lyapunov stability theory. Following reference [3], a radial basis function (RBF) network with a single hidden layer and only one input neuron is adopted. The chosen network architecture allows universal approximation [33] and avoids the issues related to the curse of dimensionality [2]. The aforementioned features minimize the computational complexity of the resulting intelligent controller, making it light enough to be deployed in cardiac rhythm management devices. Furthermore, by assuming that the mathematical model is not available to the control system designer and adopting an online approach to update the weights of the ANNs, the neural network is able to adapt to different individuals and continuously approximate their cardiac dynamics, denoting the capacity of the proposed scheme to deal with both inter- and intrapatient variability. Heart dynamics is represented by synthetic electrocardiograms (ECGs) produced by a reduced-order model considering a three-oscillator model with delayed coupling terms [13, 22]. In this regard, it should be pointed out that the mathematical model is only employed to simulate the cardiac response to the control signal. Different pathological responses are investigated showing that the intelligent controller is able to stabilize a desired rhythm and avoid undesired ones.

2 Mathematical modeling

Heart rhythms are commonly inferred from the electrical activity of the cardiac system, which in turn can be described by means of three coupled oscillators [13, 22]. This work investigates the control of heart electrical activity considering synthetic ECGs produced by this mathematical model. Figure 2 shows the conceptual diagram adopted for the cardiac system, including the HP complex and both sinoatrial and atrioventricular nodes, as well as all possible couplings and external excitations.

Fig. 2
figure 2

Conceptual diagram of the cardiac system, including both sinoatrial and atrioventricular nodes, the His-Purkinje complex, all possible couplings and corresponding external excitations

Now, modified van der Pol oscillators [23] are chosen to represent the HP complex and the sinoatrial and atrioventricular nodes, with time-delayed couplings being assumed to properly tune the transmission time between these oscillators. Each coupling can be individually defined, which allows for asymmetrical and bidirectional characteristics. The introduction of external stimuli in the model enables the representation of abnormal rhythms, in addition to the self-excitatory behavior typically generated by the central nervous system. The resulting cardiac system is then described by the following equations [12]:

$$\begin{aligned} \ddot{u}_{\text {SA}} =&\, F_{\text {SA}}(t) - \alpha _{\text {SA}}\,\dot{u}_{\text {SA}}(u_{\text {SA}} - \nu _{\text {SA}_1})(u_{\text {SA}} - \nu _{\text {SA}_2})\nonumber \\&+-\frac{ u_{\text {SA}}(u_{\text {SA}} + d_{\text {SA}})(u_{\text {SA}} + e_{\text {SA}})}{d_{\text {SA}}\,e_{\text {SA}}}\nonumber \\&- k_{\text {AV}-\text {SA}}\,u_{\text {SA}} + k^{\tau }_{\text {AV}-\text {SA}}\,u_{\text {AV}}^{\tau _{\text {AV}-\text {SA}}}\nonumber \\&+- k_{\text {HP}-\text {SA}}\,u_{\text {SA}} + k^{\tau }_{\text {HP}-\text {SA}}\, u_{\text {HP}}^{\tau _{\text {HP}-\text {SA}}} \end{aligned}$$
(1)
$$\begin{aligned} \ddot{u}_{\text {AV}} =&\, F_{\text {AV}}(t) - \alpha _{\text {AV}}\,\dot{u}_{\text {AV}}(u_{\text {AV}} - \nu _{\text {AV}_1})(u_{\text {AV}} - \nu _{\text {AV}_2})\nonumber \\&+- \frac{u_{\text {AV}} (u_{\text {AV}} + d_{\text {AV}})(u_{\text {AV}} + e_{AV})}{d_{\text {AV}}\,e_{\text {AV}}}\nonumber \\&- k_{\text {SA}-\text {AV}}\,u_{\text {AV}} + k^{\tau }_{\text {SA}-\text {AV}}\,u_{\text {SA}}^{\tau _{\text {SA}-\text {AV}}}\nonumber \\&+- k_{\text {HP}-\text {AV}}\,u_{\text {AV}} + k^{\tau }_{\text {HP}-\text {AV}}\,u_{\text {HP}}^{\tau _{\text {HP}-\text {AV}}} \end{aligned}$$
(2)
$$\begin{aligned} \ddot{u}_{\text {HP}} =&\, F_{\text {HP}}(t) - \alpha _{\text {HP}}\,\dot{u}_{\text {HP}}(u_{\text {HP}} - \nu _{\text {HP}_1})(u_{\text {HP}} - \nu _{\text {HP}_2})\nonumber \\&v -\frac{u_{\text {HP}}(u_{\text {HP}} + d_{\text {HP}})(u_{\text {HP}} + e_{\text {HP}})}{d_{\text {HP}}\,e_{\text {HP}}}\nonumber \\&-k_{\text {SA}-\text {HP}}\,u_{\text {HP}} + k^{\tau }_{\text {SA}-\text {HP}}\,u_{\text {SA}}^{\tau _{\text {SA}-\text {HP}}}\nonumber \\&+- k_{\text {AV}-\text {HP}}\,u_{\text {HP}} + k^{\tau }_{\text {AV}-\text {HP}}\,u_{\text {AV}}^{\tau _{\text {AV}-\text {HP}}} \end{aligned}$$
(3)

where \(k_{m-n}\) and \(k_{m-n}^{\tau }\) are the coupling coefficients between m and n nodes, with m and n standing for SA, AV or HP; \(x_{i}^{\tau _{m-n}} = x_{i} (t-\tau _{m-n})\) represent the delayed terms, with \( \tau _{m-n} \) being the time delay; and the external excitation \(F_{m}(t) = \rho _{m} \sin (\omega _{m} t)\) is introduced as a lumped model of spatiotemporal aspects.

Moreover, it is worth noting that the periodic behavior associated with atrial fibrillation (AF) is captured by the harmonic form of \(F_{m}\) [25, 36], which in fact, due to its explicit dependence on time, ends up increasing the dimension of the system.

The ECG can be represented by incorporating the signals of the three oscillators, being expressed as a linear combination of the state variables [22]:

$$\begin{aligned} x = \text {ECG} = \beta _0 + \beta _1\,u_{\text {SA}} + \beta _2\,u_{\text {AV}} + \beta _3\,u_{\text {HP}} \end{aligned}$$
(4)

with \( \beta _0 \), \( \beta _1 \), \( \beta _2 \) and \( \beta _3 \) being parameters, so that the derivative of the ECG with respect to t becomes

$$\begin{aligned} \dot{x} =\frac{d}{dt}(\text {ECG}) =\beta _1\,\dot{u}_{\text {SA}} + \beta _2\,\dot{u}_{\text {AV}} + \beta _3\,\dot{u}_{\text {HP}} \end{aligned}$$
(5)

Equations (4) and (5) can be used to represent the ECG phase space, favoring a qualitative assessment of cardiac cycle.

Since governing equations are presented in dimensionless form, it is interesting to define a dimensional time \(\bar{t}\)[s]\(: \bar{t} = \beta _t t\), where \(\beta _t\) is expressed in seconds and can be estimated by the ratio between real RR interval, RR\(_\text {exp}\), and numerical RR interval, RR\(_\text {num}\), \(\beta _t = \text {mean}(\text {RR}_\text {exp})/\text {mean}(\text {RR}_\text {num})\).

Table 1 Cardiac system parameters [11, 13]

2.1 Cardiac rhythms

In order to assess the model’s ability to represent cardiac dynamics, six different rhythms are investigated: normal rhythm, ventricular flutter, two different ventricular fibrillation (with and without external stimulus), atrial flutter, and atrial fibrillation. The dynamic model is numerically implemented in C++ using the fourth order Runge–Kutta method with sampling rate of 1 kHz. The model parameters are presented in the Table 1. The numerical results obtained with the adopted model are compared with the real ECG data and are shown in Figs. 3,4, 5, 6, 7 and 8, with the real data provided by the PhysioNet Databases [34]. For all simulations, it is considered that \(\beta _0 = 1\) mV, \(\beta _1 = 0.06\) mV, \(\beta _2 = 0.1\) mV, and \(\beta _3 = 0.3\) mV. Initial conditions are defined as \(\varvec{u}_0 = [-0.1 ~ -0.6 ~ -3.3 ]^\top \) and \(\dot{\varvec{u}}_0 = [0.025 ~ 0.1 ~ 2/3 ]^\top \), with \(\varvec{u} = [u_\text {SA} ~ u_\text {AV} ~ u_\text {HP}]^\top \). Both model parameters and initial conditions were chosen according to [11, 13] in order to ensure the proper emulation of typical cardiac rhythms.

Fig. 3
figure 3

Normal cardiac rhythm: a real ECG signal [34]; b simulated time series; c phase space representation of the simulated time series. Note the close agreement between real and simulated ECG signals, especially the P and T waves and the QRS complex

The expected normal heart rhythm is presented in Fig. 3 showing a close agreement between the real ECG signal and the simulated one, respectively (Fig. 3a and b). It should be pointed out that simulations capture the main features of the real ECG signal, characterized by the P and T waves and the QRS complex. Numerical results can also be easily represented in phase space form (Fig. 3c), allowing a better visualization of normal cardiac cycle, which facilitates comparison with abnormal rhythms.

Fig. 4
figure 4

Ventricular flutter: a real ECG signal [34]; b simulated time series; c phase space representation of the simulated time series. Both real and simulated ECG signals show no clear distinction between QRS complex, ST segment and T wave

Ventricular flutter is a pathological rhythm associated with high-frequency (300 bpm) ventricular contraction and typically without clear distinction between QRS complex, ST segment and T wave, as seen in actual ECG data (Fig. 4a), and corresponding simulated signal (Fig. 4b).

Fig. 5
figure 5

Ventricular fibrillation with external stimulus: a real ECG signal [34]; b simulated time series; c phase space representation of the simulated time series clearly revealing its chaotic behavior

Fig. 6
figure 6

Ventricular fibrillation without external stimulus: a real ECG signal [34]; b simulated time series; c phase space representation of the simulated time series clearly revealing its chaotic behavior

Figures 5 and 6 are related to the ventricular fibrillation pathology. Their irregular and chaotic behavior can be manifested in several variations with the P waves, QRS complex, and T waves that are not recognized. Regarding its mathematical description, basically, two different approaches can be employed [12]. The first one takes into account an external stimulus in the HP oscillator, as shown in Fig. 5, and the second does not consider it, as shown in Fig. 6. In both cases, it is noticeable that the model is capable of representing this type of arrhythmia.

Fig. 7
figure 7

Atrial flutter: a real ECG signal [34]; b simulated time series; c phase space representation of the simulated time series. Both real and simulated ECG signals show the typical f waves and “sawtooth” P waves

Atrial flutter is a rhythmic disorder characterized by an increase in heart rate, usually 300 bpm, but which can range from 240 to 430 bpm [9]. Figure 7 presents typical results related to this pathology, such as a comparison between the real ECG signal (Fig. 7a), and the corresponding simulation results (Fig. 7b), as well as the numerically obtained phase space (Fig. 7c). Note the qualitative agreement between the real and simulated results, particularly seen in typical f waves and clear “sawtooth” shaped P waves.

Fig. 8
figure 8

Atrial fibrillation: a real ECG signal [34]; b simulated time series; c phase space representation of the simulated time series. Note that both real and simulated ECG signals have irregular RR intervals

Atrial fibrillation is a pathology characterized by an irregular RR interval and multiple random impulses [31]. Figure 8 shows this abnormal rhythm, presenting a comparative analysis between real and simulated ECG data, respectively, as shown in Fig. 8(a) and (b). It is worth mentioning that once again the numerical model is able to capture the general behavior of the real ECG signal. The numerically obtained phase space is depicted in Fig. 8(c).

In the next section, in order to turn these pathological rhythms into normal ones, an intelligent controller is introduced. Nevertheless, it is important to emphasize that, even though the adopted model has an essential role in the simulation of heart rhythms, it is assumed to be not known by the controller’s designer. Thus, the equations (1)–(3) and their corresponding parameters are not used in the control law, but only in the simulator, which in turn is needed to evaluate the performance of the control.

3 Intelligent controller

Intelligent control schemes are able to adapt, learn from experience and predict plant dynamics. They have been successfully employed in the control of chaotic [4, 6], robotic [7, 29], underactuated [8, 28] and other uncertain nonlinear systems [5, 15].

Thus, in view of the design of a control system for the heart dynamics, the adopted mathematical model is rewritten in the following form

$$\begin{aligned} \ddot{x} = f + v + d \end{aligned}$$
(6)

where v is the control signal, assumed to be applied to the HP complex, f represents the part of the vector field (1)–(3) that is assumed to be known by the controller designer, d stands for unmodeled dynamics and occasional perturbations, and \((x,\dot{x})\) are the states to be controlled.

Following the feedback linearization approach [38], the control law for a system represented by equation (6) can be designed as follows:

$$\begin{aligned} v = -\hat{f} - \hat{d} + \ddot{x}_\text {d} - 2\lambda \dot{\tilde{x}} - \lambda ^2 \tilde{x} \end{aligned}$$
(7)

with \(\hat{f}\) and \(\hat{d}\) being, respectively, estimates for f and d, \(\tilde{x} = x - x_\text {d}\) representing the tracking error associated with the desired state \(x_\text {d}\), and \(\lambda \) being a strictly positive constant.

Applying the control law (7) to (6) and assuming that all modeling uncertainties are properly represented by d, i.e. \(f=\hat{f}\) is well known, we get

$$\begin{aligned} \ddot{\tilde{x}} + 2\lambda \dot{\tilde{x}} + \lambda ^2 \tilde{x} = \tilde{d} \end{aligned}$$
(8)

with \(\tilde{d} = d - \hat{d}\) being the approximation error.

Now, by defining a combined error signal inspired by the sliding mode method \(s(x,\dot{x}) = \dot{\tilde{x}} + \lambda \tilde{x}\), the closed-loop dynamics (8) becomes

$$\begin{aligned} \dot{s} + \lambda s = \tilde{d} \end{aligned}$$
(9)

From (9), it can be seen that in the case of perfect estimation, i.e. \(\hat{d}=d\), the combined error s and therefore the tracking error \(\tilde{x}\) converges to zero. Perfect estimation, however, is quite hard to obtain in real-world applications. In these cases, the closed-loop dynamics is driven by the approximation error \(\tilde{d}\). As a matter of fact, it suggests that the signal s may also represent a reasonable metric and help to compute an estimate \(\hat{d}(s)\).

Recalling that radial basis function (RBF) networks can perform universal approximation [33], it can be used to estimate d with to any desired degree of accuracy \(\varepsilon \), i.e. \(d(x,\dot{x},t)=\hat{d}^*(s(x,\dot{x}))+\epsilon (t)\), with \(\hat{d}^*(s)\) being the optimal estimate and \(\vert \epsilon (t)\vert \le \varepsilon \).

Thus, a RBF network, as depicted in Fig. 9, is adopted to compute \(\hat{d}\):

$$\begin{aligned} \hat{d} = \varvec{w}^\top {\psi }(s) \end{aligned}$$
(10)

where \({w} = [w_1 ~ \ldots ~ w_n]\) is the weight vector and \({\psi } = [\psi _1 ~ \ldots ~ \psi _n]\) represents the vector of activation functions \(\psi _i\), with n being the number of neurons in the hidden layer.

The chosen input to the neural network is the combined error measure s, which merges the error \(\tilde{x}\) and its time derivative \(\dot{\tilde{x}}\) into a single signal. By adopting s as the single input, instead of the two state errors, we are able to reduce the complexity order of the neural network and make it light enough to be deployed in cardiac rhythm management devices.

Fig. 9
figure 9

Radial basis function network with one input, n neurons in the hidden layer and one output

The boundedness and convergence properties of the closed-loop signals s and \(\varvec{w}\) can be investigated by means of a Lyapunov-like stability analysis. First, let the difference between the actual and optimal weight vector, respectively, \(\varvec{w}\) and \(\varvec{w}^*\), be defined as \(\varvec{\delta } = \varvec{w} - \varvec{w}^*\).

Remembering that \(\tilde{d} = d - \hat{d}\), with \(d=\hat{d}^*+\epsilon \) and \(\hat{d} = \varvec{w}^\top {\psi }\), Eq. (9) becomes

$$\begin{aligned} \begin{aligned} \dot{s} + \lambda s&= d - \hat{d}\\&= \hat{d}^*+ \epsilon - \hat{d}\\&= -[\varvec{w}-\varvec{w}^*]^\top \varvec{\psi } + \epsilon \\&= -\varvec{\delta }^\top \varvec{\psi } + \epsilon \end{aligned} \end{aligned}$$

By conveniently rewriting the above equation, we get

$$\begin{aligned} \dot{s} = -\lambda s - \varvec{\delta }^\top \varvec{\psi } + \epsilon \end{aligned}$$
(11)

which clearly shows that the closed-loop dynamics is driven by approximation errors. This confirms the importance of adopting a neural network with universal approximation capability [33] and whose weights can be learned online.

Now, let a positive-definite function V be defined as

$$\begin{aligned} V(t) = \frac{1}{2} s^2 + \frac{1}{2\eta } \varvec{\delta }^\top \varvec{\delta } \end{aligned}$$
(12)

where \(\eta \) is a strictly positive constant.

It is important to note that the adopted Lyapunov function is globally positive definite, \(V\ge 0\), being equal to zero when \(s=0\) and \(\varvec{\delta }=\varvec{0}\) (\(\varvec{w}=\varvec{w}^*\)).

Now, since \(\dot{\varvec{\delta }} = \dot{\varvec{w}}\), the time derivative of V becomes

$$\begin{aligned} \begin{aligned} \dot{V}(t)&= s \dot{s} + \eta ^{-1} \varvec{\delta }^\top \dot{{w}}\\&= -s[\lambda s + \varvec{\delta }^\top {\psi } - \epsilon ] + \eta ^{-1} \varvec{\delta }^\top \dot{{w}}\\&= -s[\lambda s - \epsilon ] + \eta ^{-1} \varvec{\delta }^\top [\dot{\varvec{w}} - \eta s{\psi }] \end{aligned} \end{aligned}$$

Hence, by updating \(\varvec{w}\) according to \(\dot{\varvec{w}} = \eta s \varvec{\psi }\), \(\dot{V}\) becomes

$$\begin{aligned} \dot{V}(t) = -[\lambda s - \epsilon ]s \le - [\lambda \vert s\vert - \varepsilon ]\vert s \vert \end{aligned}$$
(13)

However, Eq. (13) implies that the bounds of \(\varvec{w}\) cannot be guaranteed when \(\vert s \vert \le \varepsilon / \lambda \). To overcome this issue, the projection algorithm [24] can be evoked to ensure that \(\varvec{w}\) will remain within a convex region \(\mathcal {W} = \{\varvec{w} \in \mathbb {R}^n: \varvec{w} ^\top \varvec{w} \le \mu ^2 \}\):

$$\begin{aligned} \dot{\varvec{w}} = \left\{ \begin{array}{ll} \eta s {\psi } &{}\quad \text {if}~\Vert \varvec{w} \Vert _2< \mu ~\text {or} \\ &{}\quad \text {if}~\Vert \varvec{w} \Vert _2 = \mu ~\text {and}~ \eta s \varvec{w}^\top \varvec{\psi } < 0 \\ \left( \varvec{I} - \frac{\varvec{w} \varvec{w}^\top }{\varvec{w}^\top \varvec{w}} \right) \eta s {\psi } &{}\quad \text {otherwise} \end{array} \right. \end{aligned}$$
(14)

where \(\mu \) is the desired upper bound of \(\Vert \varvec{w} \Vert _2\).

Since \(\Vert \varvec{w}(0) \Vert _2 \le \mu \), it follows that \(\vert s \vert \le \varepsilon / \lambda \) and \(\Vert \varvec{w}(t) \Vert _2 \le \mu \) as \(t \rightarrow \infty \). Hence, remembering that \(s = \dot{\tilde{x}} + \lambda \tilde{x}\), we have

$$\begin{aligned} -\lambda ^{-1}\varepsilon \le \dot{\tilde{x}} + \lambda \tilde{x} \le \lambda ^{-1}\varepsilon \end{aligned}$$
(15)

Thus, multiplying (15) by \(e^{\lambda t}\) gives

$$\begin{aligned} -\lambda ^{-1}\varepsilon \,e^{\lambda t} \le \frac{d}{dt} \left( \tilde{x} e^{\lambda t} \right) \le \lambda ^{-1}\varepsilon \,e^{\lambda t} \end{aligned}$$
(16)

Integrating (16) between 0 and t yields

$$\begin{aligned}{} & {} -\frac{\varepsilon }{\lambda ^2} e^{\lambda t} - \left[ \vert \tilde{x} (0)\vert + \frac{\varepsilon }{\lambda ^2} \right] \nonumber \\{} & {} \quad \le \tilde{x} e^{\lambda t} \le \frac{\varepsilon }{\lambda ^2} e^{\lambda t} + \left[ \vert \tilde{x} (0)\vert + \frac{\varepsilon }{\lambda ^2} \right] \end{aligned}$$
(17)

By dividing (17) by \(e^{\lambda t}\)

$$\begin{aligned}{} & {} -\frac{\varepsilon }{\lambda ^2} - \left[ \vert \tilde{x} (0)\vert + \frac{\varepsilon }{\lambda ^2} \right] e^{- \lambda t} \nonumber \\{} & {} \quad \le \tilde{x} \le \frac{\varepsilon }{\lambda ^2} + \left[ \vert \tilde{x} (0)\vert + \frac{\varepsilon }{\lambda ^2} \right] e^{- \lambda t} \end{aligned}$$
(18)

it follows, for \(t \rightarrow \infty \), that

$$\begin{aligned} -\frac{\varepsilon }{\lambda ^2} \le \tilde{x} \le \frac{\varepsilon }{\lambda ^2} \end{aligned}$$
(19)

Applying (19) to (15), it can be verified that

$$\begin{aligned} -2\frac{\varepsilon }{\lambda } \le \dot{\tilde{x}} \le 2\frac{\varepsilon }{\lambda } \end{aligned}$$
(20)

Therefore, it is possible to conclude that the controller ensures the exponential convergence of the tracking error to the closed region \(\mathcal {X} = \{ (\tilde{x},\dot{\tilde{x}}) \in \mathbb {R}^2: \vert \tilde{x}\vert \le \varepsilon \lambda ^{-2} \, \text {and} \, \vert \dot{\tilde{x}}\vert \le 2\varepsilon \lambda ^{-1}\}\).

4 Rhythm control

The proposed intelligent controller is now evaluated by means of numerical simulations at a sampling rate of 100 Hz. The desired states are extracted from a expected normal heart cycle, which means that the controller’s main goal is to achieve a normal rhythm while avoiding pathological behavior. Equations (1)–(5) are used to simulate heart dynamics by computing x and \(\dot{x}\). Four different pathologies are investigated: ventricular flutter, two different ventricular fibrillation cases, atrial flutter, and atrial fibrillation. First, the intelligent control law is compared to the conventional one in the case of ventricular flutter. Afterward, the intelligent controller is employed to prevent the other abnormal rhythms. Figures 10, 11, 12, 13, 14, and 15 show the obtained results.

The controller parameter is set to \(\lambda = 10\). Assuming that no prior knowledge about the heart model is available to the control system designer, i.e. \(\hat{f} = 0\), the ability of \(\hat{d}\) to handle all neglected dynamical effects is investigated. Six neurons with Gaussian functions are chosen for the RBF network: \(\psi _i(s; c_i, \sigma _i) = \exp \{ -0.5[(s - c_i)/\sigma _i]^2 \}\), with \(i = 1, \ldots , 6\). The centers and widths are chosen as follows \(\varvec{c} = [-\phi /2; -\phi /8;\) \(-\phi /16; \phi /16; \phi /8; \phi /2]\) and \(\varvec{\sigma } = [\phi /2; \phi /3; \phi /6; \phi /6; \phi /3; \phi /2]\), respectively, with \(\phi =20\) being a tuning parameter. The weight vector is initialized as \(\varvec{w} = \varvec{0}\) and updated according to (14), with a learning rate \(\eta = 100\). It is worth mentioning that the conventional controller used in comparative analysis is easily obtained by setting the learning rate to zero, which completely eliminates the neural network contribution to the control law.

Fig. 10
figure 10

Control of ventricular flutter: a ECG with conventional scheme, b ECG with intelligent scheme, c control error \(\tilde{x}\), and d control signal v. Note that the intelligent controller is able to stabilize the expected normal rhythm, while the conventional one fails

Fig. 11
figure 11

Control of ventricular flutter: Phase space with a conventional scheme and b intelligent scheme. The improved performance of the intelligent controller can be clearly observed in the phase space on the left

Figures 10 and 11 show a comparison between conventional and intelligent schemes applied to the control of ventricular flutter pathology. As can be seen, after turning on the controller at \(t = 16\) s, the intelligent approach is able to stabilize the expected normal rhythm (Fig. 10b), while the conventional one fails (Fig. 10a). The intelligent controller (Fig. 10(b)), allows the expected normal rhythm to be achieved, considerably decreasing the heart rate to around 70 bpm. It should also be noted that the proposed scheme drastically reduces the control error (Fig. 10c), being able to provide an ECG signal with clearly evident QRS complex and both P and T waves (Fig. 10b), while in the conventional approach these characteristics are not properly distinguishable (Fig. 10a), although it seems to at least try to approximate the PQ segment. Another point to be highlighted is that the intelligent scheme, due to the capacity of the adaptive neural network to approximate heart dynamics, provides a very reduced level of control effort (Fig. 10d), when compared to the conventional approach.

The phase spaces depicted in Fig. 11 for both conventional and intelligent approaches also clearly emphasize the strongly improved performance of the proposed control scheme and its ability to turn a pathological cardiac rhythm into a normal one. Therefore, considering the inefficacy of the conventional controller to stabilize the expected normal rhythm, only the proposed intelligent scheme is considered for the other pathologies.

Fig. 12
figure 12

Control of ventricular fibrillation with external stimulus: a ECG with intelligent scheme, b control signal v, and c phase space. The intelligent controller is able to quickly turn a pathological rhythm into a normal one

Fig. 13
figure 13

Control of ventricular fibrillation without external stimulus: a ECG with intelligent scheme, b control signal v, and c phase space. Normal rhythm stabilized by the intelligent controller showing QRS complex and P and T waves

The control of ventricular fibrillation is evaluated by taking into account two different situations: with and without external stimulus, as shown in Fig. 12 and Fig. 13, respectively. As can be seen in Figs. 12(a) and 13(a), the intelligent controller is once again able to stabilize an expected normal rhythm from a pathological one. In both circumstances, with and without external stimulus, the QRS complex and both P and T waves can be clearly observed, as expected in normal behavior. It is also important to highlight the ability of the proposed scheme to deal with the R and S peaks, even if it requires a stronger response from the controller, as can be seen in Figs. 12(b) and 13(b). The corresponding phase spaces, shown in Figs. 12(c) and 13(c), confirm the ability of the proposed scheme to stabilize a normal rhythm. It is worth noting the accurate tracking of the inner loop around the origin, which indeed agrees with what can be observed in the stabilization of P and T waves.

Fig. 14
figure 14

Control of atrial flutter: a ECG with intelligent scheme, b control signal v, and c phase space. The intelligent controller is able to stabilize the heart rate by eliminating the f waves and regulating both Q–S time and RR interval

Atrial flutter arrhythmia is now in focus (Fig. 14), showing that the proposed intelligent controller is able to normalize heart rate. By inspecting Fig. 14(a), it can be seen that the Q–S time duration is reduced, the RR interval is regulated and the f waves are eliminated. The QRS complex is easily recognized, even with overshoots at the R vertices, but with irregular peaks associated with P and T waves. In fact, due to this behavior, the controller is quite demanded (Fig. 14b), making its actuation more pronounced when compared to other simulations. When considering the phase plane representation, Fig. 14(c), it can be observed that the intelligent controller changes the loop detected on the left side in the pathological behavior, reducing its amplitude and tending to attract the external loop to a normal rhythm.

Fig. 15
figure 15

Control of atrial fibrillation: a ECG with intelligent scheme, b control signal v, and c phase space. Despite the overshoots in the R peaks, the intelligent controller is again able to settle into a normal heart rate

Finally, atrial fibrillation is also taken into account, with results shown in Fig. 15. This abnormal rhythm is characterized by an irregular RR interval, but the intelligent controller is able to turn it into normal behavior, Fig. 15(a). The stabilized ECG shows P, QRS and T waves, but some overshoots are recognized in the R peaks, which can be correlated with the corresponding peaks in the control signal, Fig. 15(b). The phase plane is shown in Fig. 15(c), showing that the controller is able to approximate the inner loop, which emphasizes the tracking of P and T waves. The outer loop, however, is not perfectly captured, which can be confirmed by the small residual error associated with the QRS complex.

It is also worth mentioning that, by setting \(\hat{f}=0\) in the control law, it is assumed that the heart dynamics is fully compensated by \(\hat{d}\), the output of the artificial neural network. As a matter of fact, since the Eqs. (1)–(3) and their corresponding parameters are not considered in the control law, the robustness of the proposed intelligent controller against unmodeled dynamics can be corroborated by the presented results. For healthcare applications, a robust controller is crucial to deal with both inter- and intrapatient variability.

5 Concluding remarks

This paper investigates the control of the electrical activity of the heart. A mathematical model based on three coupled nonlinear oscillators is employed to describe cardiac rhythms, being able to represent both normal and pathological behaviors. An intelligent controller is then proposed to avoid pathological behaviors, by stabilizing the heart dynamics in a normal rhythm. Considering its universal approximation property, a radial basis function network is embedded in the control law to compensate for unmodeled dynamics. Furthermore, a learning scheme designed by means of the Lyapunov stability analysis allows the weights of the neural network to be adjusted online. These features, in fact, allow the adopted neural network to adapt to different individuals and continuously approach their cardiac dynamics, which confers the ability to deal with intra- and interpatient variability. Numerical simulations are carried out considering four different pathologies: ventricular flutter, two different ventricular fibrillation cases, atrial flutter, and atrial fibrillation. The obtained results show that the controller is able to perform rhythm control, avoiding critical cardiac behaviors.