Howdy, Stranger!

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

Supported by

Logging fMRI TR signals

Hi everyone,

Our group is trying to implement an auditory experiment that uses interrupted acquisitions on fMRI. In order to check that all stimuli are synchronized with the duration of the TRs, we would like to register in the log all TR onsets.

In our particular scanner, at each TR the machine sends a signal that is connected to the computer via USB, and is registered as a 't' keypress. We would like to log all occurrences of said keypress (or any other way of registering the signal), and the time when it happens, without blocking the code.

I checked the io.TriggerInput() setting but don't really understand how to set it up to do this. Is there a way to log all occurrences of 't' keypresses? If not, how to set up the TriggerInput object in order to do this?

Thank you very much!

Juan Jesus Torre


  • Hi there,

    if you use USB triggers (keyboard emulation), then indeed you cannot use the TriggerInput, since this expects a serial or parallel port as interface.

    Getting all triggers without blocking the code is very tricky. You could do this in an additional thread (or process), but that could affect the timing in your main thread (your experiment).

    The first thing to think about is whether logging each trigger is really needed. If you expect the clock of your scanner to be accurate, then you know when your triggers will come in, if you know your TR. So most of the time there is no need for actually log it and syncing once in the beginning of the experiment is enough.

    Sometimes, however, the trigger helps to time your design (if it is not free running). What I often do is a combination of knowing when the trigger should come, and then briefly wait for it (we often need this for real-time fMRI). For instance, if your TR is 2000, then you can basically do stuff for most of that time, and only in the end briefly wait for the next trigger. It of course depends on what else you are doing in your experiment, but I often have code similar like this:

    while last_trigger_time < TR - 100:
        # do stuff
    exp.keyboard.wait()  # wait for next trigger
    last_trigger_time = exp.clock.time

    Also keep in mind that the log time of the audio stimulus is not s accurate as that of a visual stimulus! (see for more information).

    Florian Krause (Developer)

Sign In or Register to comment.