neuropsychology / NeuroKit.py

A Python Toolbox for Statistics and Neurophysiological Signal Processing (EEG, EDA, ECG, EMG...).
http://neurokit.rtfd.io
MIT License
365 stars 102 forks source link

ecg_process(): Sequence too short to compute heart rate - optimising for short signal #81

Open dicobrazz opened 6 years ago

dicobrazz commented 6 years ago

Hello,

We are trying to work with some of the researchers from a hospital and there signal samples are at about 2.4 seconds, which is too short. I modified the "interpolate" function and changed k to 2 in signal.py It made the signal run, but still gives ecg_process(): Sequence too short to compute heart rate and therefore, setting heart_rate to np.nan

How could be modified for a short signal? Thank you!

DominiqueMakowski commented 6 years ago

Hey @dicobrazz.

Short answer is, not really (to my knowledge) ^^. Within such time ranges, I expect you to have around 3 to 4 heart beats per epoch. Let's say 4 for the sake of illustration. Thus, you can only compute 3 different momentary heart rates (b1-b0, b2-b1...). Hence, while you could compute the average (of these several momentary hear rate values) over the whole window, computing the "continuous" heart rate is kind of complicated (and I believed not advised). Indeed, the rationale behind this artificial signal is that the momentary heart rate points (that differs at each new heartbeat) are the reflection of a smooth underlying process.

However, attempting at recovering this underlying process (i.e., the continuous and smooth change of heart rate) heavily rely on interpolation and filtering, which do not work well (and can lead to artefacts) for very short time periods.

Thus, depending on what you need this heart rate for, I would recommend 1) to use the average heart rate, or 2) use the momentary heart rates (made of 2 or 3 points). But again, it depends on what you want to do in the end.