Download presentation
Presentation is loading. Please wait.
Published bySamuel Hutchinson Modified over 9 years ago
1
PYTHON EEG ANALYSIS EXAMPLE FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST
2
EEG DATA COLLECTION
3
THEIR TEST BENCH
4
GENERATES A CSV FILE LOOKS LIKE THE FOLLOWING IN EXCEL Channels sample number
5
LOOKING AT IT IN NOTEPAD++
6
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.
7
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
8
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?!
9
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
11
WHAT ABOUT MULTIPLE GRAPHS File=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])
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.