Universal Bluetooth EEG (/ECG/EMG)
The interest in biofeedback, in particular in the DIY community, is widespread. The idea of playing with one's own brainwaves under household conditions is very appealing to almost anyone. One motivation might be to learn something about human physiology. As a student in med school this is of particular interest, since the EEG is barely covered in the curriculum. If you get the setup stable enough, which I'm sure you can accomplish, you get to analyze your own quality of sleep if you have a little background in medicine. Another very interesting application is the creation of a brain computer interface that you create from scratch, which should also make a homebrew EEG interesting to engineers and computer scientists.
As a tinkerer, you want to look for the most affordable, yet result-promising way to get an EEG up and running. A well-known project is OpenEEG (http://openeeg.sourceforge.net/doc/), which is a modular setup using lots of discrete through-hole components. When considering building an EEG setup I was sort of scared off by the complexity and cost of that project. By now several brain computer interface devices such as the NeuroSky MindWave are available on the market. Some of them don't let you access the raw EEG data though, whereas some might be hackable such as the Zeo platform (http://zeorawdata.sourceforge.net/index.html).
Anyways, I had some great experience with the Olimex ECG/EMG shield (see the pages on the arduino ECG monitors) and I wondered why it shouldn't be capable of amplifying what is going on electrically on the surface of your scalp. When we are dealing with ECG and EMG, we are dealing with amplitudes in the 1mV range, whereas EEG amplitude range around 0.1mV, so physically we should be able to get what we want.
Inevitably, the electrode question has to come up now. Interestingly I got my first results by simply placing pennies on my forehead in a playful mood and wiring the whole thing up to the shield. It feels awesome when you suddenly get to record your first EEG with household items! It definitely was a huge step for me (while probably not being too huge of a step for mankind). If you sweat a little under the coins, it improves conductivity. I didn't even have to apply any conducting gel whatsoever. The setup I finally came up with after some sewing and attaching punch-through steel buttons to an elastic band is this one (the cable is a simple shielded stereo cable, the shielding goes to the common mode rejection electrode): it is only for recording on one hemisphere where one "electrode" is on the lateral forehead, one on the temple of the same side and one on the mastoid of the same side (the hard bony structure behind your ear). What do those places have in common? Yep. No hair involved. Note: those steel buttons have actually coins soldered to them!. Make sure you do that first before you atach them to the elastic tissue.
Maybe we should talk about the digital part now. Well, as an Android device user I discovered the Amarino project some day, which is a very versatile Bluetooth communication protocol between a microcontroller (guess which one ;) ) and the Android OS. Those phones have a lot of processing power and great displays these days, so why not establish a connectivity to Android? One very popular example application of the Amarino API is the Sensor Graph project. You find more information as well as tutorials on how to set up the app and make it work with Arduino under the following link: http://www.amarino-toolkit.net/index.php/download.html. In order to install that App on your Android device you need to have the whole Android SDK installed within Eclipse, which serves you as a develpment environment. I will not go into detail on how to set it up in this documentation, but there should be plenty on info on the internet.
Back to topic: I modified the app for use as a receiver for electrophysiological signals and extended it by adding a wake lock (now the screen stays on all the time to enable constant monitoring), time scale divisons (1 sec/div) and a recording function. The link to the project files is at the very bottom at the page. If you hit the "recording" toggle button in the bottom left corner, the application will start recording to a file called "record.txt" in a directory called "Electrophysiology" in the storage of your phone (not the SD card!). Important: this directory has to be created before you try recording the first time, so go to your sdcard0 folder (not extsdcard) and create a folder called "Electrophysiology". There the record.txt will be stored. Note that the file will be extended each time you stop and start recording, so if you start a new record, delete the file. It will be created automatically next time you hit the toggle button. I know, this is pretty inefficient programming, but hey, it's working! ;)
Another important thing you have to do when using my app (this is also mentioned in the Sensor Graph tutorial) is to enter the address of the Bluetooth module you are using in the line private static final String DEVICE_ADDRESS = "00:12:09:20:05:68"; in SensorGraph.java. Once you are done setting up the app and building the device, getting phone and transmitter to talk is really easy, assuming that you did everything right. ust turn on the the device and then the app and you're done.
Ok, now let's get to the Arduino part. The version above is the first test version. It had a Bluetooth Mate Silver as a BT module and a Sparkfun 5V Step-Up regulator built-in besides an Arduino Uno and, of course, the EKG/EMG shield. I've written some code that doesn't require the Meet Android library, so it's pretty straight forward. It samples your brain waves (or whatever you attach it to) at 256Hz, which is done by simply executing the analogRead() function within a timer2 ISR. Then a packet is built that matches the Amarino communication protocol and we're pretty much done. The code is at the bottom of the page, where all the code is ;)
Version 2 was built entirely bearbones: the system uses a 3.3V step-up regulator to run from easily available AAA cells and a HC-05 BT-module, which I have written about already (Arduino/Microcontroller / OLED Terminal). A detailed Eagle schematic, as well as my first serious .brd file can be downloaded at the bottom of the page. I've decided to solder additional female headers to the shield and mount the digital and analog part "face to face". Extending to multiple channels is still possible. The electrodes used are medical grade ECG electrodes. You can simply stick them on your scalp on points that make sense. Those are a better choice if you want to record sleep EEG since a headband tends to get quite uncomfortable.
This project was ideal to learn to design a PCB in Eagle and have it being manufactured professionally. I contacted BILEX LP for that purpose and everything went as expected. I thought trying this will boost my DIY capabilities and it sure did. Here's the result:
Now, the components have to be soldered, but this should be a breeze on such a PCB.
Of course this device is quite universal. It can be extended to multiple channels by simply stacking more shields on top of each other and extending the code and of course it can also be used as an ECG and an EMG. You can easily connect to any PC by just using a dirt-cheap BT dongle. Wireless transmission makes the device safe to operate. No potentially deadly mains voltage that is only millimeters away from your electrodes! The evaluation or real time processing can be done with most data acquisition tools. In collaboration with a friend of mine we developed some MATLAB scripts that do different kinds of processing. Let's have a look at some results:
The below image is 60sec of EEG recorded with the headband and processed in MATLAB. After about 24sec you can see an artefact which is me, closing my eyes. After this event the spectrogram reveals a prominent red strip near the 12Hz frequency band, which is called the Berger Effect, named after the inventor of the EEG. If you close your eyes, the so-called Alpha rhythm (8-12Hz) becomes prominent. Nobody knows for sure what this is for, but some authors (Zschocke et al.) hypothesize that it might indicate the brain being in some kind of stand-by mode that prevents you from falling asleep immediately.
In the image above the EEG seems to be kind of compressed so you would not quite recognize it as such. Below we have a short excerpt, where you have a close-up. (The x scale shows the number of sample points). Until the middle you see some typical alpha waves which terminate as soon as I start flapping my eyelids and inducing some artefacts. The spectrogram confirms that the waves in the first half are in the alpha spectrum.
In this depiction you see approx. 120 seconds of recorded ECG from the Android App that underwent R peak detection and calculation of RR intervals. As you can see, the time between heartbeats varies.
I hope that this article gives you plenty of inspiration to start exploring the world of your brain waves, heart waves, muscle waves.....whatever.
Here is the archive with Arduino source code, Android project files, Eagle files and a MATLAB heart rate evaluation script: EEG.rar