Get your data ready
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.
Events File
If you are working with Motor Imagery, Event Related Cortical Potentials (ERPs) or you just interested in the data followed by a specific moment, you need to upload Events Information in a “.txt” file.
Since I am working with Motor Imagery and Motor Execution and I am using OpenBCI axelerometer data to save my events, I wrote an script that finds all the events that I am interested in.
% Trials Events RF_Re = find(Trials == 1); % Move Right Finger LF_Re = find(Trials == 2); % Move Left Finger RF_Im = find(Trials == 3); % Imagine Moving Right Finger LF_Im = find(Trials == 4); % Imagine Moving Left Finger Events_row = [RF_Re; LF_Re; RF_Im; LF_Im]; % List of events (based on counts) E = sort(Events_row); % List of events (based on counts) sorted % Two External Buttons RightButton = find(Right == 25120); % RightButton is pressed Events_RB = RightButton*4-4; % Translate the row to time for RB_Char = {'RightButton'}; % Create 'Right Button' column RB = repmat (RB_Char, length(Events_RB),1); end R = table(Events_RB,RB); % Create a table with Right Button events LeftButton = find(Left == 25120); % LeftButton is pressed Events_LB = LeftButton*4-4; % Translate the row to time for LB_Char = {'LeftButton'}; % Create 'Left Button' column LB = repmat (LB_Char, length(Events_LB),1); end L = table(Events_LB,LB); % Create a table with Left Button events % OBSERVATION: Some events are not saved. There is a difference of 2506ms % between two different type of events (RF_Re and LF_Re, for example). % This means that between two values of the same event there is difference % of 10000ms. Currently, you must add this new values manually. MoveRF = RF_Re(1,:); % Find 1st Move RF Event MoveLF = LF_Re(1,:); % Find 1st Move LF Event ImagineRF = RF_Im(1,:); % Find 1st Imagine RF Event ImagineLF = LF_Im(1,:); % Find 1st Imagine RF Event Move_RF = (MoveRF:10000:(MoveRF+100000-1000))'; % Create Move RF Event Variable Move_LF = (MoveLF:10000:(MoveLF+100000-1000))'; % Create Move LF Event Variable Imagine_RF = (ImagineRF:10000:(ImagineRF+100000-1000))'; % Create Imagine RF Event Variable Imagine_LF = (ImagineLF:10000:(ImagineLF+100000-1000))'; % Create Imagine LF Event Variable % Conversion of variables (From counts to time) Events_RFRe = Move_RF*4-4; % Translate MoveRF counts into time Events_LFRe = Move_LF*4-4; % Translate MoveLF counts into time Events_RFIm = Imagine_RF*4-4; % Translate ImagineRF counts into time Events_LFIm = Imagine_LF*4-4; % Translate ImagineLF counts into time Events = [Events_RFRe; Events_LFRe; Events_RFIm; Events_LFIm]; % List of events (based on time) Events_Time = sort(Events); % Sort of the 2nd List of Events
Also, to make my life easier, I wrote a legit script to save the events accordingly to EEGLAB requirements. , where all the events are label and sort in time.
% EEGLAB Event file (.xls) % Latency (1st Column) Latency = sort(Events); % Sort of 1st Events List (EEGLAB variable) % Type (2nd Column) for Cues = {'MoveRF';'MoveLF'; 'ImagineRF';'ImagineLF'}; % Repeat matix 10 times (10 trials) in column 1 Type = repmat(Cues, 10, 1); end % Duration (3rd Column) for Sec = 4; Duration = repmat(Sec,40,1); end % General Variable EEGLAB_Events = table(Latency, Type, Duration); % Save EEGLAB_Events.xlsx in Excel File (Ready to upload in EEGLAB) filename = 'EEGLAB_Events.xlsx'; writetable(EEGLAB_Events,filename,'Sheet',1,'Range','A1');
Thus, the result is a “.csv” file distributed in three different columns:
- Latency column has the specific times event happend sorted by time.
- Type column distinguish among the different types of events.
- Duration column shows the length of the event.

Plot your data into EEGLAB using the EEGLAB GUI: Plot -> Channel data (scroll). By default, EEGLAB has a 5 seconds window length (x axis). If you want to change it, you must select Settings -> time range to display in the figure window and type the new window length (s).

Besides, you can also change the scale of the plot by playing a little bit with the “+” and “-“in the bottom of the plot. I would suggest a scale of 50 or 100. Thus, you will have better perspective and visualization of EEG data. This should be the result:
If you wanna go one step further, you can import events into your data by using the EEGLAB GUI: File -> Import event info -> From Matlab array or ASCII file. Make sure to write in Input field “latency type duration”, and the following parameters showed in Figure 8.

At this point, you can plot EEG data with the events marked in different colours by following the same steps as earlier when we plot only EEG data.

There is also the opportunity to reject continous EEG data so as to “clean” your data by selecting with the cursor the length of the data that you want to remove from the signal. Although I will explain in another post how to do it significantly, feel free to play with it!

References
- EEGLAB Tutorial: http://sccn.ucsd.edu/wiki/EEGLAB_TUTORIAL_OUTLINE
- EEGLAB Wiki: http://sccn.ucsd.edu/wiki/EEGLAB