Introduction

The electrocardiograph (ECG) is a common method to analyse heart rhythm and its disturbances. While some arrhythmias (such as atrial fibrillation in Fig. 1C,D) may be episodical, a patient can be equipped with a Holter ECG device to record longer periods (from 24 h to several days or weeks). Alternatively, a patient may be equipped with a wearable device to check the rhythm permanently. In both scenarios, the entry point in clinical analysis of Holter ECG data is reliable beat (i.e., QRS complex) detection and classification (Fig. 1) to describe patient rhythm.

Figure 1
figure 1

Examples of Holter ECG signals: Normal sinus rhythm (A); the same patient with the same rhythm, but disturbed by noise due to patient movements (B). A different patient with atrial fibrillation and premature ventricular contractions (PVC) in a couplet (C); the same patient a few minutes later, with disturbed ECG signal (D) with at least one PVC.

QRS detection

Existing beat detection methods are based on morphology analysis as QRS slope, amplitude, and width1, digital filtering2,3,4,5,6, wavelet transform7, machine learning8,9 or deep-learning10,11 approaches. These QRS detection methods performed great on public datasets as an MIT-BIH12. However, the Holter ECG data acquired during daily activities might still be challenging. The data contains a higher amount of noise caused by patient movements (Fig. 1B,D), further affected by the quality of electrode placement since during long-term Holter monitoring, subjects often place electrodes by themselves.

QRS classification

Knowing QRS positions allows for evaluating heart-rate variability, minima, maxima, or the presence of pauses. If more precise ECG analysis is required, the most common beat classes can be recognised (Fig. 2): normal beats, premature atrial contractions (PAC), or premature ventricular contractions (PVC). When these beat classes are known, pathologies formed by specific beat sequences can be analysed. Then, for example, we can automatically identify PVC couplets, triplets, sustained or persistent ventricular tachycardia, or runs of supraventricular tachycardia.

Figure 2
figure 2

Examples of ECG signal with the most common QRS types: normal sinus beats (N), premature atrial contractions (A, PAC), and premature ventricular contractions (B, PVC).

Existing classification approaches may be based on engineered features13,14 or, nowadays, on deep learning techniques15,16, further implementing convolutional17,18 or recurrent layers19,20. Most of them are trained and tested using the public MIT-BIH database (47 patients) or CPSC database (2000 patients), both recorded in resting supine position. These methods are supposed to work using preceding QRS detection. However, deep-learning techniques allow the preparation of models covering QRS detection and classification in one inference step. Thus, we present a robust, deep-learning method to detect and classify QRS complexes in ECG data recorded during usual daily activities. We also introduce a novel approach, delivering detection and classification results in one inference step.

Data

We used private (Fig. 3A) and public (Fig. 3B) ECG datasets in this study. The anonymised, private ECG dataset was collected during routine ECG screening and, therefore, was not subject to the ethical committee by Czech law. This private dataset was used for the method development (Fig. 3C) and testing, and public datasets were used only for cross-database tests (Fig. 3D). The lead "I" was used if the dataset contained multiple leads. If it was not present, the first ECG lead was used.

Figure 3
figure 3

Dataflow in the presented study: private MDT data (A) were split into training, validation, and test subsets. Training and validation subsets were used to develop the proposed method (C). Next, the method performance was measured (D) using MDT private test data and data from twelve public databases (B). For the QRS classification task, only four databases were used.

Private dataset

The private dataset MDT (Medical Data Transfer, s. r. o., Brno, Czechia) consisted of 12,111 single-lead Holter ECG recordings. Each recording was 45 s long, sampled at 200 Hz. Recordings were acquired from patients during usual daily activities and often contained a high amount of noise (Fig. 1B,D). We have developed a software tool, "QRS Marker". Two specialists with more than five years of experience with QRS detection and classification semi-automatically marked 619,681 QRS complexes in this tool. Next, data were split into training (80%), validation (10%), and testing (10%) datasets (Table 1) in an out-of-patient manner.

Table 1 QRS complex counts in the private MDT data for model training, validation and test.

Public datasets

We also used twelve public databases (1,602,960 QRS complexes from 3,050 recordings, sampling frequency from 128 to 1000 Hz) to test QRS detection performance (Table 2). Set of twelve public datasets contained both parts of public data from CinC/PhysioNet Challenge 201421, CPSC-2019 database22, CYBHi database23 using later created annotations11, European ST-T database (EDB)24, St. Petersburg INCART database (available from PhysioNet25), Lobachevski University Database (LUDB)26, MIT-BIH arrhythmia database12, QT database27, MIT-BIH ST change database (STDB)25, MIT-BIH Supraventricular Arrhythmia Database28, and T-wave alternans dataset (TWADB) from CinC/PhysioNet/Challenge 200829. These twelve databases (Table 2) were used for cross-database tests in the QRS detection task.

