Problem with sending fMRI gradient artifact triggers to EEG recording

Dear PsychoPy Experts,

I’m currently running a simultaneous fMRI-EEG study. In the experiment we try to send 3 types of triggers to EEG recording using Serial Out and Code components. Specifically, the triggers we wanted to see are listed below:

  1. A single trigger that initiates the task using Serial Out. This trigger corresponds to the first TR of the scanner, and we have successfully achieved this.
  2. Several triggers being sent whenever a visual stimulus is presented. We have successfully achieved this via Serial Out.
  3. After the first TR trigger, we also wanted several triggers being sent at every TR (every 1.6 seconds in our study) so that we can remove the MRI gradient artifact later, but we couldn’t see any of these triggers. The setting for these TR triggers is described below and all suggestions are appreciated.
  • We created a Keyboard component that allows the key press 5 because our MRI scanner imitates this keypress. We are confident about this because this is how we set up for the first TR trigger.
  • And some codes we’ve tried:

Before experiment:
import serial #Import the serial library
port = serial.Serial(‘COM4’) #Serial port address

Begin Routine:
stimulus_pulse_started = False
stimulus_pulse_ended = False
thisMriTriggerLen = 0
lastMriTriggerLen = 0

Each frame:
stimulus_pulse_started = False
stimulus_pulse_ended = False

thisMriTriggerLen = event.getKeys().count(‘5’)

if thisMriTriggerLen != lastMriTriggerLen and not stimulus_pulse_started:
…win.callOnFlip(port.write, str.encode(chr(1)))
…stimulus_pulse_start_time = globalClock.getTime()
…stimulus_pulse_started = True
…stimulus_pulse_ended = False
if stimulus_pulse_started and not stimulus_pulse_ended:
…if globalClock.getTime() - stimulus_pulse_start_time >= 0.005:
… …port.write (str.encode(chr(0)))
… …stimulus_pulse_ended = True

lastMriTriggerLen = thisMriTriggerLen

Hello @Chia-Chuan_Yu

I have no experience of programming fMRI experiments with triggers. but could it be something as simple as indenting by three spaces instead of four? The three dots in your code suggest that you used only three spaces instead of four pre if-statement.

Best wishes Jens

Hi @JensBoelte
Thank you for your suggestion. Actually this is a formatting issue on this forum only, the format is correct in my PsychoPy task (4 spaces instead of 3). I’m pretty sure that the format is correct because the task can be run to the end without showing any error message.

Best,
Chuan

Hello @Chia-Chuan_Yu

well, that would have been too easy. My next step would be to include some print statements to check whether the if-constructions are ever true.

Best wishes Jens

I generally recommend against using serial ports for signaling the fMRI trigger since you generally need something more consistent in timing.

Just so I’m not missing anything:

  1. What EEG system do you have?
  2. Do you have other ways of capturing the TR directly into the EEG system?
  3. Are you syncing with the scanner’s 10Mhz clock?

@JensBoelte Great idea! I’ll check that!

Hi @pmolfese

  1. We use the system from Brain Products.
  2. I’m new to fMRI-EEG study, and this is the only way of sending TR triggers I’m aware of so far.
  3. Yes, we use the SyncBox from Brain Products to ensure the timing synchronization.

Hmm you should be getting the necessary TR markers automatically. Are you using RecView to online see the data cleaning?

I can check our system next week. My memory is that it’s in this manual but I don’t have my login handy: Brain Products GmbH | No Access

Hi @pmolfese,

Thank you for your reply. I haven’t used RecView to check the data. Regarding automatically sending the triggers, do you mean that the triggers should be sent automatically if Brain Products’ system (with SyncBox and TriggerBox) is used?

I’ll check the manual. Thank you!

Yes if you have the sync box then you may just need to configure Recorder to correctly work with it and get those volume triggers. This page has the relevant info:

@pmolfese Thank you so much!

I think our study follows the setting instruction you posted. One thing just came to my mind is that we set up the TriggerBox and Recorder by following that instruction; at the same time, we also set up a serial port component in PsychoPy trying to send the TR triggers.

Do you think set up the serial port component to receive TR triggers can stop the automatic TR triggers from Brain Products’ system?

You should rely on the volume triggers coming from the SyncBox and not send your own volume markers.

The reason being that in order to do gradient artifact subtraction, your markers need to be exact to the millisecond. Even a tiny bit of wiggle will cause the gradient correction to fail, and the serial component isn’t that precise.

On the plus side, not having to code those markers will keep your PsychoPy scripts considerably lighter!

@pmolfese I see. Thank you so much for your explanation! I’ll disable the serial port component and test if we can automatically receive the RT triggers.