def preprocess(data, filt=None): # copying data dat = data.copy() fs_n = dat.fs / 2.0 # butter filtering low b, a = proc.signal.butter(5, [13 / fs_n], btype='low') #dat = proc.filtfilt(dat, b, a) # butter filtering high b, a = proc.signal.butter(4, [9 / fs_n], btype='high') dat = proc.filtfilt(dat, b, a) # subsampling #dat = proc.subsample(dat, 50) if filt is None: # calculate_csp filt, pattern, _ = proc.calculate_csp(dat) # plot_csp_pattern #plot_csp_pattern(pattern) # apply_csp dat = proc.apply_csp(dat, filt) # variance and logarithm dat = proc.variance(dat) #dat = proc.logarithm(dat) return dat, filt
def test_apply_csp(self): """apply_csp.""" dat = apply_csp(self.epo, self.filter) # reduce the channels down to 2, the rest of the shape should # stay the same self.assertEqual(self.epo.data.shape[0], dat.data.shape[0]) self.assertEqual(self.epo.data.shape[1], dat.data.shape[1]) self.assertEqual(2, dat.data.shape[2]) # new name for csp axis self.assertEqual(dat.names[-1], 'CSP Channel') # check if the dot product was calculated correctly d = np.array([np.dot(self.epo.data[i], self.filter[:, [0, -1]]) for i in range(self.epo.data.shape[0])]) np.testing.assert_array_equal(d, dat.data)
def test_apply_csp(self): """apply_csp.""" dat = apply_csp(self.epo, self.filter) # reduce the channels down to 2, the rest of the shape should # stay the same self.assertEqual(self.epo.data.shape[0], dat.data.shape[0]) self.assertEqual(self.epo.data.shape[1], dat.data.shape[1]) self.assertEqual(2, dat.data.shape[2]) # new name for csp axis self.assertEqual(dat.names[-1], 'CSP Channel') # check if the dot product was calculated correctly d = np.array([ np.dot(self.epo.data[i], self.filter[:, [0, -1]]) for i in range(self.epo.data.shape[0]) ]) np.testing.assert_array_equal(d, dat.data)
def preprocess(data, filt=None): dat = data.copy() fs_n = 250 # sample rate is 250 for us b, a = proc.signal.butter(5, [13 / fs_n], btype='low') dat = proc.filtfilt(dat, b, a) b, a = proc.signal.butter(5, [9 / fs_n], btype='high') dat = proc.filtfilt(dat, b, a) dat = proc.subsample(dat, 50) if filt is None: filt, pattern, _ = proc.calculate_csp(dat) plot_csp_pattern(pattern) dat = proc.apply_csp(dat, filt) dat = proc.variance(dat) dat = proc.logarithm(dat) return dat, filt
def preprocess(data, filt=None): dat = data.copy() fs_n = dat.fs / 2 b, a = proc.signal.butter(5, [13 / fs_n], btype='low') dat = proc.filtfilt(dat, b, a) b, a = proc.signal.butter(5, [9 / fs_n], btype='high') dat = proc.filtfilt(dat, b, a) dat = proc.subsample(dat, 50) if filt is None: filt, pattern, _ = proc.calculate_csp(dat) plot_csp_pattern(pattern) dat = proc.apply_csp(dat, filt) dat = proc.variance(dat) dat = proc.logarithm(dat) return dat, filt
def preprocess(dat,filt=None): '''fs_n = dat.fs / 2 b, a = proc.signal.butter(5, [13 / fs_n], btype='low') dat = proc.lfilter(dat, b, a) b, a = proc.signal.butter(5, [8 / fs_n], btype='high') dat = proc.lfilter(dat, b, a) print dat''' dat = proc.subsample(dat, 64) #epo = proc.segment_dat(dat, MRK_DEF, SEG_IVAL) #fv = proc.jumping_means(epo, JUMPING_MEANS_IVALS) #fv = proc.create_feature_vectors(dat) if filt is None: filt, pattern, _ = proc.calculate_csp(dat) #plot_csp_pattern(pattern) dat = proc.apply_csp(dat, filt) dat = proc.variance(dat) dat = proc.logarithm(dat) return dat, filt
cD_Energy.append(abs(np.sum(np.square(cD_values[x])))) features.append(abs(np.sum(np.square(cD_values[x])))) return features final_epoch1 = append_epo(epoch_subject1_class1, epoch_subject1_class2) final_epoch_ch1 = append_epo( epoch_subject1_ch1_class1, epoch_subject1_ch1_class2) #appended both the epoch data sets w1, a1, d1 = calculate_csp(final_epoch1) w2, a2, d2 = calculate_csp( final_epoch_ch1 ) #calculate csp but why we need to append the data and calculate the csp paramters waht if we calculate it individually fil_epoch_subject1_class1 = apply_csp( epoch_subject1_class1, w1, [0, 1, 2, 3, 4, -5, -4, -3, -2, -1 ]) # brackets number are the column number to use fil_epoch_subject1_class2 = apply_csp(epoch_subject1_class2, w1, [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]) fil_final_epoch1 = append_epo( fil_epoch_subject1_class1, fil_epoch_subject1_class2) # final filtered epo class*time*channel fil_epoch_subject1_ch1_class1 = apply_csp( epoch_subject1_ch1_class1, w2, [0, 1, 2, 3, 4, -5, -4, -3, -2, -1 ]) # brackets number are the column number to use fil_epoch_subject1_ch1_class2 = apply_csp(epoch_subject1_ch1_class2, w2, [0, 1, 2, 3, 4, -5, -4, -3, -2, -1]) fil_final_epoch_ch1 = append_epo( fil_epoch_subject1_class1, fil_epoch_subject1_class2) # final filtered epo class*time*channel
def test_apply_csp_copy(self): """apply_csp must not modify argument.""" cpy = self.epo.copy() apply_csp(self.epo, self.filter) self.assertEqual(self.epo, cpy)