I am coding a task that shows images and has jittered fixation and ISI periods. I am running into an issue where the first trial in my task moves way too fast and is not accounting for the jittered time periods or the length of time the image is set to display for (4s).
The jitter code appears before the routine for the trials (which contains the fixation, image, and ISI) is run. Every other trial times just fine, but the first trial is consistently too fast. Has anyone come across this or have any suggestions on addressing this?
I am using both the builder and code in psychopy version 2023.2.2
Here is my code that jitters the timing for the fixation cross and ISI:
# Run 'Begin Routine' code from code_jitter
#Jitter for the fixation cross
jitter = round(normal(5,2),0)
while (jitter < 3) | (jitter > 7):
jitter = round(normal(5,2),0)
# Jitter of the blank screen following the image
jitTwo = round(normal(3,2),0)
while (jitTwo < 1) | (jitTwo > 5):
jitTwo = round(normal(3,2),0)
The code component is at the top of the trial routine, following a bit of code which implements some MRI-specific lines of code. The fixation and ISI then depend on jitter and jitTwo.
Here is a toy example of a jittered fixation cross and stimulus onset. Note that I use different minima and maxima and a uniform distribution instead of a normal distribution than you do. You may want to modify this part of the code to suit your needs.
Incidentally, an exponential distribution is probably the best distribution to use because the probability of the stimulus appearing does not increase with the length of the jittered interval.
@wakecarter I tried to put a new routine for a fixation cross before the trials loop, with a set display time of 2s. In my testing, this set fixation cross display time is too short, but the then the subsequent image display trials with jittered fixation and ISI are accurately timed. I wonder if there is some other cause to this?
When do you perform the calculation of your jitter? From your description, it is not in the begin routine tab?
Have a look at my toy example. This should do the job, but be sure to check the timing Note that I use a different approach to get a random number between 3 and 7, or 1 and 5 to avoid the while-loop. However, this might not have the desired distribution properties.