Sending trigger to EGI system: Ethernet latency

Hello everyone,

I’m currently using Psychopy to transmit triggers (events) to the EGI system (Net Amp 400) via an Ethernet cable (Cat 5e), following the company’s recommendations. I have two questions regarding this setup. Firstly, there are moments where Psychopy fails to display the stimulus properly, resulting in a delay, and consequently, the trigger is not sent to the EGI system, resulting in its loss. Why did this happen? Secondly, I’ve noticed that the timing data received from Psychopy consistently exhibits some degree of delay, which varies inconsistently (usually within a few milliseconds). Is this variability normal? I would appreciate any insights you may have on this matter.

Best regards,
Mohammadreza

Hello,

Firstly, there are moments where Psychopy fails to display the stimulus properly, resulting in a delay, and consequently, the trigger is not sent to the EGI system

Assuming you’re using the code from the main docs page (Sending triggers via EGI NetStation — PsychoPy v2024.1.1), if a stimulus isn’t displayed then conditions for sending the trigger are never met: if stimulus.status == STARTED and not triggerSent

Secondly, I’ve noticed that the timing data received from Psychopy consistently exhibits some degree of delay, which varies inconsistently (usually within a few milliseconds). Is this variability normal?

The “delay” or offset is caused by a difference between when PsychoPy draws the stimuli and when it sends the command, that delay should be fairly consistent. Using the example code from above, the deviations around that offset should be (mostly) within 3-5ms.

