1 Introduction

In North America and Europe, between 50 and 100 sudden unexpected cardiac failure deaths occur every year per a population of 100,000. This condition is even worse in Latin America. Heart diseases that lead to cardiac failure remain as the most important cause of death accounting for more than 17 million deaths per year [23]. These diseases produce abnormalities in the heart beat rhythm, or arrhythmias, which are caused by irregular (faster or slower) electrical impulses that coordinate the heart’s normal operation [26]. Most of these abnormalities are not dangerous, but if they remain untreated, more complex arrhythmias may appear yielding to life threatening events.

Correct characterization of these atypical behaviors is important when trying to achieve the accurate classification of normal and abnormal heart activity. This fact is truly important considering the effect of correct and opportune diagnosis on the patient survival. Indeed, several studies have proven that significant progress has been made in the prevention of deaths resulting from the correct prediction of severe heart arrhythmias [15]. Since the nineteenth century, electrocardiograph devices have allowed the recording of both regular and unusual electrocardiographic signals [10]. The constant evolution of clinical electrophysiology has provided detailed descriptions of the normal heart beat and some different types of abnormalities.

The emergence of modern technologies has transformed the way that physicians handle treatment and prevention of heart diseases. Therefore, automatic classification of EKG signals has received great attention given that the early detection of heart diseases can prolong life and enhance the life quality through appropriate treatment. Therefore, in recent years, there have been numerous research efforts analyzing the EKG signals by automatic signal processing algorithms. Indeed, there is a large number of publications documenting methods to classify certain arrhythmia in EKG signals [2, 20, 21, 31].

All these studies have used the fact that the state of cardiac health is generally reflected in the shape of the EKG waveform and heart beat rate. Indeed, it has been recognized that this waveform may contain important pointers to the nature of diseases afflicting the heart. The nature of the biological signals produced in the EKG waveform may impact the EKG at random times. Despite the variations of EKG waveform among different individuals, the signal alterations across patients often appear similar with the same type of arrhythmias. However, these variations may not show up all the time, but they can manifest at some specific period of time, thus appearing asynchronously.

These characteristics motivate the development of automatic waveform classifications to recognize the appearance of EKG abnormalities with high accuracy. This offers a reliable and affordable method to perform continuous mass screenings for cardiac abnormalities. The aim of this method is to obtain a set of characteristic shapes from the waveform that discriminate effectively one particular abnormal signal from another. Signal parameters, such as amplitude and phase, as well as signal shapes are typical characteristics used by the classification algorithms.

Over the years, several methods have been proposed to improve the accuracy and sensitivity of waveform classification strategies. These methods have included wavelet coefficient [7], autoregressive modeling [11] , radial base functions neural networks [19], self-organizing map, rough sets, fuzzy c-means clustering techniques [25] and many others [32]. These methods are implemented on personal computers but not on embedded hardware.

Software implementation uses the flexibility and full (float number) precision of powerful microprocessors with complex architecture algorithms; however, they are not portable. These computer algorithms have the disadvantage of being slower and with higher computational costs associated with operating system execution [21].

On the other hand, hardware implementation is limited in flexibility and usually offers lower precision, but has the advantage of processing data in parallel (as in field programming gate arrays or FPGA for short), making possible the implementation of complex algorithms in real time. In addition, they can be small and low power consuming, allowing them to be easily worn on the body.

Nowadays, FPGAs have increased their speed and circuit density making them suitable for signal processing in parallel. There are several reports describing the implementation of EKG parameter detection using FPGA devices [8]. Some of them have focused on the detection of certain sections of the EKG waveform [29], and others on the detection of abnormalities in the EKG wave [12], but most of them undergo preprocessing of the signal rather than working with the raw EKG [9]. Therefore, EKG signals classification demands some additional computer processes that may increase the computational complexity of the classifier. Furthermore, most of the waveform classifiers consider a time windowing process which limits the generalization capacity of signal classifiers because selecting the window size is still a major problem in designing pattern classifiers. Indeed, if the window size is not selected accurately, the classification accuracy can decrease significant even if the classifier methodology could be correct.

Classification problems occur when an object needs to be assigned into a predefined group or class based on a number of observed attributes related to that object. Artificial neural networks (NNs) provide an effective method to perform classification on continuous EKG signals. NN solutions are desirable because of their ability to self-adjusted as new information is provided to the system and their ability to approximate complex nonlinear functions. In the last decade, continuous neural network (CoNN), usually called differential NN, has emerged as a powerful tool to extend the classification capacities of systems that need this level of adaptability. Notice that continuous classification algorithms are not usual in the literature [4]. CoNN is a new type of NN described by a set of ordinary differential equations (ODEs). These ODEs are used to represent the set of signals monitored by the EKG amplifier. Generally, NN requires preliminary training stages. For instance, in conventional gradient descendant type, weight adaptation sensitivity of unknown systems is required during the so-called online training process [16]. This condition ensures the correct classification of signals into the different classes. By virtue of its parallel distribution, NN is generally robust, tolerant under the presence of faults and external noise, able to generalize well and capable of solving nonlinear problems [5].

