Skip to content

Commit 976b26c

Browse files
committed
Add doc.
1 parent e30c756 commit 976b26c

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

README.rst

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,8 @@ Input arguments:
558558
- ``window_size`` (required): The smoothing window width.
559559

560560

561-
GQRS detector
562-
~~~~~~~~~~~~~
561+
Peak detection
562+
~~~~~~~~~~~~~~
563563

564564
**gqrs_detect** - The GQRS detector function
565565

@@ -576,8 +576,7 @@ Example Usage:
576576
tf = 20000
577577
sig, fields = wfdb.srdsamp('sampledata/100', sampfrom=t0, sampto=tf, channels=[0])
578578
record = wfdb.rdsamp("sampledata/100", sampfrom=t0, sampto=tf, channels=[0], physical=False)
579-
580-
peak_indexes = wfdb.processing.gqrs_detect(x=x, freq=fields['fs'], gain=record.adcgain[0], adczero=record.adczero[0], threshold=1.0)
579+
peak_indexes = wfdb.processing.gqrs_detect(x=sig[:,0], freq=fields['fs'], gain=record.adcgain[0], adczero=record.adczero[0], threshold=1.0)
581580

582581
Input arguments:
583582

@@ -598,6 +597,40 @@ Input arguments:
598597
- ``QRSamin`` (default=130): Minimum QRS peak-to-peak amplitude, in microvolts.
599598

600599

600+
**correct_peaks** - A post-processing algorithm to correct peaks position.
601+
602+
See code comments for details about the algorithm.
603+
604+
605+
::
606+
607+
correct_peaks(x, peaks_indexes, min_gap, max_gap, smooth_window)
608+
609+
Example Usage:
610+
611+
::
612+
613+
import wfdb
614+
t0 = 10000
615+
tf = 20000
616+
sig, fields = wfdb.srdsamp('sampledata/100', sampfrom=t0, sampto=tf, channels=[0])
617+
record = wfdb.rdsamp("sampledata/100", sampfrom=t0, sampto=tf, channels=[0], physical=False)
618+
peak_indexes = wfdb.processing.gqrs_detect(x=sig[:,0], freq=fields['fs'], gain=record.adcgain[0], adczero=record.adczero[0], threshold=1.0)
619+
fs = fields['fs']
620+
min_bpm = 10
621+
max_bpm = 350
622+
min_gap = fs*60/min_bpm
623+
max_gap = fs*60/max_bpm
624+
y_idxs = wfdb.processing.correct_peaks(x=sig[:,0], peak_indexes=peak_indexes, min_gap=min_gap, max_gap=max_gap, smooth_window=150)
625+
626+
Input arguments:
627+
peaks_indexes, min_gap, max_gap, smooth_window
628+
- ``x`` (required): The signal.
629+
- ``peaks_indexes`` (required): The location of the peaks.
630+
- ``min_gap`` (required): The minimum gap in samples between two peaks.
631+
- ``max_gap`` (required): The maximum gap in samples between two peaks.
632+
- ``smooth_window`` (required): The size of the smoothing window.
633+
601634
Based on the original WFDB software package specifications
602635
----------------------------------------------------------
603636

tests/test_processing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def test_7(self):
6767
sig, fields = wfdb.srdsamp('sampledata/100', channels = [0, 1])
6868
ann = wfdb.rdann('sampledata/100', 'atr')
6969
fs = fields['fs']
70-
trained_fs = 360
7170
min_bpm = 10
7271
max_bpm = 350
7372
min_gap = fs*60/min_bpm

wfdb/processing/peaks.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def find_peaks(x):
7676
return hard_peaks, soft_peaks
7777

7878

79-
def correct_peaks(signal, peaks_indexes, min_gap, max_gap, smooth_window):
80-
N = signal.shape[0]
79+
def correct_peaks(x, peaks_indexes, min_gap, max_gap, smooth_window):
80+
N = x.shape[0]
8181

8282
rpeaks = numpy.zeros(N)
8383
rpeaks[peaks_indexes] = 1.0
@@ -97,23 +97,23 @@ def correct_peaks(signal, peaks_indexes, min_gap, max_gap, smooth_window):
9797
if rpeaks[i] == 1:
9898
tmp_idx = i
9999

100-
smoothed = smooth(signal, smooth_window)
100+
smoothed = smooth(x, smooth_window)
101101

102102
# Compute signal's peaks
103-
hard_peaks, soft_peaks = find_peaks(x=signal)
103+
hard_peaks, soft_peaks = find_peaks(x=x)
104104
all_peak_idxs = numpy.concatenate((hard_peaks, soft_peaks)).astype('int64')
105105

106106
# Replace each range of ones by the index of the best value in it
107107
tmp = set()
108108
for rp_range in rpeaks_ranges:
109109
r = numpy.arange(rp_range[0], rp_range[1]+1, dtype='int64')
110-
vals = signal[r]
110+
vals = x[r]
111111
smoothed_vals = smoothed[r]
112112
p = r[numpy.argmax(numpy.absolute(numpy.asarray(vals)-smoothed_vals))]
113113
tmp.add(p)
114114

115115
# Replace all peaks by the peak within x-max_gap < x < x+max_gap which have the bigget distance from smooth curve
116-
dist = numpy.absolute(signal-smoothed) # Peak distance from the smoothed mean
116+
dist = numpy.absolute(x-smoothed) # Peak distance from the smoothed mean
117117
rpeaks_indexes = set()
118118
for p in tmp:
119119
a = max(0, p-max_gap)
@@ -135,7 +135,7 @@ def correct_peaks(signal, peaks_indexes, min_gap, max_gap, smooth_window):
135135
if len(r) == 1:
136136
continue
137137
rr = r.astype('int64')
138-
vals = signal[rr]
138+
vals = x[rr]
139139
smoo = smoothed[rr]
140140
the_one = r[numpy.argmax(numpy.absolute(vals-smoo))]
141141
for i in r:

0 commit comments

Comments
 (0)