neuropsychology / NeuroKit

NeuroKit2: The Python Toolbox for Neurophysiological Signal Processing
https://neuropsychology.github.io/NeuroKit
MIT License
1.58k stars 420 forks source link

ECG peak detection robust to signal inversion #558

Closed raphaelvallat closed 2 years ago

raphaelvallat commented 3 years ago

Question and context

Hi here!

Great work on the package 👏 👏

I am analyzing a large database of ECG recordings (n=2000+) and I suspect that for some of those (but not all), the ECG data is inverted. I do not have the time to do a manual check of all the files. My question is therefore whether there is a preferred method that I should use in ecg_clean and ecg_peaks that will be robust to such polarity inversion. I have been using the default method ("neurokit") and it seems to be working quite well, but maybe there's a better alternative.

PS: I think this is related to https://github.com/neuropsychology/NeuroKit/issues/368.

Thanks for your help! Raphael

DominiqueMakowski commented 3 years ago

Yo! I thought about this issue today and I am tempted to think that the best way of addressing that is to, rather than having a method of peak detection robust enough to inversions (at the probable cost of accuracy), would be to detect the inverted signals, re-invert them and then detect peaks normally.

Now the problem is how to detect possibly inverted ECG signals, as it doesn't seem super straightforward from basic descriptive features like SD, skewness or average (based on my quick checks). Maybe it could work with nk.ecg_quality(ecg, method="zhao2018") (https://github.com/neuropsychology/NeuroKit/blob/master/neurokit2/ecg/ecg_quality.py#L26), which might be sensitive to inverted signals?

But in general I think if you manage to find a few of these inverted signals manually, you could compare their characteristics with a normal signal, and try to find a way of detecting them in an automated fashion, so that you can re-revert them and fully benefit from advanced peak detections for normal signals

raphaelvallat commented 3 years ago

@DominiqueMakowski! I agree that this is probably the best approach. I'll run some tests on my data. Thanks!

stale[bot] commented 2 years ago

This issue has been automatically marked as inactive because it has not had recent activity. It will eventually be closed if no further activity occurs.

stale[bot] commented 2 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

DominiqueMakowski commented 2 years ago

Did you have any luck with that in the end?

raphaelvallat commented 2 years ago

Nope, ended up working on other projects and never had the time to finish this. Feel free to close the issue!

DominiqueMakowski commented 2 years ago

FYI @raphaelvallat, @danibene implemented a new ecg_invert() function that detects whether inversion is needed (and inverts it if need be). Closing this then :)