Abstract
Aims
Accurate electrocardiogram (ECG) waveform delineation, rhythm classification, and median beat generation are interdependent steps whose joint modelling improves consistency for downstream computerized diagnostic tasks. This study aimed to develop a lead-agnostic segmentation model that performs these tasks by segmenting individual leads and aggregating predictions in post-processing.
Methods and results
A DeepLabV3-based neural network was trained to segment ECG leads into 20 waveform and rhythm classes using 1931 annotated ECGs and 33 093 ECGs with physician-verified diagnostic statements. Post-processing combined lead-wise predictions to delineate intervals, classify rhythm, and construct median beats. Performance was evaluated on internal (n = 988) and external (n = 1303) test sets. Median beats were compared with PTB-XL+ reference medians from Marquette 12SL and University of Glasgow (Uni-G) using similarity metrics and downstream classification. An interactive web tool (http://segmentation.ecgx.ai) was released to support further research. In the external set, delineation for PQ interval, QRS duration, and QT interval had mean errors of −0.9 ± 10.4 ms, 0.2 ± 7.4 ms, and 1.8 ± 16.0 ms. Rhythm classification was performed by assigning class labels to segmented waveform components, with weighted F1 scores of 0.94 for P waves and 0.89 for QRS complexes. Qualitative review showed good alignment with reference beats and differences in beat selection, adjacent beat handling, and QRS identification. Downstream classification performance was equivalent to Marquette 12SL medians but statistically superior to Uni-G medians for 7/10 diagnostic labels.
Conclusion
This study demonstrates a robust, clinically applicable, vendor- and lead-agnostic deep learning model for ECG analysis, encompassing waveform delineation, rhythm classification, and median beat construction.
Keywords: Semantic segmentation, Median beat ECG, Electrocardiogram, Computer vision, Deep learning, Explainable AI
Graphical Abstract
Graphical Abstract.

Introduction
The 12-lead electrocardiogram (ECG) is a cornerstone of cardiovascular diagnostics, supporting the detection of arrhythmias, conduction abnormalities, ischaemia, and structural heart disease. Manual interpretation remains the standard in clinical practice but is time-consuming, costly, and prone to inter-observer variability.1–3 Computerized interpretation is widely used to support clinicians, yet existing systems often struggle with noisy or heterogeneous recordings and show inconsistent performance across clinical settings.4 These limitations highlight the need for automated methods that are robust to patient variability, recording formats, and signal quality.
Accurate computerized interpretation depends on three interrelated tasks: waveform delineation, rhythm classification, and generation of a representative median beat, providing a foundation for downstream interpretation.4 Traditionally, these tasks have been addressed by separate rule-based models or processing steps, which can introduce inconsistencies across the pipeline. For example, waveform delineation without rhythm classification may yield inaccurate interval measurements, as ectopic beats should be excluded. Likewise, generating a median beat without considering rhythm can produce non-representative templates. These dependencies underscore the importance of unified approaches that preserve internal consistency across tasks.
Deep learning models have markedly improved advanced delineation and classification accuracy by capturing both spatial and temporal dependencies.5,6 Encoder–decoder architectures, such as U-Net and DeepLabV3, have become dominant for segmentation tasks, and multitask frameworks have emerged that attempt to unify delineation and classification.1,7,8 However, most existing models are limited to narrow rhythm classes, lead subsets, or broad timing tolerances.1,5–7,9–13 Many are trained and validated on complete 12-lead recordings and rely on inter-lead contextual features, which restricts their applicability to settings with reduced lead configurations. Moreover, public datasets used for training and evaluation, such as LUDB and QTDB, often contain predominantly normal ECGs and annotations of mixed quality, limiting their value for generalizable learning and external validation.1,14,15
To address these limitations, we developed a unified, lead-agnostic segmentation model that jointly performs waveform delineation and rhythm classification, from which median beats are subsequently derived. This design enables consistent performance across a broad range of ECG formats, including single-lead wearables, Holter monitors, and standard 12-lead recordings, without requiring retraining. By basing both interval measurements and median beat generation exclusively on beats from the primary rhythm, the model ensures internal consistency across tasks and enhances clinical reliability. The model was trained on manually annotated ECGs and evaluated using curated subsets from eight geographically and technically diverse public datasets. We also compared the generated median beats with reference medians produced by commercial algorithms. By integrating complementary tasks within a single framework and releasing derived median beats from multiple public datasets, this study provides a reproducible and clinically applicable tool for automated ECG interpretation.
Methods
Data sources
We used three internal datasets of 12-lead ECGs acquired at the University Medical Center Utrecht (UMCU). The primary dataset consisted of ECGs that were manually annotated for waveform delineation and rhythm classification. These recordings were selected using stratified random sampling to ensure coverage of underrepresented waveform and rhythm classes. To further increase rhythm label diversity, a second internal dataset was included, consisting of ECGs with ECG-wide rhythm labels but without timepoint-level annotations. This dataset was also sampled stratified randomly (see Supplementary material online, Table S1). Diagnostic labels were extracted using a previously validated text-mining algorithm from physician-verified diagnostic statements exported from MUSE (GE Healthcare).16 Both datasets were split into training (80%) and validation (20%) sets with patient-level separation.
A third internal dataset, consisting of randomly sampled and manually annotated ECGs, was used as an independent internal test set to assess generalizability. This dataset had a representative distribution of abnormalities and included distinct patients not present in the training or validation sets.
To evaluate external generalizability, we constructed an external test set using stratified, random sampling from eight publicly available ECG datasets spanning four continents (see Supplementary material online, Table S2 and Figure S1). These datasets vary in recording quality, sampling rate, and diagnostic class prevalence and include conditions not represented in our internal validation set, such as ST-elevation myocardial infarction, T wave abnormalities, benign early repolarization, and Brugada pattern. All external ECGs were manually annotated using the same procedures as for the primary dataset.
All ECG data from the UMCU were deidentified following the European Union General Data Protection Regulation, and ethical approval by the accredited Dutch medical ethics committee was not needed since the study design fell outside the scope of the Dutch Medical Research Involving Human Subjects Act (WMO). Due to the retrospective nature of the study and large patient cohort, informed consent was not required.
Preprocessing
Electrocardiogram waveforms and diagnostic statements were extracted from MUSE at the UMCU or retrieved from publicly available online repositories (see Supplementary material online, Table S2). Eight leads (I, II, V1–V6) were used, as the remaining leads are mathematically derived and provide no unique information. All waveforms underwent uniform preprocessing, including bandpass filtering with a third-order Butterworth filter with cut-off frequencies of 0.05 and 150 Hz and powerline filtering using 50 and 60 Hz narrowband zero-phase notch filters. Signals were resampled to 500 Hz when necessary, using polyphase resampling. Because our model operates on individual leads, each lead was treated as a separate input throughout preprocessing and model training.
Manual annotation process
Electrocardiograms were manually annotated in a digital format by physicians with extensive experience in ECG interpretation. For each beat, the earliest onset and latest offset of the P wave, QRS complex, and T wave were labelled across all leads at once. Segments with excessive noise or baseline wander were explicitly marked, along with an overall assessment of recording quality. Each waveform segment (P, QRS, or T) was classified to 1 of 19 diagnostic rhythm classes derived from PhysioNet codes (Table 1). Samples not corresponding to any beat or noise segment were labelled as baseline. All annotations were reviewed by a second physician for consistency, and disagreements were resolved through consensus with an electrophysiologist.
Table 1.
Diagnostic labels for each timepoint
| P | QRS | Other |
|---|---|---|
| Sinus rhythm | Sinus rhythm | T wave |
| Premature atrial complex | Atrial fibrillation | Noise |
| Atrial rhythm | Atrial flutter | Baseline |
| No atrioventricular conduction | Atrial rhythm | |
| Atrial pacing | Atrial pacing | |
| Premature atrial complex | ||
| Premature ventricular complex | ||
| Supraventricular tachycardia | ||
| Nodal rhythm | ||
| Ventricular rhythm | ||
| Ventricular tachycardia | ||
| Ventricular pacing |
Model architecture and post-processing
A one-dimensional semantic segmentation model was implemented based on a modified DeepLabV3 architecture adapted for time series input.17 DeepLabV3 was selected for its proven performance in boundary-sensitive segmentation tasks and its ability to preserve fine temporal detail through atrous spatial pyramid pooling.18 The network used a residual convolutional backbone with repeated double-convolutional blocks and skip connections to extract multi-scale temporal features. Batch normalization, dropout, and rectified linear unit activations were used throughout to improve generalization and training stability. Model training was monitored using the validation loss, and early stopping was applied. The model outputs per-sample class probabilities for waveform types and rhythms via a softmax layer and was optimized using cross-entropy loss. Detailed model parameters are provided in the Supplementary Methods.
To maximize applicability across ECG acquisition formats, the model was trained on a per-lead basis. This design aligns with the one-dimensional convolutional architecture and avoids reliance on inter-lead context, which is absent in single-lead recordings. As a result, the model can operate without modification on 12-lead ECGs, Holter monitors, and single-lead wearable devices.
During inference, outputs from the multiple leads are combined for full ECG analysis. For delineation, the modal class per timepoint across leads was used, excluding segments labelled as noise. Post-processing steps included merging short segments (<20 ms) and correcting biologically implausible class transitions. For rhythm classification, beat-level predictions were aggregated using majority voting across leads, yielding a primary rhythm while excluding ectopic beats. Median beats were constructed by extracting beats of this primary rhythm, aligning beats within each lead at QRS onset, and applying median filtering. Signals were zero padded before P onset and after T offset to obtain a uniform length of 1.2 s (Figure 1).
Figure 1.

Overview of lead-wise segmentation, rhythm classification, and median beat generation. (A) Each electrocardiogram lead is segmented independently by the model into waveform and rhythm classes. Segmentations are aggregated across leads and refined through post-processing, including removal of noise segments and biologically implausible transitions. (B) The primary rhythm is determined based on consensus across leads and time, enabling calculation of conduction intervals from beats belonging to this dominant rhythm. These beats are used to construct the median beat after alignment and filtering. (C) Lead I example from three 12-lead electrocardiograms with colour overlays and beat labels. The median beat derived from the same trace is displayed on the right. Examples include sinus rhythm (Ps and N), premature ventricular complex (V), premature atrial complex (A), atrial flutter (AFl), and ventricular tachycardia (VT).
Model training
Model training was performed in three sequential phases. In the initial phase, the model was trained using the manually annotated primary internal dataset, treating each of the eight leads as an independent input. Training loss was calculated through a cross-entropy loss between the predicted per-sample class probabilities and the corresponding manual annotations. Lead-wise training was chosen to allow subsequent use in both 12-lead and single-lead ECGs, such as Holter recordings.
In the second phase, all model parameters were further trained using the secondary internal dataset, which included only ECG-wide rhythm labels without waveform annotations. The model from phase one was used to generate preliminary segmentations, which are further cleaned during post-processing, and the primary rhythm is subsequently compared with the ECG-wide rhythm label. Disagreements were corrected before fine-tuning the model on the adjusted labels.
In the final phase, all model parameters from the second stage were fine-tuned on the manually annotated dataset again. As in the first phase, each lead was used separately during training. This final step served to refine waveform boundary delineation and enhance rhythm classification performance.
Statistical analysis
Waveform delineation performance was evaluated by comparing model-derived and annotated onsets and offsets of the P wave, QRS complex, and T wave. Conduction intervals (PR interval, QRS duration, and QT interval) were derived from these timepoints. For each interval and timepoint, delineation performance was assessed using the mean error, mean absolute error (MAE), root mean square error (RMSE), and proportion of beats with <10 and <20 ms error.
To evaluate agreement beyond central tendency, we calculated the intersection over union (IoU) for each interval and wave. This metric reflects the proportion of overlapping timepoints between model-derived and annotated intervals relative to their union. Bland–Altman and Q–Q plots were generated to visualize agreement and identify any systematic bias in waveform boundaries across the test datasets. Subgroup analysis was performed across datasets and beat types.
Rhythm classification performance was assessed separately for the primary P-wave and QRS complex rhythm labels. The primary rhythm was defined as the most prevalent rhythm label assigned to each waveform type (P or QRS), excluding ectopic beats. This approach ensures that interval measurements and median beat construction reflect clinically relevant rhythm patterns and are not biased by transient or ectopic beats. Predicted primary labels were compared with the corresponding manually annotated labels. Subgroup analysis was performed to examine the effects of overlapping P and T waves, the proportion of beats matching the primary rhythm, and the recording quality.
In addition to primary rhythm evaluation, beat-level analysis was performed by first matching predicted and annotated beats using an overlap rule. Specifically, a predicted segment was matched to a manually annotated segment if they overlapped by at least one sample. A true positive was counted when the matched pair had the same class label. False positives were predicted segments with no overlap with any annotated class, and false negatives were annotated segments with no matching prediction. Predictions were grouped into P, QRS, and T waveform categories to assess category-level discrimination, followed by per-class evaluation within each group. Precision, recall, and F1 scores were computed and averaged across classes and external test datasets.
Performance metrics for delineation and rhythm classification were primarily reported on the external test set, restricted to annotations with onsets after 0.5 s and offsets before 9.5 s to exclude incomplete beats.
Median beats generated by our model were compared with publicly available Marquette 12SL (MUSE, GE Healthcare) and University of Glasgow (Uni-G) reference median beats from PTB-XL+.19 Only median beats containing all 12 leads were used for the analysis. Morphological similarity was assessed per lead using normalized mean derivative dynamic time warping (DDTW) distance and normalized cross-correlation (NCC).20 To avoid contamination from adjacent beats, similarity analyses were restricted to the predicted P onset and T offset. Electrocardiograms in the top 2.5% of DDTW distance and bottom 2.5% of correlation were reviewed qualitatively to verify clinical plausibility and identify segmentation errors.
To assess downstream utility, we trained lightweight convolutional neural networks (CNNs) to classify the 10 most frequent morphological ECG labels from median beats. Separate models were trained for each label and for each median beat source (UMCU, Marquette 12SL, and Uni-G) using five-fold stratified cross-validation. All models were trained on the same set of 20 160 PTB-XL+ ECGs, all recorded on Schiller AG devices, differing only in the source of the median beats (see Supplementary Methods). The mean ± standard deviation (SD) area under the receiver operating characteristic curve (AUROC) per method was reported. Differences in AUROC were tested using paired t-tests with Bonferroni correction across folds, treating folds as repeated measures.
All model training and statistical analyses were performed using Python 3.10 using PyTorch and PyTorch Lightning on an NVIDIA RTX A6000 GPU with 48 GB VRAM.
Results
Data characteristics
The model development cohort included 1931 manually annotated ECGs and 33 093 ECGs with ECG-level rhythm labels. The internal held-out test set consisted of 988 ECGs, while the external test set contained 1303 ECGs from eight publicly available, geographically diverse datasets. Across all datasets, approximately one-third to one-half of participants were female (Table 2). The median age ranged from 59 [interquartile range (IQR): 33–72] years in the external test set to 69 (IQR: 59–77) years in the manually annotated development cohort, reflecting a broad age distribution.
Table 2.
Baseline characteristics per data split
| Development—manually annotated | Development—ECG-wide labels | Test internal | Test external | |
|---|---|---|---|---|
| Demographics, n (%) | ||||
| n | 1931 | 33 093 | 988 | 1303 |
| Female | 622 (32.2) | 13 075 (39.5) | 441 (44.6) | 435 (33.4)a |
| Age, median [IQR] | 69 [59–77] | 68 [57–76] | 63 [53–73] | 59 [34–72]b |
| ECG primary rhythm, n ECGs (%) | ||||
| Sinus rhythm | 660 (34.2) | 10 392 (31.4) | 843 (85.3) | 848 (65.1) |
| Atrial pacing | 34 (1.8) | 0 (0.0) | 6 (0.6) | 10 (0.8) |
| Atrial fibrillation | 334 (17.3) | 10 004 (30.2) | 94 (9.5) | 162 (12.4) |
| Atrial flutter | 227 (11.8) | 4000 (12.1) | 5 (0.5) | 53 (4.1) |
| Atrial rhythm | 119 (6.2) | 4002 (12.1) | 5 (0.5) | 26 (2.0) |
| SVT | 106 (5.5) | 2499 (7.6) | 10 (1.0) | 87 (6.7) |
| Nodal rhythm | 98 (5.1) | 1021 (3.1) | 3 (0.3) | 23 (1.8) |
| Ventricular rhythm | 52 (2.7) | 240 (0.7) | 1 (0.1) | 16 (1.2) |
| Ventricular tachycardia | 88 (4.6) | 935 (2.8) | 2 (0.2) | 32 (2.5) |
| Ventricular pacing | 213 (11.0) | 0 (0.0) | 19 (1.9) | 46 (3.5) |
a271 missing.
b1271 missing.
Abbreviations: AV, atrioventricular; IQR, interquartile range; PAC, premature atrial complex; PVC, premature ventricular complex; SVT, supraventricular tachycardia.
Sinus rhythm was the most frequent primary rhythm in all splits, although the proportion ranged from 31.2% in the ECG-wide label set to 85.3% in the internal test set. Atrial fibrillation was the second most common rhythm, representing 17.3% of the manually annotated development set and 30.2% of the ECG-wide label set, but was less frequent in the test sets (9.5–12.4%). Other rhythms, such as atrial flutter, supraventricular tachycardia, and ventricular pacing, occurred in smaller but consistent proportions (typically 2–12%, depending on the dataset).
Waveform delineation performance
Agreement between model-derived and reference measurements was assessed in the external test set using Bland–Altman plots, scatter plots, and summary error metrics (Figure 2; Table 3). Across conduction intervals, Bland–Altman analysis showed minimal mean bias (range: −0.9–1.8 ms). PR interval predictions showed excellent agreement with reference values, with minimal bias and narrow limits of agreement (LoA) (mean, −0.9 ms; LoA, −21.3–19.5 ms). QRS duration also demonstrated strong agreement, although slight underestimation was observed at longer durations (mean, 0.2 ms; LoA, −14.3–14.7 ms). QT interval predictions were somewhat more variable, especially at higher values (mean, 1.8 ms; LoA, −29.7–33.2 ms). Scatter plots confirmed strong linear correlations for all intervals, with the best performance observed in PR and QRS durations.
Figure 2.

Agreement between manual and model-derived electrocardiogram intervals. Left panels (A, C, and E) show Bland–Altman plots with bias (solid line) and 95% limits of agreement (grey band). Right panels (B, D, and F) show model-derived vs. manual intervals with 1:1 reference line (dashed). Insets indicate Pearson correlation coefficient (r), mean absolute error, bias, and limits of agreement. All intervals in milliseconds. Abbreviations: MAE, mean absolute error; ms, milliseconds.
Table 3.
Performance of the delineation model for waveform boundary detection and conduction interval measurement
| Mean error (SD), ms | MAE, ms | RMSE | <10ms error, % | <20ms error, % | IoU | |
|---|---|---|---|---|---|---|
| P onset | 0.5 (10.1) | 6.0 | 10.1 | 81.7 | 93.7 | 0.893 |
| P offset | 0.2 (9.1) | 5.3 | 9.1 | 84.5 | 94.9 | 0.893 |
| QRS onset | −0.3 (5.1) | 3.0 | 5.1 | 94.0 | 98.6 | 0.943 |
| QRS offset | 0.0 (6.6) | 3.5 | 6.6 | 91.8 | 97.5 | 0.935 |
| T onset | 0.0 (6.6) | 3.5 | 6.6 | 91.8 | 97.5 | 0.955 |
| T offset | 1.6 (15.3) | 8.3 | 15.4 | 74.5 | 90.8 | 0.955 |
| PQ interval | −0.9 (10.4) | 6.2 | 10.5 | 80.9 | 93.1 | 0.949 |
| QRS duration | 0.2 (7.4) | 4.7 | 7.4 | 87.3 | 97.1 | 0.943 |
| QT interval | 1.8 (16.0) | 9.1 | 16.1 | 69.5 | 89.0 | 0.970 |
Abbreviations: IoU, intersection over union; MAE, mean absolute error; ms, milliseconds; RMSE, root mean square error; SD, standard deviation.
The proportion of predictions within 20 ms of the reference ranged from 89.0% for QT interval to 97.1% for QRS duration (Table 3). For waveform onset and offset predictions, this proportion ranged from 90.8% for T wave offset to 97.5% for QRS wave offset and T wave onset. Per-class delineation metrics are provided in Supplementary material online, Tables S3 and S4, indicating reduced performance in non-sinus P waves and ventricular tachycardia and ventricular pacing QRS complexes. Delineation performance was stable across datasets, including the internal test set (see Supplementary material online, Figure S2).
Rhythm classification performance
Rhythm classification results are summarized in Figure 3. Evaluation focused on the dominant rhythm for the P wave and QRS complex, excluding ectopic beats. The weighted F1 score for P waves was 0.94. Performance varied in the P-wave subclasses: sinus P waves showed the highest F1 score (0.96), followed by P waves without atrioventricular (AV) conduction (0.83), atrial pacing (0.69), and atrial rhythm (0.49).
Figure 3.

Classification performance for primary P-wave types (A) and primary QRS-wave types (B), showing precision, recall, and F1 score. Abbreviations: AP, atrial pacing; AR, atrial rhythm; PnAV, P without AV conduction; SR, sinus rhythm; AF, atrial fibrillation; AFl, atrial flutter; NR, nodal rhythm; SVT, supraventricular tachycardia; VP, ventricular pacing; VR, ventricular rhythm; VT, ventricular tachycardia.
The model achieved an overall primary QRS F1 score of 0.89 across all ECGs. Among the subclasses, primary rhythm classification performance was highest for ventricular pacing (0.97) and sinus rhythm (0.95). Strong performance was also observed for supraventricular tachycardia (0.87), atrial fibrillation (0.83), and ventricular tachycardia (0.90). Lower F1 scores were seen for less common primary rhythms, such as atrial rhythm (0.46) and nodal rhythm (0.45). A lower proportion of beats that match the primary rhythm type was associated with a lower weighted F1 score in both P and QRS waves (see Supplementary material online, Table S5).
Beat-level classification results are shown in Supplementary material online, Figure S3. For P waves, a high precision of 0.99 with a lower recall of 0.91 indicates that P waves are rarely mislabelled but occasionally missed. Recall dropped substantially when P waves occurred within 10 ms of the preceding T wave (0.21 vs. 0.93; Supplementary material online, Table S6), while precision remained high. Highest beat-level F1 scores were observed for common rhythms, including sinus rhythm (P wave 0.98, QRS complex 0.95), atrial fibrillation (QRS complex 0.83), and ventricular pacing (QRS complex 0.96), while performance was lower for rarer or morphologically ambiguous rhythms, such as nodal rhythm (QRS complex 0.44) and atrial rhythm (P wave 0.60, QRS wave 0.50). Among ectopic beats, premature atrial complexes (PACs) achieved an F1 score of 0.72 (P) and 0.67 (QRS), while premature ventricular complexes (PVCs) reached 0.86 (QRS), with most misclassifications occurring as atrial fibrillation. Performance remained stable for common rhythms across ECGs with adequate and partially interpretable recording quality, as well as across individual datasets. In contrast, classification was more variable for rare or morphologically ambiguous rhythms (see Supplementary material online, Table S7 and Figures S4 and S5). Confusion matrices illustrating class-level performance are provided in Supplementary material online, Figures S6 and S7.
Median beat construction
Baseline characteristics of the PTB-XL+ subset are provided in Supplementary material online, Table S8. Median beats were successfully generated for 20 160 PTB-XL+ ECGs (92.3%; Supplementary material online, Figure S8) by all three algorithms. Marquette 12SL median beats with IDs above 20 956 were not available, resulting in 863 (4.0%) cases where only our method and Uni-G produced results. Conversely, our model excluded 720 (3.3%) ECGs due to excessive noise, in contrast to the commercial systems, which do not apply an explicit signal quality check. Examples of both poor alignment due to noise and strong agreement between methods in clean recordings are shown in Supplementary material online, Figure S9.
Qualitative comparison
Among ECGs with medians available from all three methods, our approach demonstrated high morphological similarity to both Marquette 12SL and Uni-G. NCC values were near perfect (median: 0.999), and DDTW distances were low and comparable across methods, indicating strong waveform alignment and minimal morphological deviation.
Qualitative review of outliers revealed several main sources of discrepancy. One frequent source was differences in primary beat selection rules in ECGs with multiple morphologies. University of Glasgow often selected non-paced over paced beats in paced recordings (Figure 4A), or the non-paced beat was a PVC. Marquette 12SL also selected non-paced beats in some cases, but applied a higher selection threshold.
Figure 4.

Comparison of median beat generation across three algorithms. Twelve-lead electrocardiograms with corresponding median beats generated by Marquette 12SL (black), University of Glasgow (blue), and University Medical Center Utrecht (orange) in leads II and V1. (A) The algorithms selected different dominant morphologies for median beat construction in the presence of paced and non-paced beats. (B) Differences are observed in the signal retained outside the principal beat complex. (C) The available median waveform segment differs between algorithms in the presence of a premature ventricular complex. (D) Differences in handling pacing spikes result in differing estimates of waveform onset and median beat morphology.
Another discrepancy arose from how noise and adjacent beats were handled. University of Glasgow included all beats within the 1.2-s window without filtering, resulting in differences in the signal outside the principal beat complex in recordings with atrial fibrillation or frequent PVCs (Figure 4B). Moreover, the median waveform segment differs between vendors in the presence of adjacent PVCs (Figure 4C).
A third discrepancy involved pacing spikes. Differences in handling pacing spikes resulted in differing estimates of waveform onset and median beat morphology (Figure 4D).
Downstream classification performance
Median beats from each method were used to train a lightweight CNN for classifying the 10 most common morphological ECG labels. All models performed well, with mean AUROCs ranging from 0.83 to 0.97 (Figure 5). Models trained on medians from our algorithm and Marquette 12SL outperformed those trained on Uni-G signals for 6 of the 10 labels (Bonferroni-corrected P < 0.05), with no significant differences between our algorithm and Marquette 12SL across all labels. Our algorithm outperformed Uni-G for 7 of the 10 labels (Bonferroni-corrected P < 0.05). For inferior myocardial infarction and incomplete right bundle branch block, performance was similar across methods (P > 0.05). Similar results were observed when using F1 score, which better accounts for class imbalance, as an alternative evaluation metric (see Supplementary material online, Figure S10).
Figure 5.

Performance of convolutional neural networks trained on three different median beat electrocardiograms from the PTB-XL database across 10 outcome labels. Bars show mean area under the receiver operating characteristic curve across five cross-validation folds; error bars represent 1 SD. *P < 0.05; **P < 0.01. Abbreviations: ABQRS, abnormal QRS; ASMI, anteroseptal myocardial infarction; IMI, inferior myocardial infarction; IRBBB, incomplete right bundle branch block; ISC_, non-specific ischaemic; LAFB, left anterior fascicular block; LVH, left ventricular hypertrophy; NDT, non-diagnostic T-abnormalities; NORM, normal electrocardiogram; STD_, non-specific ST-depression.
Discussion
In this study, we developed and validated an explainable multi-task deep learning model that performs three central components of electrocardiographic analysis: waveform delineation, rhythm classification, and median beat construction. Producing these outputs within a single model reflects their physiologic interdependence and improves internal consistency across tasks. Compared with existing approaches, this model offers three advantages: it is vendor and lead agnostic, supporting single-lead, wearable, and Holter recordings that proprietary 12-lead systems cannot process; its predictions are explainable and inspectable at the waveform level through an openly available web tool, supporting external verification; and it matches the downstream classification performance of a widely used commercial reference system. Whether this translates into improved diagnostic consistency, efficiency, or trust remains to be studied. The model achieved delineation errors well within clinically accepted tolerances, with mean absolute errors of only a few milliseconds across P, QRS, and T wave boundaries. The high F1 score for primary P and QRS rhythms, together with high beat-level F1 scores for common rhythm classes, indicates that the model can reliably capture the dominant rhythm in most ECGs, whereas performance was lower in rare or morphologically ambiguous rhythm classes, which could lead to clinical misclassification if outputs are used without safeguards. For deployment, such cases should be handled with protective mechanisms, such as confidence-based flagging. The algorithm produced median beats with high morphological fidelity compared with medians generated by the Marquette 12SL and Uni-G algorithms, achieving similar or greater downstream utility in ECG classification. Together, these findings demonstrate that a unified model can provide reliable ECG interpretation across multiple core tasks and may streamline diagnostic workflows while supporting downstream artificial intelligence (AI) applications.
Accurate computerized ECG waveform delineation has been the subject of extensive research, as it underpins interval measurement and rhythm interpretation.1,5–7,9–13 Most prior studies have reported performance on LUDB, QTDB, or both, datasets that primarily contain normal rhythms and exhibit manual annotation inconsistencies.1 To ensure generalizability, we assessed performance across a broader set of rhythms and demonstrated delineation accuracy comparable to expert manual measurements. The mean absolute errors of a few milliseconds align with interobserver variability reported for manual QT and QRS measurements (SD, 12–13 ms; LoA, 30 ms), supporting that our delineations are clinically interchangeable with expert annotation.21–23 Our results show that the model reliably identifies P, QRS, and T waveforms as groups and retains strong performance at a more granular level, with high beat-wise F1 scores. Evaluating both primary rhythm labels and detailed beat-level subclasses demonstrates that the network captures rhythm information consistently across scales. An additional advantage of our model is the ability to detect multiple P waves between QRS complexes, which is relevant for higher-degree AV blocks and is unavailable in many previous algorithms.9
Most prior deep learning work on ECG classification has focused on arrhythmia detection as a stand-alone task. Landmark studies, such as those of Hannun et al. and van de Leur et al., trained convolutional neural networks (CNNs) on the entire 10-s ECGs to classify multiple rhythm and structural abnormalities directly from the full recording.16,24 Although these models achieved expert-level diagnostic accuracy, they operate on whole signals and did not explicitly identify the beats or waveform segments contributing to each prediction. Similarly, the PhysioNet Challenges have advanced multi-rhythm classification, yet most approaches rely on global signal embeddings or beat-level labels without explicit delineation.25 In contrast, our model learns rhythm classification jointly with waveform delineation, allowing it to use physiologic dependencies, such as the absence of P waves as a marker of atrial fibrillation. Evaluation across eight external datasets from multiple continents further supports the model’s generalizability, addressing a key limitation of prior single-centre work.
Median beats are widely used in hospital ECG management systems as the primary representation for clinician review and automated interpretation. Despite their ubiquity, few studies have explicitly addressed their generation and evaluation. In the release of PTB-XL+ that included median beats, no technical validation was performed.19 Commercial proprietary algorithms, such as Marquette 12SL and Uni-G, construct medians by averaging across beats without explicit knowledge of beat onsets and offsets, often centring on QRS onset without zero padding. As a result, portions of the preceding T wave or following P wave may be included in the median, which can distort morphology. In contrast, our approach uses the delineated beat boundaries to isolate a single complete beat, centres it on QRS onset, and applies zero padding to standardize length before temporal median filtering. In addition, built-in noise detection ensures that medians are generated only when signal quality is adequate, a safeguard less strictly implemented in existing commercial systems. Quantitative similarity metrics, including DDTW and cross-correlation, confirmed that our median beats were at least as consistent as reference medians. Furthermore, downstream classification using only median beats demonstrated higher area under the curve compared with medians from Uni-G, and similar to the medians from Marquette 12SL, underscoring their functional utility. Although no common reference standard exists, our results highlight the relative strengths and weaknesses of these methods. To our knowledge, this is the first study to benchmark median beat fidelity across algorithms and to discuss its clinical and algorithmic implications. Future work should extend evaluation beyond morphology-based median beat classification to clinically oriented downstream tasks, including risk and prognostic prediction.
Integrating delineation, rhythm analysis, and median beat construction into a single model has several practical advantages. First, it reduces the need for multiple specialized algorithms, simplifying integration into clinical workflows. A cardiologist or automated reporting system could obtain interval measurements, rhythm interpretation, and a representative median beat from a single inference step, ensuring these outputs are derived from a consistent set of model predictions. This may be particularly useful as decision support in settings with limited specialized ECG expertise, where structured outputs can support review and escalation. Second, accurate automated delineation enables extraction of quantitative features, such as PR, QRS, and QT intervals, which can feed into decision support systems or pharmacovigilance monitoring. Third, rhythm classification across a broad set of classes suggests that the model could serve as a triage tool, flagging clinically important arrhythmias for expedited review. Finally, high-fidelity median beats provide interpretable, noise-reduced representations that are both clinically familiar and useful as standardized inputs for downstream AI models, including foundation models that require consistent ECG representations.
Several aspects strengthen confidence in our findings. We created a carefully annotated internal dataset of ∼3000 ECGs with beat-level delineation and rhythm labels, including oversampling of rare rhythms to improve diversity. We validated performance on eight external datasets spanning different geographies, sampling rates, and class distributions, demonstrating generalizability. Evaluation was comprehensive and tailored to each prediction task. To promote reproducibility, we provide derived median beats from the full public datasets used in this study. Using our online tool, users can upload an ECG for delineation, classification, and median beat results (http://segmentation.ecgx.ai).
Despite these strengths, several limitations warrant consideration. First, the rhythm classification component was partially trained using weakly supervised labels extracted from diagnostic statements. While this increased rhythm class diversity, it also introduced potential label noise, especially for uncommon or morphologically ambiguous rhythms. Although beat-wise evaluation and noise exclusion helped mitigate this issue, imperfect labels may have affected the upper bound of achievable performance. Second, the model was evaluated on a broad array of publicly available datasets, but these do not capture all possible sources of variation in real-world ECG acquisition, such as differing electrode placements or evolving signal preprocessing techniques, which may influence generalizability. Related to this, some rhythm classes, including atrial pacing, atrial rhythms, and ventricular rhythms, remained underrepresented, resulting in lower per-class F1 scores and wider confidence intervals. Larger and more balanced datasets will be needed to improve performance for these rare classes. Moreover, because all methods were evaluated on the same recorded ECG signals, any acquisition-related limitations, such as sampling rate and device filtering, apply equally across methods. However, we cannot exclude that very narrow pacemaker artefacts were attenuated or missed at 500 Hz, which could reduce performance in paced rhythms. Third, the current approach treats P wave and QRS complex classification as separate tasks, yet in some cases, labelling differences that do not alter beat morphology, such as labelling a normal QRS complex as a premature atrial contraction, may reduce performance. Similarly, the model architecture assumes non-overlapping waveforms, which does not hold for rhythms, such as higher-degree AV blocks or sinus tachycardia. Fourth, the model output relies on several rule-based post-processing steps. Because we did not perform ablation experiments, we cannot quantify the relative contribution to overall performance of these rules compared with the segmentation model. Finally, reference median beats from Marquette 12SL and Uni-G are not perfect ground truths, and their inclusion of adjacent beats may disadvantage our approach in the downstream classification performance experiment due to the inclusion of additional information.
Conclusions
We developed a unified multi-label deep learning model that performs simultaneous ECG waveform delineation and rhythm classification, from which median beats are subsequently derived. The model achieved accuracy within clinical tolerances for waveform boundaries, robust rhythm classification, and high-fidelity median beats suitable for downstream analysis. This integrated approach can streamline ECG analysis, provide clinicians with consistent and interpretable outputs, and lay the foundation for downstream AI applications. Our findings support the feasibility of clinically deployable, multi-purpose AI tools for electrocardiography, moving beyond task-specific models towards comprehensive ECG interpretation systems.
Supplementary Material
Acknowledgements
The authors would like to thank Melle Vessies, Faye Raaijmakers, Joske van der Zande, Alejandra Zepeda Echevarria, Milou Schuurbiers, and Johanneke ten Broeke for their contributions to this project. During the preparation of this work, the authors used ChatGPT 5 in order to improve spelling, grammar, and readability of the manuscript. After using this tool/service, the authors reviewed and edited the content as needed and take full responsibility for the content of the published article.
Contributor Information
Bauke K O Arends, Department of Cardiology, University Medical Center Utrecht, Internal ref E03.511, Heidelberglaan 100, Utrecht 3584 CX, The Netherlands.
Bas B S Schots, Department of Cardiology, University Medical Center Utrecht, Internal ref E03.511, Heidelberglaan 100, Utrecht 3584 CX, The Netherlands.
Parmenion Koutsogeorgos, Cordys Analytics B.V., Utrecht, The Netherlands.
Timo Nijkamp, Department of Cardiology, University Medical Center Utrecht, Internal ref E03.511, Heidelberglaan 100, Utrecht 3584 CX, The Netherlands.
Tim M Paquaij, Department of Cardiology, University Medical Center Utrecht, Internal ref E03.511, Heidelberglaan 100, Utrecht 3584 CX, The Netherlands.
Diantha J M Schipaanboord, Department of Cardiology, University Medical Center Utrecht, Internal ref E03.511, Heidelberglaan 100, Utrecht 3584 CX, The Netherlands.
Rutger J Hassink, Department of Cardiology, University Medical Center Utrecht, Internal ref E03.511, Heidelberglaan 100, Utrecht 3584 CX, The Netherlands.
Pim van der Harst, Department of Cardiology, University Medical Center Utrecht, Internal ref E03.511, Heidelberglaan 100, Utrecht 3584 CX, The Netherlands.
René van Es, Department of Cardiology, University Medical Center Utrecht, Internal ref E03.511, Heidelberglaan 100, Utrecht 3584 CX, The Netherlands; Cordys Analytics B.V., Utrecht, The Netherlands.
Rutger R van de Leur, Department of Cardiology, University Medical Center Utrecht, Internal ref E03.511, Heidelberglaan 100, Utrecht 3584 CX, The Netherlands; Cordys Analytics B.V., Utrecht, The Netherlands.
Lead author biography
Bauke K.O. Arends is a physician–scientist specializing in the intersection of electrocardiography and deep learning. His research focuses on developing and validating AI–ECG algorithms to streamline diagnostic workflows and improve the detection of cardiovascular disease. He is particularly interested in advancing explainable and generalizable deep learning methods to enable safe and effective clinical integration of AI in cardiology.
Supplementary material
Supplementary material is available at European Heart Journal – Digital Health.
Author contributions
Bauke K.O. Arends (Formal analysis, Investigation, Visualization, Writing—original draft [lead], Methodology, Software [equal]), Bas B.S. Schots (Formal analysis, Investigation, Software, Visualization [supporting], Writing—review & editing [equal]), Parmenion Koutsogeorgos (Software, Writing—review & editing [equal]), Timo Nijkamp (Writing—review & editing [equal]), Tim M. Paquaij (Writing—review & editing [equal]), Diantha J.M. Schipaanboord (Writing—review & editing [equal]), Rutger J. Hassink (Writing—review & editing [equal]), Pim van der Harst (Funding acquisition, Writing—review & editing [equal], Supervision [supporting]), René van Es (Conceptualization [supporting], Funding acquisition, Supervision, Writing—review & editing [equal], Project administration [lead]), and Rutger R. van de Leur (Conceptualization, Data curation, Supervision, Writing—review & editing [lead], Investigation, Software [supporting], Methodology [equal])
Funding
The collaboration project is co-funded by public-private partnership allowances awarded by Health∼Holland, Top Sector Life Sciences & Health, to stimulate public–private partnerships (project no. 2021TKI2217, ECGxAI+, and project no. HH-PPS-24027-MKB, Future Heart) and the Eurostars programme (project no. 5846, REX-AI), which is co-funded by the European Union through the Horizon Europe programme and by the Eurostars participating countries.
Data availability
The UMCU internal dataset is not publicly available due to privacy restrictions. The external test datasets are available through their respective databanks. The evaluation code, the full list of cases used for external testing, and links to the derived median beats and manual annotations are available at: https://github.com/UMCUtrecht-ECGxAI/ecgsegmentation-pub.
Code availability
The code used for evaluation is available on https://github.com/UMCUtrecht-ECGxAI/ecg-segmentation-pub. Users can access the segmentation tool through http://segmentation.ecgx.ai.
References
- 1. Jimenez-Perez G, Acosta J, Alcaine A, Camara O. Generalising electrocardiogram detection and delineation: training convolutional neural networks with synthetic data augmentation. Front Cardiovasc Med 2024;11:1341786. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 2. Kashou AH, Noseworthy PA, Beckman TJ, Anavekar NS, Cullen MW, Angstman KB, et al. ECG interpretation proficiency of healthcare professionals. Curr Probl Cardiol 2023;48:101924. [DOI] [PubMed] [Google Scholar]
- 3. Cook DA, Oh SY, Pusic MV. Accuracy of physicians’ electrocardiogram interpretations: a systematic review and meta-analysis. JAMA Intern Med 2020;180:1461–1471. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 4. Schläpfer J, Wellens HJ. Computer-interpreted electrocardiograms. J Am Coll Cardiol 2017;70:1183–1192. [DOI] [PubMed] [Google Scholar]
- 5. Moskalenko V, Zolotykh N, Osipov G. Deep learning for ECG segmentation, eds. International Conference on Neuroinformatics. Cham: Springer International Publishing; Vol 856. 2020. p246–254. [Google Scholar]
- 6. Haleem MS, Pecchia L. A deep learning based ECG segmentation tool for detection of ECG beat parameters. 2022 IEEE Symp Comput Commun (ISCC) 2022:1–4. [Google Scholar]
- 7. Park J, Park T, Kim G, Jo YY. Benchmarking ECG delineation using deep neural network-based semantic segmentation models. Proc Mach Learn Res 2025;287:63–88. [Google Scholar]
- 8. Hernández-Fernández C, Gómez-Moreno H, Holgado-Cuadrado R, Blanco-Velasco M. Long-term ECG analysis through image conversion and deep learning. Comput Cardiol 2023;50:1–4. [Google Scholar]
- 9. Joung C, Kim M, Paik T, Kong S-H, Oh S-Y, Jeon WK, et al. Deep learning based ECG segmentation for delineation of diverse arrhythmias. Hammad M, ed. PLoS One 2024;19:e0303178. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 10. Chen Z, Wang M, Zhang M, Huang W, Gu H, Xu J. Post-processing refined ECG delineation based on 1D-UNet. Biomed Signal Process Control 2023;79:104106. [Google Scholar]
- 11. Darmawahyuni A, Nurmaini S, Rachmatullah MN, Avi PP, Teguh SBP, Sapitri AI, et al. Improved delineation model of a standard 12-lead electrocardiogram based on a deep learning algorithm. BMC Med Inform Decis Mak 2023;23:139. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 12. Niroshana SMI, Kuroda S, Tanaka K, Chen W. Beat-wise segmentation of electrocardiogram using adaptive windowing and deep neural network. Sci Rep 2023;13:11039. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 13. Nurmaini S, Darmawahyuni A, Rachmatullah MN, Firdaus F, Sapitri AI, Tutuko B, et al. Robust electrocardiogram delineation model for automatic morphological abnormality interpretation. Sci Rep 2023;13:13736. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 14. Laguna P, Mark R, Goldberger A, Moody G. A database for evaluation of algorithms for measurement of QT and other waveform intervals in the ECG. Comput Cardiol 1997;24:673–676. [Google Scholar]
- 15. Kalyakulina AI, Yusipov II, Moskalenko VA, Nikolskiy AV, Kosonogov KA, Osipov GV, et al. LUDB: a new open-access validation tool for electrocardiogram delineation algorithms. IEEE Access 2020;8:186181–186190. [Google Scholar]
- 16. Van De Leur RR, Blom LJ, Gavves E, Hof IE, van der Heijden JF, Clappers NC, et al. Automatic triage of 12-lead ECGs using deep convolutional neural networks. J Am Heart Assoc 2020;9:e015138. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 17. Chen LC, Zhu Y, Papandreou G, Schroff F, Adam H. Encoder-decoder with atrous separable convolution for semantic image segmentation. In: Ferrari V, Hebert M, Sminchisescu C, Weiss Y, eds. Computer Vision—ECCV 2018. Vol. 11211. Lecture Notes in Computer Science: Springer International Publishing; 2018. p833–851. [Google Scholar]
- 18. Wang Y, Wang C, Wu H, Chen P. An improved Deeplabv3 + semantic segmentation algorithm with multiple loss constraints. Zhang Q, ed. PLoS One 2022;17:e0261582. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 19. Strodthoff N, Mehari T, Nagel C, Aston PJ, Sundar A, Graff C, et al. PTB-XL+, a comprehensive electrocardiographic feature dataset. Sci Data 2023;10:279. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 20. Berger L, Haberbusch M, Moscato F. Generative adversarial networks in electrocardiogram synthesis: recent developments and challenges. Artif Intell Med 2023;143:102632. [DOI] [PubMed] [Google Scholar]
- 21. Hermans BJM, Vink AS, Bennis FC, Filippini LH, Meijborg VMF, Wilde AAM, et al. The development and validation of an easy to use automatic QT-interval algorithm. Baumert M, ed. PLoS One 2017;12:e0184352. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 22. Panicker GK, Karnad DR, Natekar M, Kothari S, Narula D, Lokhandwala Y. Intra- and interreader variability in QT interval measurement by tangent and threshold methods in a central electrocardiogram laboratory. J Electrocardiol 2009;42:348–352. [DOI] [PubMed] [Google Scholar]
- 23. Stephansen C, Kronborg MB, Witt CT, Kristensen J, Gerdes C, Sommer A, et al. Reproducibility of measuring QRS duration and implications for optimization of interventricular pacing delay in cardiac resynchronization therapy. Ann Noninvasive Electrocardiol 2019;24:e12621. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 24. Hannun AY, Rajpurkar P, Haghpanahi M, Tison GH, Bourn C, Turakhia MP, et al. Cardiologist-level arrhythmia detection and classification in ambulatory electrocardiograms using a deep neural network. Nat Med 2019;25:65–69. [DOI] [PMC free article] [PubMed] [Google Scholar]
- 25. Alday EAP, Gu A, Shah A, Robichaux C, Ian Wong AK, Liu C, et al. Classification of 12-lead ECGs: the PhysioNet/computing in cardiology challenge 2020. Physiol Meas;41:124003. [DOI] [PMC free article] [PubMed] [Google Scholar]
Associated Data
This section collects any data citations, data availability statements, or supplementary materials included in this article.
Supplementary Materials
Data Availability Statement
The UMCU internal dataset is not publicly available due to privacy restrictions. The external test datasets are available through their respective databanks. The evaluation code, the full list of cases used for external testing, and links to the derived median beats and manual annotations are available at: https://github.com/UMCUtrecht-ECGxAI/ecgsegmentation-pub.