In this paper, the implementation of CoNN as a real-time classifier for EKG signals is presented. The classifier used the raw EKG signal that prevents losing information if some preliminary signal treatments are applied. Therefore, CoNN uses the EKG signal as input and a characteristic sigmoid function was selected as target that corresponds to signals where arrhythmia may appear. Therefore, a class of associative memory was constructed with the same CoNN structure but fixed weights obtained after applying a supervised training. An alternative option to use CoNN as signal classifier is to use the same EKG signal as the pattern that should be classified; therefore, a special class of continuous autoencoder system can be designed. To the authors knowledge, this is one of the first attempts to use EKG signal as it is to enforce the classification of arrhythmia presence. Moreover, the class of CoNN considered in this paper has not been used as signal classifier. The complete scheme for training as well as the classification was developed by applying the Lyapunov stability theory. This classifier based on a CoNN was also tested with both the software and hardware implementations to compare the results when working at full arithmetic precision and at lower precision. In particular, the hardware CoNN implementation was developed in a commercial FPGA Xilinx Zinq Board that also represented a contribution considering the previous attempts to implement CoNN in embedded systems.

In summary, the contributions of this paper are:

  • The development of an automatic classifier for 8 different electrocardiography arrhythmia based on CoNN.

  • A soft real-time implementation of the classifier on a field programming gate array.

  • Detailed description on how to implement the training, generalization and validation processes for the pattern classifier based on CoNN.

1.1 Paper structure

The paper is organized as follows: Section 2 presents the mathematical support for the proposed classification algorithm which is based on the application of the CoNN implemented as a nonparametric identifier. Section 3 gives details on the EKG database used to test and validate the CoNN-based classifier. The fivefold cross-validation algorithm was considered to justify the application of the classification algorithm. Section 4 presents a comparison between the software and hardware CoNN implementations. Section 5 describes aspects of the FPGA evaluation board implementing the parallel CoNN signal classifier (VHDL code). Section 6 presents the results of the validation process of the CoNN classifier. Finally, the performance of the proposed classification CoNN on an FPGA compared to other methods applied to the same database is described in Sect. 7.

2 CoNN as a classifier for EKG arrhythmia

Figure 1 shows a general analytic scheme of the CoNN-based classifier considered in this study. The first part performs a training algorithm associating the EKG signal with a predefined trajectory used to represent the specific class (among the N possible ones) where that particular EKG signal belongs. In a second stage, a set of N CoNN was fixed with weights obtained after training. This parallel structure, usually known as classifier ensemble, was used to evaluate/test the classifier performance. The selection of what signals were used in the training and testing phases was done according to the rules established in the k-fold cross-validation method [27]. The blocks labeled as LMSE describe the least mean square error calculus that are determined for the set of nine CoNN with fixed weights. These LMSE values are compared to select the minimum one (clearly this minimum value is attainable). This value defines the class where the tested signal belongs. This structure looks like a variation of the so-called associative memory concept [14].

Fig. 1
figure 1

CoNN process for the classification of EKG arrhythmias

2.1 CoNN online identifier

EKG signals are represented here as \(u\in \mathbb {R} ^{m}\). These signals are assumed to be continuous with respect to time. Therefore, the EKG signals classifier can be represented as

$$\begin{aligned}\dfrac{d}{\mathrm{d}t}x^{j}\left( t\right) &=\left[ A\right] ^{\top }x^{j}\left( t\right) +\left[ W_{1}^{0,j}\right] ^{\top }\Psi _{1}(x^{j}\left( t\right) )+ \\ &\quad \left[ W_{2}^{0,j}\right] ^{\top }\Psi _{2}(x^{j}\left( t\right) )u_{i}^{j}\left( t\right) +\xi \left( x(t),t\right) \\&\quad x\left( 0\right) \text { fixed\,and\,bounded} \end{aligned}$$
(1)

where \(A\in \mathbb {R} ^{n},W_{1}^{0}\in \mathbb {R} ^{l_{1}},W_{2}^{0}\in \mathbb {R} ^{l_{2}}\) are constant matrices used to approximate the EKG signals. The scalar \(x\in \mathbb {R}\) defines a specific class characteristic to a particular EKG signal represented by u. The functions \(\Psi _{1}\in \mathbb {R} ^{l_{1}}\) and \(\Psi _{2}\in \mathbb {R} ^{l_{2}\times m}\) define the set of activation functions used to design the NN structure. When the CoNN is used to classify the EKG signal using a reference function, to categorize the specific class where the EKG signal belongs, the class x was proposed to satisfy the structure of a sigmoid function, that is

