1. Charles Moyes (cwm55) and Mengxiang Jiang (mj294)
Cornell University ECE 4760 Final Project:
Brain-Computer Interface using Multi-Channel
Electroencephalography
Project Overview
The goal of the project is to build a multi-channel electroencephalography (EEG) Brain-Computer Inter-
face (BCI). At a high level, the project will record and collect EEG data from the user using electrodes
attached to the patient’s scalp. The data will then be processed by a machine learning algorithm such as
a feed-forward artificial neural network (ANN) which will attempt to classify the data. We plan on either
trying to discover which color the user is thinking of or allowing the user to control a mouse pointer using
their thoughts. Because of the nature of the machine learning algorithms we will be using, an initial training
period will be required where the user is prompted to “think of” or “imagine” colors and mouse movement
directions. The EEG data corresponding to the user’s thoughts will then be used to train the neural network
via the back-propagation method. From there, the user will be able to control the system using their mind:
Because we feel that this project is fairly ambitious, there will be several “checkpoints” or stopping
points, in case we run out of time or encounter difficulties. The first goal will be to collect EEG data from
the user using the microcontroller’s analog-to-digital (ADC) converter. The analog circuitry involved will
consist of a three-stage amplification circuit with an instrumentation amplifier, an operation amplifier, and
a filter. The filter will consist of a high-pass filter with a cut-off frequency very close to zero to remove DC
offsets from the signal, along with a low-pass filter with a cut-off frequency of around 60 Hz for anti-aliasing
and possibly a 60 Hz notch filter to remove AC power noise induced in the user’s body. We ordered low-cost
EEG electrodes from a Chinese medical supply company on eBay for around $20, but we may resort to
home-made electrodes constructed from metal guitar picks borrowed from a friend who is a musician and an
old baseball cap if the budget does not permit us to use the medical-grade electrodes. Another note is that
a so-called “right-leg driver” connected to the user’s right leg will be necessary to cancel out common-mode
noise from the user’s body. This driver will be connected to the instrumentation amplifier to take advantage
of its common-mode rejection functionality. The main challenge will be amplifying a signal from the user’s
scalp on the order of microvolts, while filtering out the vast sources of noise.
This data could then be presented on a graphical pixel LCD attached to the microcontroller, or it could
be transmitted to a computer over USB serial UART. However, for now we will be content with merely
collecting the EEG data from the user and sending it to MATLAB over UART. This will require some C
code to be written for the microcontroller that will read the ADC input, format the data in Modular EEG
packet format, and send it to the PC over the serial port. Once we have a working EEG (this is one “check-
point”), we would like to add as many channels (up to 16, ideally) as our budget permits. We have found
1
2. an instrumentation amplifier and Besselworth filter IC from Maxim IC and cheap op amps that we will use
for this project. A possible time-permitting feature is the addition of a Bluetooth system-on-chip wireless
transceiver (TI has one that we could sample). This would allow the user to control their smartphone or
Bluetooth-enabled laptop using the BCI, but it would also impact our budget significantly.
The next checkpoint would be processing the collected data. We have had significant coursework in
artificial intelligence (AI) and have been studying papers on diagnosing sleep apnea and processing EEG
data in the context of brain-computer interfaces throughout the semester. We cannot guarantee good results
with the latter since we have not done anything like it before, so if we are unable to obtain good results,
then we will merely determine the patient’s level of emotional arousal based on the EEG waveforms using
their frequency spectra. An example follows:
However, we would definitely like to take time to experiment, namely with ANN’s so that we can attempt
to classify the user’s thoughts based on their brainwaves. Another simpler possibility would be detecting
EEG arousals in users that have sleep apnea. This is fairly simple to do given that one has a real-time EEG
data source, and the details have been outlined in several IEEE papers. The goal would be to have a user
think of a color (e.g. red, blue, or green) and then have the ANN classify which color the user is thinking of
from the received EEG data. Yet another possibility is having them thinking of cardinal movement directions
and then using the EEG data to move the mouse pointer. We feel that this is significantly more advanced,
however, than the color-detection process. At this point, we would be very satisfied with our project and we
would be more than happy to call it complete.
Relevant Standards
We will follow the Modular EEG serial packet standard for transmitting EEG data over UART. Moreover,
serial communications will follow the RS232/USB standards. Another consideration is the IEC601 standard.
IEC601 is a medical safety standard for medical devices that ensures that they are safe for patient use.
Unfortunately, testing for IEC601 compliance is very much out-of-budget. Nevertheless, we discuss the
many safety considerations that we will absolutely adhere by in the Societal Impact of Project section
of this write-up. If we opt to use Bluetooth as a wireless communication interface for this project, we will
use the Texas Instruments CC2560 single-chip Bluetooth IC, which complies with FCC standards.
2
3. Tentative Parts List
A tentative parts list follows:
For Each Analog EEG Channel:
Part Cost
MAX4194 - instrumentation amplifier IC SAMPLE
MAX7401 - 8th order Bessel filter IC SAMPLE
AD8605 - op amp IC SAMPLE
TL062CP - op amp IC 2*$0.26/channel (Digikey)
Filter capacitors and resistors LAB/CHEAP
2K Potentiometer LAB/CHEAP
4x NPN and PNP transistors LAB/CHEAP
EEG electrodes:
Part Cost
CONTEC ten pcs silver plated electrodes (budget-permitting) $20 (eBay)
OR OR
Metal Guitar Picks and Headband ALREADY OWN
RS232 isolation:
Part Cost
6N137 optoisolator (or equivalent) 2*$1.55 (1 if only using TX) (Digikey)
2x NPN transistors LAB/CHEAP
Unavoidable Lab Costs Incurred:
Part Cost
White Board OR Solder Board (Time-Permitting) $6 OR $2.50
4x AA Batteries ALREADY OWN
4 AA Battery Holder $1.33 (Digikey)
Mega644 Microcontroller $8
SIP Header Sockets/DIP sockets To Be Determined (TBD)
AT Mega 644 Target Board LAB
Extra features:
Part Cost
Graphical LCD (budget-permitting) $15 (SparkFun)
CC2560 - TI Single-Chip Bluetooth SAMPLE (time-permitting)
Societal Impact of Project/Safety Features
Because this is a device attached to a patient’s brain, safety is our utmost priority. The microcontroller
will only be powered by four 1.5V AA batteries, rather than through an AC power supply connected to
mains. Moreover, serial communication to a PC over USB will be isolated from the USB using optocouplers,
which we will test extensively to ensure that both ground loops are separated. Only laptops running off of
battery power supplies (no AC adapters connected) will ever be connected to the microcontroller over USB.
As a corollary, the microcontroller will never be connected to a user’s head while the programmer cable is
connected to a PC. Lastly, the EEG circuitry itself will have transistors connected directly to the electrodes
(in between the electrodes and the analog circuitry) to act as a user current/ESD protection mechanism.
We promise that 120 VAC power will never be connected to this project directly or indirectly. As a result,
3
4. users will never be allowed to touch any other electrical devices while wearing the EEG helmet. We will take
safety very seriously throughout the development of the project.
This project will have great societal impact because it is designed for users with special needs. Using
brain-computer interfaces, users with special needs will be able to interact in computers in ways that were
not previously possible. Patients with sleep apnea will be able to collect and analyze their own EEG data
while asleep without having to participate in expensive overnight sleep studies at hospitals. They will be
able to see their data; rather than being shielded from it by a medical doctor. Because our budget is less
than $75, they will be able to do this at a very low cost. We are strongly considering releasing our schematics
and source code on the Internet free-of-charge under the Creative Commons license in order to give back to
society.
Project Block Diagram
An overall block diagram of the project follows:
EEG High-Pass High-Pass
Electrodes Filter Filter ADC
ESD Discharge
Instrumentation Operational Besselworth AT Mega 644
Protection
Amplifier Amplifier Filter Microcontroller
Circuit
User’s
Head
UART
EEG
Electrodes Right-Leg
Driver
ELECTRICALLY ISOLATED LINE:
Real-Time FFT
On-Screen with
Battery-Powered FTDI
Classification Artificial Neural
Laptop PC USB RS232
Output to User Network
in MATLAB
Tentative Schematics
NOTE: These tentative schematics are highly subject to change throughout the development of our project!
Analog Amplification Circuit
4
5. Opto-isolated UART Serial
As mandated by our safety procedures, we will electrically isolate the UART from the USB. The isolated
UART will use high-bandwidth 6N137 opto-couplers from Fairchild Semiconductor as follows:
It will interface with the UART Pin D.0 and Pin D.1 from the microcontroller. Note that we may have
to add NPN transistors to invert the output as specified in the 6N137 datasheet if we cannot figure out a
way to invert the UART output in software. The TX and RX lines will then connect to the FT232RL FTDI
chip, which will be connected to USB GND and USB 5V for power. Unlike Open EEG’s Modular EEG project,
we opted to use 6N137 optoisolators with USB rather than 6N139’s with RS232 using a MAX232 IC.
Code Overview
Sample code for reading the ADC values and transmitting them to MATLAB over the UART follows. This
code will be extended to support multiple ADC channels and output to a graphical LCD. Note that the
following code listing has not been tested yet and so we cannot guarantee code correctness:
1 # include < avr / io .h >
# include < avr / interrupt .h >
3 # include < avr / pgmspace .h >
# include < avr / eeprom .h >
5 # include < stdio .h >
# include < stdlib .h >
7 # include < string .h >
# include " lcd_lib . h "
9 # include < util / delay .h >
11 // UART file descriptor
// putchar and getchar are in uart . c
13 FILE uart_str = F D E V _ S E T U P _ S T R E A M ( uart_putchar , uart_getchar , _FDE V_SETUP_ RW ) ;
15 // ADC variables
volatile int Ain , AinLow ;
17 # define ADC_BITS 10
19 // ADC ISR
ISR ( ADC_vect )
5
6. 21 {
AinLow = ( int ) ADCL ;
23 Ain = ( int ) ADCH *256;
Ain = Ain + AinLow ;
25
fprintf ( stdout , " % d n r " , Ain ) ;
27
ADCSRA |= (1 < < ADSC ) ; // start another ADC conversion
29 }
31 void main ()
{
33 // init the A to D converter
// channel zero / left adj / EXTERNAL Aref
35 // !!! DO NOT CONNECT Aref jumper !!!!
// Need capacitor at AREF pin and AVCC set to VCC
37 ADMUX = (1 << REFS0 ) ;
39 // enable ADC and set prescaler to 1/128*16 MHz =125 ,000
// and clear interupt enable
41 // and start a conversion
ADCSRA = (1 < < ADEN ) | (1 < < ADIE ) + 7;
43
// sleep register
45 SMCR = (1 << SM0 ) ; // ADC sleep
47 // init the UART -- uart_init () is in uart . c
uart_init () ;
49 stdout = stdin = stderr = & uart_str ;
fprintf ( stdout , " Starting ADC demo ... n r " ) ;
51
sei () ; // start interrupts
53
// main loop
55 while (1)
{
57 sleep_cpu () ;
}
59 }
Listing 1: C Source Code Listing
References
[1] Openeeg project. http://http://openeeg.sourceforge.net/, 2009.
[2] Homebrew do-it-yourself eeg, ekg, and emg. http://sites.google.com/site/chipstein/home-page, 2011.
[3] F Lotte. A review of classication algorithms for eeg-based braincomputer interfaces. Journal of Neural
Engineering, 2007.
[4] G. Matsuoka, T. Sugi, F. Kawana, and M. Nakamura. Automatic detection of apnea and eeg arousals
for sleep apnea syndrome. In ICCAS-SICE, 2009, pages 4651 –4654, aug. 2009.
[5] Hazrati MKh and Efranian A. An online eeg-based brain-computer interface for controlling hand grasp
using an adaptive probabilistic neural network. PubMed, 2010.
[6] Jorge Baztarrica Ochoa. EEG Signal Classification for Brain Computer Interface Applications. PhD
thesis, Ecole Polytechnique Federale de Lausanne, 2002.
[7] Olson. Eeg page. http://www.pkfamily.com/users/solson/eeg/eeg.html, 2007.
[8] Kouhyar Tavakolian, Faratash Vasefi, Kaveh Naziripour, and Siamak Rezaei. Mental task classifica-
tion for brain computer interface applications. In First Canadian Student Conference on Biomedical
Programming.
6