[FieldTrip] Single trial baseline correction in ft_preprocessing

Schoffelen, J.M. (Jan Mathijs) jan.schoffelen at donders.ru.nl
Wed Oct 2 16:44:09 CEST 2019


Hi Duru,

Thank you for your response. It seemed like your suggestion helped, but I thave another potential issue now.
The problem is, when I use ft_databrowser to visualise the trials after baseline corection loop, I can no longer see the markers, even if I add  cfg.plotevents  = 'yes'. I can see that this information exists in the data structure, so I'm not sure if this is a problem per se. But the bigger issue is, after running these loops, the data becomes very large (even after being appended), impossible to save, and slows down the rest of my analysis, where regular baseline correction doesn't cause this.
 Any ideas where I might be going wrong? I suspect I might have used the wrong kinds of brackets, but the curly brackets as in your suggestion caused an error about cell structures, and when I run it as I wrote, the data structures actually look fine.Or it might be the way that I made a loop to append the data, instead of spelling it out for all of the 360 trials.

The data becomes very ‘big’ because you are creating 360 copies of the metadata (which includes the cfg’s of all previous processing steps), AND you are appending the data one trial at a time, which makes this duplication even worse (specifically the duplication of the cfgs).
One thing you could do to alleviate this is to save your bl_end_E data structures as a cell-array {}, rather than a struct-array (). Then, you can call ft_appenddata only once with the following syntax: ft_appenddata([], bl_end_E{:}); As a result, you will have only 360 copies of the original cfg in the output data structure, rather than 361*180 copies.

The best solution however to me seems to be an extension of the functionality of the baseline correction scheme, where a matricial baselinewindow is supported. I could think of a situation where a check is performed whether size(baselinewindow,1) is equal to the number of input trials, and if so, a per trial baselinewindow is applied. if the size is equal to 1, the same baselinewindow will be used for all trials. If the size is something else, an error should be thrown. I would assume that this can be most cleanly implemented in the preproc function. We will look forward to a Pull Request on github that impements this!


Another somewhat related question, is it possible to have the baseline window outside of the defined trial length?

No.

Best wishes,
Jan-Mathijs



 Here is what I did:

 for trial_index = 1:360

     cfg                = [];
     cfg.demean         = 'yes';
     cfg.baselinewindow = [BaselineWindow(trial_index,1) BaselineWindow(trial_index,2)];
     cfg.trials         = trial_index;
     bl_end_E(trial_index)  = ft_preprocessing(cfg, data_end_E);

 end

%% This results in the struct:
 bl_end_E =   1×360 struct array with 8 fields:
    hdr
    fsample
    trialinfo
    sampleinfo
    trial
    time
    label
    cfg

%% Then I append the data:
 data_base_end_E = bl_end_E(1);

 for trial_ind = 2:360

     cfg                 = [];
     cfg.keepsampleinfo  = 'yes';
     data_base_end_E     = ft_appenddata(cfg,data_base_end_E,bl_end_E(trial_ind));

 end

%% This results in losing hdr and fsample fields: data_base_end_E =   struct with fields:

         label: {29×1 cell}
     trialinfo: [360×4 double]
    sampleinfo: [360×2 double]
         trial: {1×360 cell}
          time: {1×360 cell}
           cfg: [1×1 struct]
%% So I add them back:
  base_end_E.hdr = data_end_E.hdr;
  base_end_E.fsample = data_end_E.fsample;

    %% Visual data inspection
    cfg                   = [];
    cfg.viewmode  = 'vertical';
    cfg.continuous = 'no';
    cfg.blocksize   = 1.5;
    cfg.channel     = {'all'};
    cfg                   = ft_databrowser(cfg,data_base_end_E);


Thanks again for the help!

Duru

--
Duru Gün Özkan

Ph.D. student in Cognitive Social and Affective Neuroscience.
Department of Psychology.
University of Rome "La Sapienza".
Via dei Marsi 78 - 00185 - Roma.
 e-mail: durugun.ozkan at uniroma1.it<mailto:vanessa.era at uniroma1.it>
https://agliotilab.org/lab-staff/phd-students/2nd-year#anchor

> Hi Duru,

>   Use cfg.trials = trial_index
>   Put the output in a struct, i.e. bl{trial_index}
>   Then combine with ft_append_data([],bl{:});

>   Hope this helps,
>   Stephen


>   On Tue, 17 Sep 2019, 19:30 Duru Gun Ozkan, <durugun.ozkan at uniroma1.it<mailto:durugun.ozkan at uniroma1.it>>
>   wrote:

> Hi everyone,
>
> I have a question regarding specifying a different baseline correction
> time for each trial in ft_preprocessing.
> I had 360 audio stimuli all of which had different lengths. My trigger is
> located at the end of each stimuli, and I would like to place the baseline
> correction between 200 ms before stimulus start and stimulus start.
> I have a matrix for cfg.baselinewindow called BaselineWindow such as this:
> -1.83018 -1.630182
> -1.69807 -1.498071
> -0.58653 -0.38653
> -1.07604 -0.876039
> -2.2608 -2.060803
> -0.80863 -0.608632
> -1.55663 -1.356629
> -0.94261 -0.742605
> -1.20845 -1.008448 ...
> I tried to create a loop:
>
> for trial_index = 1:360
>
>      cfg = [];
>      cfg.demean        = 'yes';
>      cfg.baselinewindow = [BaselineWindow(trial_index,1)
> BaselineWindow(trial_index,2)];
>
>      data_baselined_end_E = ft_preprocessing(cfg, data_end_E);
>
>  end
>
> This didn't work because it kept running the preprocessing with all the
> baselines with all trials, instead of keeping to its specific trial.
>
> My question is, is there another way to specify individual baselines for
> individual trials? Or can anyone suggest to improve this loop to have the
> data preprocessed with its specific baseline windows?
>
> Thank you in advance.
>
> Best,
>
>

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20191002/0d26b100/attachment.html>


More information about the fieldtrip mailing list