If you’re noticing deviations more than this or a linear drift over the course of your experiment then there’s some things to check:

  1. Are you using the most recent copy of the package (GitHub - nimh-sfim/egi-pynetstation: Python package to enable the use of a Python-based API for EGI's NetStation EEG amplifier interface.), also available to pip install.
  2. If you’re measuring the offset with the EGI timing kit, making sure that you’re getting as clear a signal as possible using either the gold plug audio cable or the photo-diode with brightness on the display turned up.
  3. Consider adding in an occasional resync() command. Using the example page from above, it would be to add a eci_client.resync() to the start of a routine. This instructs egi-pynetstation to query the amplifier for the current time and calculate a behind the scenes difference that will be used to compute stimulus onset times. *I’ll add this instruction to the official docs page next chance I get.

Feel free to post your code and/or the output from a timing test (MFF file preferred, but can make do with a screenshot of the Timing Tool output).

-Peter

For illustration on a task I recently collected. The offset is the difference between the photocell and the event trigger. The variability on that offset should be consistent, you can see here that 95% are within 1ms of the median and 98% are within 2ms. There’s one outlier offset.

When analyzing these data I would specify that offset to Net Station, MNE, FieldTrip, etc to recalculate the onset times to that median.

Hi Peter,
Thank you for your response,

Allow me to clarify my concern. I’m currently working on an ERP task where each event is expected to occur at a 1.2-second interval from the preceding one. However, upon receiving the events in the EGI system, I noticed a variance in the timing of event arrivals. As depicted in Figure 1, the recorded event times exhibit a mean of 1.2048 seconds with a standard deviation of 0.0909 seconds.

Furthermore, I have included the structure (without a response pad console and video projector) of my recording (reference: https://www.egi.com/images/stories/manuals/GES_400/core/GES_400MR_uman_8100401-55_20150722_hires.pdf).

Thank you.
MohammadReza
avg_egi

Hello,

Could be a lot of contributing factors. My first feeling is that refresh rate on the screen is influencing the mean.

What is the refresh rate on your monitor and projector? Are you collecting the photocell data from the projector? You could look at the photocell output to see if psychopy is causing the variance in presentation.

Happy to look at the psychopy script and MFF If you post them.

-PM

Hi Peter,

Apologies for the delay; I’ve been recording some data these past few days. Both the projector and PC have a refresh rate of 60 Hz. Unfortunately, we weren’t able to gather photocell data.

I’ve uploaded three EEG files (without signals which are more than 350 MG each): one from outside the scanner, one from inside without any scanning (fMRI), and one from inside with scanning (fMRI). As you’ll notice, all three show missing data and latency. However, the EEG with fMRI shows more delays and latency.

Additionally, I’ve included my Psychopy code for your review. Please share any thoughts you have on it. I’m using two separate Ethernet ports: one for receiving data from the camera and the other for sending EGI events.

Looking forward to your feedback.

Best regards,
Mohammadreza
log_ERP_WO_fMRI_20240418_052915.mff.zip (43.6 KB)

log_ERP_WITH_fMRI_20240418_053854.zip (48.0 KB)

ERP_stimulation.zip (40.6 KB)

Hi Mohammadreza-

I believe the issue of 1.2-second intervals not being exact is a higher-level PsychoPy drawing to the screen feature. You can read a bit about how PsychoPy does screen refresh calculations: Presenting Stimuli — PsychoPy v2024.1.3

If I just hook a photocell up and calculate difference between the presentation of a stimulus and the one before it, there’s wiggle in that signal just coming off the photocell. This isn’t terribly surprising given that I tested this on my computer with a non-optimized (curved) display. You can play with the Display settings in PsychoPy to see if that improves things or perhaps a PsychoPy support person has further ideas. Data attached at end of post.

In addition to just differences in the photocell, I tested the EEG offsets and there are a couple of notes. You don’t currently have any calls to resync() the clock, which would cause some wiggle and drift in your EEG markers. The EGI communication package isn’t updated in PsychoPy 2024.1.1, I’ll work on getting that pushed to the next version. You could update it via pip like on this webpage: Sending triggers via EGI NetStation — PsychoPy v2024.1.3. However you can get 99% of the functionality by adding eci_client.ntpsync() to your “begin routine” blocks that deal with EEG communication to Net Station.

When I test your project on my (non-optimized) desktop with these added, I see the offset (time delta from presentation strobe on screen and EEG marker) ranging from 12-15ms with all offsets within ± 2 milliseconds of the median (45% exactly 0, 52% within 1ms, 3% within 2% for norm condition).

Having an offset like this is pretty standard, so long as the offset from the EEG is consistent when measured by a photo-diode, which this seems to be.

This is all to say that I think what you’re seeing is not an ethernet latency issue or an issue with the EGI communication package. It’s about optimization of monitors and refresh frames.



There’s some potentially important information that you haven’t mentioned yet that may help others chime in on solutions to the frame-rate display.

  1. Which is what type of computer are you presenting from? Specs?
  2. Who makes the projector that you’re using and the display?
  3. Are they connected via a splitter?
  4. Are you running on Windows, Mac, or Linux?

-Peter
qq_20240424_015508.evt.zip (3.1 KB)

Hi Peter,

Thank you for your help and valuable information,

I have tested the experiment with resynchronization (using eci_client.ntpsync()) at the beginning of the routines, and the outcomes have shown notable improvement. Previously, we were experiencing a standard deviation of 90ms delay, which has now reduced to 40ms delay. While this is certainly promising, I’m curious if there are any further optimizations we could explore. Attached is the ECI output from one of my recent recordings. I’d greatly appreciate your opinions about the new recording.

In response to your questions:

  1. My computer is an Acer Aspire 5 15.6" Laptop with an Intel Core i7-1260P processor, 512GB SSD, and 12GB RAM, running Windows 11.
  2. The projector and display are from an MRI company, designed for MRI environments, with a 60Hz sampling rate. It transfers data using optical fibre to the outside of the MRI room.
  3. Yes, I use a splitter to convert the optical fibre to HDMI.
  4. I use Windows for presentations and Mac for the EGI system.

Thanks again,
Mohammadreza
log_ERP_with_MRI_resync_14_20240429_052658.zip (70.5 KB)

Laptops aren’t my favorite thing in the world for doing psychophysics work. My main suggestion would be to run a timing test with the photo-diode on the laptop screen (without the splitter and without the projector) so you can see how stable the presentation and then compare that to the EEG tags. That will rule out a few things.

Next, I would check if the eye tracking code is causing issues depending on how long the device takes to respond. You could try turning that off for testing purposes and comment out the code (or put it in a True/False code block).

A full data file with EEG data so I can parse it with net station would be useful. Can just toss it on google drive or one drive or any other sharing platform if it won’t fit on the message board.

Not sure where you’re physically located; who is your EGI support rep?