Troubles with inter-frame interval

Hello there. I recently moved to a new computer that has Windows 11 installed, and NVIDIA GeForce RTX 4070 as GPU. I’m using PTB for a passive-viewing experiment where I just show some pre-programmed movies. Each movie consists of 120 frames, which I present to a 60 Hz Philips 273V monitor, 1080x1920 resolution. This is my main monitor. Besides of this monitor I have another one that I use for running Matlab, interacting with its environment, running other software, etc…, but not for stimulus presentation. Here’s what happens, with a snippet of a code I use (comments are useful, especially in the final ‘DrawTexture’ part):

% initialization
Screen('Preference', 'SkipSyncTests', 0);
oldLevelVisual = Screen('Preference', 'VisualDebugLevel', 3);
oldLevelVerbosity = Screen('Preference','verbosity',0);

win = Screen('OpenWindow',1); 

% create textures
for ff=1:length(file_list)
    this_file = fullfile(file_list(ff).folder,file_list(ff).name);
    this_png = imread(this_file);
    textures(ff) = Screen('MakeTexture',win,this_png);
end

% inter-frame interval
wait_time = Screen('GetFlipInterval',win,1000);

% this part is just for a single movie presentation, but consider 
% I have a sequence with many of them 
for frame=1:length(textures)
Screen('DrawTexture',win,textures(frame))
vbl=Screen('Flip',win,vbl(end) + wait_time);
end 

Together with this code I have some few lines (not shown) that allow me to keep track of the actual timing between each frame and the next one, and store this information within a vector. This is used to later check that the period between each frame matches exactly the refresh rate of my main monitor (the one from where I present the stimuli). However, sometimes when I run this code I get a jitter in the recorded inter-frame interval (i.e., some frames last 0.01667 sec - 1/60Hz -, which is the period I want, but many others have different durations, so it’s not stable). On top of this problem theres’s another one: after I run the code and display the movies, interacting with the computer via the second monitor (for example running another software for brain recording) causes an immediate change in the inter-frame interval, which shortens the stimulus duration from 2 seconds to 1.3 seconds (this is also revealed in the vector storing the inter-stimulus interval, mentioned a few lines back).

I have no clue of what is happening. I had a look at the PTB SyncTrouble help page, but I failed to see systems bugs. The only thing which was recommended from the help file was to keep the “Vertical Sync” setting of my GPU to “Application controlled” or “Application controlled, default to on”, but I don’t have that option (so I’m keeping it to “on”).

Any help would be much appreciated!

What happens if you use the second screen for PTB and the main screen for MATLAB GUI? Have you updated drivers etc.?

Are you counting frames to compute your stimulus duration, or measuring absolute time?

As usual, windows + Nvidia is not a good combination if you need timing precision, on my systems, high-end NVidia GPU + Windows is totally unusable whereas switching to a less powerful AMD card and dual-booting to Linux on the same computer gives me a rock-solid PTB…

This is suboptimal for stable frame timing, either not defining the tWhen or vbl + 0.5 * wait_time would be a good choice. Cfe. our various timing demos and docs.

What you describe is fully expected and to my knowledge not fixable on Microsoft Windows with multi-display setups, due to limitations of the MS-Windows operating systems display stack. See the following excerpt from help SyncTrouble:

“On MS-Windows, you will suffer drastic timing problems if the stimulus
presentation window loses the “keyboard focus”. The window with the
“keyboard focus” is the one which is in the foreground (in front of all other
windows), has its titlebar highlighted instead of shaded (assuming it has a
titlebar) and receives all keyboard input, i.e., key presses. Therefore we
assign “keyboard focus” to our onscreen windows automatically. However, if the
user clicks into windows other than our window with the mouse, or onto the
desktop background, or uses key combos like ALT+TAB or Windows+TAB to switch
between windows, then our window will “lose” the keyboard focus and severe
timing and performance problems may occur. If any window on the screen is
highlighted, this means it has stolen the keyboard focus from our window.
This weird keyboard focus problem is an unfortunate design decision (or rather
design flaw) of the MS-Windows graphics subsystem. There isn’t anything we or
the graphics cards vendors could do about it, so you’ll have to accept it and
work around it. Of course this becomes mostly a problem on multi-display setups
where one display shows the desktop and GUI, and others show Psychtoolbox stimuli,
so avoid such configurations if you can.”

The advice is to use a single display setup only, or avoid touching keyboard and mouse / interacting with any other software or the GUI if you need multi-display, or upgrade to Linux where such problems don’t exist. Except that NVidia cards like yours are not recommended for Linux, and the worst choice for good timing, although they tend to be often still better on Linux than on Windows or macOS, and at least PTB is better at diagnosing timing trouble with them on Linux due to superior infrastructure. It is all clearly stated in our hardware recommendations on our website.

-mario