Commit 52d9e221 authored by Alex Fout's avatar Alex Fout

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	patient.py
#	preprocessing.py
parents 37656071 1b847073
# EEG Data analysis
# Neuro-ID
## Scope
Is there a significat difference between the EEG data from the start of the Season and the end of the season if they had concussion during the season.
Is EEG test-retest data consistent enough to identify an individual? Do mTBI and concussive events change the effectiveness of the algorithm due to brainwave changes?
## Abstract
Raw brainwave data taken from an electroencephalogram (EEG) system has been shown to be unique for each individual. Developing a machine learning algorithm to
identify a specific person by their raw brainwave data can help to determine if a person’s brainwaves become unidentifiable after a concussion and therefore
indicate changes in the brain.
## Tools
Python package to analyse EEG Data: https://martinos.org/mne/stable/index.html
## Waves in EEG
<b> Delta:</b> 0-4 Hz
<br><b> Theta:</b> 4-8 Hz
<br><b> Alpha:</b> 8-13 Hz
<br><b> Beta:</b> 13-20 Hz
<br><b> Gamma:</b> 20-40 Hz
## Data
Labelling of data:
......@@ -15,6 +25,9 @@ Labelling of data:
Data were measured in multiple times per subject, once at the start of the season, once at the end of the season and everytime the subject had a concussion.
the data is labeled alphabetically from starting from a to represent the EED data collection for different times.
**Ex/**
if a subject has data labeled as:
......
......@@ -91,6 +91,9 @@ def main():
#patient.season_start.extract_windows()
#patient.season_start.plot_windows(windows=np.arange(10), channels=["c3", "cz", "c4", "p3", "pz", "p4"])
prep.extractWaves(patient.season_start, n=4001, samplingRate=256, wave='alpha')
patient.season_start.extract_windows()
patient.season_start.plot_windows(windows=np.arange(10), channels=["c3", "cz", "c4", "p3", "pz", "p4"])
#patient.season_start.plot_channels(channels=["c3", "cz", "c4", "p3", "pz", "p4"], end=256)
import pdb; pdb.set_trace()
......
import pandas as pd
from scipy import signal
import numpy as np
ignore_columns = ["time", "window"]
def stft(session, **kwargs):
"""
......@@ -12,6 +14,89 @@ def stft(session, **kwargs):
"""
if not hasattr(session, "stft"):
session.stft = {}
for col in session.raw.columns:
session.stft[col] = signal.stft(session.raw[col], **kwargs)
columns = [col for col in session.raw.columns if col not in ignore_columns]
for col in columns:
session.stft[col] = signal.stft(session.raw[col])
def extractWaves(session, n=4001, samplingRate=256, wave='all'):
"""
Extracts a given waveform from the EEG data.
The available waveforms are:
delta : 0-4 Hz
theta : 4-8 Hz
alpha : 8-13 Hz
beta : 13-20 Hz
gamma : 20-40 Hz
:param session: session of eeg data with a raw instance variable containing a pandas data frame of channels
n : The number of filter coefficients used to construct thge filter (Higher number gives a more accurate filter)
samplingRate : The sampling rate of the EEG Data, to which the filter will be applied
wave : The waveform, defines the bands of the filter
:type session: EEGSession
:return: 0 if success, 1 if it failed
:rtype: int
"""
# Create a dictionary of filter coefficients, the keys are waveforms
b = {}
if (wave == 'all'):
waves = ['delta', 'theta', 'alpha', 'beta', 'gamma']
for i in waves:
b[i] = FIR(n,samplingRate, wave)
else:
b[wave] = FIR(n,samplingRate, wave)
if not hasattr(session, "waves"):
# create a dictionary of pandas dataframes
session.waves = {}
columns = [col for col in session.raw.columns if col not in ignore_columns]
for key in b:
for col in columns:
# apply filter, via convolution
df = pd.DataFrame()
s = pd.Series(np.convolve(session.raw[col], b[key], mode='valid'))
df["_".join([col,wave])] = s
session.waves[key] = df
return 0
def FIR(n=4001, samplingRate=256, wave='alpha'):
"""
:param n : The number of filter coefficients used to construct thge filter (Higher number gives a more accurate filter)
samplingRate : The sampling rate of the EEG Data, to which the filter will be applied
wave : The waveform, defines the bands of the filter
:return: filter coefficients, 1 if it failed
:rtype: int
"""
nyquest = samplingRate/2.0
if wave == 'delta':
# 0-4 Hz Band Filter
f = 4/nyquest
b = signal.firwin(n, f, pass_zero=True)
elif wave == 'theta':
# 4-8 Hz Band Filter
f1 = 4/nyquest
f2 = 8/nyquest
b = signal.firwin(n, [f1, f2], pass_zero=False)
elif wave == 'alpha':
# 8-13 Hz Band Filter
f1 = 8/nyquest
f2 = 13/nyquest
b = signal.firwin(n, [f1, f2], pass_zero=False)
elif wave == 'beta':
# 13-20 Hz Band Filter
f1 = 13/nyquest
f2 = 20/nyquest
b = signal.firwin(n, [f1, f2], pass_zero=False)
elif wave == 'gamma':
# 20-40 Hz Band Filter
f1 = 20/nyquest
f2 = 40/nyquest
b = signal.firwin(n, [f1, f2], pass_zero=False)
else:
print('ERROR: Wave option not available')
return 1
return b
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment