kurokida / jspsych-psychophysics

A jsPsych plugin for psychophysics
https://kurokida.github.io/jspsych-psychophysics/
MIT License
51 stars 13 forks source link

Define sequence of stimulus and indicate duration in both ms and frames #32

Closed ffigari closed 2 years ago

ffigari commented 2 years ago

Hi, I have a scenario in which I need to specify a sequence of stimulus and then finish the trial. It seems to me that psychophysics' stimulus are meant to be independent but maybe there is some way of doing this.

My scenario is analogous to the following timeline:

Two timing issues appears when I try to implement this.
On one hand, I don't find a way to specify when the second cross should start to be shown. I would like to define stimulus times using both ms and frames (~ start time = 500 ms + 3 frames) but I have to choose one or the other. On the other hand, neither do I see how to correctly finish the trial after 1000 ms and 3 frames. I can use response_ends_trial = false to indicate I don't expect a response from the user, but then I have no way of indicating the total time. Doing trial_duration = 1000 ms + 3 frames would be ideal but I'm guessing that could conflict with JSPsych in some way.

In the real case scenario we chose to define times in milliseconds so I'm opening this more out of curiosity than anything else.
Thanks, Francisco.

kurokida commented 2 years ago

Thank you for using my plugin. As you expectected, you have to specify time in either milliseconds or frames. You can't mix the two. Since 3 frames are consistent with 50 ms, you can spcefity the duration as trial_duration: 1050. Note that you can specify time in frames about stimulus and time in milliseconds about the trial_duration property.

ffigari commented 2 years ago

Since 3 frames are consistent with 50 ms

This is most probably computer dependent. If I had a good estimate for the relation between frames and time I could use that when setting up the trial_duration. It could still happen that I don't exactly the amount of frames I want

kurokida commented 2 years ago

You are right, but note that if you specify the time of 50 ms, the program will not necessarily present the stimulus for 50 ms. Technically speaking, all programs have a loop function that depends on the refresh rate, i.e., requestAnimationFrame. In the loop, the program checks whether the current time exceeds the time you specified or not.

If the program runs on a display which has a refresh rate of 75 Hz, 2 frames and 3 frames are consistent with about 40 ms and 53 ms, respectivey. If you specify the duration of 50 ms, the presentation time would be about 53 ms (3 frames). In other words, the actual presentation time will extend slightly longer than the time you specify.

If you specify time time in frames, the presentation time varies from computer to computer. I think this variation is not desirable in a normal experiment. My plugin allows you to specify the stimulus presentation time in frames, but I feel that for most experiments this is not necessary.

ffigari commented 2 years ago

Ok agreed, js makes it already hard to be precise

ffigari commented 2 years ago

Hi @kurokida, I digged a bit deeper and turns out the drawFunc already receives the elapsed time and the amount of frames. That would allow me to check both time and frame values when drawing a stimuli. I could for instance check if elapsedTime > 1000 and then manually count three frames following the example above. This does not solve the issue about the trial total trial_duration even though it can be enough in some cases. But anyway, I opened a short PR to update the docs of drawFunc. Bests, Francisco.