Skip to content

Commit

Permalink
Merge pull request neuropsychology#399 from jluby/fix_signal_zerocros…
Browse files Browse the repository at this point in the history
…sings

[Fix] Fix signal_zerocrossings indexing issues
  • Loading branch information
DominiqueMakowski authored Dec 30, 2020
2 parents 79e9c28 + 0af0cb9 commit b3fe1ec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions neurokit2/ecg/ecg_delineate.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _dwt_delineate_tp_peaks(
for idx_peak, idx_peak_nxt in zip(peaks[:-1], peaks[1:]):
correct_sign = dwt_local[idx_peak] > 0 and dwt_local[idx_peak_nxt] < 0 # pylint: disable=R1716
if correct_sign:
idx_zero = signal_zerocrossings(dwt_local[idx_peak:idx_peak_nxt])[0] + idx_peak
idx_zero = signal_zerocrossings(dwt_local[idx_peak:idx_peak_nxt+1])[0] + idx_peak
# This is the score assigned to each peak. The peak with the highest score will be
# selected.
score = ecg_local[idx_zero] - (float(idx_zero) / sampling_rate - (rt_duration - 0.5 * qrs_width))
Expand Down Expand Up @@ -303,7 +303,7 @@ def _dwt_delineate_tp_peaks(
for idx_peak, idx_peak_nxt in zip(peaks[:-1], peaks[1:]):
correct_sign = dwt_local[idx_peak] > 0 and dwt_local[idx_peak_nxt] < 0 # pylint: disable=R1716
if correct_sign:
idx_zero = signal_zerocrossings(dwt_local[idx_peak:idx_peak_nxt])[0] + idx_peak
idx_zero = signal_zerocrossings(dwt_local[idx_peak:idx_peak_nxt+1])[0] + idx_peak
# This is the score assigned to each peak. The peak with the highest score will be
# selected.
score = ecg_local[idx_zero] - abs(
Expand Down Expand Up @@ -669,7 +669,7 @@ def _find_tppeaks(ecg, keep_tp, sampling_rate=1000):
# near = (index_next - index_cur) < max_wv_peak_dist #limit 2
# if near and correct_sign:
if correct_sign:
index_zero_cr = signal_zerocrossings(cwtmatr[4, :][index_cur:index_next])[0] + index_cur
index_zero_cr = signal_zerocrossings(cwtmatr[4, :][index_cur:index_next+1])[0] + index_cur
nb_idx = int(max_search_duration * sampling_rate)
index_max = np.argmax(ecg[index_zero_cr - nb_idx : index_zero_cr + nb_idx]) + (index_zero_cr - nb_idx)
tppeaks.append(index_max)
Expand Down
2 changes: 1 addition & 1 deletion neurokit2/ecg/ecg_findpeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ def _ecg_findpeaks_WT(signal, sampling_rate=1000):
correct_sign = signal_1[index_cur] < 0 and signal_1[index_next] > 0 # pylint: disable=R1716
near = (index_next - index_cur) < max_R_peak_dist # limit 2
if near and correct_sign:
rpeaks.append(signal_zerocrossings(signal_1[index_cur:index_next])[0] + index_cur)
rpeaks.append(signal_zerocrossings(signal_1[index_cur:index_next+1])[0] + index_cur)

rpeaks = np.array(rpeaks, dtype="int")
return rpeaks
Expand Down

0 comments on commit b3fe1ec

Please sign in to comment.