Saturday, November 2, 2013

BrainBay - EEG Visualization Software

When I got started with EEG, I started with the OpenEEG project and the excellent information that they have available.  That led to me buying the SMT version of the OpenEEG hardware available from Olimex.  Once I got that hardware, it led me to downloading and using BrainBay, which is an open source software for receiving, processing, and visualizing biosignals, especially EEG signals.  While the interface feels a little quirky when you first start using it, it is surprisingly flexible and powerful.  I decided that I wanted to be able to inject data from our OpenBCI EEG system into BrainBay so that I could use its processing and display tools.

Screenshot from BrainBay's Website of One Person's Processing and Visualization Configuration.  The configurations are completely user defined, which is powerful...and confusing to a new person.

>>> Getting Data into BrainBay

By default, BrainBay can be configured to receive data streamed from a few different EEG systems.  It seems that most people probably use the OpenEEG hardware (such as the Olimex unit linked earlier).  The OpenEEG hardware communicates to the PC using a binary data format.  If I want to inject OpenBCI data into BrainBay, the easiest way is to make my OpenBCI system look like an OpenEEG system.  This means that I need to alter my Arduino software (which is what my OpenBCI is connected to) to output the EEG data in the same format as used by OpenEEG.  Easy!

Um, but what is the OpenEEG data transfer format?

Well, the core of the OpenEEG hardware is an AVR processor like the Arduino, so the embedded software running on the OpenEEG hardware should be intelligible to someone with experience in Arduino.  You could download the software, read it (if you were suitably skilled) and figure out the data format.  Given the number of AVR macros employed in that code, however, figuring out what's going on can be challenging for a lot of folks (including myself).

Alternatively, if you look in BrainBay's own Developer Manual and jump to Section 6, it discusses the data format in actual words.  Very nice.  I chose to target the "P2" data format.

You may notice that this format has a couple of limitations relative to the capabilities of OpenBCI.  First, this data format only allows for 6 EEG channels, whereas OpenBCI has 8 channels.  So, we'll lose two EEG channels, which is unfortunate but not horrible.  Second, note that this format only allows for 16-bit EEG values, whereas OpenBCI generates EEG data samples at 24-bit resolution.  So, I'll have to cut 8 bits of resolution, which means that I'll lose some dynamic range.  A 16-bit value still has a lot of dynamic range, so this will probably be OK.

(Super-technical aside:   I'll need to decide whether to truncate the lowest bits (and lose resolution at the lowest signal levels) or to cut the highest bits and lose the ability to handle large DC offsets.  I think that I'll split the difference and cut some from both the high and low sides of my dynamic range.  For the moment, I do this by dividing my 24-bit sample by 32 and cast from my 32-bit data type to a 16-bit data type.  The "divide by 32" step, in effect, drops 5 bits of resolution from the low end of my dynamic range, which means that the casting drops 3 bits of headroom on the high end of my dynamic range.)

>>> Configuring BrainBay for OpenBCI

So, after writing a small extension to my existing Arduino software for translating the OpenBCI data into this new format, I can successfully get my OpenBCI data into BrainBay.  Yay!  There are, however, a couple of small changes to the settings in BrainBay to get the most out of the OpenBCI data.  Specially, in the "EEG Block" used by BrainBay to get data from the EEG hardware, you'll need to alter the "Baud Rate"," Sampling Rate", and "Resolution".  With my current settings in the Arduino software (which might change in the future), here's how I configured the EEG input block in BrainBay:

To Use OpenBCI in BrainBay, select "Modular EEG P2" and then change the Baud Rate to 115200, change the Resolution to 1432 and (not shown) change the Sampling Rate to 250 Hz.
Baud Rate:  OpenEEG defaults to 56000 bps whereas I configured my OpenBCI Arduino software to run at 115200 bps.  If you don't change this value, BrainBay probably will not be able to receive the data from OpenBCI.

Sampling Rate:  OpenEEG runs at 256 Hz.  The sampling rate for OpenBCI has several different settings, but my Arduino software has it running at 250 Hz.  In BrainBay, you should change the value to 250 Hz so that BrainBay shows the graphs with the correct time and frequency scales.

Resolution:  OpenEEG samples have a resolution of 10-bits (ie 1024 counts).  Full-scale is 512 uV (ie, +/- 256 uV).  BrainBay always assumes that full scale is 512 uV and, in this window, it is asking how many counts correspond to 512 uV.  For OpenEEG, you enter 1024 because it spans 512 uV with its 10-bit (ie 1024 count) digitizer.  For OpenBCI, it's a little more complicated.  The correct value (for now) is to enter 1432.

