-
Notifications
You must be signed in to change notification settings - Fork 2
/
graphing_matrix.py
118 lines (79 loc) · 2.07 KB
/
graphing_matrix.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
112
113
114
115
116
117
118
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal
from scipy.stats import zscore
# coding: utf-8
# In[1]:
from scipy.io import loadmat
from scipy import signal
# In[2]:
m = loadmat('s5d2nap_justdata.mat')
# In[3]:
matrix = m['s5d2nap']
#lowpass
b1, a1 = signal.butter(2, 0.1, 'low', analog=True)
w1, h1 = signal.freqs(b1, a1)
#highpass
b2, a2 = signal.butter(2, 0.5, 'high', analog=True)
w2, h2 = signal.freqs(b2, a2)
low = 0.3
high = 30
fs = 1000
lowcut = low/(0.5*fs)
highcut = high/(0.5*fs)
#bandpass
b3, a3 = signal.butter(2, [lowcut,highcut], 'band')
w3, h3 = signal.freqs(b3, a3)
#create matrix
new_matrix = []
for index, row in (enumerate(matrix)):
if(index!=63 and index!=62 and index!=61):
print index
new_matrix.append(row[0:600000])
# print len(new_matrix[0])
eeg = signal.detrend(np.array(new_matrix),type='constant')
#normal print
#]mat = []
#for row in range(len(new_matrix)):
# mat.append(eeg[row])
#s = pd.DataFrame(mat).transpose()
#lowpass print
#mat1 = []
#for row in range(len(new_matrix)):
# mat1.append(signal.lfilter(b1, a1, eeg[row]))
#s1 = pd.DataFrame(mat1).transpose()
#highpass print
#mat2 = []
#for row in range(len(new_matrix)):
# mat2.append(signal.lfilter(b2, a2, eeg[row]))
#s2 = pd.DataFrame(mat2).transpose()
#bandpass
mat3 = []
for row in range(len(new_matrix)):
mat3.append(signal.lfilter(b3, a3, eeg[row]))
stemp = pd.DataFrame(mat3).clip(-300,300)
#stemp = pd.DataFrame(mat3)
s3 = pd.DataFrame((stemp))
band = np.array(s3)
band.dump('bandClipped1.dumps')
# In[ ]:
#s.plot(legend=False)
#s1.plot(legend=False)
#s2.plot(legend=False)
print "\n Huh?"
#s3.plot(legend=False)
print "Did that work?"
# cumsum() adds the value of each channel and displays the sum
# s = s.cumsum()
# s.plot()
# fig = plt.figure()
# fig.savefig('matrix.svg')
#plt.figure(2);
# plt.plot(eeg[:8,:30000].T + 8000*np.arange(7,-1,-1));
# plt.plot(np.zeros((30000,8)) + 8000*np.arange(7,-1,-1),'--',color='gray');
#plt.yticks([]);
# plt.legend(first['channels']);
#plt.axis('tight');
#plt.show()