analysis of pre-ictal and non-ictal eeg activity: an emotiv and …/67531/metadc955040/... ·...

77
APPROVED: Vijay Vaidyanathan, Major Professor Kamesh Namuduri, Committee Member Xinrong Li, Committee Member Shengli Fu, Chair of the Department of Electrical Engineering Costas Tsatsoulis, Dean of the College of Engineering Victor Prybutok, Vice Provost of the Toulouse Graduate School ANALYSIS OF PRE-ICTAL AND NON-ICTAL EEG ACTIVITY: AN EMOTIV AND LabVIEW APPROACH Oscar Ferney Medina Thesis Prepared for the Degree of MASTER OF SCIENCE UNIVERSITY OF NORTH TEXAS December 2016

Upload: others

Post on 27-Dec-2019

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

APPROVED: Vijay Vaidyanathan, Major Professor Kamesh Namuduri, Committee Member Xinrong Li, Committee Member Shengli Fu, Chair of the Department of

Electrical Engineering Costas Tsatsoulis, Dean of the College of

Engineering Victor Prybutok, Vice Provost of the Toulouse

Graduate School

ANALYSIS OF PRE-ICTAL AND NON-ICTAL EEG ACTIVITY:

AN EMOTIV AND LabVIEW APPROACH

Oscar Ferney Medina

Thesis Prepared for the Degree of

MASTER OF SCIENCE

UNIVERSITY OF NORTH TEXAS

December 2016

Page 2: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

LabVIEW Approach. Master of Science (Electrical Engineering), December 2016, 67 pp., 2 tables,

38 figures, 26 numbered references.

In the past few years, the study of electrical activity in the brain and its interactions with

the body has become popular among researchers. One of the hottest topics related to brain

activity is the epileptic seizure prediction. Currently, there are several techniques on how to

predict a seizure; however, most of the techniques found in research papers are just

mathematical models and not system implementations. The seizure prediction approach

proposed in this thesis paper is achieved using the EMOTIV Epoc+ headset, MATLAB, and

LabVIEW as the analog and digital signal processing devices. In addition, this thesis project

incorporates the use of the Hilbert Huang transform (HHT) method to obtain intrinsic mode

functions (IMF) and instantaneous frequency components of the transform. From the IMFs,

features as variation coefficient (VC) and fluctuation indexes (FI) are extracted to feed a support

vector machine that classifies the EEG data as pre-ictal and non-ictal EEGs. Outstanding

patterns in non-ictal and pre-ictal are observed and demonstrated by significant differences

between both types of EEG signals. In other words, a classification of EEG signals according to a

category can be achieved proving that an epileptic seizure prediction technology has a future in

engineering and biotechnology fields.

Page 3: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

ii

Copyright 2016

by

Oscar Ferney Medina

Page 4: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

iii

ACKNOWLEDGEMENTS

It has been quite an honor to work with Dr. Vijay Vaidyanathan for the past two and a

half years. He has not only provided me with the opportunity to work with him in my research,

but also be able to be part of the creation of the biomedical engineering department at the

University of North Texas. He has also served as a mentor and a friend. Also, I would like to give

thanks to Dr. Kamesh Namuduri for being patient with me throughout my time in the electrical

engineering department and for providing the means to have a partnership with the biomedical

and electrical engineering departments. Thanks to Ramanpreet Singh for being my

unconditional friend and study partner. Without him, graduate school would have been a lot

harder. Last, I would like to thank my parents, Adela and Oscar, and my sister Jennifer for being

there for me in the most difficult times and providing their unconditional support.

Page 5: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

iv

TABLE OF CONTENTS

Page

ACKNOWLEDGEMENTS ...................................................................................................................iii LIST OF TABLES ............................................................................................................................... vii LIST OF FIGURES ............................................................................................................................ viii CHAPTER 1. INTRODUCTION ........................................................................................................... 1

1.1 Motivation ............................................................................................................... 1

1.2 Electroencephalography (EEG) ............................................................................... 2

1.3 Epilepsy and Seizure Basics ..................................................................................... 3

1.3.1 Common Generalized Seizures [1] .............................................................. 4

1.3.2 Common Partial or Focal Seizures [1] ......................................................... 4

1.3.3 EEG Activity Terminology ............................................................................ 5

1.4 Artifacts ................................................................................................................... 5

1.5 Conclusion ............................................................................................................... 6 CHAPTER 2. METHODS .................................................................................................................... 7

2.1 EEG Acquisition device ............................................................................................ 7

2.1.1 Other EMOTIV Epoc+ Specifications ........................................................... 8

2.1.2 EMOTIV Pure EEG Raw EEG Software ......................................................... 8

2.2 Software .................................................................................................................. 9

2.2.1 Simulink ....................................................................................................... 9

2.2.2 MATLAB ..................................................................................................... 10

2.2.3 LabVIEW .................................................................................................... 11

2.3 Mathematical Background .................................................................................... 12

2.3.1 The Fourier Transform .............................................................................. 12

2.3.2 The Discrete Fourier Transform (DFT) ...................................................... 13

2.3.3 The Fast Fourier Transform (FFT) .............................................................. 13

2.3.4 Fourier Transform Digital Implementation ............................................... 14

2.3.5 Hilbert Huang Transform (HHT) ................................................................ 14

2.3.6 Empirical Mode Decomposition ............................................................... 14

Page 6: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

v

2.3.7 The Hilbert Transform ............................................................................... 17

2.3.8 Instantaneous Frequency ......................................................................... 17

2.3.9 Statistical Mean ........................................................................................ 18

2.3.10 Standard Deviation ................................................................................... 19

2.3.11 Feature Extraction ..................................................................................... 20

2.3.12 Variation Coefficient ................................................................................. 21

2.3.13 Fluctuation Index (FI) ................................................................................ 21

2.3.14 Machine Learning Algorithms for Classification ....................................... 23

2.3.15 Machine Learning Algorithms ................................................................... 24

2.3.16 Supervised Learning .................................................................................. 24

2.3.17 Support Vector Machine ........................................................................... 25

2.3.18 Linear Classification SVM .......................................................................... 26

2.3.19 Nonlinear Classification SVM .................................................................... 27

2.4 LabVIEW Code ....................................................................................................... 28

2.5 LabVIEW Code List ................................................................................................ 29

2.5.1 EMOTIV Epoc+ to LabVIEW ....................................................................... 29

2.5.2 LabVIEW EMOTIV Toolkit V2 ..................................................................... 30

2.5.3 EMOTIV Toolkit VI Modifications .............................................................. 30

2.6 Hilbert Huang Transform and EMD ...................................................................... 35

2.6.1 Feature Extraction ..................................................................................... 36

2.6.2 Support Vector Machine: Supervised Learning ........................................ 38

2.7 Conclusion ............................................................................................................. 39 CHAPTER 3. RESULTS AND DISCUSSION........................................................................................ 41

3.1 EEG Signal LabVIEW Reader .................................................................................. 41

3.2 Non-ictal and Pre-Ictal EEG Signal Analysis .......................................................... 42

3.3 EEG Signal Visual Inspection ................................................................................. 42

3.4 EMD and Features ................................................................................................. 45

3.5 SVM Training Data Set Analysis ............................................................................ 45 CHAPTER 4. COMMENTS, FUTURE WORK, AND CONCLUSION .................................................... 53

4.1 The Next Generation ............................................................................................. 53

Page 7: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

vi

4.2 Other Considerations ............................................................................................ 53

4.3 Future Work .......................................................................................................... 54

4.3.1 A Doctor's Recommendation .................................................................... 54

4.3.2 A Patient’s Perspective ............................................................................. 55

4.3.3 Personal Comments .................................................................................. 58

4.3.4 Emergency Response Protocol ................................................................. 59

4.3.5 A Mobile Phone Application ..................................................................... 60

4.3.6 Adaptation of an EMOTIV Headset ........................................................... 60

4.4 Conclusion ............................................................................................................. 61 REFERENCES .................................................................................................................................. 64

Page 8: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

vii

LIST OF TABLES

Page

3.1 Features extracted using the EMD VI LabVIEW code ....................................................... 46

3.2 Differences between non-ictal and pre-ictal features ...................................................... 50

Page 9: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

LIST OF FIGURES

Figure 1: EEG waves by frequency [1]............................................................................................. 2

Figure 2: EMOTIV Epoc+ and Insight EEG headsets. Courtesy of EMOTIV Brainware® ................. 3

Figure 3: EPOC headset Channel Position Map. Courtesy of EMOTIV Brainwear®. ....................... 8

Figure 4: EMOTIV Xavier Composer-Raw EEG Software. ................................................................ 9

Figure 5: EMD Data, Mean, Upper and Lower Envelope .............................................................. 16

Figure 6: EEG IMF1 though IMF5 example ................................................................................... 17

Figure 7: Prediction Algorithm Flow Chart ................................................................................... 23

Figure 8:SVM Support Vectors and Separating Hyperplane ........................................................ 27

Figure 9: Nonlinear SVM example Data set [24]........................................................................... 28

Figure 10: EMOTIV LabVIEW Toolkit VI (original Version) [25] .................................................... 30

Figure 11: Original Plot EEG sub VI ............................................................................................... 31

Figure 12: Modified Plot EEG VI .................................................................................................... 31

Figure 13: Front Panel EEG Signal Reader .................................................................................... 33

Figure 14: Case Structure Example Help ....................................................................................... 33

Figure 15: Modified EEG Reader with Case Structure .................................................................. 33

Figure 16:Modified EEG Reader with Case Structure Part 1......................................................... 34

Figure 17:Case Structure to Save 512 Recorded Samples ............................................................ 35

Figure 18: Hilbert Huang Transform VI ......................................................................................... 36

Figure 19: Fluctuation Index and Coefficient of Variation Extraction [26] ................................... 37

Figure 20:Front Panel for EEG readings, IMFs, VC and FI ............................................................. 38

Figure 21 SVM LabVIEW code Block diagram ............................................................................... 39

viii