$$\begin{aligned} x^{j}(t)=\frac{a^{j}}{1+e^{-c^{j}t}} \end{aligned}$$
(2)

where \(a^{j}\) is the positive constant that characterizes the class and \(c^{j}\) is the positive constant to adjust the transition rate of the sigmoid function. This function represents the pattern to be approximated by the CoNN. Therefore, if the signal \(u_{i}^{j}\) belongs to the class j, then the corresponding signal \(x^{j}\) is characterized by both parameters, \(a^{j}\) and \(c^{j}\). Clearly, if the type of arrhythmia changes during the training process, this couple of parameters also changes. For example, for ARFCT \(a^{1}=1.5\), APC signals were characterized with \(a^{2}=2.5,\) FUSION beats \(a^{3}=3\), for normal EKG signals, \(a^{4}=4.5\); SVT used \(a^{5}=5.0.\) For ST change, \(a^{6}=6.0\), SVPB \(a^{7}=7.5\), T-wave change \(a^{8}=9.0\), and finally, PVC signals were characterized with \(a^{9}=10.0\).

An alternative option is using \(x^{j}=N_{i}^{-1}\sum _{i=1}^{N_{i}}u_{i}^{j}\) where \(N_{i}\) is the number of EKG signals within each class (normal, APC, PVC and SVT). This particular form of applying CoNN is a variation of an autoencoder.

The term \(\xi \left( x,t\right) :\mathbb {R} ^{n+1}\rightarrow \mathbb {R} ^{n}\) defines the approximation error of EKG signal associated with the finite number of activation functions used in the network structure. By assumption, the set of approximation errors represented by \(\xi\) satisfies the following definition: \(\vert \xi \vert \le \xi _{0}+ \xi _{1} \vert x \vert\) with \(\xi _{0}\) and \(\xi _{1}\) positive scalars. Clearly, by including the term \(\xi _{0}\), there is the possibility of including discontinuous functions. Therefore, uniqueness of solution must be understood in the sense of Filipov proposed in his seminal book. If \(\xi _{0}=0\) , then the uniqueness and existence of solution for the state x can be justified by the regular technique based on the application of the Lipchitz condition.

There are several theoretical results that justify the existence of finite constant matrices \(W_{1}^{0,j},\)\(W_{2}^{0,j}\) such that EKG signals can be presented as the NN structures presented in (1).

If different variations of EKG signals, represented by \(u=u^{j}\), are considered, then different sets of matrices \(W_{i}^{0,j}\) must exist, one per class of arrhythmia. Therefore, any feasible signal classifier must be capable of identifying the set of parameters \(W_{1}^{0,j},\)\(W_{2}^{0,j}\) when \(u^{j}\) is appearing as part of the EKG signal. The signal classifier proposed in this study is based on a set of parallel nonparametric identifier with similar structure to the approximation proposed in (1). This condition is proposed to use the extended and well-established continuous parameter identification theory.

The set of CoNN used to perform the online signal classification satisfies the structure of the nonparametric identifier proposed in [28], that is

$$\begin{aligned}\dfrac{d}{\mathrm{d}t}\hat{x}^{j}\left( t\right) &=\left[ A\right] ^{\top }\hat{x} ^{j}\left( t\right) +\left[ W_{1}^{j}\left( t\right) \right] ^{\top }\Psi _{1}(\hat{x}^{j}\left( t\right) ) \\&\quad +\,\left[ W_{2}^{j}\left( t\right) \right] ^{\top }\Psi _{2}(\hat{x}^{j}\left( t\right) )u^{j}\left( t\right) \\ &\quad \hat{x}^{j}\left( 0\right) \text { fixed\,and\,bounded} \end{aligned}$$
(3)

where \(W_{1}^{j}\in \mathbb {R} ^{l_{1}},W_{2}^{j}\in \mathbb {R} ^{l_{2}}\). The vector \(\hat{x}^{j}\in \mathbb {R}\) defines the state of class signal associated with the classifier. The set of time-varying weights, i.e., the matrices \(W_{1}^{j}\) and \(W_{2}^{j}\), contains the adaptive parameters that are adjusted to produce the self-adaptive classification of the EKG signals in different classes. \(\Psi _{1}\in \mathbb {R} ^{l_{1}}\) and \(\Psi _{2}\in \mathbb {R} ^{l_{2}\times m}\) define the set of activation functions used for the NN structure [28]. In this study, the activation functions were selected as sigmoid ones. That means that each component of these two vectorial functions was selected in that form. Usually, the correct adjustment of CoNN weights \((W_{i}^{j},\)\(i=1,2)\) provide the signal classification capacity. According to the results developed in [28], the so-called weight updating (learning) law is described by the following set of matrix differential equations

