An open-source implementation of a closed-loop electrocorticographic Brain-Computer Interface using Micromed, FieldTrip, and PsychoPy

An open-source implementation of a closed-loop electrocorticographic Brain-Computer Interface using Micromed, FieldTrip, and PsychoPy
Notice: This research summary and analysis were automatically generated using AI technology. For absolute accuracy, please refer to the [Original Paper Viewer] below or the Original ArXiv Source.

We present an open-source implementation of a closed-loop Brain-Computer Interface (BCI) system based on electrocorticographic (ECoG) recordings. Our setup integrates FieldTrip for interfacing with a Micromed acquisition system and PsychoPy for implementing experiments. We open-source three custom Python libraries (psychopylib, pymarkerlib, and pyfieldtriplib) each covering different aspects of a closed-loop BCI interface: designing interactive experiments, sending event information, and real-time signal processing. Our modules facilitate the design and operation of a transparent BCI system, promoting customization and flexibility in BCI research, and lowering the barrier for researchers to translate advances in ECoG decoding into BCI applications.


💡 Research Summary

The paper presents a fully open‑source implementation of a closed‑loop electrocorticographic (ECoG) brain‑computer interface (BCI) that can be deployed in a clinical epilepsy‑monitoring environment. The authors integrate three widely used tools—Micromed’s acquisition hardware, the FieldTrip toolbox for real‑time signal handling, and PsychoPy for stimulus presentation and feedback—by developing three dedicated Python libraries: psychopylib, pymarkerlib, and pyfieldtriplib.

The system is organized into three operational stages. In the clinical data‑acquisition stage, a Micromed SD‑L TM 64 Express amplifier records broadband ECoG signals, which are stored on a dedicated recording PC as TRC files. For training‑data acquisition, a portable experiment PC runs PsychoPy scripts built with psychopylib; each “Segment” defines a stimulus, duration, optional key response, and a marker value, while a “Sequence” arranges segments into trials and blocks. Markers are sent over a serial COM port using pymarkerlib, guaranteeing precise temporal alignment between stimulus events and neural recordings.

During BCI calibration and real‑time use, the recorded data stream is forwarded from the recording PC to the experiment PC via a reliable TCP/IP connection. A MATLAB‑based FieldTrip proxy receives the Micromed stream and writes it into the FieldTrip buffer, a multithreaded TCP server that maintains a ring buffer accessible by multiple clients. pyfieldtriplib connects to this buffer, pulls data in a separate thread, and applies a user‑defined processing chain (e.g., resampling, rereferencing, band‑pass filtering, artifact rejection). The processed epochs are placed on a queue that the PsychoPy application consumes; model predictions derived from these epochs are immediately translated into visual or auditory feedback, closing the loop.

Key technical contributions include:

  1. Modular Python design – Each library isolates a distinct BCI function, allowing researchers to replace or extend components without rewriting the whole pipeline.
  2. Precise timing via callbacks – psychopylib’s before/after callbacks prepare the next stimulus while logging the previous one, preserving sub‑second timing even for 1‑second segments.
  3. Hardware‑agnostic marker handling – pymarkerlib abstracts serial communication, supporting Micromed SystemPlus markers, VIEWPixx triggers, eye‑tracker events, and generic visual markers.
  4. Thread‑based real‑time processing – pyfieldtriplib runs segmentation, preprocessing, and model inference in parallel threads, preventing heavy computations from blocking data acquisition.

The authors also discuss practical constraints. The Micromed “SW EEG BCI” license introduces a ~30 s connection‑search delay; they recommend disabling it when real‑time streaming is not required. TCP/IP, while reliable, adds latency compared with lower‑level protocols, so network quality must be monitored for ultra‑low‑latency applications.

All source code, documentation, and runnable examples (including a complete block‑design experiment and a real‑time decoding loop) are released on a public GitLab repository. By providing a transparent, extensible, and clinically viable BCI stack, the work lowers the barrier for researchers to translate advances in ECoG decoding into closed‑loop neurotechnology, fostering reproducibility and accelerating the path toward therapeutic BCI applications.


Comments & Academic Discussion

Loading comments...

Leave a Comment