paulvangentcom / heartrate_analysis_python

Python Heart Rate Analysis Package, for both PPG and ECG signals
MIT License
930 stars 321 forks source link

Issue with hp.enhance_ecg_peaks #79

Closed LeilaNS closed 1 year ago

LeilaNS commented 2 years ago

Thanks for this useful library! I'm using the ECG recorded during MEG scan.


sample_rate=500
filtered = hp.enhance_ecg_peaks(hp.scale_data(my_ecg[1]), sample_rate, 
                                aggregation='median', iterations=6)
wd, m = hp.process(hp.scale_data(filtered), sample_rate)
for measure in m.keys():
   print('%s: %f' %(measure, m[measure]))
`

And I got the Run Time Warning:

bpm: nan
ibi: nan
sdnn: nan
sdsd: nan
rmssd: nan
pnn20: nan
pnn50: nan
hr_mad: nan
sd1: nan
sd2: nan
s: nan
sd1/sd2: nan
breathingrate: nan
C:\Users\Anaconda3\envs\mne\lib\site-packages\numpy\core\fromnumeric.py:3372: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
C:\Users\Anaconda3\envs\mne\lib\site-packages\numpy\core\_methods.py:233: RuntimeWarning: Degrees of freedom <= 0 for slice
  ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
C:\Users\Anaconda3\envs\mne\lib\site-packages\numpy\ma\core.py:5243: RuntimeWarning: Mean of empty slice.
  result = super(MaskedArray, self).mean(axis=axis,
C:\Users\Anaconda3\envs\mne\lib\site-packages\numpy\core\fromnumeric.py:3621: RuntimeWarning: Degrees of freedom <= 0 for slice
  return _methods._var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
<ipython-input-193-9fd471b49f5b>:13: UserWarning: Warning: converting a masked element to nan.
  print('%s: %f' %(measure, m[measure]))`

But if I put the iteration = 4 with the same code : No Warning: and the output will be correct :

filtered = hp.enhance_ecg_peaks(hp.scale_data(my_ecg[1]), sample_rate, 
                                aggregation='median', iterations=4)
wd, m = hp.process(hp.scale_data(filtered), sample_rate)
for measure in m.keys():
   print('%s: %f' %(measure, m[measure]))

Output :

bpm: 62.735815
ibi: 956.391489
sdnn: 30.573245
sdsd: 16.366074
rmssd: 27.733243
pnn20: 0.446903
pnn50: 0.039823
hr_mad: 18.000000
sd1: 19.607452
sd2: 38.200466
s: 2353.096297
sd1/sd2: 0.513278
breathingrate: 0.333333

Do you know why this happend? How can I fixed this Issue? Best

paulvangentcom commented 2 years ago

Apologies for my late reaction.

Can you share with me the data file that caused the issue? I'll have a look what's happening

paulvangentcom commented 1 year ago

Closing for now, feel free to re-open if you come across this again and are still having issues