$$\begin{aligned} \dot{W}_{i}^{j}\left( t\right) =-k_{i}^{j}P^{j}\Delta ^{j}\left( t\right) \Psi _{i}^{\intercal }(\hat{x}\left( t\right) )-2^{-1}k_{i}^{j}\tilde{W} _{i}^{j}\left( t\right) , \quad i=1,2 \end{aligned}$$
(4)

The time-varying vectors \(\Delta ^{j}\in \mathbb {R} ^{n},\)\(\Delta ^{j}=x^{j}-\hat{x }^{j}\) are the identification errors used during the training procedure. The parameters, \(k_{i}^{j}\)\(\ i=1,2\), are the constant parameters used to adjust the learning rates. The time-varying terms \(\tilde{W}_{i}^{j}\) represent the deviation from the time-varying weights \(W_{i}^{j}\) and \(W_{i}^{0,j}.\) The last constant parameters are obtained by a sequence off-line which is described in the next section.

Matrix \(P^{j}\) is the positive definite solution of the Riccati equations defined by

$$\begin{aligned} &2PA+P^{j}R^{j}P^{j}+Q^{j}=0 \\ &R^{j}=W_{1}^{0,j}(\Lambda _{2}^{j})^{-1}[W_{1}^{0,j}]^{\top }+W_{2}^{0,j}(\Lambda _{4}^{j})^{-1}[W_{2}^{0,j}]^{\top } \\&\qquad+\Lambda _{1}^{j}+\Lambda _{3}^{j} \\ &Q^{j}=(\bar{f}_{1}^{j}+\lambda _{\max }(2\Lambda _{2}^{j})l_{1})I_{nxn}+Q_{0}^{j} \end{aligned}$$
(5)

Here \(\Lambda _{k}^{j}\in \mathbb {R} ^{n\times n},k=1,..,4\) are positive definite matrices. The constant \(\bar{f}_{1}^{j}\) represents the upper bound for the approximation error obtained as a consequence of fixing the number of weights in the CoNN structure. The matrices \(W_{1}^{0,j}\,\)and \(W_{2}^{0,j}\) are the initial conditions of weights used in the first signal within each class j. The matrix, \(Q_{0}^{j}\), is a positive definite matrix used to provide the asymptotic stability to the classifier structure. In fact, it must be selected (over a large set of possible values) just to ensure the existence of the solution for the Riccati equations. These results give the theoretical support to ensure that the CoNN algorithm may be used to classify the EKG signals. The classifier considers the evolution of the individual performance indices

$$\begin{array}{c} J^{j}\left( t=\mu T_{k}\right) :=\displaystyle \int \limits _{t=\left( \mu -1\right) T_{k}}^{t=\mu T_{k}}\left\| \Delta ^{j}(t)\right\| ^{2}\mathrm{d}t, \\ \quad 1\le \mu \le N \end{array}$$
(6)

Therefore, the class \(j^{*}(n)\) selected by the classifier is determined by \(j^{*}(n)=j\) such that \(J^{j*}(t=T)=\underset{j}{\min }J^{j}\left( t=T\right)\) is attained at each \(t=nT_{k}\) where \(T_{k}\) is the size of the signal window to be analyzed and T is the total time of the signal considered to be studied. The selection of the period of time \(T_{k}\) is not a simple task because this value defines the number of samples that should be taken into account to obtain the classification. Some results can be consulted in the literature regarding how to select the best window size for different pattern recognition methods. Nevertheless, their application on the problem considered in this study is still a matter of investigation.

2.2 Off-line training of the CoNN

Learning laws proposed in (4) require the term \(\tilde{W} _{i}^{j}\left( t\right)\) which depends on \(W_{i}^{0,j}\). These constant values must be adjusted by preliminary off-line matrix identification algorithms. These algorithms use the least mean square method. To solve this part of the training procedure, a set of several EKG signals were selected to obtain \(W_{i}^{0,j}.\) Details of the matrix least mean square can be found in [1] where the convergence analysis as well as the identification algorithm is described.

The training process was completely developed on a personal computer implementing MATLAB 2014b. As usual in the k-fold cross-validation method, the number of folders was fixed to 5 to analyze the collected EKG signals that were used in this part of the off-line training method.

Two different numerical representations were evaluated: the first one used float variables (full precision) to represent all the weights, and the second one used 16-bit fixed point variables. This strategy was used for both the off-line and online training algorithms. We used off-line training produced weights to set the classifier connection matrix. On the other hand, the continuous training process proposed in (4) yields to the online classification of EKG signals.

