Heartbeat classification system based on neural networks and dimensionality reduction

Introduction: This paper presents a complete approach for the automatic classification of heartbeats to assist experts in the diagnosis of typical arrhythmias, such as right bundle branch block, left bundle branch block, premature ventricular beats, premature atrial beats and paced beats. Methods: A pre-processing step was performed on the electrocardiograms (ECG) for baseline removal. Next, a QRS complex detection algorithm was implemented to detect the heartbeats, which contain the primary information that is employed in the classification approach. Next, ECG segmentation was performed, by which a set of features based on the RR interval and the beat waveform morphology were extracted from the ECG signal. The size of the feature vector was reduced by principal component analysis. Finally, the reduced feature vector was employed as the input to an artificial neural network. Results: Our approach was tested on the Massachusetts Institute of Technology arrhythmia database. The classification performance on a test set of 18 ECG records of 30 min each achieved an accuracy of 96.97%, a sensitivity of 95.05%, a specificity of 90.88%, a positive predictive value of 95.11%, and a negative predictive value of 92.7%. Conclusion: The proposed approach achieved high accuracy for classifying ECG heartbeats and could be used to assist cardiologists in telecardiology services. The main contribution of our classification strategy is in the feature selection step, which reduced classification complexity without major changes in the performance.


Introduction
Technological developments and cost reductions associated with internet access have contributed to the growth of telehealth services.These services are suitable in situations in which there is lack of health professionals or the nearest medical service center is located a great distance from those who require care.Among the various telemedicine modalities, telecardiology is related to the remote provision of cardiologic services.The main telecardiology service deals with the remote diagnostics of abnormalities presents in electrocardiograms (ECGs), which are sent through the internet to a telehealth center (Marcolino et al., 2012).The diagnostic report generated by the cardiologist is then sent back to the health professional who requested the service.The response time of the telecardiology service is critical depending on the severity of the diagnosis, as serious diseases require priority, early diagnosis and immediate treatment.To prioritize these cases, telecardiology services, in general, provide the health professional the option to manually classify that the request as urgent.Requests that are not classified as urgent are analyzed according to the arrival time (Andreão et al., 2013).Approximately 14% of ECG exams sent through a telecardiology service were manually classified as urgent (Sparenberg and Fetter, 2012), although the majority of these classifications corresponded to healthy people who did not require emergency treatment.On the other hand, several of the patients with electrocardiographic abnormalities have not received priority and remained in the waiting queue of non-urgent cases for a specialized report.The delay in generating reports for normal ECGs can harm patients who present an abnormality because, for some diseases, it is essential that the treatment be initiated quickly.
In this context, the Espírito Santo Telehealth program (Telessaúde ES, 2014) is proposing an automatic triage service for ECG exams (Andreão et al., 2013), where the most urgent cases are prioritized in the waiting queue to be diagnosed.The automatic triage service is integrated with the telecardiology service, and both are implemented on a web-based platform called Salus.Each telecardiology request consists of an ECG generated by a digital electrocardiograph uploaded through the Salus platform and made available to the cardiologist performing the report.The idea behind the triage service is to automatically classify each Volume 32, Number 4, p. 318-326, 2016 ECG stored in the waiting queue, where the abnormal ECGs are placed in the top positions of the waiting queue.Every time an ECG is stored on the platform, a notification is sent to the cardiologist via SMS and e-mail (Andreão et al., 2013).
A good classification performance is essential for an effective triage of urgent cases.In the literature, many studies proposes approaches based on machine learning, such as neural networks (Kim et al., 2011;Mohamad et al., 2013), support vector machines (She et al., 2010;Zhang et al., 2014), fuzzy logic (Arif et al., 2009), or linear discriminant analyses (Chazal et al., 2004), to perform automatic ECG classification.This paper also proposes a classification approach based on neural networks.The main contribution of our classification strategy is in the feature selection step; wherein, the goal is to improve classification performance.The classification approach was evaluated using the Physionet arrhythmia database, where the heartbeats from the ECG records were gathered into six different classes.The results are compared with other works published on the subject.

Methods
The ECG classification approach proposed for the automatic triage service is basically composed of three stages: pre-processing of the ECG signal, feature extraction and, finally, the automatic classification.A block diagram of the entire system is shown in Figure 1.

Data base
The development of this work requires a database with digital ECG records for computational analysis of different patients with different pathologies.Accordingly, we employed the widely known Massachusetts Institute of Technology (MIT) arrhythmia database, which is available on the website of the PhysioNet group (Goldberger et al., 2000).This database contains 48 records of two channels with half-hour durations each.The ECG signals were sampled at 360 Hz.It was necessary to apply a rescaling factor of 200 to the amplitude of the signal to obtain the values in millivolts.In addition to the ECG signal, annotations, made by different cardiologists in common consent, containing the beat localization and the beat class are also available.Only six beat classes were considered in this work: right bundle branch block (R), left bundle branch block (L), premature ventricular beat (V), premature atrial beat (A) and paced beat (PB).