Page 10: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 22: EEG Signal LabVIEW Reader Front Panel ..................................................................... 41

Figure 23: Ten Minute Non-Ictal EEG Reading.............................................................................. 42

Figure 24: Ten Minute Non-Ictal EEG Reading Continued ............................................................ 43

Figure 25:Ten Minute Non-Ictal EEG Reading Final ...................................................................... 43

Figure 26:Ten Minute Pre-Ictal EEG Reading ................................................................................ 44

Figure 27:Ten Minute Pre-Ictal EEG Reading Continued .............................................................. 44

Figure 28:Ten Minute Pre-Ictal EEG Reading Final Section .......................................................... 44

Figure 29: EMD Front Panel with EEG, IMFs, and Features Display ............................................. 45

Figure 30:Variation Coefficient: Non- Ictal and Pre-Ictal Values .................................................. 47

Figure 31:Fluctuation Index: Non-Ictal and Pre-Ictal Values ........................................................ 48

Figure 32 Variation Coefficients for Ictal and Inter-ictal EEG segments....................................... 48

Figure 33 Fluctuation Index for Ictal and Inter-Ictal EEG segments [9]. ....................................... 49

Figure 34:Variation Coefficient Vs Fluctuation Index Plot ............................................................ 49

Figure 35:SVM Refined Training Data Plot ................................................................................... 51

Figure 36: SVM Classifier Test 1 .................................................................................................... 52

Figure 37:SVM Classifier Test 2 ..................................................................................................... 52

Figure 38: Block Diagram Cellphone App Feature ........................................................................ 60

ix

Page 11: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

CHAPTER 1

INTRODUCTION

1.1 Motivation

The study of EEG signals is not novel and there are numerous applications in which EEG

signals can help us understand and develop new sophisticated technology. Studies using EEGs

have been used for biomedical applications as well as military applications; however, there is not

a unique or set of patterns that allow us to fully understand the nature of EEG signals. In this

research, the study of EEG signals is oriented towards the analysis and prediction of epileptic

seizure activity in the brain. It is important to mention the fact that there are other ways to

analyze and predict epileptic seizures; however, the objective of this thesis is to implement a

digital signal processing algorithm to predict the initial states of a seizure before it happens. To

achieve the intended goal, bio-instrumentation hardware such as the EMOTIV Epoc+ and Insight

are used to capture the analog EEG signals and software such as LabVIEW and MATLAB to process

the EEG signals.

According to the Epilepsy foundation, epilepsy is one of the most common neurological

problems. Around 2.2 million Americans report to have some sort of epilepsy but higher number

of people report to have active epilepsy and even higher numbers are reported when people

have been asked if they ever had epilepsy at some point in their lives [1].

1

Page 12: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

1.2 Electroencephalography (EEG)

The discovery of the EEG has provided an avenue on the study of the human brain and its

interactions with the rest of the body. Since then, scientists and researchers are able to provide

a meaning for such a random non-periodic signal as the EEG. The range of amplitudes in EEG’s is

normally from 10 mV to 150 mV when recorded from electrodes from the scalp [1]. EEG signals

also contain frequency components that range from 0.5 to 50 Hertz. However, the most

important EEG frequency patterns are categorized in the following bands:

Delta band. Typically, from 0.1 to 3.5 Hz

Theta band. 4.5 Hz to 7.5 Hz

Alpha band. 8 to 13 Hz

Beta band. Typically, from 14 to 30 Hz

Figure 1: EEG waves by frequency [1]

In the past few years, the EEG has become popular among scientists and researchers who

study the control of electronics and mechanical devices using mental commands as well as those

2

Page 13: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

who study epileptic seizure phenomena. However, it is necessary to have the right

instrumentation equipment to acquire an EEG signal regardless of the application.

Figure 2: EMOTIV Epoc+ and Insight EEG headsets. Courtesy of EMOTIV Brainware®

A seizure happens when a person’s brain is overloaded by abnormal amount of electrical

and chemical activity. Neurologists describe seizures as “storm in the brain” [2]. In the moment

a seizure happens, there are changes happening in how a person thinks, feels, or moves.

Depending on the types of seizure, these changes can cause thing like:

Loss of consciousness

Convulsions

Confusion

Brief periods of staring

A sudden feeling of fear or panic

Uncontrolled shaking of an arm or leg.

1.3 Epilepsy and Seizure Basics

3

Page 14: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

There are over 20 types of seizures and the type may depend on where the activity

happens and how much the brain is involved. All types of seizures fall into two broad categories.

Generalized Seizures: Occur when the abnormal activity happens in both sides of the

brain at the same time.

Partial or Focal Seizures: Typically happen in one specific part of the brain.

1.3.1 Common Generalized Seizures [1]

Generalized Tonic-Clonic Seizures are the most common and well known type of seizure

for children. Tonic seizures begin with stiffening of the limbs and loss of consciousness.

Breathing may decrease or cease altogether. The clonic stage causes jerking that may

last several minutes.

Absence Seizures are characterized by a blank stare, rolling of the eyes, and chewing

movements. There is no confusion afterwards.

Atonic Seizures causes a loss of normal muscle tone. The affected person may fall or

drop down his or her head involuntarily.

Myoclonic Seizures cause sudden muscle jerks.

1.3.2 Common Partial or Focal Seizures [1]

Simple Partial (or focal) Seizures: this type of seizure may take many forms. Usually affect

movement on one part of the body, or it may affect a sensation. Typically, the affected

person stays awake and aware unless the seizures turns into a generalized seizure.

Complex Partial (or focal) Seizures: this type of seizure affects consciousness. The

affected person may start with a blank stare and then display strange, repetitious

4

Page 15: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

behaviors such as blinks, twitches, mouth movements, removing clothes, or walking in a

circle without retaining memory of what happened during the seizure.

1.3.3 EEG Activity Terminology

Non-Ictal: A physiological state which is characterized by normal electrical activity in

neuronal tissue [3].

Ictal: A physiological state which is characterized by periods of high-frequency high

amplitude electrical activity in neuronal tissue [3].

Pre-Ictal: Electrical activity occurring before a seizure or a stroke.

1.4 Artifacts

EEG measurements techniques suffer from signal distortions that can cause higher

amplitudes and different shapes in the signal. These are called artifacts. Most of these artifacts

are unwanted physiological signals caused by the patient and may cause a major

misinterpretation of an EEG signal [4]. Other forms of artifacts are the power line loss and a

decrease in electrode impedance. Some of the most common artifacts found in EEG are the

following:

Patient related artifacts:

Electromyography (EMG)

Electrocardiography (ECG)

Eye and other minor body movements

5

Page 16: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Technical artifacts

50/60 Hertz noise due to AC line losses

Broken electrodes or contacts

Low Battery

Loss in data transmission

1.5 Conclusion

In this research, I explore the use of several EEG recordings from the Epilepsy Foundation

to implement and test the signal processing code written in LabVIEW. Also, implementation of

filtering and spectral analysis techniques will be briefly discussed. However, the main techniques

being used for this algorithm involve statistical calculations such as the mean and standard

deviation of a transformed EEG signal.

This thesis research project was developed in order to facilitate the use of a technology

that a layperson would be able to access using a home computer and an EEG headset device. The

goal of this research is to develop a prediction algorithm that would interface to LabVIEW source

code to extract prominent features of interest from EEG waveforms. Once that is accomplished,

this research will serve as a feasibility study on an early warning system for epileptic seizure

activity.

6

Page 17: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

CHAPTER 2

METHODS

2.1 EEG Acquisition Device

An EMOTIV Epoc+ EEG headset was used to record data from subjects. Both, male and

female subjects were chosen on a voluntary basis. Each EEG recording lasted about five to ten

minutes while the subjects operated a computer or remained still. The sampling frequency of

the EMOTIV Epoc+ was set to capture 256 samples per second and a 60 hertz digital embedded

filter to keep unwanted noises caused by electric lines. The EMOTIV headset has fourteen

different channels that monitor the EEG from different regions of the brain and a ground node

at each side of the device [5]. A total of 16 probes are to be placed on the individual’s scalp.

In accordance with the international 10-20 system of electrodes for the EEG, the

EMOTIV Epoc+ headset contains the following channels:

Frontal: AF3, AF4, F3, F4, F7, and F8

Fronto-Central: FC5 and FC6

Occipital: O1 and O2

Parietal: P7 and P8

Temporal Sites: T7 and T8

References: CMS/DRL noise cancellation configuration P3 and P4 locations

Figure 3 graphically depicts the approximate locations where the EMOTIV Epoc+

headset places their electrodes.

7

Page 18: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 3: EPOC headset Channel Position Map. Courtesy of EMOTIV Brainwear®.

2.1.1 Other EMOTIV Epoc+ Specifications

Connectivity

Wireless: Bluetooth® Smart

Proprietary wireless: 2.4GHz band

Power

Battery: Internal Lithium Polymer battery 480mAh

Battery life: up to 12 hours using proprietary wireless, up to 6 hours using Bluetooth®

Smart

2.1.2 EMOTIV Pure EEG Raw EEG Software

All the EEG recordings are captured and visualized using the EMOTIV Xavier composer,

which contains the root file to access the EEG raw data. The EMOTIV Xavier Composer-Raw EEG

Software is unique because it provides the ability to see which electrodes make good contact

with the human scalp. If there is not a good contact, as seen in Figure 4, a red indicator will turn

on along with the position of the electrode. However, if there is good contact, the indicators will

8

Page 19: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

turn green. This feature proves itself useful for electrode-scalp contact when the EMOTIV Epoc+

is used with an external signal processing software. The EMOTIV Xavier Composer-Raw EEG

Software includes more capabilities such as data recording and a full view of the different signals

being recorded.

Figure 4: EMOTIV Xavier Composer-Raw EEG Software.

In addition to visualizing and recording EEG signals, EMOTIV Xavier Composer-Raw EEG

Software is able to display the fast Fourier transform of the current signals. Because this

software does not provide the capability of performing other signal processing or prediction

