EEG Hacker, 2015-03-17, MIT License
Open data file. Look at behavior of the EEG signals to see what the EEG bias might be doing.
First, we have to import some libraries...though this might be done automagically for IPython Notebooks...I'm not sure.
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.mlab as mlab
# Define Data to Load...be sure to UNZIP the data!!!
pname = 'SavedData/'
test_id = 0;
if (1):
#day 2...after caffeine
fname = 'OpenBCI-RAW-2015-01-25_18-28-58_eyesOpen_AMSine.txt'
sname = 'OpenBCI, Auditory Stimulation (2015-01-25)'
t_lim_sec = [110.0, 280.0]
test_id = 1
elif (0):
#day 2...after caffeine
fname = 'OpenBCI-RAW-2015-01-25_19-04-27_twoTone_focus2500_focus1000.txt' #2500 is 43 Hz, 1000 is 37 Hz
t_lim_sec = [42.0, 92.0]
test_id = 2
else:
#day 2...after caffeine
fname = 'OpenBCI-RAW-2015-01-25_19-15-48_twoTone_eyesClosed_focus1000_focus2500.txt'
t_lim_sec = [85.0, 135.0]
test_id = 3
# load data into numpy array
fs_Hz = 250.0 # assumed sample rate for the EEG data
data = np.loadtxt(pname + fname,
delimiter=',',
skiprows=5)
#unpack the data...ignore other columns
nchan = 8
eeg_data_uV = data[:, 1:(nchan+1)] # EEG data, microvolts
# create a vector with the time of each sample
t_sec = np.arange(len(eeg_data_uV[:, 0])) / fs_Hz
# plot the raw EEG data to see the DC drive
dec_fac = 10; #reduce the number of data points plotted...speeds it up
plt.figure(figsize=(8,4.5))
plt.plot(t_sec[1::dec_fac],eeg_data_uV[1::dec_fac,:]/1000)
plt.xlabel("Time (sec)")
plt.ylabel("Raw EEG (milliVolt)")
plt.title(sname)
plt.ylim([-60, 60])
plt.xlim([t_sec[0], t_sec[-1]])
(0.0, 289.76799999999997)
#common mode is the mean of all signals at a given instance in time
common_mode_uV = np.mean(eeg_data_uV,1) #get mean of each row, not column
rms_common_mode_uV = np.sqrt(np.mean(common_mode_uV**2));
#plot the common mode
plt.figure(figsize=(8,4.5))
plt.plot(t_sec[1::dec_fac],common_mode_uV[1::dec_fac])
plt.xlabel("Time (sec)")
plt.ylabel("Mean Across all EEG Channels (microVolt)")
plt.title("Common Mode Across " + str(nchan) + " EEG Channels\n" + sname)
plt.ylim(30000*np.array([-1, 1]))
plt.xlim([t_sec[0], t_sec[-1]])
xl=plt.xlim()
yl=plt.ylim()
plt.text(xl[1]-0.05*np.diff(xl), yl[1]-0.05*np.diff(yl),
"RMS = " + str(round(rms_common_mode_uV,3)) + " uV",
horizontalalignment='right',verticalalignment='top')
<matplotlib.text.Text at 0xd9952b0>