Community /

Loading OpenBCI datasets in EEGLAB

EEGLAB can be used for the analysis and visualization of EEG datasets recorded using OpenBCI hardware and software. EEGLAB can work with a variety of different file types, including those that are exported from the OpenBCI GUI, as we saw in the previous post.

EEG data can be stored ASCII files (often saved with the “.txt” extension). The OpenBCI Processing GUI saves data in text or comma separated value (csv) files, which are output into the “SavedData” directory within the OpenBCI_Processing directory.

Import the CSV file as a MATLAB matrix using the following command:

> eeg_data = csvread(‘…/directory/yourfile.txt’, row offset, column offset)

For example:

> eeg_data = csvread(‘…/OpenBCI-RAW-__.txt’, 5, 1);

Row offset is the number of rows in your txt file before the start of your EEG data (in the current version of the OpenBCI GUI, there are 5 commented lines before the start of the data, so the offset should be 5 to make the matrix start on line 6). Column offset skips the sample number column.

If you are using the OpenBCI V3 board with accelerometer data and aux data, you might want to remove the last three channels of your data before you send it into EEGLAB in order to only work with the EEG data. To remove the last three columns, enter the command:

> eeg_data  =  eeg_data (:,1:end-3);

In the case of OpenBCI Processing’s “.txt” data, the matrix is imported in the opposite orientation than what EEGLAB needs, so to transpose the data before importing in EEGLAB, perform a simple matrix transposition:

> eeg_data = eeg_data’;

 

1.5 - eegdata.png
Figure 1. You must save the EEG data accordingly to the Loading Data in EEGLAB post.

 

If EEGLAB isn’t already running, enter “eeglab” into the Matlab command line to start the program.

1 - eeglab.png
Figure 2. To start working with EEGLAB toolbox type “eeglab” in the MATLAB command window and press enter. 

Import your matrix into EEGLAB using the EEGLAB GUI: File -> Import Data -> Using EEGLAB functions and plugins -> From ASCII/float file or Matlab array.

 

app3
Figure 3. Importing data to EEGLAB. From EEGLAB.

In the pop-up window that appears, enter information about the data set. Select “Matlab variable”, and enter the name of the variable where your matrix is stored. Enter the Data Sampling rate (it should be commented in at the top of the txt file – usually 250 Hz by default in the OpenBCI GUI). The other fields can be left at default, and EEGLAB will automatically fill in the information from the data set.

2 - upload eegdata and ch loc.png
Figure 4. Select the EEG data and Channel Locations files.

Channel locations are useful for plotting EEG scalp maps in 2-D or 3-D format. OpenBCI uses the standard 10-20 format for the 8 and 16 channel models, which can be found within these .ced files: 8 channel and 16 channel. You can then import channel data by click “Browse” next to “Channel location file or info” and locating the OpenBCI .ced file you downloaded.

 

1.5 - chlocs.png
Figure 5. My 8 Channel locations file in .ced format.

 

If you need to edit the channel locations, I would suggest you editing either “eeglab_chan32.locs” located in “\EEGLAB\sample_data” or “Standard-10-20-Cap25.ced” located in “\EEGLAB\sample_locs”. You should use any text editors such as WordPad, NotePad++, Atom… Whichever works better for you and edit the files.

The data is now imported into EEGLAB, and you can perform a variety of data analysis on the data. See (Performing EEG data analysis and visualization) for next steps on working with your data.

Leave a Reply