You are on page 1of 49

Real-Time Processing of EEG Signals for Mobile Detection of Seizures

Colm Seale
B.E. Electronic & Computer Engineering Project Report

EE426

Supervisor: Prof. Edward Jones

Co-assessor: Dr. Gearid Laighin

March 2012

Page |i

Abstract
The following is a Project Thesis titled Real-Time Processing of EEG Signals for Mobile Detection of Seizures. Discussed in the report are the main aims and objectives of the project and the results achieved and conclusions drawn throughout the course of the project. The overall aim of the project is to design an algorithm that will read signal data from an EEG source and process this data to determine if the person is undergoing an epileptic seizure. This program will be ported to mobile devices. The aim is to find a balance between the performance of the algorithm employed in detecting seizures and the amount of processing required to calculate the presence of seizure. The project also aims to investigate the effect of compression of EEG signal data on the overall effectiveness of the seizure detection algorithm. This report will detail some of the methods and procedures taken for developing algorithms, what milestones were reached and results from testing and development. The results demonstrate the feasibility of implementing seizure detection on a smart phone platform, and furthermore, significant compression of the EEG signal is possible without loss of diagnostic data. Thus, the outcome of the project supports the possibility of significantly enhancing the range of technology available to support mobile healthcare.

P a g e | ii

Declaration of Originality
I declare that this thesis is my original work except where stated.

Date: ___________________________________

Signature: ___________________________________

P a g e | iii

Acknowledgements
The author would like to acknowledge the help and support I received throughout the project from my project supervisor Dr. Edward Jones. The author would also like to thank Gary Higgins for his input and Dr. Liam Kilmartin for his assistance at various points throughout the project. This project would not have been possible without the support of my fellow 4th EE/ECE classmates. Finally, the author would like to thank my parents for their continued support over the last 4 years.

P a g e | iv

Table of Contents
Abstract.......................................................................................................................................... i Declaration of Originality .............................................................................................................. ii Acknowledgements ..................................................................................................................... iii Table of Figures............................................................................................................................ vi Figures...................................................................................................................................... vi Tables ...................................................................................................................................... vii Equations ................................................................................................................................ vii Glossary ..................................................................................................................................... viii 1. Project Introduction.............................................................................................................. 1 1.1 1.2 1.3 1.4 1.5 1.6 2. Background ................................................................................................................... 1 Aims .............................................................................................................................. 1 Project Milestones ........................................................................................................ 2 Health and Safety Issues ............................................................................................... 2 Project Timeline ............................................................................................................ 3 Thesis Outline ............................................................................................................... 4

Project Components ............................................................................................................. 5 2.1 2.2 2.3 Project Hardware .......................................................................................................... 5 Project Software ........................................................................................................... 7 Data Sources ................................................................................................................. 9

3.

Algorithm Development (MATLAB) .................................................................................... 12 3.1 3.2 3.3 3.4 3.5 3.6 Introduction ................................................................................................................ 12 Algorithm Design ........................................................................................................ 12 Algorithm Development ............................................................................................. 13 Classification in MATLAB ............................................................................................ 15 Pre-Processing ............................................................................................................ 17 Results......................................................................................................................... 19

Linear Discriminate Analysis: .............................................................................................. 19 Support Vector Machine:.................................................................................................... 20 3.7 4. Conclusions ................................................................................................................. 20

Mobile System Development ............................................................................................. 21 4.1 Introduction ................................................................................................................ 21

Page |v

4.2 4.3 3.5 3.6 3.7 5.

Java Development....................................................................................................... 21 Programs ..................................................................................................................... 22 Emotiv EPOC Development ........................................................................................ 26 Results......................................................................................................................... 28 Conclusions ................................................................................................................. 29

Compression of EEG Data ................................................................................................... 30 5.1 5.2 5.3 5.4 Introduction ................................................................................................................ 30 Method of Study ......................................................................................................... 30 Results......................................................................................................................... 32 Conclusions ................................................................................................................. 33

6.

Discussion ........................................................................................................................... 34 6.1 Introduction ................................................................................................................ 34

6.2 Discussion ......................................................................................................................... 34 6.3 Conclusion................................................................................................................... 35

References .................................................................................................................................. 37 Appendix ..................................................................................................................................... 39 A.1 HTC Wildfire Specifications: ............................................................................................. 39 A.2 MATLAB Filter Code.......................................................................................................... 39 A.3 Wildfire Bluetooth Code Problem .................................................................................... 40

P a g e | vi

Table of Figures
Figures
Figure 1-1: Gantt chart of Project Timeline .................................................................................. 3 Figure 2-1: MATLAB processing EEG data..................................................................................... 8 Figure 2-2: Image demonstrating the different areas in an Ictal signal file taken from the Freiburg Database....................................................................................................................... 10 Figure 3-1: Block Diagram of Seizure Algorithm ......................................................................... 12 Figure 3-2: Graphs showing EEG Ictal signal [top]; power spectra [second from top]; Shannon [centre] and Kullback-Leibler [second from bottom] entropies; Relative Band Ratios [bottom] .................................................................................................................................................... 13 Figure 3-3: Visual representation of EEG data for the raw signal and Hjorth parameters......... 15 Figure 3-4: LDA Classifier Performance of Raw Signal compared to Pre-Processed Signal ........ 17 Figure 3-5: SVM Classifier Performance results of Raw Signal compared to Pre-Processed ..... 17 Figure 3-6: A visual example of a pre-processing algorithm for raw EEG signals for seizure ..... 18 Figure 3-7: Raw EEG (Top) vs. Filtered EEG (Bottom) ................................................................. 18 Figure 3-8: Frequency Response of MATLAB Band-Pass Filter ................................................... 19 Figure 4-1: Flowchart showing high-level design ....................................................................... 24 Figure 4-2: Flowchart of Real-Time System Loop ....................................................................... 24 Figure 4-3: Application Screen Captures; Application requesting Bluetooth [left], Scanning for devices [centre], Classifying data [right] .................................................................................... 26 Figure 4-4: Results output of the Nave-Bayes Classifier using the evaluateModel function from WEKA libraries ............................................................................................................................ 28 Figure 4-5: PowerTutor measurements of Seizure Detection App; Power usage over a period of 10 seconds [left] and Power usage as a percentage of whole application [left]........................ 29 Figure 5-1: Comparison of EEG Signal at varying CR .................................................................. 31 Figure 5-2: Pseudo-Code for calculation of CR ........................................................................... 31 Figure 5-3: Percentage Root-Mean-Squared Deviation vs. Compression Ratio using SPIHT Compression ............................................................................................................................... 32 Figure A-1: Code used to design MATLAB Filter Coefficients ..................................................... 39

P a g e | vii

Tables
Table 2-1: Comparison of two available consumer EEG Hardware options ................................. 6 Table 2-2: Comparison of EEG Data Sources .............................................................................. 11 Table 3-1: Results of LDA Classifier on Original Signals ............................................................. 19 Table 3-2: Results of LDA Classifier on Original Signal................................................................ 20 Table 5-1: Performance of LDA Classifier vs. CR ......................................................................... 32 Table 5-2: Performance of SVM Classifier vs. CR ........................................................................ 33 Table A-1: Specifications of HTC Wildfire. .................................................................................. 39