Table 2 Public data for cross-database tests.

Databases EDB, INCART, MIT-BIH, and SVDB contained QRS classes and were used for cross-database tests of QRS classification performance (Table 2, rows highlighted with *). The proposed method is designed to classify into normal beats, PAC and PVC; therefore, if the QRS complexes were classified in more detail (e.g., a paced beat), the closest possible option was selected (e.g., a normal beat).

Training data augmentation

We randomly inverted each signal with a probability of 0.5 and cropped the signal to random 30 s, modifying the data for each batch. We used weighted oversampling to balance the counts of the QRS types we trained on.

Method

All experiments were performed in accordance with relevant guidelines and regulations. The method is designed to work as in Fig. 4. Raw ECG signal (Fig. 4A) is preprocessed (Fig. 4B), model inference (Fig. 4C) delivers probabilities of QRS classes (Fig. 4D), and post-processing (Fig. 4E) leads to resultant QRS with class information (Fig. 4F).

Figure 4
figure 4

A workflow to detect and classify QRS with the proposed method. The ECG signal (A) is preprocessed (B) and imputted to the inference engine with the deep-learning model (C). The output of the model (D) consists of four probability vectors at the length of the input ECG signal. Output vectors are post-processed (E), and QRS annotation marks and classes are reported (F). N refers to normal sinus beat; PVC refers to premature ventricular contraction with one example of correctly detected but incorrectly classified QRS (the left-most PVC).

Preprocessing

Before feeding the training signals into the model, we resampled the signal to 100 Hz and standardised the signal independently to have zero mean and unit variance (Fig. 5A). Target data (y) for the model were prepared as follows: each QRS location was widened to 10 samples to create a four-channel segmentation mask (as in Fig. 4D).

Figure 5
figure 5

Architecture of the presented neural network. Standardized input ECG (A) enters the first Residual Block (RB). Five of RBs are chained together (B). RB is described in further detail in (C). Then the signal enters Gated Recurrent Unit (GRU, D) layer, Fully connected layer (FC, F) and transposition (F). B × C × L refers to batch size x channel count x signal length.

Model architecture and training

The developed model consists of five residual blocks (Fig. 5B,C), a gated recurrent layer (Fig. 5D), and a fully connected layer (Fig. 5E). The model outputs a four-channel tensor (Fig. 5F). Each residual block consists of several convolutional layers. We used a batch size of 64, a cross-entropy loss function, an AdamW optimiser with a learning rate of 0.001, clipped the gradient L2 norm to 1.0, no weight decay.

Post-processing

The network outputs the likelihood (Fig. 4F) of the four different QRS classes (no QRS, normal QRS, atrial QRS, ventricular QRS) for every input sample. We take the class with the maximum likelihood for every sample and post-process the resulting segmentation mask to get a list of the QRS peaks. First, we calculate the centers of the segmentation mask and save them into a list of potential peaks. Then, we remove lower peaks that are too close (< 0.15 s) to stronger peaks, as such a low distance between beats is physiologically improbable.

Compared QRS detectors and used metrics

For comparison, we also evaluated used datasets by several publicly available QRS detection methods: by Elgendi2, Malik et al.3, XQRS detector from Python WFDB package30, and by Pan and Tompkins1. We also evaluated three-detectors from the python NeuroKit package—modified Engelse & Zeelenberg6, Hamilton detector4, and Kalidash detector7. Results for these detectors might differ from the performance reported by respective papers since we used all available data from all datasets; we implemented detectors by Elgendi2 and Malik3 using respective papers.

We used the F1 score to compare and evaluate results. A detected QRS complex was considered true positive when its annotation mark was closer than 0.1 s (inclusive) to an annotation mark prepared by an expert. The false positive or false negative cases were considered when a beat was missing in expert annotations or detected QRS complexes.

Results

The model was built using the PyTorch framework31 and trained in 70 epochs using the private MDT dataset. We separately evaluated QRS detection performance and QRS classification performance; we also evaluated computational method performance.

QRS detection performance

