Reinforced BCI

Citation Author(s):
Joshua
Ho
Submitted by:
Joshua Ho
Last updated:
Thu, 07/04/2024 - 13:23
DOI:
10.21227/tavv-ax88
Data Format:
License:
61 Views
Categories:
Keywords:
0
0 ratings - Please login to submit your rating.

Abstract 

This is a collection of scripts to perform essential preprocessing steps,

doing denoise and feature extraction of EEG (ERP) data using MATLAB and the EEGLAB toolbox.

The scripts are under current development with no guarantee of proper

functioning. The scripts are published in the hopes of helping people with interests in our experiment to reproduce the steps under their environment, and maybe extend to further improvement in the future. Currently, this project works with Muse S band (cortex TP9, TP10, AF7, AF8) device and is implemented with XDF raw Data. 

 

EEG data is processed in two steps: First step is the ICA. Raw EEG data that is only preprocessed by ICA Filtering before hand. In our case, we manually do the labelling using the built-in ICA(Independent Component Analysis) tools with EEGLAB, to do the blind signal separation on different brain signal, and remove the component that is irrelevant to our objective. The second step is to do the feature extraction, in this step we would address all the subject data as a batch, and apply DWT with pwelch to all channels of EEG with a static window size, to form the input data. Users can try different window size/processing function/subject number for different configuration(so far modifications can be done by changing the variable value in preprocess_csv.m directly).

 

As for the model training, in our experiment we use Classification Learner with utilizing minimum redundancy-maximum relevance (MRMR) algorithm in Matlab, which is an application bundled in "Statistics and Machine Learning Toolbox", a built-in toolbox for Matlab R2022a and later version. By taking advantage on this application, we can run training with many models in parallel mode, and make a quick comparison between them.

Instructions: 

DEPENDENCIES: The following scripts and programs are needed for proper running of the scripts.

 

Matlab R2024a - An official version of Matlab

 

EEGLAB 2024.0 - Delorme A & Makeig S (2004) EEGLAB: an open-source toolbox for analysis of single-trial EEG dynamics, Journal of Neuroscience Methods 134:9-21. 

 

xdfimport     - Can be installed via EEGLAB extension manager(2019 and later version)

 

Statistics and Machine Learning Toolbox - Built-in data analysis and training toolbox in R2022a and later version of Matlab. Tutorial: https://www.mathworks.com/help/stats/classificationlearner-app.html

 

Wavelet Toolbox - A built-in toolbox for dwt and pwelch extraction methods. R2023b: Specify DWT Extension Mode. Tutorial: https://www.mathworks.com/help/wavelet/ref/wavedec.html

 

 

USAGE: 

 

The feature extraction is able to run without any params as inputs, it is serial mode by default, which means you can run them by the following command:

 

preprocess_csv

 

in the MATLAB.

 

There is some configuration that can manually change for different experiment (can be found in the code/present/matlab/preprocess_csv.m):

 

subjects: a list of subject name for directory mapping

 

subdirs: a list of classification category. In our experiment, we separate 

the EEG data for different frequency to different folder.

 

dirpath: the directory path to the raw data folder

 

feature_extraction_XXX: For now we have three different feature extraction scripts.

    1. feature_extraction_dwt: The DWT with low level wavelet for extraction.

    2. feature_extraction_test: The pwelch extraction

    3. feature_extraction_fft: The FFT extraction in earlier experiment stage

 

filename: The output file naming

 

 

ALREADY IMPLEMENTED:

- The whole feature extraction procedure in serial mode.

- Some different methodologies implemented for feature extraction that can do comparison.

- Some customizable in-code configuration for user setting.

 

 

NOT YET IMPLEMENTED:

- automatic testing and validating pipeline

- make the configuration level up to params rather than in-code

- Implement batch version for parallel processing

 

 

#############################################################################

SHORT DESCRIPTION OF THE SCRIPTS FOR EXPERIMENTS:

#############################################################################

 

Main control script where the whole feature extraction procedure starts from

-----------------------------------------------------------------------------

code/present/matlab/preprocess_csv

 

Pipelining and apply different feature extraction for all subject data sequentially.

 

Meta script which is the main objective method in our experiment

-----------------------------------------------------------------------------

code/present/matlab/feature_extraction_dwt.m

 

Using DWT with low level wavelet function for feature extraction on EEG

 

 

Complementary scripts for other worth trying methodology 

-----------------------------------------------------------------------------

code/present/matlab/feature_extraction_test.m

 

Using pwelch for feature extraction on EEG

 

code/present/matlab/feature_extraction_fft.m

 

Using FFT for feature extraction on EEG

 

Datas we use as part of demonstration

-----------------------------------------------------------------------------

data/present/output_xs/*

 

x is the window size, those are extracted csv for different window size comparison.

 

 

 

data/present/output_ica/*

data/present/output_ica_2s/*

 

Test data extracted with pwelch

 

data/present/output_ica/*

data/present/output_ica_3s/*

 

Test data extracted with pwelch

 

data/present/output_raw/*

data/present/output_raw_highlv/*

 

Test data extracted with dwt on different level

 

data/present/raw/*