When an electrocardiogram (ECG) classifier trained at a few hospitals is tested at a new one, it fails worst on rare diagnoses. The best published domain-generalization model on a six-database ECG benchmark still leaves 9 of 24 diagnoses undetected at unseen sites. We propose that this failure is largely a confound created by data fragmentation. Rare diagnoses are recorded mostly at one or two hospitals, so a network can learn "this hospital's recording signature" as a stand-in for "this rare disease." Each site's equipment leaves a recognizable acquisition fingerprint: its noise floor, its built-in filtering, its baseline drift. These fingerprints sit in specific frequency bands at specific time scales, and that is exactly what a wavelet transform separates out. A wavelet transform splits a signal into a coarse trend plus detail layers at successively finer time scales, so sharp heartbeat features stay localized while noise spreads thinly across the fine layers.
The idea is to break the link between rare labels and their source site. We estimate each hospital's per-scale wavelet fingerprint using the standard noise estimators from wavelet thresholding. During training, we re-render every rare-class recording as if it had been acquired at each of the other training hospitals. This is minority oversampling that varies the one thing the model should ignore, rather than duplicating examples and their artifacts. If the confound explanation is right, the gains should land on the rare classes whose positives are most concentrated at a single site. Uniform noise augmentation, denoising everything to a canonical form, or simply reweighting the loss should not produce the same gains. We also measure that concentration directly, so the hypothesis can fail cleanly.
Core Claim
Out-of-distribution failure on rare ECG classes is predicted by how strongly each class's positives are concentrated at a single training site. Site-matched wavelet fingerprint transplantation, applied preferentially to minority-class examples, reduces this failure more than three alternatives: generic noise augmentation, wavelet denoising used as canonicalization, or imbalance-aware losses. Neither ingredient works alone. Imbalance handling without fingerprint transplantation still lets the model memorize site artifacts. Transplantation applied uniformly spends most of its effect on majority classes that were never confounded.
Relation to Prior Work
The motivating evidence comes from Ballas and Diou. Their earlier study, A Domain Generalization Approach for Out-Of-Distribution 12-lead ECG Classification with Convolutional Neural Networks, trains a ResNet-18 on Chinese and German databases and tests on Russian and American ones, combining features from 16 intermediate layers. Only 12 of 24 abnormalities were detected by either model in that study. Their benchmark paper, Towards Domain Generalization for ECG and EEG Classification: Algorithms and Benchmarks (BioDG), runs leave-one-domain-out evaluation over six ECG datasets. It reports an out-of-distribution Macro-F1 of 35.88% for the multi-layer ResNet-18 against 23.40% for plain training, with 15 conditions detected against 11, and attributes the remaining failures to class imbalance across registries. Neither paper uses wavelets, and neither intervenes on the label–site confound. We reuse their data, protocol and backbone, and change only how training examples are generated.
The method draws on classical wavelet denoising. ECG-based machine-learning algorithms for heartbeat classification applies a fixed Daubechies-4 decomposition to strip baseline wander and muscle noise before training on one database and testing on another. Its filter is static and identical for every site, which is the assumption that hardware heterogeneity breaks (EKG-Diagnostik mithilfe künstlicher Intelligenz documents vendor-locked formats across ECG manufacturers). Subband-adaptive soft thresholding of the kind used in Image Super-Resolution as a Defense Against Adversarial Attacks supplies our per-scale noise estimate. We use these estimates to synthesize site variation instead of removing it.
Two papers constrain the design. Deep Learning for ECG Analysis: Benchmarks and Insights from PTB-XL shows that wavelet coefficients fed to a shallow network badly underperform end-to-end convolutional networks (macro AUC 0.868 against 0.939). We therefore keep wavelets out of the classifier's input and use them only to generate training data. WaveSSM shows that wavelet frames inside a sequence model reach AUROC 0.942 on PTB-XL, but only on a single-source split. A wavelet backbone is therefore a competitor we must beat, not something we can assume generalizes across sites. On the imbalance side, the note that naive minority duplication causes memorization of idiosyncratic artifacts (Tousignant et al., summarized in the file) is the specific failure our oversampling is designed to avoid. ECG-specific generators such as ODE-Constrained Generative Modeling of Cardiac Dynamics for 12-Lead ECG Synthesis attack scarcity by synthesizing new beats. That carries a risk of unphysiological waveforms. We leave the cardiac content untouched and alter only the acquisition layer.
Research Program
The first step is diagnostic and requires no new model. For each of the 24 BioDG classes, we compute a site-concentration score: the normalized mutual information between site identity and source among that class's positive records in the training domains of each leave-one-out fold. We then ask whether this score, more than raw prevalence, predicts the class's out-of-distribution F1 under the published multi-layer model. This test can kill the project early. If concentration has no explanatory power beyond prevalence, then the failure is plain data scarcity, and the proposal should turn into a pure imbalance study.
The second step builds the site fingerprint. Records are first resampled to a common rate. Each record is then decomposed with a stationary (undecimated) Daubechies wavelet transform; the undecimated version is chosen so that resynthesis does not depend on where the signal happens to start. For site $s$ and detail scale $j$, we estimate two quantities. The first is a noise level $\sigma_{s,j}$, the median absolute deviation of the detail coefficients divided by 0.6745, which is the standard robust estimator behind universal thresholding. The second is a band gain $g_{s,j}$, the median sub-band energy of beat-aligned, denoised QRS segments relative to a pooled reference. The gain captures each vendor's built-in filtering. The coarsest approximation band gives a baseline-wander spectrum $B_s$.
To transplant a record $x$ from site $s$ to site $t$, we soft-threshold its detail coefficients $w_j$ with a scale-wise threshold to obtain an estimate $\hat w_j$ of the clean content. We rebuild
$$\tilde w_j = \frac{g_{t,j}}{g_{s,j}}\,\hat w_j + \sigma_{t,j}\,\epsilon_j,$$
where $\epsilon_j$ is Gaussian noise resampled from site $t$'s residual coefficients instead of drawn from an idealized distribution. We also replace the approximation band's low-frequency residual with one drawn from $B_t$, then invert the transform.
The third step is the training procedure. Minority-class records are oversampled up to a target ratio. Each extra copy is transplanted to a training site that is chosen with probability inversely proportional to how often that class already appears there. Every rare label therefore ends up seen under every available fingerprint. Majority-class records are transplanted with a small probability, so the model does not learn transplantation artifacts as a class cue. The backbone and loss match BioDG exactly. One variant pairs this with logit adjustment, a correction that subtracts each class's log prior from its output score, to test whether the two ingredients are complementary.
Baselines
The do-nothing reference is plain empirical risk minimization on the BioDG ResNet-18 with the benchmark's own preprocessing. It is reported at 23.40% out-of-distribution Macro-F1 in the BioDG paper. We rerun it from the BioDG repository so that every comparison shares seeds, folds and the detection threshold.
The strongest existing method is the BioDG multi-layer ResNet-18, reported at 35.88% out-of-distribution Macro-F1 with 15 of 24 conditions detected. It is the most direct competitor because it was designed for this benchmark and its failure is the one we target. We apply our training procedure on top of this same architecture. Beating it means a mean leave-one-out Macro-F1 gain whose confidence interval over five seeds excludes zero, together with more conditions detected under BioDG's own criterion. It must also show a positive gain on the worst held-out site, so the improvement is not an average carried by one easy site.
The BioDG versions of CORAL, IRM, MMD and RSC serve as feature-alignment competitors and are run with their published configurations.
WaveSSM, from WaveSSM (0.942 AUROC on PTB-XL, single-source), is the strongest wavelet-native model. We train it under the same leave-one-out folds with a matched parameter count. There is no reported result on Lacuna for WaveSSM under a multi-center out-of-distribution protocol, so this is a new measurement.
Three ablations isolate the key ingredient. The first draws profiles at random instead of from real sites. The second applies transplantation uniformly instead of targeting minority classes. The third oversamples minority classes by duplication only. Every arm gets the same number of gradient steps and the same budget of 20 hyperparameter trials, selected on held-out training-domain validation data and never on the test site.
Why not just…?
Why not just reweight the loss or adjust logits for imbalance? This is the most serious alternative. It needs no signal processing, and imbalance is the cause the BioDG authors themselves name. If rare classes fail simply because they are rare, logit adjustment on the multi-layer model should recover most of the gain. Our concentration diagnostic separates the two explanations. Loss reweighting should help in proportion to prevalence. Transplantation should help in proportion to site concentration. If logit adjustment matches our method on high-concentration classes, the confound story is wrong and we will report that.
Why not just add generic noise and baseline wander? Random Gaussian noise, synthetic drift and band-pass jitter are cheap. They also blur site identity somewhat. The random-profile ablation tests this directly: it uses the same pipeline with profiles that do not correspond to any real hospital. If real site profiles give no advantage over random ones, the "fingerprint" framing adds nothing, and the honest conclusion is that strong generic augmentation suffices.
Why not just denoise everything into a canonical form? Applying the same adaptive wavelet shrinkage to every record at training and test time, in the spirit of ECG-based machine-learning algorithms for heartbeat classification, removes noise instead of randomizing it, and has the appeal of determinism. Two problems remain. Vendor filtering removes content outright, and denoising cannot restore it, so band-gain differences survive canonicalization. Shrinkage also erases the fine-scale detail of the pathology, which matters for some diagnoses. We run canonicalization as a full arm. If it matches transplantation, we would recommend it, since it is simpler.
Why not just use a wavelet-based backbone? WaveSSM's gains were measured on a single source. A model that represents local transients well may represent site artifacts equally well. Our WaveSSM arm tests this. If it closes the out-of-distribution rare-class gap without any data intervention, our contribution shrinks to a diagnostic.
Decisive Checks
The experiments use BioDG's six ECG datasets (including CPSC, CPSC-Extra, PTB, PTB-XL, INCART and G12EC) under leave-one-domain-out evaluation. Metrics are per-class F1, area under the precision–recall curve, Macro-F1 and the count of detected conditions, each reported per held-out site and as the worst site.
The core prediction is that the per-class gain over the multi-layer baseline correlates positively with site concentration. Gains on classes with low concentration should be near zero.
A second check concerns the learned features. We train a linear probe on penultimate features to predict site among rare-class positives. Its accuracy should fall substantially under transplantation and fall far less under duplication or loss reweighting.
A third check guards against artifacts. A classifier trained to tell real from transplanted records should perform near chance on held-out data. If it does not, the model may be learning transplantation itself as a cue. In that case we would restrict transplantation to the scales where the real-versus-transplanted classifier fails.
Finally, AUROC-style aggregates are known to hide subgroup collapse (AFISP found 0.986 overall but 0.81 in one subgroup). We therefore report the worst site-by-class cell alongside every average, and treat a gain that leaves that cell unchanged as no gain.
References
- A Domain Generalization Approach for Out-Of-Distribution 12-lead ECG Classification with Convolutional Neural Networks
- Towards Domain Generalization for ECG and EEG Classification: Algorithms and Benchmarks
- ECG-based machine-learning algorithms for heartbeat classification
- EKG-Diagnostik mithilfe künstlicher Intelligenz: aktueller Stand und zukünftige Perspektiven – Teil 1
- Image Super-Resolution as a Defense Against Adversarial Attacks
- Deep Learning for ECG Analysis: Benchmarks and Insights from PTB-XL
- WaveSSM: Multiscale State-Space Models for Non-stationary Signal Attention
- ODE-Constrained Generative Modeling of Cardiac Dynamics for 12-Lead ECG Synthesis
- A data-driven framework for identifying patient subgroups on which an AI/machine learning model may underperform