Within-Record Adversaries for Noise-Invariant 12-Lead ECG Models

Clinical electrocardiograms (ECGs, the 12 voltage traces a hospital records from electrodes on the chest and limbs) are routinely corrupted by electrode motion, muscle activity and breathing-induced baseline drift. This noise usually hits one or a few leads at a time, not the whole recording. A standard way to make a classifier ignore such corruption is adversarial domain adaptation. In this approach, a second network (the discriminator) tries to tell "clean" from "noisy" inputs, and the feature extractor is trained to fool it. The extractor then ends up with features that carry no information about noise. The trouble is that in real hospital data, noisy recordings are not a random sample. They come disproportionately from sicker, moving, or monitored patients. A discriminator that separates noisy from clean recordings can therefore succeed partly by detecting pathology, and fooling it erases exactly the diagnostic signal we care about.

We propose to remove this confound by construction. Within a single 12-lead recording, every lead sees the same heart at the same moment, so the pathology is identical across leads. If one lead is noisy and another is clean, the only systematic difference between them is the noise and the lead's viewing angle. We train a per-lead discriminator only on such within-record contrasts and give it the lead's identity as an input. The discriminator can then learn noise but cannot learn disease, and the encoder can be pushed to be invariant to real, unpaired clinical noise without being pushed to forget pathology. As a by-product, the trained discriminator becomes a per-lead quality score that can down-weight badly corrupted leads at test time.

Core Claim

Adversarial noise-invariance for multi-lead biosignals should be enforced inside each recording, between leads that share the same pathology, rather than across recordings or datasets. Our claim has three parts. A lead-conditioned, within-record discriminator trained on real annotated noise improves diagnostic accuracy on genuinely noisy recordings. It does so beyond what synthetic noise injection with clean/noisy consistency achieves. And it avoids the loss of pathology information that a record-level clean-versus-noisy discriminator causes when noise and disease are correlated.

What is new is the choice of comparison set for the adversary. The adversarial machinery itself is standard. Its role in our design is to handle real noise that has no clean counterpart. Synthetic noise is still handled by the simpler consistency loss.

Where This Sits

Three biosignal papers already join adversarial or domain-adaptive training with physiological noise, and each leaves our question open. ALIGN attaches a session discriminator to intermediate layers of an intracortical speech decoder and cuts session-average phoneme error on T12 from 38.74% to 30.46%. It aligns all channels uniformly and treats whole sessions as domains, so localized artifacts and confounds between session and content are not modeled. DWLR aligns time and global-Fourier features across wearable users while reweighting for label shift. It absorbs noise into a generic domain shift and does not test multi-lead clinical ECG. DE-PADA adapts ECG biometrics across rest and exercise using segment-specific experts. Its segmentation depends on R-peak detection, which fails under heavy noise. All three define the domain at the level of the session, user or recording. That level is exactly where pathology can leak into the domain label.

The confound itself motivates the proposal. Learning Disentangled Semantic Representation for Domain Adaptation documents "false alignment": marginal alignment merges semantically different classes. Their remedy factorizes latents with a variational autoencoder, which is a modeling fix. Ours is a sampling fix that makes the adversary's target independent of the label by design. BRADA shows that treating all EEG channels as one block causes negative transfer, and it selects channels by hand. We let the data say which leads are corrupted.

On the noise side, TolerantECG distills from a noise-specialist teacher trained with injected noise from the MIT-BIH Noise Stress Test Database (NSTDB) and from a missing-lead teacher. That is the strongest version of "augment with synthetic noise," and it is our main competitor. Robustness of electrocardiogram signal quality indices shows that statistical quality indices with fixed thresholds lose specificity under dataset shift. This constrains our design: any quality signal we use must be learned and tested across datasets.

We reuse two methods. The first is the test-time reuse of a discriminator as a quality weight, from Unsupervised Domain Adaptation for Face Recognition in Unlabeled Videos. That paper also argues that feature-level adaptation beats pixel-level restoration. The second is the clean-only convolutional autoencoder with Gaussian-mixture scoring from Automatic Detection of Noisy Electrocardiogram Signals Without Explicit Noise Labels, which we use as a fallback per-lead noise labeler.

Research Program

Model. The model is a shared per-lead convolutional encoder that maps each lead $l$ of record $r$ to an embedding $z_{r,l}$. A cross-lead attention layer pools these embeddings into a record representation, and a multi-label diagnostic head sits on top. A discriminator $D(z_{r,l}, l)$ receives a lead's embedding together with that lead's identity and predicts its quality label $q_{r,l}$ (clean or noisy).

Where quality labels come from. PTB-XL ships signal-quality annotations (PTB-XL, a large publicly available electrocardiography dataset). Where these name the affected leads, we use them directly. Where they do not, we assign per-lead labels with the clean-trained autoencoder detector, after validating that detector on BUTQDB.

Training objective. The discriminator is trained only on lead pairs drawn from mixed-quality records, meaning records with at least one clean and at least one noisy lead. Within such a pair the diagnostic labels are equal by construction. The encoder $E$ minimizes

$$ \mathcal{L} = \mathcal{L}_{\text{task}} + \lambda_c \, \lVert E(x) - E(x + n) \rVert^2 - \lambda_a \, \mathcal{L}_{D}^{\text{within}}, $$

where the terms are as follows. $\mathcal{L}_{\text{task}}$ is the diagnostic loss on all records. The second term is a consistency penalty between a clean lead $x$ and the same lead with injected NSTDB noise $n$. $\mathcal{L}_{D}^{\text{within}}$ is the discriminator's cross-entropy on within-record pairs, which the encoder maximizes through a gradient reversal layer, and $\lambda_c, \lambda_a$ are weights. Conditioning $D$ on $l$ matters because some leads are noisy more often than others. Without lead identity, the discriminator could detect "this is lead V1" instead of "this is noise."

