Skip to content

Commit 590cda6

Browse files
authored
add flag for when missed peak is added
1 parent f6c21f2 commit 590cda6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

neurokit2/ecg/ecg_findpeaks.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,12 @@ def _ecg_findpeaks_hamilton(signal, sampling_rate=1000, **kwargs):
346346
- Hamilton, Open Source ECG Analysis Software Documentation, E.P.Limited, 2002.
347347
348348
"""
349-
diff = abs(np.diff(signal))
349+
import numpy as np
350+
import scipy.signal
351+
from collections import deque
352+
from bisect import insort
353+
354+
diff = np.abs(np.diff(signal))
350355

351356
b = np.ones(int(0.08 * sampling_rate))
352357
b = b / int(0.08 * sampling_rate)
@@ -382,13 +387,17 @@ def _ecg_findpeaks_hamilton(signal, sampling_rate=1000, **kwargs):
382387

383388
if RR_ave != 0.0 and QRS[-1] - QRS[-2] > 1.5 * RR_ave:
384389
missed_peaks = peaks[idx[-2] + 1 : idx[-1]]
390+
missed_peak_added = False
385391
for missed_peak in missed_peaks:
386392
if (
387393
missed_peak - peaks[idx[-2]] > int(0.36 * sampling_rate)
388394
and ma[missed_peak] > 0.5 * th
389395
):
390396
insort(QRS, missed_peak)
397+
missed_peak_added = True
391398
break
399+
if missed_peak_added:
400+
continue
392401

393402
if len(QRS) > 2:
394403
RR.append(QRS[-1] - QRS[-2])

0 commit comments

Comments
 (0)