As mentioned before, the weights \(W_{i}^{0,j}\) contain the corresponding specific characteristic for each EKG class corresponding to normal and abnormal signals. To get the weights that represent each class, 37 of the 74 samples of the ARFCT, 37 of the 75 samples of the APC, 37 of the 100 samples of the FUSION, 37 of the 100 samples of the NORMAL, 37 of the 75 samples of the SVT, 37 of the 100 samples of the STCH, 37 of the 100 samples of the SVPB, 37 of the 100 samples of the TCH and 37 of the 75 PVC were used in the off-line training process.

2.3 Validation of CoNN classification process

In order to validate the capacity of the CoNN to classify the EKG signals, the regular k-fold cross-validation (k-cv) method was implemented. Since the k-cv process is not an exhaustive cross-validation method, the data were split into (80/20) training and validation samples with some predefined ratio. Validation samples were used to estimate the prediction error. In the k-cv method, a set of sample \(S_{n}\) is uniformly and randomly partitioned into k-fold with similar sizes \(\rho =\{\rho _{1},...,\rho _{k}\}.\)

Let \(S_{i}=S_{n}\backslash \rho _{i}\) be the complement data set of \(\rho _{i}\). Then, all the samples belonging to \(S_{i}\) are used as training data. This particular cross-validation procedure is repeated k times (the number of folds), with each of the k subsamples used exactly once as the validation data. The complete set of k results obtained from the folds is averaged to produce a single estimation.

Indeed, the cross-validation algorithm \(G\left( \cdot \right)\) induces a classifier from \(S_{i},\) defined by \(\psi _{i}=G\left( S_{i}\right) ,\) where the prediction error based on \(\rho _{i}\) is estimated. So the general prediction error \(\hat{\epsilon }_{k}\left( S_{n},\rho \right)\) based on the classifier \(\psi =G\left( S_{n}\right)\) that uses the entire set of samples is estimated as follows [27]

$$\begin{aligned} \hat{\epsilon }_{k}\left( S_{n},\rho \right) =\dfrac{1}{n}\overset{k}{ \underset{i=1}{\displaystyle \sum }}\underset{\left( x,c\right) \in \rho _{i}}{\displaystyle \sum } 1\left( c,\psi _{i}\left( x\right) \right) \end{aligned}$$

where n is multiple of k, \(1\left( i,j\right) =1\) if \(i\ne j\) and zero otherwise. This error is the average of errors committed by \(\psi _{i}\) in their corresponding partitions \(\rho _{i}.\) In particular, the so-called fivefold cross-validation was used to perform the validation procedure of the signal classifier proposed in this study. An additional general validation measure was performed by using a modified version of signal-to-noise-plus-distortion ratio (SNDR). This measure was following the next mathematical structure for each class

$$\begin{aligned} Q^{j}=20\log \left( \left[ J^{j}\left( t=\mu T\right) \right] ^{-1}\displaystyle \int \limits _{t=\left( \mu -1\right) T_{k}}^{t=\mu T_{k}}\left\| \Delta ^{j}(t)\right\| ^{2}\mathrm{d}t,\right) \end{aligned}$$
(7)

SNDR introduces a normalized method to characterize the classification accuracy. This measure can be considered an amplitude independent quality measure. So, their results can be trusted more than the one presented in (6).

3 Database description

To test the CoNN classification capabilities, the MIT-BIH Arrhythmia database and the European ST-T database were elected as information sources. Due to their availability and full detailed description of each beat, both databases are recommended in the American National Standard for Testing and reporting performance results of cardiac rhythm and ST segment. The MIT-BIH Arrhythmia database is described in [13, 24], and the European ST-T database is described in [13, 30]. Both databases have been used on several occasions by different research groups [6, 22] which allows their results for the comparison of the performances of the proposed classification algorithm based on CoNN.

The MIT-BIH Arrhythmia database contains 48 half-hour records of ambulatory EKG recordings obtained from 47 subjects. The EKG data were digitized at 360 samples per second per channel with an 11-bit resolution over a 10 mV range. Two or more cardiologists independently made annotations on each record. Disagreements were resolved to obtain the computer-readable reference annotations for each beat (approximately 110,000 annotations in all) included with the database.

The European ST-T database consists of 90 annotated excerpts of ambulatory ECG recordings from 79 subjects. Each record is two hours in duration, sampled at 250 samples per second with 12-bit resolution over a nominal 20 mV input range. Annotations were made by two cardiologists that worked independently to annotate each record beat by beat.

