A physiologically informed deep-learning framework that disentangles ECG morphology from rhythm to generalize to unseen hospitals and devices without fine-tuning.

Deep learning already classifies electrocardiograms (ECG) well within a single dataset. The obstacle to clinical deployment is what happens across datasets: move a model to another hospital, with different hardware, lead placement, sampling rates and patient mix, and accuracy often falls away. ECG-RAMBA attacks that generalization gap by explicitly separating the two information streams clinicians actually reason about — morphology and rhythm — and re-integrating them through context-aware fusion.
Many architectures implicitly entangle morphological waveform patterns with rhythm dynamics inside a single representation. That entanglement encourages shortcut learning: the network latches onto dataset-specific acquisition cues that correlate with labels in training but do not reflect causal physiology. The result is a model that looks excellent on its own benchmark and becomes brittle under distribution shift — precisely the behaviour that erodes clinical trust.
Clinical ECG interpretation integrates at least two complementary streams: morphology (P/QRS/T shape, ST–T deviations) and rhythm (beat-to-beat variability and regularity). ECG-RAMBA mirrors that separation in the architecture itself:
Transient abnormalities are easy to lose under windowed inference: max pooling is brittle to noise, while averaging dilutes short pathological events. We introduce a numerically stable Power Mean pooling operator that acts as a soft-attention mechanism over windows. A full sweep showed higher exponents marginally improve F1 while increasing sensitivity to noise artifacts, so Q=3 was adopted as the robust operating point.
Evaluation choices strongly influence reported ECG results. Protocols that allow subject overlap between training and test splits, or that tune decision thresholds in ways deployment would not permit, yield optimistic estimates. We therefore enforce subject-level separation, a fixed decision threshold and no test-time adaptation throughout.
In distribution, ECG-RAMBA reaches a macro ROC-AUC of 0.848 ± 0.047 with a macro F1 of 0.312 ± 0.052 at a fixed threshold. In zero-shot transfer it attains PR-AUC 0.708 for atrial fibrillation on CPSC-2021, substantially outperforming a comparable raw-signal Mamba baseline and remaining competitive against learned convolutional and transformer baselines.
Transfer reveals a dichotomy grounded in physiology rather than noise. Rhythm-dominant abnormalities generalize robustly across devices, confirming the model captures global temporal invariants. Morphology-dependent pathologies — particularly myocardial infarction on PTB-XL — degrade under transfer, reflecting sensitivity to lead-set configuration. We quantify that behaviour rather than averaging it away.
The gap between strong ranking (ROC-AUC) and more conservative fixed-threshold decisions is examined directly through a calibration analysis, distinguishing a genuinely conservative operating point from simple miscalibration — a distinction that matters for a decision-support system expected to minimise false positives and avoid alarm fatigue.
Ablations indicate deterministic morphology provides a strong foundation, while explicit rhythm modeling and long-range context are the critical drivers of cross-domain robustness. Robustness checks cover noise, sampling-rate and lead perturbations, alongside an HRV domain-identifiability probe that tests whether rhythm features leak dataset provenance.
ECG-RAMBA shows that physiological disentanglement is a practical route to cross-domain robustness: the model transfers to unseen cohorts without fine-tuning, and its interpretable division of labour between waveform morphology, rhythm descriptors and long-range evidence makes its failure modes legible instead of mysterious.
Figures and interface screenshots from the project.







