neuropsychology / NeuroKit

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

hrv_time and ecg_intervalrelated functions shows a disparity while computing HRV_MeanNN and a few more time domain parameters #767

Closed rahulvenugopal closed 1 year ago

rahulvenugopal commented 1 year ago

Describe the bug

To Reproduce Here is the sample script to reproduce the above situation

# Load the library
import neurokit2 as nk

# Simulate the data
ecg = nk.ecg_simulate(duration=30, sampling_rate=200, heart_rate=70)

# Clean the ECG trace and see the data
signals, info1 = nk.ecg_process(ecg,
                               sampling_rate = 200)

# Find peaks
peaks, info2 = nk.ecg_peaks(signals["ECG_Clean"],
                           sampling_rate = 200)

# Time domain and non linear HRV parameters
hrv_time = nk.hrv_time(peaks, sampling_rate = 200, show=True)

hrv_non = nk.hrv_nonlinear(info2, sampling_rate = 200, show=True)

# All HRV parameters using ecg_intervalrelated function
all_params_hrv = nk.ecg_intervalrelated(signals)

Screenshots params_discrepancy

System Specifications

- OS: Windows (WindowsPE 64bit) 
- Python: 3.9.10 
- NeuroKit2: 0.1.7 

- NumPy: 1.21.5 
- Pandas: 1.4.1 
- SciPy: 1.8.0 
- sklearn: 1.0.2 
- matplotlib: 3.5.1

I updated neurokit2 to latest version and checked, issue persists. Clearly the ecg_intervalrelated function outputs incorrect parameters!

welcome[bot] commented 1 year ago

Hi 👋 Thanks for reaching out and opening your first issue here! We'll try to come back to you as soon as possible. ❤️ kenobi

DominiqueMakowski commented 1 year ago

Hi, if you add sampling_rate = 200 to nk.ecg_intervalrelated(signals) it should work as expected.