techniques, a different recording and signal processing approach had to be investigated. As a

solution, MathWorks Simulink offers an alternative user interface that communicates with the

EMOTIV Epoc+ headset.

2.2 Software

2.2.1 Simulink

MathWorks’ Simulink package included in MATLAB was explored to create a graphic

interface capable of allowing the user to display raw EEG signals and implement complex digital

9

Page 20: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

signal processing. Despite the functionalities Simulink possesses, it contained very few ways to

track and display immediate results. In addition, Simulink ceased to be the signal processing

resource for this thesis research project due to the lack of documentation.

2.2.2 MATLAB

Matrix Laboratory (MATLAB) is an essential tool to make basic and complex calculations

allowing the user to process data much faster. For the purposes of this thesis, MATLAB serves as

a mean to read pre-recorded data from either the EMOTIV Epoc+/Insight or any other devices

that capture EEG signals. In some cases, when the data has been pre-recorded by a different EEG

device with different sampling frequency (usually higher than 256 samples per second), MATLAB

can help to down sample the EEG signal without corrupting data from the pre-recorded signal.

Most of the time, a pre-recorded EEG data set was found; however, the sampling

frequency would be 20 times higher than the sampling frequency of an EMOTIV device. The

reason why down sampling needs to be done to any non-EMOTIV recorded EEG data set is

because it is necessary to test the epileptic prediction algorithm as if it was taking data from an

EEG EMOTIV device. Fortunately, MATLAB facilitates this down sampling process by a technique

that could be termed data stitching or in more technical terms data concatenation.

When MATLAB reads a pre-recorded EEG data set, it reads it as a CSV file; however, these

CSV files have a limit on how much data they can store at a time. Chunks of data are

independently stored in a separate CSV files to avoid this problem. The EEG data is read by

MATLAB to be down sampled and stored in a new file with less. This process is applied to the

majority of the signal and in the end, it is possible to save a separate CSV file with fewer data.

10

Page 21: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Once again, all this CSV files are read in MATLAB and then concatenated with the other chunks

of the EEG signal into one EEG signal CSV file.

MATLAB also provides a digital filter design implementation tool for signal processing

purposes. Some of the pre-recorded EEG signals may or may not include unwanted signals that

interfere with the integrity an EEG recording. Most of this unwanted signals are caused by a 60

Hertz signal present in electric lines. Depending in the geographic location, a 50 Hertz signal may

be present as well.

2.2.3 LabVIEW

This software tool has similar capabilities as Simulink; however, LabVIEW provides more

ways to provide a better user interface and an easy to understand programming flow process. In

addition, LabVIEW supports parallel processing that enables more processing power to a given

code. In addition, National Instruments has developed a Virtual Instrument (VI) that allows

EMOTIV devices and LabVIEW communicate and transfer EEG data via a Bluetooth connection.

There are other functionalities that National Instruments added to their EMOTIV LabVIEW VI

package such as digital filtering and Fast Fourier transform capabilities. Once the communication

between the EMOTIV Epoc+ headset and LabVIEW is established, signal processing techniques

can be implemented and executed.

The hardest part of real time digital signal processing is the ability to keep track of data

stored in memory and data that has been processed by a given LabVIEW algorithm. To solve this

issue, all the EEG data obtained is being saved to a master Comma Separated Vector (CSV) File

and to a CSV dummy copy that tracks most recent data. This dummy copy only contains the last

11

Page 22: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

and most recent 1280 samples at a given time, that is about 5 seconds of recorded data assuming

a sampling frequency of 256 samples per second.

Then the LabVIEW VI is set to extract 512 samples out of the 1280 samples previously

recorded and undergo through a digital processing algorithm. The extracted samples are erased

from the dummy copy leaving 768 samples. At the same time, the EMOTIV Epoc+ headset is still

feeding LabVIEW with new data to both master CSV file and the dummy copy. Once the dummy

copy reaches 1280 samples, LabVIEW will process another set of 512 samples in the order the

data was received while the master copy is saving all the data from the start. Thus, this becomes

an iterative process until the recoding comes to an end. More detailed explanations on how the

LabVIEW code is executed will be discussed in a later chapter.

2.3 Mathematical Background

To get a better grasp of the mathematical procedures used in thesis research study, it is

necessary to define some concepts ranging from general engineering mathematical operations

to statistical analysis.

2.3.1 The Fourier Transform

This mathematical procedure breaks down a complex signal or a waveform into its sine

and cosine and frequency domain representation [6] . In other words, the Fourier transform

converts a time signal into its frequency domain signal. In addition, an inverse Fourier transform

can be obtained from this process. The mathematical representation for the Fourier transform

and Inverse Fourier transform is by equation 1 and 2 respectively.

12

Page 23: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

𝐹(𝜔) = ∫ 𝑓(𝑡)𝑒−𝑖𝜔𝑡𝑑𝑡

−∞

(1)

𝑓(𝑡) =1

2𝜋∫ 𝐹(𝜔)𝑒𝑖𝜔𝑡𝑑𝜔

−∞

(2)

where 𝑓(𝑡) represents the signal being analyzed and 𝜔 represents the frequency component.

2.3.2 The Discrete Fourier Transform (DFT)

Any continuous time domain signal x(t) can be represented in a set of “n” samples forming

a discrete time signal x(n) to be able to be processed by a digital system. This process is called

discretization and often performed by a sampler. In mathematical computations, it is possible to

obtain the Fourier transform of a discrete time signal by applying a similar process as the Fourier

Transform in continuous time domain. An inverse transform also holds true for this process. The

mathematical representation on how to obtain the DFT and IDFT given by equation 3 and 4.

𝐷𝐹𝑇 𝑋(𝑘) = ∑ 𝑥(𝑛)𝑒−𝑖2𝜋𝑘𝑛

𝑁

𝑁−1

𝑛=0

𝑘 = 0,1,2,3,… ,𝑁 − 1

(3)

𝐼𝐷𝐹𝑇 𝑥(𝑛) =1

𝑁∑ 𝑋(𝑘)𝑒

𝑖2𝜋𝑘𝑛𝑁

𝑁−1

𝑛=0

𝑛 = 0,1,2,3,… ,𝑁 − 1

(4)

2.3.3 The Fast Fourier Transform (FFT)

The FFT mathematical computation has the same results like the DFT; however, the FFT

reduces the computation complexity by obtaining faster results than the DFT [7]. In the same

manner, an inverse FFT can be performed to return an N point discrete time domain signal x(n).

13

Page 24: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

2.3.4 Fourier Transform Digital Implementation

In this theses, all the Fourier transforms were obtained by using LabVIEW’s signal

processing package. This transform was uniquely used to capture the frequency components of

an EEG signal as it was recorded by the EMOTIV Epoc+ headset. In a later topic, a variation of the

FFT will be used to obtain the instantaneous frequency components of the empiric mode

decomposition (EMD) results. These instantaneous frequencies will determine the amount of

modes that fall in the 0-60 Hertz range.

2.3.5 Hilbert Huang Transform (HHT)

The use of the HHT is purely an empirical approach analysis that combines the empirical

mode decomposition and the Hilbert spectral analysis. This transform is designed to analyze

non-linear and non-stationary signal such as the EEG as it is in the case for this this research

project. Interestingly enough, the HHT transform provides much better results than the

traditional and well known time-frequency analysis techniques. Furthermore, the HHT has been

proven to reveal physical meanings in many of the data examined [8].

2.3.6 Empirical Mode Decomposition

The empirical mode decomposition (EMD) allows the extraction of important data in the

nonlinear and nonstationary signal in an intuitive and adaptive manner. As a result, the

representation of this empirical method is called intrinsic mode function (IMF). These IMFs

represent an oscillatory mode with a variable amplitude and instantaneous frequency as

functions of time [9]. An IMF should satisfy the following conditions:

14

Page 25: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

a. In the whole data set, the number of extreme points and the number of zero crossings

must either equal or differ at most by one.

b. At every point, the mean value of the envelopes defined by local maxima and local

minima is zero.

In order to decompose any nonstationary and nonlinear function into IMFs one must do

the following sifting process:

1. Get the local maxima and minima of the recorded signal 𝑥(𝑡).

2. Get the upper envelope (𝐸𝑚𝑎𝑥) by connecting all the local maximums of the recorded

signal using a cubic spline function. The Cubic spline function can be found in LabVIEW.

3. Repeat process 2 for the local minimums and produce the lower envelop (𝐸𝑚𝑖𝑛).

4. Calculate the mean value at every point of both upper and lower envelopes.

𝐸𝑚𝑒𝑎𝑛 =(𝐸𝑚𝑎𝑥 + 𝐸𝑚𝑖𝑛)

2(5)

5. Let ℎ(𝑡) = 𝑥(𝑡) − 𝐸𝑚𝑒𝑎𝑛. If ℎ(𝑡) satisfies the IMF condition, then go to step 6

else, repeat process 1-5

6. If r(t) is a monotonic function, end the sifting process, else x(t)=r(t) and go back to step

1.

15

Page 26: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 5: EMD Data, Mean, Upper and Lower Envelope

EMD works like an adaptive filter by shifting out the fastest changing component of a

composite signal first. The cutoff frequency of the filter is adaptive and data driven. IMFs are

generated in order of decreasing frequency. For example, IMF1 is the one-associated with the

locally highest frequency while the residue contains the lowest frequency. The main features of

the ictal EEG are closely related to the first few IMFs, and IMF1-IMF3 of each EEG segment are

used to extract the EEG features. [8]. Just like the sifting process describes, it is possible to see

that EMD is a very systematic, intuitive, and provides useful information about a given non-

stationary signal. For other types of studies, the EMD provides meaningful information that

reveals events in specific data.

It is essential to mention that this process has statistical methods to provide the

information we are looking for. The most important ones are mean (µ) and standard deviation

(𝜎) calculated using data from the IMFs. In the end, these two will serve to extract features from

the recorded EEG signal.

16

Page 27: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 6: EEG IMF1 though IMF5 example

2.3.7 The Hilbert Transform

Once the IMFs are obtained through the sifting process, one will have no difficulty in

applying the Hilbert Transform to each IMF component. The Hilbert transform is useful in

calculating instantaneous attributes of a time series, especially the amplitude and frequency [10].

The instantaneous amplitude is the amplitude of the complex Hilbert transform; the

instantaneous frequency is the time rate of change of the instantaneous phase angle. For a pure

sinusoid, the instantaneous amplitude and frequency are constant. The instantaneous phase,

however, is a saw-tooth, reflecting how the local phase angle varies linearly over a single cycle.

For mixtures of sinusoids, the attributes are short term, or local, averages spanning no more than

two or three points [11].

2.3.8 Instantaneous Frequency

Typically, non-stationary signals do not decompose themselves into sinusoidal

components. For our case, the idea of frequency losses its effectiveness; however, it is necessary

to take into account for the time varying nature of the process and thus giving birth to the

17

Page 28: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

instantaneous frequency [12]. Let 𝑓(𝑡) represent non-stationary signal as a function of time 𝑡.

The corresponding complex trace 𝑐(𝑡) is defined as:

𝑐(𝑡) = 𝑓(𝑡) + 𝑖 ℎ(𝑡),

(6)

where ℎ(𝑡) is the Hilbert transform of the real trace 𝑓(𝑡) [13]. One can also represent the

complex trace in terms of the envelope 𝐴(𝑡) and the instantaneous phase 𝜑(𝑡), as follows:

𝑐(𝑡) = 𝐴(𝑡)𝑐𝑖𝜑(𝑡)

(7)

By simple definition, instantaneous frequency is the time derivative of the instantaneous

phase[14]. Refer to the equation 8.

𝑤(𝑡) = 𝜑′(𝑡) = 𝐼𝑚 [𝑐′(𝑡)

𝑐(𝑡)] =

𝑓(𝑡)ℎ′(𝑡) − 𝑓′(𝑡)ℎ(𝑡)

𝑓2(𝑡) + ℎ2(𝑡)

(8)

2.3.9 Statistical Mean

In Mathematics and statistics, the mean is the summation of all the data divided by the

length number of data given in a specific set. That is,

𝜇 =(𝑥1 + 𝑥2 + 𝑥3 + 𝑥4 … .+𝑥𝑛)

𝑛(9)

or

18

Page 29: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

𝜇 = 1

𝑁∑𝑥𝑖

𝑁

𝑖=1

(10)

where n is the length number of the data set and x is the index value at the 𝑖𝑡ℎ position

However, for our purpose; the mean equation looks slightly different, but the result is the

same. The mean formula is given by equation 11

𝜇 = 1

𝑙 ∑ |𝐼𝑀𝐹(𝑗)|

𝑙

𝑗=1

(11)

where 𝑙 is the length of the data in each IMF and 𝑗 is the individual value of the IMF in the 𝑗𝑡ℎ

position.

2.3.10 Standard Deviation

As it has been mentioned several times, an EEG signal is nonstationary and non-linear.

This simply implies that the signal has the characteristic of being random and it should be treated

differently when calculating the standard deviation [8]. The formula is given by equation 12.

𝜎 = √1

𝑁[(𝑥1 − 𝜇)2 + (𝑥2 − 𝜇)2 + ⋯+ (𝑥𝑁 − 𝜇)2],

(12)

where 𝜇 = 1

𝑁∑𝑥𝑖

𝑁

𝑖=1

(13)

Once again, the standard deviation formula looks slightly different, but in theory both

equations are the same. The standard deviation formula in terms of IMF is the following:

19

Page 30: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

𝜎 = √1

𝑙∑ (𝐼𝑀𝐹(𝑗) − (

1

𝑙)∑ 𝐼𝑀𝐹(𝑗))2

𝑙

𝑗=1

𝑙

𝑗=1,

(14)

where 𝑙 is the length of the IMFs. In this research 𝑙 = 512, however; this number can vary or be

modified as needed. The number 512 was selected as it represents the number of samples being

processed at a time and is equivalent to two seconds of EEG data assuming a sampling frequency

of 256 samples per second.

Realistically speaking, not all EEG signal acquisition devices have the same sampling

frequency. The EMOTIV Epoc+ has a minimum sampling frequency of 128 samples per second

and a maximum sampling frequency of 256 samples per second. Consequently, most of the

numbers related to temporary stored data lengths will be multiples of 128. In a later chapter, it

is possible to see these numbers have an important role for this seizure prediction algorithm.

2.3.11 Feature Extraction

Feature extraction plays an important role in machine learning by providing details that

are not obvious to the naked eye. Common feature extraction techniques include histogram of

oriented gradients (HOG), speeded up robust features (SURF), local binary patterns (LBP), Haar

wavelets, and color histograms [15]. In machine learning and pattern recognition, features

contain relevant information that allows a prediction algorithm complete its task as efficient as

possible. However, for this thesis the most common feature extraction techniques will not be

explored or implemented.

In order to be able to predict whether an EEG signal has pre-ictal or non-ictal

characteristics, it is absolutely necessary to compute a few features to achieve our goal in this

20

Page 31: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

thesis research. The calculated features are the Variation Coefficient, Fluctuation index, and

instantaneous frequency.

2.3.12 Variation Coefficient

Having already introduced the standard deviation and the mean in terms of IMF data, we

are able to obtain one of the features in the EEG signal based on these two statistical elements.

To calculate the Variation Coefficient, the IMFs’ standard deviation is divided by the mean of the

IMFs’ data set [9]. That is

𝐶𝑉 =𝜎2

𝜇2

(15)

where 𝜎 and 𝜇 represent the standard deviation and the mean respectively.

In simple terms, the variation coefficient tells us about the variations of a signal

amplitude. Also, this CV is applied to the first few IMFs of the EEG signal to explore more patterns

[16]. In chapter 4, the coefficient of variation results will be presented for completeness of this

thesis research project.

2.3.13 Fluctuation Index (FI)

This index serves as a feature and is used to measure the changes in the intensity of a

given signal [17]. The formula for Fi is given by equation 16

𝐹𝑖 = 1

𝑙 ∑|𝐼𝑀𝐹(𝑗 + 1) − 𝐼𝑀𝐹(𝑗)|

𝑙

𝑗=1

(16)

where 𝑙 represents the length of the IMF and 𝑗 is the index value of the IMF.

21

Page 32: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Based on the experiments performed in LabVIEW, the Fi in the pre-ictal stage is typically

a lot higher than the normal non-ictal stage. This pattern tends to exist in the subsequent IMF’s

calculated in LabVIEW. For completeness, the fluctuation index results obtained in the LabVIEW

simulations will be discussed in a later chapter. Graphics will be also presented to back up the

results.

22

Page 33: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

2.3.14 Machine Learning Algorithms for Classification

Machine learning studies how to automatically learn to make accurate predictions based

on past observations [18]. Most classifications algorithms classify examples into set of categories;

however, the primary goal is to predict on test data.

Figure 7: Prediction Algorithm Flow Chart

Advantages of machine learning classifier:

Tend to be more accurate than human created rules.

Do not need a human expert.

The algorithm is flexible. It can apply to any kind of learning task.

Disadvantages:

Often require a lot of labeled data

Prone to errors- It is hard to get a perfect prediction accuracy

Labeled Training

Examples

Machine Learning Algorithm

Supervised/Unsupervised

Classification Rules

New Incoming

Examples

Predicted Classification

23

Page 34: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

2.3.15 Machine Learning Algorithms

Machine learning algorithms find statistical regularities or patterns in the data. The most

important thing is that the algorithms allow a computer to learn; however, these machine

learning algorithms barely resemble human approaches to learn a task [19]. Some algorithm

types include:

Supervised Learning--- the main goal for this algorithm is to classify a problem by mapping

inputs to desired outputs. The algorithm approximates the behavior of a data set based

on a labeled training data set.

Unsupervised Learning --- very similar to supervised learning; however, a labeled training

data set is not provided for classification.

Semi-supervised Learning---this type of learning algorithm is a combination of the

supervised and unsupervised learning algorithms.

Reinforcement Learning--- this type of algorithms learns as it goes. It learns from the

environment is exposed and gets feedback to guide the learning algorithm.

2.3.16 Supervised Learning

Supervised learning algorithms uses a known training data set in order to classify or make

predictions. This training data set contains the input and output values that allow the algorithm

to build a model to make predictions given a new dataset [20]. Also, the machine learning

algorithm has to be validated by a test data set in order to verify the prediction power of the

algorithm itself.

24

Page 35: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Most common classification methods are the following:

Support vector machines (SVM)

Neural networks

Decision trees

Discriminant analysis

Nearest neighbors

For this thesis research project, I have chosen to use the supervised learning algorithms

route. The classification method used in the LabVIEW code is the support vector machine (SVM)

which has proven to be more effective than other supervised learning algorithms. Other learning

algorithms will be tested out; however, the emphasis is on the SVM.

2.3.17 Support Vector Machine

In essence, a SVM is a mathematical entity. An algorithm or recipe for maximizing a

particular mathematical function with respect to a given collection of data [21]. The SVM is a very

common biomedical application to classify different objects and some of this objects can vary

from DNA sequences to EEG readings. Because the SVM has demonstrated great power in the

Biomedical Engineering field, this classification method will be used here.

Types of SVM:

Linear classification SVM

Nonlinear classification SVM

25

Page 36: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

2.3.18 Linear Classification SVM

A linear classifier separates a set of objects into their respective groups using imaginary

hyperplane lines [26]. These separating hyperplane lines are obtained through a training data set

that is considered to be linearly separable and the closest data points to the imaginary

hyperplanes are called support vectors. These hyperplanes are defined by the following

equations:

�⃗⃗� ∙ 𝑥 + 𝑏 = 1

(17)

and

�⃗⃗� ∙ 𝑥 + 𝑏 = −1

(18)

where �⃗⃗� is the normal vector to the hyper-plane [22].

However, the goal is to obtain a margin line that lies half way between both hyperplanes.

