In [1]:
# ERP Analysis Example
# roughly based on /svn/bbci/toolbox/demos/stdERPanalysis.m

In [2]:
from __future__ import division

import numpy as np
from matplotlib import pyplot as plt
from scipy.signal import butter

from wyrm import processing as proc
from wyrm import plot
from wyrm import io

In [3]:
# load bv data into cnt
cnt = io.load_brain_vision_data('data/OnlineTrainFileVPfaz.vhdr')

In [4]:
# remove unneeded channels
cnt = proc.remove_channels(cnt, ['EOG.*', 'Mas.*'])

In [5]:
# bandpass filter the data
fn = cnt.fs / 2
b, a = butter(4, [2 / fn, 40 / fn], btype='band')
cnt = proc.lfilter(cnt, b, a)

In [6]:
# subsample to 100hz
cnt = proc.subsample(cnt, 100)

In [7]:
# TODO: rereferencing?

In [8]:
# epoch the data
mrk_def = {'std': ['S %2i' % i for i in range(2, 7)],
           'dev': ['S %2i' % i for i in range(12, 17)]
           }
epo = proc.segment_dat(cnt, mrk_def, [-150, 800])

In [9]:
# TODO: artifact rejection

In [10]:
# TODO: compute disciminability
# proc_r_square_signed

In [11]:
avg_epo = proc.calculate_classwise_average(epo)

In [12]:
for i, e in enumerate(avg_epo.class_names):
    plot.plot_channels(proc.select_epochs(avg_epo, [i]))
    
plt.legend(avg_epo.class_names)
plt.show()

In [13]:
plot.plot_channels(proc.select_epochs(epo, [100]))
plt.show()

In [13]: