[FieldTrip] redefine trials using different trigger as zero point

Eelke Spaak eelke.spaak at donders.ru.nl
Sat Oct 11 11:40:05 CEST 2014


Hi Katrin,

The first *3* (not just 2) columns of the trl-matrix are special, they
define the start and end sample of the trial, and the offset. Right
now you are not storing the offset in the output of your trialfun.
Instead, you put the RT in the third column. Since there are no
columns 4 and above, no trialinfo is created (plus your time axes will
likely be wrong as the RT is now interpreted as offset by FieldTrip).

Change the relevant line to the following:

newtrl = [trlbegin trlend offset RT];

and you should get a proper trialinfo.

Best,
Eelke



On 2 October 2014 21:53, KatrinH Heimann <katrinheimann at gmail.com> wrote:
> Dear Anne, dear all,
>
> I did try to create a customized trialfunction serving my needs.
> This is what I came up with:
>
> function [trl, event] = response_trialfun(cfg);
>
>
>
> % read the header information and the events from the data
>
> hdr   = ft_read_header(cfg.dataset);
>
> event = ft_read_event(cfg.dataset);
>
>
>
>
>
> % search for "trigger" events
>
> value  = [event(find(strcmp('ceck', {event.value}))).value]';
>
> sample = [event(find(strcmp('ceck', {event.value}))).sample]';
>
>
>
> % search for "trigger" events
>
> value2  = [event(find(strcmp('resp', {event.value}))).value]';
>
> sample2 = [event(find(strcmp('resp', {event.value}))).sample]';
>
>
>
> % determine the number of samples before and after the trigger
>
> pretrig  = -round(cfg.trialdef.prestim  * hdr.Fs);
>
> posttrig =  round(cfg.trialdef.poststim * hdr.Fs);
>
>
>
> % look for the combination of a trigger "7" followed by a trigger "64"
>
> % for each trigger except the last one
>
> trl = [];
>
>
>
>     trlbegin = sample + pretrig
>
>     trlend   = sample + posttrig
>
>     offset   = pretrig
>
>     RT       = sample2 - sample
>
>     newtrl   = [trlbegin trlend RT];
>
>     trl      = [trl; newtrl];
>
>
>
> end
>
>
>
> In fact it seems to work, the trials look good and the RT is computed
> correctly. Only that after the preprocessing (with ft_preprocessing:
>
>
> %% preprocess data
>
> cfg.channel    = 'all';
>
> cfg.preproc.detrend       = 'yes';
>
> cfg.preproc.demean = 'yes';
>
> cfg.preproc.baselinewindow = [-0.1 0]
>
>
>
> mov_data           = ft_preprocessing(cfg);
>
> %
>
> ) there is no mov_data.trialinfo created. I thought that the information in
> trl above would be saved there. Without those I am not able to do the
> redefinition as planned (like Anne proposed:
>
>
>
>
>         offset      = (mov_data.trialinfo(:,3));
>
>         prestim     = 0.75;
>
>         poststim    = 0.75;
>
>
>
>         cfg           = [];
>
>         cfg.begsample = round(offset - prestim*data.fsample);
>
>         cfg.endsample = round(offset + poststim*data.fsample);
>
>         mov_data_small = ft_redefinetrial(cfg, mov_data);
>
>
>
>         % then shift the time axis
>
>         cfg = [];
>
>         cfg.offset = -offset;
>
>         mov_data_small = ft_redefinetrial(cfg, move_data_small);
>
>
>
>
> How come the information is not stored? Somebody an idea?
>
> Thanks a million
>
> Katrin
>
>
> 2014-09-28 18:35 GMT+02:00 Anne Urai <anne.urai at gmail.com>:
>>
>> Dear Katrin,
>>
>> if you use a custom trialfun
>> (http://fieldtrip.fcdonders.nl/example/making_your_own_trialfun_for_conditional_trial_definition)
>> you can code the time between stimulus onset and response in an additional
>> column. That way, you can shift the time axis of the data by this amount on
>> each trial. For example:
>>
>>         % redefine trials
>>         offset      = (data.trialinfo(:,RTcol));
>>         prestim     = 1;
>>         poststim    = 2;
>>
>>
>>
>>         cfg           = [];
>>         cfg.begsample = round(offset - prestim*data.fsample);
>>         cfg.endsample = round(offset + poststim*data.fsample);
>>         data = ft_redefinetrial(cfg, data);
>>
>>
>>
>>         % then shift the time axis
>>         cfg = [];
>>         cfg.offset = -offset;
>>         data = ft_redefinetrial(cfg, data);
>>
>>         % timelock
>>         cfg = [];
>>         cfg.keeptrials = 'yes';
>>         data = ft_timelockanalysis(cfg, data);
>>
>> That way, your new data structure will now be response locked. Note that
>> the timelockanalysis is optional, and only works when you have trials that
>> are all the same length.
>>
>> If you do not want to use a custom trialfun, you could also rerun the same
>> analysis as you have for the stimulus-locked data, but then taking the
>> response code as your eventvalue.
>>
>> Good luck,
>>
>> ---
>> Anne E. Urai, MSc
>> PhD student | Institut f├╝r Neurophysiologie und Pathophysiologie |
>> Universit├Ątsklinikum Hamburg-Eppendorf
>> Martinistrasse 52, 20246 Hamburg, Germany | http://anneurai.wordpress.com
>>
>>
>>
>>
>>
>> On 28 Sep 2014, at 11:54, KatrinH Heimann <katrinheimann at gmail.com> wrote:
>>
>> Dear all,
>> I know I asked this already twice, but I did not get the right answer yet
>> and just cannot figure it out myself.
>> So, I did cut my data in quite large trials using ft_define trial and
>> logging it to the beginning of a slide.
>>
>> cfg                     = [];
>> cfg.dataset             = name;
>> cfg.trialfun            = 'ft_trialfun_general'; % this is the default
>> cfg.trialdef.eventtype  = 'trigger';
>> cfg.trialdef.eventvalue = 'ceck'; % the value of the stimulus trigger
>> cfg.trialdef.prestim    = 0.216; % in seconds
>> cfg.trialdef.poststim   = 7.284; % in seconds (max time of check slide)
>> cfg                     = ft_definetrial(cfg);
>>
>>
>>
>> % cancel out training trials
>> cfg.trl([1:4],:) = [];
>>
>>
>>
>> %change timeline according to constant offset of 16 ms = 8 samples
>> (because recorded with 500 hz)in
>> %structure trial - plus delay reported by EGE = 18 ms = 9 samples
>> cfg.trl(:,3)=cfg.trl(:,3)-17
>>
>>
>>
>>
>>
>>
>>  Then I preprocessed these trials
>>
>> %% preprocess data
>> cfg.channel    = 'all';
>> cfg.preproc.detrend       = 'yes';
>> cfg.preproc.demean = 'yes';
>> cfg.preproc.baselinewindow = [-0.1 0]
>> %
>> mov_data           = ft_preprocessing(cfg);
>> %
>> save (strcat(sb,'mov_data') , 'mov_data')
>>
>>
>>
>>
>> Now I wanna cut out smaller pieces that are centered around another
>> trigger - the response of the subject. I did not use this trigger at the
>> beginning as then defining a baselinewindow is impossible (as the response
>> is always happening at a different time).
>>
>> I tried to just use ft_definetrial again, as I don't see a possibility to
>> use ft_redefine trial:
>>
>> cfg = []
>> cfg.dataset= strcat(sb,'mov_data.mat')
>> cfg.trialdef.eventtype  = 'trigger';
>> cfg.trialdef.eventvalue = 'resp'
>> cfg.trialdef.prestim    = 0.75
>> cfg.trialdef.poststim   = 0.75
>>
>>
>>
>> mov_data_small = ft_definetrial(cfg)
>>
>> but I get the error message:
>>
>> Error using ft_read_header (line 1833)
>> unsupported header format (matlab)
>>
>> Error in ft_trialfun_general (line 71)
>> hdr = ft_read_header(cfg.headerfile, 'headerformat', cfg.headerformat);
>>
>> Error in ft_definetrial (line 169)
>>     [trl, event] = feval(cfg.trialfun, cfg);
>>
>>
>>
>>
>>  I wonder if that is as the file produced by fieldtrip during the
>> preprocessing is not one that is specified for ft_read_header - but how do I
>> deal with this?
>>
>> Thanks a lot for your help
>>
>> Katrin
>> _______________________________________________
>> fieldtrip mailing list
>> fieldtrip at donders.ru.nl
>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>
>>
>>
>> _______________________________________________
>> fieldtrip mailing list
>> fieldtrip at donders.ru.nl
>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
>
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip




More information about the fieldtrip mailing list