<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<font size="4" class="">Dear Marcel,</font>
<div class=""><font size="4" class=""><br class="">
</font></div>
<div class=""><font size="4" class="">This looks good, indeed. To be sure about this, you can check the first elements in each of the trials’ corresponding time vectors. These now should be the negative of the trial specific reaction time: data.time{i}(1) ~=
 -movement_rt_inseconds(i); (give or take a sample)</font></div>
<div class=""><font size="4" class=""><br class="">
</font></div>
<div class=""><font size="4" class="">Best wishes,</font></div>
<div class=""><font size="4" class="">Jan-Mathijs</font></div>
<div class=""><font size="4" class=""><br class="">
</font></div>
<div class=""><font size="4" class=""><br class="">
</font></div>
<div class=""><font size="4" class=""><br class="">
</font>
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 7 May 2020, at 01:50, Marcel van den Velde <<a href="mailto:marcel.van.den.velde@gmail.com" class="">marcel.van.den.velde@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">
<div class="">Dear all,<br class="">
<br class="">
I am doing a MEG analysis on hand movement preparation: subjects are presented with visual stimuli (coded in the trigger channel) and have to respond by moving their hand. The study requires that I investigate the ERFs prior to the movement onset (but not capturing
 anything pre-stimulus). How can I best move the 0 point from stimulus onset to movement onset and look back?<br class="">
<br class="">
What I have now is the following, but I am not sure whether this is correct:<br class="">
<br class="">
First a trial definition calling an own function and an own added field to assign the response time (cfg.trialdef.rt)<br class="">
<br class="">
        % trial definition <br class="">
        cfg = [];<br class="">
        cfg.dataset = subject_meg_data;<br class="">
        cfg.trialfun = ‘trialfun_move’;                           % <— own function<br class="">
        cfg.trialdef.rt = movement_rt_inseconds;       % <— own field, to pass RTs on<br class="">
        cfg.trialdef.eventtype  = 'UPPT001';<br class="">
        cfg.trialdef.eventvalue = [1:32];<br class="">
        cfg = ft_definetrial(cfg);<br class="">
<br class="">
With as function:<br class="">
<br class="">
function [trl, event] = trialfun_move(cfg)<br class="">
<br class="">
        % read header information and events from dataset<br class="">
        hdr   = ft_read_header(cfg.dataset);<br class="">
        event = ft_read_event(cfg.dataset);<br class="">
<br class="">
        % search for events of interest, get value and sample<br class="">
        value  = [event(find(strcmp(cfg.trialdef.eventtype, {event.type}))).value]';<br class="">
        sample = [event(find(strcmp(cfg.trialdef.eventtype, {event.type}))).sample]';<br class="">
<br class="">
        % define trial: starts at picture onset, stops at movement onset (response)<br class="">
        trl_begin = sample;<br class="">
        trl_end   = sample + round(cfg.trialdef.rt * hdr.Fs);<br class="">
        offset    = repmat(0, numel(value), 1);<br class="">
        trl       = [trl_begin trl_end offset value cfg.trialdef.rt];<br class="">
<br class="">
end % end function<br class="">
<br class="">
The trial definition block is then followed by preprocessing and moving the 0 time point from picture onset to movement onset using ft_redefinetrial:<br class="">
<br class="">
        % preprocessing<br class="">
        cfg.channel = {'MEG'}; <br class="">
        cfg.continuous = 'yes'; <br class="">
        cfg.bpfilter = 'yes'; <br class="">
        cfg.bpfreq = [1 30];<br class="">
        data = ft_preprocessing(cfg);<br class="">
<br class="">
        % shift 0 time point from picture to movement onset<br class="">
        cfg = [];<br class="">
        cfg.offset = - round(movement_rt_inseconds * data.fsample);<br class="">
        data = ft_redefinetrial(cfg, data);<br class="">
<br class="">
Is this a correct approach, and am I correct in assuming that with this last step, the 0 time point is now correctly shifted from picture onset to movement onset, as the first sample is defined to be minus RT earlier than the 0 time point? Is there a way to
 check this in the data structure? Thanks for any help.<br class="">
<br class="">
Best regards,<br class="">
</div>
<div class=""></div>
<div class="">Marcel</div>
</div>
_______________________________________________<br class="">
fieldtrip mailing list<br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br class="">
https://doi.org/10.1371/journal.pcbi.1002202<br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>