# Real-Time Arrhythmia Classification Algorithm Using Time-Domain ECG Feature Based on FFNN and CNN

Authors: Jing Cai; Ge Zhou; Mengkun Dong; Xinlei Hu; Guangda Liu; Weiguang Ni
Journal: Mathematical Problems in Engineering
 (2021)

---

## Abstract

To solve the problem of real-time arrhythmia classification, this paper proposes a real-time arrhythmia classification algorithm using deep learning with low latency, high practicality, and high reliability, which can be easily applied to a real-time arrhythmia classification system. In the algorithm, a classifier detects the QRS complex position in real time for heartbeat segmentation. Then, the ECG_RRR feature is constructed according to the heartbeat segmentation result. Finally, another classifier classifies the arrhythmia in real time using the ECG_RRR feature. This article uses the MIT-BIH arrhythmia database and divides the 44 qualified records into two groups (DS1 and DS2) for training and evaluation, respectively. The result shows that the recall rate, precision rate, and overall accuracy of the algorithm’s interpatient QRS complex position prediction are 98.0%, 99.5%, and 97.6%, respectively. The overall accuracy for 5-class and 13-class interpatient arrhythmia classification is 91.5% and 75.6%, respectively. Furthermore, the real-time arrhythmia classification algorithm proposed in this paper has the advantages of practicability and low latency. It is easy to deploy the algorithm since the input is the original ECG signal with no feature processing required. And, the latency of the arrhythmia classification is only the duration of one heartbeat cycle.


---

## Body

## 1. Introduction

According to the World Health Organization (WHO), 17.9 million people died of cardiovascular disease in 2019, of which 85% died of sudden heart disease and stroke [1]. Arrhythmia refers to a problem with the frequency or rhythm of the heartbeat, and severe arrhythmia may cause lethal heart disease [2]. Clinically, doctors usually diagnose it by analyzing the patient’s electrocardiogram (ECG) with his/her relevant medical history and clinical manifestations [3]. However, abnormal ECG signals usually occur by chance, which cannot be obtained from a short-term ECG. It is time-consuming and labor-intensive and lacks objectivity to only rely on manual processing of a patient’s long-term ECG records. Moreover, centralized analysis after recording ECG lacks real-time performance and cannot deal well with the sudden risk of patients.With the development of computer science and technology, computer-aided diagnosis (CAD) for ECG analysis has helped solve the shortage of manual processing of ECG [4]. An increasing number of algorithms have been proposed for the automatic analysis of ECG signals for arrhythmia classification. Generally, an arrhythmia classification algorithm consists of four steps: preprocessing, heartbeat segmentation, feature extraction, and classification algorithm. Heartbeat segmentation has been studied for 30 years [5–8]. The classical heartbeat segmentation method uses an adaptive threshold method [5]. With the deepening of research, more and more new technologies have been applied to heartbeat segmentation algorithms, such as wavelet transform [9], genetic algorithm [10], and neural network [11]. The accuracy of heartbeat segmentation has a great impact on the final arrhythmia classification. However, many studies on arrhythmia classification algorithms directly use the heartbeat markers in the database, ignoring the influence of errors in heartbeat segmentation on the overall algorithm. Typical ECG features include single features (such as heart rate variability, QRS width, PQ/PR interval, and amplitude of QRS) and time-domain features or corresponding frequency-domain features extracted directly from ECG signals. More popular arrhythmia classification algorithms include support vector machine (SVM) [12, 13], artificial neural network (ANN) [14, 15], linear discriminant (LD) [16], and logistic regression (LR) [17].Deep learning is a branch of machine learning. It is a computational model with multiple processing layers to learn data representation with multiple levels of abstraction [18]. Deep learning optimizes the parameters of each layer by backpropagation and discovers complex structures in big datasets [18]. It has been proven to be useful for many disciplines, such as computer vision, speech recognition, natural language processing, and bioinformatics. Increasingly methods based on deep learning are used to study the classification of arrhythmia. Mathews et al. [19] proposed a deep learning-based ECG classifier using single-lead ECG and trained a deep learning model-based classifier to classify arrhythmias on the ECG signal with a 114 Hz sampling rate. Paweł and Acharya [20] used long-duration (10 s) ECG signal segments, strengthened the characteristic ECG signal features with spectral power density estimation, and introduced a novel three-layer deep genetic ensemble of classifiers. Shaker et al. [21] proposed a novel data augmentation technique using generative adversarial networks (GANs) to balance the dataset and effectively improve the performance of ECG classification over the same models trained on the original dataset. These studies have made good progress in the accuracy and the interpatient performance of the arrhythmia classification algorithm; however, they lack the real-time improvement of the algorithm. In practice, developing the most appropriate classifier that is capable of classifying arrhythmia in real time is also an issue in ECG arrhythmia classification [22].Due to the specificity of individual ECGs, the main concern in practical application is the interpatient performance of the arrhythmia classification algorithm. There are two main ways to improve it. The first method is to use an expert to annotate arrhythmia on a portion of a specific patient’s ECG and fine-tune the model with the annotation to improve the model performance for this patient [23–26]. Among them, Luo et al. [26] proposed a patient-specific arrhythmia classifier based on deep learning, in which a deterministic patient-specific heartbeat classifier is fine-tuned on heartbeat samples that include a small subset of individual samples (the overall accuracy increases from 89.3% to 97.5%). However, this method is feasible but not scalable because fine-tuning the model requires expert intervention. Another method is to train a general classifier with good interpatient performance through a reasonable selection of features, normalization, training datasets, and evaluation methods [14, 27–31]. The second method is used in this paper because it is cheaper and more practical.The combination of edge computing [32] and wearable ECG acquisition technology for real-time arrhythmia monitoring cannot only help patients monitor their health and prevent sudden risks but also has the advantages of low latency, low power consumption, low bandwidth, and high privacy. An arrhythmia classification algorithm with low latency, high practicability, and reliability is the key to the monitoring system. Therefore, this paper proposes a real-time arrhythmia classification algorithm using deep learning. In the algorithm, a classifier based on the FFNN (Feedforward Neural Network) model first detects the QRS complex position for real-time heartbeat segmentation. Then, the time-domain morphological features of each heartbeat cycle are extracted according to the heartbeat segments, and another classifier based on the CNN (Convolutional Neural Network) model classifies arrhythmia in real time. The algorithm achieves a real-time performance of heartbeat cycle latency in arrhythmia classification and overcomes the shortcomings of traditional arrhythmia classification algorithms, which are unscalable and complex in feature processing and not suitable for edge computing. This paper provides a real-time, efficient, and reliable arrhythmia classification algorithm for edge computing-based ECG monitoring systems.


## 2. Materials and Methods

### 2.1. Data Description