Equations
Activity .................................................................................................................................................. 14 Mobility ................................................................................................................................................. 14 Complexity ............................................................................................................................................ 14 Sensitivity .............................................................................................................................................. 16 Specificity .............................................................................................................................................. 16 Correct Rate .......................................................................................................................................... 16 Standard Deviation ............................................................................................................................... 21 Derivative of a Signal ............................................................................................................................ 22

P a g e | viii

Glossary
API Application programming Interface CR Compression Ratio CSV Comma Separated Values EEG Electroencephalography JNA Java Native Access JNI Java Native Interface IDE Integrated Development Environment LDA Linear Discriminate Analysis PRD Percentage Root mean Squared Distortion SDK Software Development Kit SPIHT Set Partitioning in Hierarchical Trees SVM Support Vector Machine

Page |1

1. Project Introduction
1.1 Background

With the increasing cost and demands made of healthcare infrastructure and services, there is significant interest in the development of technology that can help to detect medical problems at an early stage, where successful (and lower cost) intervention is more likely. In particular, there is growing interest in the development of wearable or ambulatory systems for monitoring and analyzing various biological signals. A key requirement of such systems is that they operate with low power to permit extended battery life. A commonly-used framework for the implementation of such systems (particularly where more than one sensor may be employed) is a so-called Body Area Network (BAN), which consists of a network hub, to which one or more smart sensors are connected (ideally wirelessly, for unrestricted movement by the wearer). Signal and data processing may be divided between the smart sensors and the hub, depending on how computational power is distributed in the BAN (Body Area Networks typically also incorporate coding and encryption for data privacy, however, this functionality is beyond the scope of this project).

1.2

Aims

