FrameRate variable vs calculated refresh rates discrepancy

Hi,

I have an online experiment that features a stimulus whose duration is specified in frames (long story short: precise timing needed).

I know that PsychoPy automatically calculates the frame rate and saves this to a frameRate variable, but being paranoid, I also used a piece of code to manually calculate the frame rate:

begin routine:

frame_count = 0;
duration_clock = new util.Clock();
frame_times = [ ];

each frame:

if ((frame_count > 0)) {
    frame_times.push(duration_clock.getTime());
    duration_clock.reset();
}
frame_count += 1;

end routine:

average_refresh_time = ((util.sum(frame_times) / frame_times.length) * 1000);
psychoJS.experiment.addData("AVG_refreshdur", average_refresh_time);
approx_frame_rate = (1000 / average_refresh_time);
psychoJS.experiment.addData("AVG_refreshrate", approx_frame_rate);

The problem now is that the frame rate automatically calculated by PsychoPy and the frame rate calculated in my own code don’t always agree:

As can be seen in the figure, often both frame rates are close, but there are notable instances were they deviate quite a bit, which in turn has not insignificant consequences when using the frame rate to determine stimulus presentation durations.

Does anyone know what may be going on here? More importantly, which of the frame rates should I trust more - the one automatically calculated by PsychoPy, or my own manually calculated one?

Best wishes,

Bianca

Hello @bianhaan

You figure is missing the axis labels. Am I right in assuming that the y-axis is the frame-time? What is the x-axix, trial-number?

I might be wrong but I think that PsychoPy calculated the frame rate only once.

  // store frame rate of monitor if we can measure it successfully
  expInfo['frameRate'] = psychoJS.window.getActualFrameRate();
  if (typeof expInfo['frameRate'] !== 'undefined')
    frameDur = 1.0 / Math.round(expInfo['frameRate']);
  else
    frameDur = 1.0 / 60.0; // couldn't get a reliable measure so guess

Am I right?

I tested the frame rate for an online exeriment and noticed, unfortunately after data collection, that the frameRate can vary from trial to trial. I then continued testing on a win11 pc and a mac mini. The win 11 pc varied between 59 Hz and 60 Hz which I would not care about. The mac was more variable.

The programmers should be able to tell us whether PsychoPy requests the frame rate only ocne or for each trial.

Best wishes Jens

The x-axis is different participants - sorry, should have stated that.

My code also only calculates the frame rate once at the beginning of the experiment, but I suppose given that the inbuild PsychoPy routine and my routine calculate the frame rate at different time points, large differences in frame rate over time could account for the difference…

In terms of Windows vs Mac, there was not much of a difference: counting the participants where the difference between the PsychoPy frame rate and my frame rate was more than 5Hz, 8 were Windows OS and 7 were Mac OS (out of 53 participants in total).

Hello @bianhaan

I observed a difference in frame rate of 5 Hz between trials on the two Macs, but not on the two Windows PCs I used for testing. PsychoPy also reports the operating system provided by the browser. Do you notice the greatest differences on Macs?

Best wishes Jens

The absolute difference (in Hz) between frame rate calculated by PsychoPy and frame rate calculated by my code was 4.10 (stdev 5.65) for Windows and 5.75 (stdev 9.23) for Mac.

So does seem that average deviation and range of deviation are somewhat larger for Macs than Windows PCs