示例#1
0
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
示例#2
0
 def test_variance(self):
     """Variance."""
     dat = variance(self.dat)
     # test the resulting dat has one axis less (the middle one)
     self.assertEqual(dat.data.shape, self.dat.data.shape[::2])
     # each epoch should have a variance of zero, test if the var of
     # all epochs is 0
     self.assertEqual(dat.data.var(), 0)
示例#3
0
 def test_variance(self):
     """Variance."""
     dat = variance(self.dat)
     # test the resulting dat has one axis less (the middle one)
     self.assertEqual(dat.data.shape, self.dat.data.shape[::2])
     # each epoch should have a variance of zero, test if the var of
     # all epochs is 0
     self.assertEqual(dat.data.var(), 0)
     self.assertEqual(len(dat.axes), len(self.dat.axes) - 1)
示例#4
0
 def test_variance_with_cnt(self):
     """variance must work with cnt argument."""
     data = self.dat.data[1]
     axes = self.dat.axes[1:]
     names = self.dat.names[1:]
     units = self.dat.units[1:]
     dat = self.dat.copy(data=data, axes=axes, names=names, units=units)
     dat = variance(dat)
     self.assertEqual(dat.data.var(), 0)
示例#5
0
 def test_variance_with_cnt(self):
     """variance must work with cnt argument."""
     data = self.dat.data[1]
     axes = self.dat.axes[1:]
     names = self.dat.names[1:]
     units = self.dat.units[1:]
     dat = self.dat.copy(data=data, axes=axes, names=names, units=units)
     dat = variance(dat)
     self.assertEqual(dat.data.var(), 0)
     self.assertEqual(len(dat.axes), len(self.dat.axes) - 2)
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
示例#8
0
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
示例#9
0
 def test_variance_copy(self):
     """variance must not modify argument."""
     cpy = self.dat.copy()
     variance(self.dat)
     self.assertEqual(self.dat, cpy)
示例#10
0
 def test_variance_swapaxes(self):
     """variance must work with nonstandard timeaxis."""
     dat = variance(swapaxes(self.dat, 1, 2), timeaxis=2)
     # we don't swap back here as variance removes the timeaxis
     dat2 = variance(self.dat)
     self.assertEqual(dat, dat2)
示例#11
0
 def test_variance_copy(self):
     """variance must not modify argument."""
     cpy = self.dat.copy()
     variance(self.dat)
     self.assertEqual(self.dat, cpy)
示例#12
0
 def test_variance_swapaxes(self):
     """variance must work with nonstandard timeaxis."""
     dat = variance(swapaxes(self.dat, 1, 2), timeaxis=2)
     # we don't swap back here as variance removes the timeaxis
     dat2 = variance(self.dat)
     self.assertEqual(dat, dat2)