Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Timing Coroutines

Hi everybody,

I implemented a 2-back task (Modelled after Gajewski 2018), using coroutines. The experiment works and responses are collected correctly.

However I am having trouble with timing: the experiment takes roughly 40 seconds longer than it is supposed to. I already tried changing the back-end settings an implementation of the inline script mentioned in the manual. I also tried to perform the same experiment in sequence (where coroutines are used within each trial), but this did not reduce the timing error.

I think the timing issue is related to the generation of the sketchpatches ([stimulus] which is defined in the block loop). Is there a way to prepare the sketchpatches before showing?

I am new in python programming, making an inline script is not that easy for me...


Thank you in advance!


kind regards

Comments

  • Hi @Mira ,

    You cannot reduce the preparation time (although it varies depending on the backend, so you could try another backend to see if that reduces it). But you can reduce the variability of the preparation time, so that you can better control how long the experiment takes. To do so, you can add an inline_script to the start of the trial_sequence. In the Prepare phase, note when the preparation starts:

    prepare_onset = clock.time()
    

    Then, in the Run phase, calculate how long the Prepare phase of all items in the trial_sequence took, and subtract this value from a fixed intertrial interval (ITI ). Of course, this interval should be a bit higher than the maximum prepare duration that you see in your experiment, because you can only make the intertrial interval longer, not shorter!

    ITI = 1000  # Fixed intertrial interval
    run_onset = clock.time()
    prepare_duration = run_onset - prepare_onset
    print('prepare duration: {}'.format(prepare_duration))
    if prepare_duration > ITI:
        print('Warning: preparation took longer than ITI')
    else:
        clock.sleep(ITI - prepare_duration)
    

    An even fancier solution is to determine beforehand exactly when each trial should start, and then wait at the start of the trial_sequence until that moment. With such 'non-slip timing' you have perfect control over the duration of the experiment; but this is generally only useful in an fMRI experiment.

    Cheers,

    Sebastiaan

Sign In or Register to comment.