real-time prediction of epileptic seizures using eeg...
TRANSCRIPT
Real-time Prediction of EpilepticSeizures using EEG signal
A thesis submitted in partial fulfillmentof the requirements for the degree of
BACHELOR OF TECHNOLOGY
in
Electrical Engineering
by
Gorish AggarwalEntry No. 2012EE10454
Under the guidance of
Dr. Tapan K. Gandhi
Department of Electrical Engineering,Indian Institute of Technology, Delhi.
May 2016.
Certificate
This is to certify that the thesis titled Real-time Prediction of Epileptic
Seizures using EEG signal being submitted by Gorish Aggarwal for the
award of Bachelor of Technology in Electrical Engineering is a record
of bona fide work carried out by him under my guidance and supervision at
the Department of Electrical Engineering. The work presented in this
thesis has not been submitted elsewhere either in part or full, for the award
of any other degree or diploma.
Dr. Tapan K. Gandhi
Department of Electrical Engineering
Indian Institute of Technology, Delhi
Abstract
Around 1-2% of the worlds population suffers from epilepsy and 25% of the
epilepsy patients are not curable through surgery or medicine. Epileptic
seizures often occur unpredictably and may cause serious damage to the
patient in some situations, for example, getting a seizure while driving or
crossing a road may lead to a person losing his life. In such a scenario,
a reliable mechanism to predict the onset of seizure beforehand is much
desirable. Past work has been dedicated to the detection of seizure activity
by analysis of EEG data [1] [2]. However, the presence of certain patterns in
the EEG in the pre-ictal stage, indicating a future occurrence of a seizure, has
been established recently [3]. In this study, we shall focus towards reliable
real-time prediction & detection of epileptic seizures.
In this thesis, we initially implemented a seizure detection algorithm using
discrete wavelet transform and Support Vector Machine (SVM) classifier to
detect the presence of seizures in a given EEG signal for a single channel data.
Furthermore, We used the Mean Phase Coherence (MPC) as a measure of
phase synchronization to predict the impending seizures in a multi-channel
EEG data. We showed that during the pre-ictal stages, the MPC values
and thus the synchronization between various channels was found to drop
significantly below the level in an non-ictal EEG signal. Thus, we used
this concept to develop a real-time model in MATLAB for the prediction of
epileptic seizures prior to their actual occurrence. We have also implemented
the above algorithm & technique in Hardware on a Raspberry Pi architecture.
Acknowledgments
I, Gorish Aggarwal, would like to express my deepest gratitude towards my
Bachelor’s Thesis supervisor Dr. Tapan Gandhi, for his invaluable knowl-
edge, motivation and constant support during the project. Tapan sir has
been very supportive during the project. He has provided insightful discus-
sions about the ongoing research on epilepsy. Hw has always guided us to
work towards the betterment of the society and to dream big. Working with
him for my B.Tech project has truly helped me to build a greater under-
standing of this field.
I would also like to thank Mr. Piyush Swami, Mr. Sanjeev Nara and Mr.
Chetan Ralekar for giving us advice, opinions and suggestions for further
improvement in the project. They also gave the much needed data for the
project. The time I spent with the team and at the Neuro-Computing lab
was a great learning experience for me. It helped me to develop my appetite
for this field of research and I would love to continue working in this field
later on in my life so as to help society in a better way. I would also like to
thank Akash Verma, my project partner for the first phase of the project.
We have worked together for the developing the algorithm for the detection
of seizure and giving a proof of concept for seizure prediction in the BTech
Project - 1. His academic genius helped to take the project a long way for-
ward. In the end, I would like to thank my teachers, parents and friends for
their constant support and encouragement.
Gorish Aggarwal
2012EE10454
Contents
1 Introduction 1
2 Literature Review 4
2.1 Previous research on detection of seizure . . . . . . . . . . . . 4
2.2 Previous research on prediction of seizures . . . . . . . . . . . 6
3 Background Work 9
3.1 Electroencephalography . . . . . . . . . . . . . . . . . . . . . 9
3.2 EEG frequency bands . . . . . . . . . . . . . . . . . . . . . . . 10
3.3 Wavelet Transform . . . . . . . . . . . . . . . . . . . . . . . . 11
3.4 Morphological Operations . . . . . . . . . . . . . . . . . . . . 12
4 Detection 16
4.1 Bonn University Data . . . . . . . . . . . . . . . . . . . . . . 16
4.2 Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2.1 Pre-processing of Data . . . . . . . . . . . . . . . . . . 17
4.2.2 Decomposition of Data into separate frequency bands . 17
4.2.3 Feature Set Extraction . . . . . . . . . . . . . . . . . . 18
4.2.4 Training the classifier . . . . . . . . . . . . . . . . . . . 19
4.3 Testing & Results . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.3.1 Feature set analysis . . . . . . . . . . . . . . . . . . . . 20
4.3.2 Accuracy, sensitivity, Specificity . . . . . . . . . . . . . 23
4.4 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
c© 2015, Indian Institute of Technology Delhi
5 Prediction 26
5.1 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
5.2 Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.2.1 Mean Phase Coherence . . . . . . . . . . . . . . . . . . 27
5.2.2 Spike Rate . . . . . . . . . . . . . . . . . . . . . . . . . 29
5.2.3 Phase synchronization using bi-variate empirical mode
decomposition(BEMD) . . . . . . . . . . . . . . . . . . 31
5.3 Testing and Results . . . . . . . . . . . . . . . . . . . . . . . . 31
5.3.1 Mean Phase Coherence . . . . . . . . . . . . . . . . . . 31
5.3.2 Spike Rate . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.3.3 Bi-Empirical Mode Decomposition . . . . . . . . . . . 41
5.4 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6 Real Time Prediction Model 44
6.1 Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6.2.1 Patient with Non-generalized Epilepsy . . . . . . . . . 45
6.3 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6.2.2 Patient with Generalized Epilepsy . . . . . . . . . . . . 49
7 Conclusions and Future Work 51
Bibliography 53
List of Figures
3.1 Brain Electrodes Location [4] . . . . . . . . . . . . . . . . . . 10
3.2 One cycle of Haar wavelet transform . . . . . . . . . . . . . . 12
3.3 Erosion of an image [5] . . . . . . . . . . . . . . . . . . . . . 13
3.4 Dilation of an image [5] . . . . . . . . . . . . . . . . . . . . . 14
3.5 Opening of an image [5] . . . . . . . . . . . . . . . . . . . . . 15
3.6 Closing of an image [5] . . . . . . . . . . . . . . . . . . . . . . 15
4.1 Seizure free signal in the delta band . . . . . . . . . . . . . . . 20
4.2 Seizure signal in the delta band . . . . . . . . . . . . . . . . . 21
4.3 Entropy of samples for their wavelets in the alpha band . . . 22
4.4 Maximum Power spectral density for the samples correspond-
ing to their wavelets in the alpha band . . . . . . . . . . . . . 23
4.5 Kurtosis of data samples corresponding to their wavelets in
the Alpha band . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.6 Kurtosis of data samples corresponding to their wavelets in
the delta band . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.1 Seizure Activity for Patient 1 . . . . . . . . . . . . . . . . . . 32
5.2 MPC for patient 1 for channels O2 and T6 . . . . . . . . . . . 33
5.3 MPC for patient 1 for channels O2 and P4 . . . . . . . . . . . 34
5.4 MPC for patient 1 for channels F8 and T4 . . . . . . . . . . . 34
5.5 Seizure Window for patient 2 . . . . . . . . . . . . . . . . . . 35
5.6 MPC for patient 2 for channels C4 and P4 . . . . . . . . . . . 36
5.7 MPC for patient 2 for channels C3 and P3 . . . . . . . . . . . 36
5.8 MPC for normal person for channels T4 and F8 . . . . . . . . 37
5.9 MPC for normal person for channels F4 and FP2 . . . . . . . 37
c© 2015, Indian Institute of Technology Delhi
5.10 Seizure Interval of Patient 1. Note that the seizure is present
in left hemisphere only . . . . . . . . . . . . . . . . . . . . . . 39
5.11 Spike Rate in Channel PG1(left hemisphere) . . . . . . . . . . 40
5.12 Spike Rate in Channel PG2(right hemisphere) . . . . . . . . . 40
5.13 Spike Rate in Channel FP2 . . . . . . . . . . . . . . . . . . . 41
5.14 Spike Rate in Channel PG1 . . . . . . . . . . . . . . . . . . . 42
5.15 Plot of Mean phase coherence using BEMD for channels PG2
and F8. The plot corresponds to the phase coherence values
of 3rd IMF (intrinsic mode function) . . . . . . . . . . . . . . 42
6.1 Mean Phase Coherence values between channels T5 and P3.
Blue denotes inter-ictal stage, Green denotes pre-ictal, Red
denotes ictal stage . . . . . . . . . . . . . . . . . . . . . . . . 46
6.2 Mean Phase Coherence values between channels T5 and O1 . . 46
6.3 Mean Phase Coherence values for various channel pairs in left
hemisphere . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
6.4 Mean Phase Coherence values between channels FP2-F8 (right
hemisphere) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
6.5 Mean Phase Coherence values between channel pair related to
occipital zone . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
6.6 Mean Phase Coherence values between occipital zone and P4
in non-seizure hemisphere . . . . . . . . . . . . . . . . . . . . 49
6.7 Mean Phase Coherence values between channel pairs(other
than occipital lobe) in non-seizure hemisphere . . . . . . . . . 50
Chapter 1
Introduction
Epilepsy is a chronic brain disorder characterized by recurrent seizures. They
are brief stretches of involuntary movement affecting either a part of the body
or the entire body and occur due to the excessive electrical discharges in a
group of brain cells. Seizures can vary in their origin location, distance of
spread as well as the time and frequency of occurrence.
According to the World Health Organization[6], Epilepsy affects around 50
million people worldwide, making it one of the most common neurological
disease, along with Stroke and Alzheimers disease. Each year, around 2.4
million people are diagnosed with epilepsy globally. Epilepsy is a huge prob-
lem in developing nations where it affects around 40 millions people. The lack
of knowledge combined with non-existence of proper treatment for epilepsy
makes the problem enormous for the people of developing countries. Reports
show that only around 5% of the people diagnosed with epilepsy in India
receive treatment and care for the same[7]. The rest, majority of which are
rural people, do not get benefit of specialized treatment.
There is no known cause associated with epilepsy in most of the cases. How-
ever sometimes, brain injury, stroke, brain tumor and developmental abilities
have been identified to cause epilepsy in some patients. The major symptoms
of epilepsy are continued occurrence of seizure attacks. The younger and the
older generation are known to be most prone to epileptic seizures, though
it can be contracted by anyone at any time. Since the attack themselves
are highly unpredictable in nature and magnitude, they can cause serious
damage to the patient in some situations .
Therefore, a low cost, easily accessible, point of care testing method for the
detection and prediction of seizure is required, to monitor the patient’s men-
tal condition and warn him in advance of an impending seizure attack.
In this project, we have reviewed many of the existing techniques used for
detection and prediction of seizures. During the literature review, we have
come across many linear and non linear techniques for analysis and process-
c© 2015, Indian Institute of Technology Delhi
2
ing of EEG data for the prediction of seizures. We have designed a real time
prediction algorithm which can predict an impending seizure in the near fu-
ture. Such an algorithm would go a long way in building a point of care,
cost effective and economically viable device for the prediction of epileptic
seizures. We are also trying to build a hardware architecture for direct EEG
signal collection and epileptic seizures prediction. Such a device would be a
revolutionary product and a first of its kind to be build. We are planning
to implement the structure on a Beagle board so that Integration of EEG
headset is possible.
The objectives achieved by us during the duration of the project are: BTech
Project Part-1 (Along with Akash Verma):
• Literature Review of the previous existing techniques for detection and
prediction of seizure.
• Classified EEG signals into their ictal and non-ictal stages by using our
seizure detection algorithm and an extensive feature set. Achieved a
good accuracy(94.5%) and high senstivity(96.25%) on the Bonn Uni-
versity Dataset.
• Provided a proof of concept for our seizure prediction algorithm. Demon-
strated that the Mean Phase Coherence values between the electrode
pairs in pre-ictal stages are less as compared to those in inter-ictal
stages.
BTech Project Part-2:
• Extensive testing of the previously developed prediction algorithm on
more than 10 subjects to ensure its correctness and functioning.
• Implemented a real-time MATLAB based on the above concept which
can take EEG signals as inputs in real-time and process each window
sequentially.
• Literature Review of other existing seizure prediction techniques to
increase the pool of features set to be used for classification of pre-ictal
and ictal stages.
c© 2015, Indian Institute of Technology Delhi
3
• Used Spike Rate as another parameter for predicting the onset of an
epileptic seizure. Developed the MATLAB model for finding the ictal
spike rate in an EEG signal.
c© 2015, Indian Institute of Technology Delhi
Chapter 2
Literature Review
Research work on Detection and Prediction of Epileptic Seizure using EEG
has been going on for more than 60 years but only from the mid 1990s has
there been a significant increase in the methods used to detect and predict
the seizures using EEG. The common thread throughout the research is the
deviation of EEG signal from the normal condition during and before the
seizure period (pre-ictal) [8] . With the recent advances in technology and
knowledge, pioneering research groups could now conceivably attempt to de-
velop a system that could detect an ongoing seizure or predict the future
onset of a seizure, thus helping the people prone to seizure to be careful in
advance about an imminent seizure.
Many research groups have been trying to devise various methods of using
EEG data from the brain electrodes to automatically act as an alert system
for the patient to warn him or his caregivers of an impending seizure so that
precautionary measures can be taken in time.[9]. Researchers are also trying
to use the warning system for triggering seizure control mechanisms. Vari-
ous linear and non-linear signal processing techniques coupled with machine
learning algorithms for both uni variate as well as multivariate data have
been used for the above. [10] In this chapter, we shall discuss the major
techniques used for the detection and prediction of seizures in the past have
been discussed and then, we shall give a brief overview into the techniques
applied by us for our work.
2.1 Previous research on detection of seizure
Although the relationship between the mental states and the rhythmic char-
acter of the EEG has been known from a long time, the mechanisms to detect
the mental states(for eg: seizures, sleep or awake condition) of a person from
an EEG data were built only in 1990s. Recently, many studies have also
c© 2015, Indian Institute of Technology Delhi
2.1 Previous research on detection of seizure 5
shown that EEG recording can be used to predict seizures even before the
actual seizure occur. The most common seizure detection techniques uses a
machine learning based classifier to train the feature sets extracted from the
EEG data. We reviewed four major papers which uses this techniques for
the detection of seizures.
Panda et al. [11] used a wavelet transform to decompose signals into different
frequency bands and a SVM classifier to separate epileptic data. The Bonn
university data set [12] was used as a sample for training and testing data
set. The feature set used for the detection purpose included energy, entropy
and standard deviation for each of the frequency bands decomposed using the
Daubechies Discrete Wavelet Transform (DWT-db2). The accuracy achieved
was 91.2% with time for detection around 0.5 sec.
Srinivasan et al. [13] have used approximate entropy measure as a feature
and implemented a neural network based classifier, to detect the presence of
seizure in EEG recording.
Similarly, Ahammad et al. [14] also used the Bonn university data set and
the CHB-MIT scalp database[60] for the detection and onset detection of
seizure respectively. Their feature set included the mean, standard devia-
tion, entropy, power spectral density as well as some statistical features like
inter quartile range and mean absolute deviation. The reported accuracy
was 84.2% with a linear classifier along with a specificity and sensitivity of
85.6% and 76% respectively.
Gandhi et al. [15] developed an expert model for the detection of epileptic ac-
tivity in EEG signature using a probabilistic neural network for classification
of data. Clinical database was used for the training and testing the classifier.
Ten fold cross validation was used in the expert model. A high accuracy of
99.33% and specificity and sensitivity of 99.6% and 99% was obtained using
the model. Yuan et al. [16] compared the SVM and PNN classifier for de-
tection of seizure in EEG signal and showed that SVM classifier requires a
lower number of features sets compared to PNN to accurately determine the
data containing epilepsy. Cao’s method was used to compute the embedding
dimensions of the EEG data which were further used as feature sets for the
classifiers.
c© 2015, Indian Institute of Technology Delhi
2.2 Previous research on prediction of seizures 6
2.2 Previous research on prediction of seizures
Prediction of seizure is a relatively new field as compared to the detection
which has been prevalent for a long time. In the late 1990s, a hypothesis [17]
[18] was given that the seizure starts building minutes to hours before the
actual attack. This led to an interest and subsequent work on the prediction
of seizure. However, till now, a robust technique has not been developed
to predict seizure in all situations. The papers on the prediction of seizures
are being reviewed by other authors as only near-chance predictions [19].We
came across many papers, such as those by Carney et al. [18] and Fazel-
Rezai et al. [20], where several techniques for seizure prediction have been
discussed. They provided a good starting point for the research.
Mormann et al. [21] showed that phase synchronization between different
EEG channels could be used as measure for detecting the pre-ictal stage. He
showed that the correlation coefficient can be used as statistical tool for the
finding the phase synchronization between the EEG channels. The reporting
shown in the paper shows that in 12 out of 14 cases, the ictal stages can be
predicted in advance. In another related paper, Mormann [22] found that
both the linear and non-linear techniques shows similar performance for the
prediction of seizures, thereby indicating that the changes in dynamics were
not necessarily caused solely by non-linear features of dynamics.
Le Van Quyen et al. [23] have used a method based on measuring the dynam-
ical similarity of the EEG recording with a reference state. It is a uni-variate
technique. The training data is first segmented into inter-ictal, pre-ictal and
ictal stages. For each stage, the method of delays has been used to trans-
form the time series data to a sequence of points in an m-dimensional space.
Instead of using the sample values directly, the duration between two con-
secutive positive zero crossings has been used. This allows for a greater
robustness to additive noise. Then, the dynamical similarity between any
two windows was calculated by computing the cross correlation integral be-
tween the windows. [24] The dynamical similarity is close to one if the signal
is stationary, while it is lower for non stationary signal. The signal windows
were compared to a reference window,extracted from the inter ictal stage.
The authors observed a decrease in similarity index, a few minutes before
c© 2015, Indian Institute of Technology Delhi
2.2 Previous research on prediction of seizures 7
the seizure occurred.
Maiwal et al. [25] have given a set of criteria and performance measures, to
evaluate seizure prediction techniques, before they can be applied clinically.
Their study mainly focuses in the most popular technique of dynamical sim-
ilarity [26].
Mormann et al. [19] states that many of the measures previously considered
suitable for prediction perform no better than a random predictor. He pro-
poses that only if the performance of a algorithm for the original seizure times
is significantly better than the performance for a number of independent re-
alizations of the surrogate seizure times, can the null hypothesis, namely,
that a given algorithm cannot detect a pre-seizure state with a performance
above chance level, be rejected. As an example, he specified that the paper
using correlation dimension, the Lyapunov exponent and the signal energy,
were not able to discriminate the pre-ictal from the inter-ictal period above
chance level.
Schad et al. [27] have investigated the detection and prediction of seizure, us-
ing scalp and intra-cranial recordings. They have used a neural network based
classifier, using simulated leaky integrate and fire neurons.Their method uses
the derivative of the EEG signal as a feature. The times at which this deriva-
tive exceeded a certain threshold is noted and a pulse is generated at this
time. These pulses are integrated with the leaky neurons, and when the in-
tegral value reaches a threshold, the integrator is reset to zero. A signal is
generated, every time the integrate and fire neuron is reset, giving a spiking
rate. This spiking rate is then used to declare the presence of seizure activ-
ity. In a similar way, the derivative of the spiking rate is employed to detect
pre-seizure changes, in order to predict the occurrence of seizure.
Mirowski et al. [28] have studied 4 bi-variate features of EEG synchroniza-
tion, namely, cross-correlation, interdependence, dynamical entrainment and
wavelet synchronization. Non linear interdependence measures the distance
between two EEG signals in state space, which is similar to dynamical sim-
ilarity. Dynamical entrainment is a measure of the difference between the
largest Lyapunov exponent between two time series, which is a measure of
chaos. The third is similar to phase synchronization technique, given in [22].
These have been used as features for several machine learning techniques,
c© 2015, Indian Institute of Technology Delhi
2.2 Previous research on prediction of seizures 8
like SVM, logistic regression and convolutional neural networks. They have
concluded that the convolutional neural network technique on the wavelet
coherence feature, achieves a sensitivity of 71%, without any false positives.
Zheng et al. [29] used a Bi variate Empirical Mode Decomposition(BEMD)
to first decompose windows of each pair of EEG to intrinsic mode func-
tions(IMF). BEMD was used due to the non-stationary nature of EEG sig-
nals. The BEMD technique decomposes the data into various IMFs without
losing the time information contained the original data. The mean phase
coherence for all the windows is then calculated and observed for occurrence
of pre-ictal stage. He observed that there was both an increase and decrease
of phase synchronization before the seizure onset.
Shufang et al. [30] used spike rate to distinguish the pre-ictal stage from ictal
stage. The research uses the hypothesis that with the advent of seizures, the
spike rate of various windows will take different values. They used a mor-
phology filtering operation to estimate the background EEG signal from the
original and deduct the background signal from the original signal to get the
spike signal. The morphology filter can be implemented with simple addition
and subtraction operations, thus reducing the computational complexity of
the algorithm. The spike rate of each window is analysed to find the increase
in the rate. Using the spike rate, they were able to predict a seizure with a
sensitivity of 75.8% and false prediction rate of 0.09hr. Guanghua et al. [31]
shows an improved spike detection algorithm in EEG signals using Morpho-
logical filtering operations.
Teixeira et al. [32] tried to classify the EEG signal of an epileptic patient
into 4 state: inter-ictal, pre-ictal, ictal and post-ictal. They used multiclass
SVM classifier and used 22 univariate features such as Energy, Mean, Power,
Hjorth Parameters, etc. They used an extensive patient database of 278 pa-
tient to perform this research. They were able to anticipate more than half
of the seizure through their method with a false prediction rate of less than
0.15hr. They also observed that invasive and non-invasive EEG recordings
gave nearly the same results in terms of prediction of seizures.
c© 2015, Indian Institute of Technology Delhi
Chapter 3
Background Work
3.1 Electroencephalography
Electroencephalography (EEG) is the recording of electrical activity along
the scalp produced by the firing of neurons within the brain [33]. In clinical
contexts, EEG refers to the recording of the brain’s spontaneous electrical
activity over periods of time. EEG device is attached to the scalp through
electrodes. These electrodes are connected to a machine, which records the
electrical impulses. The signals are then processed to finally get the mental
state of the brain during the recording period. Each area of the brain pro-
duces a different brain wave according to the mental state, the kind of tasks
the person was imagining and the general condition of the patient [34].
The continuous monitoring of EEG signals can be highly helpful in clinical
environments e.g. for diagnosing epilepsy or brain tumor, predicting seizure,
detecting abnormal brain stages or even post stroke neuro-rehabilitation [35].
The EEG data is usually obtained through a EEG electrodes attached to
the scalp of the brain. These electrodes are connected to a machine, which
records the electrical impulses received from the brain.
The 10-20 system is an internationally for the placement of electrodes on
the scalp of the brain for recording the EEG data. The system is based on
the relation between the electrodes location and the corresponding area of
cerebral cortex. The number ’10’ and ’20’ are representative of the fact that
the distance between adjacent electrodes are either 10% or 20% of the total
front- back or left-right skull distance [4]. All the electrode placement sites
are given a specific name depending on the cerebral lobe underlying and the
hemisphere. The letters F, T, P and O stand for frontal, temporal, pari-
etal, and occipital lobes, respectively. The letter C is used to identify the
electrodes located over the central region of the brain. The even and odd
numbers used to refer to the electrodes points to the positioning of electrodes
c© 2015, Indian Institute of Technology Delhi
3.2 EEG frequency bands 10
Figure 3.1: Brain Electrodes Location [4]
in right and left hemispheres respectively. Figure 1.1 shows the placement
of electrodes on the scalp for obtaining the EEG recording. The outer circle
in the figure is drawn at the level of nasion and inion while the inner circle
represents the temporal line of electrodes.
3.2 EEG frequency bands
The signals received through the BCI are then processed to finally get the
mental state of the brain during the recording period. Each area of the
brain produces a different brain wave according to the mental state, the kind
of tasks he was imagining and the general condition of the patient. The
EEG signal consists of different frequency bands defined by their wave to
characterize and identify psychological states [33]:
• Delta Waves: Frequency ranges up to 4 Hz. It tends to be the highest
in amplitude. It is seen normally in adults for slow wave sleep.
• Theta Waves: Frequency ranges from 4 Hz to 7 Hz. Theta is seen
normally in young children. It may be seen in drowsiness or arousal in
older children and adults; it can also be seen in meditation.
c© 2015, Indian Institute of Technology Delhi
3.3 Wavelet Transform 11
• Alpha waves: Frequency ranges from 8 Hz to 12 Hz. It is higher in
amplitude on the dominant side.
• Beta Waves: Frequency ranges from 12 Hz to about 30 Hz. It is seen
usually on both sides in symmetrical distribution and is most evident
frontally. Beta activity is closely linked to motor behavior and is gen-
erally attenuated during active movements [15].
• Gamma Waves: Frequency ranges are approximately 30-100 Hz. Gamma
rhythms are thought to represent binding of different populations of
neurons together into a network for the purpose of carrying out a cog-
nitive or motor function.
The normal Electroencephalography (EEG) varies by age. The EEG in child-
hood generally has slower frequency oscillations than the adult EEG. Pre-
viously, Epileptic Seizures information were thought to be present only in
the lower frequency bands(Theta, Alpha, Beta). However, there are growing
number of studies which show that the high frequency oscillations(Gamma
rhythms) also contain important data about seizure activity [36]. In our
study, we have only used frequencies till 40 Hz for the detection and predic-
tion of epileptic seizures.
3.3 Wavelet Transform
Wavelet transform is a tool to study time varying signals. Unlike Fourier
transform, which represent the signal in frequency domain and loose the
time domain information, the wavelet transform is capable of representing
the frequency, as well as, time related information. In digital domain, where
signals are represented by their sampled values, the discrete wavelet trans-
form is used as an alternative to Fast Fourier transform [37]. We have used
a Haar Wavelet transform to get various frequency bands for the data. The
Haar wavelet transform can be computed in O(N) time, N being the size of
the input data. For a time series input of 2n values, the Haar wavelet trans-
form outputs two time series, each of length 2n−1[38]. One of these, called
c© 2015, Indian Institute of Technology Delhi
3.4 Morphological Operations 12
Figure 3.2: One cycle of Haar wavelet transform
the approximate coefficients, are formed by taking the mean of two consec-
utive values in the original time series. The sum operation is analogous to
the low pass filtering of the data. The second series, called detail coefficients,
is formed by taking the difference of two consecutive values of the original
series. The difference operation as high pass filtering of the data. Since each
of the resultant time series have information bandwidth half of the original
time series, they are down-sampled by 2. One cycle transform is illustrated
in Fig 3.2.
3.4 Morphological Operations
Mathematical morphology is a tool for extracting image components useful
in the representation and description of region shape, such as boundaries,
skeletons and convex hulls[39]. Morphological operators often take a binary
image and a structuring element as input and combine them using a set
operator (intersection, union, inclusion, complement). They process objects
in the input image based on characteristics of its shape, which are encoded
in the structuring element. The structuring element is a small binary image,
i.e. a small matrix of pixels, each with a value of zero or one. The structuring
element is positioned at all possible locations in the image and it is compared
with the corresponding neighborhood of pixels. Some operations test whether
c© 2015, Indian Institute of Technology Delhi
3.4 Morphological Operations 13
Figure 3.3: Erosion of an image [5]
the element fits within the neighborhood, while others test whether it hits
or intersects the neighborhood. The four basic operations of Morphological
filtering are[40]-[41]:
• Erosion : The erosion operation is defined as:
(fθg)(n) = minm=0,1,...,M−1
{f(n+m)− g(m)}
where n = 0, 1...., N −M . For an image, when the center of a struc-
turing element g(n) is located on the origin of the image f(n), then the
erosion of A by B is the locus of points reached by the center of B when
B moves inside A. This can be visualized in the Fig 3.3. The erosion
of the dark-blue square by a disk, results in formation of a light-blue
square.
• Dilation : The dilation operation is defined as:
(f ⊕ g)(n) = maxm=0,1,...,M−1
{f(n−m) + g(m)}
where n = M − 1,M − 2...., N − 1. For an image, when the center of
a structuring element g(n) is located on the origin of the image f(n),
then the dilation of A by B is the locus of the points covered by B when
the center of B moves inside A. This can be visualized in the Fig 3.4.
c© 2015, Indian Institute of Technology Delhi
3.4 Morphological Operations 14
Figure 3.4: Dilation of an image [5]
The dilation of the dark-blue square by a disk results in formation of
the light-blue square with rounded corners.
• Opening : The opening operation is given by
(f ◦ g)(n) = [(fθg)⊕ g](n)
where f(n) and g(n) are discrete functions defined on F = 0, 1...., N − 1
and G = 0, 1....,M − 1 respectively and N >> M . For an image, the
opening operation is the locus of translations of the structuring element
B inside the image A. This can be visualized in the Fig 3.5. The opening
of the dark-blue square by a disk, results in formation of the light-blue
square with round corners.
• Closing : The closing operation is given by
(f • g)(n) = [(f ⊕ g)θg](n)
where f(n) and g(n) are discrete functions defined on F = 0, 1...., N − 1
and G = 0, 1....,M − 1 respectively and N >> M . For an image, the
closing is the complement of the locus of translations of the symmetric
of the structuring element outside the image A. This can be visualized
c© 2015, Indian Institute of Technology Delhi
3.4 Morphological Operations 15
Figure 3.5: Opening of an image [5]
Figure 3.6: Closing of an image [5]
in the Fig 3.6. The closing of the dark-blue shape (union of two squares)
by a disk, which results in the union of the dark-blue shape and the
light-blue areas.
c© 2015, Indian Institute of Technology Delhi
Chapter 4
Detection
In this chapter, we will describe our method for the detection of seizure in a
given EEG signal, the data sets we have used for testing the algorithm and
the results we have obtained for the same.
4.1 Bonn University Data
The dataset used for detection part was obtained from the University of Bonn
[12]. The dataset consists of 5 sets of data, labelled as A,B,C,D and E. Each
set consists of 100 EEG recordings, each recording for a duration of 23.6
seconds, at sampling rate of 173.61 Hz. All of the recordings were devoid of
artefacts, such as eye movements or muscle movement. The details of each
set are described below-
1. Set A and Set B correspond to 5 healthy patients’ surface EEG record-
ing. The set A consists of recording with eyes open, while set B consists
of recording with eyes closed.
2. Sets C and D consist of recording from patients suffering from epilepsy.
Set D corresponds to recordings from the epileptogenic zone, while
Set C consists of recordings from corresponding zone in the opposite
hemisphere. Both set C and set D were recorded during seizure free
intervals. That is, they correspond to inter-ictal stage.
3. Set E corresponds to data from patients with diagnosed epilepsy, recorded
during seizure intervals. That is, set E consists of the ictal stage.
c© 2015, Indian Institute of Technology Delhi
4.2 Methodology 17
4.2 Methodology
In this section, we will explain the method used for the detection of seizure.
We have used Support Vector Machine Classifier to train and test the feature
sets extracted from each of the frequency bands. Discrete wavelet transform
was used. The procedure explained above has been implemented before in
Panda et al. [11] but only 3 features were used for each frequency band. The
following steps were implemented for the detecting the presence of seizure
activity in an EEG recording.
1. Pre-processing of data
2. Decomposition of Data into separate frequency bands
3. Feature set extraction
4. Training and testing of data
4.2.1 Pre-processing of Data
The data was pre-processed to remove high frequency (if any), noise in the
EEG as well as power line interference from the signal. The EEG recording
was filtered using an FIR filter with cutoff frequency of 40 Hz. A notch filter
at 50 Hz was applied to the EEG signal.
4.2.2 Decomposition of Data into separate frequency
bands
After pre-processing, a discrete time wavelet transform was used, to split
each EEG recording into the 5 sub bands, namely- delta, theta, alpha, beta
and gamma. The wavelet transform provides a convenient and simultaneous
picture of frequency and time for the signal. It also gives insights into the
significance of certain frequency bands that characterize a seizure. We have
used the Haar Wavelet transform. The Haar wavelet transform uses simple
mathematical operations for separating low and high frequency data. For low
c© 2015, Indian Institute of Technology Delhi
4.2 Methodology 18
pass, it sums two consecutive values and for high pass, it takes difference of
consecutive values. The comparison of use of different wavelet transform was
done by Mohensi et al. [42]. Haar wavelet transform gave sufficiently good
results for decomposition of a signal into 2 bands and it was supplemented
by results too.
4.2.3 Feature Set Extraction
After separating the data into the five bands, the following features were
extracted from each of these bands:
1. The variance is the deviation of the signal from its mean. The variance
of seizure data is higher than the that of the normal data. It is given
as,
σ2 =
N∑i=1
(xi − µ)2
N
2. The mean signal energy of a seizure data generally tends to be higher
than that of normal data due to higher amplitudes. It is given as,
E =
N∑i=1
x2i
N
3. Power spectral density is calculated in two steps, first finding the
fast Fourier transform (X(wi)) of the time series and then taking the
squared modulus of the FFT coefficients.
P (wi) =|X(wi)|2
N
From this, the maximum and the minimum values are used.
4. Entropy is the measure of randomness and the information content of
a signal. To calculate the entropy of the given EEG signal, we have
c© 2015, Indian Institute of Technology Delhi
4.2 Methodology 19
used the Shannon entropy formula-
Entropy = −N∑i=1
x2i log(x2
i )
This equation goves the un-normalized entropy of the signal.
5. The inter quartile range of the EEG signal gives the statistical dis-
persion of a signal, which is a measure of how squeezed or stretched
a distribution is. To calculate the inter quartile range, the signal is
divided into two parts, one containing values lower than the median
and the other containing values higher than the median. Then, the
interquartile range is the difference between the median of the left half
and median of the right half.
6. Kurtosis is a measure of how much weight the tail of the probability
distribution has. Thus, the presence of spikes is indicated by increased
kurtosis. Kurtosis is calculated as-
Kurt[X] =
N∑i=1
(xi − µ)4
Nσ4
where X denotes the time series of an EEG data set and N the number of
samples in the signal. X =(
x1 x2 x3 .... xN
). In all of these features,
described above, we aim to capture the presence of signal spikes, which is a
signature of an existing seizure activity.
4.2.4 Training the classifier
We then used a linear support vector machine, to classify each recording as
having seizure or not having seizure. Again, the linear SVM classifier has a
very simple model of calculations and is thus not very heavy computationally.
The SVM was initially trained on 240 samples, of which 80 were true positive
(containing seizure activity) and 160 were true negative (seizure free). Then,
the model was tested on 20 true positive data and 40 true negative data.
c© 2015, Indian Institute of Technology Delhi
4.3 Testing & Results 20
Figure 4.1: Seizure free signal in the delta band
The source code for the above methodology can be found in the Appendix
section.
4.3 Testing & Results
Fig 4.1 shows the EEG signal for seizure free interval, while Fig 4.2 shows the
EEG signal for the ictal stage in the delta frequency band(0.5 to 4 Hz). As
we can see, the alpha band in the ictal stage contains high amplitude spikes,
as compared to that in the seizure free interval. The amplitude of the EEG
signal in the other bands also showed a rise in their values.
4.3.1 Feature set analysis
We have plotted the calculated values of the various features for the true
negative and true positive data. The seizure containing samples were found
to be significantly different from non-seizure samples for most of the the
frequency bands.
c© 2015, Indian Institute of Technology Delhi
4.3 Testing & Results 21
Figure 4.2: Seizure signal in the delta band
In the graphs Fig 4.3 - 4.6, the x-axis corresponds to the sample number,
while the y-axis corresponds to the entropy, maximum Power spectral density
and Kurtosis respectively. The x axis from 1 to 200 corresponds to sample
from seizure free intervals and from 201 to 300 correspond to samples having
presence of seizure activity.
1. Entropy: The entropy values in all bands declined, with Fig 4.3 de-
picting the entropy for wavelets in the sub band 10-20 Hz. We can see
that the entropy of the EEG samples in the ictal stage (samples from
201 onward) are lower than that of the seizure free stage (samples 1 to
200). Thus, we may conclude that during ictal stage, the randomness
in the EEG signal declines.
2. Power spectral density: We have plotted the maximum power spec-
tral density for the samples corresponding to the wavelets in the sub
band 10-20 Hz in Fig 4.4. Maximum PSD in the other sub-bands cor-
relate with this sub band. As expected, the maximum power spectral
density in during the ictal period (samples 201 to 300) is much higher
c© 2015, Indian Institute of Technology Delhi
4.3 Testing & Results 22
Figure 4.3: Entropy of samples for their wavelets in the alpha band
than that in the seizure free period (samples 1 to 200). Thus, power
spectral density is a good indicator of presence of seizure.
3. Kurtosis: The kurtosis for the samples is plotted in Fig 4.6 for wavelets
in the delta band and Fig 4.5 for those in the alpha band. As can be
seen, the kurtosis measure is relatively insignificant for classification in
the delta band. However, significant increase in kurtosis of the samples
is observed during ictal stage in the Alpha band wavelets. Thus, it
can be seen that some features are highly useful for classification in
some frequency bands while in other bands they are not particularly
important.
The signal energy, variance and inter-quartile range also showed significant
differences in the normal and the EEG sample. The signal energy and vari-
ance were higher for seizure duration due to high amplitude signals and the
inter-quartile range is higher due to presence of spikes in the signal.
c© 2015, Indian Institute of Technology Delhi
4.3 Testing & Results 23
Figure 4.4: Maximum Power spectral density for the samples correspondingto their wavelets in the alpha band
4.3.2 Accuracy, sensitivity, Specificity
Let us use TP for true positive classification, TN for true negative, FP for
false positive and FN for false negatives. The classification is TP if the
classifier detects a seizure, when the seizure is actually present, TN if it does
not detect seizure when seizure is absent, FP if it detects seizure when it
is actually absent and FN if it does not detect seizure when it is actually
present. The following evaluation measures were used-
1. Accuracy: It is defined as the sum of TP and TN as a percentage of
total test cases.
Accuracy =TP + TN
TP + TN + FP + FN∗ 100
2. Sensitivity: It is defined as -
Sensitivity =TP
TP + FN∗ 100
c© 2015, Indian Institute of Technology Delhi
4.4 Discussion 24
Figure 4.5: Kurtosis of data samples corresponding to their wavelets in theAlpha band
3. Specificity It is defined as-
Specificity =TN
TN + FP∗ 100
Following our approach, we obtained an accuracy of 94.4%, sensitivity of
96.25% and specificity of 89.38%.
4.4 Discussion
Comparing with the existing methods, we can see that our algorithm for
seizure prediction performs well. It has a very high sensitivity and is thus
very good for detection of seizure activity in patients with diagnosed epilepsy.
The result is partly due to the large ensemble of features that we have used
for the classification purpose. However, another reason for significant im-
provement is the proper pre-processing of the data to remove artifact from
the EEG signal.
c© 2015, Indian Institute of Technology Delhi
4.4 Discussion 25
Figure 4.6: Kurtosis of data samples corresponding to their wavelets in thedelta band
There could be further improvement in the results if more complicated tech-
niques were used for the wavelet decomposition of the signal. However, our
objective is to build a less computationally heavy algorithm that can be eas-
ily productized within low budget constraints. Therefore, the use of simple
techniques is important.
c© 2015, Indian Institute of Technology Delhi
Chapter 5
Prediction
In this chapter, we have described the algorithm used for predicting a seizure
attack in advance using EEG signal. Previously we had showed a Proof
of Concept to demonstrate the potential of using the drop in Mean Phase
Coherence values as a reliable indicator of an impending seizure. We had a
small pool of test subjects on which we tested the algorithm.
Now, we have more than 10 test individuals data set on which we have tested
our algorithm. The algorithm is able to predict most of the epileptic seizures
more than 5 minutes before the actual onset. Through the literature review,
we found other feature which can be used to improve the Mean Prediction
Time of our algorithm. It was found that spike rate is be good indicator for
predicting seizures. It gave a reasonable result in most of the cases.
5.1 Data
The data sets used for prediction of seizure was obtained from 10 Epileptic
patients and 2 Normal Individuals. The EEG data was received for 18 brain
electrode channels, 9 in each hemisphere. The electrode placement was ac-
cording to International 10 20 standards. The recordings were sampled at
frequency of 200 Hz. 7 of the patients had cases of generalized epilepsy and
remaining 3 had a focal epilepsy. The data was obtained from the Grass
Telefactor Twin3 EEG machine at the Neurology and Sleep Center, Hauz
Khas, New Delhi.
The EEG data of an epileptic patient which contains seizures can be classified
into 4 major regions:
• Inter-ictal: Duration in-between the seizures and at sufficient gaps ( 3
hours) from any seizure activities.
c© 2015, Indian Institute of Technology Delhi
5.2 Methodology 27
• Pre-ictal: Duration before and near to a seizure activities. Generally
chosen as 1-hour before a seizure. This is the region in which our system
should be able to predict that a seizure can occur in the near future.
• Ictal: The duration between the seizure beginning till its end.
• Post-ictal: Duration just after the seizure end till the EEG signal goes
back to normal.
5.2 Methodology
We tried 3 features to predict impending seizure activity. These were using
Mean - Phase Coherence, Spike rate and Bi-empirical mode decomposition.
Among these methods, the mean-phase coherence values between pairs of
neighboring electrodes gave the best results for the prediction. The Mean-
phase coherence values were found to decrease before the onset of an epileptic
seizure. The methodology and results for each of the algorithm are given
below. The source code for each of the methods can be found in the Appendix
section.
5.2.1 Mean Phase Coherence
Calculation of Mean Phase Coherence values between pairs of neighboring
electrodes has been used as a means of detecting phase synchronization be-
tween the 2 EEG channels. Phase Synchronization is defined as the locking
of the phases of 2 oscillatory system [51]. It is calculated as:
φn,m = nφa(t)−mφb(t) = constant (5.1)
The instantaneous phase of the signal can be calculated using
φ(t) = tan−1 s(t)
s(t)(5.2)
c© 2015, Indian Institute of Technology Delhi
5.2 Methodology 28
where s(t) is the Hilbert transform of the signal given by
s(t) = −iFT−1(FT (S(t)) ∗ sign(w)) (5.3)
Here FT and FT−1 denotes the Fourier and the inverse Fourier transform
respectively of the signal.
To measure the relative phase between these two signals a and b and to
confine the phase between (−π/2, π/2), the following formula is used with
values of m = n = 1
φ1,1 = φa(t)− φb(t) = arctansa(t)sb(t)− sa(t)sb(t)sa(t)sb(t)− sa(t)sb(t)
(5.4)
The mean phase coherence is calculated as:
R =
∣∣∣∣∣N−1∑j=1
eiφ1,1(j∆T )
∣∣∣∣∣N
(5.5)
Studies show that the mean phase coherence [19] as a measure of phase
synchronization between the EEG channels changes significantly during the
pre-ictal stage when the brain waves shows signs of seizure formation as com-
pared to the inter-ictal stage [50]. This change in phase synchronization was
found to occur before the actual seizure of seizure. Therefore, by measuring
the value of mean phase coherence between channels, we were able to predict
the onset of seizures. The following steps were used:
• Pre-processing of data: The initial EEG data from 20 channels was
filtered with a band pass filter from 0.5 Hz to 40 Hz and a notch filter
at 50 Hz (to remove interference from the power supply of 50 Hz). The
data sampled at frequency of 200 Hz was divided into windows of 5
seconds each.
• Calculation of Mean phase coherence(MPC): The MPC values
were calculated for each of the windows between 2 pairs of electrodes.
The electrodes were chosen such only the coherence values between
the neighboring pairs of electrodes in each hemisphere were observed.
c© 2015, Indian Institute of Technology Delhi
5.2 Methodology 29
This reduced the number of pairs to 24 from 153 (for 9 electrodes in
each hemisphere). The above step helps in reducing the computational
complexity as well as removes the redundancy in the data. The Hilbert
transform and MPC were then calculated using the equation 5.5.
• Thresholding and Classification By thresholding the running sum
of areas between the MPC values and their mean, we can find whether
a seizure attack is imminent in the near future. The threshold value
used in our case for 10 windows i.e. 50 seconds was -0.4. Whenever the
area between the graphs for the last 10 windows went below this value,
the alarm would be turned on to warn the patient of an impending
seizure. This threshold value was found to work fairly well for all the
cases.
5.2.2 Spike Rate
Seizures are usually characterized by generalized spikes in an EEG signal[31].
Spikes are transient signals with a pointed peak, clearly distinguishable from
the background activity. In addition, some previous studies [43],[44] have
shown that the spike rates change significantly minutes prior to a seizure.
Lange et al. [43] found that the rate of bilateral spikes increased obviously
across 20 min pre-ictal segments.
In this research, we have used spike rate as an indicator for prediction of
seizure. In an EEG signal, the spikes as well as the background EEG data
is present. [31] used Morphological filtering operations to identify the back-
ground noise and separate the spikes from the given EEG signal. We are also
going to use Mathematical Morphology to distinguish the spikes from the
original signal and thus, find the spike rate for the signal. The calculation is
as follows:
The opening and closing operations for Morphological filtering operations
were explained in 3.4. An opening operation can smooth the signal posi-
tive pulse (peak), while a closing operation can smooth the signal negative
pulse(valley). Since an ictal EEG signal contains both positive and neg-
ative phase spikes, the combination of morphological opening-closing(OC)
c© 2015, Indian Institute of Technology Delhi
5.2 Methodology 30
and closing-opening(CO) are used to detect bi-directional spikes[31]. They
are defined as
OC(f(n)) = f(n) ◦ g(n) • g(n)
CO(f(n)) = f(n) • g(n) ◦ g(n)
Where f(n) is the input time series signal and g(n) is the structuring element.
However, since the filtering operations leads to a change in amplitudes, the
results of OC operations has lower amplitude than original signal and those
of CO operations have a higher amplitude. Thus, their weighted mean is
used to avoid amplitude detection.
y(n) = 0.5 ∗ (OC(x(n))) + CO(x(k)))
where
x(n) = y(n) + z(n)
Here, x(n) is the original windowed EEG signal. y(n) is the slow-changing
background signal and z(k) are the detected spikes. z(n) can be found by
subtracting y(n) from x(n).
z(n) = x(n)− y(n)
The structuring element g(n) used for the morphological operations deter-
mines the performance of the transform and thus the accuracy of the seizure
prediction. In order to remove the background components of original EEG
and highlight spikes, the structuring element selected should reflect the geo-
metrical characteristic of the original EEG signals, and at the same time, the
width of structuring element must be between spike rhythm and background
EEG rhythm. We select triangle structure element as follows:
g(n) = k ∗ (1− ‖n‖L
)
Here n varies from -L to L and hence, the total length of structuring element
is 2L+1. The duration of the spikes on the EEG varies from 20 to 70 ms,
and most of amplitudes exceed 100 [45]. In this project, the value of L has
c© 2015, Indian Institute of Technology Delhi
5.3 Testing and Results 31
been chosen to be 5.
After detecting the spikes in the EEG signal, the spike rate is computed for
each 5 second window and results are compared to a threshold value which
can be used to classify the EEG signal window into pre-ictal, inter-ictal or
ictal stage.
5.2.3 Phase synchronization using bi-variate empirical
mode decomposition(BEMD)
In this method, the BEMD and Hilbert transform was used to decompose
pairs of EEG channels into intrinsic mode functions(IMFs) and extract phase
information from the data. The MPC values were then calculated for sepa-
rate windows for all the IMFs. The visual changes in each of the different
frequency bands were then observed and visualized for changes in the pre-
ictal stage.
5.3 Testing and Results
In this section, we will discuss the results obtained from using the three
techniques: Mean Phase Coherence, Spike Rate and BEMD. The first two
techniques, especially the first one, gave fairly good results for all the test
subjects. However, BEMD did not show good results for the data sets.
5.3.1 Mean Phase Coherence
In this part, We have presented our results for Seizure Prediction using Mean
Phase Coherence Values for 3 patients: one with focal epilepsy, with gener-
alized epilepsy and the last one for a normal patient. The value of mean
phase coherence was found to decrease significantly during the pre-ictal and
rise again during the ictal stages. This also proves the correctness of the
hypothesis that phase synchronization between different channels decreases
during pre-ictal stages. In the individual with no epilepsy, no such changes
were observed.
c© 2015, Indian Institute of Technology Delhi
5.3 Testing and Results 32
Figure 5.1: Seizure Activity for Patient 1
Patient with focal epilepsy
The first patient had a history of focal epilepsy in the occipital lobe. In
the recorded data available for the patient, the seizure is found at the time
00:13:01 i.e. 156th window for a window size of 5 seconds. Fig 5.1 shows the
location of seizure at the given location for all the channels.
Fig 5.2 shows the value of MPC between the channels O2 and T6 for all the
windows. The red line corresponds to the running mean values of the MPC
and the green line shows the smoothed values of the graph, smoothing done
by a moving average filter of length 4. Before the seizure actually occurs
at 156th window, we can see that the MPC values goes below the mean for
a long duration before finally rising back up at the seizure time. Though
there is variation of MPC throughout the recording period, the drop below
the mean just before the seizure is the longest and most widely pronounced.
c© 2015, Indian Institute of Technology Delhi
5.3 Testing and Results 33
Figure 5.2: MPC for patient 1 for channels O2 and T6
The MPC values just before seizure goes down around 93rd window. Around
window, we can sure due to continuous below mean values that this is the
pre-ictal stage. Hence, we could successfully predict seizures 4 minutes in
this case before the actual onset.
Fig 5.3 also shows the MPC values between O2 and P4. We can see that the
drop below the mean value is also pronounced highly just before the seizure.
However, in Fig 5.4, for the MPC values between T4 and F8, the drop is not
significant and thus, we will not able to tell from this data that a seizure is
impending. Therefore, we can say that the impact of phase synchronization
decrease in the pre-ictal period is not reflected in the entire brain in case of
a focal epilepsy.
Patient with generalized epilepsy
The second patient had a history of generalized epilepsy in the brain. The
data available is of 25 minutes. Fig 5.5 shows the seizure for the patient 2.
We can see that the EEG pattern shows large amplitude during the seizure
and also very small gaps between 2 seizure duration. The entire frame size is
around 100 seconds. The seizure is starting at 00:06:10. The pre-ictal stage
c© 2015, Indian Institute of Technology Delhi
5.3 Testing and Results 34
Figure 5.3: MPC for patient 1 for channels O2 and P4
Figure 5.4: MPC for patient 1 for channels F8 and T4
c© 2015, Indian Institute of Technology Delhi
5.3 Testing and Results 35
Figure 5.5: Seizure Window for patient 2
available for this patient is very short for only around 5 minutes. Hence, the
drop of the curve below the mean is not very distinctive. Fig 5.6 shows the
filtered MPC values between the channels C4 and P4. As we can see from
the figure, from the 10th window till the 55th window, there is a drop below
the mean of the filtered MPC values. Similarly, the above situation is also
observed for the MPC values(Fig 5.7) between channels C3 and P3 of the
left hemisphere.
Thus, we can receive an indication of the oncoming seizure from the MPC
graphs.
Normal Individual
We have also plotted the mean phase coherence for a normal person, while he
was asleep. The Fig 5.8 corresponds to the MPC between channel T4 and F8,
c© 2015, Indian Institute of Technology Delhi
5.3 Testing and Results 36
Figure 5.6: MPC for patient 2 for channels C4 and P4
Figure 5.7: MPC for patient 2 for channels C3 and P3
c© 2015, Indian Institute of Technology Delhi
5.3 Testing and Results 37
Figure 5.8: MPC for normal person for channels T4 and F8
Figure 5.9: MPC for normal person for channels F4 and FP2
c© 2015, Indian Institute of Technology Delhi
5.3 Testing and Results 38
while Fig 5.9 refers to the mean phase coherence between channel F4 and
FP2. From the graphs, we observe that the mean phase coherence values
neither increase, nor decrease considerably. Thus we can safely conclude the
absence of seizure. Also, there is no long term trend of MPC being below
the running average, so there is no prediction of an impending seizure. This
once again strengthens the basic idea of our approach.
5.3.2 Spike Rate
This subsection presents the results for utilizing the spike rate as a feature for
seizure prediction. The spike rate is seen to increase partially minutes before
the seizure. During the seizure activity, the spike rate reaches it maximum
values. It can also be seen the spike rate is different for different brain regions.
This concept can be used for focal localization of seizures.
Patient with seizure in specific regions
In this data set, the first seizure occurs around 12 minutes and 30 seconds
which corresponds to the 150th window in the EEG data. It is visible from
the seizure interval in Fig 5.10 that the seizure is present only in the left
hemisphere of the brain (Channels: PG1-P3). Fig 5.11 shows the Spike rate
of each window for the PG1 channel of Patient 1. It can be seen that though
the spike rate rises above 45 around 150th window, the increase in spike rate
begins from the 100th window, thus indicating an impending seizure. There is
a peak in spike rate in the end also which is more pronounced comparatively
in Fig 5.12 which represents spike rate in channel PG2 of right hemisphere.
The 1st seizure shows a very low spike rate of less than 10 in this channel
as compared to PG1. This is also an indicator of the fact that spike rate
is higher from those channels where the seizure is actually present. This
hypothesis can be used for the focal localization of a seizure and will be
highly helpful for the treatment.
c© 2015, Indian Institute of Technology Delhi
5.3 Testing and Results 39
Figure 5.10: Seizure Interval of Patient 1. Note that the seizure is present inleft hemisphere only
c© 2015, Indian Institute of Technology Delhi
5.3 Testing and Results 40
Figure 5.11: Spike Rate in Channel PG1(left hemisphere)
Figure 5.12: Spike Rate in Channel PG2(right hemisphere)
c© 2015, Indian Institute of Technology Delhi
5.3 Testing and Results 41
Figure 5.13: Spike Rate in Channel FP2
Patient with generalized epilepsy
The patient’s seizure in this case comes around 75th window as explained in
5.3.1 and shown in Fig 5.5. From the spike rate of Channel FP2 shown in
Fig 5.13, we can see that spike rate increases around 50th window and peaks
around 75th window. From the actual seizure Fig 5.5, we can see that not
all channels have similar peaks of amplitude during the seizures. For eg. the
channel PG1 has lower seizure amplitude peaks. The plot of this channel’s
spike rate Fig 5.14 also indicates a similar trend. The spike rate near 75th
window in PG1 is comparatively lower than those in channel FP2.
5.3.3 Bi-Empirical Mode Decomposition
As we can see from the Fig 5.15, the MPC values keep varying throughout the
duration of the data and there is no continuous decrease of the filtered value
of MPC below the running mean before the seizure duration (75th window).
Similar behavior is observed for other channels also. Since, the results we
achieved for this technique were not very distinctive, we did not use this
technique for the final results.
c© 2015, Indian Institute of Technology Delhi
5.3 Testing and Results 42
Figure 5.14: Spike Rate in Channel PG1
Figure 5.15: Plot of Mean phase coherence using BEMD for channels PG2and F8. The plot corresponds to the phase coherence values of 3rd IMF(intrinsic mode function)
c© 2015, Indian Institute of Technology Delhi
5.4 Discussion 43
5.4 Discussion
The hypothesis that the phase synchronization decreased minutes before
seizure occurrence was found to be true for most of the cases. Mean Phase
Coherence was used as a measure of phase synchronization between EEG
channels. For testing, multi-channel EEG data was used for more than 10 test
subjects. During the pre-ictal stage, the MPC values were found to decrease
as compared to the inter-ictal stage. However, as the seizure approaches, the
MPC values rises sharply indicating a higher phase synchronization between
channels during ictal period and lower synchronization during the pre-ictal
period. The results were found to work in case of both focal and generalized
epileptic seizures. We also used spike rate as a feature for predicting the
onset of seizure. The spike rate was found to increase as the seizure activity
approaches. The prediction time in case of using spike rate as a measure is
lower than in the case of Mean Phase Coherence. Spike rate can also to be a
useful tool for source localization of an epileptic seizure. The last technique
which applied Bi Variate Empirical Mode Decomposition before computing
Mean Phase Coherence did not yield any fruitful results.
c© 2015, Indian Institute of Technology Delhi
Chapter 6
Real Time Prediction Model
In this chapter, we describe the development of real-time model for the pre-
diction of epileptic seizure. The real-time model can predict an impending
seizure more than 5 minutes in advance with a fairly certain accuracy. It is
currently being implemented in MATLAB. However, it can be easily ported
to OCTAVE and then to Beagle Board/Raspberry Pi and be used for build-
ing a cost effective, point of care alert system. Such a device is not available
anywhere else in the world and it will be a revolutionary product in the field
of medical health care.
6.1 Methodology
In this model, we have used the concept of Mean Phase Coherence described
in subsection 5.2.1. However, now we are processing a single data window
at a time and analyzing it before proceeding to the next window. This way
we do not need the entire data at once. It is in contrast to the previous
implementation where the whole data was required in the beginning.
Three states were classified in the model: Inter-ictal, Pre-ictal and Ictal. The
states are colored with different colors in the results that we obtain: Blue for
Inter-ictal, Green for Pre-ictal and Red for Ictal. A threshold value was set
for area for fixed number of windows under the MPC curve and its running
mean curve. When the total area goes below this threshold in a particular
channel pair, the system gave an alert that a seizure attack might occur to
the patient in the next few minutes. The window size was kept at 2 sec for
all windows and the first few windows were neglected for calculating the area
to account for the sudden rise in MPC values.
The focus of the seizure may also be identified by carefully studying the
alarm occurrence time and MPC value drop in individual channel pair. We
found that for many cases that if seizure activity is visible in a particular
c© 2015, Indian Institute of Technology Delhi
6.2 Results 45
region, then the MPC drop will be better visible in the channel pairs from
that region majorly. But there were anomalies with this concept for a few
cases as will be demonstrated below.
For the data, we have used the same data as used for the offline prediction
of seizure 5.1.
6.2 Results
In this section, we will show the results and inferences that we obtained from
using the above model. The results are shown for 2 patients.
6.2.1 Patient with Non-generalized Epilepsy
5.3.2 In this case, we observe from Fig 6.1 and 6.2 that the model was able
to detect the pre-ictal stage at 75th window. The actual seizure onset is on
150th window. This gives us a prediction time of more than 6 minutes. Also
as we saw in Figs 5.11 and 5.12, there are spikes in the end and hence, a
seizure activity is also happening in the end of the given data. This can also
be validated by the fact that the Mean Phase Coherence Values are dropping
below the threshold value.
6.3 Discussion
The real-time seizure prediction model in MATLAB as to classify the EEG
signal into 3 stages: inter-ictal, pre-ictal and ictal. The results we found
were pretty good. The area under the curve for a fixed number of windows
was thresholded to obtain this classification. The mean prediction time for
detecting the pre-ictal stage was around 6 minutes. The model was tested
on various test subjects and it predicted the seizure correctly for most of the
cases. A anomaly was observed in the case of the patient with generalized
epilepsy where 1 of the channel pairs did not show a decrease in the MPC
values whereas other channels were showing a decrease in phase synchroniza-
tion.
c© 2015, Indian Institute of Technology Delhi
6.3 Discussion 46
Figure 6.1: Mean Phase Coherence values between channels T5 and P3. Bluedenotes inter-ictal stage, Green denotes pre-ictal, Red denotes ictal stage
Figure 6.2: Mean Phase Coherence values between channels T5 and O1
c© 2015, Indian Institute of Technology Delhi
6.3 Discussion 47
In Fig 6.3, we can see 4 EEG channel pair getting processed parallely andshowing similar results. These channel pairs are from the left hemispherewhere seizure activity is actually occurring 5.10.
Figure 6.3: Mean Phase Coherence values for various channel pairs in lefthemisphere
c© 2015, Indian Institute of Technology Delhi
6.3 Discussion 48
The Fig 6.4 show the MPC values and seizure stages as detected by the modelin the right hemisphere channels. It can be seen that there is no indicationof any ictal or pre-ictal activity in the graph near the 150th window. This iscorrect since the seizure activity is actually occurring in the left hemisphere.
Figure 6.4: Mean Phase Coherence values between channels FP2-F8 (righthemisphere)
c© 2015, Indian Institute of Technology Delhi
6.3 Discussion 49
6.2.2 Patient with Generalized Epilepsy
5.3.1
Figure 6.5: Mean Phase Coherence values between channel pair related tooccipital zone
Figure 6.6: Mean Phase Coherence values between occipital zone and P4 innon-seizure hemisphere
c© 2015, Indian Institute of Technology Delhi
6.3 Discussion 50
Figure 6.7: Mean Phase Coherence values between channel pairs(other thanoccipital lobe) in non-seizure hemisphere
c© 2015, Indian Institute of Technology Delhi
Chapter 7
Conclusions and Future Work
In this project, we developed a real-time model for prediction of epileptic
seizures and implemented it in MATLAB.
The hypothesis that the phase synchronization decreased minutes before
seizure occurrence was found to be true for most of the cases. Mean Phase
Coherence was used as a measure of phase synchronization between EEG
channels. For testing, multi-channel EEG data was used for more than 10 test
subjects. During the pre-ictal stage, the MPC values were found to decrease
as compared to the inter-ictal stage. However, as the seizure approaches, the
MPC values rises sharply indicating a higher phase synchronization between
channels during ictal period and lower synchronization during the pre-ictal
period. The results were found to work in case of both focal and generalized
epileptic seizures. We also used spike rate as a feature for predicting the
onset of seizure. The spike rate was found to increase as the seizure activity
approaches. The prediction time in case of using spike rate as a measure is
lower than in the case of Mean Phase Coherence.
We also implemented a real-time seizure prediction model in MATLAB as
to classify the EEG signal into 3 stages: inter-ictal, pre-ictal and ictal. The
results we found were pretty good. The mean prediction time for detecting
the pre-ictal stage was around 6 minutes. The model was tested on various
test subjects and it predicted the seizure correctly for most of the cases. For
more accurate testing of the model, longer recordings with sufficiently large
inter-ictal stages shall be required so that there is no overlap of the effects of
two seizures occurring close to each other and leading to errors in the results.
The model developed by us for the prediction of seizures is highly promising
for conversion to an actual product in the market. The MATLAB code has
been ported to OCTAVE and the acquisition and processing of EEG signal
can now be easily performed on a Beagle Board/Raspberry Pi. Such a de-
vice for the prediction of seizure is not available anywhere else in the world
currently and it will be a revolutionary product in the field of medical health
c© 2015, Indian Institute of Technology Delhi
52
care, benefiting millions of people without proper access to neuro clinical
facilities.
c© 2015, Indian Institute of Technology Delhi
Bibliography
[1] U. R. Acharya, S. V. Sree, G. Swapna, R. J. Martis, and J. S. Suri, “Automated eeg
analysis of epilepsy: a review,” Knowledge-Based Systems, vol. 45, pp. 147–165, 2013.
[2] D. K. Binder and S. R. Haut, “Toward new paradigms of seizure detection,” Epilepsy
& Behavior, vol. 26, no. 3, pp. 247–252, 2013.
[3] B. Litt and J. Echauz, “Prediction of epileptic seizures,” The Lancet Neurology, vol. 1,
no. 1, pp. 22–30, 2002.
[4] G. H. Klem, H. O. Luders, H. Jasper, and C. Elger, “The ten-twenty electrode sys-
tem of the international federation,” Electroencephalogr Clin Neurophysiol, vol. 52,
no. suppl., p. 3, 1999.
[5] Wikipedia, “Mathematical morphology — wikipedia, the free encyclopedia,” 2016.
[Online; accessed 3-May-2016].
[6] W. H. Organization, The World Health Report 2001: Mental health: new understand-
ing, new hope. World Health Organization, 2001.
[7] R. A. Scott, S. D. Lhatoo, and J. W. Sander, “The treatment of epilepsy in developing
countries: where do we go from here?,” Bulletin of the World Health Organization,
vol. 79, no. 4, pp. 344–351, 2001.
[8] E. Magiorkinis, A. Diamantis, and K. Sidiropoulou, Hallmarks in the history of
epilepsy: from antiquity till the twentieth century. INTECH Open Access Publisher,
2011.
[9] J. Dorfmeister, M. Frei, D. Lerner, I. Osorio, and J. Ralston, “System for the predic-
tion, rapid detection, warning, prevention, or control of changes in activity states in
the brain of a subject,” Nov. 30 1999. US Patent 5,995,868.
[10] A. Aarabi and B. He, “A rule-based seizure prediction method for focal neocortical
epilepsy,” Clinical Neurophysiology, vol. 123, no. 6, pp. 1111–1122, 2012.
[11] R. Panda, P. Khobragade, P. Jambhule, S. Jengthe, P. Pal, and T. Gandhi, “Classifi-
cation of eeg signal using wavelet transform and support vector machine for epileptic
seizure diction,” in Systems in Medicine and Biology (ICSMB), 2010 International
Conference on, pp. 405–408, IEEE, 2010.
[12] R. G. Andrzejak, K. Lehnertz, F. Mormann, C. Rieke, P. David, and C. E. Elger,
“Indications of nonlinear deterministic and finite-dimensional structures in time series
of brain electrical activity: Dependence on recording region and brain state,” Physical
Review E, vol. 64, no. 6, p. 061907, 2001.
[13] V. Srinivasan, C. Eswaran, and N. Sriraam, “Approximate entropy-based epileptic eeg
detection using artificial neural networks,” Information Technology in Biomedicine,
IEEE Transactions on, vol. 11, no. 3, pp. 288–295, 2007.
c© 2015, Indian Institute of Technology Delhi
BIBLIOGRAPHY 54
[14] N. Ahammad, T. Fathima, and P. Joseph, “Detection of epileptic seizure event and
onset using eeg,” BioMed research international, vol. 2014, 2014.
[15] T. Gandhi, B. K. Panigrahi, M. Bhatia, and S. Anand, “Expert model for detection of
epileptic activity in eeg signature,” Expert Systems with Applications, vol. 37, no. 4,
pp. 3513–3520, 2010.
[16] Y. Yuan, “Detection of epileptic seizure based on eeg signals,” in Image and Signal
Processing (CISP), 2010 3rd International Congress on, vol. 9, pp. 4209–4211, IEEE,
2010.
[17] S. Ramgopal, S. Thome-Souza, M. Jackson, N. E. Kadish, I. S. Fernandez, J. Klehm,
W. Bosl, C. Reinsberger, S. Schachter, and T. Loddenkemper, “Seizure detection,
seizure prediction, and closed-loop warning systems in epilepsy,” Epilepsy & Behavior,
vol. 37, pp. 291–307, 2014.
[18] P. R. Carney, S. Myers, and J. D. Geyer, “Seizure prediction: methods,” Epilepsy &
Behavior, vol. 22, pp. S94–S101, 2011.
[19] F. Mormann, R. G. Andrzejak, C. E. Elger, and K. Lehnertz, “Seizure prediction:
the long and winding road,” Brain, vol. 130, no. 2, pp. 314–333, 2007.
[20] A. Aarabi, R. Fazel-Rezai, and Y. Aghakhani, “Eeg seizure prediction: measures
and challenges,” in Engineering in Medicine and Biology Society, 2009. EMBC 2009.
Annual International Conference of the IEEE, pp. 1864–1867, IEEE, 2009.
[21] F. Mormann, K. Lehnertz, P. David, and C. E. Elger, “Mean phase coherence as a
measure for phase synchronization and its application to the eeg of epilepsy patients,”
Physica D: Nonlinear Phenomena, vol. 144, no. 3, pp. 358–369, 2000.
[22] F. Mormann, T. Kreuz, R. G. Andrzejak, P. David, K. Lehnertz, and C. E. Elger,
“Epileptic seizures are preceded by a decrease in synchronization,” Epilepsy research,
vol. 53, no. 3, pp. 173–185, 2003.
[23] M. Le Van Quyen, J. Martinerie, V. Navarro, P. Boon, M. D’Have, C. Adam, B. Re-
nault, F. Varela, and M. Baulac, “schad2008application,” The Lancet, vol. 357,
no. 9251, pp. 183–188, 2001.
[24] X. Li and G. Ouyang, “Nonlinear similarity analysis for epileptic seizures prediction,”
Nonlinear Analysis: Theory, Methods & Applications, vol. 64, no. 8, pp. 1666–1678,
2006.
[25] M. Winterhalder, T. Maiwald, H. Voss, R. Aschenbrenner-Scheibe, J. Timmer, and
A. Schulze-Bonhage, “The seizure prediction characteristic: a general framework to
assess and compare seizure prediction methods,” Epilepsy & Behavior, vol. 4, no. 3,
pp. 318–325, 2003.
c© 2015, Indian Institute of Technology Delhi
BIBLIOGRAPHY 55
[26] M. Le Van Quyen, J. Martinerie, M. Baulac, and F. Varela, “Anticipating epileptic
seizures in real time by a non-linear analysis of similarity between eeg recordings,”
Neuroreport, vol. 10, no. 10, pp. 2149–2155, 1999.
[27] A. Schad, K. Schindler, B. Schelter, T. Maiwald, A. Brandt, J. Timmer, and
A. Schulze-Bonhage, “Application of a multivariate seizure detection and prediction
method to non-invasive and intracranial long-term eeg recordings,” Clinical neuro-
physiology, vol. 119, no. 1, pp. 197–211, 2008.
[28] P. Mirowski, D. Madhavan, Y. LeCun, and R. Kuzniecky, “Classification of patterns of
eeg synchronization for seizure prediction,” Clinical neurophysiology, vol. 120, no. 11,
pp. 1927–1940, 2009.
[29] Y. Zheng, G. Wang, K. Li, G. Bao, and J. Wang, “Epileptic seizure prediction using
phase synchronization based on bivariate empirical mode decomposition,” Clinical
Neurophysiology, vol. 125, no. 6, pp. 1104–1111, 2014.
[30] S. Li, W. Zhou, Q. Yuan, and Y. Liu, “Seizure prediction using spike rate of in-
tracranial eeg,” Neural Systems and Rehabilitation Engineering, IEEE Transactions
on, vol. 21, no. 6, pp. 880–886, 2013.
[31] G. Xu, J. Wang, Q. Zhang, S. Zhang, and J. Zhu, “A spike detection method in eeg
based on improved morphological filter,” Computers in biology and medicine, vol. 37,
no. 11, pp. 1647–1652, 2007.
[32] C. A. Teixeira, B. Direito, M. Bandarabadi, M. Le Van Quyen, M. Valderrama,
B. Schelter, A. Schulze-Bonhage, V. Navarro, F. Sales, and A. Dourado, “Epileptic
seizure predictors based on computational intelligence techniques: A comparative
study with 278 patients,” Computer methods and programs in biomedicine, vol. 114,
no. 3, pp. 324–336, 2014.
[33] E. Niedermeyer and F. L. da Silva, Electroencephalography: basic principles, clinical
applications, and related fields. Lippincott Williams & Wilkins, 2005.
[34] W. J. Freeman, “A neurobiological interpretation of semiotics: meaning, representa-
tion, and information,” Information Sciences, vol. 124, no. 1, pp. 93–102, 2000.
[35] D. Kumar, G. Aggarwal, R. Sehgal, A. Das, U. Lahiri, and A. Dutta, “Engagement-
sensitive interactive neuromuscular electrical therapy system for post-stroke balance
rehabilitation-a concept study,” 2015.
[36] S.-A. Lee, D. D. Spencer, and S. S. Spencer, “Intracranial eeg seizure-onset patterns
in neocortical epilepsy,” Epilepsia, vol. 41, no. 3, pp. 297–307, 2000.
[37] R. X. Gao and R. Yan, “From fourier transform to wavelet transform: A historical
perspective,” in Wavelets, pp. 17–32, Springer, 2011.
[38] D. H. Bailey and P. N. Swarztrauber, “The fractional Fourier transform and appli-
cations,” SIAM Rev., vol. 33, no. 3, pp. 389–404, 1991.
c© 2015, Indian Institute of Technology Delhi
BIBLIOGRAPHY 56
[39] R. M. Haralick, S. R. Sternberg, and X. Zhuang, “Image analysis using mathematical
morphology,” Pattern Analysis and Machine Intelligence, IEEE Transactions on,
no. 4, pp. 532–550, 1987.
[40] P. Maragos and R. W. Schafer, “Morphological filters–part i: Their set-theoretic
analysis and relations to linear shift-invariant filters,” Acoustics, Speech and Signal
Processing, IEEE Transactions on, vol. 35, no. 8, pp. 1153–1169, 1987.
[41] P. Maragos and R. W. Schafer, “Morphological filters–part ii: Their relations to
median, order-statistic, and stack filters,” Acoustics, Speech and Signal Processing,
IEEE Transactions on, vol. 35, no. 8, pp. 1170–1184, 1987.
[42] H. R. Mohseni, A. Maghsoudi, and M. B. Shamsollahi, “Seizure detection in eeg
signals: A comparison of different approaches,” in Proc. of the 28th Annual Inter-
national Conference of the IEEE Engineering in Medicine and Biology Society, vol.
Supplement, 2006.
[43] H. H. Lange, J. P. Lieb, J. Engel, and P. H. Crandall, “Temporo-spatial patterns of
pre-ictal spike activity in human temporal lobe epilepsy,” Electroencephalography and
clinical neurophysiology, vol. 56, no. 6, pp. 543–555, 1983.
[44] W. Truccolo, J. A. Donoghue, L. R. Hochberg, E. N. Eskandar, J. R. Madsen, W. S.
Anderson, E. N. Brown, E. Halgren, and S. S. Cash, “Single-neuron dynamics in
human focal epilepsy,” Nature neuroscience, vol. 14, no. 5, pp. 635–641, 2011.
[45] A. A. Dingle, R. D. Jones, G. J. Carroll, and W. R. Fright, “A multistage system to
detect epileptiform activity in the eeg,” Biomedical Engineering, IEEE Transactions
on, vol. 40, no. 12, pp. 1260–1268, 1993.
c© 2015, Indian Institute of Technology Delhi
Appendix A
Source code
A.1 Detection
1 f unc t i on [F ] = wavelet ( dr )
2 % This code imports the data in the f o l d e r s and
performs the wavelet %trans form . I t then c a l l s the
f e a t u r e e x t r a c t i o n code .
3 A = ze ro s (4097 ,100) ;
4 B = c e l l (5 ,100) ;
5 f o r i = 1:100
6 A( : , i ) = importdata ( dr ( i +2) . name) ;
7 [ h1 , l 1 ] = dwt (A( : , i ) , ’ haar ’ ) ;
8 [B{1 , i } , l 2 ] = dwt ( l1 , ’ haar ’ ) ;
9 [B{2 , i } , l 3 ] = dwt ( l2 , ’ haar ’ ) ;
10 [B{3 , i } , l 4 ] = dwt ( l3 , ’ haar ’ ) ;
11 [B{4 , i } , l 5 ] = dwt ( l4 , ’ haar ’ ) ;
12 [B{5 , i } , l 6 ] = dwt ( l5 , ’ haar ’ ) ;
13 end
14 F = ex t ra c t (B, 9 ) ;
15 end
1 f unc t i on [A] = e x t r a c t (B, n)
2 %This code e x t r a c t s a l l the f e a t u r e s mentioned in the
report , f o r the
3 % d e t e c t i o n part
4 A = ze ro s (n , 1 0 0 , 5 ) ;
5 f o r i = 1:100
6 f o r j = 1 :5
7 H = dsp . ZeroCross ingDetector ;
c© 2015, Indian Institute of Technology Delhi
A.2 Prediction 58
8 A(1 , i , j ) = var (B{ j , i }) ;
9 A(2 , i , j ) = mean(B{ j , i }) ;
10 A(3 , i , j ) = wentropy (B{ j , i } , ’
shannon ’ ) ;
11 A(4 , i , j ) = i q r (B{ j , i }) ;
12 A(5 , i , j ) = k u r t o s i s (B{ j , i }) ;
13 A(6 , i , j ) = (A(1 , i , j ) + (A(2 , i , j
) ) ˆ2)∗ l ength (B{ j , i }) ;
14 PSD = periodogram (B{ j , i }) ;
15 A(7 , i , j ) = min (PSD) ;
16 A(8 , i , j ) = max(PSD) ;
17 A(9 , i , j ) = step (H,B{ j , i }) ;
18 end
19 end
20 end
A.2 Prediction
A.2.1 Mean Phase Coherence Calculation
1 f unc t i on [R] = p h a s e a l l ( data )
2 % This f i l e c a l l s the phasesyn func t i on to c a l c u l a t e
the MPC between
3 % the s e t o f p r ede f i n ed pa i r s , PS1 and PS2
4 PS1 = [ 1 , 1 , 1 , 5 , 5 , 8 , 8 , 4 , 6 , 3 , 3 ] ;
5 PS2 = [ 2 , 3 , 4 , 6 , 2 , 7 , 4 , 7 , 2 , 6 , 7 ] ;
6 Fs = 200 ;
7 w i n s i z e = 5 ;
8 no win = f l o o r ( s i z e ( data , 1 ) /( Fs∗w i n s i z e ) ) ;
9 R = ze ro s ( no win , s i z e (PS1 , 2 ) ) ;
10 f o r i = 1 : s i z e (PS1 , 2 )
11 % f o r j=i +1: s i z e ( data , 2 )
12 R( : , i ) = phasesyn ( data ( : , PS1( i ) ) , data ( : , PS2
( i ) ) , w i n s i z e ) ;
c© 2015, Indian Institute of Technology Delhi
A.2 Prediction 59
13 end
14 end
1 f unc t i on [MPC] = phasesyn (T4 , F4 , w i n s i z e )
2 % THis func t i on implements the MPC c a l c u l a t i o n
a lgor i thm .
3 Fs = 200 ;
4 %w i n s i z e = 5 ;
5 no win = f l o o r ( s i z e (T4 , 1 ) /( Fs∗w i n s i z e ) ) ;
6 A = ze ro s ( no win , w i n s i z e ∗Fs ) ;
7 B = ze ro s ( no win , w i n s i z e ∗Fs ) ;
8 MPC = ze ro s ( ( no win ) ,1 ) ;
9 % d = f d e s i g n . lowpass ( ’N, Fc ’ , 10 , 100 , 200 ) ;
10 % Hd = des ign (d , ’ butter ’ ) ;
11 f o r i = 1 : ( no win )
12 A( i , : ) = T4( ( i −1)∗w i n s i z e ∗Fs+1 : i ∗w i n s i z e ∗Fs
) ;
13 B( i , : ) = F4 ( ( i −1)∗w i n s i z e ∗Fs+1 : i ∗w i n s i z e ∗Fs
) ;
14 A( i , : ) = A( i , : ) − mean(A( i , : ) ) ;
15 B( i , : ) = B( i , : ) − mean(B( i , : ) ) ;
16 % A( i , : ) = f i l t e r (Hd,A( i , : ) ) ;
17 % B( i , : ) = f i l t e r (Hd,B( i , : ) ) ;
18 % apply f i l t e r ( tape r ing )
19 hb A = imag ( h i l b e r t (A( i , : ) ) ) ;
20 hb B = imag ( h i l b e r t (B( i , : ) ) ) ;
21 ph = ze ro s ( w i n s i z e ∗Fs , 1 ) ;
22 f o r j = 1 : w i n s i z e ∗Fs
23 ph( j ) = atan ( ( hb A ( j )∗B( i , j ) − hb B ( j )∗A( i ,
j ) ) /(A( i , j )∗B( i , j ) + hb B ( j )∗hb A ( j ) ) ) ;
24 end
25 ph = ph ( ( w i n s i z e ∗Fs∗0.1+1) : w i n s i z e ∗Fs ∗0 . 9 ) ;
26 temp = exp (1 i ∗ph) ;
27 MPC( i ) = abs (mean( temp ) ) ;
c© 2015, Indian Institute of Technology Delhi
A.2 Prediction 60
28 % hb A = hb A [ ( w i n s i z e ∗Fs∗0.1+1) : w i n s i z e ∗Fs
∗ 0 . 9 ] ;
29 end
30 % plo t (MPC) ;
31 end
A.2.2 Spike Rate Calculation
1 f unc t i on [ s p i k e r a t e ] = s p i k e r a t e (b)
2 k = 0 . 9 ;
3 s p i k e t h = 20 ;
4 Fs = 200 ;
5 w i n s i z e = 5 ;
6 no win = f l o o r ( s i z e (b , 2 ) /( Fs∗w i n s i z e ) ) ;
7 bkg = ze ro s ( s i z e (b , 1 ) , Fs∗w i n s i z e ) ;
8 s p i k e s = ze ro s ( s i z e (b , 1 ) , Fs∗w i n s i z e ) ;
9 data = ze ro s ( s i z e (b , 1 ) , Fs∗w i n s i z e ) ;
10 s p i k e r a t e = ze ro s ( s i z e (b , 1 ) , no win ) ;
11 f o r i = 10 : no win
12 data = b ( : , ( ( i −1)∗Fs∗w i n s i z e +1) : ( i ∗Fs∗w i n s i z e
) ) ;
13 bkg = bkg va l s ( data , k ) ;
14 s p i k e s = bkg−data ;
15 s p i k e r a t e ( : , i ) = d e t e c t s p i k e ( abs ( s p i k e s ) , Fs∗win s i z e , s p i k e t h ) ;
16 end
17 % plo t ( s p i k e r a t e ) ;
18 end
1 f unc t i on [ bkg ] = bkg va l s (b , k )
2 l s e =5;
3 bkg = ze ro s ( s i z e (b , 1 ) , s i z e (b , 2 ) ) ;
4 c l o s e = ze ro s (1 , s i z e (b , 2 ) ) ;
5 open = ze ro s (1 , s i z e (b , 2 ) ) ;
6 % se = ze ro s (2∗ l s e +1 ,1) ;
c© 2015, Indian Institute of Technology Delhi
A.2 Prediction 61
7 spk th = 1 ;
8 NHOD = ones (1 ,2∗ l s e +1) ;
9 Height = 1−abs ( l i n s p a c e (−1 ,1 ,11) ) ;
10 se = s t r e l (NHOD, Height ) ;
11 f o r i = 1 : s i z e (b , 1 )
12 c l o s e = imc lo se (b( i , : ) , s e ) ;
13 open = imopen (b( i , : ) , s e ) ;
14 bkg ( i , : ) = 0 . 5∗ ( imopen ( c l o s e , se )+imc lo se ( open ,
se ) ) ;
15 end
16 end
1 f unc t i on [ s p i k e r a t e ] = d e t e c t s p i k e ( sp ikes , samples ,
s p i k e t h )
2 s p i k e r a t e = ze ro s ( s i z e ( sp ikes , 1 ) , 1 ) ;
3 f o r i = 1 : s i z e ( sp ikes , 1 )
4 f o r j = 2 : samples−1
5 i f ( ( s p i k e s ( i , j ) > s p i k e t h ) && ( s p i k e s ( i , j
)>s p i k e s ( i , j−1) ) && ( s p i k e s ( i , j )>s p i k e s (
i , j +1) ) )
6 s p i k e r a t e ( i ) = s p i k e r a t e ( i ) +1;
7 end
8 end
9 end
10 end
A.2.3 Bi-Empirical Mode Decomposition
1 f unc t i on [MPC]=calc MPC (IMF)
2 %Implements the MPC c a l c u l a t i o n
3 s e r i e s 1=r e a l (IMF) ;
4 s e r i e s 2=imag (IMF) ;
5 s e r i e s 1=s e r i e s 1−mean( s e r i e s 1 ) ;
6 s e r i e s 2=s e r i e s 2−mean( s e r i e s 2 ) ;
7 hb 1 = imag ( h i l b e r t ( s e r i e s 1 ) ) ;
c© 2015, Indian Institute of Technology Delhi
A.2 Prediction 62
8 hb 2 = imag ( h i l b e r t ( s e r i e s 2 ) ) ;
9 ph = ze ro s ( s i z e ( s e r i e s 1 , 1 ) , 1 ) ;
10 f o r j = 1 : s i z e (ph , 1 )
11 ph( j ) = atan ( ( hb 1 ( j )∗ s e r i e s 2 ( j ) − hb 2 ( j )∗ s e r i e s 1 (
j ) ) /( s e r i e s 1 ( j )∗ s e r i e s 2 ( j ) + hb 1 ( j )∗hb 2 ( j ) ) ) ;
12 end
13 ph=ph( f l o o r ( s i z e (ph , 1 ) ∗0 . 1 ) : f l o o r ( s i z e (ph , 1 ) ∗0 . 9 ) ) ;
14 temp = exp ( (1 i )∗ph) ;
15 MPC = abs (mean( temp ) ) ;
1 f unc t i on [MPC] = bemd(T4)
2 % Implements the func t i on emd , which c a l c u l a t e s the
i n t r i n s i c mode func t i on
3 % of the data . Then c a l l s calc MPC , which c a l c u l a t e s
the MPC f o r g iven IMF %and pa i r o f channe l s .
4 Fs = 200 ;
5 w i n s i z e = 10 ;
6 N=4;%d four d i r e c t i o n s f o r two channe l s o f EEG
s i g n a l s
7 no win = f l o o r ( s i z e (T4 , 1 ) /( Fs∗w i n s i z e ) ) ;
8 num channel=s i z e (T4 , 2 ) ;
9 MPC=ze ro s ( no win , num channel , num channel , 2 0 ) ;
10 f o r i =1: no win
11 begin=1+(i −1)∗Fs∗w i n s i z e ;
12 l a s t=i ∗Fs∗w i n s i z e ;
13 %Find BEMD of two p a i r s
14 f o r j =1:3%num channel
15 f o r k=j +1:3%num channel
16 dat1=T4( begin : l a s t , j ) ;
17 dat2=T4( begin : l a s t , k ) ;
18 X=complex ( dat1 , dat2 ) ;
19 IMF = emd(X, ’NDIRS ’ ,4 ) ;
20 IMF=IMF ’ ;
21 f o r m=1: s i z e (IMF, 2 )
c© 2015, Indian Institute of Technology Delhi
A.2 Prediction 63
22 MPC( i , j , k ,m)=calc MPC (IMF( : ,m) ) ;
23 end
24 end
25 end
26 end
27 end
A.2.4 Dynamical Similarity Index
1 f unc t i on [ cor ]=pred (A,B)
2 % This func t i on implements the dynamical s i m i l a r i t y
measure . I t i s %assumed that the i n i t i a l part i s
i n t e r i c t a l . We have j u s t implemented
3 % the measure o f s i m i l a r i t y o f two windows , as a
func t i on o f r , the %parameter f o r the gauss ian
d i s t ance between the t r a j e c t o r i e s .
4 %r e f e r e n c e=A
5 %t e s t=B
6 f s =200;
7 r e f w i n s i z e =20;
8 s l i d i n g w i n s i z e =10;
9 Nw=s l i d i n g w i n s i z e ∗ f s ;
10 Ns=r e f w i n s i z e ∗ f s ;
11 %Se l e c t ed channel− 3
12 dim = 9 ;
13 Ref=A( 1 : Ns) ;
14 c o u n t r e f = 0 ;
15 k=0;
16 Ref t=ze ro s (Ns , 1 ) ;
17 f o r i =1:Ns−1
18 i f ( ( Ref ( i ) <=0) & ( Ref ( i +1) >0) )
19 c o u n t r e f =c o u n t r e f +1;
20 Ref t ( c o u n t r e f ) = i−k ;
21 k = i ;
c© 2015, Indian Institute of Technology Delhi
A.2 Prediction 64
22 end
23 end
24 r=std ( Re f t ) ;
25 R = l i n s p a c e ( r ∗0 .1 ,3∗ r , 1 00 ) ;
26 p h a s e r e f = ze ro s ( count r e f−dim+1,dim) ;
27 f o r i = 1 : dim
28 f o r p = 1 : ( count r e f−dim+1)
29 p h a s e r e f (p , i ) = Ref t (p+i −1) ;
30 end
31 end
32
33 [V, e i ] = e i g ( ( phase r e f ’ ) ∗( p h a s e r e f ) ) ;
34 X re f = p h a s e r e f ∗V;
35 [ a r e f , b r e f ]= s i z e ( X re f ) ;
36 num sl id win =20;%f l o o r ( s i z e (B, 1 ) / f s /Nw)
37 %s t a r t the windows
38 f o r j r e f =1: num sl id win
39 s l i d=B(1+( j r e f −1)∗Nw: j r e f ∗Nw) ;
40 s l i d t=ze ro s (Nw, 1 ) ;
41
42 j =0;
43 c o u n t s l i d = 0 ;
44
45 f o r i = 1 :Nw−1
46 i f ( ( s l i d ( i ) <=0) & ( s l i d ( i +1) >0) )
47 c o u n t s l i d = c o u n t s l i d + 1 ;
48 s l i d t ( c o u n t s l i d ) = i−j ;
49 j=i ;
50 end
51 end
52
53 p h a s e s l i d = ze ro s ( c o u n t s l i d−dim+1,dim) ;
54 f o r i = 1 : dim
55 f o r p = 1 : ( c o u n t s l i d−dim+1)
c© 2015, Indian Institute of Technology Delhi
A.2 Prediction 65
56 p h a s e s l i d (p , i ) = s l i d t (p+i −1) ;
57 end
58 end
59
60
61
62 X st = p h a s e s l i d ∗V;
63 [ a , b ] = s i z e ( X st ) ;
64
65 Y re f = X re f ;%( 1 : ( min ( a r e f /2 , a ) ) , : ) ;
66 %ss imva l=ssim ( Y ref , X st ) ;
67 cor = ze ro s (100 ,1 ) ;
68 %cor2=ze ro s (100 ,1 ) ;
69 f o r r count =1:100
70 %c o r e l a t=co r r ( X st ’ , Y ref ’ ) ;
71 f o r i = 1 : a r e f%min ( a r e f /2 , a )
72 f o r j = 1 : a
73 c ro s s t e rm=exp(−norm ( ( Y re f ( i , : )−X st ( j , : ) ) ) /(R( r count ) ˆ2) ) ;
74 cor ( r count )=cor ( r count )+
cro s s t e rm ;
75 % cor2 ( r count )=cor2 ( r count )+(
c o r e l a t ( j , i ) /( a r e f ∗a ) ) ;
76 end
77 end
78 s e l f c o r r e f =0;
79 s e l f c o r s t =0;
80 f o r i =1: a r e f
81 f o r j =1: a r e f
82 t e rm re f=exp(−norm ( ( Y re f ( i , : )−Y re f ( j , : ) ) ) /(R( r count ) ˆ2) ) ;
83 s e l f c o r r e f=s e l f c o r r e f+te rm re f ;
84 end
85 end
c© 2015, Indian Institute of Technology Delhi
A.3 Real Time Prediction Model 66
86 f o r i =1:a
87 f o r j =1:a
88 t e rm st=exp(−norm ( ( X st ( i , : )−X st ( j
, : ) ) ) /(R( r count ) ˆ2) ) ;
89 s e l f c o r s t=s e l f c o r s t+term st ;
90 end
91 end
92 cor ( r count )=cor ( r count ) / ( ( s e l f c o r s t ∗s e l f c o r r e f ) ˆ ( 0 . 5 ) ) ;
93
94 end
95 p lo t (R, cor ) ;
96 %hold a l l
97 %plo t (R, cor2 ) ;
98 %hold o f f
99
100 end
101 end
A.3 Real Time Prediction Model
A.3.1 Methodology
1 f unc t i on [MPC, data lp , data mean , data area ] = eeg pa r s e (
b , p lo t chan )
2 Fs=200;
3 w i n s i z e =5;
4 % mean windows = 50 ;
5 chan pa i r = 12 ;
6 no win = f l o o r ( s i z e (b , 2 ) /( Fs∗w i n s i z e ) ) ;
7 % mean windows = f l o o r ( no win /1) ;
8 data = ze ro s ( s i z e (b , 1 ) , Fs∗w i n s i z e ) ;
9 MPC = ze ro s ( chan pair , no win ) ;
10 f i l = 0.25∗ ones (1 , 4 ) ;
c© 2015, Indian Institute of Technology Delhi
A.3 Real Time Prediction Model 67
11 % data lp = ze ro s ( s i z e ( p lot chan , 2 ) , no win ) ;
12 % data mean = ze ro s ( s i z e ( p lot chan , 2 ) , no win ) ;
13 data lp = ze ro s ( chan pair , no win ) ;
14 data mean = ze ro s ( chan pair , no win ) ;
15 area win = 10 ;
16 data area = ze ro s ( chan pair , no win ) ;
17 % f o r i = 1 : s i z e ( p lot chan , 2 )
18 % hold o f f ;
19 % a x i s ( [ 0 2195 0 .7 1 ] ) ;
20 % hold on ;
21 c o l = 98∗ ones ( chan pair , no win ) ;
22 a r e a t h p r e = −0.4;
23 a r e a t h i c t a l = −0.00;
24 a r e a t h p o s t = 0 . 3 ;
25 % 98 f o r i n t e r i c t a l ( b lue ) , 103 f o r pre− i c t a l ( green ) ,
114 f o r i c t a l ( red )
26 pnt = 0 ;
27 i f ˜(˜ e x i s t ( ’ p lo t chan ’ , ’ var ’ ) | | isempty ( p lo t chan
) )
28 pnt = 1 ;
29 end
30 i f ( pnt == 1)
31 % f i g u r e
32 f o r j = 1 : s i z e ( p lot chan , 2 )
33 subplot ( s i z e ( p lot chan , 2 ) ,1 , j ) ;
34 a x i s ( [ 0 no win 0 .0 1 ] ) ;
35 hold on ;
36 % t i t l e ( s p r i n t f ( ’ Channel pa i r %g ’ , p lo t chan
( j ) ) ) ;
37 end
38 end
39 f o r i =1: no win
40 data = b ( : , ( ( i −1)∗Fs∗w i n s i z e +1) : ( i ∗Fs∗w i n s i z e
) ) ;
c© 2015, Indian Institute of Technology Delhi
A.3 Real Time Prediction Model 68
41 MPC( : , i ) = win proce s s ( data , Fs , w i n s i z e ) ;
42 f o r j = 1 : chan pa i r
43 data lp ( j , : ) = f i l t e r ( f i l , 1 ,MPC( j , : ) ) ;
44 % i f ( i <= mean windows )
45 data mean ( j , i ) = mean(MPC( j , 1 : i ) ) ;
46 % e l s e i f ( i > mean windows )
47 % data mean ( j , i ) = mean(MPC( j , ( ( i−mean windows ) : i ) ) ) ;
48 % end
49 i f ( i<=7+area win )
50 data area ( j , i ) = 0 ;
51 e l s e
52 data area ( j , i ) = sum( data lp ( j , ( i−area win ) : i ) )−sum( data mean ( j , ( i−area win ) : i ) ) ;
53 end
54 end
55 pause ( 0 . 0001 ) ;
56 i f ( ( i > 1) && ( pnt == 1) )
57 f o r j = 1 : s i z e ( p lot chan , 2 )
58 ch = plot chan ( j ) ;
59 subplot ( s i z e ( p lot chan , 2 ) ,1 , j ) ;
60 p lo t ( ( ( i −1) : i ) , da ta lp ( ch , i −1: i ) , ’ r ’ ) ;
61 p lo t ( ( ( i −1) : i ) , data mean ( ch , i −1: i ) , ’ b ’ )
;
62 i f ( data area ( ch , i ) < a r e a t h p r e )
63 c o l ( ch , i ) = 103 ;
64 e l s e i f ( ( c o l ( ch , i −1) == 98) && (
data area ( ch , i ) > a r e a t h p o s t ) )
65 c o l ( ch , i ) = 114 ;
66 e l s e i f ( c o l ( ch , i −1) == 98)
67 c o l ( ch , i ) = 98 ;
68 e l s e i f ( ( c o l ( ch , i −1) == 103) && (
data area ( ch , i ) > a r e a t h i c t a l ) )
c© 2015, Indian Institute of Technology Delhi
A.3 Real Time Prediction Model 69
69 c o l ( ch , i ) = 114 ;
70 e l s e i f ( ( c o l ( ch , i −1) == 103) && (
data area ( ch , i ) < a r e a t h i c t a l ) )
71 c o l ( ch , i ) = 103 ;
72 e l s e i f ( ( c o l ( ch , i −1) == 114) && (
data area ( ch , i ) > a r e a t h i c t a l ) )
73 c o l ( ch , i ) = 114 ;
74 e l s e i f ( ( c o l ( ch , i −1) == 114) && (
data area ( ch , i ) < a r e a t h i c t a l ) )
75 c o l ( ch , i ) = 98 ;
76 end
77 temp = [ data mean ( ch , i −1) data lp ( ch , i
−1) data lp ( ch , i ) data mean ( ch , i ) ] ;
78 temp2 = f i l l ( [ ( i −1) ( i −1) i i ] , temp ,
char ( c o l ( ch , i ) ) ) ;
79 s e t ( temp2 , ’ EdgeColor ’ , ’ none ’ ) ;
80 end
81 end
82 end
83 hold o f f ;
84 end
1 f unc t i on [R] = win proce s s ( data , Fs , w i n s i z e )
2 PS L1 = [11 , 11 , 16 , 12 , 16 , 13 , 13 , 13 , 18 , 18 , 18 , 14 ] ;
3 PS L2 = [16 , 12 , 12 , 13 , 17 , 14 , 18 , 17 , 17 , 14 , 15 , 15 ] ;
4 PS C1 = [ 1 1 , 1 6 , 1 7 , 1 8 , 1 5 ] ;
5 PS C2 = [ 2 , 7 , 8 , 9 , 6 ] ;
6 PS R1 = [ 2 , 2 , 7 , 3 , 7 , 4 , 4 , 4 , 9 , 9 , 9 , 5 ] ;
7 PS R2 = [ 7 , 3 , 3 , 4 , 8 , 5 , 9 , 8 , 8 , 5 , 6 , 6 ] ;
8 channe l s = s i z e (PS R1 , 2 ) ;
9 R = ze ro s ( channels , 1 ) ;
10 f o r i = 1 : channe l s
11 R( i ) = win MPC( data ( PS L1 ( i ) , : ) , data ( PS L2 ( i )
, : ) , Fs , w i n s i z e ) ;
c© 2015, Indian Institute of Technology Delhi
A.3 Real Time Prediction Model 70
12 end
13 end
1 f unc t i on va l = win MPC(D1 , D2 , Fs , w i n s i z e )
2 %D1, D2 are the windows o f 2 channe l s
3 D1 = D1−mean(D1) ;
4 D2 = D2−mean(D2) ;
5 hb 1 = imag ( h i l b e r t (D1) ) ;
6 hb 2 = imag ( h i l b e r t (D2) ) ;
7 ph = ze ro s ( w i n s i z e ∗Fs , 1 ) ;
8 f o r j = 1 : round ( w i n s i z e ∗Fs )
9 ph( j ) = atan ( ( hb 1 ( j )∗D2( j ) − hb 2 ( j )∗D1( j ) ) /(
D1( j )∗D2( j ) + hb 1 ( j )∗hb 2 ( j ) ) ) ;
10 end
11 ph = ph ( ( w i n s i z e ∗Fs∗0.1+1) : w i n s i z e ∗Fs ∗0 . 9 ) ;
12 temp = exp (1 i ∗ph) ;
13 va l = abs (mean( temp ) ) ;
14 end
1 f unc t i on plot sum (MPC, data lp , data mean , p lot chan ,
no win )
2 hold o f f ;
3 sum lp=ze ro s (1 , no win ) ;
4 sum mean=ze ro s (1 , no win ) ;
5 f o r i = 1 : s i z e ( p lot chan , 2 )
6 sum lp = sum lp + 10∗ data lp ( p lo t chan ( i ) , : ) ;
7 sum mean = sum mean + 10∗data mean ( p lo t chan ( i )
, : ) ;
8 end
9 p lo t ( sum lp ) ;
10 hold a l l ;
11 p lo t ( sum mean ) ;
12 end
c© 2015, Indian Institute of Technology Delhi