I wanted to bring to light an observed discrepancy and confirm whether I am using pyhrv functions correctly.
I have an ECG signal and heart rate recording captured synchronously at the same sampling frequency, and I want to use pyhrv to calculate HRV parameters from the ECG signal in a 5-minute moving window with a step size of 5 seconds. I was following the tutorial (Getting Started; 1.2 R-Peak Detection with BioSPPy) to begin by calculating the normal-to-normal interval of the signal:
# exact code from the tutorial, except for imports
signal = read_input_signal(file_pathway) # is read as a pd.DataFrame and one column is the ECG waveform, cast from a Series to a NumPy array
filt_signal, rpeaks = biosppy.signals.ecg.ecg(signal, sampling_rate=srate, show=False)[1:3]
nni = tools.nn_intervals(rpeaks)
When I followed this structure and calculate heart rate parameters with nni (i.e. hr = pyhrv.time_domain.hr_parameters(nni=nni)) I get heart rate values between 109 and 220 bpm across the time series with my sliding window, which stands out because the biosppy.tools.get_heart_rate(beats=rpeaks) and my recorded heart rate both depict a heart rate between 50 and 120 bpm across the same time series and sliding window.
I inspected the Github for biosppy.signals.ecg.ecg() and pyhrv.tools.nn_intervals() for in-line and function comments, and I believe to have found the issue - the rpeaks output from ecg() is "R-peak location indices" while the input rpeaks for nn_intervals() is expected to be "R-peak times in [ms] or [s]". With this in mind, I implemented the following change to the code:
signal = read_input_signal(file_pathway) # is read as a pd.DataFrame and one column is the ECG waveform, cast from a Series to a NumPy array
ref_time, filt_signal, rpeaks = biosppy.signals.ecg.ecg(signal, sampling_rate=srate, show=False)[:3]
rpeaks = ref_time[rpeaks] # redefine rpeaks to be the occurrence times of the r-peaks from the calculated reference time
nni = tools.nn_intervals(rpeaks)
This redefines rpeaks to be in units of seconds and yields the expected heart rate range that agrees with biosppy and my data's heart rate measurement, but I wanted to confirm whether this deviation is appropriate and if I am using the packages correctly. I intend to calculate other HRV for my project, but this was the best value to validate with as I was learning the package.
Thank you!
I wanted to bring to light an observed discrepancy and confirm whether I am using pyhrv functions correctly.
I have an ECG signal and heart rate recording captured synchronously at the same sampling frequency, and I want to use pyhrv to calculate HRV parameters from the ECG signal in a 5-minute moving window with a step size of 5 seconds. I was following the tutorial (Getting Started; 1.2 R-Peak Detection with BioSPPy) to begin by calculating the normal-to-normal interval of the signal:
When I followed this structure and calculate heart rate parameters with
nni(i.e.hr = pyhrv.time_domain.hr_parameters(nni=nni)) I get heart rate values between 109 and 220 bpm across the time series with my sliding window, which stands out because thebiosppy.tools.get_heart_rate(beats=rpeaks)and my recorded heart rate both depict a heart rate between 50 and 120 bpm across the same time series and sliding window.I inspected the Github for biosppy.signals.ecg.ecg() and pyhrv.tools.nn_intervals() for in-line and function comments, and I believe to have found the issue - the
rpeaksoutput fromecg()is "R-peak location indices" while the inputrpeaksfornn_intervals()is expected to be "R-peak times in [ms] or [s]". With this in mind, I implemented the following change to the code:This redefines
rpeaksto be in units of seconds and yields the expected heart rate range that agrees with biosppy and my data's heart rate measurement, but I wanted to confirm whether this deviation is appropriate and if I am using the packages correctly. I intend to calculate other HRV for my project, but this was the best value to validate with as I was learning the package.Thank you!