<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="">
Hi Team,
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">I’m having an issue with defining my trials in what I think is a very simple set up. I have ten events in a trial. They are just stimulus on for 250ms, then off for 100ms - 10 times. The first stimulus in the sequence has a trigger value of 1,
 and the rest have a trigger value of 2. The trigger is on for the duration of the stimulus.</div>
<div class=""><br class="">
</div>
<div class="">Here is my trial definition code:</div>
<div class=""><br class="">
</div>
<div class="">
<pre class="c-mrkdwn__pre" data-stringify-type="pre" style="box-sizing: inherit; margin-top: 4px; margin-bottom: 4px; padding: 8px; --saf-0:  rgba(var(--sk_foreground_low,29,28,29),0.13); overflow-wrap: break-word; font-variant-ligatures: none; line-height: 1.50001; tab-size: 4; white-space: pre-wrap; word-break: normal; background: rgba(var(--sk_foreground_min,29,28,29),0.04); border: 1px solid var(--saf-0); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; overflow-y: hidden; counter-reset: list-0 0 list-1 0 list-2 0 list-3 0 list-4 0 list-5 0 list-6 0 list-7 0 list-8 0 list-9 0; orphans: 2; widows: 2; text-decoration-thickness: initial;"><span class="" style="background-color: rgb(255, 255, 255);"><font face="Helvetica" class=""><span class="Apple-tab-span" style="white-space: pre;">       </span>cfg                         = cfgS;
    cfg.dataset                 = dataSets{d};   
    cfg.trialdef.eventtype      = 'UPPT001';
    cfg.trialdef.eventvalue     = 1; % stimulus 1
    cfg.trialdef.prestim        = 0.5; 
    cfg.trialdef.poststim       =4;
    cfg.trialdef.nTrls          = nTrls; % number of trials per block
    cfg                         = ft_definetrial(cfg);
    
    % get it
    data                  = ft_preprocessing(cfg);    </font></span></pre>
<div class=""><br class="">
</div>
</div>
<div class="">As you can see, I’m just using the generic trialfun_general function. However, for some reason the trials are being epoched according to the end of the first trigger, rather than the start. </div>
<div class=""><br class="">
</div>
<div class="">Here is a plot of the issue: the blue line is the triggers over trials 2-35 in a block across time (all plotted on top one another). The purple lines are a photodiode signal that signals when the stimulus was actually presented to screen. The
 onset of each trial is for some reason aligned with the end of the trigger corresponding to the first stimulus. Can anyone suggest why this would be the case?</div>
<div class=""><br class="">
</div>
<div class=""><img apple-inline="yes" id="E208CACD-50F6-4D13-AD93-D7882EF6AEF0" class="" src="cid:D3A1C09A-0228-43FF-80AA-44FF29170906@lan"></div>
<div class=""><br class="">
</div>
<div class="">One theory I have is because, for some also unknown reason, in the first trial of the block, the trigger is now negative, rather than positive (image below). Still, here the trials are epoched to start with the ed of the first trigger. Could it
 also have something to do with the trigger being on at the start of this trial?</div>
<div class=""><br class="">
</div>
<div class=""><img apple-inline="yes" id="4D6781E1-C009-45F6-815A-8E2CBADB464E" class="" src="cid:376EF8BD-C85D-4BCC-A9A0-5B5CDBA7B0A9@lan"></div>
<div class=""><br class="">
</div>
<div class="">Finally, how can I go about aligning the triggers and the photodiode? I.e. so that the trial onset is aligned with the onset of the first photodiode signal, but also such that the triggers are shifted to align with the photodiode signal too. So
 that, in the end, I would end up with data that had the first stimulus’ onset at time point 0, and triggers that corresponded to the exact time the stimulus was shown, as measured by the photodiode.</div>
<div class=""><br class="">
</div>
<div class="">I appreciate all your help and wisdom :)</div>
<div class=""><br class="">
</div>
<div class="">Benjy </div>
</body>
</html>