# Incorrect frame rate logs on Pavlovia

**URL:** <https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255>\
**Category:** Online experiments\
**Tags:** timing, pavlovia\
**Created:** [July 23, 2020, 4:40pm UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255 "2020-07-23T16:40:49Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ade\_mh](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@ade\_mh](https://discourse.psychopy.org/u/ade_mh)\
**Post date:** [July 23, 2020, 4:40pm UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255/1 "2020-07-23T16:40:49Z")

</div>

Description of the problem: I am running an online study on Pavlovia in which I need to present images for the very short duration of 16.6ms (rounded to 17ms). I also need the refresh rate of the monitor.

The problem is, I have been told that some of the refresh rates that were logged in the .csv output are not the same as the real refresh rate - all the logs say 60Hz but some monitors were in fact e.g. 144Hz. I see in the JS file that:

```auto
> // 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

```

which I presume means that in my data the refresh rate either really is 60Hz, or it could not be measured successfully so it was guessed.

I also looked at the .log files, and calculated logged duration of each image by subtracting the timestamp of ‘autoDraw = False’ from ‘autoDraw = True’ in each trial, and I get a very variable distribution of durations (from 0ms to about 25-30ms), which does not peak at 17ms (but at about 11-13ms). This happens regardless of whether I set the experiment settings to display the image for 1 frame (on confirmed 60Hz monitors) or 17ms. Interestingly, I also present a blank screen for 17ms, and in this case the distribution of the onset-offset differences peaks at 17ms, with much less spread. Other images presented for 2000ms also show peaks at the expected value, and little spread.

My questions would be:  
-how could I make sure that the logged refresh rate is correct?  
-if I want to clean the data by excluding trials with frame drops/gains, which would be the best approach given the available data and taking into account measurement error?

Any help would be much appreciated!

---

<div class="post-metadata">

**Author:** ![niclai](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/niclai/32/4405_2.png) [@niclai](https://discourse.psychopy.org/u/niclai)\
**Post date:** [July 24, 2020, 11:31am UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255/2 "2020-07-24T11:31:45Z")

</div>

I don’t think the `getActualFrameRate()` does anything at all. This is the source code ([https://psychopy.github.io/psychojs/core\_Window.js.html](https://psychopy.github.io/psychojs/core_Window.js.html)) of that function. No idea if it is possible to get the refresh rate of screens online.

```auto
	/**
	 * Estimate the frame rate.
	 * 
	 * @name module:core.Window#getActualFrameRate
	 * @function
	 * @public
	 * @return {number} always returns 60.0 at the moment
	 * 
	 * @todo estimate the actual frame rate.
	 */
	getActualFrameRate()
	{
		// TODO
		return 60.0;
	}

```

---

<div class="post-metadata">

**Author:** ![ade\_mh](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@ade\_mh](https://discourse.psychopy.org/u/ade_mh)\
**Post date:** [July 27, 2020, 11:08am UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255/3 "2020-07-27T11:08:22Z")

</div>

ah okay, I see, that makes sense… Thank you very much for pointing this out!

I see online some suggestions of using the JS function requestAnimationFrame, however I am not sure how/if it is possible to integrate it with PsychoJS…

---

<div class="post-metadata">

**Author:** ![ade\_mh](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@ade\_mh](https://discourse.psychopy.org/u/ade_mh)\
**Post date:** [August 6, 2020, 6:49pm UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255/4 "2020-08-06T18:49:51Z")

</div>

I have tried (unsuccessfully) to use a separate JS function called requestAnimationFrame, as described here: [https://stackoverflow.com/questions/6131051/is-it-possible-to-find-out-what-is-the-monitor-frame-rate-in-javascript/44013686](https://stackoverflow.com/questions/6131051/is-it-possible-to-find-out-what-is-the-monitor-frame-rate-in-javascript/44013686)

This code below returns a value, but it’s clearly incorrect - I don’t really know JS but I am posting it below in case anyone can spot any errors:

```auto
if (!window.requestAnimationFrame) {
    window.requestAnimationFrame =
        window.mozRequestAnimationFrame ||
        window.webkitRequestAnimationFrame;
}

var t = [];
function animate(now) {
    
    t.unshift(now);
    if (t.length > 10) {
        var t0 = t.pop();
        var fps = Math.floor(1000 * 10 / (now - t0));
    }
    window.requestAnimationFrame(animate);
};
window.requestAnimationFrame(animate);
var frRate = window.requestAnimationFrame(animate); 
expInfo['realFrameRate'] = frRate;

```

---

<div class="post-metadata">

**Author:** ![thomas\_pronk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/thomas_pronk/32/9531_2.png) [@thomas\_pronk](https://discourse.psychopy.org/u/thomas_pronk)\
**Post date:** [August 6, 2020, 8:20pm UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255/5 "2020-08-06T20:20:59Z")

</div>

Try averaging them out over, say 60 frames: record time at first one, and at 61th one, then dive divide time difference by 60. Also, after you’re done with your measurement, be sure to stop calling rAF again, so it doesn’t get in the way of your actual experiment.

---

<div class="post-metadata">

**Author:** ![ade\_mh](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@ade\_mh](https://discourse.psychopy.org/u/ade_mh)\
**Post date:** [August 6, 2020, 8:48pm UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255/6 "2020-08-06T20:48:54Z")

</div>

Hello, thank you very much for the suggestions! The value that I get in the logs are three digits (for my 60Hz monitor, it logged on three separate occasions 869, 737, and 1232), I am not sure at all why.  
I call this in the beginning of a routine in the instructions part of the experiment, and everything afterwards looks exactly as before, so I would guess the call stops at the end of the routine.

---

<div class="post-metadata">

**Author:** ![thomas\_pronk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/thomas_pronk/32/9531_2.png) [@thomas\_pronk](https://discourse.psychopy.org/u/thomas_pronk)\
**Post date:** [August 6, 2020, 10:02pm UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255/7 "2020-08-06T22:02:42Z")

</div>

I made a little demo for you. Clone and run this experiment:  
[https://gitlab.pavlovia.org/tpronk/demo\_refresh\_rate](https://gitlab.pavlovia.org/tpronk/demo_refresh_rate)

On my 143 Hz screen (~7 ms per refresh) I get a duration per frame of indeed 7 ms.

---

<div class="post-metadata">

**Author:** ![ade\_mh](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@ade\_mh](https://discourse.psychopy.org/u/ade_mh)\
**Post date:** [August 7, 2020, 11:09am UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255/8 "2020-08-07T11:09:33Z")

</div>

This works perfectly, thank you very much for the help!  
I tweaked it a little bit to change how the values are logged, I’ll post below what I ended up adding to my Instructions routine (which is mostly your code), in case anyone else needs it - the difference here I guess is that the interval for averaging is variable e.g. for as long as the routine is viewed:

Begin Experiment:

```auto
window.refreshCount = 0;
window.refreshStart = null;
window.refreshFinish = null;

```

Each Frame:

```auto
    if (window.refreshStart === null) {
        window.refreshStart = window.performance.now();
     } else {
        window.refreshFinish = window.performance.now();
        window.refreshCount++;    
     }

    console.log(window.refreshCount);
    console.log(window.performance.now());

```

End Routine:

```auto
let duration = window.refreshFinish - window.refreshStart;
expInfo['realFrameRate'] = (duration / window.refreshCount);

```

---

<div class="post-metadata">

**Author:** ![thomas\_pronk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/thomas_pronk/32/9531_2.png) [@thomas\_pronk](https://discourse.psychopy.org/u/thomas_pronk)\
**Post date:** [August 7, 2020, 11:47am UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255/9 "2020-08-07T11:47:11Z")

</div>

Happy it works and thanks for contributing your version!

---

<div class="post-metadata">

**Author:** ![filippogambarota](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/filippogambarota/32/8131_2.png) [@filippogambarota](https://discourse.psychopy.org/u/filippogambarota)\
**Post date:** [February 16, 2021, 11:12am UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255/10 "2021-02-16T11:12:28Z")

</div>

Hi Thomas! your demo is very useful to me! I’m just wondering the difference between the two logged values and if it works only for a 30hz screen. Because I have tried on a 30hz screen and the returned value is still ~16ms

---

<div class="post-metadata">

**Author:** ![thomas\_pronk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/thomas_pronk/32/9531_2.png) [@thomas\_pronk](https://discourse.psychopy.org/u/thomas_pronk)\
**Post date:** [February 28, 2021, 2:21pm UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255/11 "2021-02-28T14:21:44Z")

</div>

Hey!

Sorry for the slow reply. As far as I know it should also work with 30Hz; I myself tested it on a 75Hz screen.

Best, Thomas

---

<div class="post-metadata">

**Author:** ![Georges\_Abitbol](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/georges_abitbol/32/36666_2.png) [@Georges\_Abitbol](https://discourse.psychopy.org/u/Georges_Abitbol)\
**Post date:** [January 17, 2023, 10:32am UTC](https://discourse.psychopy.org/t/incorrect-frame-rate-logs-on-pavlovia/15255/12 "2023-01-17T10:32:22Z")

</div>

Hi guys, @ade_mh @thomas_pronk  
I am a beginner on PsychoPy and I can’t seem to find the way to set up the duration of a mask.  
Can anyone of you be of help?  
Thanking you in advance