The margin line is obtained by calculating the maximum distance between both imaginary

hyperplanes. The maximum distance is calculated by the following formula:

𝑚 =2

‖�⃗⃗� ‖(19)

To maximize the value of 𝑚 , it is necessary to minimize the value of ‖�⃗⃗� ‖ [22]. In addition, it is

important that new data does not fall in between both imaginary separating hyperplanes

otherwise, there will be a misclassification problem.

26

Page 37: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 8:SVM Support Vectors and Separating Hyperplane

In order to use a typical SVM, it is necessary to have the following: first, a training data

set to build a model. Second, a testing data set to prove the model predicts with a certain level

of accuracy. Once these data sets are obtained, the SVM can be refined to achieve better

results. Despite the greatness of a linear SVM, it will not the most efficient classifier for this

thesis project.

2.3.19 Nonlinear Classification SVM

EEGs are typically very random data that in the long run have a defined pattern when

features are extracted. However, a few feature data points don’t follow an expected pattern all

the time. For instance, a pre-ictal EEG might contain two feature data points that follow a non-

ictal pattern. When these features are feed into a linear classifier SVM, it is possible to have a

misclassification problem simply because there cannot be a linear hyperplane as a decision

surface [23]. To solve this problem, a nonlinear SVM has to be implemented to obtain better

results. The Nonlinear SVM generates a nonlinear decision surface that can classify nonlinearly

separable data. In chapter 4, the reader can see similar nonlinear characteristics as in Figure 9.

27

Page 38: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 9: Nonlinear SVM example Data set [24]

2.4 LabVIEW Code

Designing or implementing code with LabVIEW provides an easier way to execute

functions in a systematic and a circuit type of building mechanism. As it has been mentioned

before, LabVIEW is a great tool for digital signal processing and so is the graphical user interface.

Without the real time user interface LabVIEW provides to the programmer, the outputs obtained

in a code (VI) would almost be meaningless to an external user.

Although LabVIEW offers and has many graphical user interface advantages, the portions

of a code could end up being a mess if proper LabVIEW programming techniques are not kept in

mind. In some cases, an organized code is almost impossible due to the complexity of the code.

The reader should be advised that certain figures could be hard to follow because of the

complexity of the code. Furthermore, an explanation of how certain parts of the code will be

provided. Next, a list on how the LabVIEW code is organized and implemented will be presented

hoping the reader fully understands the thought process of creating this epileptic seizure analysis

and prediction code.

28

Page 39: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

2.5 LabVIEW Code List

In order to create the code, the whole project is divided into three major different parts:

1. EMOTIV Epoc+ headset wireless connection to LabVIEW VI

2. Signal processing and Feature Extraction VI

3. Classifier SVM VI

2.5.1 EMOTIV Epoc+ to LabVIEW

The interfacing of the EMOTIV Epoc+ to LabVIEW VI is was accomplished using the

National instruments EMOTIV Toolkit. This VI allows the user to see most of the features provided

by the Xavier-Raw EEG while providing access to the raw EEG data being recorded. This toolkit

plots and saves data as a CSV file for immediate or later processing. The advantage of this VI is

that it allows initial communication link between the EMOTIV headsets and LabVIEW without

having to create a link communication VI from scratch.

Now, this VI is intended for simple applications such as EEG and data transmission

monitoring. All the EEG channels in the VI user interface are brought together into one window

displaying each channel with different colors to distinguish one channel from the other.

Displaying all channels in one window presented a few problems. First, there is no way to tell

which channel belonged to an electrode in the EMOTIV Epoc+ EEG. Second, the EEG raw data

needs to be accessed individually by channels to process the signal. In order for code to work,

the VI had to be modified and redesigned to meet the requirements needed for this research

thesis project.

29

Page 40: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

2.5.2 LabVIEW EMOTIV Toolkit V2

Before describing the modifications made to this VI, the following steps need to be

performed, to make this VI function according to National Instruments instructions:

1. Install the EMOTIV SDK software.

2. Have LabVIEW 2013 or above installed.

3. Localize the edk.dll file, this will allow the Epoc+ headset communicate with LabVIEW.

4. Run the VI in order to test functionality.

Figure 10: EMOTIV LabVIEW Toolkit VI (original Version) [25]

After applying all these changes, the EMOTIV Epoc+ must be on and the VI should be running to

display live EEG recordings. Figure 10 is a great representation of how the VI looks like when

the Epoc+ and the VI are capturing live data from all channels.Figure 10: EMOTIV LabVIEW

Toolkit VI (original Version)

2.5.3 EMOTIV Toolkit VI Modifications

First, it is necessary to look into the VIs block diagram to see the how the code was

organized. At specific points in the code, several indicators were placed to see what was

30

Page 41: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

happening when the code executed. Finally, the place where all the EEG channels signal come in

an array was found. To separate the EEG channel signals, an Index array function is added to

select the channels independently. An index array function was added 14 times to the original

signal coming from the LabVIEW EMOTIV interface sub VI EEG data.

Figure 11: Original Plot EEG sub VI

Figure 12: Modified Plot EEG VI

31

Page 42: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 12 shows the modifications made to the original code. Once the channels were

located, it was necessary to subtract 4000 to the incoming signals. If this number is not taken

away, then the amplitude of the digital signal would have been too high to display in LabVIEW’s

graphing window. Notice from Figure 11 that an amount of 4000 is also subtracted to all the

channels to avoid this problem. After the subtraction, the individual digital EEG signal-can be

visualized by adding a waveform graph visualizer. As soon as the waveform graph was added to

the block diagram, the graphical user interface or front panel is updated.

The goal was to save the EEG data every ‘N’ amount of samples into a CSV file. LabVIEW

provides a function that reads the amount of elements coming into an array and outputs that

number. When this element number reached any multiple of 2048, the code would output a

whole number.

The MATLAB script would then receive this whole number and check if the modulo of that

number was equal to zero or 0.5. If this statement was true, then the output ‘n’ equaled to one.

Otherwise, ‘n’ equaled to zero. The ‘n’ output was then transferred to a Boolean operator that

checked against another 1. If the ‘n’ output equaled to one, then a Boolean 1 would come at the

output. If the ‘n’ output was a zero, a Boolean 0 came at the output. This Boolean output

controlled the operation of the Case structure VI. The case structure VI changed according to the

numeric input given at the selector and executed a piece of code included in it. See Figure 14 for

reference.

32

Page 43: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 13: Front Panel EEG Signal Reader

Figure 14: Case Structure Example Help

Figure 15: Modified EEG Reader with Case Structure

33

Page 44: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

If the numeric input at the case structure selector of was a Boolean ‘1’, then case 1

executed by saving the data. If the input a was a Boolean ‘0’, then case 0 executed by doing

nothing. As this process happens, a similar code is running in parallel saving EEG data every 1280

samples. This number represents 5 seconds of EEG data assuming a sampling frequency of 256

samples in a second (5*256=1280). The MATLAB script works in the same way as the one

described earlier. Notice in

Figure 15, how the case structure changes for this part of the code by executing a similar code as

the one described before.

Figure 16:Modified EEG Reader with Case Structure Part 1

34

Page 45: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

In Figure 16 and Figure 17, we can see the case structure implementation executing a

different set of codes. Basically, there are two cases either case ‘one’ or case ‘two’. When case

‘one’ is executed, two things happen in parallel. First, the information is saved directly to a CSV

file and second, 512 samples of data are extracted from the buffer and saved to a separate CSV

file. If data is available at the time, the previous 512 samples are deleted so that only 512 samples

are stored in the CSV file. The EMD VI later reads this CSV file to execute the code as soon as the

EEG data is available.

Figure 17:Case Structure to Save 512 Recorded Samples

2.6 Hilbert Huang Transform and EMD

This section will serve as an explanation of the organization in the contents found in this

VI. In addition, the exact implementation will be briefly discussed as the sifting process has been

described in chapter 1.

The main idea of having this VI was to execute the EMD and Hilbert spectrum processes

to extract the characteristic features found in pre-ictal and non-ictal EEG data recordings. This VI

starts by reading the contents found in the CSV file saved by the previous Plot EEG VI. Then, EDM

35

Page 46: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

algorithm is executed and IMF outputs are displayed in an array format and graphs. This VI allows

the user to control the amount of IMFs displayed in LabVIEW’s user interface front panel. For

example, when the user selects ‘2’ modes, two results will be displayed in the front panel. Each

mode contains 512 results that will be transferred to section below in Figure 18.

Figure 18: Hilbert Huang Transform VI

The Hilbert transform sub VI receives this IMF data to compute the instantaneous

frequency components of the EEG signal. For each IMF data set, there will be a set of frequency

components at the output of the Hilbert transform sub VI [9]. The frequency components will

decrease as the amount of IMFs increases.

2.6.1 Feature Extraction

Once the IMFs were obtained using the EMD VI, the EEG data was analyzed from a

statistical point of view using LabVIEW Probability and statistic toolkit. Within this toolkit,

mathematical calculations such as the means, variance, and standard deviation can be performed

without the user having to create code out of scratch.

36

Page 47: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Since the EMD algorithm by nature provides several IMF modes, it was necessary to

create a code that would extract features depending on the number of modes present at the

output of the EMD code. If the user selects four IMF modes, then the feature extraction code will

be executed independently once per mode and a total of 4 sets of features will be saved to

memory. As mentioned in chapter 1, the features calculated are the ‘Coefficient of variation’ and

the ‘Fluctuation index’ which requires knowledge of the mean, variance, and standard-deviation

of each IMF obtained in an EEG segment. Each set of features is independently saved to separate

CSV file that will later be accessed by the user and the machine learning algorithm. Figure 19 and

Figure 20 provides a graphical representation of the code and the new front panel.

Figure 19: Fluctuation Index and Coefficient of Variation Extraction [26]

37

Page 48: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 20:Front Panel for EEG readings, IMFs, VC and FI

2.6.2 Support Vector Machine: Supervised Learning

A SVM is able to classify according to a training data set. This data set has been obtained

by the automatic feature extraction algorithm discussed before in this chapter. To obtain this

data set, it is necessary to extract features from continuous segments of non-ictal and pre-ictal

EEG signals and save them to a CSV file which the SVM code will be able to read as the code runs.

First, the known training data set (features) is loaded to the Machine Learning Techniques

(MLT) 3D plot VI, while at the same time another MLT SVM learn sub VI receives the same

information to learn about the features. The output of the MLT SVM learn goes to the input of

the MLT SVM eval sub VI. The MLT SVM eval also receives a test set (unknown set) that needs to

be classified according to training data set given at the beginning. Lastly, when the decision has

been made by the MLT SMV eval sub VI, a plot of the result is displayed with their corresponding

categories and color. The training data set and the unknown test data set are read and stored in

a CSV file for future use and reference. The LabVIEW code can be seen in Figure 21.

38

Page 49: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 21 SVM LabVIEW code Block diagram

2.7 Conclusion

Digital signal processing requires correct hardware and software to achieve the desired

goal. For instance, MATLAB is the software tool with the ability to read and process database

information that other software would not be able to do all in one package. LabVIEW facilitates

the coding process through a great user interface and the resources for signal processing are

enormous. In addition, the EMOTIV Epoc+ headset is an outstanding hardware providing state of

the art instrumentation electronics specialized for EEG studies and research.

In this chapter, the basic functionality of the different VI codes is explained as they

relate to the basic theory in chapter 2. The incorporation of three VI’s makes the task of data

acquisition, signal processing, and classification a simpler and fast way to obtain the desired

outcome. Once again, this chapter does not intend to explain how every single part of the code

works. However, this chapter gives the reader a basic idea on how the code was written and

39

Page 50: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

how the desired results were obtained. In the next chapter, the results will be discussed.

40

Page 51: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

CHAPTER 3

RESULTS AND DISCUSSION

In this chapter, my intentions are to explain the results obtained by all these VI codes.

These codes will be tested by using a data set containing both non-ictal and pre-ictal signals

obtained in an online EEG data base. The basic outline of the results will be the following: first, a

visual example of the EEG EMOTIV Epoch+ headset readings followed by the extraction of training

features using non-ictal and pre-ictal EEG signals. Second, the analysis on how a non-ictal and a

pre-ictal EEG signal differ from each other. Finally, a representation on how the support vector

machine performs data classification using a test data sets.

3.1 EEG Signal LabVIEW Reader

So far, the only way to read and process EEG signals is to transfer the data to a visualizer

interface. LabVIEW allows the EEG signals to be displayed without using an external software

provided by the creator of the EMOTIV headsets. In a previous section, the explanation of how

all the EGG signals are separated is provided. Figure 22 represents the result of the different

channels being displayed on separate windows.

Figure 22: EEG Signal LabVIEW Reader Front Panel

41

Page 52: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

3.2 Non-Ictal and Pre-Ictal EEG Signal Analysis

This section will provide an analysis based on the results obtained by visually inspecting

non-ictal and pre-ictal signals. In addition, feature extraction results will be discussed along with

its tendencies and how the support vector machine processed the data given at its input.

3.3 EEG Signal Visual Inspection

In this thesis project an online data set (Epilepsy Foundation) that contains non-ictal and

pre-ictal EEG signal readings is used to test different parts of the LabVIEW code. Because this

data set has not been obtained using any EMOTIV devices, it is important to plot samples of non-

ictal and pre-ictal signals to verify that data set used in this thesis project had proper and useful

EEG readings. With the help of MATLAB, I have plotted about 10 minutes of EEG data to inspect

this EEG signals. Figure 23 and Figure 26 contain a visual example of the EEG data found in the

both non-ictal and pre-ictal segments EEG database.

Figure 23: Ten Minute Non-Ictal EEG Reading

42

Page 53: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 24: Ten Minute Non-Ictal EEG Reading Continued

Figure 25:Ten Minute Non-Ictal EEG Reading Final

The EEG readings from Figure 23, Figure 24, and Figure 25 allowed me to see that this set

of segments contains good EEG readings; however, I was able to find segments of data that did

not contain any meaningful information to process. Let us look at the first few seconds of data in

Figure 26 to illustrate my point here. It is possible to see that the EEG signal does not exhibit EEG

patterns like those found in the Figure 23, 23, and 24. It is not until a few seconds later in the pre-

ictal set, that we are able to see some real EEG readings that contain useful information. Again,

this serves as an example of how useful the EEG recordings are in this online data set. Once good

segments of EEG signal readings were found, the information was exported to LabVIEW to extract

the training features for the Support Vector Machine.

43

Page 54: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 26:Ten Minute Pre-Ictal EEG Reading

Figure 27:Ten Minute Pre-Ictal EEG Reading Continued

Figure 28:Ten Minute Pre-Ictal EEG Reading Final Section

44

Page 55: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

3.4 EMD and Features

When good non-ictal and pre-ictal EEG readings were found, these signals were

independently loaded to the EMD VI to obtain the IMFs specified by the user. Figure 29 is an

illustration of the EMD at work when the IMF modes are set to five. Also notice how the EEG

signal and the EMD residue is being plotted as the algorithm reads 512 samples of data at a time.

Figure 29: EMD Front Panel with EEG, IMFs, and Features Display

3.5 SVM Training Data Set Analysis

The most important task is found in this section because without these information, there

is no way to predict whether an EEG signal falls in a non-ictal or pre-ictal class. To find a useful

training data set, known pre-ictal and non-ictal sets have been loaded to the feature extraction

VI (EMD). The following table represents a portion of the features extracted using the EMD VI

LabVIEW code.

45

Page 56: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Non-Ictal VC Non-ictal FI Pre-ictal VC Pre-ictal FI

2.719 4.473 1.705 5.536

2.144 3.874 1.832 5.187

2.929 4.02 2.453 6.331

2.628 3.953 1.587 5.949

2.757 5.772 1.951 5.36

2.282 4.358 2.118 6.716

3.94 4.988 2.466 6.703

2.209 5.558 2.101 5.663

2.017 4.171 2.866 7.364

2.29 4.851 3.499 7.303

1.79 4.732 1.773 5.559

2.046 4.386 1.701 5.507

5.969 5.071 1.825 6.725

3.283 4.651 1.522 5.29

2.977 4.469 2.81 5.965

3.567 5.341 2.048 5.63

2.283 4.144 1.616 5.472

2.714 4.591 1.833 5.989

46

Table 3.1: Features extracted using the EMD VI LabVIEW code.

Page 57: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

This table does not represent all the values that resulted from the EMD code feature

extractor. A total of 584 set of features were extracted; however, table can be lengthy for

demonstration purposes. Figure 30 and Figure 31 represent the difference in amplitudes of a

non-ictal and pre-ictal Variation coefficient and Fluctuation index.

Figure 30:Variation Coefficient: Non- Ictal and Pre-Ictal Values

From the graph above, it is possible to see that the average Variation Coefficient in the

non-ictal EEG signal can be higher than the Pre-ictal EEG signal. However, the amplitude

difference is not as much as expected. In some cases, the Pre-ictal signal is higher in few

instances.

47

Page 58: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Figure 31:Fluctuation Index: Non-Ictal and Pre-Ictal Values

The fluctuation index for both of these type of EEG signals is significantly different in

amplitude. The non-ictal EEG shows much more fluctuations than the Pre-ictal signal. This causes

a relief, since it is possible to see a feature that shows a difference in both types of EEG signals.

A more interesting result is seen in Figure 31, when the all these data is plotted seeing the

“Variation Coefficient Vs Fluctuation Index” graph using LabVIEW.

In a study found in [9], similar results were obtained for the classification of inter-ictal and

ictal EEGs. Refer to Figure 32. The coefficients of variation in the ictal EEG are lower than those

found in inter-ictal EEG segments.

Figure 32 Variation Coefficients for Ictal and Inter-ictal EEG segments

48

Page 59: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

In Figure 33 , the fluctuation index in the inter-ictal EEG segments appear to be lower than

those in ictal EEG segments.

Figure 33 Fluctuation Index for Ictal and Inter-Ictal EEG segments [9].

Looking at the results in Figure 32 and Figure 33, it is possible to see that the results

obtained in this thesis project are not far from other ones.

Figure 34:Variation Coefficient Vs Fluctuation Index Plot

The green dots represent non-ictal features and the red dots represent the pre-ictal

features. Outstanding results can be seen in Figure 34, as the non-ictal features are clustered

together in the same area and the pre-ictal features are clustered close to each other in a

different area. There are some non-ictal and pre-ictal features that fall within a cluster of data

49

Page 60: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

that does not belong to their corresponding group. To fix this problem, non-ictal features and

pre-ictal features values are subtracted to see how much they differ from each other; therefore,

only keeping those features that contain the most difference in value. As a result, the refinement

of the training data set was achieved. The following table contains the difference non-ictal and

pre-ictal features with highlighted values were deleted.

Non-Ictal VC Pre-ictal VC Difference Non-ictal FI Pre-ictal FI Difference

2.719 1.705 1.014 4.473 5.536 1.063

2.144 1.832 0.312 3.874 5.187 1.313

2.929 2.453 0.476 4.02 6.331 2.311

2.628 1.587 1.041 3.953 5.949 1.996

2.757 1.951 0.806 5.772 5.36 -0.412

2.282 2.118 0.164 4.358 6.716 2.358

3.94 2.466 1.474 4.988 6.703 1.715

2.209 2.101 0.108 5.558 5.663 0.105

2.017 2.866 -0.849 4.171 7.364 3.193

2.29 3.499 -1.209 4.851 7.303 2.452

1.79 1.773 0.017 4.732 5.559 0.827

2.046 1.701 0.345 4.386 5.507 1.121

5.969 1.825 4.144 5.071 6.725 1.654

3.283 1.522 1.761 4.651 5.29 0.639

2.977 2.81 0.167 4.469 5.965 1.496

