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

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.
- Locate QRS complexes
- Restore each ECG lead
- 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%
| Recall | Precision | F1 score | Dice | |
|---|---|---|---|---|
| 3 T | 99.83% | 99.68% | 99.76% | 99.01% |
| 7 T | 99.87% | 99.78% | 99.82% | 98.36% |

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
| Precision | Recall | F1 score | |
|---|---|---|---|
| All scanners | 96.98% | 99.96% | 98.45% |
| 1 T | 98.88% | 100% | 99.44% |
| 3 T | 97.72% | 99.98% | 98.84% |
| 7 T | 94.91% | 99.93% | 97.36% |

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
| Before | After | Improvement | Spectral error | |
|---|---|---|---|---|
| All data | 92.68% | 99.50% | 92.56% | 0.0524 → 0.0310 |
| 1 T | 94.32% | 98.31% | 58.79% | 0.0477 → 0.0379 |
| 3 T | 93.07% | 99.34% | 88.79% | 0.0505 → 0.0314 |
| 7 T | 92.07% | 99.46% | 92.71% | 0.0541 → 0.0318 |
| Head-first supine | 91.68% | 99.30% | 90.54% | 0.0450 → 0.0261 |
| Feet-first supine or head-first prone | 93.68% | 99.69% | 94.58% | 0.0599 → 0.0358 |


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
| Correlation | Mean absolute error | Spectral improvement | |
|---|---|---|---|
| MHD2ECGNet | 90.14% | 0.076 | 77.64% |
| UNet++ | 90.03% | 0.077 | 74.46% |
| UNet | 89.85% | 0.078 | 66.66% |
| Attention-UNet | 89.82% | 0.078 | 64.11% |
| UNet3+ | 87.96% | 0.082 | 39.46% |
| MultiResUNet | 87.77% | 0.082 | 32.63% |


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
| Precision | Recall | F1 score | |
|---|---|---|---|
| MHDGAN, all leads | 98.14% | 94.12% | 96.01% |
| MHDGAN, lead II | 99.98% | 98.89% | 99.43% |
| MHD2ECGNet, all leads | 97.12% | 92.43% | 94.85% |
| MHD2ECGNet, lead II | 99.40% | 98.06% | 98.73% |

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.
Publications
- Restoration of magnetohydrodynamic-corrupted 12-lead electrocardiogram to enhance cardiac monitoring during magnetic resonance imagingEngineering Applications of Artificial Intelligence · 2024
- Self-Attention MHDNet: A Novel Deep Learning Model for the Detection of R-Peaks in the Electrocardiogram Signals Corrupted with Magnetohydrodynamic EffectBioengineering · 2023