2.1. No Graphical User Interface
An important feature of the FieldTrip toolbox is that it does not have a Graphical User Interface (GUI). Instead, the user is interacting directly with the functions on the MATLAB command line or in scripts. Consequently, users need to have some basic knowledge of MATLAB in order to fruitfully use the toolbox. Although this requires an initial investment from the side of the user, it allows for very flexible combination of the functions to suit specific analysis needs.
The FieldTrip toolbox consists of high- and low-level functions. The high-level functions provide a consistent and easy-to-use interface of the functionality to the users, enabling them to do the analysis in well-defined steps. The low-level functions implement the core functionality, but are not designed to be used by the common neuroscience researcher and do not provide an easy programming structure to implement a complete analysis of the data. The low-level functions are largely hidden from the regular end users in private directories.
2.2. Analysis Scripts to Mix and Match
Practically, users start by writing an analysis script, in which they mix and match the FieldTrip high-level functions according to the experimental research question. A script consists of a sequence of FieldTrip function calls, each of which performing a specific part of the analysis pipeline. If required, the users extend the analyses with their own code. The content and style of analysis scripts highly depend on the expertise and programming skills of the user. In general the resulting scripts can be thought of as (parts of) analysis protocols. The scripts can be easily used for batch processing, allowing for a convenient application of the same analysis protocol to multiple subjects or experiments. Also, scripts can be exchanged between users, and between students and their supervisors, facilitating collaboration and knowledge transfer.
2.3. A Typical FieldTrip Function Call
High-level FieldTrip functions have a well-defined function-call interface. The input to a particular FieldTrip function consists of one or more MATLAB structures: a configuration structure, optionally followed by one or more data structures. The input configuration structure contains the options or parameters that specify how the data will be processed by the function and/or how the algorithm will behave in detail. The input data structure is usually the output of a FieldTrip function that was called earlier in the analysis pipeline (see below).
2.4. Configuration Structure
The specification of the parameters in the configuration structure follows the user's perspective: channels are for example indicated with their label and physical quantities are expressed in SI-units (e.g., frequency in Hz). Configuration parameters are stored in fields that express their meaning in human readable names. If possible, default values will be assigned to parameters that have not been specified by the end user.
2.5. Output of the FieldTrip Function
The output of a FieldTrip function is a MATLAB structure containing the processed data. This data structure also includes the configuration field that was used for the computations inside the function, allowing the user to inspect the details of the analysis, for example, the default configuration settings that were used. Some FieldTrip functions do not produce output data, but rather a figure displaying the data. A small set of FieldTrip functions generates neither data, nor figures, but extends the input configuration structure.
2.6. Definition of Data Structures
FieldTrip makes use of a number of well-defined data structures which are designed to be parsimonious, yet complete. They contain the numeric representation of the data in combination with the information necessary to interpret this numeric data. There are certain types of data structures for the different representations of the data. For example, segmented sensor-level time domain data is stored in a structure of data type “raw”. Structures of this data type consist of a cell-array “trial”, in which each cell contains a Channels × Timepoints matrix, a cell-array “label”, referring to the label of each of the channels, and a cell-array “time”, in which each cell contains the 1 × Timepoints vector, providing temporal information for each of the samples in each of the trials (). shows an example of a structure of data type “freq”.
Data representation examples. (a) Epoched time domain, sensor-level data. (b) Time-frequency representation of sensor-level data.
2.7. Analysis Scripts for Step-by-Step Analysis Are Protocollike
As mentioned before, analysis scripts usually contain a sequence of FieldTrip function calls. Each analysis step is usually performed by a single high-level FieldTrip function. To illustrate this, the following paragraphs and describe an analysis pipeline, showing the one-to-one mapping between a conceptual analysis step, and a high-level FieldTrip function. gives an impression of the corresponding analysis script.
2.7.1. Define Data Segments of Interest
A typical analysis starts with reading and segmenting the data such that the experimental conditions are represented as trials in a data structure. For simple experimental designs, segmenting the data can be done using a standard function that is included. For complex experimental designs, the user can provide his or her own function that decodes the sequence of triggers. Specific to FieldTrip is the possibility to create and analyze segments of variable length. One can think of segmenting the data as inverting the implementation of the experimental design in the stimulus presentation software. The definition of the boundaries of the relevant data segments is generated by ft_definetrial.
2.7.2. Identify and Remove Artifacts
Once the interesting segments of data have been identified, one may want to identify artifacts in the data that would affect the quality of the analysis results. Subsequently, the user can either remove the affected segments from the data altogether, or remove the artifact from the data by applying a linear projection.
The function ft_rejectartifact allows for semiautomatic detection of well-defined artifacts such as eye blinks, muscle contractions, or MEG SQUID jumps. With a minimum of user interaction artifacts are identified by thresholding the data after processing the data to increase the sensitivity to pick up the characteristics of the specific artifact. For example, MEG SQUID jumps are easily detected after applying a median filter to the data. Alternatively, users can use the ft_databrowser function, allowing them to browse through the data and manually identify data segments containing artifacts ().
Figure 5 Visualization of data with the ft_databrowser function. (a) Display of a set of sensors in the “butterfly” mode, showing the possibility to select segments of interest, for example, to identify artifacts (pink box). (b) Display of a set (more ...)
To project out artifacts with a characteristic spatial topography, such as eye blinks or cardiac activity, the ft_componentanalysis function can be used. This implements a variety of blind source separation methods, such as independent component analysis (ICA, based on code from the EEGLAB toolbox [1
]), and principal component analysis (PCA).
2.7.3. Read Data from Disk and Apply Filters
The ft_preprocessing function is used to read the interesting segments of data from disk into the MATLAB workspace and to apply various processing steps to the raw data such as filtering, rereferencing and baseline correction. The input to ft_preprocessing is a single configuration structure, specifying the filename of the raw data file, as well as the definition of the segments of interest. In addition, the configuration contains the instructions for the various optional processing steps.
2.7.4. Event-Related Potential Analysis
Once the segmented data are in the MATLAB workspace, the next step could be to average across trials of a particular experimental condition to obtain the event-related field (ERF) using the function ft_timelockanalysis. gives some examples of visualizing the ERFs.
Figure 7 Visualization of multidimensional data. (a) Topographical representation of a specific temporal component of the ERF. (b) Single sensor display of an ERF. (c) Topographical display of sensor-level ERFs in three experimental conditions. (d) Topographical (more ...) 2.7.5. Time-Frequency Decomposition
Alternative to the analysis of event-related fields, the experimental question may warrant the data to be analysed in the frequency domain. The transformation from the time domain into the frequency domain is achieved by ft_freqanalysis.
2.7.6. Source Reconstruction
Reconstructing the location and the strength of the underlying neuronal activity can either be done with ft_sourceanalysis or ft_dipolefitting. The latter function implements a nonlinear optimization algorithm that fits a prespecified number of dipoles to the data [2
]. The ft_sourceanalysis function implements distributed source models, such as minimum norm estimates (MNE) [3
], and beamformers for time-domain and frequency-domain data [4
]. The source space can be defined either as a three-dimensional regular grid, or can be based on a triangulation of the cortical sheet. There is no functionality in FieldTrip for the creation of cortical meshes, since excellent and freely available toolboxes such as FreeSurfer [6
] already exist. Distributed source data and beamformer maps as well as statistically transformed derivations from these maps can be readily visualized in combination with anatomical information using the ft_sourceplot function (). Functional data can be statistically thresholded and plotted on top of the anatomy, using opacity mapping. Threedimensional volumetric data can be rendered onto a template or individual cortical mesh ().
Visualization of source-reconstructed data. (a) Three-dimensional orthographic rendering of corticomuscular coherence with opacity mapping. (b) Surface rendering of statistically thresholded corticomuscular coherence after Z-transformation.
2.7.7. Statistical Inference
Usually the final step in a particular analysis stream is the assessment of statistical significance of the observed experimental effect, either at the level of a single subject or across subjects. At this point in the analysis, the data can be expressed in the time domain, frequency domain, or time-frequency domain. Furthermore, the data can either be represented at the sensor or at the source level. Independent of the data representation, FieldTrip uses the same underlying code to assess significance using parametric or nonparametric algorithms [7
] for statistical inference.
2.8. Handling the Data
An important concept in FieldTrip is that the data are in the hands of the end users. The data flows through the different FieldTrip functions and is transformed along the way. After each transformation the data corresponds to a variable, that is, a data structure in the MATLAB workspace, and the user can optionally save it to disk. The data serving as the input to a particular FieldTrip function is not included in its output. The user has to explicitly manage the data, that is, assign meaningful variable names and save the variables to disk as a MATLAB mat file, especially if intermediate analysis results need to be revisited. In addition to saving workspace variables to mat files, analysis results can be exported to a number of non-MATLAB file formats that are supported by external software. Sensor-level electrophysiological data can, for example, be saved in EDF and BrainVision Analyzer format, source reconstructed volumetric data can be saved in NIfTI format.
Although the data at the different levels of the analysis are not kept within a single structure, the history of the analysis is still present at any stage. Each output data structure of a FieldTrip function contains a nested configuration field. This field not only holds the parameters used to generate the data at the present level, but also contains the parameters used to process the data at all previous levels. In this way, information about the processing history is present at any level of the analysis pipeline.
2.9. Batch Processing
For most cognitive experiments the data from many subjects is required. Recent technological developments allow for recordings with more channels, leading to larger data sets. Therefore, despite advancements in computational power, the analysis of MEG/EEG data remains computationally demanding and takes a significant amount of time. To analyze experiments with a large number of subjects, batch processing is convenient and often necessary to systematically explore the outcome of the analysis given a particular set of parameters.
One of the preferred ways of using batch processing in a FieldTrip analysis is to start with the construction of a single script containing the full analysis pipeline for a single subject. During the implementation of this script, the user extends the script in the MATLAB editor and uses copy-and-paste to execute segments of the script. Once the user is satisfied with the sequence of analysis steps and with the parameter settings, this script can be converted into batch analysis. This can be implemented by breaking the single script into separate components, each of which resulting in an intermediate result that the user wants to inspect and/or save to disk. By adding a for loop around each of these components, the whole analysis pipeline can easily be executed for all subjects. Parameters that are specific to the individual subjects can be put in an additional subject-specific script, which is evaluated inside the batch component scripts. The whole batch can be easily reevaluated with different parameter settings.
2.10. Visualizing Analysis Results
MATLAB contains a variety of high-quality and multipurpose plotting tools and visualization of (intermediate) analysis results is often possible using these standard MATLAB plotting functions. Important for this is that the numeric representation of the data is easily accessible in the FieldTrip datastructures. However, complex analysis results and the multidimensional nature of some data representations sometimes prohibit easy visualization or exploration. To this end FieldTrip contains several high-level plotting functions for channel and source level data representations. For example ft_multiplorTFR allows the user to visualize the spatiotemporal spectral data and to interactively explore all three dimensions by making selections of channels and along the time and/or frequency axis.
Examples of the graphical output of some plotting functions are shown in Figures and . Sensor-level data can be visualized by interpolating it on a two-dimensional projection of the sensor positions, for example, to look at the spatial distribution of specific ERF components (), or the specific oscillatory components in the time-frequency representation (TFR) of the data. Another method to visualize sensor-level data is to plot the complete ERF or TFR at each sensor position (Figures and ) or to plot the averaged ERF or TFR over a subset of channels (). Source-reconstructed data can be visualized in combination with anatomical information using the ft_sourceplot function using orthogonal MRI slices or a 3D surface rendering of the cortical sheet (). Relevant for exploring the data is the interactive option, enabling the user to select with the mouse regions-of-interest in time, frequency, and/or space. Finally, the ft_databrowser () can be used to interactively explore time-domain sensor-level data, at the same time allowing for the visually guided specification of artifacts.