Stimulus being displayed 1 frame too early

Hi ,

I’m new to PTB and was hoping somebody could help me figure out a perplexing timing issue. My goal is to present a new stimulus (png image) every 10 frames. The relevant part of my code boils down to what I’ve included below. In addition to the .png stimulus, I draw a small white rectangle in the corner of the screen to trigger a photosensor connected to a BlackBox Toolkit. The timing as recorded by Screen(‘Flip’) is exactly what I’d expect ; the time stamp indicates that there is 167 ms between each vbl. But the external photodetector reports that on some trials the flip occurs too EARLY . For example, on a test of 240 trials I found that 202 trials had an SOA of 167 ms, whereas 38 had an SOA of 150 ms. This has me very confused. It’d make sense if there was something with my hardware or in my code that led to dropping a frame and increasing the SOA, but I can’t figure out how/why the stimulus is occasionally displayed a frame too early.

I’m using PTB3 (MATLAB 2021a) on a Windows 10 machine with an NVIDIA GeForce GTX 1080 GPU.

Thanks in advance for any assistance.
-Andrew

p.ifi = Screen('GetFlipInterval', wPtr);        % monitor flip interval
p.cush = p.ifi * .5;                            % set 1/2 interval
p.imageInterval = p.ifi * 10;                  % @60Hz = 167 ms
p.soa = p.imageInterval - p.cush;              % @60Hz = 167 - 8 ms (between 9th and 10th refresh)

for stimi = 1:240
% Present the stim with the white box for the first 5 frames
    Screen('DrawTexture', wPtr, imageTex{{stimi}, [], dstRects(stimi), 0);    % Draw face to buffer
    Screen('FillRect', wPtr, [1,1,1], p.optoBox);    % Draw photodiode box to buffer
    Screen('DrawingFinished', wPtr);
    [vbl] = Screen('Flip',  wPtr,  vbl + p.soa);    % Present stimulus
    p.vbltimes(stimi) = vbl;

% Present the stim without the white box for the last 5 frames
    Screen('DrawTexture', wPtr, imageTex{{stimi}, [], dstRects(stimi), 0);    % Draw face to buffer
    Screen('FillRect', wPtr, [0,0,0], p.optoBox);    % Draw photodiode box to buffer
    Screen('DrawingFinished', wPtr);
    Screen('Flip',  wPtr,  vbl + (p.soa/2));    % Present stimulus
end % End of trial loop

You did mention in that other thread that you are switching from macOS to Windows and may eventually switch to Linux. Why not immediately switch to Linux for a better life?

Especially if you care about precise visual timing, Windows won’t be much of a step up compared to macOS.

Wrt. your problem, Windows-8 and later are known to be problematic/fragile/buggy for timing under various conditions, especially for multi-display setups, HiDPI displays, Intel graphics, multi-gpu systems. I’m not aware of NVidia OpenGL timing bugs for simple single display / gpu setups atm., but i know that NVidia Vulkan timing is broken and one frame too early on my GeForce GTX 1650, so maybe some other NVidia gpu’s or specific Windows-10/11 releases also have broken timing under OpenGL. PTB can’t detect all cases of bugs on Windows. Ofc. NVidia hardware is also not recommended on Linux if avoidable, but if you don’t need high performance - and your code suggests just simple image presentation - the standard, installed by default, open-source nouveau driver should do a good job at timing with ok performance, and even with the proprietary NVidia driver, diagnostic of problems is still better than on Windows/macOS.

You should add a vbl = Screen(‘Flip’, wPtr); before the start of your for-loop though, otherwise the baseline for your first trial will be wrong and at least one timing glitch out of 240 is fully expected.

Thanks, Mario. I actually have Pop!_OS installed as a dual boot OS on the Windows machine. I spent a little bit of time today giving that a shot, but couldn’t get NeuroDebian and/or PTB3 installed due to unmet dependencies. I’m typically a macos user and so it doesn’t take much to feel out of my depth when using linux, and I won’t have the time to wrestle with the installation until after the semester. In the meantime, I’ll wring whatever I can out of the Windows machine and just live with it displaying a subset of the stimuli prior to the Screen Flip.

Pop!_OS is not officially supported or tested by us or NeuroDebian, but I thought i read that as a Ubuntu derivative, it does allow access to standard Ubuntu repos? If so, you could probably sudo apt install octave-psychtoolbox-3 to get the octave version of PTB from the standard Ubuntu repos, although a rather outdated 3.0.16 version, and then use DownloadPsychtoolbox as usual to get the latest PTB from us? Installing a PTB from the repository should probably provide most required dependencies for most bread and butter stuff, at least if this is Pop os 20.04. Our setup routine also prints some list of required dependencies for manual install in case something fails.

It would be interesting to know what those dependencies were if you still have that info?

Rather than troubleshoot the older version of POP_OS, I did a clean install of Ubuntu 20.04 and PTB3-matlab from NeuroDebian and everything is working great! The issue with the stimuli occasionally appearing one frame too early was definitely Windows related. Running PTB3 from Ubuntu on the same hardware gives me the timing I expect. That is, using the code I included earlier in this thread, the new stimulus is displayed every 10th frame without fail. I ran a test of 1680 trials and found that the stimulus was displayed at the expected time in 100% of the trials.

For what it’s worth, the unmet dependency error was referring to ‘neurodebian-popularity-contest’, but I believe the heart of the issue was that POP_OS changed the location of their repositories and so calls to retrieve other packages were failing.

1 Like