All research

Physiological signal processing · 2023–2024

Deep learning for 12-lead ECG restoration and R-peak detection during MRI

Deep learning methods that detect heartbeats and restore 12-lead ECG distorted by the magnetohydrodynamic effect in 1 T, 3 T and 7 T MRI scanners.

Qatar National Research Fund NPRP12S-0227-190164 · Prince Sattam Bin Abdulaziz University project PSAU/2024/R/1445 · Qatar University QUST-1-CENG-2023941

Three-phase framework diagram. Phase 1 segments QRS pulse trains from distorted ECG. Phase 2 uses the pulse trains to guide unpaired restoration with a 1D CycleGAN called MHDGAN. Phase 3 trains MHD2ECGNet for general restoration of all 12 leads.
Figure 2 from Mahmud et al. (2024). QRS pulse-train segmentation (Phase 1), QRS-guided unpaired restoration with MHDGAN (Phase 2) and general 12-lead restoration with MHD2ECGNet (Phase 3).View full-size figureSource article© 2024 Elsevier Ltd · author reuse

Approach

Can deep learning recover ECG morphology and heartbeat timing when an MRI magnetic field distorts the signal?

Inside an MRI scanner, blood flowing through the static magnetic field creates a magnetohydrodynamic voltage that overlaps the ECG. This can hide important waveform features and make cardiac gating and patient monitoring difficult. The work began with accurate R-peak detection, then developed a three-phase framework that uses QRS guidance, unpaired restoration and a general 12-lead model.

  1. Locate QRS complexes
  2. Restore each ECG lead
  3. Generalise to all 12 leads

Detecting R-peaks in ECG distorted inside MRI

Bioengineering · 2023

Accurate R-peaks are needed to synchronise cardiac MRI with the heartbeat, but the magnetohydrodynamic (MHD) effect distorts the ECG inside the scanner. This study used public 3 T and 7 T recordings and treated R-peak detection as a 1D segmentation task.

Self-Attention MHDNet converts three ECG channels into a pulse map of R-peak locations. It combines Self-ONN layers with attention blocks in an encoder–decoder network and was evaluated with five-fold cross-validation that kept each person’s data in one fold.

F1 score at 3 T
99.76%
F1 score at 7 T
99.82%
R-peak detection and segmentation results from M.H. Chowdhury et al. (2023).
RecallPrecisionF1 scoreDice
3 T99.83%99.68%99.76%99.01%
7 T99.87%99.78%99.82%98.36%
Encoder–decoder network taking a three-channel distorted ECG and producing a map of R-peak pulses. Self-ONN layers, pooling, upsampling, concatenation and attention blocks are marked.
Figure 5 from M.H. Chowdhury et al. (2023). The Self-Attention MHDNet architecture.View full-size figureSource articleCC BY 4.0

Phase 1: locating heartbeats from distorted 12-lead ECG

Engineering Applications of Artificial Intelligence · 2024

The restoration study used a public PhysioNet dataset from 23 healthy volunteers across 29 sessions in 1 T open-bore and 3 T and 7 T closed-bore scanners. The first phase turned distorted 12-lead ECG into QRS pulse trains that could guide restoration.

Five segmentation networks were compared with session-independent five-fold cross-validation on 15 sessions from nine people. UNet3+ performed best and found 10,776 of 10,780 annotated R-peaks within ±75 ms. It also performed well on the 1 T session after training on 3 T and 7 T data.

R-peak recall
99.96%
R-peak F1 score
98.45%
Missed R-peaks out of 10,780
4
R-peak detection with UNet3+, from Table 5 of Mahmud et al. (2024).
PrecisionRecallF1 score
All scanners96.98%99.96%98.45%
1 T98.88%100%99.44%
3 T97.72%99.98%98.84%
7 T94.91%99.93%97.36%
Three examples showing distorted lead II ECG above matching reference and predicted QRS pulse trains from 1 T and 3 T recordings.
Figure 5 from Mahmud et al. (2024), cropped to examples a–c. Distorted lead II ECG with reference and predicted QRS pulse trains.View full-size figureSource article© 2024 Elsevier Ltd · author reuse

Phase 2: unpaired restoration with MHDGAN

QRS-guided 1D-CycleGAN

A clean ECG cannot be recorded at the same moment as a distorted one because the scanner’s static field is always present. MHDGAN therefore learned from unpaired clean and distorted ECG from the same sessions. An inverted QRS pulse train was supplied with each distorted signal to keep the restored heartbeats aligned.

Separate models were trained for each of the 12 leads and two groups of body orientation, giving 24 models. Evaluation used 2,389 segments from 10 sessions in two session-independent folds. Spectral agreement with clean ECG rose from 92.68% to 99.50%, and spectral error fell from 0.0524 to 0.0310.

