EEGLAB Tutorial
What is EEGLAB?
EEGLAB is an interactive Matlab toolbox for processing continuous and event-related EEG, MEG and other electrophysiological data using independent component analysis (ICA), time/frequency analysis, and other methods including artifact rejection. First developed on Matlab 6.1 under Linux, EEGLAB runs on Matlab versions 6 (R13) and 7 (R14) under Linux or Unix, Windows, and Mac OS (Matlab v6 or current v7 recommended).
Why EEGLAB?
EEGLAB provides an interactive graphic user interface (gui) allowing users to flexibly and interactively process their high-density EEG and other dynamic brain data using independent component analysis (ICA) and/or time/frequency analysis (TFA), as well as standard averaging methods. EEGLAB also incorporates extensive tutorial and help windows, plus a command history function that eases users' transition from gui-based data exploration to building and running batch or custom data analysis scripts. EEGLAB offers a wealth of methods for visualizing and modeling event-related brain dynamics. For experienced Matlab users, EEGLAB offers a structured programming environment for storing, accessing, measuring, manipulating and visualizing event-related EEG, MEG, or other electrophysiological data. For creative research programmers and methods developers, EEGLAB offers an extensible, open-source platform through which they can share new methods with the world research community by contributing EEGLAB 'plug-in' functions that appear automatically in the EEGLAB menu. For example, EEGLAB is also being used for analysis of MEG data in several laboratories; EEGLAB plug-in functions might be created and released to perform specialized import/export, plotting and inverse source modeling for MEG data.
Tutorial Outline
This tutorial will demonstrate (hands-on) how to use EEGLAB to interactively preprocess, analyze, and visualize the dynamics of event-related EEG, MEG, or other electrophysiological data by operating on the tutorial EEG dataset "eeglab_data.set" which you may download here (4Mb). With this dataset, you should be able to reproduce the sample actions discussed in the tutorial and get the same (or equivalent) results as shown in the many results figures. For an overview outline of the whole tutorial, click here.
EEGLAB Overview
The EEGLAB graphic user interface (gui). The EEGLAB gui is designed to allow non-experienced Matlab users to apply advanced signal processing techniques to their data. However, more experienced users can also use the gui to save time in writing custom and/or batch analysis scripts in Matlab by incorporating menu shortcuts and EEGLAB history functions.
The EEGLAB menu. Text files containing event and epoch information can be imported via the EEGLAB menu. The user can also use the menu to import event and epoch information in any of several file formats (Presentation, Neuroscan, ASCII text file), or can read event marker information from the binary EEG data file (as in, e.g., EGI, Neuroscan, and Snapmaster data formats). The menu then allows users to review, edit or transform the event and epoch information. Event information can be used to extract data epochs from continuous EEG data, select epochs from EEG data epochs, or to sort data trials to create ERP-image plots (Jung et al., 1999; Makeig et al., 1999). EEGLAB also provides functions to compute and visualize epoch and event statistics.
Data structures and events. EEGLAB uses a single structure (EEG) to store data, acquisition parameters, events, channel locations, and epoch information as an EEGLAB dataset. This structure can also be accessed directly from the Matlab command line. The EEG structure contains two key sub-structures: EEG.chanlocs, holding channel locations, and EEG.event storing dataset event information. In EEGLAB v5.0 (March, 2006), a new superordinate structure, the STUDY has been introduced to allow automated processing of a group of EEG datasets. The first such facility introduced is a set of study functions to perform and evaluate clustering of similar independent data components across subjects, conditions, and sessions.
Three levels of use. EEGLAB functions may be roughly divided into three layers designed to increase ease-of-use for different types of users:
I. Gui-based use. New Matlab users may choose to interact only with the main EEGLAB window menu, first to import data into EEGLAB (in any of several supported formats), and then to call any of a large number of available data processing and visualization functions by selecting main-window menu items organized under seven headings:
- File menu functions read/load and store/save datasets and studysets.
- Edit menu functions allow editing a dataset, changing its properties, reviewing and modifying its event and channel information structures.
- Tools menu functions extract epochs from continuous data (or sub-epochs from data epochs), perform frequency filtering, baseline removal, and ICA, and can assist the user in performing semi-automated artifact data rejection based on a variety of statistical methods applied to activity in the raw electrode channels or their independent components.
- Plot menu functions allow users to visualize the data in a variety of formats, via (horizontally and vertically) scrolling displays or as trial (ERP), power spectrum, event-related time/frequency averages, etc. A large number of visualization functions are dedicated to the display and review of properties of scalp data channels and underlying independent data components. The user can make use of standard Matlab capabilities to edit, print, and/or save the resulting plots in a variety of formats.
- Study menu entries show the current studyset and which of its constituent datasets are currently loaded.
- Datasets menu entries list loaded datasets, and allows the user to swtich back and forth among them.
- Help menu functions allow users to call up documentation on EEGLAB functions and data structures, including function lists and scrolling function help messages.
II. EEGLAB command history. Intermediate level users may first use the menu to perform a series of data loading, processing and visualization functions, and then may take advantage of the EEGLAB command history functions to easily produce batch scripts for processing similar data sets. Every EEGLAB menu item calls a Matlab function that may also be called from the Matlab command line. These interactive functions, called "pop" functions, work in two modes. Called without (or in some cases with few) arguments, an interactive data-entry window pops up to allow input of additional parameters. Called with additional arguments, "pop" functions simply call the eponymous data processing function, without creating a pop-up window. When a "pop" function is called by the user by selecting a menu item in the main EEGLAB window, the function is called without additional parameters, bringing up its gui pop-up window to allow the user to enter computation parameters. When the processing function is called by EEGLAB, its function call is added as a command string to the EEGLAB session history variable. By copying history commands to the Matlab command line or embedding them in Matlab text scripts, users can easily apply actions taken during a gui-based EEGLAB session to a different data set. A comprehensive help message for each of the "pop" functions allows users to adapt the commands to new types of data.
III. Custom EEGLAB scripting. More experienced Matlab users can take advantage of EEGLAB functions and dataset structures to perform computations directly on datasets using their own scripts that call EEGLAB and any other Matlab functions while referencing EEGLAB data structures. Most "pop_" functions describe above call signal processing functions. For example, the pop_erpimage() function calls signal processing and plotting function erpimage(). Since all the EEGLAB data processing functions are fully documented, they can be used directly. Experienced users should benefit from using all three modes of EEGLAB processing: gui-based, history-based, and autonomously scripted data analyses. Such users can take advantage of the data structure (EEG) in which EEGLAB datasets are stored. EEGLAB uses a single Matlab variable, a structure, "EEG", that contains all dataset information and is always available at the Matlab command line. This variable can easily be used and/or modified to perform custom signal processing or visualizations. Finally, while EEGLAB "pop" functions (described above) assume that the data are stored in an EEG data structure, most EEGLAB signal processing functions accept standard Matlab array arguments. Thus, it is possible to bypass the EEGLAB interface and data structures entirely, and directly apply the signal processing functions to data matrices.
Distribution, documentation and support. The EEGLAB toolbox is distributed under the GNU General Public License (for details see http://www.gnu.org/licenses/gpl.txt). The source code, together with web tutorials and function description help pages, is freely available for download from http://sccn.ucsd.edu/eeglab/. The toolbox currently includes well over 300 Matlab functions comprising more than 50,000 lines of Matlab code. This user tutorial explains in detail how to import and process data using EEGLAB, including the derivation and evaluation of its independent components. SCCN also provides "Frequently Asked Questions (FAQ)" and "Known Bugs" web pages, a support email (eeglab@sccn.ucsd.edu), a dedicated mailing list for software updates (eeglabnews@sccn.ucsd.edu), and an email discussion mailing list (eeglablist@sccn.ucsd.edu), which currently reaches over two thousand EEG researchers.
Hit "save" in the pathtool window, which will make eeglab available for future Matlab sessions. Note that if you are installing a more recent version of EEGLAB, it is best to remove the old version from the Matlab path (select and hit "Remove") to avoid the possibility of calling up outdated routines.Open-source EEGLAB functions are not precompiled; users can read and modify the source code of every function. Each EEGLAB function is also documented carefully using a standardized help-message format and each function argument is described in detail with links to related functions. We have attempted to follow recognized best practice in software design for developing EEGLAB. The source code of EEGLAB is extensively documented and is internally under the Linux revision control system (RCS), which allows us to easily collaborate with remote researchers on the development of new functions. Matlab allows incremental design of functions, so adding new features to a function can be easily accomplished while preserving backward compatibility.
(Adapted from, A Delorme & S Makeig. EEGLAB: an open source toolbox for analysis of single-trial EEG dynamics. Journal of Neuroscience Methods 134:9-21 (2004)).
Start Matlab and list eeglab and all of its subdirectories in the Matlab search path.I. Analyzing Data in EEGLAB
I.1. Loading data and visualizing data information
Section I.1 introduces how to load and view EEG and associated event data.
A note on the instructions. Paragraphs that begin with KEY STEP are necessary to what follows in the tutorial. Paragraphs that begin with Exploratory Step are written to help you explore various EEGLAB features.
I.1.1. Getting started
I.1.1.1. Learning Matlab
EEGLAB graphic interface is built on top of the powerful Matlab scripting language. Enjoying the full capabilities of EEGLAB for buiding macro commands and performing custom and automated processing requires the ability to manipulate EEGLAB data structures in Matlab. After opening the Matlab desktop, we recommend running the following demos and reading the following help sections.
In the Help Content, select menu item "Help Demos" and run the following demos:
Mathematics - Basic Matrix Operations
Mathematics - Matrix manipulations
Graphics - 2-D Plots
Programming - Manipulating Multidimentional arrays
Programming - Structures
In the Help Content, read and practice at least the following sections:
Getting Started - Matrices and Arrays - Matrices and Magic squares
Getting Started - Matrices and Arrays - Expressions
Getting Started - Matrices and Arrays - Working with Matrices
Getting Started - Graphics - Basic plotting functions
Getting Started - Programming - Flow Control
Getting Started - Programming - Other data structures
Getting Started - Programming - Scripts and Functions
Each section or demo (if read thoroughly) should take you about 10 minutes, for a total here of about 2 hours. We encourage you to watch these demos and read these sections over several sessions.
If you do not have access to the Matlab demos, here is a short online introduction to Matlab (recommended pages, 1 to 12):
If you are an experienced Matlab programmer, you may want to read through the EEGLAB tutorial appendices on the EEG dataset and STUDY studyset structures and their sub-structures, and on EEGLAB script writing.
I.1.1.2. Installing EEGLAB and tutorial files
First download EEGLAB (4MB), the tutorial dataset (4MB), and if you wish, the pdf version of this tutorial (25MB).
When you uncompress EEGLAB you will obtain a folder named "eeglab4.512" (or whatever the current version number). Under Windows, Matlab usually recommends (although this is not required) that you place toolboxes in the Application/MatlabR14/toolbox/ folder (again, the name varies with the Matlab version). In Linux, the Matlab toolbox folder is typically located at /usr/local/pkgs/Matlab-r14sp2/toolbox/.
If you started Matlab with its graphical interface, go to menu item "file" and select "set path", which opens the following window.
Or, if you are running Matlab from the command line, type in "pathtool", which will also call up this window.
Click on the button marked "Add folder" and select the folder "eeglab4.512", then hit "OK" (EEGLAB will take care of adding its subfolder itself).
I.1.1.3. Starting Matlab and EEGLAB
Here we will start Matlab and EEGLAB.WINDOWS: Go to Start, find Matlab and run it.
Mac Option 1: Start from the Matlab icon in the dock or in the application folder.
Mac Option 2: Start X11 and in a terminal window type "matlab" and hit enter. For added stability type "matlab -nodesktop" to run it without its java desktop.
Linux: Open a terminal window and follow the Mac Option 2 instructions above.
KEY STEP 2 (optional): Switch to the data directory (folder).
![]()
In this case the directory you switch to should be the directory containing the example data provided for this tutorial.
If you are running Matlab with its java desktop, you may also browse for the directory by clicking on the button marked "..." in the upper right of the screen,
which opens the window below. Double-click on a directory to enter it. Double-clicking on ".." in the folder list takes you up one level. Hit "OK" once you find the folder or directory you wish to be in. Alternatively, from the command line use "cd" (change directory) to get to the desired directory.KEY STEP 3: Start EEGLAB.![]()
Just type "eeglab" at the Matlab command line and hit enter.
The blue main EEGLAB window below should pop up, with its seven menu headings:
File Edit Tools Plot Study Datasets Help
arranged in typical (left-to-right) order of use.
I.1.2. Opening an existing dataset
KEY STEP 4: Load the sample EEGLAB dataset.
Select menu item "File" and press sub-menu item "Load existing dataset".In the rest of the tutorial, we will use the convention: Menu_item > Submenu_item to refer to selecting a menu choice (e.g., here select File > Load existing dataset ).
Under Unix, the following window will pop up (the aspect of the window may be different under Windows):
To learn how to create EEGLAB datasets from your own data, see the tutorial chapter II on Importing data and data events.
When the dataset is loaded by EEGLAB, the main EEGLAB window shows relevant information about it -- the number of channels, sampling rate, etc...:Select the tutorial file "eeglab_data.set" which is distributed with the toolbox (available here - press the right mouse button and select "save link as" if strange characters appear - or in the "sample_data" sub-directory if you downloaded the full version of EEGLAB) and press " Open".
I.1.3. Editing event values
The fields "type ", "position" and "latency" have different values for each of the 154 events in the dataset.
Exploratory Step: Editing Event Values. Select menu Edit > Event Values to call up a window where we can read and edit these values:
Scroll through the events by pressing the ">", ">>", " < " and "<<" keys above.
We will now briefly describe the experiment that produced the sample dataset to motivate the analysis steps we demonstrate in the rest of the tutorial.
In this experiment, there were two types of events "square" and "rt", "square" events corresponding to the appearance of a green colored square in the display and rt to the reaction time of the subject. The square could be presented at five locations on the screen distributed along the horizontal axis. Here we only considered presentation on the left, i.e. position 1 and 2 as indicated by the "position" field (at about 3 degree and 1.5 degree of visual angle respectively). In this experiment, the subject covertly attended to the selected location on the computer screen responded with a quick thumb button press only when a square was presented at this location. They were to ignore circles presented either at the attended location or at an unattended location. To reduce the amount of data required to download and process, this dataset contains only targets (i.e., "square") stimuli presented at the two left-visual-field attended locations for a single subject. For more details about the experiment see Makeig et al., Science, 2002, 295:690-694.
When using events in an EEGLAB dataset, there are two required event fields: "type" and "latency", plus any number of additional user-defined information fields. It is important to understand here that the names of the fields were defined by the user creating the dataset, and that it is possible to create, save, and load as many event fields as desired.
Note also that "type" and "latency" (lowercase) are two keywords explicitly recognized by EEGLAB and that these fields must be defined by the user unless importing epoch event information (Note: If only field "latency" is defined, then EEGLAB will create field "type" with a constant default value of 1 for each event). Unless these two fields are defined, EEGLAB will not be able to handle events appropriately to extract epochs, plot reaction times, etc. The Creating datasets tutorial explains how to import event information and define fields.
I.1.4. About this dataset
Here we describe how to edit and view the text field which describes the current dataset, and is stored as a part of that dataset.
Exploratory Step: Editing the Dataset Description. Select Edit > About this dataset. A text-editing window pops up which allows the user to edit a description of the current dataset. For the sample data, we entered the following description of the task. Press SAVE when done.
I.1.5. Scrolling through the data
Here we learn how to vizualise data and reject portion of continous data.
Exploratory Step: Open eegplot(). To scroll through the data of the current dataset, select Plot > Channel data (scroll). This pops up the eegplot() scrolling data window below.
Note that the sample data file contains "faked" continuous EEG data. To reduce (your) download time, this "pseudo-continuous" EEG dataset was actually constructed by concatenating eighty separate three-second data epochs (which we will later separate again).
To the right of the plot window is the vertical scale value (unit, i.e. microvolts), which indicates the "height" of the given vertical scale bar. In this case, that value is 80 (microvolts). The same value is also shown in the lower right-hand edit box, where we can change it as explained below.
Exploratory Step: Voltage Scale.
Change the "Scale" edit-text box value to about 50, either by repeatedly clicking on the "-" button or by editing the text value from the keyboard, and press the "Enter" key to update the scrolling window.
Exploratory Step: Time Scale.
To adjust the time range shown (horizontal scale), select eegplot() menu item Settings > Time range to display, and set the desired window length to "10" seconds as shown below,
![]()
then press OK to display the changes.
Exploratory Step: Number of Channels to Display. To adjust the number of channels displayed, select eegplot() menu item Settings > Number of channels to display and enter the desired number of channels to display in the screen (for instance "16").
This will return a scrolling eegplot() window with a vertical channel-set slider on the left of the plot. Use it to scroll vertically through all the channels.
Exploratory Step: Zoom. To zoom in on a particular area of a data window, select eegplot() menu item Settings > Zoom off/on > Zoom on. Now using your mouse, drag a rectangle around an area of the data to zoom in on. The scrolling window may now look similar to the following. Click the right button on the mouse to zoom out again. Use menu Setting > Zoom off/on > Zoom off to turn off the zoom option.
Exploratory Step: Grid Lines. To display horizontal (x) and vertical (y) grid lines on the data, select Display > Grid > x axis or Display > Grid > y axis. Repeat this process to turn off either set of grid lines.
![]()
The eegplot() window also allows you to reject (erase) arbitrary portions of the continuous data. Actually, in the main EEGLAB menu, eegplot() is called from both menu items Plot > Scroll data and Tools > Reject continuous data using the "REJECT" button on the bottom right corner.
Exploratory Step: Rejecting Data.
Close the current eegplot() window and call Tools > Reject Continuous Data by eye from the main EEGLAB window. A warning message appears, click on continue. To erase a selected portion of the data, first drag the mouse along the area of interest to mark it for rejection. It is possible to mark multiple regions. To undo a rejection mark, click once on the marked region. Note: Zooming must be disabled to select a portion of the data.
Now, to erase the marked data regions, click the (lower right) "REJECT" button (above). A new dataset will be created with the marked regions removed. (Note: EEGLAB will also add new "rejection boundary" events to the new dataset event list. These insure that subsequent epoch selections will not cross non-contiguous rejection boundaries). For more details about rejecting continuous data regions and data epochs, see the data rejection tutorial.
Click "OK" (below) to create the new dataset with the marked data portions removed.
![]()
Press "OK" to create the new dataset. The EEGLAB main window now looks like:
![]()
Since we only performed this rejection for illustrative purposes, switch back to the original dataset by selecting main window menu item Datasets > Dataset 1 eeglab_data.
Exploratory Step: Deleting a Dataset from Memory.
To delete the newly created second dataset, select File > Clear dataset(s) or Edit > Delete dataset(s) and enter the dataset index, "2" as shown below, and press "OK".
The second dataset will now be removed from the Matlab workspace. Note: It is not necessary to switch back to the first dataset before deleting the second. It is also possible to delete several datasets at once from this window by entering their indices separated by spaces.
Tutorial home
Tutorial outline
Next tutorial