Analyzing brain signals with the FieldTrip toolbox - FieldTrip Basics
The FieldTrip toolbox: http://www.fieldtriptoolbox.org/
Excerpt of transcript from a lecture by Prof. Robert Oostenveld (slides contributed by Dr. Stephen Whitmarsh) entitled "Introduction to EEG/MEG and introduction to the FieldTrip toolbox". Video of the lecture available at the "fieldtriptoolbox" YouTube channel at the link https://youtu.be/eUVL_twWNdk.
(time point 25:19 of video)
Some FieldTrip basics. FieldTrip is a toolbox. FieldTrip does not have a graphical user interface. It really comes as a whole set of tools and you have to combine and mix and match these tools.
FieldTrip tools are basically the MATLAB functions. So if you look at the MATLAB functions or if you look at the functions inside the FieldTrip toolbox, what you see is that each function has a name, it takes a number of arguments as input and it produces an output argument.
Some of the FieldTrip functions do not produce an output, like not as a data structure, but they produce a figure. Some of the functions do not take input arguments, such as the preprocessing function (ft_preprocessing) which reads data from disk and then starts doing something with it. But in general what you see is that all of these define how the function should behave and the strategy that we use in FieldTrip is that we try to make this configuration structure human readable.
(time point 28:12 of video)
I said that we are using functions and we have a whole lot of these functions. And the way that you should think of these functions is that you put them together in analysis pipeline.
So you would start with ft_preprocessing. An ft_preprocessing reads EEG/MEG data from disk, it applies some filters and it produces an output data structure.
This is for example how you call it: you specify the data set, you specify the filters and then you call ft_preprocessing.
(transcript transposition) And once you are done with ft_preprocessing you could do reject analysis (ft_rejectartifact).
And next you could do ft_freqanalysis. You would specify a method, multitaper method with fast Fourier transform, you would specify the frequency of interest limits and then you would call ft_freqanalysis.
So by this way you're actually calling all of these FieldTrip functions and each of the functions has its own configuration. And it's important to keep in mind that there's not a single configuration that links all the FieldTrip functions together, it's your script that links all of these FieldTrip functions together.
Besides the configuration, FieldTrip works with data structures. And this is the example data structure for raw data. So what you see is that it has labels, channel labels, (...) there's trials, 87 trials. It has time axis, each trial has its own time axis and it has some additional fields.
Example use in scripts (time point 33:30 of video)
How do we use this in script. We would start with ft_preprocessing, so we would write a small section that pertains to preprocessing.
Then we will do ft_freqanalysis, write a small section.
And next we would do ft_freqstatistics and then we would continue with plotting or we'd like to branch off to a completely different type of analysis.
And it's these scripts that you manage yourself and it's these scripts that you store on disk and that's where you basically put the structure of your own analysis.
And what we quite often have is analysis over multiple subjects. So that allows you to use the scripting functionalities of MATLAB to first write your analysis for a single subject and then you just add a for loop for each of your subjects, for each of your conditions, do the same computations.
For some hands-on exercises on dealing with EEG data, the following tutorials are suggested. They have example data that one can work on:
There is quite some overlap between them, but it will pay off repeating the basic steps. Once the user is comfortable and has a sense of overview of the different steps involved, it is suggested to take a look at the FieldTrip implementation of real-time processing, which has example scripts (and a way to simulate real-time data):
You can download the FieldTrip toolbox here: http://www.fieldtriptoolbox.org/download.
After downloading the toolbox, unzip it and add the directory in which all the *.m files are located to the MATLAB path.
For instance, if you have downloaded "fieldtrip-20170930" and placed it on C:\Users, you need to write the following MATLAB command:
Execute the ft_defaults function, which sets the defaults and configures the minimal required path settings:
Download the tutorial data from the link mentioned at the red rectangle of the picture below (which is derived from page http://www.fieldtriptoolbox.org/tutorial/preprocessing). Extract the zip and find the extracted folder on the address bar. Right-click and select open.
It is recommended to work in the following way: create a file e.g. myscript.m, include the two commands mentioned above and then paste successively small pieces of code from the tutorial. You can select them and press F9 (or right click for Evaluate Selection F9) to obtain the result.