| Reference | Downloads | Github

Jitter ITI duration using Code Component in Frames

PsychoPy version Standard Standalone
I am working on a project using the builder for ERP research, and I am trying to jitter the timing of an ITI in frames. I have done this before using a conditions file before and pseudorandom jittering, but I would really like to make a code component that gives a window and the duration of the ITI is completely random within that window.

I have made a code component for a random ITI before, but again this was using a millisecond window.

Is it possible to do this in frames?

Thank you!

Yes, you just need to get random numbers that are integers. Builder imports the randint() function from numpy.random, which is suitable for this purpose:

For example, put code like this in the Begin experiment tab:

# define whatever parameters are relevant to you:
min_duration = 10 # number of frames
max_duration = 60 # e.g. 1 second at 60 Hz
number_of_trials = 100 # number of ITIs needed

# get an array of random integers:
ITIs = randint(low= min_duration, high=max_duration + 1, size=number _of_trials)

# convert from a numpy array to a standard Python list if preferred:
ITIs = list(ITIs)

And then at the beginning of every trial, you’ll need to get the next ITI value for use, so put this in the Begin routine tab:

# get the next ITI (assuming they are in a list):
current_ITI = ITIs.pop()

# manually record the ITI in the data for this trial:
thisExp.addData('ITI', current_ITI)

Put this code component above any other components that need access to the current_ITI variable, so that it gets updated prior to being used by them. Then just put $current_ITI in the frame duration field(s) of any relevant component(s) (and set that field to update on every routine).

1 Like