systole.detection.ecg_peaks#
- systole.detection.ecg_peaks(signal: Union[List, ndarray, Series], sfreq: int = 1000, new_sfreq: int = 1000, method: str = 'sleepecg', find_local: bool = False, win_size: float = 0.1, clean_nan: bool = False, verbose: bool = False) Tuple[ndarray, ndarray] [source]#
A simple wrapper for many popular R peaks detectors algorithms.
This function calls methods from py-ecg-detectors [1].
- Parameters
- signal
The raw ECG signal.
- sfreq
The sampling frequency. Default is set to 1000 Hz.
- new_sfreq
The new sampling frequency. Defaults to 1000 Hz.
- method
The method used. Can be one of the following: ‘sleepecg’, ‘hamilton’, ‘christov’, ‘engelse-zeelenberg’, ‘pan-tompkins’, ‘moving-average’.
- find_local
If True, will use peaks indexs to search for local peaks given the window size (win_size).
- win_size
Size of the time window used by
systole.utils.to_neighbour()
expressed in seconds. Defaut set to 0.1.- clean_nan
If True, will interpolate NaNs values if any before any other operation. Defaults to False.
- verbose
Control function verbosity. Defaults to False (do not print processing steps).
- Returns
- resampled_signal
Signal resampled to the new_sfreq frequency.
- peaks
Boolean array corresponding to the R peaks detection.
- Raises
- ValueError
- If method is not one of the following: ‘hamilton’, ‘christov’,
‘engelse-zeelenberg’, ‘pan-tompkins’, ‘moving-average’
Notes
Warning
This function will resample the signal to 1000 Hz.
References
- 1
Howell, L., Porr, B. Popular ECG R peak detectors written in python. DOI: 10.5281/zenodo.3353396
Examples
>>> from systole import import_dataset >>> from systole.detection import ecg_peaks >>> signal_df = import_dataset()[:20*2000] >>> signal, peaks = ecg_peaks(signal_df.ecg.to_numpy(), method='hamilton', >>> sfreq=2000, find_local=True) >>> print(f'{sum(peaks)} peaks detected.') 24 peaks detected.