Writing your own soft for a really cheap EEG hardware
(A signal shown here was taken while twisting electrodes in hands. This is not EEG =)
As a geek I’ve always dreamed of a day when my computer will really become extension of my mind – all boundaries like the need to use mouse, keyboard and other awkward interfaces to explain my idea to machine will be gone. When mind will fuse with technology, and obtain all if its computing power, logic accuracy, incredible amounts of memory… and many other good things we could only dream of.
Fortunately, advances in technology in last years show we’re quickly moving in this direction. If you watch news you know today it’s possible to control machines using only your mind. It’s done by using brain-computer interfaces.
Surely it’s more interesting to try brain-computer interfacing yourself then just to watch it in news. But here comes the roadblock: you need special hardware – an EEG device – to make the connection, and it’s not cheap. When I googled for EEG hardware, I found unfortunately prices start from 3000$ and go up to tens of thousands of bucks :(((
It’s possible to make hardware yourself – many good designs can be found on Internet, the most famous is OpenEEG project. Even if your knowledge of electronics is not very good, they have a discussion list where novices can get help. The cost of self-assembled device is about 3 hundred bucks.
Building EEG yourself is a good option, but I had doubts it would work well, especially after this discouraging comment by Anonymous Cowardon. So when somebody from OpenEEG discussion list told about KT88-1016 Digital EEG And Mapping System I couldn’t resist buying. A fully functional 16-channel EEG reading system only for $1200!! (for skeptics be sure it’s not an advertisement =)) Yes, Pendant EEG is cheaper, but it’s only 2-channel, not 16. And 2 channel is not enough for brain-computer interfaces. And KT88-1016 was intended for clinical usage – that means quality must be at good level.
Here is how does KT88-1016 look like:
After inserting electrodes to these pins and wearing headcap you will dissappear under the wires. The electrodes & cap are of old-design, I’m going to buy another, probably ElectroCap.
But another disappointment was quietly waiting inside the box. After buying I discovered that this device works only with its own proprietary software. And this soft is very old – probably written in late 90s, limited and may be useful only for doctors. No way to fed brain signals gathered by this device to for example BCI2000. So I needed to write my own software which could gather brain signals that KT88-1016 acquires & sends to the computer.
(Here I connected only 2 channels to hands)
Despite being an USB device, KT88-1016 represents itself in system as serial port. It makes the tasks easier. So let’s look on what data is sent to the device – i.e. software may be sending some control commands – and what comes from it. For doing this I used this nice tool - Serial Port Monitor. Choose port for monitoring, run KT88-1016 software and read EEG for a while.
This data was captured by Serial Port Monitor:
Looks like train of sequences starting from two signature bytes FF FF, after which 32 bytes of EEG data follows. It seems that each of 16 pairs of bytes in this data represents voltage value for one of 16 channels. Using this idea I immediately tried to plot sixth channel (C4 – A2), but resulting graph had nothing similar with any graph shown by KT software.
So I needed to look inside KT software to see what it is actually doing with these numbers. Fortunately, soft is written clearly so this is not very hard if you know assembly. Shortly, I used OllyDbg to find place in program where it does all graph-displaying stuff. For this, breakpoint was set on ReadFile function – it is called when program tries to read data from COM port. Set the breakpoint, run software through OllyDbg and read EEG, OllyDbg will show up highlighting the address where function was called. Write down all addresses (it will be called a couple of times). Then disassembly the program with IDA Pro and chek up what is going on by these addresses.
These things were found after analyzing assembly listing:
- Device is actually 12-bit, i.e only 12 bits out of 2 bytes contain EEG data
- Software performs band-pass filtering, i.e. it plots mean value of each of two consecutive voltage values
- It performs anti-floating (not yet figured out what is it, but could be kicked out to still get right graphs)
- Some other minor things
Here is source code for sample program shown in the beginning. It was written in C++ (Borland C++ Builder) and reads & displays signal from selected channel. Download source from Rapidshare It could be extended then to do more advanced things like analyzing EEGs to make brain-computer interfacing or neurofeedback (which I surely will do in future =))