EEGLAB and Fieldtrip
EEGLAB and Fieldtrip
First a little bit of history. EEGLAB was created in 2000 at The Salk Institute (La Jolla CA) by Arnaud Delorme and Scott Makeig based on ICA Toolbox for Electrphysiological Data Analysis functions released by Makeig and colleagues 1997-2000. EEGLAB was fully released in 2002 at the Swartz Center for Computational Neuroscience, UCSD (La Jolla, California, USA). In 2003-04, the EEGLAB software architect Arnaud Delorme worked with Fieldtrip senior author Robert Oostenveld to provide basic source localization to EEGLAB via the EEGLAB DIPFIT plug-in using Matlab code Robert had developed for dipole fitting. Together with many other functions written at the Donders Institute for Brain, Cognition, and Behavior (Nijmegen, The Netherlands), the source code contributed by Robert Oostenveld to DIPFIT served as a basis for Fieldtrip which was first released by the Donders Institute in 2005. Both packages run on MATLAB (The Mathworks, Inc.).
EEGLAB and Fieldtrip are in part interdependent. For basic source localization, EEGLAB uses the DIPFIT plug-in which incorporates a Fieldtrip source localization routine. EEGLAB also offers users the choice of using some Fieldtrip statistical routines as well as its own. The Fieldtrip code also includes some EEGLAB functions such as topoplot() and runica() for performing independent component analysis decomposition. EEGLAB and Fieldtrip developers meet every year or every other year to discuss progress in the field and possible collaborations or new bridges between the two software. In the spirit of open source programming, we believe that more collaboration is better. Working from experience with a multiplicity of approaches allows us to identify and deal with problematic signal processing issues.
In practice, the philosophies of EEGLAB and Fieldtrip are somewhat different:
- Fieldtrip is aimed mostly at advanced users and does not have a graphic user interface. In contrast, EEGLAB provides a graphic user interface (gui) for data exploration plus a graded path toward writing custom analysis scripts using the EEGLAB functions caleld by the EEGLAB gui.
- Fieldtrip provides limited tools for handling group data. Managing group data is intentionally left to the user's choice with a rationale that users should not be forced to use any predefined scheme for modeling the experimental design. EEGLAB by contrast provides tools to apply a variety of statistical models and sub-models to group experimental data.
- Fieldtrip allows variable length data epochs. Though EEGLAB supports some processing of multiple continuous data segments, it is not as flexible as Fieldtrip in processing data epochs of variable lengths. Historically, this difference arose in part because Fieldtrip was developed to support animal as well as human physiological data analysis, whereas EEGLAB development has always focused on analysis of human data.
- Fieldtrip functions are sometimes modified without maintaining compatibility with previous versions. EEGLAB functions aim to always provide backward compatibility, with new function versions designed to support old calling formats.
- Fieldtrip functions provide packaged solutions in which low-level processing is hidden, and subject to change. Thus, a large number of Fieldtrip functions that change frequently are hidden in private folders. By contract, there are no hidden functions in EEGLAB; users have direct access to low-level processing functions, and these are fully documented.
- Any new contribution to Fieldtrip adds to the general Fieldtrip package supported by the Donders Center. In practice, this makes it difficult for external developers to contribute code (the Fieldtrip developers are open about this though). In EEGLAB, all third party contributions are made available as EEGLAB extensions (formerly 'plug-ins'). To date there are more than 60 EEGLAB extensions available from many developers, including extensive toolboxes ERPLAB, SIFT, LIMO, NFT, MPT, BCILAB, MoBILAB, etc.. Third party developers maintain full control over their extensions.
- When you download Fieldtrip, you download the 'code of the day' (the head of the development code) which could contain recently added bugs as well as fixes. Fieldtrip is relatively unstable in that sense. A function that works one month might not work the next month - although it will probably be fixed one month later - or it might never worked again because the Fieldtrip developpers have found a smarter way to do things and have dropped backward compatibility. By contrast, in EEGLAB all changes to core code are checked by chief software architect Arnaud Delorme and are fully backward compatible. There are also over 5,000 unit tests run each night to ensure EEGLAB code stability. Finally, EEGLAB has a versioning system in which changes are first tested by the developers and then by users at the Swartz Center before being released in a more stable form. A developer version containing all the daily changes is also made available through revision control software.
In short, Fieldtrip is closer to the type of research code available in many labs for in-house use. Constantly evolving and changing, growing in a somewhat anarchic (though generally healthy) way. EEGLAB is more of a structured package for which additions to core functions are carefully considered and controlled to maximize stability. EEGLAB's third party extension (plug-in) facility provides a free medium for new tool development and publication by many groups and individuals.
Which environment should you choose to use?
The choice between either (or both) environments is yours. Some considerations:
- If you have little experience with analysis script writing, we definitely recommend you try EEGLAB. EEGLAB facilities and documentation will also guide you through learning how to write scripts, even writing scripts for you based on your menu choices.
- If you are an advanced programmer, Fieldtrip's nested data structures might also appeal to you. EEGLAB data structures have been kept simple on purpose so beginners do not feel overwhelmed and have easy script access to information about their data.
- If you want maximum control over your processing pipeline, you might also want to choose EEGLAB, since it gives you ready access to low-level processing functions and has in-depth documentation. Also, if you want to maximize the probability that your code will continue to work in future revision of the software, again EEGLAB might be the best option.
- If you want to publish Matlab code for new functions or toolboxes, EEGLAB extensions provide a sure way to make your code known and available for widespread, easy use and testing - even directly from the EEGLAB gui of users who download your extensions. The EEGLAB Extension Manager will also allow you to help users maintain current versions of your extensions.
- Both EEGLAB and Fieldtrip can be added to the Matlab path and run together. Some functions are available to convert between data structures of both toolboxes, such as the EEGLAB eeglab2fieldtrip.m and the fieldtrip2eeglab.m functions - note that these functions focus on converting specific structure of data (Fieldtrip has several of them) and are not meant to be all purpose functions. EEGLAB can also import data from FILE-IO which is compatible with Matlab files saved by Fieldtrip. There is a notable function name conflict when using both EEGLAB and Fieldtrip together - the topoplot.m function is present in both toolboxes, although if you start EEGLAB it should resolve conflicts.
Converting between EEGLAB and Fieldtrip data structures
In practice, it is easy to use both EEGLAB and Fieldtrip at the same time and to convert back and forth between data structures.
To import Fieldtrip data structures into EEGLAB, you may use the pop_fileio function of EEGLAB or the fieldtrip2eeglab function (the code is the same since fieldtrip2eeglab calls pop_fileio). This requires EEGLAB 15 or the latest changes in the develop branch of EEGLAB on Github.
EEG = pop_fileio(hdr, dat, events);
EEG = fieldtrip2eeglab(hdr, dat, events);
To import EEGLAB datasets in Fieldtrip is to read EEGLAB datasets using the file File-IO interface either using the standard FILE-IO interface or using the low level EEGLAB reading function of FILE-IO as below.
hdr = ft_read_header( EEGLABFILE ); data = ft_read_data( EEGLABFILE, 'header', hdr ); events = ft_read_event( EEGLABFILE, 'header', hdr );
A legacy function eeglab2fieldtrip also exists although it is mostly used internally in EEGLAB to convert EEGLAB datasets to Fieldtrip for source localization purposes (DIPFIT). It is not recommended to use that function although it might still work for your application.
Performing advanced source localization using DIPFIT/Fieldtrip
See this section of the tutorial.