-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextracted_features.py
111 lines (93 loc) · 2.97 KB
/
extracted_features.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import matplotlib.pyplot as plt
from scipy.signal import butter, lfilter
import scipy.io as sio
from scipy.fftpack import fft
import numpy as np
import pandas as pd
from scipy.linalg import eig
from numpy import linalg as LA
from scipy import stats
y_train = []
time_Mean_c1 = []
freq_Mean_c1 = []
time_stanard_deviation_c1 = []
freq_stanard_deviation_c1 = []
time_variance_c1 = []
frequency_variance_c1 = []
power_time_c1 = []
time_Mean_c3 = []
freq_Mean_c3 = []
time_stanard_deviation_c3 = []
freq_stanard_deviation_c3 = []
time_variance_c3 = []
frequency_variance_c3 = []
power_time_c3 = []
p = []
maximum_c1 = []
maximum_c3 = []
fs = 128.0
nyq_rate = fs/2.0
lowcut = 8
highcut = 12
T = 1/128.0
N = 1152
def band_pass(data,lowcut,highcut,fs,order=10):
Nyq = 0.5*fs
low = lowcut/Nyq
high = highcut/Nyq
b, a = butter(order, [low,high], btype='band')
y = lfilter(b,a,data)
return y
x = np.linspace(0,2*np.pi*N*T,N)
xf = np.linspace(0,1.0/(2.0*T),N/2)
#read data
extracted_data = sio.loadmat('/home/omar/Documents/python_programs/graduation/graz_data/dataset_BCIcomp1.mat')
data = extracted_data['x_train']
for i in range(0,139):
t = data[:,0,i]
xc1=band_pass(t,lowcut,highcut,fs,order=6)
f = fft(xc1)
xf1 = abs(f)
Mt = np.mean(xc1)
St = np.std(xc1)
k=np.square(xc1)
power_time_c1.append(np.trapz(k,axis=0))
variance_t = np.var(xc1)
time_Mean_c1.append(Mt)
time_stanard_deviation_c1.append(St)
time_variance_c1.append(variance_t)
maximum_c1.append(max(xf1))
Mf = np.mean(xf1)
Sf = np.std(xf1)
variance_f = np.var(xf1)
freq_Mean_c1.append(Mf)
freq_stanard_deviation_c1.append(Sf)
frequency_variance_c1.append(variance_f)
for i in range(0,139):
t = data[:,2,i]
xc1=band_pass(t,lowcut,highcut,fs,order=6)
f = fft(xc1)
xf1 = abs(f)
Mt = np.mean(xc1)
St = np.std(xc1)
k=np.square(xc1)
power_time_c3.append(np.trapz(k,axis=0))
variance_t = np.var(xc1)
time_Mean_c3.append(Mt)
time_stanard_deviation_c3.append(St)
time_variance_c3.append(variance_t)
maximum_c3.append(max(xf1))
Mf = np.mean(xf1)
Sf = np.std(xf1)
variance_f = np.var(xf1)
freq_Mean_c3.append(Mf)
freq_stanard_deviation_c3.append(Sf)
frequency_variance_c3.append(variance_f)
# print len(val)
#dic = {'eig':w,'val':v}
# df = pd.DataFrame(dic)
# df.to_csv('/home/omar/Documents/python_programs/graduation/datasets/eigens.csv',index=False)
print stats.ttest_ind(time_Mean_c1,time_Mean_c3,equal_var = False)
dic = {'time_stanard_deviation_c1':time_stanard_deviation_c1,'freq_stanard_deviation_c1':freq_stanard_deviation_c1,'time_variance_c1':time_variance_c1,'frequency_variance_c1':frequency_variance_c1,'signal_power_c1':power_time_c1,'c1_max':maximum_c1,'c3_max':maximum_c3,'time_stanard_deviation_c3':time_stanard_deviation_c3,'freq_stanard_deviation_c3':freq_stanard_deviation_c3,'time_variance_c3':time_variance_c3,'frequency_variance_c3':frequency_variance_c3,'signal_power_c3':power_time_c3}
df = pd.DataFrame(dic)
df.to_csv('/home/omar/Documents/python_programs/graduation/datasets/tkn2.csv',index=False)