Skip to content

ECG peak detection gets stuck when data is very noisy #141

Description

@raphaelvallat

Hi,

This is an issue I have encountered a few times already — when the ECG data is very noisy for either part of or most of the recording, the detect_heartbeats function just gets stuck forever. This is problematic when you run peak detection across hundreds of participants and cannot visually check each recording.

To reproduce the error:

Download the EDF file with 8 hours ECG: https://drive.google.com/file/d/1ReYlFPAd3-dYk0C2WF7nDRQS3MxE2lyE/view?usp=share_link

import mne
from sleepecg import detect_heartbeats

# Load ECG
raw = mne.io.read_raw_edf("original_ecg.EDF", preload=True, verbose=False)
ecg = raw.get_data(units="uV")[0]
sf = raw.info["sfreq"]# Load ECG

# Peak detection
detect_heartbeats(ecg, sf) # gets stuck

In that case, the ECG data is so bad that honestly it would be better not to attempt the peak detection at all...!

Potential solutions:

  1. Modification of the algorithm to avoid getting stuck when no peak is found?
  2. Pre-screening of the ECG signal quality — if the data is very noisy then the detection is skipped and an empty array is returned instead? For example we could use some kind of ECG signal quality metric (see method="zhao2018" in https://neuropsychology.github.io/NeuroKit/functions/ecg.html#ecg-quality)

Thanks,
Raphael

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions