Skip to content

Commit

Permalink
add flag for when missed peak is added
Browse files Browse the repository at this point in the history
  • Loading branch information
danibene authored Mar 11, 2024
1 parent f6c21f2 commit 590cda6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion neurokit2/ecg/ecg_findpeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,12 @@ def _ecg_findpeaks_hamilton(signal, sampling_rate=1000, **kwargs):
- Hamilton, Open Source ECG Analysis Software Documentation, E.P.Limited, 2002.
"""
diff = abs(np.diff(signal))
import numpy as np
import scipy.signal
from collections import deque
from bisect import insort

diff = np.abs(np.diff(signal))

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

if RR_ave != 0.0 and QRS[-1] - QRS[-2] > 1.5 * RR_ave:
missed_peaks = peaks[idx[-2] + 1 : idx[-1]]
missed_peak_added = False
for missed_peak in missed_peaks:
if (
missed_peak - peaks[idx[-2]] > int(0.36 * sampling_rate)
and ma[missed_peak] > 0.5 * th
):
insort(QRS, missed_peak)
missed_peak_added = True
break
if missed_peak_added:
continue

if len(QRS) > 2:
RR.append(QRS[-1] - QRS[-2])
Expand Down

0 comments on commit 590cda6

Please sign in to comment.