Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from wfdb import processing


class test_processing:
class TestProcessing:
"""
Test processing functions
"""
Expand Down Expand Up @@ -62,6 +62,13 @@ def test_find_peaks_empty(self):
assert hp.shape == (0,)
assert sp.shape == (0,)

def test_find_local_peaks(self):
# the sample `radius` positions to the right is part of the window
x = np.array([0, 1, 2, 3, 2, 1, 0], dtype=float)
assert np.array_equal(processing.find_local_peaks(x, 1), [3])
x = np.array([0, 1, 3, 2, 10, 5, 1, 0], dtype=float)
assert np.array_equal(processing.find_local_peaks(x, 2), [4])

def test_gqrs(self):
record = wfdb.rdrecord(
"sample-data/100",
Expand Down Expand Up @@ -178,7 +185,7 @@ def test_correct_peaks(self):
assert np.array_equal(yz, expected_peaks)


class test_qrs:
class TestQrs:
"""
Testing QRS detectors
"""
Expand Down
16 changes: 1 addition & 15 deletions wfdb/processing/peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,8 @@ def find_local_peaks(sig, radius):
peak_inds = []

i = 0
while i < radius + 1:
if sig[i] == max(sig[: i + radius]):
peak_inds.append(i)
i += radius
else:
i += 1

while i < len(sig):
if sig[i] == max(sig[i - radius : i + radius]):
peak_inds.append(i)
i += radius
else:
i += 1

while i < len(sig):
if sig[i] == max(sig[i - radius :]):
if sig[i] == max(sig[max(0, i - radius) : i + radius + 1]):
peak_inds.append(i)
i += radius
else:
Expand Down