psychopy.org | Reference | Downloads | Github

How do stimulus durations set in seconds get rounded when converted to frames?

Hi all,

I am about to launch my first experiment and I have been thinking about how to deal with the fact that non 60Hz monitors are becoming more and more common these days. My stimuli currently vary (randomly) between 200-800ms, and I was originally going to just round them to the nearest 50/3s (one frame on a 60Hz monitor), but this wouldn’t be precise on 144Hz (or 75Hz) monitors.

In the table above you can see the nearest number of frames needed to display stimuli that increment by 50ms on 60Hz, 75Hz and 144Hz monitors. As you can see, for 60Hz monitors the durations are precise, for 75Hz they can be as much as 6.67ms off and for 144Hz they can be as much as 4.17ms off. Using 50ms increments seems like a fair compromise for me to be able to run the experiment on any monitor, as stimulus presentation durations should then differ by no more than 6.67ms between monitors (and most users will likely still be using 60Hz monitors on which the stimuli will be precisely displayed).

This assumes, however, that Pavlovia takes the stimulus duration in milliseconds and converts it to the closest number of frames (e.g. a 150ms stimulus converted to 11 frames on a 75Hz monitor, rounded up from 146.67). Does Pavlovia round frames in this way? Does it always round to the nearest frame? Always round down? Always up?

How it behaves would determine how I set the durations of my stimuli.

Thanks for reading, hope someone here can help!

I’m looking at this again and I’m realising that rounding to the nearest multiple of 16.67ms is still the most precise option… Not sure why I thought I had to round to 50. Still, does anyone know how pavlovia rounds frames to durations that are between n and n+1 frames?

1 Like

Hey! Just wanted to say your question is on my radar. However, to give a careful answer I need to ask around bit. Update later!

Hi There,

This is a good question. I just wanted to highlight a variable that I am not sure you are aware of, that could help you out a bit. You can access the frameRate of your participants monitor by calling the variable expInfo['frameRate'], you could then in theory set the duration of your stimuli to be in terms of frames rather than seconds for more precise timing control without needing to worry about how things are rounded, and you could also ensure the number of presentation frames was selected to be optimal to that setup.

More direct to your Q, I believe (although need to check) frames are usually rounded up rather than to the “closest” frame

Hope that helps!
Becca

Thanks for your reply.

expInfo[‘frameRate’] appears to be bugged - always returns 60. I used @ade_mh’s code from here: Incorrect frame rate logs on Pavlovia - #8 by ade_mh to get the actual framerates.

The reason I didn’t want to set the duration in frames is because then it would exclude anyone with monitors that aren’t 60Hz. 120, 144, even 240Hz monitors are relatively common, and I didn’t want to exclude those people from going through the study.

It’s no longer a pressing issue for me to resolve this right now, as I have decided to set the stimuli to fixed duration levels and collect their actual framerates with the code linked above, although it would still be interesting to know if frames are indeed rounded up.

That’s indeed an interesting issue, but I’m happy to read there is no hurry :slight_smile:

About expInfo['frameRate']; yes, older versions of PsychoJS would just return 60, but newer versions make an accurate estimate of frameRate.

PsychoPy and PsychoJS don’t do any conversion or rounding. If you specify the stimulus onset/duration/offset in units of time then the script (which you can read by outputting the code into either flavour) tries to determine on every screen refresh period whether it should try to squeeze in one more frame. That has the advantage that, if frames have been dropped due to lack of rendering power (meaning the frame period appears to be double the duration it should have been for that frame) then this is handled seamlessly.

But I would strongly recommend for brief stimuli that you don’t specify your stimulus in units of time, especially if you know that duration can’t be achieved on your monitor because that decision can give unpredictable results. See also Online timing: frames or time in seconds?