Spectral correlation improvement
92.56%
Spectral correlation after restoration
99.50%
Lead and orientation models
24
Spectral performance of MHDGAN against clean ECG, from Table 3 of Mahmud et al. (2024).
BeforeAfterImprovementSpectral error
All data92.68%99.50%92.56%0.0524 → 0.0310
1 T94.32%98.31%58.79%0.0477 → 0.0379
3 T93.07%99.34%88.79%0.0505 → 0.0314
7 T92.07%99.46%92.71%0.0541 → 0.0318
Head-first supine91.68%99.30%90.54%0.0450 → 0.0261
Feet-first supine or head-first prone93.68%99.69%94.58%0.0599 → 0.0358
Three examples for ECG leads I, II and III. Each shows an unpaired clean ECG, the distorted ECG, an inverse QRS pulse train and the restored QRS-aligned ECG.
Figure 7 from Mahmud et al. (2024), cropped to examples a–c. Clean, distorted and restored ECG with the QRS guide signal.View full-size figureSource article© 2024 Elsevier Ltd · author reuse
Power spectral density plot from 0 to 40 Hz comparing clean ECG, distorted ECG and ECG restored in Phases 2 and 3. The distorted ECG departs from the clean spectrum, with a bump at low frequencies, while the restored signals follow the clean spectrum more closely.
Figure 6 from Mahmud et al. (2024). Power spectral density of the clean, distorted and restored ECG.View full-size figureSource article© 2024 Elsevier Ltd · author reuse

Phase 3: one model for all 12 leads

Supervised 1D segmentation

Running 24 separate models is impractical during a scan, especially when patient orientation changes. Phase 3 used the aligned MHDGAN outputs as training targets for one network that restores all 12 leads together, without needing a QRS input or separate orientation models.

MHD2ECGNet combines a nested UNet++ structure with recurrent residual units and modified guided attention. It has 2.647 million parameters, compared with 3.936 million across the 24 MHDGAN generators, and it gave the strongest results among the six compared networks.

Spectral correlation improvement
77.64%
Correlation with Phase 2 output
90.14%
Model for all 12 leads
1
General 12-lead restoration compared with the Phase 2 output, from Table 4 of Mahmud et al. (2024).
CorrelationMean absolute errorSpectral improvement
MHD2ECGNet90.14%0.07677.64%
UNet++90.03%0.07774.46%
UNet89.85%0.07866.66%
Attention-UNet89.82%0.07864.11%
UNet3+87.96%0.08239.46%
MultiResUNet87.77%0.08232.63%
Nested MHD2ECGNet architecture with encoder and decoder nodes, modified guided attention blocks and deep supervision, beside an enlarged recurrent residual unit.
Figure 4 from Mahmud et al. (2024), cropped to panels a and b. (a) MHD2ECGNet and (b) its recurrent residual unit.View full-size figureSource article© 2024 Elsevier Ltd · author reuse
Distorted ECG, Phase 2 restored ECG and Phase 3 restored ECG for leads I, II, III and aVR from a 3 tesla recording. Both restored signals show clearer heartbeat patterns.
Figure 10 from Mahmud et al. (2024), cropped to four leads. Distorted ECG with the Phase 2 and Phase 3 restorations from a 3 T session.View full-size figureSource article© 2024 Elsevier Ltd · author reuse

Checking R-peaks, heart rate and variability

Comparison with expert annotations

Restored signals were assessed with an independent R-peak detector and compared with expert annotations. Mean heart rate was 62.40 beats per minute in the reference, 62.63 after MHDGAN and 63.26 after MHD2ECGNet. Heart rate variability (SDNN) was 119.76 ms in the reference, 120.54 ms after MHDGAN and 127.98 ms after MHD2ECGNet.

MHDGAN R-peak F1 score
96.01%
MHD2ECGNet R-peak F1 score
94.85%
Heart-rate correlation with MHDGAN
0.93
R-peak detection after restoration, from Table 5 of Mahmud et al. (2024).
PrecisionRecallF1 score
MHDGAN, all leads98.14%94.12%96.01%
MHDGAN, lead II99.98%98.89%99.43%
MHD2ECGNet, all leads97.12%92.43%94.85%
MHD2ECGNet, lead II99.40%98.06%98.73%
Line plots of heart rate and heart rate variability across recording sessions for Phase 2 and Phase 3, beside scatter plots of estimated against reference heart rate with correlations of 0.93 and 0.80.
Figure 12 from Mahmud et al. (2024). Heart rate and variability trends, with heart-rate correlation for Phases 2 and 3.View full-size figureSource article© 2024 Elsevier Ltd · author reuse

My contribution

For the 12-lead restoration study, I led conceptualisation, data curation, methodology and software development, formal analysis, experiments and manuscript preparation. For Self-Attention MHDNet, I contributed to the investigation, methodology, software, validation and manuscript drafting and revision.

Study scope

The recordings came from young healthy volunteers while the scanners were not acquiring images, so gradient and radio-frequency artefacts were not addressed. Only one 1 T session was available, and low-amplitude P and T waves remained harder to restore. Studies with patients and active MRI scans are needed before clinical use.