Classification of EEG Signals in A Brain-Computer Interface System
Classification of EEG Signals in A Brain-Computer Interface System
This assignment should include both a theoretical and a practical part. In the
theoretical part, current Brain-Computer Interface systems and methods should be
researched, to create a state-of-the-art overview of, and to learn about the domain.
The focus should be on the emergent commercialization of EEG products on the
public market. In this project, a NeuroSky mindset (EEG equipment) is available
as a test device.
The practical part should implement a system consisting of three modules. The
first module should communicate with the NeuroSky mindset and get EEG signals,
the second module should process those signals and make input parameters for the
third module, which should be a game that have one or several features controlled
by the input parameters. The goal is 1) that users should be able to control a game
using their minds, and 2) investigate if low price EEG equipment enables that.
Assignment given: 17. January 2011
Supervisor: Alf Inge Wang, IDI
Co-supervisor: Jørn Hokland, IDI
i
ii
Abstract
iii
iv
Preface
This report is the final product to complete my Master of Science degree at the
Norwegian University of Science and Technology (NTNU). The project was con-
ducted in the period of January to June 2011, at the Department of Computer and
Information Science.
I would like to thank my supervisor, associate professor Alf Inge Wang, for valu-
able discussions and supporting follow-up throughout the project lifespan and for
providing me with the necessary equipment. Also, thanks to my co-supervisor,
associate professor Jørn Hokland for giving me this opportunity and for being un-
derstanding.
Finally, I would like to thank my fellow students Kjetil Aamodt and Kjetil Valle for
their general support, lectures on neural networks and for sharing their thoughts
when I asked questions, even though they were just as clueless to the answers as
me. And of course Bjørg Ane Sandve for being an enthusiastic test guinea pig.
Trondheim, June 2011,
Erik Andreas Larsen
v
vi
Contents
1 Introduction : The Big Picture 1
1.1 Project Purpose: Why Take BCIs to a new Level? . . . . . . . . . . . 1
1.2 Project Strategy: How NeuroSky Could Level Up BCIs . . . . . . . . 2
1.3 Project Results: What a NeuroSky BCI System Could Become . . . . 2
1.4 Report Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4 Brain-Computer Interfaces 15
4.1 What is a Brain-Computer Interface? . . . . . . . . . . . . . . . . . . 15
4.2 State of the Art BCI and Existing Systems . . . . . . . . . . . . . . . 16
4.3 BCI Development: EEG Analysis, FFT and Band Powers . . . . . . . 19
4.4 Five Different Approaches for Classifying EEG Signals . . . . . . . . 20
9 Conclusion 51
9.1 Further Development and Ideas for the Future . . . . . . . . . . . . . 52
References 55
vii
viii
List of Figures
1.1 The golden circle model (Sinek, 2009). . . . . . . . . . . . . . . . . . 1
1.2 Feedback using a blue bar graph. . . . . . . . . . . . . . . . . . . . . 2
7.1 Second graphical sampling screen used to collect raw EEG samples . 36
7.2 Comparing total band power from all 5 sets in session one . . . . . . 37
7.3 Comparing total band power from all 5 sets in the session two . . . 37
7.4 Spatial sample of baseline - Eyes closed . . . . . . . . . . . . . . . . . 39
7.5 Frequency spectrum of baseline - Eyes closed . . . . . . . . . . . . . 39
7.6 Spatial sample of visual count . . . . . . . . . . . . . . . . . . . . . . 39
7.7 Frequency spectrum of visual count sample . . . . . . . . . . . . . . 39
ix
8.1 Overview of final system flow . . . . . . . . . . . . . . . . . . . . . . 43
8.2 State machine of the game action control . . . . . . . . . . . . . . . . 44
8.3 Screenshot from a Snake game . . . . . . . . . . . . . . . . . . . . . . 46
8.4 Results from control testing, subject one . . . . . . . . . . . . . . . . 48
8.5 Results from control testing, subject two . . . . . . . . . . . . . . . . 48
8.6 Picture from testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
x
List of Tables
2.1 Superior research questions . . . . . . . . . . . . . . . . . . . . . . . 7
xi
xii
1 Introduction : The Big Picture
This chapter introduces the project by elaborating its why, how and what, illus-
trated in figure 1.1. It presents the project motivation and context. Finally, an
overview of the report structure is stated.
1
Project Strategy: How NeuroSky Could Level Up BCIs
1.2
NeuroSky is a company with the slogan ”Bio Sensors for Everyone!”, and in late 2009
they released a EEG device named the NeuroSky mindset at a low cost, aimed at
the consumer market (Neurosky, n.d.). Shipped with software development tools,
people at home can explore the technology, and integrate it with their own design
and systems. What used to be reserved for those who had the big money to pay for
such equipment, are now very much available for anyone who are interested, either
as a user, a developer, or both. This is great news for accelerating BCI research
since more people can contribute. The strategy for this project is to utilize the
NeuroSky mindset technology and do just that. But, the mindset only provides
the brain wave signal, and to interpret and classify it, an artificial neural network
will be used. More on this in chapter 5.
To better understand current BCI, consider an example
from neurofeedback training used as a treatment alterna-
tive for persons with AD/HD. Neurofeedback, also called
biofeedback, is a treatment where EEG equipment is used
to present real-time records of brain activity. This enables
you to train yourself, for instance to become more concen-
trated or relaxed, by altering your brain wave patterns over
time. Feedback about your concentration level is for in- Figure 1.2: Feedback
stance given as a graph, illustrated in figure 1.2. using a blue bar graph.
The subjects task is usually to keep the bar above a certain threshold, indicated
here by the horizontal black line. Typically one training sessions like this last for
about 45-60 minutes and needs to be repeated to get the wanted effect, variat-
ing from 25-50 times depending on the patient (Heinrich, Gevensleven, & Strehl,
2007). This can easily get boring or frustrating for a patient with AD/HD, or any-
one else for that matter. Now it is possible to change that.
2
1.3.1 Medical Verification Disclaimer
Report Outline
1.4
This section describes the remaining chapters and the report structure. The goals
and objectives of the project have been introduced in this chapter.
Chapter 2 describes the related work and background for this project and iden-
tifies the most important research questions and method of approach.
Chapter 3 explains how the EEG technology works, and the different brain activ-
ity patterns that are the foundation for EEG analysis.
Chapter 4 elaborates the Brain-Computer Interface technology, how far it has de-
veloped, what it is currently used for and a few underlying methods.
Chapter 5 introduces the main system design and equipment that was available
for realizing and implementing it. The different components and their relations to
each other are explained.
Chapter 6 reviews the result of using the implemented system for basic eye-blink
classification. It describes the method used, and analyses the results in a discus-
sion.
Chapter 7 reviews the result of using the implemented system for mental task
classification, which is counting. It describes the method used, and analyses the
results in a discussion.
Chapter 8 reviews the result of using the implemented system for controlling
a game (a classical Snake-game) according to the project goal. It describes the
method used, and analyses the results in a discussion.
Chapter 9 summarize and concludes the project in perspective of the big picture
and the research questions from chapter 2. It also makes suggestions for further
work.
3
4
2 Research Questions and Methods
This chapter explains the background for this project, and identifies the main re-
search questions and methods to bring clarity and define the projects focus, based
on lessons learned from earlier efforts and new anticipations.
Figure 2.1: System Design: component overview. Sensors reads brain activity and sends
signal to the EEG amplifier equipment. The EEG signal is sent to the module, that over-
rides the Playstation controller. Feedback is given on the screen.
The goal of this project was to meet some of the challenges that people with Atten-
tion Deficit and Hyperactive Disorder (AD/HD) have regarding the use of neuro-
feedback as a treatment option (Pointed out in section 1.2). The electroencephalog-
5
raphy laboratory (EEGlab) at the Department of Psychology at NTNU, BUP (out-
patients clinic for children) and St.Olavs Hospital, have a co-operative venture
where neurofeedback is used when there is suspicion of such disorder or learning
disabilities in children. They were interested in exploring a different approach to
the usage of this technology; making neurofeedback training more attractive, re-
ducing the training and equipment expenses and making it more fun and available
to the public. The proposed method was to combine neurofeedback training with
playing video games on a Playstation.
The result was a system with the ability to use clinical approved EEG equipment to
control the acceleration of a racing car in a video game, both on PC and Playstation,
see figure 2.1. In conclusion, this made it possible to consider a more entertain-
ing way of performing neurotherapy and prompted for a field study to map the
potential for further investment (Larsen, 2010).
The playstation project builds on work done by Andersen, Juvik, Kjellen, and
Storstein (2009), as part of a multidisciplinary course at NTNU. On initiative from
Egil Tjåland and in cooperation with Stig Hollup at Department of Psychology,
their assignment was to steer a radio controlled helicopter using the principles of
neurofeedback. With their solution they were able to adjust the speed of the rotor
using the level of concentration in a test person, and lift it off the ground. They
developed an application that interfaced EEG software with the radio controller
software of the helicopter.
Figure 2.2: Traditional cap with a grid of electrodes vs. new type, single electrode headset
(NeuroSky).
A major limitation in the playstation and the helicopter project was that the EEG
signal from the equipment was unavailable as raw and unaltered data. The only
information that was available was a modified number from the accompanying
software that represented the users concentration level, ranging from 1 to 15. Also,
6
the EEG equipment used, from the Russian company Mitsar (Mitsar, 2008), is ex-
pensive. But, the second major limitation is the electrodes needs to be manually
placed in a cap, similar to the ones to the left in figure 2.2, but with only two
electrodes. Conductive gel was need to be used between the electrodes and scalp
surface, and took some time to set up.
The NeuroSky mindset eliminates those limitations by making raw EEG data avail-
able and by using a dry sensor which comes pre-attached to the headset. Those are
major advantages regarding system development and usability, but there is also
drawbacks attached. There is only one electrode, that is statically placed on the
forehead. Observable at the tip of the arm to the right, in figure 2.2. Compar-
ing the traditional cap and the NeuroSky mindset, the traditional cap looks like it
gives a lot more accurate measurements.
Table 2.1 shows the few superior research questions pre to implementing and ex-
perimenting. They are kept open-wide as much details are unknown in advance,
but expected to emerge throughout the project.
Tag Description
RQ1: Can one static sensor on the forehead make up for a grid of sensors
placed across the scalp?
RQ2: What are the advantages and limitations of the NeuroSky mindset?
RQ3: What kind of classification of brain waves will it be possible to make
using a neural network? And if possible, how stable is this classification?
RQ4: How satisfying or useful will a resulting and working BCI system
be for the user?
RQ5: How little practice and training time is it possible to get away with
without affecting the performance of the BCI system?
7
8
3 EEG Technology: Why and How it Works
This chapter explains how EEG technology works, and the different brain activity
patterns that are a foundation for EEG analysis. Followed by some words on the
practical applications of it. First, a quick distinction: EEG is about the brain waves
themselves, and BCI are more the entire system of interpreting these in a computer
fashion.
The brain have always fascinated humans, and particularly a German scientist
named Hans Berger, who discover electroencephalography (EEG) about 80 years
ago. After this, new methods for exploring it have been found and we can catego-
rize them into two main groups. Invasive and non-invasive. An invasive approach
requires physical implants of electrodes in humans or animals, making it possible
to measure single neurons or very local field potentials. A non-invasive approach
makes use of, for instance, magnetic resonance imaging (MRI) and EEG technol-
ogy to make measurements. Both gives different perspectives and enables us to
look inside the brain and to observe what happens (Kropotov, 2009). In EEG,
brain-related electrical potentials are recorded from the scalp. Pairs of conductive
electrodes (see figure 4.2) made of silver, for example, are used to read this elec-
tricity. The difference in voltage between the electrodes are measured, and since
the signal is weak (30-100µV) it has to be amplified. Current occurs when neurons
communicate. The simplest event is called action potential, and is a discharge
caused by fast opening and closing of N a+ and K + ion channels in the neuron
membrane. If the membrane depolarize to some threshold, the neuron will ”fire”.
Tracking these discharges over time reveals the brain activity.
9
Figure 3.2: The 1020 System - Standardized placement of electrodes on scalp for EEG
measurements (Immara, n.d).
10
Theta waves, ranging from 3.5 to 7.5 Hz, are linked to inefficiency,
daydreaming, and the very lowest waves of theta represent the fine
Figure 3.6: line between being awake or in a sleep state. Theta arises from emo-
Theta
tional stress, especially frustration or disappointment (L. Zhang, He,
wave.
Miao, & Yang, 2005). It has also been associated with access to uncon-
scious material, creative inspiration and deep meditation. High levels
of theta are considered abnormal in adults, and is, for instance, much
related to AD/HD (Heinrich, Gevensleven, & Strehl, 2007).
Delta waves, ranging from 0.5 to 3.5 Hz, are the slowest waves and
occurs when sleeping (Hammond, 2006). If these waves occur in the
Figure 3.7: awake state, it thought to indicate physical defects in the brain. Move-
Delta wave. ment can make artificial delta waves, but with an instant analysis (just
observing raw EEG records), this can be verified or unconfirmed.
MU is associated with motor activities, and is also found in the alpha wave fre-
quency range, but where the maximum amplitude is recorded over motor cortex.
So it basically triggers when there is an actual movement or there is an intent to
move (Bernier, Dawson, Webb, & Murias, 2007).
All these wave-groups occur in different parts of the brain in varying degree.
Figure 3.8: The 5 main frequency bands and their relation to each other.
11
figure 3.2) makes activity in these areas observable. Indeed, EEG is a tool used in
hospitals for declaring patients brains to be dead, when no activity is monitored.
The study of brain waves and how they relate to different mental states, have led
to number of alternative methods and beliefs on how to manipulate these waves.
For instance, in order to become e.g more relaxed, focused and smarter, you can
buy music that plays in specific hertzes that promise to do just that (Brain Enter-
tainment, n.d.). A well known advice deduced from this is that you should let your
baby listen to Mozart while growing up, having the effects mentioned. Besides this
somewhat regarded pseudoscience, there have been a lot of interesting studies of
mental states and how they are effected, summarized for instance in Braverman
(1990). A area that have been researched in a great amount is the relation of drugs,
medication and EEG. And according to his article, an increase of alpha activity is
found when taking antidepressants, and addictive drugs like morphine, heroin
and marijuana. It has also been identified that drug users often lack a natural
amount of occurring alpha waves, and thus it can explain why they become ad-
dicts. Alcoholics have been found to have an excess of occurring beta waves, and
that this can inhibit their ability to relax. Alcohol research shows that its use in-
creases the amplitude of the slow waves frequencies and decrease the fast waves.
Thus, it suggests that alcohol becomes the quick remedy to become relaxed.
Further, Braverman talk about ”how brain waves symbolizes the various parts of
our consciousness, and that if we get the knowledge and treatment to change them,
we can get closer to get our very balanced brain waves, or happiness”. One way to
get knowledge is to use ERP, described below, and one way to conduct treatment
is a method called neurofeedback, further described in section 3.3.2.
12
3.3.1 Event Related Potentials (ERP)
Exposure to external stimuli, such as a tone or light flash, can generate responses in
the EEG wave, as shown in figure 3.10. Internal stimuli, like skipping an expected
stimulus can also generate a response. In both cases this is called Event Related
Potentials (ERP), or Evoked Potential (EP). What this means exactly is that there
is an observable amplitude peak (potential) that occurs at a definite latency time
after the specific stimuli. The most used is the P300, were the peak comes 300 ms
after the event. In chapter 4 we will see BCI systems applying this. In diagnostic
appliance, however, P300 is used to map the external stimuli to brain activity in
specific areas. For example, if exposed to a tone, there should be a reaction in the
EEG close to the auditory processing area (See figure 3.9).
Figure 3.10: ”Sample-evoked response potential in response to a target (70 dB. 2 kHz) and
nontarget (70 dB, 1 kHz) tone. The P300 wave is clearly seen only after presentation of the
target tone.” (Lukas et al., 1990).
13
before it is sent to a software on a computer. There the signal gets interpreted and
processed into feedback to the user. Dividing the signal into the frequency bands
can be done by applying a Fourier transform (further explained in section 4.3).
Their factors can then be used to calculate a ratio, for instance Beta/Theta (Leins,
Goth, Hinterberger, Klinger, & Strehl, 2007). This ratio can be used to determine
the hight of a bar graph (Figure 1.2) and displayed on a monitor. Feedback is
obtained.
Figure 3.11: Neurofeedback principle. MR scanning is of the author’s own head. Elec-
trodes are attached to the scalp. The amplifier reads the electricity registered, amplifies
this and issues a analog-to-digital converter which sends EEG data to the computer. The
computer process the data and display it for the patient. The feedback can be used to
verify correct behaviour.
Not everyone seems to need visual feedback in order to alter their brain waves.
Studies of experienced mediators, using EEG, shows remarkable capabilities to af-
fect their frequency power while meditating, and keep a stable frequency for the
entire time (Stigsby, Rodenberg, & Moth, 1981). In one study, 20 normal peo-
ple showed increased fast Theta and slow Beta frequencies, predominantly in the
frontal area, by applying a Zen meditation task(Takahashia et al., 2005). It re-
quires no previous training because it focuses on breath control. This gives an
interesting perspective on neurofeedback and brain waves in general.
14
4 Brain-Computer Interfaces
This chapter explains Brain-Computer Interfaces and reviews some of the avail-
able products and systems on the market today. Current methods and potentials
in the technology are identified.
Further, it is identified four different application areas of BCI, some which have
been mentioned in chapter 3 already:
In this project we are concerned with item 4, and all steps in the common BCI
process flow shown in figure 4.1.
15
4.1.1 Five Central Factors of BCI Design
Lotte, Congedo, Lécuyer, Lamarche, and Arnaldi (2007) have identified a few fea-
tures that are common, and critical, to BCI design, that are listed here:
1. noise and outliers: BCI features are noisy or contain outliers because EEG
signals have a poor signal-to-noise ratio;
2. high dimensionality: in BCI systems, feature vectors are often of high di-
mensionality. Indeed, several features are generally extracted from sev-
eral channels and from several time segments before being concatenated
into a single feature vector;
3. time information: BCI features should contain time information as brain
activity patterns are generally related to specific time variations of EEG;
4. non-stationarity: BCI features are non-stationary since EEG signals may
rapidly vary over time and more especially over sessions;
5. small training sets: the training sets are relatively small, since the training
process is time consuming and demanding for the subjects.
Item 2 is highlighted because the NeuroSky EEG device used for this project is a
single channel device. This reduces complexity for processing, but it also reduces
signal accuracy, because there is only a single source of input. All of the referenced
studies that are presented in the next section used 4 electrodes and most of them
even more.
When describing some of the products on the market it gives a good insight to
the potential that lies in neurofeedback. The NASA and Sony feedback system
16
differs from the traditional neurofeedback in that the feedback and reward are not
explicit on the display, but implicit in the how the subject is able to control a task
using brain waves.
• ”Yt Mer” (Perform More): By expanding the target group, more efforts will
be made to make the technology available, user friendly, entertaining and
affordable. But this is only started. In 2010, the first ”BrainWave Optimiza-
tion” company was established in Norway (Berg, 2010). ”Yt Mer” is an or-
ganization that is offering neurofeedback training to customers so that they
can achieve higher performance, lower stress levels, better sleep patterns and
increased well-being. It is very expensive, thus it is mostly targeting larger
firms and enterprises.
• Emotiv: Their motto is ”You think, therefore you can” (Emotiv, n.d.). Emo-
tiv claims that you can use thoughts, feelings and emotions to control your
computer. The accompanying software comes with a machine learning al-
gorithm that learns how your brain visualizes, for example push and pull of
objects, from the EEG measurements. This can be mapped to computer con-
trols. Their neuroheadset consists of 14 sensors, includes a gyroscope and
is priced 299 US dollars. The headset is high-tech and a comparison with a
traditional EEG hair net is shown in figure 4.2.
However, the Emotiv EPOC Neuroheadset is only available
for purchase to US customers. This is because there is not
enough testing of the headset to achieve CE marking that
makes it possible to sell in Europe and other countries, in-
cluding Norway. Software Development Kits (SDKs) can be
bought however, it includes a beta-headset to use at ones
own risk and software to develop applications for it.
17
controller and does not require a computer to operate. The controller be-
comes more responsive when the user is concentrated and is basically the
market product of the NASA study mentioned in section 4.2. Two versions
are for sale: a personal and a professionally supervised. The personal edition
costs approximately 600 US dollars and comes with three training presets. In
general, they reward decrease of the slow brain patterns of alpha and theta
brain waves and increase in faster brain waves (beta). The professionally su-
pervised edition makes it possible to adjust the parameters individually to
fit the user needs.
• Mind Cursor: A earlier study by Wolpaw and Mcfarland (1994), uses the
principle of MU (see section 3.2), the amplitude, or power levels for vertical
movement, and the difference between the power levels for horizontal move-
ment. This allowed the user to select from four icons, one at each corner
of the screen. Using MU for movement is common, because it maps well to
intentional movement.
18
4.2.4 Games on the Market and What all the Products Have in Common
The two game examples below is very common properties to apply in BCI games.
As with most games available today, they rely on attention and concentration val-
ues. It seems it is the most reliable or easiest property to calculate, especially when
readings from the forehead is used.
• Adventures of Neuroboy: NeuroSky have their own demo game that comes
with the mindset. You are a character that can move in a world and levitate,
push, pull and burn things with you mind. Attention and meditation values
calculated in the mindset decides how this happen. Increased meditation
value will lift objects, and increased attention will for instance burn things.
• Mindball: You wear a headband that reads brain waves, like the NeuroSky
mindset, from the forehead. Theta and alpha (drowsiness and relaxation)
band powers are used to control the speed of a ball. It is used to move a
ball from A to B in competition with an opponent. The one who is more
concentrated pushed the ball towards the other, and wins.
An example of a game that only uses the NeuroSky attention value is the Mind-
Blaster game (Peek, 2010a). Using a Nintendo Wiimote, targets on the screen are
locked in, and when maximum attention value is reach, the target explodes. Other
projects involve driving a remote controlled toy vehicle. These examples makes it
less interesting to apply the attention value from the mindset directly.
Another thing that these games have in common is that it reflects the brain waves
in almost real-time, so it is like neurofeedback. If you do not concentrate, the car
will not move. So it may require a lot of training to be able to drive smoothly, or
to levitate an object and so forth. This can be demotivating because one never gets
to the play part, but is stuck struggling with brain wave control. One could easily
get bored, or just giving up. Thus, this is a good reason for lowering the need for
training, and make games more easy to play.
N −1
1 X n
xn = Xk ei2kπ N (4.2)
N
n=0
19
The performance of the DTF is O(N 2 ), but there is a more efficient algorithm called
fast Fourier Transform (FFT), that can compute the same result in only O(N logN ).
This is a great improvement and one of the reasons why FFT is the favorable
method of analyzing EEG signals, and other waves like sound.
Multilayer perceptron means that the neural network consists of an input layer,
possibly and minimum one hidden layer, and one output layer, as shown in fig-
ure 4.3. The output of each node in one layer connects to the input of the next
layer, but not within the same layer.
Figure 4.3: Neural network: 2 input neurons, 3 hidden layer neurons and 2 output neu-
rons. Neurons are also referred to as nodes, and the lines between the nodes are called
synapses.
The inspiration comes from the network of neurons in the human brain, but very
much a simplified version of it. The great strength with neural networks is that
they are flexible and almost universal approximators, giving the right setup: Neu-
ral networks needs to be trained before it can be used. In case of supervised learn-
ing, training sets with sample input and the corresponding output are given to
the network, and then an algorithm adjust the weights of the synapses so that it
can map valid input to correct output. A very common algorithm for this use
is the backpropagation algorithm. In that case, the neurons look like the one in
figure 4.4.
20
Except from the input nodes, all other nodes will have their input determined
by the sum of all the incoming synapses. This becomes input to the activation
function in the nodes (corresponds to the action potential in biological neurons,
see section 3.1), which determine the nodes output: if it ”fires” nor not.
To understand neural networks better, and how the backpropagation works, the
algorithm is given in pseudocode below. For more details, please refer to Dario
and Mattiussi (2008) and NeuronDotNet (n.d.-a).
The Mean Squared Error (MSE) value is calculated using equation 4.3. This value
reflects the effectiveness of the training done so far. The stopping criterion could
either be when the MSE has reached an acceptable limit, or when the number of
training cycles is attained.
θ̂ = E[(θ̂(X) − θ)2 ] (4.3)
There are several types of activation function commonly used, these are:
• Sigmoid Activation Function: y = 1/(1 + Exp(−x))
• Linear Activation Function: y = x
• Logarithmic Activation Function: y = Log(1 + |x|)
• Sine Activation Function: y = Sin(x)
• Tanh Activation Function: y = T anh(x)
21
22
5 Solution Design: System Implementation
This chapter describes the overall final system implementation. Some details are
left for chapter 6, 7 and 8, as they are more relevant there.
Figure 5.1: System Design: component overview. NeuroSky mindset and the computer
program main parts.
Comparing these components with the BCI process flow in figure 4.1, we see that
Mindset, Bluetooth-to-COM, and Mindset Interface, corresponds to ”brain sig-
nal input”; toolbox corresponds to ”EEG signal processing”; Neural Network cor-
responds to ”EEG signal classification” and Game corresponds to ”computer inter-
action”.
23
NeuroSky mindset: The easy to apply EEG device, that is wear-
able like regular headphones. It has one dry sensor that can be
placed on the forehead, left side (approximately equal to Fp1 in
the 10-20 system, figure 3.2). And 3 dry sensors on the left ear,
for reference. It has a microchip which pre-process the EEG
signal, and transmits that data via bluetooth. The output data
is presented in table 5.1. The processing algorithms are not an
open protocol, but it does a FFT on the signal which gives the
band powers. However, these powers are scaled and filtered
and thus only relative to each other (NeuroSky, 2010). Also,
the mindset have speakers, like a headset, and a microphone,
so it can be used for multiple tasks.
Output Description
Raw Data Returns raw EEG data, sampled at 1HZ
Signal Returns poor signal level, 0 is good signal, 200 is off-head state.
Delta The ”delta band” of EEG (0.5 - 2.75Hz).
Theta The ”theta band” of EEG (3.5 - 6.75Hz).
Alpha 1 The ”low alpha” band of EEG (7.5 - 9.25Hz).
Alpha 2 The ”high alpha” band of EEG (10 - 11.75Hz).
Beta 1 The ”low beta” band of EEG (13 - 16.75Hz).
Beta 2 The ”high beta” band of EEG (18 - 29.75Hz).
Gamma 1 The ”low gamma” band of EEG (31 - 39.75Hz).
Gamma 2 The ”mid gamma” band of EEG (41 - 49.75Hz).
Attention Returns the eSense Attention integer value, between 0 and 100
Meditation Returns the eSense Meditation integer value, between 0 and 100
Blink Returns an integer value between 0-255, indicating the blink strength.
Note: Even though band power data are available from the mindset, having total
control of that process using only the raw data is part of understanding BCI.
Mindset interface: There are libraries available for almost ev-
ery platform and programming language, that interfaces the
bluetooth communication with the mindset and computer. In
this project, a .NET wrapper from Peek (2010b) was used.
It handles connection, disconnection, and receives a container
with all the output data in table 5.1 every 10 milliseconds (raw
data) and every second (all other output).
Bluetooth: A bluetooth device is included in the mindset pack-
age. The device software converts the bluetooth connection to
a COM-port, which makes application and device communica-
tion much easier.
24
The Program is the main thread, event-handler and is named
BrainMonitor. It has a graphical user interface, viewable in
figure 5.2, that both displays and give users control of all the
implemented features.
Figure 5.2: Screenshot of BrainMonitor Graphical Interface. Upper left: Mindset Control
for connection, and mindset container view. At the top, middle screen: real-time raw EEG
record. Upper right: Sample view 27 spatial points and the Fourier Transformation and
band power. From bottom left to right: Scenario buttons, Neural Network training and
parameter setting, Neural Network testing, and Sample control buttons.
The ”Take sample” button in the sample control panel in figure 5.2 is particularly
useful for taking a live sample from the incoming EEG signal. Doing this, all data
about the sample is displayed in the sample view. It can be named, saved to disk
and retrieved later. Also, if a neural network is trained and ready to receive input,
the current live sample can be tested with that network. This is a great help to
quickly generate and test EEG samples.
25
The neural network is built on a solution available
at NeuronDotNet (n.d.-b), and is an implementation of the sort
explained in 4.4.1. A network setup screen was written to
enable easy modification of parameters, these are: Maximum
training cycles, learning rate, number of nodes in the hidden
layer, adjustment of input type to the network (details in chap-
ter 6,7,8), and the activation function in each layer; sigmoid
activation, linear activation, logarithmic activation, sine activa-
tion and tanh activation.
The game was one of the reasons for choosing Visual Studio
and C#, in addition to the available mindset library. The first
idea was to find an open source XNA game, preferably a role
playing game, to which the EEG could control some feature in
a dialog; feeling angry or tense could make the main character
only able to select bad options, for instance. However, this was
omitted later in the project, and a version of the classical game
Snake was implemented instead. This is covered in more detail
in chapter 8.
26
6 Step One: EEG Eye-Blink Classification
Describes the first approach towards reaching the project goals. The method that
leads to the results is explained, the results presented, analyzed and followed by a
discussion about the methods benefits, disadvantages and lessons learned.
This worked flawlessly. The library that handles the communication with the blue-
tooth device did the job.
The program is written to generate new sample objects that will add themselves
as observers of the mindset datastream (following the observer pattern), and fill
up an array of raw EEG data until it reaches the set sample size. This size was set
to 128 data points, so each sample takes 1280 milliseconds to complete (data is
updated every 10ms). There are two simple reasons for this: FFT analysis needs a
frame that is of a reasonable length, or else it will be difficult to do any accurate
analysis (Wolpaw, 2010). And, the FFT algorithm in the program needs an input
array were the size of it is a power of two.
By observing the real-time EEG record in the BrainMonitor program (see figure 5.1),
it was evident, but not surprisingly, that an eye blink gave a major fluctuation in
the EEG signal. Thus, it was decided to make this a first classification feature for
the neural network; correctness of the neural networks output would be easily ver-
ified, since analyzing the sample by observation would tell if it should be classified
as a blink or not. The other feature would be the baseline: thinking of nothing in
particular, keeping the eyes open. To gather a collection of EEG samples to be used
for network training, a scenario program was written that would do this automati-
cally while giving task instructions. Figure 6.1 shows the test scenario screen used.
27
Additionally, it was observed that the mindset was very sensitive to movement and
noise, and this is dealt with in section 6.2.2.
Figure 6.1: Sampling Screen: Middle: live instructions; bottom right: overall test instruc-
tions; bottom left: test control, session save directory and name. When the subject should
blink, the ”blink” string was flashed on the screen.
The test scenario was split in two parts, giving instructions to the user on the
screen. Part one gathered samples from the baseline task, 5 in total, and part two
gathered samples from the blink task, 5 in total. All the samples (with name,
number, raw EEG and FFT data) are saved to disk so they can be recalled later.
The collection of samples from each part in a scenario is called a set.
Figure 6.2 shows the architecture of the neural network. The input string to
the network was the five power bands of a sample: delta, theta, alpha, beta and
gamma. These were obtained by conducting FFT on the raw EEG data, and then
dividing them into buckets according to their frequency range. Each band value is
scaled with respect to the highest frequency in each individual sample, ensuring
that all values are in the interval between 0 and 1.
Figure 6.2: Neural network architecture 1: 5 input nodes, 3 hidden nodes, 1 output node.
28
Because there are only two features, 1 output node is sufficient, and all baseline
samples were trained to have 0 as the output value, and all blink samples were
trained to have 1 as the output value. The network was trained with 1 set of each
sample feature (5 blink samples, and 5 baseline samples).
Network parameters: learning rate was set to 0.25, learning cycles to 5000 and
number of hidden nodes to 3. Activation function for the input layer was linear,
and sigmoid was used for both hidden and output layer. Variations of these pa-
rameters were tested, but it did not have any great impact on the results.
The network can be tested using a single sample, or a collection of samples (which
was used in this experiment). In the latter case, the correctness of the set is cal-
culated with the basic average equation 6.1, which sums the result from each in-
dividual input sample in the set and divide it on the total number of samples.
An experiment consists of 5 scenarios taken in one single session (no headset re-
moval). Result values above 0.5 is regarded as a 1, and values below 0.5 is regarded
as a 0. N
1X
A= ai (6.1)
N
i=1
Figure 6.3, 6.4, 6.5, 6.6, and 6.7 are graphical presentation of input samples, from
both the baseline and blink task as specified.
Figure 6.3: Displays the raw EEG record of a baseline sample. Frequency spectrum of it is
showed in figure 6.4.
29
Figure 6.4: Displays the frequency spectrum of baseline sample in figure 6.3.
Figure 6.5: Displays the raw EEG record of a blink sample. Frequency spectrum of it is
showed in figure 6.6.
Figure 6.6: Displays the frequency spectrum of blink sample in figure 6.5.
30
Figure 6.7: 4 of the 5 samples used to generate blink training input for the neural network.
Table 6.1 and 6.2 contains the baseline and blink input used, respectively, for the
neural network. Each set equals the sum of band powers for each sample in one
scenario run. Set 1 in each table was used to train the network. Table 6.3 is the
corresponding output, the classification results, from the neural network.
Table 6.3: Classification result using data sets from table 6.1 and 6.2. Close to 1 = baseline,
and close to 0 = blink.
31
During each scenario, the attention and meditation values, that is calculated by
and received from the mindset, were plotten in a graph, and figure 6.8 is an exam-
ple of this. The plotting is from scenario 4, the first half (Time < 1600) is from the
baseline, and second half is the blink set (found in table 6.2 and 6.1).
Figure 6.8: Plotting of attention and meditation levels during scenario 1, a shift in both
values when going from baseline to blink task is clearly seen.
Figure 6.9 shows a noise sample, with the respective frequency spectrum in fig-
ure 6.10. When compared to the figures 6.5 and 6.6 of the blink sample, they are
quite similar. This sample was taken when the forehead of the test person was
tapped with a finger. Other movements like jumping, turning the head, nodding
also gave similar noise samples. This particular sample was classified as a blink.
Figure 6.9: Spatial sample of noise : Tapping Figure 6.10: Frequency spectrum of noise :
on the forehead. Tapping on the forehead.
32
Discussion of Results and the Sensitive Electrode
6.3
The result from the tests demonstrates that the implementation works as it should,
so far. It can connect and communicate with the mindset, sample EEG input, train
and test a neural network. Also, the system was able to classify blink correctly,
averaging at 99%.
Although noise was expected from the headset, it was still not anticipated that it
would be so sensitive to movements. Because of this, it was decided to conduct all
baseline experiments and sampling with eyes open, and without any movements
of head and body. The disadvantage of this is that it becomes very tiresome for the
eyes, on the other hand, the strict rule ease off the need to filter the EEG signal for
such artifacts. Indeed, this noise issue and the fact that the only electrode on the
mindset is placed in the forehead, brings research question 1 to the table: Does
blinking disturb the only input signal too much so that it makes it unreliable?
In figure 6.8, it is clearly seen that the NeuroSky algorithms that calculates atten-
tion and meditation are influenced by blinking. During the baseline part, the av-
erage attention and meditation level is approximately between 80-100 and 50-60,
respectively. When the blink part starts, both these levels drop drastically, espe-
cially attention. This is counter-intuitive, because waiting for the blink commands,
and respond to them appropriately, should bring the test person to a higher level
of alertness and focus, and not make them more inattentive. The blinks in this par-
ticular scenario may have been exaggerated and caused major disturbance, but the
tendency across all the experiments is that whenever there is an absence of blink,
the attention level goes to the top, and that the same level is very difficult to reach
even when blinking normally. But would this still be true if the electrode was
placed elsewhere on the scalp? This was tried, but it was unsuccessful to get a sig-
nal. And because the electrode is static, the options are limited without breaking
the mindset. In some studies, placement of frontal electrode is used to control that
the samples they take from other electrodes do not contain blink artifacts (Lukas
et al., 1995) (Wolpaw et al., 2000). However, the fact remains that the results in-
dicates that persons using the mindset should not blink during sampling. This is
not ideal when considering to make use of it in a real-time system and for longer
periods, like in gaming.
In table 6.1 and 6.2, or when comparing the power spectrum of figure 6.4 and 6.6,
the difference between baseline and blink is clear. Blink is a simultaneously high
boost of delta (more than 4 times in average), theta and alpha amplitudes, and a
decrease in gamma. Blink detection could be done by monitoring, for instance,
delta, theta and gamma. If delta and theta values increased simultaneously, and
gamma decreased, that would be a blink signature. The amount of change from
pre-values could indicate strength. Like that of NeuroSky. No neural network is
needed. Finally, blinking could also be detected by using a camera, and it is a
muscle movement. Thus, it is not regarded as true brain communication as BCI
33
is defined in chapter 4. The system should be able to classify more than muscle
movement.
6.3.2 Critical Discovery: Making Better and More Stable Input Samples
This was actually discovered while trying to classify a mental task in step two. No
positive results were found when trying to classify input samples, so changes had
to be made. It is mention here, because it led to the fact that lot of test sessions
needed to be redone. Further, all results presented in this step, in step 2 and 3,
follows this way of generating network input.
Up to this point in the project, the neural network had been trained and tested with
single samples, representing 1280 milliseconds of EEG information each. This was
fine when only dealing with blink detection, because that is a very defined and
short event (Testing of blink was still redone to ensure consistency in all tests, in all
steps). However, when dealing with mental states, it is safe to assume that this is
not so, without long practice at least. The discovery was that the samples needed to
be reflecting a time period much greater than 1.3 seconds. This was done by taking
the average of all the band powers from all samples in a scenario set. The result
is shown above. Table 6.4 represent the band powers of a single baseline sample
(Scaled with respect to highest frequency). Table 6.5 represents the summation of
band powers of 20 baseline samples (taken from the same scenario), and finally,
table 6.6 is the average of table 6.5, and represents one sample set, usable for
training and testing. The difference between band powers of the single sample
and the set is evident.
The drawback is that it now takes approximately 20 seconds to generate input for
the network. In a game setting and real-time environment, this is a long time, and
it is a limitation.
34
7 Step Two: EEG Mental Task Classification
It was decided that the mental state should be of a simple character, and the first
choice then became a motion task: thinking about and visualizing movement.
This is a mental task that is common to use in EEG experiments (Curran, 2003).
Collection of data sets was done by sampling baseline first, followed by visualizing
movement: Raising and lowering one arm, both arms, and legs. However, despite
all efforts and numerous trials and testing, there were no consistent findings that
proved to be classifiable. This led to the second experiment.
The idea for this experiment was that visually invoked movement could help change
the mental state of the test person faster and more consistent. By combining mo-
tion intention and ERP (see section 3.3.1), it could be possible that the P300 effect
would have an impact on the band powers. A new test scenario screen was im-
plemented, see figure 7.1, that had a cartoon character doing arm movements:
moving an arm up and down repetitively towards the forehead. The test person
is instructed to imagine doing the same, and follow the rhythm in the motion;
receiving and responding to external stimuli.
Again, recording and sampling were done with eyes open during the whole ses-
sion. The scenario was split in two parts: sampling motion first and baseline sec-
ond. As input to the neural network, three types were tried: 5 band powers (delta,
theta, alpha, beta, gamma); 5 band powers and meditation and attention values,
making it a 7 input network; specific band powers (delta, theta, alpha1, alpha2,
beta1, beta2, gamma1, gamma2), making it a 8 input network.
Numerous trials and tests were conducted, but no results were found indicating
that this was a usable approach towards being able to classify a mental state. How-
35
ever, from the classification results it became clear that using meditation and at-
tention values as additional input to the neural network, and the specific band
powers, were worser options than only using the 5 band powers. This if further
discussed in section 7.3.
Figure 7.1: Sampling screen: Middle: live instructions; bottom right: overall test instruc-
tions; bottom left: test control, session save directory and options.
It was decided to try another mental task: visual counting, which have been used
successfully in, for instance, a study by Keirn and Aunon (1990). This also matches
the functionality of the frontal lobe, as it is related to mathematics and problem
solving. 1 scenario consisted of two parts: in the first part, 20 baseline samples
was recorded. In the second part, 20 visual counting samples was recorder. Eyes
were open during the entire scenario. The 20 samples from each part was used
to generate 1 training set per feature, averaged and scaled to 1, like discussed in
section 6.3.2.
Experiment 3A gave results, but they were not satisfying. This led to a variant
where the baseline part of a scenario was conducted with eyes closed, in an attempt
to increase the difference in band powers. This should work because if one assumes
that when closing your eyes, the perception process is halted in the brain since
there are no visual input anymore. Regardless, in a study by L. Zhang et al. (2005)
it was recorded a major alpha waves increase in 20 EEG subjects, when their eyes
were closed vs. when their eyes were open.
36
7.1.5 Neural Network Architecture and Setup for Experiment Three
The neural network architecture are the same as in step 1 (see section 6.1.3). Re-
sults from experiment two indicated that the 5 input band power gave better per-
formance, so that was used in this setup as well. Network consisted of 1 input
layer: 5 input nodes, 1 hidden layer: 3 hidden nodes, 1 output layer, 1 node.
Network parameters setup: learning rate was set to 0.2, learning cycles set to 1000.
Activation function for the input layer was linear, sigmoid function for the hidden
and the output layer. Variations of these parameters were also tested, but did not
have any great impact on the results, like in step 1.
Figure 7.2: Comparing total band power from all 5 sets in session one.
Figure 7.3: Comparing total band power from all 5 sets in the sessino two.
37
Figure 7.2 and 7.3 show results from two sessions of experiment three. The bars
show the total summation of power in each frequency band over all the sets from
5 scenarios. When comparing the two charts, they are the opposite of each other:
Blue dominates red in session one, and vice versa in session two.
The results in table 7.1 is the best among the sessions that were conducted, and
classified 4 of 5 sets correctly, both baseline and count. 3 correct classifications of
5 possible was the average. In one session, only 1 of 5 was correctly classified, and
that was when the neural network was tested with the same set that was trained
with.
Table 7.1: Classification result using data sets from figure 7.2
Table 7.4: Classification result using data sets from table 7.2 and 7.3.
38
As seen in table 7.4, classification scores 5 of 5. Specific detail about the total band
power from each set used for baseline and counting, are found in 7.2 and 7.3,
respectively. The tables show an increase of alpha activity, and a decrease of all
the other waves, when eyes are closed.
Figure 7.4 through 7.7 are input samples used in the session, it illustrates the dif-
ficulty to interpret the waves by observation for the untrained eye.
Figure 7.4: Spatial sample of baseline - Eyes Figure 7.5: Frequency spectrum of baseline -
closed Eyes closed
39
Discussion of Results and How the Eye State is the Key
7.3
Results from the experiments indicate the possibility to classify baseline and men-
tal count states, with a probability greater than 90%. This is if using a method that
combines sampling with eyes open and eyes closed. Experiments with eyes open
only, averaged with about 60% correct classifications. There were some exceptions
making only 20% in average, and one that made it above 90%. In summation,
these are unstable results. There can be a number of reasons for this, and they are
listed below and then discussed:
1. One electrode is not adequate to get the information needed to identify com-
plex though patterns in the mind.
2. The chosen tasks are not suitable with regards to the location of the electrode.
3. The chosen tasks are not suitable with regards to the test person.
4. Band frequencies are not the best choice for signal analysis in this context.
5. It is difficult to control that tasks are carried out correctly by the test person.
6. Neural Network is not the most suitable classification choice in this context.
As mentioned in section 4.1.1, most EEG studies uses 4 electrodes on more, placed
at some distance from the forehead (C, P, O groups in the 10-20 system, see fig-
ure 3.2). This suggest that perhaps one electrode is just not enough, since this is
not common practice. This aside, it can also mean that it is more difficult to find
a function or task that can be directed towards the electrode location. There is no
way to safeguard that one of several electrodes will record the essential informa-
tion. Still, results from experiment 3B accords with the conclusion from previous
research in L. Zhang et al. (2005). The biggest difference in total sum of band
power with eyes closed and eyes open is the alpha wave, as the study suggests.
However, in a game scenario, closing the eyes in long periods are not ideal for
gameplay, unless something is particularly designed for it. This is also the reason
why it took so long before experimenting with the eyes closed. The focus was what
would work in a game setting, and not in the system.
Visualizing movement is something that is very much used in EEG experiments.
Usually, it gives very good classification ratings in other studies (Lotte et al., 2007),
but no results were made when trying it in this project. Again, location of the elec-
trode can be assumed to be the reason for this. However, this can not be verified
since the mindset electrode is static. Moving it would require to break the device.
But there could also be other explanations. It is known that EEG patients and test
persons can learn to do a mental task, that is recognizable in the system, and then
forget how to do them some time later. Some are unable to re-learn it again. It
also happens that there are one or several persons in a healthy test population that
cannot be recognized for their mental efforts by the system, even though the rest of
the group can (Curran, 2003). The EEG of people is very different, so it is possible
that the test person in this experiment was not able to do the task, in a manner that
affected the EEG in any case. Also, it could be that other persons motion intentions
40
will be detected, but not their mental counting, or perhaps both. As an example
of not doing the task correctly, consider the baseline task. Could the instruction
to not think about anything in particular, have the opposite effect? That you start
to think about not thinking, or you focus to much about not thinking? This is
where practice comes into play, being able to regulate mental activity, an issue of
EEG that is discussed in section 3.3.2. However, this could explain the variations
of results in experiment 3A: High mental activity in both baseline and visualiza-
tion would give similar band powers. The test person may think he is doing two
different task, but in reality he is doing the same.
From this, some experiments were decided to be conducted with the attention and
meditation levels as extra input to the neural network. But the levels did not vary
enough, for the same reasons discussed in section 6.3: eyes open over time will
return a stable, high level attention value. Thus, this did not solve the problem.
Results were also made that suggests that EEG signals can vary even in the same
person, as the identifier in section 4.1.1 states: EEG signals are non-stationarity.
The results referred to are the two identical sessions with opposite input values in
experiment 3A, figure 7.2 and 7.3. The band powers in session one are generally
lower than baseline during mental count, but higher in session two. This indicates
that new neural networks should be trained with fresh input, for every session.
Having the baseline task done with eyes closed may not be ideal for gameplay, but
it gives a very good opportunity to rest them. It is stressed again here, that forcing
your eyes not to blink is disturbing in the long run. This is the most negative
when it comes to carry out these experiments, but as we have seen, it is the best
alternative if one wants to both view the screen and execute commands.
41
42
8 Step Three: Controlling a Game with EEG
Figure 8.1 shows the two parts of the final system and the steps within them. In
order to play, the system needs to be initialized with a trained neural network.
43
8.1.2 Snake Gameplay, Controllable Features and Game Loop
This implemented version of Snake has the following gameplay. You start with
a single square that you control, and which represents the snake. It can move
in three directions: forward, left and right. The goal is to locate and eat apples
on a map, making the snake grow in length, and to become as large as possible.
Collision with the snake body will end the game, and avoiding this gets more
difficult as the snake grows, adding thrill. The map is borderless, meaning that if
the snake goes outside the screen, it will re-enter from the border opposite of it.
This adds an strategic element, and it can be used to escape from a tight spot, or
quickly navigate from one end of the screen, to the other.
The controllable features to choose from, are the three directions of movement.
For the sake of having speed in the game, moving forward should be automatic,
and whether to turn left or right should be controlled by the user via EEG input.
Section 6.3.2 discusses the need for many samples to be able to classify a mental
task, and as a result of that, the game can not be real-time; meaning that the game
should pause while collecting samples for classification. If it was to be real-time,
not only would the user need to know the next action 20 seconds in advance, but it
would only be possible to issue a command every 20 seconds. During that time, the
snake would continue forward uncontrolled. Unless the snake moves really slow.
To have EEG controlling all three directions would also be too slow, for the same
reasons. Alternatively, the forward direction could be controlled by the attention
level received every second from the mindset. But, for now, moving forward is
considered automatic. This is a fair setup to attain speed, since forward is the
most used direction in which the snake moves.
The system should have a mechanism to initialize the pause for sample collection.
This should be user controlled, and a blink input was chosen. User blink can
be detected almost real-time, and since the mindset gives information about the
blink strength, it is possible to set a a high threshold that allows regular blinking
for the user. This removes the need to play the entire game with open eyes. Also,
choosing blink eliminates the need to interact with a keyboard or mouse, making
the game totally controlled by EEG. Figure 8.2 is the resulting state diagram for the
game control. At game start, snake enters the move forward state. When blink is
detected, ”sampling mode” is entered. The system waits 1.5 seconds before doing
this. If not, the first sample taken would be contaminated with blink artifacts.
44
Results from classification determines either a ”left turn” or a ”right turn” state,
before returning to the forward state again. Since the intended classification ex-
periment is 3B, the baseline task is conducted with eyes closed, so the user needs to
be informed when the sample collection is over. This is solved by playing a ”ding”
sound when sample mode is entered and exited.
The testing follows the system flow of figure 8.1. There is two types of tests, 1)
play and 2) control. Sessions in both test types repeats step 2 to 6. The headset is
not to be moved during a session. For step 2, 20 samples of baseline (eyes closed)
and 20 samples of mental counting (eyes open) were taken and used to train the
network. The network is then tested with the same sets, to ensure that they classify
correctly: Close to 1 represents baseline, close to 0 represents mental count. Same
network setup as in section 6.1.3 still applies.
NOTE: Because 20 seconds seemed like a long time, sample collection while play-
ing was reduced to 10 seconds, averaging 10 samples into a single input instead of
20.
1. Play Test: The user plays the game following the rules. Tests were done where
only step 3 to 6 was repeated, using old data to training the neural network. The
purpose is to see if those training sets are usable after disconnection and reloca-
tion of the headset. In that case, it could indicate that it is possible to make user
profiles, to quickly start a game and bypass the last setup steps.
Testing stops when the game is over, or if the user do not want to continue for
whatever reason. During the test, statistics of the following is taken:
• Number of wrong classifications: result is not like the test person intended.
• Number of correct blinks: System correctly enters sampling mode after user
gave a powerful blink to indicate that it should.
• Number of faulty blinks: System incorrectly enters sampling mode after the
user blinked normally, without intention of going into sampling mode.
2. Control test: The user tries to classify a baseline task with eyes open, and a
counting task with eyes closed. This is interesting, because it can indicate whether
mental efforts affects the results at all, or if it is just controlled by eye states.
45
Final Testing, Results and Findings
8.2
Figure 8.3: Screenshot from the snake-game. Middle top: Box that is colored red when
brain waves are NOT recorded, and green when it is recording. Center: Game display:
Red dots represents the snake body, green dot is the snake head, and blue dot is an apple.
Bottom left: current action.
Game 1 lasted 7 minutes and 47 seconds, were 61% of that time was used to collect
samples. 4 apples were eaten before the game was over (crashed into the end of
the tail when growing). The neural network was trained, and had an accuracy of
0.98 when tested with the same sets it was trained with.
Table 8.1: Test results game 1, subject one
46
Game 2 lasted approximately 6 minutes, were 51% of the time was used to collect
samples. 8 apples were eaten before it was game over (The 3 blink misses was the
cause of that). The neural network was trained, and had an accuracy of 0.95 when
tested with the same sets it was trained with.
Table 8.2: Test results game 2, subject one
Game 1 lasted 9 minutes and 13 seconds, were 34% of that time was used to collect
samples. 3 apples were eaten before it was game over. The neural network was
trained, and had an accuracy of 0.97 when tested with the same sets it was trained
with.
Table 8.4: Test results game 2, subject two
Game 2 lasted approximately 5 minutes, were 38% of the time was used to collect
samples. 3 apples were eaten before it was game over. The neural network was
trained, and had an accuracy of 0.96 when tested with the same sets it was trained
with.
Reusing Training Sets: For both subjects, it was unsuccessful to reuse the training
sets. No correct classifications were achieved.
47
8.2.2 Control test
In figure 8.4, each bar is the total average from 5 classification results in the control
test. With eyes closed, recognition certainty of the baseline task is close to 100%,
and gets reduced to about 50% when doing mental counting instead. With eyes
open, recognition certainty of mental counting is close to 80% (Close to 0 is classi-
fied as counting, thus the probability is calculated by subtracting 1), and reduced
to 60% when conducting the baseline task.
In figure 8.5, each bar is the total average from 5 classification results in the con-
trol test. With eyes closed, recognition certainty of the baseline task is 91%, and
gets reduced to about 78% when doing mental counting instead. With eyes open,
recognition certainty of mental counting is close to 99% (Close to 0 is classified
as counting, thus the probability is calculated by subtracting 1), and reduced to
0.97% when conducting the baseline task.
48
Discussion of Results
8.3
The results show a BCI system that enables users to play a game of Snake, control-
ling everything with EEG signals. Correct classification and eye-blink detection in
the play tests for the subjects are over 90%. Also, acquiring this accuracy required
no training. This is true for subject two, who had never used EEG equipment
before. The author of this project, who is subject one, have had two months of
experimenting with it, and can not be regarded as unfamiliar with the device and
the classification tasks. However, the results are acceptable as a proof-of-concept
for this project, and provides a good platform for which further improvements can
increase the accuracy.
Further, the control tests indicates that it is not just the two eye states, open and
closed, that affects the EEG signal. With eyes open, it was possible to successfully
classify a baseline task when attempted, and likewise, it was possible to identify
a count task when eyes were closed. In general, when not doing the mental tasks
correctly, the classification probability was lowered with 40% to 50%. This sug-
gests, that perhaps with more experience and practice it will be possible to obtain
faster and more accurate brain wave control and thus make the eye state redun-
dant. Still, these states are the key to correct classification in the current system,
at least for beginners. It is clear that subject one was more able to alter the waves
than subject two, implying that perhaps training made this effect. However, and
more importantly, these result indicates that the classification is not controlled by
muscle movement.
49
Both users had good experiences with using EEG to control the snake. Compared
to the test experiments in step 2, the game testing was much more relaxed and less
strainful for the eyes. This has to do with the blink strength feature that allows
normal blinking to go undetected, and that closed eyes is a key feature for the
baseline task. This is a satisfying solution since the game needs to pause to collect
samples anyway, and the user is in control of when that will happen. Also, since
mouse and keyboard are not used, the possibilities of sitting position are many
more (Illustrated in figure 8.6).
Observations and notations from playing:
• If focused, it is easy to handle and control the snake.
• One time, when the snake was in a tight spot and it had to make a baseline
turn (left turn), the excitement led to too much mental activity, and it was
classified as a counting task, and the snake died.
• Since the snake rotates, it is not always so obvious what the left and the right
side of the snake is.
• There can be some delay from the physical blink to it is detected by the sys-
tem. Therefore, the blinking must be timed extra carefully.
• Being able to get the classification results that is intended gave a mastering
feeling.
• The borderless map was used a lot to make shortcuts and to escape. It re-
duces the necessity of having to turn very often. This also speeds up the
game.
• Time used to collect samples did not feel long.
50
9 Conclusion
This report presents results that shows that is it possible to build a Brain-Computer
Interface system that allow users to play a game and controlling it with their brain
waves. This have been accomplished by using the NeuroSky mindset EEG equip-
ment featuring only one electrode on the forehead. EEG signals from the user are
sent to the computer via bluetooth. The signal is then processed and the waves
band power is calculated using the Fourier transform. This information is used
as input to a neural network that is trained to classify two different mental tasks.
Then this classification is used to control the movements (left and right turn) of a
character in a custom built PC game, successfully.
The biggest challenge and time-consumption in the project was not the implemen-
tation itself, but testing it with the use of real-time EEG input. Three major test
steps is outlined with results that have given insights in the workings of EEG and
difficulties with BCI systems. The first step was to implement all the components
of the system and make them communicate with each other, then enable the sys-
tem to classify blinks in the incoming EEG signal samples. This was done with
a success rate close to 99%. The solution worked, indeed, but was not adequate
to classify mental tasks. This was improved in step two, were a new method was
discovered that required ten times as many samples and thus effort from the user.
Still, it became possible to classify two mental states: baseline (relaxed, calm and
not thinking of anything in particular), and mental counting. The first results
only gave 60% probability of correct classification, but this was further increased
to greater than 90%. This high rate was only attainable when eye states (eyes open
and closed) were used actively by the user in addition to the tasks. However, this
enabled the realization of step 3, were a version of the game Snake was designed
and implemented to work with the EEG input. Results from user tests show that
the snakes movements were correctly controlled with an accuracy of 90 to 100%.
Regarding the research questions (see section 2.2.1), the following conclusions are
made from the project results and findings:
RQ1: That one electrode in the forehead can replace a grid of, or several, elec-
trodes is highly unlikely. No papers were found of previous studies, were only one
electrode have been used. The experience from this study, is that mental efforts
that are relatively safe to classify did not work. There can however be other rea-
sons for this than just the single electrode, but at least it suggest that one is not
adequate.
RQ2: Having the experience of using both the NeuroSky mindset and traditional
EEG equipment, NeuroSky fulfills the expectations as described in the early chap-
ters. More interestingly, the limitation that was most profound with the mindset
was the static electrode placement. It can be moved to a certain degree, but not
51
enough to get it away from the forehead. Also, one or two additional sensors would
have been great. The Emotive headset, featuring 14 electrodes (see section 4.2.1),
would be the recommended choice for this upgrade. It is only slightly more ex-
pensive. The connected limitation with placement is that the sensor is heavily
influenced by blink. However, the reason the electrode is placed on the forehead,
is because people do not have hair there, which is a requirement for this type of
dry sensor.
RQ3: The type of classification achieved using a neural network is that of band
power patterns. Where the difference between the power bands is of such degree
that they are distinguishable, and were the right mental tasks are chosen that will
promote this pattern in the users EEG.
RQ4: The resulting BCI system enables an entertaining way for training brain
wave control. Both test persons thought is was more fun to play the snake game,
than the NeuroBoy software that comes with the NeuroSky mindset. However,
more people should test the system to verify that this is truly so.
RQ5: It requires no training to use the resulting system, only 1-2 minutes of prepa-
ration time, were EEG samples needs to be taken for the neural network training.
With these samples the network learns the difference between the two mental task
patterns based on the users current EEG. It was assumed that some training would
be needed in order to learn how to do the tasks. This too should be verified by
testing the system on more people and get the necessary statistics.
Compared to the games that have used the NeuroSky mindset and the attention
value only, this game stand out as more easy to use. It is easier to control the
output of mental efforts and thus the accuracy is higher. In a context were the
output is binary, the accuracy is additionally higher. The classification (rather
than a threshold) takes longer time, so the game is slower. But is works, and it is
still fun. Also, there is no training needed in order to play, one just have to focus
on the task. In the other games, the parameters than controls the attention levels
are unknown. If it is raised by increased beta waves and lower theta waves, one
would have to figure out how to manipulate these waves in a trail-and-error style.
In neurofeedback therapy, this is perhaps wanted, but if one just want to play, the
snake game is much easier. Like a patient that is paralyzed and want to kill some
time, and not train brain wave control.
There are two main suggestion for continued work with the system presented in
this report. 1) Further development of the program, improving the game, signal
processing and classification procedures and feature extensions. 2) Use the cur-
rent program as a tool for larger scale tests with people, to do EEG surveys and
monitoring studies. Most of these suggestions comes from observations made, or
questions asked, in the discussion sections of chapter 6, 7 and 8.
52
1) Further development and improvements of BrainMonitor
2) BrainMonitor as a tool
Here are some suggestions of how to utilize the current system as it is:
• More verifications: Run tests that run over a period of time, to see if it is
possible to improve brain wave control skills using the system. The goal and
motivation should be to annihilate the need for the eye states, and rely on
mental efforts only.
• Explore classification possibilities: Define new experiments to find if there
are other mental tasks that are usable for classification in the system. This
could be rotation, mental speech or specific memory retrieval.
53
• Explore placement possibilities: Disassemble, if possible, the arm on the
mindset that holds the electrode and find alternative placement for it. Con-
duct test to see if those placements are better suited for solving the classifi-
cation tasks at hand. The inconvenience is that there can be no hair between
the electrode and scalp.
Instead of having the mind directly control features of a game, it could be used as
an unconscious influence in the gameplay. For example, in a role playing game,
you have a main character, and perhaps a party of followers or helpers. It is com-
mon, that throughout the game, your main character gains more experience and
get better in a set of skills that will help to conquer challenges later in the game.
EEG could be used to add a new dimension to that kind of character building. A
continuous analysis of the brain waves could form user models that will be used
for influence, with both short- and long-term effects. In the latter case, if you are
in general very relaxed or focused, your character might regenerate quicker (if
combat is involved), or have more endurance, or get access to special spells of the
defensive kind. The opposite would apply for those who are generally restless.
In the external game world, it the player gives signs of drowsiness, the game could
introduce unexpected happenings, like an suddenly ambush or develop a creepy
atmosphere using mediums like music and lights, whatever is most appropriate.
This would be a short-term effect. An other example could be that the dialog could
adjust to the users current mood, or how the party of followers engage and act
around you. This would create more variation in the game and give them more
personality. Additionally, the EEG classifications and algorithms that are to ana-
lyze the brain waves do not have to be that accurate. Incorrect results would not
hinder the gameplay. And thus it may be a good place to start applying EEG. At
least when applying one electrode equipment like the mindset and sampling takes
time, indirect influence may be the better way to go.
54
References
Andersen, K., Juvik, E., Kjellen, E., & Storstein, K. I. B. (2009). Radio controlled
helicopter using neurofeedback. unpublished.
Andrew T Campbell, Tanzeem Choudhury, Shaohan Hu, Hong Lu, Mashfiqui
Rabbi, Rajeev D S Raizada, M. K. M. . (2010). NeuroPhone: Brain-Mobile
Phone Interface using a Wireless EEG Headset. MobiHeld 2, 3–8. Available
from http://www1.cs.dartmouth.edu/reports/TR2010-666.pdf
Berg, K. (2010). Balanser hjernen og yt mer. Retrieved from http://www.ytmer.no/.
Bernier, R., Dawson, G., Webb, S., & Murias, M. (2007, August). EEG mu rhythm
and imitation impairments in individuals with autism spectrum disorder.
Brain and cognition, 64(3), 228–37.
Blankertz, B., Dornhege, G., Krauledat, M., Müller, K.-R., Kunzmann, V., Losch,
F., et al. (2006, June). The Berlin Brain-Computer Interface: EEG-
based communication without subject training. IEEE transactions on neu-
ral systems and rehabilitation engineering : a publication of the IEEE En-
gineering in Medicine and Biology Society, 14(2), 147–52. Available from
http://www.ncbi.nlm.nih.gov/pubmed/16792281
Bos, O., & Reuderink, B. (2008). Brainbasher: a BCI game. Eindhoven University of
Technology, 36–39. Available from http://doc.utwente.nl/65050/
Brain Entertainment. (n.d.). Available from http://betabrainwave.com/
Braverman, E. (1990). Brain mapping: a short guide to interpretation, philosophy
and future. Journal of Orthomolecular Medicine, 5(4), 189–197. Available
from http://orthomolecular.org/library/jom/1990/pdf/1990-v05n04-
p189.pdf
Curran, E. (2003, April). Learning to control brain activity: A review of the pro-
duction and control of EEG components for driving brain–computer inter-
face (BCI) systems. Brain and Cognition, 51(3), 326–336. Available from
http://linkinghub.elsevier.com/retrieve/pii/S0278262603000368
Dario, F., & Mattiussi, C. (2008). Bio-Inspired Artificial Intelligence (R. C. Arkin,
Ed.). London, England: MIT press.
Emotiv. (n.d.). Brain Computer Interface Technology. Retrieved autumn 2010 from
http://www.emotiv.com/.
Fabiani, G. E., McFarland, D. J., Wolpaw, J. R., & Pfurtscheller, G. (2004,
September). Conversion of EEG activity into cursor movement by
a brain-computer interface (BCI). IEEE transactions on neural sys-
tems and rehabilitation engineering : a publication of the IEEE Engi-
neering in Medicine and Biology Society, 12(3), 331–8. Available from
http://www.ncbi.nlm.nih.gov/pubmed/15473195
Felzer, T., & Freisleben, B. (2003, December). Analyzing EEG signals using
the probability estimating guarded neural classifier. IEEE transactions on
neural systems and rehabilitation engineering : a publication of the IEEE En-
gineering in Medicine and Biology Society, 11(4), 361–71. Available from
http://www.ncbi.nlm.nih.gov/pubmed/14960111
55
Gevensleben, H., Holl, B., Albrecht, B., Vogel, C., Schlamp, D., Kratz, O., et al.
(2009). Is neurofeedback an efficacious treatment for ADHD? A randomised
controlled clinical trial. Journal of Child Psychology and Psychiatry, 50:7, 780–
789.
Gilden, L. (2009). The Role of Language in Human Social Conflict. Retrieved autumn
2010, from http://www.lifwynnfoundation.org/langrole.htm.
G.tec. (2009). intendiX - World ’ s first personal BCI speller (Vol. 2011) (No. i).
Available from http://www.intendix.com/
Hammond, D. C. (2006). What is Neurofeedback? Journal of Neurotherapy, 10:4,
11.
Heinrich, H., Gevensleven, H., & Strehl, U. (2007). Annotation: Neurofeedback -
train your brain to train behaviour. Journal of Child Psychology and Psychiatry,
48:1, 3–16.
Hiraiwa, A., Shimohara, K., & Tokunaga, Y. (2002). EEG topog-
raphy recognition by neural networks. Engineering in Medicine
and Biology Magazine, IEEE, 9(3), 39–42. Available from
http://ieeexplore.ieee.org/xpls/abs all.jsp?arnumber=59211
Hsu, W.-Y., & Sun, Y.-N. (2009, January). EEG-based motor imagery analysis using
weighted wavelet transform features. Journal of neuroscience methods, 176(2),
310–8. Available from http://www.ncbi.nlm.nih.gov/pubmed/18848844
Immrama. (n.d.). Available from http://www.immrama.org/eeg/electrode.html
56
EEG Using Artificial Neural Network. 2008 Congress on Image and Signal
Processing, 213–215.
Lotte, F., Congedo, M., Lécuyer, a., Lamarche, F., & Arnaldi, B. (2007, June).
A review of classification algorithms for EEG-based brain-computer in-
terfaces. Journal of neural engineering, 4(2), R1–R13. Available from
http://www.ncbi.nlm.nih.gov/pubmed/17409472
Lukas, S. E., Mendelson, J. H., & Benedikt, R. (1995, February).
Electroencephalographic correlates of marihuana-induced eupho-
ria. Drug and alcohol dependence, 37(2), 131–40. Available from
http://www.ncbi.nlm.nih.gov/pubmed/7758402
Lukas, S. E., Mendelson, J. H., Kouri, E., Bolduc, M., & Amass, L. (1990). Ethanol-
induced alterations in EEG alpha activity and apparent source of the audi-
tory P300 evoked response potential. Alcohol (Fayetteville, N.Y.), 7(5), 471–7.
Available from http://www.ncbi.nlm.nih.gov/pubmed/2222851
Masterpasqua, F., & Healey, K. N. (2003). Neurofeedback in Psychological Practice.
Professional Psychology: Research and Practice, 34:6, 652–656.
Mitsar. (2008). BIOFEEDBACK TRAINER MITSAR-BFB. pdf available at
http://www.mitsar-medical.com/download/promo/Mitsar-BFB 2008.pdf.
Mitsar. (2010). Mitsar Co. Ltd. Medical equipment for functional diagnostics and
neurofeedback. Retrieved from http://www.mitsar-medical.com/.
Nawrath, M. (n.d.). Lab3 - Laboratory for Experimen-
tal Computer Science. Retrieved autumn 2010, from
http://interface.khm.de/index.php/lab/experiments/arduino-realtime-
audio-processing.
NeuronDotNet. (n.d.-a). Backpropagation Algorithm. Available from
http://neurondotnet.freehostia.com/manual/bpnalgo.html
NeuronDotNet. (n.d.-b). NeuronDotNet. Available from
http://neurondotnet.freehostia.com/download.html
Neurosky. (n.d.). Neurosky. Available from http://www.neurosky.com/
NeuroSky, I. A. (2010). ThinkGear Socket Protocol (Tech. Rep.). Available from
http://www.neurosky.com/
Peek, B. (2010a). MindBlaster. Available from
http://channel9.msdn.com/coding4fun/articles/MindBlaster
Peek, B. (2010b). ThinkGearNET 1.1. Available from
http://thinkgearnet.codeplex.com/
Plass-Oude Bos, D., Reuderink, B., Laar, B. L. A. van de, Gürkök, H.,
Mühl, C., Poel, M., et al. (2010, October). Human-Computer Inter-
action for BCI Games: Usability and User Experience. In A. Sourin
(Ed.), Proceedings of the international conference on cyberworlds 2010, sin-
gapore (pp. 277–281). Los Alamitos: IEEE Computer Society Press.
http://eprints.eemcs.utwente.nl/18057/.
PlayAttention. (n.d.). Play Attention. Retrieved in august 2010 from
http://www.playattention.com/.
Rangaswamy, M., Porjesz, B., Chorlian, D. B., Wang, K., Jones, K. a.,
Bauer, L. O., et al. (2002, October). Beta power in the EEG
of alcoholics. Biological psychiatry, 52(8), 831–42. Available from
http://www.ncbi.nlm.nih.gov/pubmed/12372655
Reuderink, B. (2008a). Games and Brain-Computer In-
57
terfaces: The State of the Art. Internal Report.
http://www.borisreuderink.nl/files/publications/reuderink2008gbc.pdf.
Reuderink, B. (2008b). Games and brain-computer interfaces: The state of the
art. WP2 BrainGain Deliverable, HMI, University of Twente (September 2008),
1–11.
Schalk, G., McFarland, D. J., Hinterberger, T., Birbaumer, N., & Wol-
paw, J. R. (2004, June). BCI2000: a general-purpose brain-
computer interface (BCI) system. (Vol. 51) (No. 6). Available from
http://www.ncbi.nlm.nih.gov/pubmed/15188875
Sherlin, Leslie, Arns, Martijn, Lubar, Joel, et al. (2010). A Position Paper on Neuro-
feedback for the Treatment of ADHD. Journal of Neurotherapy, 14:2, 66–78.
Sinek, S. (2009). Start With Why. Retrieved autumn 2010 from
http://www.startwithwhy.com/.
SmartBrain. (n.d.). Biofeedback. Retrieved december 2010, from
http://www.smartbraintech.com/.
Stigsby, B., Rodenberg, J. C., & Moth, H. B. (1981). Electroencephalographic find-
ings during mantra meditation (Transcendental Meditation). A Controlled,
Quantitative Study of Experienced Mediators. Electroencephalography and
Chnical Neurophystology,, 51, 434–442.
Sundaram, M., Sadler, R. M., Young, G. B., & Pillay, N. (1999). REVIEW ARTICLE
EEG in Epilepsy : Current Perspectives. The Canadian Journal of Neurological
Sciences, 26(4), 255–262.
Takahashia, T., Murataa, T., Hamadab, T., Omoria, M., Kosakaa, H., Kikuchic, M.,
et al. (2005). Changes in EEG and autonomic nervous activity during med-
itation and their association with personality traits. International Journal of
Psychophysiology, 55, 199–207.
Universe-review.ca. (n.d.). A Review of the Universe. Available from
http://universe-review.ca/I10-80-prefrontal.jpg
Wolpaw, J. R. (2010, November). Brain-computer interface re-
search comes of age: traditional assumptions meet emerging re-
alities. Journal of motor behavior, 42(6), 351–3. Available from
http://www.ncbi.nlm.nih.gov/pubmed/21278858
Wolpaw, J. R., Editor, G., Birbaumer, N., Heetderks, W. J., Mcfarland, D. J., Peck-
ham, P. H., et al. (2000). Brain – Computer Interface Technology : A Review
of the First International Meeting. IEEE Trans. Rehabil., 8(2), 164–173.
Wolpaw, J. R., & Mcfarland, D. J. (1994). Multichannel EEG-based brain-computer
communication. Electroencephalography and clinical Neurophysiolog, 90, 444–
449.
Zhang, L., He, W., Miao, X., & Yang, J. (2005, January). Dynamic EEG Analy-
sis via the Variability of Band Relative Intensity Ratio: A Time-Frequency
Method. Conference proceedings : ... Annual International Conference of
the IEEE Engineering in Medicine and Biology Society. IEEE Engineering in
Medicine and Biology Society. Conference, 3(1), 2664–7. Available from
http://www.ncbi.nlm.nih.gov/pubmed/17282787
Zhang, Y., Chen, Y., Bressler, S. L., & Ding, M. (2009). Response preparation and
inhibition: The role of the cortical sensorimotor beta rhythm. Neuroscience,
156:1, 238–246.
58