Skip to content

Commit d515911

Browse files
committed
Add doc.
1 parent ddfac13 commit d515911

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
@@ -561,8 +561,8 @@ Input arguments:
561561
- ``window_size`` (required): The smoothing window width.
562562

563563

564-
GQRS detector
565-
~~~~~~~~~~~~~
564+
Peak detection
565+
~~~~~~~~~~~~~~
566566

567567
**gqrs_detect** - The GQRS detector function
568568

@@ -579,8 +579,7 @@ Example Usage:
579579
tf = 20000
580580
sig, fields = wfdb.srdsamp('sampledata/100', sampfrom=t0, sampto=tf, channels=[0])
581581
record = wfdb.rdsamp("sampledata/100", sampfrom=t0, sampto=tf, channels=[0], physical=False)
582-
583-
peak_indexes = wfdb.processing.gqrs_detect(x=x, freq=fields['fs'], gain=record.adcgain[0], adczero=record.adczero[0], threshold=1.0)
582+
peak_indexes = wfdb.processing.gqrs_detect(x=sig[:,0], freq=fields['fs'], gain=record.adcgain[0], adczero=record.adczero[0], threshold=1.0)
584583

585584
Input arguments:
586585

@@ -601,6 +600,40 @@ Input arguments:
601600
- ``QRSamin`` (default=130): Minimum QRS peak-to-peak amplitude, in microvolts.
602601

603602

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

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)