(Second super-technical aside:  I get this value by finding OpenBCI's internal scale factor, which is (2^24) / (4.5 V / 24x Gain) = 89.5 counts / microVolt.  I then cut this down by by 32x bit-reduction divisor discussed earlier, which yields 2.796 counts / microVolt.  Finally, BrainBay expects "full scale" to be 512 uV, so to find out the number of "counts" it takes to represent this value, you take 512 uV * 2.796 counts / microVolt and get 1432 counts.  Viola!)

>>> Example: OpenBCI Data in BrainBay

Once you get all of those settings correct, you can setup a simple data flow in BrainBay and start watching your OpenBCI data flow smoothly and beautifully.  Below is an example of using OpenBCI for ECG (see here for the setup).  You can see the four blocks: (1) the EEG block to receive the data from OpenBCI via serial link, (2) a sharp 60 Hz notch filter to eliminate line noise, (3) a gentle bandpass filter to remove low frequency drift, and (4) an oscilloscope block to graph the data.  Look at how nice and clear my ECG is!

Using BrainBay to Receive Data from OpenBCI and Plot the Results in Real Time.  Awesome!
My favorite part of getting my data into BrainBay is that the filtering and graphs all run in real-time.  There are signal detection blocks that you can insert which can then be connected blocks that play sounds for feedback (or launch video or animation).  It's quite powerful.  Sure, I could write all of this in Matlab (which I did for Maker Faire NYC) or in Processing (which I just completed) or in Python (which we're still working on), but those programs are not as easy to reconfigure quickly as BrainBay.  BrainBay is very nice for that.

>>> Next Steps

The major downside of BrainBay is that it is only on Windows.  In the future, I'm going to look into interfacing OpenBCI with OpenViBE, which is another powerful open source software platform for receiving, processing, and visualizing EEG data.  It looks like it is also primarily aimed at Windows, but it is nice to have another choice in addition BrainBay and in addition to my own Matlab and Processing and Python interfaces.

Follow-Up: Here's a post where I describe how to make ECG measurements.
Follow-Up: Chris (the developer of BrainBay) wrote a BrainBay driver for OpenBCI.  Check it out!


  1. Hi Chip !

    this is Chris (developer of BrainBay) - and I finally found your blog :-)
    very nice work you did for the OpenBCI !! - and: cute hack to get BrainBay working with the device. I recently made some improvements and tweaks and though it might be nice to support the OpenBCI device natively.

    have a look at:
    I tried to figure out the data protocol from your AVR firmware. BrainBay now sends a 'b' to the COM port if an OpenBCI device is connected at the session is started - in hope to activate the binary data stream from the device ;-)

    I could not test anything in lack of the hardware - curious if it works or what bugs may appear :-)

    .. will be the "First-Time-Right"-design ?? ;-)

    1. Hey Chris, this is fantastic! It would be so great if there could be a native interface in BrainBay for OpenBCI. The part that I didn't like about my kludge described here is that I had to throw away a bunch of bits to fit within the 16-bit OpenEEG P2 format. I also didn't like throwing away two channels (OpenBCI has eight channels whereas OpenEEG P2 only supports six). If we could make BrainBay work with OpenBCI with all 8 channels at full bit depth (with the correct sample rate and scale factor, of course), it would be a party! I'll check out your github...

    2. okay great !
      please tell me if it works - maybe contact me via email (see brainbay site)

    3. Hey Chris, sorry for the delay...I've been stuck at home without an OpenBCI unit. Oh, the horrors! I'll be able to get a unit tomorrow, so hopefully I can give it a go over the weekend.

    4. I checked out Chris' new driver for OpenBCI in BrainBay. After ironing out a couple bugs, it works great! Check it out:

  2. Hi Chip,
    did you understand how to read the Olimex SMT on MatLab? In particulary I'm still having trouble to understand how to split channel's signals on MatLab...thank you for your attention and your work.

  3. The latest BrainBay 1.9 (Windows in VirtualBox on MacOs) doesn't seem to contain a dedicated Notch-Filter (anymore?). Trying to enter a BandStop-filter it crashes as soon as you enter a 2-digit frequency value (such as pressing the '5' when entering '51'.

  4. Hey everyone, do you think it might be possible to make Brainbay to work with a mobile Android device, so that Android receives the signal data via serial port and transfers it via bluetooth to the Desktop where Brainbay is running, is it possible?

    1. The latest version of OpenBCI is bluetooth enabled, so it can talk directly to the PC without going through the phone.

    2. Hi Chip, thanks a lot for your help. Can I have your email id please, I need to ask you some queries; hope that's fine with you.

  5. Is that OpenBCI V3 hardware and a new software io a v4 hardware?
    v3 uses an RFDuino compatible USB-stick as receiver.

  6. This comment has been removed by the author.

  7. Does someone know what type of video file is accepted on BrainBay. I've tryed to load .avi movies and it does not work.

    Thank you.


  8. Hey.
    Im Laeeq and trying to get ecg waveform using ads1299-evm board.
    Can you tell me the registers setting specially for config 3 register.