This project will investigate the development and implementation of a number of signal processing algorithms for epileptic seizure detection based on signal processing of Electroencephalogram (EEG) signals, in the mobile digital health environment. Firstly, this will involve DSP algorithm development (in MATLAB) in order to build a system for analysis and detection of seizures. Secondly, the project will aim towards implementation of some of the DSP algorithms in a simulated BAN, using an off-the-shelf Emotiv EEG Headset (http://www.emotiv.com) communicating with an Android mobile phone acting as a network hub (because of restrictions imposed by the development environment, it may be necessary to emulate a direct connection between the headset and the phone). The project will also aim to investigate the effects of signal compression on seizure detection performance. For test and development purposes, publicly-available databases of EEG signals will be used, particularly the University of Freiburg EEG database [1]. Where real-time testing is being carried out using software implemented on the Android platform, this will be restricted to use with normal healthy subjects.

Page |2

1.3
Pass

Project Milestones

Implementation of feature extraction and classification algorithms for seizure detection (in MATLAB), using Freiburg EEG database.

Average Translation of feature extraction and classification algorithms into C or Java, and validation of performance. Development of a basic Android application to gain familiarity with software development on this platform. Good Development of communications infrastructure (indirect via laptop) to enable communication between Emotiv headset and Android mobile phone. Characterization of computational complexity of feature extraction on Android platform.

Very Good Implementation of real-time or near real-time seizure detection on Android platform, and validation using healthy test subject(s). Excellent Investigation of the impact of compression on seizure detection performance. Analysis of potential power savings to be gained through the use of compression.

1.4

Health and Safety Issues

There are no health and safety issues. The project will largely involve software development on PC and Android platforms. The Emotiv EEG headset is an approved part, and will not be used other than in accordance with the manufacturers recommendations.

Page |3

1.5

Project Timeline

Figure 1-1: Gantt chart of Project Timeline

Page |4

1.6

Thesis Outline

The main text of this thesis is split into 4 main chapters, a discussion and a conclusion; Project Components, Algorithm Development (MATLAB), Mobile System Development and Investigation of Compression on EEG. The first chapter outlines the major system components used in the design and development for each of the following chapters. This chapter provides a detailed background into each major non-standard hardware and software project components. The following two main chapters (3-4) will detail the design and development of the seizure detection algorithm on PC and Smartphone. These chapters begin by outlining the necessary background and major aims for the chapter. Following this, these chapters will focus on the design, development and testing processes of their respective objectives. Each chapter will conclude with the results obtained throughout the course of the chapters development and conclude with a brief summary. The fifth chapter includes a small scale study on the effects of Compression of EEG. The final discussion and conclusion of the main text will bring together the results from the 3 main chapters and draw conclusions whilst outlining areas for future research, and will provide a critique of the project itself including areas such as Project Management etc.

Page |5

2. Project Components
2.1 Project Hardware

Emotiv EPOC The Emotiv EPOC is a high resolution, neuro-signal acquisition and processing wireless neuro headset. The Emotiv Headset is a peripheral originally designed for gaming purposes by detecting conscious thought, emotions and head rotation. It can also be used to collect raw EEG data from users. The Headset features include: 14 saline sensors which are places along the scalp in order to read signals from different areas of the brain. Gyroscopes for head rotation and tilt Bluetooth connection to PC Software Suites which allow the connection to each sensor to be tested and the raw EEG can be monitored from a test bench program.

The headset documentation includes programs written in C++ which allows the user to Log the preprocessed EEG data from the headset. Also included was a JNA Wrapper (Java Native Access) program which would allow users to write Java applications to access this EEG data. This Wrapper works by allowing Java programs to access native DLL libraries on a machine while sacrificing the program portability that Java offers, but this approach encountered issues which will be discussed later in this thesis.

This particular headset provides a cheap and affordable platform for portable wireless capture of EEG data. However, the Emotiv EPOC headset has some limitations which would affect how this project progressed. The Emotiv EPOC headset is only compatible with Windows PC and the EPOC Headset itself is not programmable. Therefore in order to capture real-time data and process this data on a mobile device, a method had to be devised of transferring the raw data over wireless connection to the handheld.

Numerous approaches were investigated towards this, due to the time-limited nature of this project, only a partial solution was found, details on which are discussed below. At the close of work on this project, the method for transferring real data from the Emotiv EEG headset is as follows:

Page |6 A C++ program is run on PC which reads data from the connected Emotiv EPOC Headset. It is a modified version of the C++ provided in the support

documentation provided by Emotiv Systems. This data is saved to a CSV (Comma Separated Values) file which is placed in a common directory between the C++ and Java programs. The Java program is manually run afterwards, which reads the data from the CSV file, and buffers this data into window frames with no overlaps, and transfers this data to phone over Bluetooth. EEG features are extracted from each of these frames of data and classified as either non-Ictal or Ictal frames.

Other methods of transferring the data included the creation of a C++ to Java client-server socket connection, or JNI (Java Native Interface, an alternative to JNA) which would also allow the java program to directly access the native DLL libraries in order to directly connect with the headset.

Another option available is to use a headset with compatibility with the Android mobile devices. This would in the long-term, be a more desirable and more practical solution. A comparison of the Emotiv EPOC Headset and the Android/iOS compatible XWave Headset is given in Table 2-1.

Device Emotiv EPOC XWave

Cost $300 $90

Electrodes 14 1

SDK Yes Yes

Android No Yes

iPhone No Yes

Table 2-1: Comparison of two available consumer EEG Hardware options

Android Mobile Device The Android mobile platform is an open source software platform developed by Google, based off the Linux Kernel. Development of Android Applications is generally through Java using Google developed java libraries. Android is available under an open-source license since October 21st, 2008. As it is open-source, all the software and documentation required to build the desired application is free and therefore it is the platform of choice for the development lifecycle of this project. Android OS also provides hardware support for Bluetooth which will the method of choice for establishing wireless connections between EEG Source and the

Page |7 Mobile Device. The hardware model of Android device used through this project was the HTC Wildfire Smartphone whose specs relevant to this project are detailed in Appendices A1. Programming of the Android device was carried out in the Eclipse IDE with the Android SDK Plug-in installed. The Eclipse IDE provides an Android Virtual Device which allows limited functionality for debugging Android programs without requiring the use of a physical Android device. Bluetooth v3.0 Bluetooth is an open wireless technology standard for transmitting data over short distances between Bluetooth enabled devices, enabling the creation of Personal Area Networks (PANs). Several devices can be connected to one Bluetooth server device, which opens up the possibility for using a device such as Android Mobile Devices to act as the central hub in order to create the Body Area Network (BAN) which would allow a user to monitor biofeedback from various sensors. Bluetooth v3.0 supports up to 24 Mbit/sec theoretically, which is beyond adequate for the purposes of this project.

2.2

Project Software

MATLAB MATLAB (shown running on windows 7 in Figure 2-1) is a high level technical computing language and graphical interface used for intensive mathematically computations. It is designed to be more efficient and more accurate than typical programming languages like C++ and Java. It provides users with various tools for data analysis and visualization, and will be the primary tool used in this project for accessing the effectiveness and sensitivity of any developed algorithms. The software also provides various toolboxes designed for use with specific parts of this project, which are further detailed below.

Page |8

Figure 2-1: MATLAB processing EEG data

Signal Processing Toolbox: The Signal Processing toolbox provides tools for analyzing and developing algorithms for digital signal processing. It includes tools for analyzing in time and frequency domains, computation of FFTs etc. The signal processing toolbox was used for design of FIR filters for this project. Bioinformatics Toolbox: The Bioinformatics Toolbox includes SVM (Support Vector Machine) which was one algorithm used to classify frames of data to their individual Ictal and Non-Ictal states. Statistics Toolbox: The Statistics Toolbox includes a simple Nave- Bayes Linear Discriminate Classifier (LDA) which was another investigated algorithm used to classify frames of data to their individual Ictal and Non-Ictal states. WEKA In order to develop classifiers in Java, data mining and data processing jar libraries developed by the University of Waikato (dubbed WEKA Libraries) were employed to the program in order to provide the necessary tools to continue development. WEKA is a collection of machine learning algorithms for data mining tasks. The algorithms can either be applied directly to a dataset or called from your own Java code. WEKA contains tools

Page |9 for data pre-processing, classification, regression, clustering, association rules, and visualization. It is also well-suited for developing new machine learning schemes. WEKA is open source software issued under the GNU General Public License [2]. WEKA provides full documentation and support online. WEKA Linear Classifiers are employed in both the PC and Android Java programs for classification of seizure data. BlueCove API BlueCove is a Java library which provides an interface for java programs with Bluetooth stacks found in Windows, Mac OS and other operating systems. SPIHT Compression For the latter part of the project, investigation was carried out into the effect that compression algorithms on the quality of the results obtained from the classifier models. First the signal is compressed to a desired compression ratio. Following this the compressed undergoes decompression, before entering the preprocessing and feature extraction phases. The results are then compared with that of the original signal (see Section 9: Compression on EEG Signals). Compression will be carried out using the Set Partitioning in Hierarchical Trees (SPIHT) Algorithm. SPIHT Compression is a form of lossy compression, i.e. a certain amount of data is lost in the compression process. SPIHT Compression of a signal involves splitting a signal up into window frames, and calculating the Discrete Wavelet Transform (DWT) at each window. This converts a frame of samples to a sequence of bits. These bits are stored in a vector and organized in order of most important bits first. Compression is then carried about by simply truncating the bit sequence by the desired compression ratio (CR) and retaining the most important bit sequence. For example, for a compression ratio of 4:1, only the first 25% of bits are retained. This report investigates the Percentage Root Mean Squared Distortion (PRD) of a signal at different CR values, and compares the output of the classifier to that of the original signal.

2.3

Data Sources

Freiburg Seizure Database The Freiburg database is a collection of EEG recordings from 21 patients suffering from medically intractable focal epilepsy. The data was taken from intracranial EEG recordings conducted by the Epilepsy Center of the University Hospital of Freiburg. The strict test

P a g e | 10 environment which this data was recorded ensures that the signals collected in the EEG database have high signal-to-noise ratios and few artifacts. The data itself was captured at a rate of 256Hz and quantized to 16bits and has not undergone any sort of pre-processing. The records are saved as ASC files, and each file consists of a 1dimensional array of data representing data recorded in mV from one EEG channel. The recordings are split into 2 classes: Ictal: These files are 1 hour long containing epileptic seizures and at least 50 minutes of pre-Ictal data. Inter-Ictal: Data files consisting of 24 hours worth of Non-Ictal data.

The signal data itself into 2 different class groups, Icital (Seizure EEG) and Non-Icital (NonSeizure EEG). Figure 2-2 is a signal from an Ictal class data file from the Freiburg Database, with an overlay demonstrating which section of data is Ictal or Non-Ictal.

Figure 2-2: Image demonstrating the different areas in an Ictal signal file taken from the Freiburg Database.

Live EEG Data Live EEG Data for this project was recorded from the Emotiv EPOC headset mentioned earlier in this paper. Using a modified version of C++ code provided in the documentation for the EPOC Headset, EEG readings are recorded from the headset at a rate of 128Hz and save these recordings in CSV format. The recordings are usually between 30-seconds to a minute long where the user is in a relaxed state. This was to reduce the effect that artifacts would have on the seizure detection algorithm. It is important to note that for this project, the aim was not to create an application which would be ready for use by a patient, but to investigate the possibility of being able to use the processing power of modern Smartphone technology to detect seizures. Therefore,

P a g e | 11 this report focuses on the ability of the Smartphone to classify seizure data in or close to real time. For health and safety reasons outlined earlier, no live seizure data was captured from epileptic patients using the EEG Headset. This is a serious limitation in the validation of the softwares performance, as it is only possible to validate the ability of the software to correctly detect Non-Ictal data. Table 2-2 demonstrates the important differences between the data collected locally from the Emotiv Headset and data gathered from the Freiburg database. Freiburg Database Sampled at 256Hz 16 bit resolution Invasive No preprocessing Features Ictal data
Table 2-2: Comparison of EEG Data Sources

Emotiv EPOC Sampled at 128Hz 16 bit resolution Non-Invasive Preprocessed No Ictal data

P a g e | 12

3. Algorithm Development (MATLAB)


3.1 Introduction

This section details the design and implementation of a preliminary classification algorithm in MATLAB, with the intention of carrying this algorithm forward through to development of the Android Application. Discussed in this chapter are what parameters and features of EEG signals were used in the classification of seizure activity, what classification algorithms were investigated, how the algorithms respective performance was measured and how the respective algorithm performance was improved relating to each classification algorithm.

3.2

Algorithm Design

The intention during this section of the project was to design the simplest system possible for initial Android development and iteratively increase the complexity and computational cost of the system to find the best balance of Algorithm Complexity vs. System Performance. Figure 31 is a sample block diagram of how the system was expected to work at a high level. X(n) represents the original signal; R(n) represents the preprocessed signal, and Y0 Yn represent features extracted from window frames of the preprocessed signal R.

X(n)

Band-Pass Filter

R(n)

Y0(m), Y1(m) ... Yn(m) Feature Extraction


Classify featrues

Figure 3-1: Block Diagram of Seizure Algorithm

Throughout the design it was important to keep in mind that direct porting of code from MATLAB to Java is impossible. MATLAB is a high level computing language, which includes toolboxes for dealing with a wide array of mathematical functions. In order to port these to java, individual functions would have to be written in java for each MATLAB function used in the ported algorithm. Also, the Java programming language is poorly optimized for Digital Signal Processing. This is because java is a high level programming language in itself. Unlike C++, Java does not allow for lower level management of memory and pointers in order to make the code more efficient.

P a g e | 13 This became important when attempting to choose the features which would be extracted in order to classify EEG signals. For example, calculating the FFT of a windowed signal is much more time consuming and processor intensive than calculating standard deviation.

3.3

Algorithm Development

Initial development of algorithms began on one file featuring Ictal data taken from the Freiburg database. This data was loaded into MATLAB and tested on code to extract a number of different features. The original code calculates the Windowed Fourier Transform at a frame size of 1024 samples per frame with no window overlap and then calculates and plots the power spectra and the Shannon and Kullback-Leibler (relative) entropies. It also calculates the relative band ratio (RIR). [3] The calculations taken and plotted over patient seizure data in order to get a visual representation for the changes that occur in these EEG features during the onset of seizure as shown in Figure 3-2. However, some of these calculations are rather complex to port over to java code. Efforts were made to look at alternative options for calculating possible seizure activity with less computational cost and complexity.

Figure 3-2: Graphs showing EEG Ictal signal [top]; power spectra [second from top]; Shannon [centre] and Kullback-Leibler [second from bottom] entropies; Relative Band Ratios [bottom].

Research conducted in the paper Epileptic Seizure Detection: A Non-Linear Viewpoint and its examination of time-dependant techniques of EEG analysis, it was apparent the basis for the simple seizure detection algorithms would be to calculate the Hjorth Parameters [4].

P a g e | 14 Using the code described above as a base, M files was developed to calculate the Hjorth Parameters; Activity ( ), Mobility ( ) and Complexity ( ) and plot these values to

graphs. The first parameter ACTIVITY is a measure of the mean power representing the activity of the signal. The second parameter is an estimate of the mean frequency and is called the MOBILITY. The last parameter, COMPLEXITY gives an estimate of the bandwidth of the signal. Since the calculation of Hjorth parameters is based on variance, the computational cost of this method and its complexity is considered low in comparison to other methods[5][6]. The discrete time formulas for the calculation of these parameters are on the following page.

Activity:

3-1

Mobility:

3-2

Complexity:

3-3

Where

represents the variance of the signal x, and

represents the variance of the first

derivative of signal x, and

represents the variance of the second derivative of signal x.

Window frames of 1024 (i.e. 4 seconds of data) samples were originally used to form the feature vectors from which the values from Activity and Complexity would be calculated. There was no overlap between each individual frame. For each frame of data, the values for Activity and Complexity were calculated as per the formulae above. The resulting visual representations demonstrated in Figure 3-3 show clear distinguishing features during Ictal periods, demonstrating a large spike in Activity while conversely showing a drop in Complexity to almost zero for the duration of the Ictal period. Visually these are solid indicators of seizure activity under test conditions. However, the Mobility of the signal does not show a definite change between Seizure and Non-Seizure states, and thus this feature was not used when classifying the signal.

P a g e | 15

Thus it was assumed at this point in the project that the Hjorth Parameters would be the easiest to implement in Java code and later convert to the Android platform, and thus will provide the basic benchmark for the system.

Figure 3-3: Visual representation of EEG data for the raw signal and Hjorth parameters

3.4

Classification in MATLAB

Following supervisor advice, it was decided to conduct research into two different classification algorithms: Linear Discriminate Analysis Support Vector Machines.

Analysis of the 2 classification algorithms was carried out in MATLAB by training the linear and SVM classifier models on identical sets of training data. Training data consisted of the precalculated Activity and Complexity, as well as the equivalent group data indicated if each frame represents either Ictal or Non-Ictal data. Utilizing the Statistics and Bioinformatics Toolbox in MATLAB, classifiers were created, trained and evaluated through cross-validation of data with a dataset split of 10/90 (10% test, 90% training data). Comparison tests for classifiers were carried out with raw data features vs. preprocessed feature extraction (Discussed later in this report). The results of the MATLAB Classifiers can be viewed below.

P a g e | 16 When evaluating the performance of a given Classifier, three values are taken into account. CorrectRate is the percentage value of frames within a sample which were correctly classified when compared to previously known results (i.e. the percentage of true positives and true negatives of classified samples). Sensitivity relates to the test's ability to identify positive results. Specificity relates to the ability of the classifier to identify negative results. When attempting to create classifier models and choose between them, there is often a trade-off between the Sensitivity and Specificity. Classifier performance in MATLAB is analyzed through the classperf function. This function compares the results of the classifier on a set of test data with the real group labels of the test data.

3-4

3-5

3-6

P a g e | 17

Figure 3-4: LDA Classifier Performance results of Raw Signal compared to Pre-Processed Signal. The inclusion of a band-pass filter increases the Classifiers performance by approx 6%, however the increase in sensitivity has lead to a decline in specificity, a common trade off when designing classification algorithms.

Figure 3-5: SVM Classifier Performance results of Raw Signal compared to Pre-Processed Signal. The introduction of a band-pass filter increases the Correct Rate by 2%.

3.5

Pre-Processing

Investigation was carried out to measure the effect of introducing pre-processing to the raw EEG data before extracting features for seizure detection. Blanke et al. (2000) indicated that the dominant Ictal frequencies exist between the ranges of 3Hz to 8.5Hz [7]. A sample DSP algorithm from the aforementioned paper is featured in Figure 3-6. From A digital band pass filter from 2Hz to 20Hz was implemented in MATLAB before carrying out the extraction and classification programs to remove noise and artifacts (More detail in section titled MATLAB

P a g e | 18 Filters). The results demonstrated a considerable increase in the specificity and sensitivity of the LDA Classifier, as documented in Figure 3-4 and 3-5 above.

Figure 3-6: A visual example of a pre-processing algorithm for raw EEG signals for seizure detection taken from Cecchin et. All 2010[8]

It should be noted here that all data being tested to date was sourced from 1 patient under strict test conditions which minimized the effect of artifacts and noise in the EEG signals, and such reliability being demonstrated using these features should not be expected in real-world applications. For the moment, the project aims only to test the theoretical possibility of implementing seizure detection on mobile phones. When approaching the problem of capturing live EEG data from a mobile patient, there are many more factors to be taken into account which impede the quality of the data received and the performance of the classification algorithms. Figure 3.7 gives a visual example of the change in the raw data after filtering.

Figure 3-7: Raw EEG (Top) vs. Filtered EEG (Bottom)

P a g e | 19

MATLAB Filter Design As mentioned earlier in this report, the dominant Ictal frequencies are believed to reside between the 2 and 20Hz region. A simple filter was designed using MATLABs fir1 function of order 50 with a band-pass between 2 and 20Hz in order to isolate these signal bands. The code listing for the filter can be found at Appendix A.2. The MATLAB fir1 function creates a digital filter using the window method. The filter was designed based on the following parameters. (The code for the filter can be found in the filterB.m function file found on the disc provided with this report). The frequency response for the filter is plotted in Figure 3-8 using MATLAB's freqz function.

Figure 3-8: Frequency Response of MATLAB Band-Pass Filter

3.6

Results

Tables 3-1 and 3-2 contain results from tests run on the classifier models with data from the Freiburg Database. The tables feature 3 the performance of the algorithms on 3 Ictal datasets from the Freiburg Database and 2 Non-Ictal Datasets. Linear Discriminate Analysis: Dataset: Correct Rate Sensitivity Specificity 0015 (Ictal) 0.9867 0.7988 0.6129 0018 (Ictal) 0.9855 0.9955 0.5 0021 (Ictal) 0.9922 0.998 0.7143 0017 0.9911 0.9999 0.9911 0022 0.98 0.011 0.9811

Table 3-1: Results of LDA Classifier on Original Signals

P a g e | 20 Support Vector Machine: Dataset: Correct Rate Sensitivity Specificity 0015 (Ictal) 0.9121 0.9355 0.9113 0018 (Ictal) 0.5818 0.778 0.5778 0021 (Ictal) 0.9055 0.9575 0.9015 0017 0.6719 0 0.6726 0022 0.485 0 0.4855

Table 3-2: Results of LDA Classifier on Original Signal

3.7

Conclusions

The results for this section of the project demonstrate that overall, the LDA classifier was significantly better than the SVM Classifier. Preprocessing the signal before classification through a 2-20Hz band-pass filter increased the rate of correctly classified results by between 2-6%, whilst also affecting the sensitivity and specificity of each algorithm to different extents. Taking this knowledge forward into the Mobile Development part of the project, it was decided that the LDA classifier the Hjorth Parameter feature extraction would be implemented on the Android platform for the first iteration of the Android Application. However, the effect compression has on data classification is analyzed later in this paper and includes the Support Vector Machine classifier model in its analysis. It should be noted here that the EEG signals used for this part of the report were sourced from the intracranial data of one individual patient in the database featuring little to no artifacts, and high signal-to-noise ratio. In turn this means that the data used to develop the algorithm was ideal in nature and the resulting high classification rates should not be expected with signals that are more complex in nature.

P a g e | 21

4. Mobile System Development


4.1 Introduction

This section details the development process of the underlying java classification program which formed the basis for porting the application to the Android Mobile Platform. Areas of the project covered in this section are the application design, converting high-level Math Programming Language code to Java processes and deploying this code to the Android OS platform. Also covered is the integration of WEKA Libraries into the classifier application at both the Java and Android levels, as well as a discussion on the use of Bluetooth and integrating the Emotiv EPOC into the mobile development, and the issues thereof. The overall aim of this part of the project was to determine if it is possible to implement a simple seizure detection algorithm on a mobile platform which operates in or close to real time. It was outside the scope of this project to develop an interactive UI for potential users to monitor their own EEG state.

4.2

Java Development

The aim of this section of the project was simply to convert the code produced in MATLAB .m files and replicate these codes in java. This involved manually writing Java code which calculates basic values such as standard deviation and the derivative of a signal, two equations which form the basis for calculating the Activity and Complexity of a signal. These calculations were later verified through comparison with MATLAB that these were desirable results. These results were identical to 10 decimal places, which should be more than adequate for the purposes of this project. Standard Deviation:

4-1

P a g e | 22 Derivative of a Signal

4-2

4.3

Programs

Classifier Training Program (PC) The first program created was a simple program which loaded a signal file and created a instance of a Nave-Bayes Classifier model, trained this model on the signal file and provided group data (the same data used to train the MATLAB classifiers), and its performance was evaluated by running it against another test set of data. From the libraries provided by WEKA, a Nave-Bayes linear classification algorithm was chosen and a classifier model trained and evaluated on sample data through cross validation. The resulting trained model can be serialized and saved to a .MODEL file. This allows for a classifier model to be trained and evaluated offline before the model is ported to the target android platform. This is important functionality because the training of a classifier is the most processor intensive and most power-hungry part of developing classifier models. The Android device simply does not have the required computational power to do this. Two important methods were created from within the model class in java. One method performed an evaluation of the classifiers performance. The other method was intended for end use by the Android application and classified an individual instance of data against the classifier model. Once the model was created and evaluated, this program serializes and saves the trained java classifier object to a .MODEL file to the project directory. This .MODEL file can then be ported to the Android device, where the java classifier can be de-serialized and used for classification of received signals. Porting Classifier to Android Following the creation of a program which would run on PC, a simple Android program was developed. This program opened and de-serialized the .MODEL file provided by the PC program. The app then ran classification on hard-coded data in order to verify the classification algorithm was functioning on the hardware. Development of the classification program on the Android platform required that some changes had to be made to the source WEKA libraries in order to make them compatible with

P a g e | 23 the OS. Doing this required certain parts of the WEKA libraries to be stripped away [9].It should be noted here that the java program used to generate the classifier model offline should use an identical version of the WEKA library used by the Android OS. This is to avoid issues which arise when serializing a .MODEL file and then attempting to de-serialize this .model file on the target device, as they will not be compatible. In other words, both the offline classification training program and the classification application running on the Android target device must use identical jar libraries. It is not possible to serialize a .MODEL file with one version of WEKA and de-serialize the file with another. There was some time spent investigating if it was possible to implement the MRE (MATLAB Runtime Environment) on the Android Platform. For a PC based OS, the MRE would allow developers to create Java classes directly from the MATLAB IDE or command-line interface, and implement them in Java programs provided the correct version of the MRE is present on that system. This was abandoned in favor of a simpler approach. At this point, attention shifted towards using the WEKA java libraries in order to implement a classifier on the Android platform. Bluetooth Client and Server Programs (Android and PC) The third and fourth programs created throughout this project are Bluetooth client and server programs which run on the Android Device and PC respectively. This Android program was based off the Bluetooth Chat app provided by Google and a simple Bluetooth Chat to PC application sourced online [8]. The java PC server was programmed through the BlueCove API Libraries. The main aim was to merge the Client app with the classification program and allow the Server to send EEG data over a Bluetooth link every 4 seconds to allow the mobile platform to convert data close to real-time. Following the development of a Bluetooth ServerClient connection between PC and Android, it was intended to create a connection between the Emotiv EPOC Headset and PC. The full intention was to allow the PC to act as a relay device to allow the Emotiv EPOC headset to transmit data to the Android device in real time. Figure 4-1 demonstrates this intention visually. The PC would also be used to buffer data from the headset (sampling at 128Hz) into frames of 1024 samples to be transmitted to the Android device every 8 seconds.

P a g e | 24

Data transmitted at 128Hz

Buffered at frames of 1024

EMOTIV EPOC

PC

ANDROID

Figure 4-1: Flowchart showing high-level design

When determining the suitable system architecture for the real-time Android application, it was decided that due to the time friendly nature of the original aim for the application (1 frame of data every 4/8 seconds) a simple control loop was determined to suffice, as shown in Figure 4-2:
Read Data from Buffer

Extract Features

Classify Data

Wait for Buffer

Figure 4-2: Flowchart of Real-Time System Loop

This would require that the time taken for the total processing required for these 4 steps to be under 8 seconds, allowing the system to return to a wait state before the next frame of data is ready. Bluetooth was chosen due because it is commonplace in devices which are used in short-distance communication and because it was readily available in the chosen hardware. The development of Bluetooth Server for java involved the inclusion of BlueCove API (mentioned in the chapter 2, System Overview) which allows for development of Bluetooth (JSR-82 implementation) with Bluetooth enabled devices with the proper JRE version installed.

P a g e | 25 The Bluetooth Client side of the application was built using Bluetooth Chat example provided by the Android SDK as a basis. The Bluetooth Server was developed on top of an existing Bluetooth PC Server example online. This server was modified to receive a connection from an Android client and begin transmitting stored data from the Freiburg Database at rates specified within the code. To transmit the data, each frame is parsed to a string with hard-coded delimiters separating each sample. Object input and output streams are then opened between server and client and the String is passed between programs at a fixed rate. Seizure Application The Android Application is made of 4 main classes. Each of these classes can be view in full on the supplied CD. The main design aim was to create an application which would classify EEG data in or close to real time. These results would be displayed on screen for programmer verification. The code also logs all results to Android LogCat for verification. RemoteBluetoothService.java This Android service is created on Activity startup and remains running until stopped by Activity or killed by Android OS. This service creates the Bluetooth Adapter, searches for Bluetooth devices when called by DeviceListActvity, and connects to Bluetooth devices specified by DeviceListActivity. DeviceListActivity.java This Activity creates a ListView widget overlay populated with Bluetooth device names and IDs retrieved from RemoteBluetoothService.java and allows the user to specify what Bluetooth device they wish to connect to. RemoteBluetooth.java This is the main Activity. On startup, first checks to see if Bluetooth has been enabled on the device. If not, a dialogue appears requesting user to turn on Bluetooth. On a No click, program shuts down. On yes this activity starts RemoteBluetoothService.java. From this Activity, DeviceListActivity.java can be called, and RemoteBluetoothService.java can be stopped. RemoteBluetooth.java controls the main GUI interface for displaying current Activity, Complexity and Ictal State to the user. This information is purely for immediate programmer feedback, it is not expected for a Patient to need to monitor these values and creating a userfriendly GUI for the application is outside the scope of this project. As mentioned earlier, the

P a g e | 26 aim is to validate the possibility of a mobile seizure detection system with the Smartphone as the central processing hub. WEKALDA.java This java class contains the Classifier model and creates the Attributes and Elements which are the WEKA libraries equivalent to Features and States. This class also includes a method for classifying data against the stored Classifier Model. Application Screenshots

Figure 4-3: Application Screen Captures; Application requesting Bluetooth [left], Scanning for devices [centre], Classifying data [right]

Issues with HTC Wildfire: Working with the HTC Wildfire as the Mobile Device of choice proved problematic throughout for the beginning of the development of the Bluetooth application for Android. The issue related to the device being able to see and pair with other Bluetooth devices, but unable to connect. The problem was eventually traced back to the following line of code, the workaround for which is featured in Appendices A.3. This issue halted development on the application for around 3 weeks during the Christmas period.

3.5

Emotiv EPOC Development

Developing the system to incorporate real-time classification of EEG data required a number of steps. Firstly, this required a direct connection between PC and the Emotiv EPOC over Bluetooth had to be established, and values sensed from the Emotiv EPOC at a rate of 128Hz. The next requirement of the system was to establish a method from which this signal could be

P a g e | 27 processed from within a java program. This presented a number of issues which will be discussed later. The simple C++ examples acquired from the Emotiv EPOC documentation were extended to log EEG data to a CSV file which was stored on the desktop. The java server program could then be run, which reads the CSV file from the desktop and stores the values in an array, and buffers the array into blocks of 1024 samples. These samples were then transmitted over Bluetooth connection to the Android device where classification could be carried out. There were issues related to obtaining a true real-time connection between the Emotiv EPOC Headset and the Android phone. The Emotiv EPOC is not Android compatible therefore it is not possible to directly connect the Android Phone to the Emotiv EPOC through Bluetooth. This led to the decision to use a PC as a relay point as mentioned earlier. However, this also proved to be problematic. The main issue is the incompatibility between Java (Android OS) and C++ (Emotiv EPOC). Two methods of connecting the C++ and Android applications on PC were investigated, including the Java Native Access (JNA) Wrapper provided with the system documentation and a C++ to Java Socket Client-Server. The JNA Wrapper has been used successfully with projects carried out on other systems [10] but proved ineffective here, likewise the Java-C++ ClientServer Emotiv EEG signals The main difference between data gathered from Emotiv and data gathered from Freiburg Database, is mentioned above, is that the Emotiv signal has undergone preprocessing. Therefore EEG classification of Emotiv data against a model trained from the database is unreliable. Due to Health and Safety limitations, Epileptic patients are inaccessible for seizure data gathering utilizing the Emotiv EEG headset as the collection device. As such, it can only be verified that data can be transmitted from Headset to Android and that classification does occur.

P a g e | 28

3.6

Results

A java classifier model was created and performance evaluated using a small test set. This model could be ported to an Android device for use in mobile classification. A working Android Application which classifies EEG signals using basic features and a lightweight NaveBayes linear classifier was created. The Android App was tested to take buffered data at frame sizes of 128 every half second. Its impact on phone power consumption and the speed which it performs classification was measured. It was intended to also focus time on developing digital filters in java, but this was not completed within the project timeline. Application Statistics Contained in Figure 4-4 are the results of a WEKA Linear Classifier model, evaluated through WEKAs evaluateModel function
Sensitivity: 0.9711981566820277 Specificity: 0.03225806451612903 Correctly Classified Instances Incorrectly Classified Instances Kappa statistic Mean absolute error Root mean squared error Relative absolute error Root relative squared error Coverage of cases (0.95 level) 844 55 0.0037 0.0669 0.2448 99.0938 % 134.1465 % 94.327 % 93.8821 % 6.1179 %

Mean rel. region size (0.95 level) Total Number of Instances

51.6129 % 899

Figure 4-4: Results output of the Nave-Bayes Classifier using the evaluateModel function from WEKA libraries

Total Number of Instances

899

Using an application called PowerTutor designed by students in the University of Michigan [11] the power consumption of the application while active was processing could be estimated, graphed in Figure 4-5 below.

P a g e | 29

Figure 4-5: PowerTutor measurements of Seizure Detection App; Power usage over a period of 10 seconds [left] and Power usage as a percentage of whole application [left]

The average runtime of the Classification algorithm is approximately 5-8ms per frame.

3.7

Conclusions

The Emotiv EPOC Headset has numerous limitations which devalue its continued use within the scope of future projects similar to this. The headset itself is large and bulky in design, and is not suited for use while the user is mobile. Erratic movement cause major interference and noise in signal output. In order to continue exploring the use of mobile technology in detecting a seizure within an environment where the users themselves are mobile, project specific hardware must be constructed in order to provide more stability to the system and reduce the affect that physical movement has on the quality of the EEG signal received. This will be discussed in more detail later in Chapter 6. However, completion of the java classifier program on Android suggests that it is indeed viable to use a mobile device such as an Android phone as a portable platform for monitoring of EEG state. Despite issues relating to the Emotiv EPOCs physical limitations, this report proves that the Android device is able to handle a Bluetooth stream of data from an EEG source at desirable frequencies and performance data classification. Connecting the Emotiv headset to Android for live-data BAN simulation would have been ideal, but not a vital part of this project.

P a g e | 30

5. Compression of EEG Data


5.1 Introduction

This chapter deals with the small scale study conducted as part of this project into the effect of compression of EEG data on classifier performance and its behavior. Compression of data offers numerous benefits in systems like the one described throughout this paper, including reducing saving space in memory and having potential power saving benefits. For this study, the SPIHT algorithm was employed in MATLAB in order to investigate the effects of compression. Due to the time sensitive nature and wide scope of this project, the SPIHT algorithm is not developed or implemented in Java code. Instead, on supervisor advice the algorithm will be treated as a Black Box wherein only the effect on EEG data and the seizure detection algorithms performance is studied, not the SPIHT algorithm itself.

5.2

Method of Study

For this small study, data was again sourced from the Freiburg Database. This data was passed into a compression program in MATLAB. Detail on the SPIHT Algorithm can be found earlier in Chapter 2: Project Components. There are 2 main variants of the MATLAB SPIHT program code found on the CD provided with this thesis. The first variant (driver1.m) takes a 1024 sample frame of data from an EEG signal file and calculates the PRD (Percentage Root-Mean-Square Deviation) for 50 different CR (Compression Ratio) values and plots these to a graph. The second variant (my_genSPIHT.m) takes a full signal file, compresses the data to a specified CR and reconstructs the data for use in evaluating change in classifier performance. Figure 5-1 is a visual representation of the signal compressed at ratios of 1:4, 1:25, 1:50 and 1:100 and compared to the original signal. For this section both Linear Discriminate Analysis and Support Vector Machine performance was evaluated against the compressed datasets.

P a g e | 31

Figure 5-1: Comparison of EEG Signal at varying CR

For the study 4 main areas of effect of compression on EEG and Classifier performance were analyzed. The PRD is a measure of how accurate the reconstructed signal is when compared to the original waveform. A higher PRD value demonstrates a higher level of distortion compared to the uncompressed signal. The compression ratios were calculated programmatically as in Figure 5-2:

NumberofPoints = 100 totalBits = length(bits)


fractionBitLen = nearestWhole((totalBits/numberOfPoints));

for i = 1 to NumberofPoints do{ reconstructedBits = fractionBitLen*NumberofPoints x = doSPIHTCompression(signal, reconstructedBits) x = decompressSignal(x) } end


Figure 5-2: Pseudo-Code for calculation of CR

CorrectRate, Sensitivity and Specificity are the values used earlier in this paper to evaluate the performance of different classifiers.

P a g e | 32

5.3

Results

Figure 5-3 demonstrates the increase in PRD as the CR increases incrementally for 100 different compression ratios.

Figure 5-3: Percentage Root-Mean-Squared Deviation vs. Compression Ratio using SPIHT Compression

Tables 5-1 and 5-2 each demonstrate the effect of different SPIHT Compression ratios on the LDA and SVM Classifier performance estimation values respectively. The tables demonstrate the average change in percentage performance of the LDA Classifier, and the second set is representative of the Support Vector Machine Classifier. Linear Discriminate Classifier: Compression Ratio 4:1 25:1 50:1 100:1 Sensitivity -0% -0.05% -0.23% -0.4% Specificity -0.28% -7.94% -10.32% -12.7% Correct Rate -0.05% -0.16% -0.38% -0.61%

Table 5-1: Average change in performance of LDA Classifier vs. CR

P a g e | 33 Support Vector Machine: Compression Ratio 4:1 25:1 50:1 100:1 Sensitivity -0% -0 % -0.28% -14.88% Specificity -0. 79% -3.01 % -4.84% -2.645% Correct Rate -0.78% -2.0% -4.76% -4.18%

Table 5-2: Average change in performance of SVM Classifier vs. CR

5.4

Conclusions

Graphing the above data shows a steady decline in Specificity in accordance with Compression Ratio, thus demonstrating that the most significant impact of increasing Compression Ratio is a decreasing ability in the algorithms ability to correctly detect negative results. Also, the SVM classifier itself seems to show extra sensitivity towards the change in CR compared to the Linear Classifier, which suggests that under circumstances where data compression is involved, the Linear Classifier would be the more robust choice. However, the performance of both classifiers on compressed EEG is relatively similar to that of the original signal, suggesting that the system could benefit from data compression, without a significant drop in performance.

P a g e | 34

6. Discussion
6.1 Introduction
This chapter aims to put in context what has been achieved through the timeline of this project, areas which caused trouble, what was successful and what has still to be done in terms of a project with this scope.

6.2 Discussion
In chapter 3, the Algorithm Development phase of this project was covered. This phase heavily depended on the use of MATLAB in developing the algorithm, being required for measuring algorithm performance, extraction and comparison of features, examination of the effects and benefits of signal pre-processing and ultimately deciding on an algorithm to move forward with into the mobile development phase of the project. The resulting algorithm proved effective on test data and fit the requirements outlined throughout the project. In chapter 4, the development of the mobile system was discussed. The initial Android Seizure Classifier Application was completed in full. This system connected over Bluetooth to a Bluetooth Server containing EEG data. This data could be transmitted in frames to the Android device, which would then perform classification of the received data. This phase came with numerous difficulties, the two major issues being the development of the Bluetooth connection between PC and the HTC Wildfire phone, and the development of a real-time system relay between the Emotiv EPOC and Android phone through the PC. The Bluetooth connection issue was specific to the HTC Wildfire and limited other HTC models. The issue was not well documented and therefore a work-around was hard to find. This issue could have been mitigated had the program been tested on a second device earlier in the Bluetooth development cycle. This would have identified the issue as being hardware specific at an earlier stage and a solution could have been resolved quicker. The second issue faced at this stage related to the incompatibility between the Emotiv EPOC headset and Android. This issue arose due to the incompatibility issues between Java and C++. This was unforeseen to a degree, as the Emotiv headset documentation provides a JNA Wrapper class for Java to allow Java applications to access Native DLL libraries on a system in order for these programs to read EEG data from the Emotiv Headset. However after numerous attempts, which involved changing configuration settings, changing system paths and project class paths, this method was abandoned. However this method has seen success in other projects, as referenced earlier in Chapter 4. The second attempted solution was also to modify

P a g e | 35 an example C++/Java Client-Server code, but this also proved unsuccessful. The issue regarding connecting the Emotiv headset directly or indirectly to Android is still open for resolution. As the project progressed, there are a number of limitations that have been noted with regard to the Emotiv EPOC Headset as a mobile EEG Capture device, and its usefulness within this project, as touched upon earlier in Chapter 4. Firstly, being restricted to the use of healthy personal for live testing means it is very difficult to determine if the classifier is working on live data. In order to continue development, Ictal data must be collected beforehand on the EEG sensing device which is to be used in the mobile BAN system. The Emotiv EPOC is not suited to this purpose due to its bulky nature. This causes additional movement when a patient is mobile and increases the level of noise on the EEG signals. Chapter 5 detailed the small scale study into the effects of compression of EEG signal and the resulting impact compression has on Classifier performance. This small scale study identified an inverse relationship between increasing CR and classifier specificity. However, the percentage of correctly identified instances only dropped by roughly 4.5% perfect between compression ratios of 50:1 to 100:1, suggesting that either the features used in classification in this project, or the classification algorithms themselves are robust in terms of dealing with compressed data. With regards to the Project Plan outlined for Semester 1 and Semester 2 and the relative effectiveness of both: the Project Plan for Semester 1 proved to be very successful and was adhered to throughout the course of the Semester. The plan allowed ample time for research, implementation and testing. The Semester II plan could have featured more detail and offer more time for development considering the newer technologies involved (e.g. Bluetooth and the Emotiv EPOC).

6.3

Conclusion

The aim of this project was to investigate the development and implementation of a number of signal processing algorithms for epileptic seizure detection through digital signal processing of EEG signals, within the mobile digital health environment. It aimed to combine off-the-shelf hardware for sensing EEG signals and Smartphone technology to act as the processing hub to create a BAN for monitoring of EEG signals. The project also aimed to carry out small scale investigation of compression of EEG signals in order to determine if there was a relationship between signal compression and seizure detection performance. To this end, the project achieved all of the milestones set out in the opening chapter, with the exception of measuring

P a g e | 36 the potential power savings to be gained from the use of data compression. A mobile application was created which could process EEG signals and classify Ictal activity. This application could be connected through Bluetooth to a compatible EEG source, essentially demonstrating that wireless EEG signal processing through mobile technology was indeed possible. The small-scale study into EEG compression was completed and demonstrated an inverse relationship between signal compression and classifier specificity. However also demonstrated was the off-the-shelf system used within this project proved to have many limitations in a real-life application such as the one described in this project. Therefore it should be deemed unsuitable for further use in projects such as this. It is advised that future projects and studies into the area of mobile EEG monitoring should focus on developing hardware specific solutions to the EEG sensing issues. Specific hardware could be constructed which would be designed to remain physically stable during patient mobility in order to significantly remove noise. EEG hardware could also be compatible with mobile devices to give the system practical value. This project opens up a new area of patient wearable systems for monitoring and analyzing biological signals. This projects value could be increased as further research continues into areas such as seizure prediction, which when combined with the research in this project, could provide epileptic patients with early warning systems to minimize risk to self.

P a g e | 37

References
[1]EEG Database, Seizure Prediction in Freiburg, Germany - https://epilepsy.unifreiburg.de/freiburg-seizure-prediction-project/eeg-database

[2]WEKA: Data Mining Software in Java, University of Waikato http://www.cs.waikato.ac.nz/ml/weka/

[3] MATLAB EEG code, The Andersen Lab. Division of Biology California Institute of Technology Pasadena, CA 91125-http://www.vis.caltech.edu/~rodri/programs/spect.m

[4] Niina Pivinen, Seppo Lammi, Asla Pitknen, Jari Nissinen, Markku Penttonen, Tapio Grnfors, Epileptic seizure detection: A nonlinear viewpoint, Computer Methods and Programs in Biomedicine, Volume 79, Issue 2, August 2005, Pages 151-159. doi:10.1016/j.cmpb.2005.04.006

[5]M. Vourkas, S. Micheloyannis and G. Papadourakis, Use of ANN and Hjorth parameters in mental-task discrimination, First International Conference on Advances in Medical Signal and Information Processing

[6]Hamid R. Mohseni, A. Maghsoudi and Mohammad B. Shamsollahi, Seizure Detection in EEG signals: A Comparison of Different Approaches, 28th International Annual Conference IEEE Engineering in Medicine and Biology Society(EMBS), August 2006, http://embc2006.njit.edu/pdf/1721_Mohseni.pdf

[7] O. Blanke, G. Lantz, M. Seeck, L. Spinelli, R. Grave de Peralta, G. Thut, T. Landis, C.M. Michel, Temporal and spatial determination of EEG-seizure onset in the frequency domain, Clinical Neurophysiology, Volume 111, Issue 5, 1 May 2000, Pages 763772

[8] T. Cecchin, R. Ranta, L. Koessler, O. Caspary, H. Vespignani, L. Maillard, Seizure lateralization in scalp EEG using Hjorth parameters, Clinical Neurophysiology, Volume 121, Issue 3, March 2010, Pages 290-300

P a g e | 38 *9+RJ Marson, Weka for Android, http://rjmarsan.com/#/Research/WekaforAndroid/ [10] A. Hoffman, EEG Signal Processing and Emotivs Neuro Headset, 28-09-2010, Page 46 [11]PowerTutor, Mark Gordon, Lide Zhang, University of Michigan, http://ziyang.eecs.umich.edu/projects/powertutor/

P a g e | 39

Appendix
A.1 HTC Wildfire Specifications:
Relevant Specs: OS Android OS, v2.3 (Gingerbread), upgradable to v2.3.5 Chipset GPU CPU Java Battery Bluetooth
Table A-1: Specifications of HTC Wildfire.

Qulacomm MSM7227 600 MHz ARM 11 Adreno 200 Yes, via Java MIDP emulator Standard battery, Li-Ion 1230 mAh Yes, v3.0

A.2 MATLAB Filter Code


function hd = filterB() %FILTERB Summary of this function goes here % Detailed explanation goes here %sampling frequency fsamp = 256; bandstart=2; bandstop=20; N=50; W1 = (bandstart/(fsamp/2)); W2 = (bandstop/(fsamp/2)); W = [W1 W2]; hd = fir1(N, W); end

Figure A-1: Code used to design MATLAB Filter Coefficients

P a g e | 40

A.3 Wildfire Bluetooth Code Problem


In RemoteBluetoothService.java, ConnectThread method, a Service Discovery Failed Exception occurs. This error seems to stem from HTC lacking Bluetooth support in some phone models. The code below was provided as a work-around. Offending Code: tmp = device.createRfcommSocketToServiceRecord(MY_UUID); Replaced With: Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); tmp = (BluetoothSocket) m.invoke(device, 1);

You might also like