@@ -4097,8 +4097,8 @@ def wfdbtime(record_name, input_times, pn_dir=None):
4097
4097
4098
4098
4099
4099
def sigavg (record_name , extension , pn_dir = None , return_df = False ,
4100
- start_range = - 0.05 , stop_range = 0.05 , time_start = 0 , time_stop = - 1 ,
4101
- verbose = False ):
4100
+ start_range = - 0.05 , stop_range = 0.05 , ann_type = 'all' , start_time = 0 ,
4101
+ stop_time = - 1 , verbose = False ):
4102
4102
"""
4103
4103
A common problem in signal processing is to determine the shape of a
4104
4104
recurring waveform in the presence of noise. If the waveform recurs
@@ -4139,10 +4139,14 @@ def sigavg(record_name, extension, pn_dir=None, return_df=False,
4139
4139
Set the measurement window relative to QRS annotations. Negative
4140
4140
values correspond to offsets that precede the annotations. The default
4141
4141
is 0.05 seconds.
4142
- time_start : float, int, optional
4142
+ ann_type : list[str], str, optional
4143
+ Include annotations of the specified types only (i.e. 'N'). Multiple
4144
+ types are also accepted (i.e. ['V','N']). The default is 'all' which
4145
+ means to include all QRS annotations.
4146
+ start_time : float, int, optional
4143
4147
Begin at the specified time in record. The default is 0 which denotes
4144
4148
the start of the record.
4145
- time_stop : float, int, optional
4149
+ stop_time : float, int, optional
4146
4150
Process until the specified time in record. The default is -1 which
4147
4151
denotes the end of the record.
4148
4152
verbose : bool, optional
@@ -4158,14 +4162,14 @@ def sigavg(record_name, extension, pn_dir=None, return_df=False,
4158
4162
"""
4159
4163
if start_range >= stop_range :
4160
4164
raise Exception ('`start_range` must be less than `stop_range`' )
4161
- if time_start == time_stop :
4162
- raise Exception ('`time_start ` must be different than `time_stop `' )
4163
- if (time_stop != - 1 ) and (time_start >= time_stop ):
4164
- raise Exception ('`time_start ` must be less than `time_stop `' )
4165
- if time_start < 0 :
4166
- raise Exception ('`time_start ` must be at least 0' )
4167
- if (time_stop != - 1 ) and (time_stop <= 0 ):
4168
- raise Exception ('`time_stop ` must be at least greater than 0' )
4165
+ if start_time == stop_time :
4166
+ raise Exception ('`start_time ` must be different than `stop_time `' )
4167
+ if (stop_time != - 1 ) and (start_time >= stop_time ):
4168
+ raise Exception ('`start_time ` must be less than `stop_time `' )
4169
+ if start_time < 0 :
4170
+ raise Exception ('`start_time ` must be at least 0' )
4171
+ if (stop_time != - 1 ) and (stop_time <= 0 ):
4172
+ raise Exception ('`stop_time ` must be at least greater than 0' )
4169
4173
4170
4174
if (pn_dir is not None ) and ('.' not in pn_dir ):
4171
4175
dir_list = pn_dir .split ('/' )
@@ -4175,10 +4179,10 @@ def sigavg(record_name, extension, pn_dir=None, return_df=False,
4175
4179
rec = rdrecord (record_name , pn_dir = pn_dir , physical = False )
4176
4180
ann = annotation .rdann (record_name , extension )
4177
4181
4178
- if time_stop == - 1 :
4179
- time_stop = max (ann .sample ) / ann .fs
4180
- samp_start = int (time_start * ann .fs )
4181
- samp_stop = int (time_stop * ann .fs )
4182
+ if stop_time == - 1 :
4183
+ stop_time = max (ann .sample ) / ann .fs
4184
+ samp_start = int (start_time * ann .fs )
4185
+ samp_stop = int (stop_time * ann .fs )
4182
4186
filtered_samples = ann .sample [(ann .sample >= samp_start ) & (ann .sample <= samp_stop )]
4183
4187
4184
4188
times = np .arange (int (start_range * rec .fs ) / rec .fs ,
@@ -4188,12 +4192,16 @@ def sigavg(record_name, extension, pn_dir=None, return_df=False,
4188
4192
4189
4193
n_beats = 0
4190
4194
initial_sig_avgs = np .zeros ((times .shape [0 ],rec .n_sig ))
4195
+ all_symbols = [a .symbol for a in annotation .ann_labels ]
4196
+
4191
4197
for samp in filtered_samples :
4192
4198
samp_i = np .where (ann .sample == samp )[0 ][0 ]
4193
-
4194
- all_symbols = [a .symbol for a in annotation .ann_labels ]
4199
+ current_ann = ann .symbol [samp_i ]
4200
+ if (ann_type != 'all' ) and (((type (ann_type ) is str ) and (current_ann != ann_type )) or
4201
+ ((type (ann_type ) is list ) and (current_ann not in ann_type ))):
4202
+ continue
4195
4203
try :
4196
- if not annotation .is_qrs [all_symbols .index (ann . symbol [ samp_i ] )]:
4204
+ if not annotation .is_qrs [all_symbols .index (current_ann )]:
4197
4205
continue
4198
4206
except ValueError :
4199
4207
continue
0 commit comments