Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
tutorial:preprocessing [2018/10/21 15:17]
42.49.180.224 [Trigger-based trial selection]
tutorial:preprocessing [2017/08/17 11:21] (current)
127.0.0.1 external edit
Line 33: Line 33:
   * Read the data into MATLAB using **[[reference:​ft_preprocessing|ft_preprocessing]]**   * Read the data into MATLAB using **[[reference:​ft_preprocessing|ft_preprocessing]]**
  
-====== ​Trigger-based trial selection ​=========== Use your own function for trial selection =====+===== Reading and preprocessing the interesting trials ​===== 
 +Using the FieldTrip function **[[reference:​ft_definetrial|ft_definetrial]]** you can define the pieces of data that will be read in for preprocessing. Trials are defined by their begin and end sample in the data file and each trial has an offset that defines where the relative t=0 point (usually the point of the stimulus-trigger) is for that trial.  
 + 
 +The **[[reference:​ft_definetrial]]** and **[[reference:​ft_preprocessing]]** functions require the original MEG dataset, which is available at [[ftp://​ftp.fieldtriptoolbox.org/​pub/​fieldtrip/​tutorial/​Subject01.zip]] 
 + 
 +Do the trial definition for the fully incongruent (FIC) condition:​ 
 +<code matlab> ​  
 +  cfg                         []; 
 +  cfg.dataset ​                '​Subject01.ds';​ 
 +  cfg.trialfun ​               ​'​ft_trialfun_general';​ % this is the default 
 +  cfg.trialdef.eventtype ​     ​'​backpanel trigger';​ 
 +  cfg.trialdef.eventvalue ​    3; % the value of the stimulus trigger for fully incongruent (FIC). 
 +  cfg.trialdef.prestim ​       ​1; % in seconds 
 +  cfg.trialdef.poststim ​      = 2; % in seconds 
 +   
 +  cfg = ft_definetrial(cfg);​ 
 +</​code>​ 
 + 
 +This results in a cfg.trl in which the beginning, the trigger offset and the end of each trial relative to the beginning of the raw data is defined. 
 + 
 + 
 +The output of **[[reference:​ft_definetrial|ft_definetrial]]** can be used for **[[reference:​ft_preprocessing|ft_preprocessing]]**. 
 + 
 +  cfg.channel ​   = {'​MEG'​ '​EOG'​};​ 
 +  cfg.continuous = '​yes';​ 
 +  dataFIC = ft_preprocessing(cfg);​ 
 + 
 + 
 +Save the preprocessed data to disk: 
 + 
 +  save PreprocData dataFIC 
 + 
 +The output of **[[reference:​ft_preprocessing]]** is the structure dataFIC which has the following fields: 
 + 
 +<code matlab> ​  
 +dataFIC =  
 +           hdr: [1x1 struct] 
 +         ​label:​ {152x1 cell} 
 +          time: {1x87 cell} 
 +         ​trial:​ {1x87 cell} 
 +       ​fsample:​ 300 
 +    sampleinfo: [87x2 double] 
 +     ​trialinfo:​ [87x1 double] 
 +          grad: [1x1 struct] 
 +           cfg: [1x1 struct] 
 +</​code>​ 
 + 
 +The most important fields are dataFIC.trial containing the individual trials and dataFIC.time containing the time vector for each trial. To visualize the single trial data (trial 1) on one channel (channel 130) do the following:​ 
 + 
 +    plot(dataFIC.time{1},​ dataFIC.trial{1}(130,:​)) 
 + 
 +{{tutorial:​preprocessing:​preprocess1.png}} 
 + 
 +The preprocessing steps will be repeated for the other conditions as well. 
 + 
 +The initially congruent (IC) condition:​ 
 +   
 +  cfg                         = []; 
 +  cfg.dataset ​                = '​Subject01.ds';​ 
 +  cfg.trialdef.eventtype ​     = '​backpanel trigger'; ​  
 +  cfg.trialdef.eventvalue ​    = 5; % the value of the stimulus trigger for initially congruent (IC). 
 +  cfg.trialdef.prestim ​       = 1; % in seconds 
 +  cfg.trialdef.poststim ​      = 2; % in seconds 
 +   
 +  cfg = ft_definetrial(cfg);​ 
 +   
 +  cfg.channel ​   = {'​MEG'​ '​EOG'​};​ 
 +  cfg.continuous = '​yes';​ 
 +  dataIC = ft_preprocessing(cfg);​ 
 + 
 +Save the preprocessed data to disk: 
 + 
 +  save PreprocData dataIC -append 
 + 
 +And the fully congruent (FC) condition:​ 
 + 
 +  cfg                         = []; 
 +  cfg.dataset ​                = '​Subject01.ds';​ 
 +  cfg.trialdef.eventtype ​     = '​backpanel trigger';​ 
 +  cfg.trialdef.eventvalue ​    = 9; % the value of the stimulus trigger for fully congruent (FC). 
 +  cfg.trialdef.prestim ​       = 1; % in seconds 
 +  cfg.trialdef.poststim ​      = 2; % in seconds 
 +     
 +  cfg = ft_definetrial(cfg);​ 
 +   
 +  cfg.channel ​   = {'​MEG'​ '​EOG'​};​ 
 +  cfg.continuous = '​yes';​ 
 +  dataFC = ft_preprocessing(cfg);​ 
 + 
 +Save the preprocessed data to disk: 
 + 
 +  save PreprocData dataFC -append 
 + 
 +These functions demonstrate how to extract trials from a dataset based on trigger information. Note that some of these trials will be contaminated with various artifact such as eye blinks or MEG sensor jumps. Artifact rejection is described in [[tutorial:​visual_artifact_rejection|Preprocessing - Visual artifact rejection]] 
 + 
 +===== Use your own function for trial selection =====
  
 There are often cases in which it is not sufficient to define a trial only according to a given trigger signal. For instance you might want to accept or reject a trial according to a button response recorded by the trigger channel as well. Another example might be that you want the signals from the EMG or A/D channel being part of the trial selection. In those cases it is necessary to define a specialized function for trial selections. Below is an example which can be adapted to your needs. There are often cases in which it is not sufficient to define a trial only according to a given trigger signal. For instance you might want to accept or reject a trial according to a button response recorded by the trigger channel as well. Another example might be that you want the signals from the EMG or A/D channel being part of the trial selection. In those cases it is necessary to define a specialized function for trial selections. Below is an example which can be adapted to your needs.
Line 114: Line 209:
  
 This tutorial was last tested with version 20120501 of FieldTrip using MATLAB 2009b on a 64-bit Linux platform. This tutorial was last tested with version 20120501 of FieldTrip using MATLAB 2009b on a 64-bit Linux platform.
 +