In [1]:
%matplotlib inline
from matplotlib import pylab as pl
import cPickle as pickle
import pandas as pd
import numpy as np
import os
import random
In [2]:
import sys
sys.path.append('..')
According to https://www.kaggle.com/c/seizure-prediction/forums/t/10274/technical-artefacts-in-some-channels-and-data-files-for-patient-1 the following has noise:
In [37]:
target = 'Patient_2'
data_type = 'preictal' # interictal, test
segment = 3
In [23]:
target = 'Dog_5'
data_type = 'test' # preictal interictal, test
segment = 3
In [38]:
fname = '../seizure-data/%s/%s_%s_segment_%04d.mat'%(target,target,data_type,segment)
In [39]:
import scipy.io
data = scipy.io.loadmat(fname)
In [40]:
data.keys()
Out[40]:
In [41]:
k = '%s_segment_%d'%(data_type,segment)
In [42]:
data_length_sec = data[k]['data_length_sec'][0,0][0,0]
sequence = data[k]['sequence'][0,0][0,0]
Fs = float(data[k]['sampling_frequency'][0,0][0,0])
data_length_sec, sequence, Fs
Out[42]:
In [43]:
channels = [t[0] for t in data[k]['channels'][0,0][0]]
len(channels),channels
Out[43]:
In [183]:
d = data[k]['data'][0,0]
d.shape
Out[183]:
In [184]:
assert len(channels) == d.shape[0]
In [185]:
assert int(Fs*data_length_sec + 0.5) == d.shape[1],int(Fs*data_length_sec + 0.5)
In [186]:
Nchannels = 4 # d.shape[0]
for i in range(Nchannels):
pl.subplot(Nchannels,1,i+1)
pl.plot(d[i,:500000])
pl.title(channels[i])
pl.gcf().set_size_inches(14,8);
In [187]:
Y = np.abs(np.fft.rfft(d[0,:]))
In [188]:
Y[60*data_length_sec]/np.std(d[0,:])
Out[188]:
In [193]:
pl.plot(Y[:200*data_length_sec])
Out[193]:
In [192]:
NFFT=8192
Pxx, freqs, bins, im = pl.specgram(d[3,:], NFFT=NFFT, pad_to=NFFT*2, Fs=Fs, noverlap=NFFT/2)
pl.gca().set_ylim((0,1000))
pl.show()