Preprocessing
Each record contains raw ECG signal, which is usually a combination of the cardiac electrical activity and noise.Because the ECG signal has low amplitude, it is very sensitive to noise interference (Igarashi, 2007).Therefore, at this stage, we sought to eliminate the high-frequency noise and baseline wander.
To reduce the baseline wander, two median filters (Chazal et al., 2004) were used.First, a 200 ms median filter was applied to remove the P waves and the QRS complexes because these segments are shorter than 100 ms.The resulting signal was processed by another median filter with a window size of 600 ms to remove the T waves, which have width of approximately 150 ms.Finally, the resulting signal contained the baseline of the ECG signal, which was then subtracted from the original signal for ECG baseline correction (Figure 2).
On the other hand, a 12th order low-pass finite impulse response filter with a cutoff frequency of 35Hz was employed to eliminate high-frequency noise (Chazal et al., 2004).This filter was chosen because it fulfills the requirements for this work, achieving -3 dB gain at the cutoff frequency and having low complexity.

Detection of beats
The ECG signal must be segmented in terms of beats and its different waveforms (P wave, QRS complex and T wave) prior to the feature extraction stage.For beat detection, an algorithm that detects the peak of the QRS complex waveform was developed because it is the wave with the largest amplitude in the heartbeat.The algorithm used is based on the wavelet transform of the signal.To highlight the QRS complex, a Mexican hat wavelet function was chosen (Madeiro et al., 2007).The signal resulting from the wavelet transform was analyzed according to a threshold, where only the peaks greater than the threshold are selected.The minimum separation between consecutive peaks was 83 ms, which is wide enough to prevent the detection of positive and negative peaks of a single QRS complex as different QRS complexes.A threshold definition was used to avoid misidentification of P and T waves as QRS complex: signal amplitude should be larger than that of the 4 nearest peaks and reach 30% of the largest of the 20 nearest peaks.

ECG segmentation
An important stage in most ECG classification algorithms is segmentation, which consists of obtaining the onset, the peak and the offset of each beat waveform.The entire segmentation process is shown in Figure 3 and was applied on the first lead of each preprocessed record.
The peak of the QRS complex already detected was taken as the reference point for segmentation of the other waves.After a close inspection of the ECG signal from the database, it was observed that the onsets of all P waves were located no more than 280 ms before the QRS complex peak.Similarly, it was observed that the T wave offsets were located no more than 430 ms after the QRS peak.Thus, a good estimation of the limits of the heartbeat is 280 ms before the QRS complex peak and 430 ms after the QRS peak.
Considering a normal ECG, the QRS complex is a sequence of three waveforms (or three peaks) within approximately 220 ms around the QRS peak.The onset of the QRS complex is estimated considering two possible events and always selecting the event nearest to the largest peak.One of the events is the first zero crossing, and the other event is the transition from a smoother slope signal segment.To determine such a transition, the summation of a sequence of five values is considered, where each value is the difference between two consecutive samples, which is then applied as a threshold.The offset of the QRS complex, similarly to the onset, is estimated considering the same two events and always selecting the event nearest to the peak.
For the detection of the P and T wave peaks, the maximum amplitude points placed before and after the QRS complex are considered, respecting the limits of the heartbeat that were estimated in a previous processing step.Finally, the detection of the onset and offset of the P and T waves is performed according to the same strategy employed for the QRS complex onset and offset.

Feature extraction
The feature extraction stage takes into account the features commonly employed by other works in the field and the beat classes of the ECG database.As a consequence, 106 morphological features were selected, namely, the RR intervals, which are important for the detection of arrhythmias; the features obtained during the ECG segmentation, which consist of the peaks and durations of the different waves composing the signal; and some special features in the frequency domain, which are used in other works primarily for block detection.All the selected features are presented in Table 1.

Reduction of the feature vector dimension
A vector of 106 features is likely to have redundancy and strong correlation among some features.Moreover, the complexity of the classification stage grows with the number of features.Therefore, principal component analysis (PCA) was implemented to reduce the size of the feature vector.PCA is a useful statistical technique that has many applications in fields, such as facial recognition and image compression, and is widely used to identify patterns in high-dimensional data (Smith, 2002).This technique consists of reducing a feature vector by linear transformation as to lose as little information as possible.
In this work, the PCA technique was applied to select the best 25 features while retaining 99.93% of the information.Usually, the features are normalized, but in this study this was not necessary because their dynamic range was narrow (most of the features were measured in millivolts and milliseconds).The number of selected features was chosen empirically for a good result with low computational cost.Table 2 and Figure 4 show the results, indicating the percentage of information preserved by the number of features used in the reduction.