The MIT-BIH arrhythmia database [33] is published by the Massachusetts Institute of Technology-Beth Israel Hospital. It contains 48 ECG records with a sampling rate of 360 Hz and a duration of 30 minutes. In this paper, only the ECG signals of the MLII lead are used for arrhythmia classification, which requires less hardware and computational cost, while giving a satisfactory overall accuracy [31, 34].ANSI/AAMI [35] categorizes the 15 recommended classes of arrhythmia into five superclasses which are normal (N), supraventricular ectopic beat (SVEB), ventricular ectopic beat (VEB), fused beat (F), and unknown beats (Q). It is recommended to classify with only these superclasses. Since there are only 13 classes of arrhythmia in MIT-BIH, this paper designs the heartbeat classification model as a 13-class classification model, which can then get the 5-class classification results according to the class hierarchy. Some studies also classify arrhythmia into other five classes: normal (N), left bundle branch block (LBBB), right bundle branch block (RBBB), premature ventricular contraction (PVC), and atrial premature beat (APB) [36–38].To better adapt to the actual environment and to improve the practicality of the algorithm, this paper divides the 44 records in the MIT-BIH database without pacemakers into two groups, according to the work of Chazal et al. [16]. The first group, named the DS1 group, consists of the records of 101, 106, 108, 109, 112, 114, 115, 116, 118, 119, 122, 124, 201, 203, 205, 207, 208, 209, 215, 220, 223, and 230. The second group, named the DS2 group, consists of the records of 100, 103, 105, 111, 113, 117, 121, 123, 200, 202, 210, 212, 213, 214, 219, 221, 222, 228, 231, 232, 233, and 234. The records of Groups DS1 and DS2 are basically from different patients (201 and 202 are from the same patient but in different groups). Figure 1 shows part of the waveform of each data record in the DS1 and DS2 groups.Figure 1
Part of the waveform of each data record in the DS1 and DS2 groups.Table1 shows the hierarchy of superclasses and subclasses in arrhythmia classes. It also contains descriptions and quantity statistics of each class in Groups DS1 and DS2. Since some nonbeat annotations exist in the MIT-BIH database, this article marks them as the OTHER superclass. The relevant data should be excluded from the following process of constructing datasets.Table 1
Description and quantity statistics of each class in the MIT-BIH database.
Superclass labels and descriptionsAllds0ds1Subclass labels and descriptionsAllds0ds1(N) any heartbeat not categorized as SVEB, VEB, F, or Q901254586644259(N) normal beat745463810236444(L) left bundle branch block beat807539494126(R) right bundle branch block beat725937833476(j) nodal (junctional) escape beat22916213(e) atrial escape beat16160(SVEB) supraventricular ectopic beat27819441837(A) atrial premature beat25468101736(a) aberrated atrial premature beat15010050(J) nodal (junctional) premature beat833251(S) supraventricular premature or ectopic beat220(VEB) ventricular ectopic beat700937883221(V) premature ventricular contraction690336833220(E) ventricular escape beat1061051(F) fusion beat803415388(F) fusion of ventricular and normal beat803415388(Q) unknown beat1587(Q) unclassifiable beat1587(OTHER) nonbeat annotations299115151476(+) rhythm change1173616557(∼) change in signal quality573289284(!) ventricular flutter wave4724720(") comment annotation4372435(x) Nonconducted P-wave (blocked APC)19358135(|) isolated QRS-like artifact1316665([) start of ventricular flutter/fibrillation660(]) end of ventricular flutter/fibrillation660


### 2.2. Overall Design

The overall algorithm design is shown in Figure2:(1)
The real-time ECG signal sequence is cut into ECG segments with a 200 ms time window(2)
The algorithm detects the QRS complex positions with Classifier 1 in the ECG segments(3)
The algorithm caches ECG data and extracts the time-domain feature (named ECG_RRR) based on the last three QRS complex positions(4)
Classifier 2 predicts arrhythmias using the ECG_RRR featureFigure 2
Schematic diagram of the overall algorithm.The algorithm’s output is the arrhythmia type and the corresponding QRS complex position information. As shown in Figure2, the ECG_RRR feature is a resampled ECG sequence with a fixed length. The starting point of the sequence is the last R wave point of the current heartbeat cycle, and the endpoint is the next R wave point of the current heartbeat cycle. Therefore, the ECG_RRR feature contains the complete ECG signal of the current heartbeat cycle. Meanwhile, to improve the accuracy of QRS complex detection, Classifier 1 adopts a step-window voting mechanism to ensure that the moving window contains complete QRS complex information. Since the preprocessing of the ECG signal (such as removing baseline offset, noise, and power-line interference) should be done at the acquisition devices, this algorithm does not consider signal preprocessing.The 200 ms time window is selected because it not only guarantees real-time performance but also ensures that each two adjacent time windows contain no more than one complete QRS complex.The real-time ECG signal is cut into ECG segments (namedECG_200ms, length is 72 when the sample rate is 360 Hz in this paper) by a 200 ms time window, expressed by(1)ECG_200ms=ECGsn:n+72.TheECG_200ms is input into Classifier 1, which outputs an integer qrs. qrs=0 means that the input ECG segment does not contain QRS complexes. 0<qrs≤72 means that the input ECG segment contains QRS complexes and the center position of the QRS complex is qrs. The position of this QRS complex in the ECG signal is qrs+n and is stored in the QRS buffer.After obtaining the position of the last three consecutive QRS complexesQRSm−2,QRSm−1,andQRSm, the heart rate (HR) and heart rate variability (HRV) are calculated by(2)HRm−1=QRSm−1−QRSm−2fs×60,HRm=QRSm−QRSm−1fs×60,HRVm=HRm−HRm−1HRm−1×100%,where fs is the sampling rate of ECG (360 Hz in this paper).Only whenHRm−1 and HRm are both within the normal range (30∼150), the three QRS positions are considered valid. Then, the ECG_RRR feature is obtained by resampling the ECG signal in the ECG buffer between QRSm−2 and QRSm into 360 data points.Finally, the ECG_RRR feature is input into Classifier 2 which outputs the arrhythmia classificationTYPEm−1 of the heartbeat cycle at QRSm−1.The ECG_RRR feature is selected for arrhythmia heartbeat classification because it contains both the complete information of the current heartbeat cycle and partial information of the preceding and succeeding heartbeat cycles as the heart rate variation information.Classifiers 1 and 2 are both based on deep learning models. According to the characteristics of the input features, Classifier 1 uses a Deep Neural Network (DNN) model of fully connected layers, also called Feedforward Neural Network (FFNN). Classifier 2 uses the Convolutional Neural Network (CNN) model. CNN is a neural network with multiple hidden layers such as fully connected layers, convolutional layers, and pooling layers. CNN is a type of DNN with convolutional layers and pooling layers to extract and abstract features.For the fully connected layers, which are directly connected layer by layer, the forward propagation from the layerl−1 with m features to the layer l with n features is(3)Xl=flWlXl−1+Bl.The formula in the matrix form is(4)x1l⋮xnl=flw1l1…w1ln⋮⋱⋮wml1…wmlnx1l−1⋮xnl−1+b1l⋮bnl,where Xl−1 is the feature vector of the layer l−1, a column vector of length m, Xl is the feature vector of the layer l, a column vector of length n, Wl is the weight matrix of the layer l, a matrix of m rows and n columns, Bl is the bias vector of the layer l, a column vector of length n, and fl is the nonlinear activation function of the layerl.Each convolution layer contains several convolution kernels. The features of the previous layer are convolved with the corresponding convolution kernels to output new features. For the layerl−1 with depth i(the feature maps are X1l−1,…,Xil−1), after the operation of the convolution layer (with learnable convolution kernels K1,1l,…,Ki,1l,…,K1,jl,…,Ki,jl and learnable bias B1l,…,Bjl), the layer l with depth j (the feature maps are X1l,…,Xjl) is obtained. The calculation formula of each feature map is(5)Xjl=fl∑i∈MjXil−1⊗Ki,jl+Bjl,where Mj is the set of input feature maps, ⊗ is the convolution operation, and fl is the activation function.For a CNN model, there is usually a pooling layer following the convolutional layer to reduce the feature size. After several convolutional layers and pooling layers, a flatten layer transforms the features into a vector, and then, the output is obtained through several fully connected layers.In this study, the hidden layer uses the linear rectification function (Rectified Linear Unit, ReLU) as the activation function, which has the advantage of fast convergence. For an input column vectorx1,…,xnT, the function output is(6)fxi=xi,xi>0,0,xi≤0,,foriin1,…,n,x=x1,…,xnT.In this paper, the output layer uses the SoftMax activation function to normalize the output into a probability distribution. For an input column vectorx1,…,xnT, the function output is(7)fxi=exi∑j=1nexi,foriin1,…,n,x=x1,…,xnT.The loss function evaluates the difference between the predicted outputy^ and the true value y. In this paper, the cross-entropy loss function is used, and its function for an n-class classification problem is(8)Lossy^,y=−∑i=1nyilogy^i+1−yilog1−y^i,where y^=y^1,…,y^n is the predicted output and y=y1,…,ynis usually obtained by the one-hot encoding of the true class.In this study, the Adam algorithm optimizes the model parameters. It has the advantages of the adaptive learning rate, fast convergence, and stable results. This article uses TensorFlow 2, a deep learning open-source tool released by Google, to build, train, and test the models.


### 2.3. Dataset Construction

According to the overall algorithm design, there are two classifiers, and the cores of them are deep learning-based neural network models. They are trained on two datasets, named ECG_200 ms_POS_72 and ECG_RRR_TYPE_360, respectively.The generation of the ECG_200 ms_POS_72 and ECG_RRR_TYPE_360 datasets from the MIT-BIH database is shown in Figure3. To ensure the validity of the dataset, we should eliminate the relevant data in the superclass OTHER. Meanwhile, when intercepting ECG_RRR, a moving window with a length of 200 ms (72) and a step of 100 ms (36) splits the original data.Figure 3
Schematic diagram of generating the ECG_200 ms_POS_72 and ECG_RRR_TYPE_360 datasets from the MIT-BIH database. The ECG_200 ms_POS_72 dataset is used to train Classifier 1 for QRS complex position prediction. Each of these samples contains an ECG segment (ECG_200 ms) and the corresponding QRS complex position label. The ECG_200 ms is a 200 ms ECG-MLII lead ECG segment with a length of 72 (when the sampling rate is 360 Hz) in mV. The labelp is the center position of the QRS complex (an integer in [0, 71], where 0 means no QRS complex). The ECG_RRR_TYPE_360 dataset is used to train Classifier 2 for arrhythmia classification. Each of these samples contains an ECG_RRR feature and a corresponding arrhythmia type (TYPE). An ECG_RRR ECG segment is the MLII lead ECG data between every three QRS complexes resampled to a fixed length of 360 in mV. The data label TYPE is the arrhythmia type corresponding to the middle QRS complex (an integer in [0, 12], which represents 13 classes of arrhythmia).Figure4 shows partial waveform diagrams of various ECG_RRR features. There are apparent differences in the morphological characteristics of various ECG_RRR features, which further proves the effectiveness of ECG_RRR features for arrhythmia classification.Figure 4
Partial waveform diagrams of various ECG_RRR features.This paper constructs the two datasets (ECG_200 ms_POS_72 and ECG_RRR_TYPE_360) after processing all 44 records. Table2 shows the description of the constructed two datasets. Table 3 shows the distribution of samples in the ECG_200 ms_POS_72 dataset, which contains a total of 794,376 samples (sample_A). Among them, 590,230 samples (sample_N) are negative samples with label 0, indicating that no QRS complex is included. The other 204,146 samples (sample_P) are positive examples with positive integer labels, meaning that the QRS complex is included. The positive label values are approximately uniformly distributed in [1, 71]. The average value (P_ave) of the distribution is 2875.30, the maximum value (P_max) is 3019, the minimum value (P_min) is 2784, and the variance (P_s) is 55.13. Table 4 shows the distribution of the samples in the ECG_RRR_TYPE_360 dataset, which contains a total of 97,898 records. Although the data of Categories F (fusion beat) and Q (unknown beat) are imbalanced (the amount of data is small), these two categories are not the main classification targets of the classifier.Table 2
The description of the constructed two datasets.
DatasetECG_200 ms_POS_72ECG_RRR_TYPE_360Input200 ms ECG segment (mV)“ECG_RRR” feature (mV)Input shape72360OutputQRS complex position ([0, 71])Arrhythmia type ([0, 12])Output shape11Total samples79437697898Table 3
Statistics of label distribution in the ECG_200 ms_POS_72 dataset.
Groupsample_Asample_Nsample_PP_aveP_maxP_minP_sDS13971882937971033911456.211551138436.39DS23971882964331007551419.081490131836.88DS1 + DS27943765902302041462875.303019278455.13Table 4
Distribution statistics of samples in the ECG_RRR_TYPE_360 dataset.
SuperclassDS1DS2SubclassDS1DS2N4505543237N3731035503L39414122R37743400e160j14212SVEB5761741A4661678a7635J3228S20VEB34123104V33093103E1031F373385F373385Q87Q87


### 2.4. QRS Position Detection

The QRS position detection subalgorithm marks the position of the QRS complex in the ECG signal so that the overall algorithm can segment the heartbeat. In this paper, the input of the QRS position detection subalgorithm is the 200 ms ECG segment with a length of 72, and the output is the QRS complex position (an integer in [1, 71]) or 0 (when the QRS complex is not included).This subalgorithm consists of a 72-class FFNN-based model (named Model_QRS) and a QRS detection strategy.The Model_QRS model is trained and evaluated on the DS1 group of the ECG_200 ms_POS_72 dataset, which is randomly divided into a training set (train set) and a validation set (valid set) with a ratio of 8 : 2. The test set consists of the data in the DS2 group of the ECG_200 ms_POS_72 dataset.To reduce the computational cost and meet the requirements of edge computing equipment, it is a good idea to use as small a model as possible to obtain better results. Therefore, grid searching is employed to identify the optimal model for QRS position detection. This paper designs all hidden layers to the same size to facilitate searching. As shown in Figure5, the number of hidden layers varies from 1 to 8. Since the input feature size is 72, the candidate size of each hidden layer is {9, 18, 36, 72, 144}.Figure 5
The search grid for an appropriate FFNN model for QRS detection.Sometimes there is a slight error between the marked points in the MIT-BIH database and the actual QRS complex position. It also allows a certain error to exist in the QRS complex position prediction in practice. Therefore, this article concerns more about the accuracy (named acc2) that the QRS complex position is within the tolerated error range (±5).The sizes of the input and output layers are both 72 (the result of the QRS complex position is the index of the maximum value in the output layer). After training the model with the cross-entropy loss, Adam optimizer, and early stopping strategy (if the loss of the model is less than 1e − 5 for consecutive five epochs, stop training to prevent overfitting), we get the result of grid searching, which is shown in Figure 6. As can be seen from the figure, with the increase of the number and size of hidden layers, the accuracy of the model improves, but when the size of each hidden layer is greater than 36 and the number of hidden layers is greater than three, the improvement of acc2 is not significant. Therefore, in this paper, an FFNN model with three hidden layers and 36 neurons in each hidden layer is selected as the model for Classifier 1 for QRS position detection. Figure 7 shows the structure of the final selected FFNN model. Table 5 shows the details of each layer of the model. The number of parameters in this model is 7956, the model size is about 32 kB, and the amount of computation required for the model is 16092 FLOPs (floating-point operations [39]). Figure 8 shows the accuracy and loss curves of the model training process.Figure 6
Training results of the models with different layer numbers and sizes in grid search.Figure 7
The structure of the final selected FFNN model for QRS complex position detection.Table 5
Layers of the final selected FFNN model for QRS complex position detection.
IndexNameLayer typeActive functionOutput shapeParams0InputInput—7201Hidden0DenseReLU3626282Hidden1DenseReLU3613323Hidden2DenseReLU3613324OutputOutputSoftMax722664Figure 8
The accuracy and loss curves during the training process of the FFNN model for QRS position prediction.Finally, the acc2 on the test set is 96.8%.The algorithm uses a strategy based on a step-window voting mechanism when the model is deployed in production to improve the accuracy, as shown in Figure9:(1)
The algorithm caches the latest ECG segment with a length of 144 and a duration of 400 ms and uniformly usesN windows with length 72 to obtain N 200 ms ECG segments ecg_w72N.(2)
The algorithm inputs theecg_w72N to the FFNN model to get the results of N QRS complex positions QRSsN.(3)
The final QRS positionqrs and total votes vote are calculated according to QRSsN. The prediction result qrs of this QRS complex is retained only when vote is greater than threshold V and the position from the previous QRS complex is greater than threshold L. The values of thresholds VandL and the number of windows N can be adjusted according to requirements.Figure 9
QRS detection strategy based on a step-window voting mechanism.In this paper, we chooseN=8,V=4,andL=72 and use all 22 records of the DS2 group in the original data to evaluate Classifier 1 (for QRS position detection). The recall rate, precision rate, and overall accuracy of QRS complex position prediction are 98.0%, 99.5%, and 97.6%, respectively.


### 2.5. Heartbeat Classification

The heartbeat classification subalgorithm uses the ECG_RRR feature. Since there are only 13 classes of arrhythmia in MIT-BIH, this subalgorithm is a 13-class arrhythmia classification model that can get 5-class arrhythmia classification according to the class hierarchy.Since ECG_RRR features have relatively strong morphological characteristics, the core of this subalgorithm is a 13-class classifier based on the CNN model (named Model_TYRE) and uses the ECG_RRR_TYPE_360 dataset for training and evaluation. We use the DS1 group of the ECG_RRR_TYPE_360 dataset as training data, which is further randomly split into a training set (train set) and a validation set (valid set) with a ratio of 8 : 2. The test data comes from the DS2 group of the ECG_RRR_TYPE_360 dataset.The input of the model is the ECG_RRR feature proposed in this paper, with a length of 360 and clear morphological characteristics. Therefore, a one-dimensional CNN model constructs the model, and the result shows that this model has a good performance.After considering the tradeoff between the size and accuracy of the model, we select a structure of the CNN-based model and show it in Figure10. Table 6 shows the details of the model. The number of parameters in this model is 6273, the model size is about 25 kB, and the amount of computation required is 105678 FLOPs (floating-point operations [39]). The input of the model is the ECG_RRR feature with a depth of 1 and a length of 360. The model then uses a cascade of three one-dimensional convolutional layers and pooling layers to transform the data into features with depth 20 and length 6. Then, a flatten layer flattens the features to a vector of length 120. Finally, two full connection layers of size 30 and one output layer obtain an output of length 13, each representing the probability of one of the 13 classes. The output with the highest probability is the model’s predicted class, and then, the 5-class prediction is obtained according to the class hierarchy.Figure 10
The structure of the CNN-based heartbeat classification model.Table 6
Layers of the CNN-based heartbeat classification model.
IndexNameLayer typeF (x)ShapeParams0InputReshape—360, 101Hidden1Conv1DReLU360, 5302Hidden2MaxPool1DReLU72, 503Hidden3Conv1DReLU72, 102604Hidden4MaxPool1DReLU18, 1005Hidden5Conv1DReLU18, 2010206Hidden6MaxPool1DReLU6, 2007Hidden7FlattenReLU12008Hidden8DenseReLU3036309Hidden9DenseReLU3093010OutputDenseSoftMax13403To prevent overfitting, dropout is applied on pooling layers and full connection layers during model training and randomly disables 30% of neuron connections.After training the model with the cross entropy, Adam optimizer, and early stopping strategy (if the loss of the model is less than 1e − 5 for consecutive five epochs, it stops training to prevent overfitting), the accuracy and loss curves during the training process are shown in Figure 11. Since the dropout is applied in the training process, the training loss is higher than the validation loss, and the training accuracy is lower than the validation accuracy.Figure 11
The accuracy and loss curves during the training process of the heartbeat classification model based on CNN.Since the data in the DS1 and DS2 groups belong to different patients and the model only learns on 80% of the data in the DS1 group, the performance of the model on the DS2 group is an indicator of interpatient performance. The accuracy of 13-class classification is not good enough (only 77.0%), but the accuracy of 5-class classification according to the hierarchy is as high as 94.2%.


## 2.1. Data Description

The MIT-BIH arrhythmia database [33] is published by the Massachusetts Institute of Technology-Beth Israel Hospital. It contains 48 ECG records with a sampling rate of 360 Hz and a duration of 30 minutes. In this paper, only the ECG signals of the MLII lead are used for arrhythmia classification, which requires less hardware and computational cost, while giving a satisfactory overall accuracy [31, 34].ANSI/AAMI [35] categorizes the 15 recommended classes of arrhythmia into five superclasses which are normal (N), supraventricular ectopic beat (SVEB), ventricular ectopic beat (VEB), fused beat (F), and unknown beats (Q). It is recommended to classify with only these superclasses. Since there are only 13 classes of arrhythmia in MIT-BIH, this paper designs the heartbeat classification model as a 13-class classification model, which can then get the 5-class classification results according to the class hierarchy. Some studies also classify arrhythmia into other five classes: normal (N), left bundle branch block (LBBB), right bundle branch block (RBBB), premature ventricular contraction (PVC), and atrial premature beat (APB) [36–38].To better adapt to the actual environment and to improve the practicality of the algorithm, this paper divides the 44 records in the MIT-BIH database without pacemakers into two groups, according to the work of Chazal et al. [16]. The first group, named the DS1 group, consists of the records of 101, 106, 108, 109, 112, 114, 115, 116, 118, 119, 122, 124, 201, 203, 205, 207, 208, 209, 215, 220, 223, and 230. The second group, named the DS2 group, consists of the records of 100, 103, 105, 111, 113, 117, 121, 123, 200, 202, 210, 212, 213, 214, 219, 221, 222, 228, 231, 232, 233, and 234. The records of Groups DS1 and DS2 are basically from different patients (201 and 202 are from the same patient but in different groups). Figure 1 shows part of the waveform of each data record in the DS1 and DS2 groups.Figure 1
Part of the waveform of each data record in the DS1 and DS2 groups.Table1 shows the hierarchy of superclasses and subclasses in arrhythmia classes. It also contains descriptions and quantity statistics of each class in Groups DS1 and DS2. Since some nonbeat annotations exist in the MIT-BIH database, this article marks them as the OTHER superclass. The relevant data should be excluded from the following process of constructing datasets.Table 1
Description and quantity statistics of each class in the MIT-BIH database.
Superclass labels and descriptionsAllds0ds1Subclass labels and descriptionsAllds0ds1(N) any heartbeat not categorized as SVEB, VEB, F, or Q901254586644259(N) normal beat745463810236444(L) left bundle branch block beat807539494126(R) right bundle branch block beat725937833476(j) nodal (junctional) escape beat22916213(e) atrial escape beat16160(SVEB) supraventricular ectopic beat27819441837(A) atrial premature beat25468101736(a) aberrated atrial premature beat15010050(J) nodal (junctional) premature beat833251(S) supraventricular premature or ectopic beat220(VEB) ventricular ectopic beat700937883221(V) premature ventricular contraction690336833220(E) ventricular escape beat1061051(F) fusion beat803415388(F) fusion of ventricular and normal beat803415388(Q) unknown beat1587(Q) unclassifiable beat1587(OTHER) nonbeat annotations299115151476(+) rhythm change1173616557(∼) change in signal quality573289284(!) ventricular flutter wave4724720(") comment annotation4372435(x) Nonconducted P-wave (blocked APC)19358135(|) isolated QRS-like artifact1316665([) start of ventricular flutter/fibrillation660(]) end of ventricular flutter/fibrillation660


## 2.2. Overall Design

The overall algorithm design is shown in Figure2:(1)
The real-time ECG signal sequence is cut into ECG segments with a 200 ms time window(2)
The algorithm detects the QRS complex positions with Classifier 1 in the ECG segments(3)
The algorithm caches ECG data and extracts the time-domain feature (named ECG_RRR) based on the last three QRS complex positions(4)
Classifier 2 predicts arrhythmias using the ECG_RRR featureFigure 2
Schematic diagram of the overall algorithm.The algorithm’s output is the arrhythmia type and the corresponding QRS complex position information. As shown in Figure2, the ECG_RRR feature is a resampled ECG sequence with a fixed length. The starting point of the sequence is the last R wave point of the current heartbeat cycle, and the endpoint is the next R wave point of the current heartbeat cycle. Therefore, the ECG_RRR feature contains the complete ECG signal of the current heartbeat cycle. Meanwhile, to improve the accuracy of QRS complex detection, Classifier 1 adopts a step-window voting mechanism to ensure that the moving window contains complete QRS complex information. Since the preprocessing of the ECG signal (such as removing baseline offset, noise, and power-line interference) should be done at the acquisition devices, this algorithm does not consider signal preprocessing.The 200 ms time window is selected because it not only guarantees real-time performance but also ensures that each two adjacent time windows contain no more than one complete QRS complex.The real-time ECG signal is cut into ECG segments (namedECG_200ms, length is 72 when the sample rate is 360 Hz in this paper) by a 200 ms time window, expressed by(1)ECG_200ms=ECGsn:n+72.TheECG_200ms is input into Classifier 1, which outputs an integer qrs. qrs=0 means that the input ECG segment does not contain QRS complexes. 0<qrs≤72 means that the input ECG segment contains QRS complexes and the center position of the QRS complex is qrs. The position of this QRS complex in the ECG signal is qrs+n and is stored in the QRS buffer.After obtaining the position of the last three consecutive QRS complexesQRSm−2,QRSm−1,andQRSm, the heart rate (HR) and heart rate variability (HRV) are calculated by(2)HRm−1=QRSm−1−QRSm−2fs×60,HRm=QRSm−QRSm−1fs×60,HRVm=HRm−HRm−1HRm−1×100%,where fs is the sampling rate of ECG (360 Hz in this paper).Only whenHRm−1 and HRm are both within the normal range (30∼150), the three QRS positions are considered valid. Then, the ECG_RRR feature is obtained by resampling the ECG signal in the ECG buffer between QRSm−2 and QRSm into 360 data points.Finally, the ECG_RRR feature is input into Classifier 2 which outputs the arrhythmia classificationTYPEm−1 of the heartbeat cycle at QRSm−1.The ECG_RRR feature is selected for arrhythmia heartbeat classification because it contains both the complete information of the current heartbeat cycle and partial information of the preceding and succeeding heartbeat cycles as the heart rate variation information.Classifiers 1 and 2 are both based on deep learning models. According to the characteristics of the input features, Classifier 1 uses a Deep Neural Network (DNN) model of fully connected layers, also called Feedforward Neural Network (FFNN). Classifier 2 uses the Convolutional Neural Network (CNN) model. CNN is a neural network with multiple hidden layers such as fully connected layers, convolutional layers, and pooling layers. CNN is a type of DNN with convolutional layers and pooling layers to extract and abstract features.For the fully connected layers, which are directly connected layer by layer, the forward propagation from the layerl−1 with m features to the layer l with n features is(3)Xl=flWlXl−1+Bl.The formula in the matrix form is(4)x1l⋮xnl=flw1l1…w1ln⋮⋱⋮wml1…wmlnx1l−1⋮xnl−1+b1l⋮bnl,where Xl−1 is the feature vector of the layer l−1, a column vector of length m, Xl is the feature vector of the layer l, a column vector of length n, Wl is the weight matrix of the layer l, a matrix of m rows and n columns, Bl is the bias vector of the layer l, a column vector of length n, and fl is the nonlinear activation function of the layerl.Each convolution layer contains several convolution kernels. The features of the previous layer are convolved with the corresponding convolution kernels to output new features. For the layerl−1 with depth i(the feature maps are X1l−1,…,Xil−1), after the operation of the convolution layer (with learnable convolution kernels K1,1l,…,Ki,1l,…,K1,jl,…,Ki,jl and learnable bias B1l,…,Bjl), the layer l with depth j (the feature maps are X1l,…,Xjl) is obtained. The calculation formula of each feature map is(5)Xjl=fl∑i∈MjXil−1⊗Ki,jl+Bjl,where Mj is the set of input feature maps, ⊗ is the convolution operation, and fl is the activation function.For a CNN model, there is usually a pooling layer following the convolutional layer to reduce the feature size. After several convolutional layers and pooling layers, a flatten layer transforms the features into a vector, and then, the output is obtained through several fully connected layers.In this study, the hidden layer uses the linear rectification function (Rectified Linear Unit, ReLU) as the activation function, which has the advantage of fast convergence. For an input column vectorx1,…,xnT, the function output is(6)fxi=xi,xi>0,0,xi≤0,,foriin1,…,n,x=x1,…,xnT.In this paper, the output layer uses the SoftMax activation function to normalize the output into a probability distribution. For an input column vectorx1,…,xnT, the function output is(7)fxi=exi∑j=1nexi,foriin1,…,n,x=x1,…,xnT.The loss function evaluates the difference between the predicted outputy^ and the true value y. In this paper, the cross-entropy loss function is used, and its function for an n-class classification problem is(8)Lossy^,y=−∑i=1nyilogy^i+1−yilog1−y^i,where y^=y^1,…,y^n is the predicted output and y=y1,…,ynis usually obtained by the one-hot encoding of the true class.In this study, the Adam algorithm optimizes the model parameters. It has the advantages of the adaptive learning rate, fast convergence, and stable results. This article uses TensorFlow 2, a deep learning open-source tool released by Google, to build, train, and test the models.


## 2.3. Dataset Construction

According to the overall algorithm design, there are two classifiers, and the cores of them are deep learning-based neural network models. They are trained on two datasets, named ECG_200 ms_POS_72 and ECG_RRR_TYPE_360, respectively.The generation of the ECG_200 ms_POS_72 and ECG_RRR_TYPE_360 datasets from the MIT-BIH database is shown in Figure3. To ensure the validity of the dataset, we should eliminate the relevant data in the superclass OTHER. Meanwhile, when intercepting ECG_RRR, a moving window with a length of 200 ms (72) and a step of 100 ms (36) splits the original data.Figure 3
Schematic diagram of generating the ECG_200 ms_POS_72 and ECG_RRR_TYPE_360 datasets from the MIT-BIH database. The ECG_200 ms_POS_72 dataset is used to train Classifier 1 for QRS complex position prediction. Each of these samples contains an ECG segment (ECG_200 ms) and the corresponding QRS complex position label. The ECG_200 ms is a 200 ms ECG-MLII lead ECG segment with a length of 72 (when the sampling rate is 360 Hz) in mV. The labelp is the center position of the QRS complex (an integer in [0, 71], where 0 means no QRS complex). The ECG_RRR_TYPE_360 dataset is used to train Classifier 2 for arrhythmia classification. Each of these samples contains an ECG_RRR feature and a corresponding arrhythmia type (TYPE). An ECG_RRR ECG segment is the MLII lead ECG data between every three QRS complexes resampled to a fixed length of 360 in mV. The data label TYPE is the arrhythmia type corresponding to the middle QRS complex (an integer in [0, 12], which represents 13 classes of arrhythmia).Figure4 shows partial waveform diagrams of various ECG_RRR features. There are apparent differences in the morphological characteristics of various ECG_RRR features, which further proves the effectiveness of ECG_RRR features for arrhythmia classification.Figure 4
Partial waveform diagrams of various ECG_RRR features.This paper constructs the two datasets (ECG_200 ms_POS_72 and ECG_RRR_TYPE_360) after processing all 44 records. Table2 shows the description of the constructed two datasets. Table 3 shows the distribution of samples in the ECG_200 ms_POS_72 dataset, which contains a total of 794,376 samples (sample_A). Among them, 590,230 samples (sample_N) are negative samples with label 0, indicating that no QRS complex is included. The other 204,146 samples (sample_P) are positive examples with positive integer labels, meaning that the QRS complex is included. The positive label values are approximately uniformly distributed in [1, 71]. The average value (P_ave) of the distribution is 2875.30, the maximum value (P_max) is 3019, the minimum value (P_min) is 2784, and the variance (P_s) is 55.13. Table 4 shows the distribution of the samples in the ECG_RRR_TYPE_360 dataset, which contains a total of 97,898 records. Although the data of Categories F (fusion beat) and Q (unknown beat) are imbalanced (the amount of data is small), these two categories are not the main classification targets of the classifier.Table 2
The description of the constructed two datasets.
DatasetECG_200 ms_POS_72ECG_RRR_TYPE_360Input200 ms ECG segment (mV)“ECG_RRR” feature (mV)Input shape72360OutputQRS complex position ([0, 71])Arrhythmia type ([0, 12])Output shape11Total samples79437697898Table 3
Statistics of label distribution in the ECG_200 ms_POS_72 dataset.
Groupsample_Asample_Nsample_PP_aveP_maxP_minP_sDS13971882937971033911456.211551138436.39DS23971882964331007551419.081490131836.88DS1 + DS27943765902302041462875.303019278455.13Table 4
Distribution statistics of samples in the ECG_RRR_TYPE_360 dataset.
SuperclassDS1DS2SubclassDS1DS2N4505543237N3731035503L39414122R37743400e160j14212SVEB5761741A4661678a7635J3228S20VEB34123104V33093103E1031F373385F373385Q87Q87


## 2.4. QRS Position Detection

The QRS position detection subalgorithm marks the position of the QRS complex in the ECG signal so that the overall algorithm can segment the heartbeat. In this paper, the input of the QRS position detection subalgorithm is the 200 ms ECG segment with a length of 72, and the output is the QRS complex position (an integer in [1, 71]) or 0 (when the QRS complex is not included).This subalgorithm consists of a 72-class FFNN-based model (named Model_QRS) and a QRS detection strategy.The Model_QRS model is trained and evaluated on the DS1 group of the ECG_200 ms_POS_72 dataset, which is randomly divided into a training set (train set) and a validation set (valid set) with a ratio of 8 : 2. The test set consists of the data in the DS2 group of the ECG_200 ms_POS_72 dataset.To reduce the computational cost and meet the requirements of edge computing equipment, it is a good idea to use as small a model as possible to obtain better results. Therefore, grid searching is employed to identify the optimal model for QRS position detection. This paper designs all hidden layers to the same size to facilitate searching. As shown in Figure5, the number of hidden layers varies from 1 to 8. Since the input feature size is 72, the candidate size of each hidden layer is {9, 18, 36, 72, 144}.Figure 5
The search grid for an appropriate FFNN model for QRS detection.Sometimes there is a slight error between the marked points in the MIT-BIH database and the actual QRS complex position. It also allows a certain error to exist in the QRS complex position prediction in practice. Therefore, this article concerns more about the accuracy (named acc2) that the QRS complex position is within the tolerated error range (±5).The sizes of the input and output layers are both 72 (the result of the QRS complex position is the index of the maximum value in the output layer). After training the model with the cross-entropy loss, Adam optimizer, and early stopping strategy (if the loss of the model is less than 1e − 5 for consecutive five epochs, stop training to prevent overfitting), we get the result of grid searching, which is shown in Figure 6. As can be seen from the figure, with the increase of the number and size of hidden layers, the accuracy of the model improves, but when the size of each hidden layer is greater than 36 and the number of hidden layers is greater than three, the improvement of acc2 is not significant. Therefore, in this paper, an FFNN model with three hidden layers and 36 neurons in each hidden layer is selected as the model for Classifier 1 for QRS position detection. Figure 7 shows the structure of the final selected FFNN model. Table 5 shows the details of each layer of the model. The number of parameters in this model is 7956, the model size is about 32 kB, and the amount of computation required for the model is 16092 FLOPs (floating-point operations [39]). Figure 8 shows the accuracy and loss curves of the model training process.Figure 6
Training results of the models with different layer numbers and sizes in grid search.Figure 7
The structure of the final selected FFNN model for QRS complex position detection.Table 5
Layers of the final selected FFNN model for QRS complex position detection.
IndexNameLayer typeActive functionOutput shapeParams0InputInput—7201Hidden0DenseReLU3626282Hidden1DenseReLU3613323Hidden2DenseReLU3613324OutputOutputSoftMax722664Figure 8
The accuracy and loss curves during the training process of the FFNN model for QRS position prediction.Finally, the acc2 on the test set is 96.8%.The algorithm uses a strategy based on a step-window voting mechanism when the model is deployed in production to improve the accuracy, as shown in Figure9:(1)
The algorithm caches the latest ECG segment with a length of 144 and a duration of 400 ms and uniformly usesN windows with length 72 to obtain N 200 ms ECG segments ecg_w72N.(2)
The algorithm inputs theecg_w72N to the FFNN model to get the results of N QRS complex positions QRSsN.(3)
The final QRS positionqrs and total votes vote are calculated according to QRSsN. The prediction result qrs of this QRS complex is retained only when vote is greater than threshold V and the position from the previous QRS complex is greater than threshold L. The values of thresholds VandL and the number of windows N can be adjusted according to requirements.Figure 9
QRS detection strategy based on a step-window voting mechanism.In this paper, we chooseN=8,V=4,andL=72 and use all 22 records of the DS2 group in the original data to evaluate Classifier 1 (for QRS position detection). The recall rate, precision rate, and overall accuracy of QRS complex position prediction are 98.0%, 99.5%, and 97.6%, respectively.


## 2.5. Heartbeat Classification

The heartbeat classification subalgorithm uses the ECG_RRR feature. Since there are only 13 classes of arrhythmia in MIT-BIH, this subalgorithm is a 13-class arrhythmia classification model that can get 5-class arrhythmia classification according to the class hierarchy.Since ECG_RRR features have relatively strong morphological characteristics, the core of this subalgorithm is a 13-class classifier based on the CNN model (named Model_TYRE) and uses the ECG_RRR_TYPE_360 dataset for training and evaluation. We use the DS1 group of the ECG_RRR_TYPE_360 dataset as training data, which is further randomly split into a training set (train set) and a validation set (valid set) with a ratio of 8 : 2. The test data comes from the DS2 group of the ECG_RRR_TYPE_360 dataset.The input of the model is the ECG_RRR feature proposed in this paper, with a length of 360 and clear morphological characteristics. Therefore, a one-dimensional CNN model constructs the model, and the result shows that this model has a good performance.After considering the tradeoff between the size and accuracy of the model, we select a structure of the CNN-based model and show it in Figure10. Table 6 shows the details of the model. The number of parameters in this model is 6273, the model size is about 25 kB, and the amount of computation required is 105678 FLOPs (floating-point operations [39]). The input of the model is the ECG_RRR feature with a depth of 1 and a length of 360. The model then uses a cascade of three one-dimensional convolutional layers and pooling layers to transform the data into features with depth 20 and length 6. Then, a flatten layer flattens the features to a vector of length 120. Finally, two full connection layers of size 30 and one output layer obtain an output of length 13, each representing the probability of one of the 13 classes. The output with the highest probability is the model’s predicted class, and then, the 5-class prediction is obtained according to the class hierarchy.Figure 10
The structure of the CNN-based heartbeat classification model.Table 6
Layers of the CNN-based heartbeat classification model.
IndexNameLayer typeF (x)ShapeParams0InputReshape—360, 101Hidden1Conv1DReLU360, 5302Hidden2MaxPool1DReLU72, 503Hidden3Conv1DReLU72, 102604Hidden4MaxPool1DReLU18, 1005Hidden5Conv1DReLU18, 2010206Hidden6MaxPool1DReLU6, 2007Hidden7FlattenReLU12008Hidden8DenseReLU3036309Hidden9DenseReLU3093010OutputDenseSoftMax13403To prevent overfitting, dropout is applied on pooling layers and full connection layers during model training and randomly disables 30% of neuron connections.After training the model with the cross entropy, Adam optimizer, and early stopping strategy (if the loss of the model is less than 1e − 5 for consecutive five epochs, it stops training to prevent overfitting), the accuracy and loss curves during the training process are shown in Figure 11. Since the dropout is applied in the training process, the training loss is higher than the validation loss, and the training accuracy is lower than the validation accuracy.Figure 11
The accuracy and loss curves during the training process of the heartbeat classification model based on CNN.Since the data in the DS1 and DS2 groups belong to different patients and the model only learns on 80% of the data in the DS1 group, the performance of the model on the DS2 group is an indicator of interpatient performance. The accuracy of 13-class classification is not good enough (only 77.0%), but the accuracy of 5-class classification according to the hierarchy is as high as 94.2%.


## 3. Results and Discussion

In the experimental test, the algorithm first uses Classifier 1 to predict the QRS complex position, which assists in segmenting the ECG_RRR feature. It then uses Classifier 2 to predict the corresponding arrhythmia type. Finally, the QRS position predictions and the corresponding arrhythmia predictions are compared with the ground truth in the database to obtain the evaluation results.This paper uses all the 44 patients’ MLII lead original ECG signals in Groups DS1 and DS2 of the MIT-BIH arrhythmia database to test the overall algorithm. Besides, the interpatient performance of the algorithm is obtained by testing on the data in the DS2 group, which is also an important evaluation metric in practice.For each of these records, the classification pipeline is as follows: firstly, the ECG signal of MLII lead is sliced by a 200 ms time window and passed into the algorithm chronologically. The algorithm then predicts the position of the QRS complex and the corresponding arrhythmia class in real time. After all data in this record is entered, the predictions of the QRS complex position sequence (QRS_pred) and the corresponding heartbeat type sequence (TYPE_pred) are obtained. Meanwhile, the ground truth QRS complex position sequence (QRS_true) and the corresponding heartbeat type sequence (TYPE_true) are obtained by analyzing the marker information in this record. Finally, by comparing QRS_pred and TYPE_pred with QRS_true and TYPE_true, respectively, the corresponding confusion matrix and statistical matrix are obtained. When comparing QRS_true with QRS_Pred, a certain error of ±5 is allowed.The recall rate (R), precision rate (P), and overall accuracy (Acc) are the evaluation metrics of classification performance. For an n-class classification problem with classes x1,x2,…,xn, the calculation formulas of precision rate, recall rate, and overall accuracy are as follows:(9)Pxi=NxixiNxi,(10)Rxi=NxixiNxi,(11)Acc=∑1nNxixi∑1nNxi=∑1nNxixi∑1nNxi,where Nxixj represents the number of samples whose true class is xi and predicted class is xj, Nxixi represents the number of samples whose true class and predicted class is both xi, Nxi represents the number of samples whose true class is xi, and Nxj represents the number of samples whose predicted class is xj.For the real-time ECG arrhythmia classification in this paper, there is a specific case in which the prediction of the QRS complex position is incorrect. This article marks this specific case as 0, and the quantity statistics are represented byN0xi and Nxi0, where N0xi represents the number of samples whose predicted class is xi in false-positive samples and Nxi0 represents the number of samples whose true class is xi in false-negative examples.For the 5-class arrhythmia classification, the results are recorded in the confusion matrix as Table7 and the statistical table as Table 8.Table 7
Example of a confusion matrix for the recording of 5-class arrhythmia classification test results.
PredictedNSVFQ0SumTrueNNNNNNSNNVNNFNNQNN0NNSNSNNSSNSVNSFNSQNS0NSVNVNNVSNVVNVFNVQNV0NVFNFNNFSNFVNFFNFQNF0NFQNQNNQSNQVNQFNQQNQ0NQ0N0NN0SN0VN0FN0Q−N0SumNNNSNVNFNQN0SUMTable 8
Example of a statistical table of 5-class arrhythmia classification test results.
No.NSVFQAccXX(P)PNPSPVPFPQAcc(R)RNRSRVRFRQThe recall rate, precision rate, and overall accuracy of N, S (SVEB), V (VEB), F, and Q are calculated according to the 6-class case regarding equations (9)–(11). Specifically, the numbers of false-positive (FP), false-negative (FN), and true-positive (TP) samples of QRS position prediction are calculated by(12)FPQRS=N0,FNQRS=N0,TPQRS=NN+NS+NV+NF+NQ−N0.The precision rate (P), recall rate (R), and overall accuracy (Acc) of QRS complex position prediction are calculated by(13)PQRS=TPQRSTPQRS+FPQRS,RQRS=TPQRSTPQRS+FNQRS,AccQRS=TPQRSTPQRS+FNQRS+FPQRS.After testing all records in the database, 44 confusion matrices are obtained. According to the DS1 and DS2 groups, two result Tables9 and 10 and a statistics Table 11 are obtained after synthesizing them.Table 9
Confusion matrix of 5-class arrhythmia classification test results on DS1.
PredictedNSVFQ0SumTrueN451417422110042045866S44541881072944V2098331511603293788F8403728806415Q2000068012136700—191Sum460025783484315083351212Table 10
Confusion matrix of 5-class arrhythmia classification of test results on DS2.
PredictedNSVFQ0SumTrueN425634464119083044259S15541904700461837V17221292990903221F2730106108388Q10300370115111610—233Sum44678658361220097749945Table 11
Statistics of 5-class arrhythmia classification test results.
No.NSVFQAccDS1(P)0.9810.7230.9040.914—0.957(R)0.9840.4430.8320.6940.000DS2(P)0.9530.2890.8110.050—0.915(R)0.9620.1030.9090.0030.000ALL(P)0.9670.4920.8570.863—0.936(R)0.9730.2190.8670.3600.000From Tables9 and 10, it can be calculated that, for the DS1 group, the recall rate, precision rate, and overall accuracy are 98.3%, 99.6%, and 98.0%, respectively. For the DS2 group, they are 98.0%, 99.5%, and 97.6%, respectively.Table11 shows that, on the data in the MIT-BIH database, the overall accuracy for 5-class arrhythmia classification is 93.6%, and the interpatient accuracy is 91.5%. The statistics of each patient’s 5-class arrhythmia classification results in Group DS2 are shown in Table 12, and the distribution of overall accuracy is shown in Figure 12. As shown in the table, except for the extremely low accuracy of Patient 232 and the low accuracy of Patients 222, 219, and 213, the accuracies of the other 18 patients are all above 90%.Table 12
Statistics of 5 arrhythmia classes for each patient on DS2.
No.NSVFQAcc103(R)0.9991.000———0.999(P)1.0000.500———100(R)0.9990.9711.000——0.998(P)0.9991.0001.000——212(P)0.998————0.996(R)0.9980.0000.000——……………………219(P)0.7800.8570.9060.000—0.782(R)0.9980.0190.287——222(P)0.7980.306———0.756(R)0.9380.7800.000——232(R)0.2280.9090.000——0.247(P)0.9800.036———Figure 12
The overall accuracy of each patient’s 5-class arrhythmia classification on DS2.Table13 summarizes the comparisons of the proposed algorithm and state-of-the-art methods which do not require expert intervention. It demonstrates that the proposed algorithm has an advantage in overall accuracy, although the recall rate and precision rate of the SVEB classification are lower than those of the other studies. The algorithm of this paper uses the heartbeat segmentation provided by Classifier 1 for arrhythmia classification, and its overall accuracy may be affected by the error of heartbeat segmentation. However, many other studies just segment heartbeat by the marked points in the database for arrhythmia classification. For a fair comparison, the results of Classifier 2 on the DS2 group in the ECG_RRR_TYPE_360 dataset are also listed (proposed∗rows in the table), which is the interpatient arrhythmia classification performance using the heartbeat markers in the database.Table 13
Comparison of the proposed algorithm with other studies.
MethodAccP (N)R (N)P (SVEB)R (SVEB)P (VEB)R (VEB)P (F)R (F)Proposed0.9150.9530.9620.2890.1030.8110.9090.0500.003Proposed∗0.9420.9830.9580.1230.3330.9560.8620.0080.176Luo et al. [26]0.8930.9300.9530.4730.1540.6680.6040.2000.500Mar et al. [14]0.8900.9920.9420.5670.8620.9340.9240.1770.664Alvarado et al. [27]0.9360.9920.9420.5670.8620.9340.9240.1770.664Ye et al. [28]0.8820.9820.9000.5510.5640.6030.8470.0580.358Zhang et al. [29]0.8830.9900.8890.3600.7910.9280.8550.1370.938Niu et al. [30]0.9230.9740.9390.7320.7660.5780.8510.4490.384


## 4. Conclusions

Real-time monitoring of ECG and intelligent diagnosis in daily life are of great significance to reduce the risk of cardiovascular disease. With the development of wearable ECG measurement technology and edge computing, a real-time arrhythmia diagnosis system combining the two is a solution in which a reliable real-time arrhythmia classification algorithm is the core. This paper introduces a novel arrhythmia classification model which performs with high accuracy and in real time. The model takes the raw ECG signal as input and segments it with a time window. Then, it detects the QRS complex positions with an FFNN-based model and extracts the time-domain feature (ECG_RRR) for another CNN-based model to predict the arrhythmia type. Experimental results show that our model performs very well on the MIT-BIH dataset. In addition, our model requires low computing power for real-time prediction, which is available on most desktop and mobile processors.


### 4.1. Practicality

The input of the algorithm is the original ECG signal without complex feature extraction. Moreover, to adapt to different sampling rates, a sampling rate adaptation layer can be added before the algorithm is in practice.The core of the algorithm is deep learning that is already very mature. There are many excellent deep learning frameworks for cloud computing or mobile devices, such as TensorFlow, Caffe, PyTorch, and MXNet, so the proposed algorithm can be easily deployed.


### 4.2. Real Time

The cores of the algorithm are two deep learning-based classifiers with simple structure, high performance, and low computational cost.The input of the algorithm is a 200 ms ECG segment. The latency of detecting the QRS complex position is 400 ms, and the latency of arrhythmia classification is just one heartbeat cycle. The numbers of parameters in the two models are 7956 and 6273, respectively, and the computational requirements are 16092 FLOPs and 105678 FLOPs, respectively. Considering the use of a step-window voting strategy to detect QRS complexes, the comprehensive computation is 0.235 MFLOPs. The device only needs 1.2 MFLOPS (FLOPS means Floating-Point Operations Per Second) of floating-point operation capability to meet the computing needs. At present, desktop-level CPUs and GPUs can reach the magnitude of GFLOPS or even TFLOPS, and mobile processors can reach hundreds of MFLOPS. Therefore, the computational requirement of the algorithm is not a problem.


### 4.3. Effectiveness

The proposed algorithm includes two deep learning-based classifiers for QRS complex position detection and arrhythmia classification, respectively. Meanwhile, a strategy based on a step-by-step window voting mechanism is proposed to improve QRS complex position prediction accuracy.For interpatient performance, the recall rate, precision rate, and overall accuracy of the algorithm’s interpatient QRS complex position prediction are 98.0%, 99.5%, and 97.6%, respectively. The algorithm has overall accuracies of 91.5% and 75.6% for 5-class and 13-class arrhythmia classification, respectively.


## 4.1. Practicality

The input of the algorithm is the original ECG signal without complex feature extraction. Moreover, to adapt to different sampling rates, a sampling rate adaptation layer can be added before the algorithm is in practice.The core of the algorithm is deep learning that is already very mature. There are many excellent deep learning frameworks for cloud computing or mobile devices, such as TensorFlow, Caffe, PyTorch, and MXNet, so the proposed algorithm can be easily deployed.


## 4.2. Real Time

The cores of the algorithm are two deep learning-based classifiers with simple structure, high performance, and low computational cost.The input of the algorithm is a 200 ms ECG segment. The latency of detecting the QRS complex position is 400 ms, and the latency of arrhythmia classification is just one heartbeat cycle. The numbers of parameters in the two models are 7956 and 6273, respectively, and the computational requirements are 16092 FLOPs and 105678 FLOPs, respectively. Considering the use of a step-window voting strategy to detect QRS complexes, the comprehensive computation is 0.235 MFLOPs. The device only needs 1.2 MFLOPS (FLOPS means Floating-Point Operations Per Second) of floating-point operation capability to meet the computing needs. At present, desktop-level CPUs and GPUs can reach the magnitude of GFLOPS or even TFLOPS, and mobile processors can reach hundreds of MFLOPS. Therefore, the computational requirement of the algorithm is not a problem.


## 4.3. Effectiveness

The proposed algorithm includes two deep learning-based classifiers for QRS complex position detection and arrhythmia classification, respectively. Meanwhile, a strategy based on a step-by-step window voting mechanism is proposed to improve QRS complex position prediction accuracy.For interpatient performance, the recall rate, precision rate, and overall accuracy of the algorithm’s interpatient QRS complex position prediction are 98.0%, 99.5%, and 97.6%, respectively. The algorithm has overall accuracies of 91.5% and 75.6% for 5-class and 13-class arrhythmia classification, respectively.



---

*Source: 6648432-2021-05-17.xml*