PTB: 3.0.19
Matlab R2022a
Linux Ubuntu 20.04
Stim timing issue: event code sometimes precedes visual stimulus, sometimes follows it.
Hello,
I was hoping someone might have some helpful insight regarding a timing issue we’re having with an EEG (Biosemi ActiveTwo) experiment. The experiment entails simple presentation of image files (jpg). To ensure accurate timing, we have a BlackBox Toolkit (BBTK) photosensor on the display screen detect a white box that is presented simultaneously with the stimulus.
We have found that the timing of the experiment is quite variable, and sometimes in completely perplexing ways. The code is written such that the stimulus screen is flipped to present the stimulus and white box, then the next line of code sends the stimulus to our Labjack device. The Labjack sends the digital event code to the BBTK, which then sends the code to our EEG acquisition system.This is a snippet of the relevant code:
% Draw face frame
Screen('FrameRect',winPt, [0, 0, 0], p.frameBox, frame_width);
% Draw question prompt
DrawFormattedText(winPt, line1,'center', p.centerY+200, white);
% Draw white opto box
Screen('FillRect', winPt, white, p.left_optoBox); % draw box for opto sensor
Screen('FillRect', winPt, white, p.right_optoBox); % draw box for opto sensor
% Draw stimulus (trialTex is defined at the start of the trial and pulled from a structure that contains all of the stimuli that were preloaded at the start of the experiment)
Screen('DrawTexture',winPt,trialTex,[],p.stimBox);% draw texture data to create pictures
Screen('DrawingFinished', winPt); % indicate drawing to the buffer is complete
% Show the picture
[stimOn_VBLTime(trial_n), stimOn_StimulusOnsetTime(trial_n), stimOn_FlipTimestamp(trial_n), stimOn_Missed(trial_n), stimOn_Beampos(trial_n)] = Screen('Flip', winPt, stimOn_sched(trial_n));
lj.setDIO(imageID_dio); % send labjack code.
Given our code, we would expect to record the stimulus event code (e.g., “1”) followed ~8 ms later by the photosensor code (“512”). Note: though the code is written so that the image is flipped prior to the Labjack code being sent, we expect ~1/2 a refresh cycle (16.67 ms) to elapse before the optical sensor is trigged because the sensor is physically located halfway down the screen.
The timing described above is what we see for several of our participants. However, for many others there is a longer delay (20-35 ms) between the timestamps of the Labjack event code and the optical sensor code. I thought that this was most likely due to a computer slowdown that caused the flip to be delayed by a refresh cycle or two. However, the latency is not always a multiple of the refresh rate and the delay is more or less consistent for a given participant. That is, when the latency is longer than expected, it’s generally the same longer latency for all trials for that participant. Moreover, for some participants the optical code appears simultaneously with the Labjack code, or for some other participants even several ms prior(!?). Again, these latency differences occur almost entirely across participants. Within a given participant the timing is usually pretty consistent; albeit consistently perplexing.
If anyone has any thoughts or is intrigued by the issue, I’d be happy to share additional info (e.g, timing files, our full PTB code)
Thanks very much in advance!
-Andrew