Models that read long heart recordings in time proportional to their length are cheap enough to run on a CPU or a wearable. Their weakness is that they miss the small shape changes inside each heartbeat that separate one cardiac diagnosis from its neighbour, such as a slightly depressed ST segment. We propose to fix this by changing the coordinate system the model reads, rather than adding more features on the side. A classical detector that also runs in linear time finds each heartbeat. The recording is then laid out as a grid: one row per heartbeat, one column per position within the beat. A state-space model, a recurrent network that carries a fixed-size memory forward and runs in linear time, scans this grid in two ways. It scans along each row, as usual. It also scans down each column, which compares the same moment of the cardiac cycle across successive beats.
The bet is that fixed-memory models lose morphology because heart-rate variability smears each waveform landmark across different time offsets. In beat coordinates, an ST deviation becomes a steady signal that the model can accumulate over many beats instead of rediscovering in every cycle. The expected payoff is diagnostic granularity. Gains should concentrate on the morphological classes of the 27-class PhysioNet 2020 task, where linear-time models currently lag. The whole pipeline, detector included, should stay inside a strict compute budget, which is exactly where earlier feature-heavy entries failed.
Core Claim
Domain knowledge helps a linear-time sequence model most when it defines the axes along which the model scans, not when it is appended as extra input. The file points to the gap from two sides. S2M2ECG runs a bidirectional Mamba branch per lead with squeeze-and-excitation fusion, reaching 91.8% F1 on Chapman with 0.705M parameters and under 5 ms CPU latency. Its authors concede a gap against heavy CNNs on subtle ST-segment changes. Goodfellow et al. injected P, R and T landmark likelihood maps as extra input channels to a dilated WaveNet and reached a 0.630 cross-validation challenge score. The model then timed out on the hidden set and scored −0.406, showing that feature pipelines must be budgeted end to end.
Qin et al. supply the missing piece. Their R-peak detector combines wavelet filtering, forward differences and adaptive thresholds, runs in strict $O(N)$ time, and takes 0.872 s per MIT-BIH record with 99.39% sensitivity. It has never been used as the indexing layer of a learned model.
The closest three-way work, DermaMamba, also scans a 2D grid in several directions and encodes clinical rules. Its grid is the image's pixel lattice, and its clinical rules enter as features, not as the geometry of the scan. It is also static 2D imaging trained with plain cross-entropy. Our grid is defined by physiology, and it changes shape with every recording's heart rate.
Concretely, let $r_b$ be the $b$-th detected R-peak, $\mathrm{RR}_b = r_{b+1} - r_b$ the interval to the next peak, $P$ a fixed number of phase bins, and $\alpha \in (0,1)$ the fraction of the cycle placed before the peak. The beat grid for lead $x$ is
$$ \tilde{x}[b, j] = x\left(r_b + \left(\tfrac{j}{P} - \alpha\right)\mathrm{RR}_b\right), \qquad j = 0, \dots, P-1, $$
computed by linear interpolation. The number of beats grows proportionally with recording length and $P$ is constant, so building and scanning the grid costs $O(N)$.
Warping each beat to a fixed length erases interval information that rhythm diagnoses need. Each row therefore carries a small token holding $\mathrm{RR}_b$, the preceding interval, and a detector-confidence score. That score is computed from template correlation and the physiological plausibility of the interval. When confidence is low, the row is masked in the column scan. A parallel raw-time scan, a copy of the S2M2ECG branch, carries global rhythm context and takes over when beat detection fails. This matters because classical detectors break on noisy records such as MITDB 207, as Qin et al. note.
Research Program
The model has three linear-time parts. The first is the Qin detector, reimplemented to run on all 12 leads. The second is a per-lead state-space model that scans the beat grid bidirectionally along phase (within a beat) and along beat index (across beats at fixed phase). The third is a raw-time state-space branch. The branches are fused per lead and then across leads.
Training uses the PhysioNet 2020 reward matrix as a differentiable expected-reward term added to binary cross-entropy. Perez-Alday et al. designed that matrix to give partial credit for clinically close confusions. We borrow the idea of a cost-aware objective from DeepTag, which used SNOMED-CT distances to regularize fine-grained codes.
This loss is not our contribution. Every baseline gets the same loss, so the comparison isolates the scan geometry. We also add a DeepTag-style abstention readout. It tests whether the column-scan uncertainty ranks borderline records better than softmax confidence does, because fine-grained labels make borderline cases more common.
The analysis question is where the gains land. We will split the 27 classes into morphology-dominated diagnoses (ST and T-wave changes, QRS and conduction abnormalities, prolonged intervals) and rhythm-dominated diagnoses (atrial fibrillation and flutter, bradycardia and tachycardia, ectopic beats). The split is fixed before any experiment is run. We will also probe the learned column-scan states for known quantities, such as ST level and QRS width, to see whether the memory carries interpretable per-phase summaries. This partly addresses the opacity of state-space models relative to attention maps.
Baselines
The naive reference is a 1D ResNet trained end to end on raw 12-lead signals with the same loss, augmentation and tuning budget. It is linear in sequence length and represents what most 2020 challenge teams did.
The strongest existing method on this benchmark is Wide and Deep Transformer. It pairs a CNN-plus-Transformer deep branch with 22 Random-Forest-selected handcrafted features and placed first with an official test score of 0.533 on 15-second windows (0.496 on 10-second windows). The official hidden test set may not be available to us, so we will reimplement it under our own leave-one-source-out protocol rather than compare against the published number directly. The published 0.533 serves as a sanity anchor for our reimplementation.
The strongest linear-time competitor is S2M2ECG, reimplemented at matched parameter count. No reported result was found on Lacuna for S2M2ECG on PTB-XL or on the PhysioNet 2020 challenge metric, so we will generate that number ourselves.
Two ablations isolate the key ingredient. The first, landmark-as-channel, feeds Goodfellow-style likelihood maps into the raw-time state-space model with no grid, testing whether the gain comes from knowing where beats are or from reorganizing the scan. The second removes the column scan and keeps only within-beat scanning, testing whether comparing beats across the cycle is what recovers morphology.
Every model gets the same folds and the same number of tuning trials. Latency is measured on a single CPU core with detection and feature time included.
Beating Wide and Deep means a higher mean challenge score across held-out hospital sources at no more than its measured end-to-end latency. Beating S2M2ECG means a significant improvement on the morphology-class reward subscore at comparable latency.
Why not just…?
Why not just add landmark maps as extra channels to a linear-time model? This is the most natural competitor, and it is run directly as the landmark-as-channel ablation. Goodfellow et al. show such channels help a convolutional model. However, their evidence says nothing about fixed-memory recurrent models, whose problem is compression across cycles of varying length rather than finding the waves. If the channel variant matches the grid on morphology classes, our central claim is wrong. We would then report that the cheaper design suffices.
Why not just use a 1D ResNet, which is already linear time and good at local shape? This is a real threat for morphology classes specifically. The S2M2ECG authors themselves say heavy CNNs beat state-space models there. The comparison that settles it is the morphology subscore of the ResNet against our model at matched latency, plus a ResNet applied to the same beat grid. If the grid ResNet ties our model, the contribution is the coordinate system rather than the state-space scan. That would still be a useful result, and we would state it that way.
Why not just use the winning Wide and Deep Transformer on short clips, where attention is affordable? On 10–15 second clips its quadratic cost is modest, so we do not claim a speed win there. Instead, the proposal tests two things it cannot do cheaply. The first is scaling to 15–30 minute recordings in QT Database and MIT-BIH, where our cost should grow linearly and its cost quadratically. The second is the negative transfer found by the challenge meta-analysis: across 41 entries, handcrafted features showed no benefit (p = 0.983). That suggests appended features are fragile across hospitals, and our leave-one-source-out split measures exactly this fragility.
Why not just pretrain a large foundation model on MIMIC-IV-ECG and let it learn beat structure? The file hints that generic time-series foundation models miss phase-localized structure. ECG-MoE reports a 46.0% RR-interval error reduction over TEMPO once a periodic expert is added. Pretraining is also orthogonal to our claim, so as a secondary experiment we will pretrain both the raw-time and beat-grid encoders on MIMIC-IV-ECG. If pretraining erases the grid's advantage, the domain prior only matters in the data-limited regime.
Proposed Experiments
The primary benchmark is the PhysioNet 2020 data with leave-one-source-out evaluation over CPSC, INCART, PTB/PTB-XL and Georgia, scored with the official reward matrix. The challenge paper documented a roughly 10% drop in clinical score on unseen hospitals. Chapman-Shaoxing provides a secondary in-distribution check against S2M2ECG's reported 91.8% F1.
The first decisive check is distributional. Improvement over S2M2ECG should concentrate in the pre-registered morphology classes, with rhythm classes roughly unchanged. Uniform gains would suggest generic capacity rather than the mechanism we propose.
The second is robustness. We will add baseline wander, muscle noise and electrode motion at increasing strength to test records, and track detector sensitivity alongside the classification score. The model should degrade no faster than the raw-time baseline as detection fails, because masking and the raw-time branch are designed for exactly that case. MITDB 207 and similar records give a natural failure test.
The third is scaling. End-to-end CPU latency and memory, detector included, should grow linearly on QT Database and MIT-BIH records from 10 seconds to 30 minutes, while the Wide and Deep deep branch grows quadratically. We will report the length at which the Transformer exceeds a fixed per-record budget, taking the 2020 time-limit failures as the reason this matters.
The fourth is abstention. At 10% deferral, we compare the gain in reward score from column-scan uncertainty against softmax confidence. If none of the first three checks hold, the beat-coordinate idea should be abandoned in favour of whichever simpler baseline won.
References
- S2M2ECG: Spatio-temporal bi-directional State Space Model Enabled Multi-branch Mamba for ECG
- Rhythm Classification of 12-Lead ECGs Using Deep Neural Networks and Class-Activation Maps for Improved Explainability
- An Adaptive and Time-Efficient ECG R-Peak Detection Algorithm
- DermaMamba: A Dual-Branch Vision Mamba Architecture with Linear Complexity for Efficient Skin Lesion Classification
- Classification of 12-lead ECGs: the PhysioNet/Computing in Cardiology Challenge 2020
- DeepTag: inferring diagnoses from veterinary clinical notes
- A Wide and Deep Transformer Neural Network for 12-Lead ECG Classification
- Practical Lessons on 12-Lead ECG Classification: Meta-Analysis of Methods From PhysioNet/Computing in Cardiology Challenge 2020
- ECG-MoE: Mixture-of-Expert Electrocardiogram Foundation Model