Howdy, Stranger!

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

Supported by

Inline code keyboard response code automatically sets the end of the trial

Hey everyone,

I'm currently working on programming an fMRI task that involves a jittered ITI lasting between 6 to 8 seconds. In specific catch trials, right after the stimulus offset, I'm want to capture keyboard responses within a time window of 0 to 1.5 seconds post-stimulus. I came up with this code but unfortunately, once I press the keyboard it automatically sets the end of the trial shortening the ITI:

Could anyone advise on a strategy to gather responses within that 1.5-second window post-stimulus, while ensuring the ITI consistently adheres to the initial definition for each trial (defined by the variable jittered_time)?

Any help on this would be fantastic.

Cheers,

Patxi

Comments

  • HI Patxi,

    Your code doesn't include how you compute the variable jittered_time Can you add that info?

    by the way, your trial_rt variable is computed the wrong way (not related to your question.

    Eduard

    Buy Me A Coffee

  • Hi Eduard,

    Thanks for your quick reply! I believe I've resolved the issue by subtracting the response time from the jitter duration, ensuring the ITI remains unaltered by the response. It's currently working well, and the timing appears accurate, but I'm curious if there might be a more efficient or safer approach to achieve this. Your insights would be greatly appreciated.

    Best,

    Patxi

    p.d.: jittered time is just a float

  • Hi Patxi,

    A slightly more efficient approach would be this:

    kb.flush()
    start_time = ITI_fix.show() 
    k, t = kb.get_key()
    if k is not None: 
        trial_rt = t - start_time
    clock.sleep(jittered_time - trial_rt)
    

    With kb = Keyboard(keylist=['1'], timeout=3500) being put before the loop (you only need to initialize it once, not on every trial). However, in practice the two versions would be almost identical.

    Eduard

    Buy Me A Coffee

  • Thank you so much Eduard! This code snippet works perfectly fine and it is definitely more elegant than my solution. In terms of timing there isn't any substantial difference.

    Best,

    Patxi

Sign In or Register to comment.