NeuroKit
NeuroKit copied to clipboard
"Neurokit" R-peak detection in ECG depends on sampling frequency
Have found a problematic issue with R peaks detection by neurokit method: it is sensitive to sampling frequency.
I have a 1000 Hz sampled ECG, where nk.ecg_peaks failed to find R-peaks.
But when I downsample it to 100 Hz, the R peaks were surprisingly found correctly!!!
I dived deeper and have found the reason.
The function _ecg_findpeaks_neurokit() have comment at the start:
The
signal
must be the highpass-filtered raw ECG with a lowcut of .5 Hz.
So, such signal I've used as input. The algorithm then calculates the abs value of signal derivative and uses 2 smoothing widows. The result of 2nd window is used as a threshold for the result of 1st window. Here is the source of problem. The derivative amplifies the hi-freq noise in the signal (even it is quite small), and the downsampling works as a low-pass filter (blue line):
After that is not surprising, that smoothed absolute derivatives have quite different values and in 1000 Hz case the threshold is much higher (blue+orange = 1000Hz, green+red=100Hz):
The obvious solution is low-pass filter of the input signal (to what frequency?) But may be there is better solution?