Inference. At test time the discriminator's noisy-probability for each lead scales that lead's attention weight. This lets severely corrupted leads fade out instead of forcing them into a clean-looking embedding.

Main risk. Making noisy-lead features indistinguishable from clean ones may push the encoder to discard fine detail, such as low-amplitude P-waves and subtle ST shifts, from clean leads too. This is the oversmoothing failure the noise literature warns about. We limit the risk in two ways. The task loss is applied on clean leads. And we restrict the adversarial term to slight-noise leads, routing severe ones through the quality-weighted attention instead. We measure this risk directly, as described in the decisive checks below.

Baselines

Naive reference. The do-nothing baseline is the same encoder and attention head trained with supervision on PTB-XL with no robustness term. For calibration, published PTB-XL numbers in the file are:

No reported result was found on Lacuna for any method restricted to PTB-XL's noise-annotated records, which is the subset that matters here. We will report it for every baseline.

Strongest existing method. The strongest competitor is synthetic-noise robustness in the style of TolerantECG: NSTDB injection plus distillation from a noise-specialist teacher, alongside our consistency term. TolerantECG reports 0.979 average precision and 0.994 AUC on MIT-BIH, but the file gives no PTB-XL noisy-subset figure. Because its MIMIC-IV-ECG pretraining scale would confound the comparison, we will reimplement its noise-teacher distillation on our backbone. If released weights exist, we will also evaluate them as a reference point. All methods share the following:

  • the same backbone, data and number of training steps;
  • an equal hyperparameter search budget of 20 configurations each;
  • selection on the same validation folds, using PTB-XL's recommended split.

Beating this baseline means a gain on the real-noise test subset whose 95% confidence interval, bootstrapped over patients, excludes zero, with no loss on clean records.

The obvious adversarial design. A record-level clean-versus-noisy discriminator with gradient reversal is the natural intersection of the two directions. It tests whether the within-record restriction matters at all.

Two-stage pipeline. We run DeScoD-ECG, with FCN-DAE as a cheaper variant, as a front-end denoiser before the naive classifier. The classifier is fine-tuned on denoised training data so that it is not penalized for distribution mismatch.

Lead masking. Since TolerantECG already handles missing leads, we drop flagged leads in two variants: one using the annotations (an oracle) and one using the learned autoencoder detector.

Ablations. Three ablations isolate the key ingredient:

  • pairs drawn across records, which keeps per-lead adversaries but loses pathology matching;
  • removing lead conditioning;
  • removing quality-weighted attention.

Why not just…?

Why not just inject NSTDB noise and enforce consistency? This is the real threat. For synthetic noise, a paired consistency loss gives invariance without any minimax game. The file's evidence that it falls short on real noise is indirect. The face-video adaptation paper found synthetic degradation alone insufficient for in-the-wild data, and the quality-index study shows that statistics calibrated on one noise source fail on others. We do not assume the point. The comparison of our full objective against the consistency-only model on real annotated noise settles it. If the within-record adversary adds nothing there, the honest conclusion is that synthetic noise suffices for ECG, and we would report that.

Why not denoise first and then classify? Generic denoisers are trained to reconstruct waveforms, not to preserve diagnostic features, and the noise literature reports that aggressive denoising rounds off the R-peaks and ST segments that indicate infarction. DeScoD-ECG's multi-shot sampling is also slow for wearables. We still run it as a full baseline. If it matches us on myocardial-infarction AUC under noise, feature-level invariance is not needed.

Why not just mask the noisy leads? When the noisy leads are known, masking is simple and safe. But annotations are absent at deployment, and slightly noisy leads still carry information. The oracle-masking and detector-masking baselines measure both effects. If detector-masking matches our method, the contribution reduces to the quality detector, and we would say so.

Why not filter with signal quality indices or bandpass filters? Fixed-threshold indices lose specificity under dataset shift (Robustness of electrocardiogram signal quality indices). Linear filters overlap spectrally with QRS and ST content and are outperformed by learned denoisers in DeScoD-ECG's evaluation. We include a 0.5–40 Hz bandpass filter as a preprocessing step in the naive baseline rather than as a separate competitor.

Proposed Experiments and Decisive Checks

Main comparison. We train on PTB-XL at 500 Hz and report macro AUC on three test subsets: clean records, records with annotated real noise, and clean records corrupted with NSTDB electrode-motion, muscle and baseline-wander noise at −6 to 12 dB.

Confound stress test. This is the decisive check for the core claim. We build training splits in which noise annotations are resampled to co-occur with myocardial infarction at controlled rates of 0.5, 1 and 2 times the base rate. The prediction is that the record-level discriminator loses MI AUC as the correlation grows, while the within-record discriminator stays flat. If both stay flat, the confound argument is wrong in practice.

Information-loss probe. We freeze each encoder and train linear probes on clean leads for P-wave presence and ST deviation. A drop relative to the naive encoder would confirm the oversmoothing risk.

Quality-detector transfer. We score BUTQDB leads with our discriminator, without training on BUTQDB. We compare against the autoencoder plus Gaussian-mixture detector's reported AUROC of 77.82% for slight noise and 95.84% for severe noise (Automatic Detection of Noisy Electrocardiogram Signals Without Explicit Noise Labels), with specificity reported explicitly given the known failure of quality indices on that measure.

Cross-dataset check. We apply the same evaluation to MIT-BIH heartbeat classes using AAMI-mapped labels, and treat it as secondary because its label space differs from PTB-XL's.