To test the proposed algorithm, eight types of arrhythmia (ARFCT, APC, FUSION, SVT, STCH, SVPB, TCH and PVC) and normal EKG rhythm samples were taken from both databases. For training and validation, only the fragments of signals that contain the arrhythmia episodes and normal EKG were considered. These signals are filtered by the regular analog filters sequence. No additional digital filters applied over the EKG signals.

In order to evaluate the classification capacities of the algorithm presented in this study, a set of evaluation tests was proposed. A set of 799 signals was prepared artificially according to the following procedure: consider a first signal \(S_{i}\) from a class \(C_{i}\) and a second one \(S_{j}\) from a class \(C_{j},\) the hybrid signal \(S_{ij}\) was generated as the convex combination of \(S_{ij}=\lambda S_{i}+(1-\lambda S_{j}).\,\)Then, these signals were tested on the parallel arrangement of trained CoNN. For this particular analysis, \(\lambda =0.8\) meaning that 80% of a signal belong to a class \(C_{i}\) was combined with a 20% of a single belonging to a class \(C_{j}\). A second round of analysis considered the analysis of borderline signals using \(\lambda =0.7.\) After the total evaluation of classification process, the CoNN-based classifier achieved a 93.8% of correct classification for both databases. This result shows the detectability capacity of the classifier proposed in this study.

To test the classification capabilities of the proposed identifier, the negative prediction value (NPV), positive prediction value (PPV), true positive rate (TPR) and specificity (SPC), where calculated in order to obtain the confusion matrix of the classifier. These values are calculated according to the following equations:

$$\begin{aligned} \mathrm{NPV} (\%)=\dfrac{\mathrm{TrueNegatives}}{(\mathrm{TruePositives}+\mathrm{TrueNegatives})}\times 100\\ \\ \mathrm{PPV} (\%)=\dfrac{\mathrm{TruePositives}}{(\mathrm{FalsePositives}+\mathrm{TruePositives})}\times 100 \\ \\ \mathrm{TPR} (\%)=\dfrac{\mathrm{TruePositives}}{(\mathrm{TruePositives}+\mathrm{FalseNegative})}\times 100 \\ \\ \mathrm{SPC} (\%)=\dfrac{\mathrm{TrueNegatives}}{(\mathrm{TrueNegatives}+\mathrm{FalsePositive})}\times 100 \end{aligned}$$
(8)

where true positives are the total number of signals that were correctly classified in the corresponding class, true negatives are the total number of signals that were not in the class evaluated and they were clearly not classified in it, false negatives are the total number of signals belonging to the class evaluated, but they were considered as part of a different class, and false positives correspond to the number of signals that belong to a different class, but they were included in the evaluated class. The confusion matrix allows a more detailed analysis of classification capacities for the CoNN-based signal classifier.

We developed the study for all the databases described in the manuscript. We only explained the description of one single example just to avoid unnecessary repetition of the same method. However, all the databases were analyzed in the same way.

4 Fixed point implementation of the classifier

The CoNN algorithm was initially developed in full precision (based on floating-point variables). A second analysis used the same model but was implemented in lower precision (16-bit fixed point variables). Table 1 shows the nature of weight signals employed for both the full and lower precision. The notation \(\langle \pm\),\({\varpi }_{1}\),\({\varpi}_{2}\)\(\rangle \) means signed float represented by \({\varpi }_{1}\) integer digits with fixed number \({\varpi }_{2}\) of fractional ciphers.

Each CoNN was evaluated numerically during the training phase using the following set of parameters \(k_{1}=0.5,\)\(k_{2}=0.7,A=-2.2,P^{1}=P^{2}=P^{3}=P^{4}=P^{5}=P^{6}=P^{7}=P^{8}=P^{9}=3.3\), and the weights were initialized with the following values \(W_{1}(0)=0.01\) and \(W_{2}(0)=0.01.\) The same set of parameters was used in either evaluation: in the personal computer or the embedded system. For all the experiments, the analysis time T was selected as 2.16 s.

The lower-precision representations presented in Table 1 were chosen to keep the off-line classification quality obtained when the float representation was considered. One may notice that this table shows the actual simplification obtained when the classifier is implemented in an embedded system instead of the personal computer. Therefore, it is expect to obtain an efficient pattern classifier based on CoNN not only from the effectiveness of classification but the computational cost also. Different lower-precision representations were chosen in order to satisfy the classification purposes described above.

Table 1 CoNN input values for software and hardware

A simplified version of the algorithms used to evaluate both the training and validation processes as well as the implementation in the FPGA device is defined as follows:

figure a
figure b