3.567 2.048 1.519 5.341 5.63 0.289

2.283 1.616 0.667 4.144 5.472 1.328

2.714 1.833 0.881 4.591 5.989 1.398

1.859 2.428 -0.569 4.016 5.622 1.606

2.472 1.658 0.814 4.442 6.872 2.43

2.146 2.787 -0.641 3.731 7.56 3.829

2.036 2.373 -0.337 4.16 6.688 2.528

2.219 1.578 0.641 5.077 6.216 1.139

2.469 3.243 -0.774 4.25 6.345 2.095

2.418 4.04 -1.622 4.191 6.514 2.323

4.257 1.639 2.618 5.037 6.037 1

2.18 2.498 -0.318 4.051 5.453 1.402

2.447 1.68 0.767 4.352 5.334 0.982

50

Table 3.2: Differences between non-ictal and pre-ictal features.

Page 61: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

Again for simplicity, Table 3. 2 is not completely displayed. As it can be seen in this table,

the highlighted features were deleted to get rid of some features that do not contain significant

information.

Figure 35:SVM Refined Training Data Plot

If Figure 34 and Figure 35 are compared against each other, it is possible to appreciate

how some of the non-ictal and pre-ictal features do not overlap on each other as much as before.

My hopes are that with this result, the SVM can predict with better accuracy than using the

previous training data set. Now, let us see the predicting results of the SVM using this new

training data set.

To test this training data set, the same training data containing only the non-ictal values

is used. The expected result is that the SVM will recognize the only the non-ictal values (green

dots) at the output graph. After running the SVM VI, the results were as expected. There are a

51

Page 62: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

few non-ictal points that were misclassified as pre-ictal (red dots); however, the SVM classified

most of the data as non-ictal. Figure 36 contains the graphical representation of the results.

Figure 36: SVM Classifier Test 1

A similar test was done to test if the SVM classified the pre-ictal values correctly. To

achieve this, another test data set was created only containing pre-ictal values in it to verify the

accuracy of the SVM. After running the SVM VI, the results obtained were as expected. Once

again, some pre-ictal values were misclassified by the algorithm. Figure 37 contains the graphical

results of the SVM.

Figure 37:SVM Classifier Test 2

52

Page 63: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

CHAPTER 4

COMMENTS, FUTURE WORK, AND CONCLUSION

4.1 The Next Generation

At the very beginning, the main idea for this project was to have a cellphone application

that would directly connect to the EMOTIV Epoc+ headset to perform signal processing and be

able to detect epileptic activity from there. As time passed, this idea seemed almost impossible

for me as I was not very acquainted with cellphone application development; however, the idea

of having a local epileptic detection system was still implementable in a different platform with

a different processing source which in this case is a normal computer. As we know, almost

anybody in the United States has a home computer and the idea of implementing an epileptic

detection system became more feasible and doable. Over time, the idea of having a local epileptic

detection system grew more and more as this technology could be used in hospitals and local

care centers.

Despite the greatness of having a local epileptic detection software, the issue comes

when we think about those young college students and active adults who struggle and fight with

epilepsy. Whatever the case is, a next generation of portable epileptic detection system will be

developed using our everyday cellphone and an aesthetical engineered headset.

4.2 Other Considerations

In most of the EEG’s collected for this thesis project, the test individual was instructed not

to talk or make any facial movement that would affect the integrity of the EEG signal. The reality

is that if we are to develop an epileptic detection system, it is necessary to consider facial

53

Page 64: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

movements that change the raw EEG reading. In future works, if we want to develop a more

precise local or mobile epileptic detection systems then, it is imperative to consider EMG signals

and EOG signals. An EMG would detect facial movements and EOG would detect ocular

movements (a.k.a artefacts). These facial and ocular movements happen all the time and cannot

be ignored if we want to achieve a more precise epileptic detection system. The EMG and EOG

will have to be subtracted from the actual EEG; however, this implies that a more sophisticated

instrumentation hardware will need to be developed to capture all these signals at once and

make the appropriate subtraction when needed.

4.3 Future Work

In the following sections, I had written out some ideas, comments, and input from an

epileptic patient and a Cardiologist. My biggest hope is that I can take all this information and

make it a reality once I have achieved a more effective system.

4.3.1 A Doctor's Recommendation

In the fall of 2015, I had the chance to meet Dr. Alo, a cardiologist who practices in Denton,

Texas and a member of the University of North Texas Biomedical Engineering Board committee,

proposed a great idea based on previous experience. He commented that some

doctors/neurologists don’t necessarily want a system that predicts whether a patient could have

an epileptic seizure or a heart attack. A doctor/neurologist may want to see other characteristics

or features in the recorded signal to better analyze and diagnose a patient’s condition.

This implies that a separate study must be performed to obtain the results doctors really

want to see. To achieve this goal in the near future, an extensive set of interviews to doctors and

54

Page 65: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

EEG specialists must be conducted to obtain a better understanding of their needs. Based on

their needs, then a new system can be implemented and who knows, maybe current epileptic

prediction algorithms are somewhat close to what doctors are wanting to have in hospitals.

4.3.2 A Patient’s Perspective

Early in the fall semester of 2016, a freshman student from biomedical engineering

expressed interest in the study of epilepsy. The student mentioned that she struggled with

epilepsy and she was more than welcome to answer any questions regarding her experience with

epilepsy. However, I want to note that this student volunteered and that neither me or the

biomedical engineering department has forced her to answer or provide other information for

this research.

For the purpose of this research and future research, I have asked her a set of questions

and she provided a response.

1. Have you felt any physical discomfort before a seizure? Describe what you have felt?

a. Roughly thirty seconds to a minute before my first seizure I felt something weird

that I now know is an aura. An aura is a sensation or a warning that happens right

before a seizure and they are different for everyone, of course. It was 2007 and I

was nine and my mom and I were shopping, I walked to her and I told her

“something is not right” and I went into Grand Mal seizure. Later I was able to

describe what I felt beforehand. I felt as if my entire body was shutting down, I

thought I could feel every system in my body wanting to stop. The next I remember

is waking up on the floor surrounded by strangers staring at me and crying while

55

Page 66: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

mom told me what happened and that paramedics were on the way. I now

describe my aura as “feeling off”. May of 2015 I had another Grand Mal seizure.

I had a normal day at school and came home to take a short nap. This nap turned

into a four-hour nap that I almost would not wake up from. I finally got out of bed

to try to eat something but I could not hold a conversation or keep my eyes open

to eat. At this time, I should have realized that was my warning but I was in denial.

My mom made me follow her to her bedroom, the great mom and nurse inside

her knew something was wrong, as she showered I sat next to a cabinet in her

room so she could know if something happened. I was trying to hold a

conversation and trying to text a friend so I could keep myself distracted from the

feeling a possible seizure. The last thing I remember before that seizure was

setting my phone on the counter, my mom said I began to seize then I hit my

forehead on the cabinet. The next thing I remember was crying on the floor while

the paramedics lifted me on a stretcher. I had a hard time making sentences,

remembering names, objects, and just generally my brain was not functioning

correctly for about two weeks because I had seizure brain activity for about three-

five hours. My next Grand Mal seizure was December 2015 on a road trip. I had

fell asleep against the window in the back seat, without anything covering the

window or my eyes, and while I was asleep we went down a road with trees (which

will make more sense in question 3). For this seizure I had no aura because I was

asleep and never woke up for it. I was told that we pulled over, and there was no

way to call for help in case the seizure lasted longer than four minutes, and my

56

Page 67: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

mom and her husband pulled me into the ditch so she could safely administer my

Diastat valium syringe to stop the seizure. They said the seizing stopped but I was

still unresponsive when I threw up, a side effect from the valium apparently. Just

like before when I woke up I was disoriented, crying, and extra confused since the

last thing I knew was that I was asleep.

b. So basically my aura causes discomfort but I do not smell or see anything distinct

like some epileptics do. I begin to feel disorientated, dizzy, my fingers twitch, my

vision is not clear. There is no clear way to describe it honestly, I know when it is

about to happen but all I can describe it as is “I feel weird, I feel off”. So I am not

sure if that can be considered physical but it is certainly uncomfortable.

2. Can you describe the physical implications after a seizure? If any.

a. I have been lucky enough to not have broken any bones or have any major injuries

after seizures, especially considering my first seizure I was next to a wall of glass

cases. I had a bruised forehead had memory loss for two weeks after my second

Grand Mal seizure. I have had a few Absence seizures, also known as Petit Mal,

but the most painful Absence I had was while playing softball. I was a catcher and

I spaced out for a few seconds and got hit right between the eyes with a 70 mph

pitch (even though I had my catcher’s mask on it hurt horribly). After any kind of

seizure or “abnormal brain activity”, I am always extremely sore all over

afterwards for days and sometimes weeks; I feel as if I have been run over by a

train.

3. Based on your experience, what do you think triggers your epilepsy?

57

Page 68: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

a. The triggers my neurologists always warn me about are lack of sleep, missed

medicine, and flashing/strobe lights. Sadly, they have all proven to be true. My

epilepsy was not passed down through generations but instead I had a seizure one

day that happened to be epileptic, therefore no one has a reason as two why I had

my first seizure. My second Grand Mal was from missed medicine. It was my fault

considering I had 14 days’ worth of medicine left in a 30-day bottle at the end of

the month. My third Grand Mal seizure was a combination of lack of sleep, missed

medicine, and flashing lights. I was not taking my medicine on time, we were on

a road trip so I wasn’t sleeping on a normal schedule, and I fell asleep against the

car window with the sunlight (strobe light style). Now on road trips I bring a mask

and I take my medicine at 7 a.m. and 7 p.m. to keep a steady 12-hour interval

between doses.

I, "Jane Smith" (pseudonym), willingly volunteered to answer these questions.

These questions were asked because we would like to know how the body responds

before and after a seizure. As a researcher, I would like to know if there are other parts of the

body that could provide useful information to detect an epileptic seizure other than the

conventional EEG readings.

4.3.3 Personal Comments

