OpenBCI to EDF

Introduction

OpenBCI is an open source brain-computer interface platform used to record electrical activity produced by the brain (EEG), the muscles (EMG) or the heart (EKG), among others. When using the OpenBCI platform one might be interested in exporting the results to EDF(+). Motivation includes easy sharing of the results with the community, using an open standard format, or the possibility to use any of the many existing tools to, for example, visualize the results, or to apply additional signal processing to the data. Check more about EDF(+) format at www.edfplus.info.

On this page a Matlab/Octave script is offered to carry out the conversion from the OpenBCI format (as resulted from logging the results to a SD card) to EDF. A mini-tutorial is also available on how to use the code and visualize the resulting signal data in Polyman.

Disclaimer

The following software is offered "as is" and it might containg errors. I cannot and do not accept any liability for damages related to the use of this sofware. Use it at your own risk.

User License

The software is freely distributed under the terms of the GNU GPL v3 license.

Download

The code can be downloaded from GitHub here

HOW-TO use the code

  1. After downloading, uncompress the zip file and you will find a set of Matlab/Octave M-files. You need to run the file named main_OpenBCI2EDF.m
  2. You can open the file in Matlab or on any text editor. Depending on the particularities of your recording, some parameters might need to be adjusted. For example you might need to specify a different sampling rate for your signals, or you might like to modify the default filtering settings to pre-process your signals:

Specifically, to know if you need to skip some lines from your OpenBCI export, or to determine the number of channels, it is recommended to use some specialized commnad such as more (Windows) or cat (Unix/Linux), or something similar. Notice opening the OpenBCI export file directly on a text editor might not be the best idea as this file might contain large amounts of data (thus you might need to be very patient):

In the example above, at least the first 3 lines of the file need to be skipped since they contain only logging information and different metadata, but the actual electrophysiological traces start at line 4. Notices though, for this example the first sample -first comma separated line containing all zeros) is zero for all the 8 channels. In this case, therefore we would like to set the skipFirstLines parameter to 3 or 4. More information about the interpretation of the OpenBCI export data format can be found here.

3. Then run the script, which will ask you to fill-in some data in order to complete the neccessary EDF header information:

4. Well, that's it!

You will end-up with to EDF files in the same directory you have run the script: one containing the raw signals (without any additional filtering), and one containing the same files after applying some default signal pre-processing (Notch and High-pass filters). You can now open the files on any EDF(+) compatible application. For example you can download the Polyman software from the www.edfplus.info/downloads/ website.:

Notice that in the image above it can be seen that, in this case, the signals still contain some artifact from the mains interference (see peak around 50 Hz in the frequency analysis plot). Using Polyman this situation can be very easily solved by applying some additional Notch filtering using 50 Hz as the central frequency. In the next image you see the result and how the artifact is now removed:

Enjoy!

PS: And remember! with Polyman you can always check the consistency of any EDF(+) file using the built-in EDF compatibility checker utility. Outputs from this conversion script should always result in good EDF files (and otherwise you can let me know and I will do my best to improve the code), however make always sure your file is really EDF(+) compliant, specially if you are using files from other 3rd party tools, before proceeding further with your data.