commit 3adbe95601ea736759ddf8fcc9a649167618d458 Author: matonglidewazi Date: Mon Nov 5 14:58:15 2018 -0500 initial commit, add readme, FFT diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8312e0a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.ipynb_checkpoints/ +*.dat +*.npy + diff --git a/Preprocess_Deap.ipynb b/Preprocess_Deap.ipynb new file mode 100644 index 0000000..c52e69f --- /dev/null +++ b/Preprocess_Deap.ipynb @@ -0,0 +1,166 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Valence value regression based on Deap Dataset\n", + "## 1. FFT with pyeeg\n", + "* [4-8]: theta band\n", + "* [8-12]: alpha band\n", + "* [12-16]: low beta band \n", + "* [16-25]: high beta band\n", + "* [25-45]: gamma band" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import pyeeg as pe\n", + "import pickle as pickle\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2. Channel Indice \n", + "File Name data\\SXX.dat, XX \\in [0,31]\n", + "* data: 40 x 40 x 8064: trial x channel x data\n", + "* label: 40 x 4: video/trial x label (valence, arousal, dominance, liking)\n", + "\n", + "Channel Indice: {\n", + "* 1 : AF3\n", + "* 2: F3\n", + "* 3: F7\n", + "* 4: FC5\n", + "* 7: T7\n", + "* 11: P7\n", + "* 13: O1\n", + "* 17: AF4\n", + "* 19: F4\n", + "* 20: F8\n", + "* 21: FC6\n", + "* 25: T8\n", + "* 29: P8\n", + "* 31: O2 }\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [], + "source": [ + "channel = [1,2,3,4,6,11,13,17,19,20,21,25,29,31] #14 Channels chosen to fit Emotiv Epoch+\n", + "band = [4,8,12,16,25,45] #5 bands\n", + "window_size = 256 #averaging band power of 2 sec\n", + "step_size = 16 #each 0.125 sec update once\n", + "sample_rate = 128 #sampling rate of 128 Hz\n", + "\n", + "def FFT_Processing (sub, channel, band, window_size, step_size, sample_rate):\n", + " '''\n", + " arguments: string subject\n", + " list channel indice\n", + " list band\n", + " int window size for FFT\n", + " int step size for FFT\n", + " int sample rate for FFT\n", + " return: void\n", + " '''\n", + " \n", + " meta = []\n", + " with open('data\\s' + sub + '.dat', 'rb') as file:\n", + "\n", + " subject = pickle.load(file, encoding='latin1') #resolve the python 2 data problem by encoding : latin1\n", + "\n", + " for i in range (0,40):\n", + " # loop over 0-39 trails\n", + " data = subject[\"data\"][i]\n", + " labels = subject[\"labels\"][i]\n", + " start = 0;\n", + "\n", + " while start + window_size < data.shape[1]:\n", + " meta_array = []\n", + " meta_data = [] #meta vector for analysis\n", + " for j in channel:\n", + " X = data[j][start : start + window_size] #Slice raw data over 2 sec, at interval of 0.125 sec\n", + " Y = pe.bin_power(X, band, sample_rate) #FFT over 2 sec of channel j, in seq of theta, alpha, low beta, high beta, gamma\n", + " meta_data = meta_data + list(Y[0])\n", + "\n", + " meta_array.append(np.array(meta_data))\n", + " meta_array.append(labels)\n", + "\n", + " meta.append(np.array(meta_array)) \n", + " start = start + step_size\n", + " meta = np.array(meta)\n", + " np.save('out\\s' + sub, meta, allow_pickle=True, fix_imports=True)\n", + "\n", + "\n", + "subjectList = ['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32']\n", + "\n", + "for subjects in subjectList:\n", + " FFT_Processing (subjects, channel, band, window_size, step_size, sample_rate)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3.Segment and training of preprocessed data\n", + "* training dataset\n", + "* testing dataset\n", + "* validation dataset\n", + "\n", + "Agrithom pool:\n", + "* Support Vector Machine (which kernal?)\n", + "* Ada-Boost\n", + "\n", + "Best practice could be refered to this paper: \n", + "\n", + "@article{alarcao2017emotions,\n", + " title={Emotions recognition using EEG signals: A survey},\n", + " author={Alarcao, Soraia M and Fonseca, Manuel J},\n", + " journal={IEEE Transactions on Affective Computing},\n", + " year={2017},\n", + " publisher={IEEE}\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..ec35cd3 --- /dev/null +++ b/Readme.md @@ -0,0 +1,16 @@ +# EEG Classifier based on DEAP database + +## This repo only include code to proceed DEAP data, no data from DEAP contained! + +For access of DEAP dataset, please sign EULA and send a request to DEAP team: http://www.eecs.qmul.ac.uk/mmv/datasets/deap/download.html + +## Dependency +*python >= 3.5 +*numpy +*pyEEG: https://github.com/forrestbao/pyeeg + + +## ERD/ERS analysis +Fast Fourier Transformation: +*Windows size = 2 sec +*Windows step = 0.125 sec \ No newline at end of file