EKG signals were repeatedly tested in the classifier presented in (3). The training process used the set of signals according to the distribution presented in the fivefold cross-validation method available in MATLAB. The weights obtained in each training sequence was recorded and used in the next trial. With the whole set of EKG signals considered as training patterns, the final set of weights was used to perform the validation stage. These final trained weights were specified according to the class of abnormality of each EKG signal. One may notice that after the training process, the EKG signals belonging to the training set were reproduced by the detector with an accuracy of 99% Fig. 2. The signals showed in this figure are just one example of how the CoNN implemented during the training process can track the EKG signals.

Fig. 2
figure 2

Performance of the CoNN for ARFCT, FUSION, SVT, ST change, SVPB, T-wave, PVC arrhythmias and normal EKG waveform, when classification sample is correct. The black line is the desired output, the red line is the full precision NN output, and the blue line is the low-precision NN output

Two sets of training processes were executed: the first one used the set of weights produced when full precision numbers were used to execute the training process, while the second one applied the set of weights represented by fixed numbers.

These two sets of training processes were simulated on a personal computer. Both training processes reproduced the EKG signals with the same quality (Fig. 3). The similar performance of both types of classifiers (with full and low precision numbers) justifies the possibility of implementing the signal classifier in an embedded system with fixed point precision, such as the FPGA system.

Fig. 3
figure 3

Closer view of the performance of the neural network for APC (top, left-hand side), STVA (top, right-hand side), PVC (bottom, right-hand side) arrhythmias and normal EKG waveform (bottom, left-hand side). On x-axis, samples refers to the number of acquired EKG measurements

The mean square error of each CoNN was evaluated for each class of arrhythmia, and the same evaluation was done to compare the performances between the identifiers running on either floating or fixed point representations. Similar performances were confirmed using the mean square error information. Also, a transient period not longer than 0.5 s was produced in all the training evaluations.

5 FPGA implementation

To implement the signal classifier in the embedded FPGA system, a fixed point representation of both the detector state and the identification error was developed. Table 2 shows the values employed to implement the low precision representation of the detector. The second column in this table demonstrates that all variables executed in MATLAB were used as floating-point variables. Nevertheless, the third column demonstrates how the variable representation was simplified to a signed (±) fixed point variable with the 16 bits to represent the integer part and variable number of bits (showed in the third column of the same table after the dot symbol). This analysis was necessary to attain the FPGA implementation.

The implementation of the classification algorithm in the FPGA system obeyed the following algorithm:

figure c

The detector implemented in the FPGA system was compared online with a similar CoNN structure implemented on a personal computer with double representation of numbers. This comparison was feasible considering the online Ethernet monitoring system of the Xilinx Zedboard FPGA development board.

The CoNN identifier was implemented on a Xilinx Zedboard development board. This board is based on the Zynq\(^{TM}\)-7000 AP SoC xc7z020-CLG484-1 processor. The memory resources of this development board include a 512MB DDR3, 256Mb Quad-SPI Flash and a 4GB external SD card. The communication systems of this board include the USB-JTAG programming, 10/100/1000 Ethernet, USB OTG 2.0 and USB-UART.

Table 2 CoNN output values for software and hardware

The programming language used to implement the 16-bit fixed point representation of CoNN was VHDL. The corresponding code was generated using the MATLAB HDL Coder 3.5 and ISE Xilinx 14.4. An auxiliary AXI-4 interface was implemented to perform the Ethernet communication between the computer and the development board to follow online the time evolution of the CoNN-based classifier. Table 3 shows the number of total registers used to implement the identifier.

Table 3 Summary of registers used in the FPGA device

All the EKG signals from the database were evaluated using the training algorithm in the FPGA system. They were done according to the same distribution characterized by the tenfold cross-validation algorithm. The identifier evaluation for each EKG signal was simulated in the FPGA system spending approximately 2.16s each.

6 Performance quality measurements

The full database was tested on the FPGA. Table 4 summarizes the training results obtained from the FPGA system. One would notice that a similar correct classification percentage was achieved when float number precision was used. This confirms the possibility of success when using the detector in the selected, low-precision embedded system.

Table 4 Training and validation results for float number precision

In order to evaluate the classification capacities of the algorithm implemented in the FPGA for this study, a set of evaluation tests were proposed. A set of 300 signals was prepared artificially according to the following procedure: consider a first signal \(S_{i}\) from a class \(C_{i}\) and a second one \(S_{j}\) from a class \(C_{j},\) the hybrid signal \(S_{ij}\) was generated as the convex combination of \(S_{ij}=\lambda S_{i}+(1-\lambda S_{j}).\,\)Then, these signals were tested on the parallel arrangement of trained CoNN. In particular, for this particular analysis, \(\lambda =0.7\) meaning that 70% of a signal belong to a class \(C_{i}\)was combined with a 30% of a single belonging to a class \(C_{j}\), the CoNN-based classifier implemented in the FPGA achieved a 72.3% of correct classification for the database. This result shows the detectability capacity of the classifier proposed in this study.

