1
1
import copy
2
2
import numpy as np
3
+
3
4
from scipy import signal
4
5
from sklearn .preprocessing import normalize
5
6
@@ -28,7 +29,8 @@ class XQRS(object):
28
29
- Conduct learning if specified, to initialize running
29
30
parameters of noise and qrs amplitudes, the qrs detection
30
31
threshold, and recent rr intervals. If learning is unspecified
31
- or fails, use default parameters.
32
+ or fails, use default parameters. See the docstring for the
33
+ `_learn_init_params` method of this class for details.
32
34
- Run the main detection. Iterate through the local maxima of
33
35
the mwi signal. For each local maxima:
34
36
@@ -221,12 +223,13 @@ def _learn_init_params(self, n_calib_beats=8):
221
223
# Find the local peaks of the signal.
222
224
peak_inds_f = find_local_peaks (self .sig_f , self .qrs_radius )
223
225
224
- peak_inds_f_r = np .where (peak_inds_f > self .qrs_width )[0 ]
225
- peak_inds_f_l = np .where (peak_inds_f <= self .sig_len - self .qrs_width )[0 ]
226
+ # Peak numbers at least qrs_width away from signal boundaries
227
+ peak_nums_r = np .where (peak_inds_f > self .qrs_width )[0 ]
228
+ peak_nums_l = np .where (peak_inds_f <= self .sig_len - self .qrs_width )[0 ]
226
229
227
230
# Skip if no peaks in range
228
- if (not peak_inds_f .size or not peak_inds_f_r .size
229
- or not peak_inds_f_l .size ):
231
+ if (not peak_inds_f .size or not peak_nums_r .size
232
+ or not peak_nums_l .size ):
230
233
if self .verbose :
231
234
print ('Failed to find %d beats during learning.'
232
235
% n_calib_beats )
@@ -235,7 +238,7 @@ def _learn_init_params(self, n_calib_beats=8):
235
238
236
239
# Go through the peaks and find qrs peaks and noise peaks.
237
240
# only inspect peaks with at least qrs_radius around either side
238
- for peak_num in range (peak_inds_f_r [0 ], peak_inds_f_l [ 0 ]):
241
+ for peak_num in range (peak_nums_r [0 ], peak_nums_l [ - 1 ]):
239
242
i = peak_inds_f [peak_num ]
240
243
# Calculate cross-correlation between the filtered signal
241
244
# segment and a ricker wavelet
@@ -291,6 +294,7 @@ def _learn_init_params(self, n_calib_beats=8):
291
294
noise_amp_recent = noise_amp ,
292
295
rr_recent = rr_recent ,
293
296
last_qrs_ind = last_qrs_ind )
297
+ self .learned_init_params = True
294
298
295
299
# Failed to find enough calibration beats. Use default values.
296
300
else :
@@ -348,6 +352,8 @@ def _set_default_init_params(self):
348
352
rr_recent = rr_recent ,
349
353
last_qrs_ind = last_qrs_ind )
350
354
355
+ self .learned_init_params = False
356
+
351
357
def _is_qrs (self , peak_num , backsearch = False ):
352
358
"""
353
359
Check whether a peak is a qrs complex. It is classified as qrs
0 commit comments