We received training, validation, and testing F1 scores of 0.991, 0.990, and 0.992 for the detection task using the MDT test set. We also provided a cross-database test to evaluate detection performance on twelve public datasets, showing a mean F1 score of 0.96 ± 0.06. The detection performance was compared to other methods using all twelve test datasets. We received a maximal mean F1 score of 0.961 using the proposed method, followed by the Malik method3 (0.955) and XQRS detector from the WFDB30 Python package. We also observed how the used databases were difficult for tested detectors. Overall F1 results by all detectors per database showed that the easiest database to detect was the STDB25 (0.979), the first part of PhysioNet/CinC challenge 201421 (0.972) and the MITDB (0.958). On the other hand, the most challenging database for tested detectors was the second part of PhysioNet/CinC challenge 2014 (0.759), the SVDB (0.805), and the MDT test set (0.809).

QRS classification performance

We evaluated the proposed method to classify QRS complexes into three groups—normal beat, premature ventricular contraction, and premature atrial contraction (Table 4—the last row). We reached an overall classification F1 performance of 0.96 and 0.74 for micro and macro computation in the MDT test set, respectively. Cross-database tests for QRS classification (Table 4, the first four rows) showed average micro and macro F1 scores of 0.95 ± 0.03 and 0.73 ± 0.06, respectively.

Method computational performance

We measured the processing time of all compared methods using all testing datasets (excluding the CYBHi) to evaluate computational performance. The average processing time per record is shown in Fig. 7. The comparison was obtained using a computer with Intel® Xeon® Gold 6248R CPU running at 3.00 GHz. Data were supplied to algorithms one by one, and we disabled GPU, which disadvantaged the proposed method (Fig. 7).

Discussion

The presented method showed the highest overall QRS detection F1 score in compared methods (Table 3) when using all test datasets. We were generally focused on Holter ECG data acquired during usual daily activities, and we received the best score of tested methods in the MDT dataset. The highest overall score might reflect that we used a high amount of disrupted ECG data for training. Table 3 (the row "MDT") demonstrates how different methods can detect QRS in noisy data. Figure 6 shows examples of non-trivial Holter ECG and results of presented and compared detection methods. Figure 6A demonstrates that four methods overlooked PVCs with abnormally low amplitude; Fig. 6B shows how methods react to signal disturbance and how most of them capture noise instead of QRS if they are very close (19th second). Finally, Fig. 6-C demonstrates how non-usual PVC couplets and noise may confuse detectors.

Table 3 Resultant F1 scores for QRS detection using various detection methods and testing datasets.
Figure 6
figure 6

Non-trivial Holter ECG examples (parts of 30-s blocks) with QRS detection results by several methods. (A) Normal sinus rhythm with multifocal premature ventricular beats; (B) normal sinus rhythm, heavily disturbed; (C) normal sinus rhythm, disturbed, with premature ventricular beats. Bold black rectangles refer to regular QRS, filled triangles refer to premature ventricular contraction (PVC). Bold vertical at approx. second 1.3 refers to a questionable PVC combined with an artifact. Shown signals were not used for development nor testing of the presented method.

We also compared the presented method to the deep-learning method11 trained on the CYBHi dataset23 and tested on MIT-BIH12 dataset with an F1 score of 0.96. Our method slightly outperforms the compared method on MIT-BIH, but on the other hand, we used a significantly more complex network structure.

The important benefit of the presented method is that it classifies QRS complexes into three groups. Our results show that the weakest point of QRS classification is in the PAC class (Table 4). Further investigation revealed that in most cases, false PACs are generated inside blocks of atrial fibrillation where the presented method tends to report PACs. We also found incorrect classifications in long SVT runs (series of PACs running on high heart rate).

Table 4 Resultant test F1 scores for QRS classification.

A limitation in comparison to most other methods is processing time, as shown in Fig. 7. However, this can be overpassed when the model uses a GPU during inference. In such a case, inference time can be decreased approximately 10–30 times depending on the specific hardware and batch size.

Figure 7
figure 7

Comparison of average processing time per record (30-s long) in all test datasets (excluding the CYBHi dataset).

Conclusion

We presented a novel deep learning method for QRS detection and classification in one inference step. The method was evaluated on twelve public datasets not used for model development. This cross-database test showed higher overall QRS detection performance than other compared methods. Furthermore, we showed how compared QRS detectors behave in non-trivial situations common in Holter ECG. We also demonstrated that both QRS classification and detection could be combined into one deep-learning model. Therefore, the usual processing chain to analyse heart rhythm can be simplified.