def resample_multichan(xs, ann, fs, fs_target, resamp_ann_chan=0): """ Resample multiple channels with their annotations. Parameters ---------- xs: ndarray The signal array. ann : WFDB Annotation The WFDB annotation object. fs : int, float The original frequency. fs_target : int, float The target frequency. resample_ann_channel : int, optional The signal channel used to compute new annotation indices. Returns ------- ndarray Array of the resampled signal values. resampled_ann : WFDB Annotation Annotation containing resampled annotation locations. """ assert resamp_ann_chan < xs.shape[1] lx = [] lt = None for chan in range(xs.shape[1]): resampled_x, resampled_t = resample_sig(xs[:, chan], fs, fs_target) lx.append(resampled_x) if chan == resamp_ann_chan: lt = resampled_t new_sample = resample_ann(lt, ann.sample) assert ann.sample.shape == new_sample.shape resampled_ann = Annotation(record_name=ann.record_name, extension=ann.extension, sample=new_sample, symbol=ann.symbol, subtype=ann.subtype, chan=ann.chan, num=ann.num, aux_note=ann.aux_note, fs=fs_target) return np.column_stack(lx), resampled_ann
def resample_singlechan(x, ann, fs, fs_target): """ Resample a single-channel signal with its annotations. Parameters ---------- x: ndarray The signal array. ann : WFDB Annotation The WFDB annotation object. fs : int, float The original frequency. fs_target : int, float The target frequency. Returns ------- resampled_x : ndarray Array of the resampled signal values. resampled_ann : WFDB Annotation Annotation containing resampled annotation locations. """ resampled_x, resampled_t = resample_sig(x, fs, fs_target) new_sample = resample_ann(resampled_t, ann.sample) assert ann.sample.shape == new_sample.shape resampled_ann = Annotation(record_name=ann.record_name, extension=ann.extension, sample=new_sample, symbol=ann.symbol, subtype=ann.subtype, chan=ann.chan, num=ann.num, aux_note=ann.aux_note, fs=fs_target) return resampled_x, resampled_ann