Presenting stimuli and randomising interstimulus interval for a duration of 40 seconds

Hello everyone,

First time using psychopy but looks reallly cool!

I would like to present a 0.2s stimulus every 6-10 seconds for a total duration of 40 seconds (the duration of a video I am showing on screen).

Now I created the 6-10 seconds stimulus presentation randomiser by creating a code object and including the following code

interstimulus_interval_randomiser_audio = randint(low = 6, high = 10) # choose a value
thisExp.addData('interstimulus_interval_randomiser_audio', interstimulus_interval_randomiser_audio) # record it in the data file

I then call $interstimulus_interval_randomiser_audio at the start box of my auditory stimulus object. My question is how do I loop this stimulus presentation->randomised ISI (6-10s)->stimulus presentation->… for the duration of my video object (40 seconds video)

Hi There,

You are on the right lines for sure! What makes this a bit tricker is that you want a component to be presented multiple times within the same routine as a the video. So, there are 2 solutions:

  1. add multiple sound components each with its own predetermined onset
  2. do this in code (which I think is the approach you might prefer here!)

For solution 2, you would use the code you have but with a few more considerations. On each frame within the routine we want to detect a) is the tone currently being presented and b) are we currently waiting for a tone to be presented c) if neiter a nor b let’s pick an interval to wait then present the tone (and do this continuously whilst our trial is going on in the background.

Since there are a couple of bits of code here, here is a demo to help you on your way. A tone is presented every 3-5 seconds on a lop for the duration of a 10 second long trial.

toneRandom.psyexp (9.2 KB)

Hope this helps,
Becca

1 Like

Fantastic, thank you very much Becca for your help! I’ve now modified your code to the ISI and trial duration that is applicable to our experiment. Final question, what lines of code should I add for doing the exact same thing but with a picture stimulus?

For a picture, you would replace the initial creation of the sound component with an image (ImageStim — PsychoPy v2021.2) and replace instances of .play() with .draw() (you also wouldn’t need things like .stop() for an imagestim.

Hope this helps!

Becca

PS. As you mention you are new to psychopy, heres something that might be useful. If you want to learn more about the code underlying a component or python in general. Make it in builder, then click compile to code Screenshot 2021-01-21 174202 then search the name of your image component in the coder window that opens! More details here Extending Builder with code — Workshops for PsychoPy 2020 2020

Thank you very much Becca for your help! Got everything to work as intended except for a new issue where the video I’m playing is always infront of the image (brief distractor) I’m trying to display. Any idea how to fix this?

Make sure your video is above your image in the components within the routine (right click > move up). If it isn’t this it’s probably a different issue, so please could you mark the solution for this thread then start a new topic :blush:

Becca