Tables 5 contains the results of NPV, PPV, TPR and SPC when the evaluation of classifier was executed over the set of borderline signals considering that \(\lambda =0.8.\) According to the accuracy results as well as the predictive analysis (with all results above 90%), the classifier proposed in this study seems to be a reliable method to classify certain characteristics in EEG signals.

Table 5 NPV, PPV, TPR and SPC results for the borderline signals with \(\lambda =0.8\) I

Figure 4 depicts the comparison between the CoNN identifier evaluated on a PC (Processor i7, 8 GB RAM and 64-bit operating system) and that on the Xilinx FPGA Zedboard evaluation system. The signal classifier was implemented as a composition of four parallel identifiers with fixed set of weights. These weights were recovered from the files recorded during the training process executed on the PC system.

To perform a continuous evaluation of the CoNN implement of parallel classifier, an artificial EKG signal was developed. This signal, which was not in the database, used partial information of signals obtained from the database. The signal contained data from the EKG signals in the following order: PVC, normal, APC and SVT.

The results of the classification system based on the parallel structure of CoNN detector with fixed weights are detailed in Fig. 4. The first signal showed at the top of the figure demonstrates the signal constructed artificially. It is clear that the error obtained in each classifier with fixed weights is less when the corresponding part of the signal contains the corresponding type of signal.

This part of the classifier evaluation was only tested in the FPGA development board. The red arrow points to the segments where the corresponding classifier represents the corresponding type of arrhythmia. The blue lines show the time when the artificial signal changes from one type of arrhythmia to the other. This evaluation also details the result of the continuous nature of the classifier proposed in this study.

Fig. 4
figure 4

From the top to the bottom, a EKG artificial signal generated from patterns containing arrhythmias and normal EKG waveform. The second trace is the error for detection of PVC events. The third trace is the error for detection of normal EKG rhythms. Next is the error for detection of APC events, and final is the error trace for detection of STV

The classifier proposed in this study also considers a different type of evaluation. It is not unusual for an incorrect signal to appear in the electrophysiological signal due to an incorrect measuring technique. It is even possible for a different bio-potential to appear when acquiring the EKG signal. Therefore, the classifier was tested on the PC and the FPGA with an electromyographic signal as the input.

In all the cases, the error grew to a point beyond a predefined threshold (2.0), which indicated that the input signal was not one of the expected waveforms. This kind of evaluation is not typically done by other researchers. Finally, a comparison between the results presented in this study and others introduced in different previous studies is presented. Only the arrhythmia classification implemented on an FPGA is presented in Table 5. This comparison is valid because the closeness between the classifier evaluated on the PC and the FPGA has already been proven.

Even when other work do not consider the same type of arrhythmias for classification purposes, most of them take into account PVC as part of the classifier evaluation. The parallel CoNN classifier evaluated on the FPGA showed a better performance than previous results (Table 6). The described algorithm attained a total correct classification of 97.62% for all the different signals included in the database.

Table 6 Comparison of several classifier performances on MIT-BIH database

In order to elucidate the training process efficiency, the quality measurement introduced in Eq. (7) was evaluated. This value was obtained during the training as well as after the testing procedures. Table 7 shows these values obtained in both phases of the classification process.

Table 7 Signal-to-noise-plus-distortion ratio applied to the DNN output

The training process took 300 s long, while the validation was 60 s long. This is a very long period for training and validation. This is an opportunity for developing more efficient numerical methods to solve the pattern classification problem by the method proposed in this study. On the other hand, the processing time in the FPGA system was 3.4 s which is closer to the actual period selected for each signal.

7 Conclusions

From the clinical point of view, automatic online detection of different types of EKG arrhythmia may contribute to immediate and better treatment of different heart diseases. This study proposes a method to perform EKG signal classifications online based on the application of parallel CoNN. This structure was first trained on a PC simulation system to prepare a set of weights which were used to design the particular CoNN used to detect multiple different arrhythmia waveforms in parallel.

The classifier was then implemented on an FPGA evaluation board and was validated using the fivefold cross-validation method. The classification TPR attained by the classifier developed in this study was the best (98.01%) among a selected set of similar classifiers, also implemented in FPGA, described previously in some similar studies. This value was obtained as the average of the accuracy percentage obtained for each class considered in this study.

The classification technique developed in this study can be extended to different problems such as (a) electroencephalographic signal analysis that can be executed online. This application can be used in the implementation of brain machine interfaces focused on assisting patients with movement limitations, (b) electromyographic pattern classifications that can used as input information in the control loop of active orthosis that can used in different sections of the human body or (c) online voice pattern classifier that can be used in security and medical devices among others.