Upload
samuel-hutchinson
View
233
Download
0
Embed Size (px)
Citation preview
PYTHONEEG ANALYSIS EXAMPLE
FROM
THINK PYTHON
HOW TO THINK LIKE A COMPUTER SCIENTIST
EEG DATA COLLECTION
THEIR TEST BENCH
GENERATES A CSV FILELOOKS LIKE THE FOLLOWING IN EXCEL
Channelssample number
LOOKING AT IT IN NOTEPAD++
Suppose we just want channel 2 and none of the other data. We will use Python to extract that column only.Once it is extracted we can graph it.
OPEN THE FILE AND READ IT.
File=open("eegdata.csv",'r')
File.readline(); # Get rid of the first line.
# It contains only header data
for line in File:
print line
# The above should open the file and print it out one line at a time.
# As soon as this works we can then process each line
REMEMBER SPLIT? If we have a string (or line) that is a CSV string we can split it into pieces and place the result into a list.
Example : str = “34,23,65,77,12”
a = str.split(‘,’)
print a
['34', '23', '65', '77', '12']
But these are strings in a list and not numbers. So.
a[2] is ‘65’ . Can we convert this guy to a float?
float(a[2]) is now 65 Capice?!
THE SCRIPT
File=open("eegdata.csv",'r')
File.readline();
channel = []
for line in File:
list=line.split(',')
channel.append(float(list[2]))
print channel
plot (channel[0:128)) # only plot the first 128 samples
WHAT ABOUT MULTIPLE GRAPHSFile=open("eegdata.csv",'r')
File.readline();
channel = []
for line in File:
list=line.split(',')
channel.append(float(list[2]))
print channel
figure(1)
plot(channel[:128])
figure(2)
plot(channel[128:256])