Random Timing for Stimuli

I am trying to present auditory and visual cues (clicks and black dots, respectively) in a series with an approximate stimulus time of 4 seconds, but I want to randomly vary the overall stimulus time by up to 35% each trial. How do I achieve variable stimulus timing in PsychoPy?

I have a similar situation where I set the timing in a coding component and then set the start and duration in the auditory components of the builder as variables. I make all of my stimuli in the beginning of experiment routine:

totaudidur = [0.96, 1.44, 1.92]
audi1_stim = []

clickdur = 0.010
click1 = 0.35 #start time of this component

#Loop creating all my trials
for tt in totaudidur:
        jitter = random.uniform(0.65, 1.35)
        click2 = tt*jitter+click1
        audi1_stim.append([tt,jitter,click1, click2])

I also set a trialcounter variable to set before the start of the task loop.

Then, in my sound component:

And in my end of routine, I record the specifics of my stimuli and iterate my trialcounter. For example:

thisExp.addData('total duration',audi1_stim[trialcounter][0])

trialcounter= trialcounter+1

There is probably a better way of doing the trial counter thing, but this way works for me. Also, Iā€™m working in secs but it might better to work in number of frames for the visual stim. Does this help?

1 Like

Also, there are different ways of randomizing your jitter. Personally, recommend having fixed values(ex. jitter_val = [0.65, 0.75,0.85,0.95, 1.05,1.15,1.25,1.35]) then creating your stim for each level of jitter using a for loop (similar to the one above but you would put jitter_val instead of totaudidur) and then you would shuffle your list using random.shuffle (audi1_stim).