Automatic classification
For automatic classification, an artificial neural network (ANN) was used, which is a popular classification technique based on mathematical models that simulate biological neural structures and acquires computational capacity through learning and generalization.
The ANN implemented in this work is basically composed of an input layer whose size is the same as the feature vector, two hidden layers with 25 neurons each, and an output layer with the number of neurons equal to the number of heartbeat classes, which in our work was six.A hyperbolic tangent was chosen as an activation function.For network training, an algorithm called backpropagation was chosen, using 1000 epochs (maximum number of interactions during training) with minimum performance gradient of 10-6 and maximum of 100 validation failures.The configuration of the ANN was defined empirically after preliminary analysis of the database signals.

Performance evaluation
The performance of our algorithm was evaluated using statistical measures, such as sensitivity (Se), specificity (PP), positive predictive value (PPV), negative predictive value (NPV) and accuracy (Ac), which are described by the equations below.

Results
The algorithms implemented were evaluated for heartbeat detection and classification performance on a MIT database.The results were compared with similar studies using the statistical measures mentioned previously.Table 3 presents the QRS detection results, and Table 4 shows the results of the neural classifier implemented for a reduced feature vector size.Each column of the confusion matrix reports the result of the classification obtained by the neural network, while the rows indicate the manual annotation made by the cardiologist.
The results of the neural classifier with and without the reduced feature vector size were compared to other studies that used the same database, as shown in Table 5.It can be observed that the beat classes employed by other studies are not similar, which is indicated by the number of classes.

Discussion
The work has achieved the proposed objective of developing an algorithm to classify heartbeats from digital ECG signals.The number of beat classes was defined according to the availability of databases with a significant number of examples for each class.In the future works, larger databases could be selected, following the methodology proposed in this paper.
The digital ECG signal is preprocessed and prepared for the QRS detection and beat segmentation steps.The detection of the QRS complex reached a sensitivity of 99.18% and a positive predictive value of 98.45%.The segmentation of the ECG signal was carried out using simple techniques based on amplitude  and duration thresholds.From this segmentation and location of each beat, a vector of 106 morphological characteristics was extracted directly from the ECG signal.Because the feature vector is too large to be applied directly to the classifier, it was reduced using the PCA technique.Despite the reduction in the number of features from 106 to 25, the classification performance did not suffer significant decrease.
The results were, in general, very good compared to other published works, reaching an accuracy of 97% and a sensitivity of 95%.It can be observed that the performance is dependent on the beat class because the classification complexity is also dependent on the beat morphology.For example, taking into consideration only premature ventricular beats, our algorithm achieved an accuracy of 98.48%.This high performance was not observed for the premature atrial beats, but the premature ventricular beats are more often associated to a serious heart condition, and for this reason its accurate detection should receive greater priority.Nevertheless, after a close analysis of the classification error in the present system, some limitations were identified, which will be the subject of future work.The most significant mistake is regarding the classification of premature atrial beats (A).In fact, normal and premature atrial beats have similar morphologies, except for a small difference in the RR interval preceding the current beat.Another mistake is related to the classification Beat classes used: normal beat (N), left bundle branch block (L), right bundle branch block (R), paced beat (PB), ventricular premature beat (V) and atrial premature beat (A).Statistical measures: True positives (TP), false negatives (FN), true negatives (TN), false positives (FP), sensibility (Se), specificity (PP), positive predictive value (PPV), negative predictive value (VPN), and accuracy (Ac).
of right bundle branch block beats (R).This beat class is not easy to identify in certain leads.Because the database uses only two leads per record and the lead configuration changes among the records, this may have affected the results.Finally, the reliable determination of the absence of the P wave remains a challenge to be addressed because this information affects the classification of some beat classes.This work is being implemented in the Salus platform, which is a web-based environment of the Espírito Santo Telehealth program (Telessaúde ES, 2014).Consequently, each ECG sent through the platform will be processed, and a report will be generated by the algorithm presented here.The report will be used for triage of the patients, so that cardiologists can prioritize the diagnosis of the critical cases with the least delay.

Figure 1 .
Figure 1.Block diagram of the developed system for heartbeat classification, which included three main stages: preprocessing, feature extraction and classification.

Figure 2 .
Figure 2. (a) The raw ECG signal; (b) The baseline of the ECG; (c) The baseline-corrected ECG signal.

Figure 3 .
Figure 3. Block diagram of the ECG segmentation of each heartbeat estimating the peaks and the limits of each wave.

Figure 4 .
Figure 4.The results obtained by the PCA method presenting the percentage of information preserved as a function of the number of considered features.

Table 1 .
List of the morphological characteristics extracted from the two-channel ECG signal.

Table 2 .
Results obtained by the PCA method presenting the percentage of information that is maintained by a selected number of features.

Table 5 .
Comparison of the classification performance among previous studies.

Table 4 .
Statistical results of the beat classification of the test set.Each column of the confusion matrix reports the result of the classification obtained by the neural network, while the row indicates the manual annotation made by the cardiologist.