EEGLAB / MATLAB / Octave : read OpenBCI CSV files

edited February 2015 in Software
All right,

So I have collected some initial data with the openBCI GUI and can see some .txt files in the "saved data" folder. I see it comprises of electrode voltage samples over time but am not certain of the exact structure of the file. Anyway, I want to import this data into EEGLAB for further processing. Any ideas how that can be done? or is there some other tool for processing openBCI recordings. Any input is appreciated

Comments

  • wjcroftwjcroft Mount Shasta, CA
    edited February 2015
    [see best answer on a later post below, using the MATLAB csvread() function.]

    Yasir,

    A common interchange format for biosignal data is EDF. Many EEG signal processing programs support this. There are some converter programs that can import CSV and export EDF. EEGLAB can read EDF.

    http://www.teuniz.net/edfbrowser/EDFbrowser manual.html#ASCII_to_EDF_converter

    EDF assumes channel samples are 16 bits. Since many new amps use 24 bit channels, a revised standard was created by Biosemi, called BDF.

    http://www.biosemi.com/faq/file_format.htm

    More tools and format specs,

    http://www.edfplus.info/downloads/index.html

    The EDFBrowser is a general multichannel biosignal display program. 

    William

  • brainbrain Canada
    edited February 2015
    @yasir

    Another option: Run your data through this Python script to convert OpenBCI .txt files to OpenViBE-compatible CSV, and then use OpenViBE to convert to EDF (it has an EDF writer).
  • wjcroftwjcroft Mount Shasta, CA
    @brain,

    I took a look at that link you posted. The OpenBCI output file csv values ARE microvolts, not "raw 24 bit values" as the author Adam maintains. The sample values do have the DC offset, so that is usually removed with a high pass filter, e.g. at .5 hz.

    http://openbci.com/forum/index.php?p=/discussion/201/large-millivolt-data-values-dc-offset

    Will Adam revise his script?

    Regards,

    William
  • thanks guys, I will go through with the mentioned options and see how it goes and post some feedback
  • wjcroftwjcroft Mount Shasta, CA
    edited February 2015
    Yasir, hi again.

    I'm not a MATLAB / EEGLAB user so forgive my ignorance. Reading in CSV files is actually supported in the base MATLAB, which EEGLAB is built upon. See,


    So to skip over the first 4 comment lines in the OpenBCI CSV, and ignore the first column (packet counter), you would use a command like:

    M = csvread('.../OpenBCI-RAW-__.txt', 4, 1)

    It's that simple. Once you have this matrix read in, you can then use other functions to process the individual channels (columns). For example here's tutorial on how to import a MATLAB array into EEGLAB,


    Sorry to take you on the "wild goose chase".  :-)  Remember you will need to filter off the DC offset with either a highpass filter at say .5, or a bandpass say from .5 to 40 hz.

    William
  • wjcroftwjcroft Mount Shasta, CA
    edited February 2015
    The EEGLAB developers (Swartz Center for Computational Neuroscience) say that if you do not have access to MATLAB, the open source Octave program may produce 'similar' results,




    There is also an open source GPUmat, that produces code which runs inside Nvidia CUDA graphics cards, utilizing their GPUs.



  • edited February 2015
    @wjcroft
    You're right. Thanks for catching that embarrassing error in my CSV conversion script. I've updated the post and the script accordingly, with credit to you in a note at the bottom of the post. (I've linked to your forum user. Let me know if there's another name or URL I should use, or if you would prefer not to be mentioned.)

    The original version of that script had no conversion factor. Reading the OpenBCI data format documentation (http://docs.openbci.com/software/02-OpenBCI_Streaming_Data_Format), I mistakenly assumed that it applied to the saved CSV data. This was pretty silly in retrospect, because the CSV includes decimal values (among other reasons).

    Thanks,
    Adam 
  • Hey Guys,

    I was able to edit a test file and simply reduce it to a CSV with electrode output values listed in columns and then opened it in EEGLAB. Though when I plot the signal (2 electrode readings) I simply see two out out of phase sine waves which isnt what i expected. I removed the DC offset of course, and then tried to notch the 50 Hz frequency to get rid of power line interferences as I originally thought the interference is too strong to see the real signal. This didn't help however. Now i can see I never handled the uV value conversions so I will try your script first thing.

    Btw, If I use the notch filter in the openBCI GUI while recording the data stream, does it store filtered values or the notch is simply for the display and I get original values in the file. Also maybe I should start another thread for this, but I dont see a record of the reference electrode being stored. I think that is needed if I want to reference all the data. Any thoughts on how that can be done?

    Thank you and apologies if I am asking too many basic things. I am still learning the ropes for EEG processing.
  • wjcroftwjcroft Mount Shasta, CA
    Yasir,

    > I was able to edit a test file and simply reduce it to a CSV with electrode output values listed in columns

    No need to manually edit the file, use the csvread(__, 4, 1) function mentioned above to skip over the 4 comment lines and 1st column.

    > Now i can see I never handled the uV value conversions

    Please reread the posts above, that was a misunderstanding. The values in the CSV file are already in uV.

    > does it store filtered values or the notch is simply for the display and I get original values in the file.

    The values in the file are raw values, unfiltered by notch or any other processing. This is stated in the comments in the CSV file.

    > I dont see a record of the reference electrode being stored.

    The SRB lead acts as a common reference for both your active electrode channels. So those channels record the differential signal between that lead and SRB. Thus no 'reference' value is recorded in the file.

    If you use a bandpass filter, say from .5 hz to 40 hz you will eliminate both the DC offset and any remaining mains noise.

    William
  • Thanks William,

    You have removed a lot of confusions I had about the data. Now I can get some work done. I get most of what you have explained, but I still see a problem with the reference electrode issue. If I cannot have a record of the reference electrode itself, I cannot say "unreference" my data or rereference it. What I think is happening  in my case is that when eeglab reads the data it computes an average reference automatically, the alternative is to provide a reference channel/channels, which I cannot do here. Maybe I should just switch tools.

    I was using cleanline for removing DC offset but I will go ahead and use a bandbpass simply as you recommended.


  • wjcroftwjcroft Mount Shasta, CA
    edited February 2015
    Yasir, hi again.

    All EEG amps are differential amplifiers, they can only measure the difference between two leads, not the individual leads. The differential nature is a requirement for noise cancellation.


    The alternative to using the SRB lead, is that you can configure the ADS1299 to use the individual IN*P and IN*N leads as pairs, instead of combining leads as the SRB pin does. This is sometimes done in certain montages. See the paragraphs describing montages at the end of this section,


    In particular, the Referential Montage section. Also see some of these links,


    William

  • Hi William,

    Thanks for the info. I am aware why we need a reference signal to record data and use of polar reference methods for recording EEG activity. Your reply helps decide what i need to do though. I should simply decide on my reference first and then record data so that there is no need to rereference the data. Thanks for all the help. I will update you guys how my experiment goes.

    Yasir
  • You can also re-reference the data after the fact...

    If you used an earlobe for reference during recording, and if you instead want Cz as a reference, you simply subtract the signal recorded from Cz from the signal recorded from the other electrodes.  Any effect of the earlobe signal is canceled out by this process.  It's as easy as that.

    Chip
  • Hi CHip,

    Oo perfect. I think I got it a bit wrong. I was thinking one needs some sense of the original reference electrode signal to add it back and then subtract the new reference. Your info makes sense. Thank you all for clerifying the misconceptions I had.

    Regards,
    Yasir
  • edited September 2016
    Does anyone know the physical maximum/physical minimum of the ADS1299?

    I'm almost done with a bdf writer for the openbci gui, you can checkout the code here:


    Which will be merged with master as soon as it's working well. The biggest problem is the EEG data does not appear to be scaling correctly.

    The numbers I'm using are:
    digital maximum: 8388607
    digital minimum: -8388608
    physical maximum: 187500
    physical minimum: -187500

    These units are in "uV" which is specified by "physical dimension".

    I am trying to verify with EDFBrowser

    I have some example data here: https://dl.dropboxusercontent.com/u/27503614/OpenBCI-EDF-2016-09-27_12-34-57.edf and would love some feedback!

    Thanks!!
Sign In or Register to comment.