Based on Jane’s response, I found really interesting the “Aura” feeling she

experienced minutes before her seizure. My intuition tells me there could be some sort of

relationship between pre-ictal activity and this so called “Aura” sensation/warning. In Jane’s

58

Page 69: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

December 2015 seizure incident, she was asleep while the seizure occurred. I believ, if there is

such a relationship between pre-ictal activity and the aura sensation and if she had been using

an EEG device connected to an epileptic seizure prediction system, this situation could have been

handled better or avoided.

On a different question, Jane said that lack of sleep and medication timing play an

important role when it comes to avoiding possible seizures. Current technology already tracks a

person’s sleep cycles, so the incorporation of this feature could be easily added to a future

system.

4.3.4 Emergency Response Protocol

The ultimate goal is to have mobile system that is able to predict an epileptic seizure. In

addition, the system should be able to keep a log of events in case an epileptic seizure happens.

Furthermore, the mobile system should have an “Emergency Response Protocol” feature. This

protocol should be activated once the pre-ictal activity is detected. The seizure emergency

protocol should automatically perform the following:

1. Contact a local or personal nurse. If applicable.

2. Call 911 for transport.

3. Notify a close relative or an emergency contact.

4. Notify a doctor/neurologist.

5. Administer emergency medications if available.

59

Page 70: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

4.3.5 A Mobile Phone Application

Currently, the EMOTIV headset devices do not count with an official phone application

that is able to directly process EEG signals using digital signal processing techniques. Such

application must be able to do the same things that were accomplished using LabVIEW, including

the SVM classification algorithm. See Figure 38 for more details. As of now, a high school student

from Frisco, Texas has been working on this mobile application. However, his goal is to establish

a direct connection from the EMOTIV headset device to the mobile app. No signal processing

techniques has been applied to this app. In my opinion, the more people working on this

research, the faster we can reach the goal of having a mobile seizure prediction system.

Figure 38: Block Diagram Cellphone App Feature

4.3.6 Adaptation of an EMOTIV Headset

The reason why the EMOTIV headset needs to be modified is because not a lot of people

want to expose the fact they have an electronic device on their heads. One way to solve this

aesthetical problem is to adapt the EMOTIV device into a hat which will conceal most of the

electrodes found in current EMOTIV devices. Electronic hardware and antennas will have to be

60

Page 71: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

placed outside the hat to avoid communication problems or exposure to bodily liquids such as

sweat. Also, proper isolation must be provided to avoid external liquids going into the electronics.

Many ideas like mine have been designed, but none of them are as efficient as the EMOTIV

headset devices. However, in the near future; I would like to take the challenge of designing a

device like the one I have described.

4.4 Conclusion

The pursuit of epilepsy detection can offer a lot relief to those who struggle with it. As

algorithms and techniques to detect these seizures arise every year, it is necessary to always keep

in mind that not everybody who has a form of epilepsy experiences the same effecs. Therefore;

more research has to be done to fully understand the mechanics of epileptic EEGs. In this thesis,

I have gained more understanding about epilepsies, seizures, and EEG signal processing;

however, there are more experiments that need to be conducted like live EEG signal recording

of an epileptic seizure. The implications and the risks of having an in house experiment like this

one are really high and should be done with the consent of the patient and an experienced

neurologist. Now, this type of experiment can be done; however, it could take months to find a

patient who is willing to collaborate and permission from the Internal Review Board at the

University of North Texas. On a different note, the epileptic seizure detection algorithm that I

have put together in this thesis project needs more modifications to perform better in different

conditions. Thus, I will continue my research in this really hot topic and eventually pass the

knowledge I have gained to upcoming researchers. I can only imagine on the day, people using a

system like this to prevent seizures that could have led to the death of a person.

61

Page 72: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

The whole idea of this project was to implement a digital system that anyone at home can

have access from a computer. Also, my idea was to have a practical system in which anyone

interested in this topic could easily learn the mechanics of the seizure detection. This thesis

project allowed me to take several conceptual topics in signal processing and machine learning

to a practical realization of a system that uses both hardware and software. In addition, the idea

of having LabVIEW as a signal processing tool proved to be the most efficient. Not only facilitated

the creation of a graphic user interface of the system, but also makes it easier to teach new

incoming researchers how to use or change the algorithm. I believe, it is also important to

mention that a system like this should be expanded to mobile versions while taking the advantage

of cell phones processing power.

In conclusion, the use of a system like will change many people’s lives and hopefully

overcome the fear of an epileptic seizure attack. As I have mentioned in previous chapters, EEG’s

are naturally random signals; however, they do have features like the fluctuation Index and

variation coefficient that provide significant differences between a non-ictal EEG or a pre-ictal

EEG. Notice, I have left out instantaneous frequency as a feature for now. Needless to say,

frequency analysis should not be left out as feature for future experiments. The results obtained

from the SVM non-linear classifier yield good results when tested with non-ictal and pre-ictal EEG

signals in database. The amount of time to process two to four seconds of EEG data through the

whole code takes about 2 seconds. This almost instantaneous results could potentially warn a

patient with enough time to take precautionary actions. Finally, the decision factor/threshold on

the ratio of non-ictal and pre-ictal features in the same EEG reading to decide whether a person

62

Page 73: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

could potentially be experiencing a pre-seizure activity needs to be determined by an

experienced neurologist.

63

Page 74: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

REFERENCES

[1] C. Controls, "EEG – Electroencephaloraphy with LabVIEW and Mindwave Mobile," July

2015. [Online]. Available: http://cerescontrols.com/projects/eeg-electroencephalography-

with-labview-and-mindwave-mobile/.

[2] Epilepsy Foundation of America, Living with Epilepsy and Seizures, 2015.

[3] Neurolex, "Non-ictal," 2009 May 2009. [Online]. Available:

http://neurolex.org/wiki/Category:Non-ictal.

[4] M. Teplan, "FUNDAMENTALS OF EEG MEASUREMENT," 2002. [Online]. Available:

http://www.measurement.sk/2002/S2/Teplan.pdf. [Accessed August 2016].

[5] EMOTIV Inc., "Epoc+," 2016. [Online]. Available: https://www.EMOTIV.com/epoc/.

[6] Bevel, "Fourier Transform," [Online]. Available: http://www.thefouriertransform.com/.

[7] J. W. Cooley, "The Re-Discovery of the Fast Fourier Transform Algorithm," Mikrochimica

Acta, pp. 33-45, 13 October 1987.

[8] N. E. Huang, "INTRODUCTION TO THE HILBERT HUANG TRANSFORM AND ITS RELATED

MATHEMATICAL PROBLEMS," Interdisciplinary Mathematical Sciences , pp. 1-26, 2014.

[9] S. Li, W. Zhou, Q. Yuan, S. Geng and D. Cai, "Feature extraction and recognition of icta

lEEG using EMD and SVM," Computers in Biology and Medicine, pp. 807-816, 2010.

64

Page 75: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

[10] F. R. Kschischang, 22 October 2006. [Online]. Available:

http://www.comm.utoronto.ca/frank/papers/hilbert.pdf.

[11] Mathworks, "Discrete-time analytic signal using Hilbert transform," 2016. [Online].

Available: http://www.mathworks.com/help/signal/ref/hilbert.html.

[12] S. Fomel, "Local seismic attributes," Geophysics, pp. 1-8, 02 March 2007.

[13] B. BOASHASH, "University of California," 4 April 1992. [Online]. Available:

https://www.math.ucdavis.edu/~saito/data/sonar/boashash1.pdf.

[14] Taner, M. T., F. Koehler and R. Sheriff, "Complex seismic trace analysis: Geophysics,"

Geophysics, pp. 1041-1063, 1979.

[15] MathWorks, "Feature extraction for compact representation of image data in computer

vision," 2016. [Online]. Available: http://www.mathworks.com/discovery/feature-

extraction.html.

[16] S. Ren and A. Fan, "K-means Clustering Algorithm Based On Coefficient Of Variation," 4th

International Congress on Image and Signal Processing, pp. 2076-2079, 2011.

[17] Mitha.M, S. S. S and M. V, "Automated Epileptic Seizure Detection using Relevant Features

in Support Vector Machines," International Conference on Control, Instrumentation,

Communication and Computational Technologies (ICCICCT), pp. 1000-1004, 2014.

65

Page 76: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

[18] R. Schapire, "Machine Learning Algorithms for Classification Machine Learning Algorithms

for Classification," [Online]. Available:

http://www.cs.princeton.edu/~schapire/talks/picasso-minicourse.pdf.

[19] T. O. Ayodele, "Types of Machine Learning Algorithms," [Online]. Available:

citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.469.8077&rep=rep1&type=pdf.

[20] M. L. MathWorks, "Machine learning technique for building predictive models from

known input and response data," 2016. [Online]. Available:

https://www.mathworks.com/discovery/supervised-learning.html.

[21] W. S. Noble, "What is a support vector machine?," Nature Biotechnology, pp. 1565-1567,

2006.

[22] Wikipedia, "Support vector machine," 10 October 2016. [Online]. Available:

https://en.wikipedia.org/wiki/Support_vector_machine#Linear_SVM.

[23] K. Chin, "Nonlinear Support Vector Machine," 10 September 1998. [Online]. Available:

http://svr-www.eng.cam.ac.uk/~kkc21/thesis_main/node14.html.

[24] A. Sharma, "Support Vector Machine without tears," 7 August 2014. [Online]. Available:

http://www.slideshare.net/ankitksharma/svm-37753690.

[25] Cassani, "LabVIEW EMOTIV Toolkit V2," 3 December 2014. [Online]. Available:

https://decibel.ni.com/content/docs/DOC-40699.

66

Page 77: Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and …/67531/metadc955040/... · Medina, Oscar Ferney. Analysis of Pre-ictal and Non-ictal EEG Activity: An EMOTIV and

[26] StatSoft, "Support Vector Machines Introductory Overview," 2016. [Online]. Available:

documentation.statsoft.com/STATISTICA. [Accessed 13 August 2016].

67