Skip to content
AI.info

Research

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

Overview Research area: Human-Computer Interaction / neural engineering — specifically closed-loop electrocorticographic (ECoG) Brain-Computer Interface software infrastructure for clinical settings.

An open-source implementation of a closed-loop electrocorticographic Brain-Computer Interface using Micromed, FieldTrip, and PsychoPy
arXiv
2602.09735
Published
2026-02-10
Authors
Bob Van Dyck, Arne Van Den Kerchove, Marc M. Van Hulle

AI summary

Overview

Research area: Human-Computer Interaction / neural engineering — specifically closed-loop electrocorticographic (ECoG) Brain-Computer Interface software infrastructure for clinical settings.

Technical level: Intermediate to Advanced. The paper assumes familiarity with Python, real-time signal processing concepts (epoching, sliding windows, latency), and research hardware (acquisition amplifiers, serial marker devices), though it explains its architecture carefully.

Scope: The paper describes a modular, open-source software stack — three Python libraries built around Micromed, FieldTrip, and PsychoPy — for running closed-loop ECoG BCI experiments in an epilepsy-monitoring clinical setting, and demonstrates it with two runnable use cases.

What This Paper Is About

BCI researchers working with ECoG in clinical environments (e.g., presurgical epilepsy monitoring) must build closed-loop systems from whatever hardware the hospital already has, and the practical systems-engineering details of doing so are rarely documented in published literature. The authors present a complete, open-source software architecture for this problem, along with three custom Python libraries that handle experiment design, event marker delivery, and real-time signal processing. The goal is to lower the barrier for researchers who want to move ECoG decoding advances out of offline analysis and into live BCI applications.

Key Contributions

  1. A detailed technical description of a closed-loop ECoG BCI in a clinical context using a Micromed acquisition system — including the hardware topology, network paths, and operational stages — intended as a practical guide for similar deployments.

  2. Three open-source Python libraries, each covering a distinct aspect of a closed-loop BCI interface:

    • psychopylib — code-based experiment design in PsychoPy with improved readability, organized around Segment and Sequence classes.
    • pymarkerlib — sending event information (precise timing and labels) and control signals to data acquisition and other external devices.
    • pyfieldtriplib — thread-based real-time signal processing enabling concurrent execution of chained processing steps alongside a user application.
  3. Two runnable end-to-end demonstrations hosted online: a closed-loop ECoG movement classification experiment (Appendix A) and a closed-loop EEG motor-imagery classification experiment using LabStreamingLayer, with accuracy and latency measurements (Appendix B).

  4. A framework for reasoning about system latency and decision rate in closed-loop BCI, decomposed into ADC, processing, and output latency, with concrete guidance on how application structure can trade off predictable timing against minimal timing.

Main Findings

  • A modular system can bridge the offline-to-closed-loop gap without a monolithic platform. The three libraries are not strictly interdependent — pyfieldtriplib is completely standalone, and users who prefer PsychoPy Builder or other stimulus tools can still use the real-time processing and marker tools.

  • Callback-based timing solves a concrete problem in stimulus presentation. Naively calling one Segment after another causes delays from stimulus preparation and logging. psychopylib instead performs stimulus preparation for the next segment (before-method) and logging for the preceding one (after-method) during the current segment. This requires segment durations to be long enough for concurrent logging and stimulus preparation, otherwise precise timing is lost.

  • Real-time processing can be chained across threads. pyfieldtriplib allocates separate threads to each processing step, chaining them into a pipeline so that data collection and processing run simultaneously and the main experimental code remains responsive. RtEpoch operates at a configurable rate with a default of 60 Hz; RtFunction applies user-defined functions to incoming epochs and also supports MNE-LSL's EpochsStream as an alternative signal source.

  • A Micromed BCI license can conflict with clinical needs. A recording only starts once a client–server connection is established, requiring an active SW EEG BCI license (Micromed, Italy). In practice, this license can introduce a 30-second gap between consecutive recordings while it searches for a connection before timing out. Because continuous monitoring is required clinically, the authors disable the license when real-time processing is not needed.

  • No explicit dejittering, drift correction, or packet reordering is implemented. While TCP/IP can introduce latency and variability in packet timing, event-based epochs retain exact alignment, and any delay impacts only the timing of feedback delivery. The system does not enforce consistency between data availability and feedback presentation — that responsibility falls to the user.

  • Motor-imagery classification accuracy varied across test blocks for a single subject. Using a filter-bank common spatial pattern (FB-CSP) model with an LDA classifier:

    Test block Accuracy (%)
    1 86.67
    2 63.33
    3 63.33

    The subject reported having experimented with other mental strategies during test blocks 2 and 3, which the authors say explains the drop in performance.

  • Measured end-to-end latency was 0.178 s ± 0.016. This figure excludes the 2 s epoch length; the total measured time difference between go cue and feedback consists of the epoch length (2 s) plus the system latency (0.178 s ± 0.016). The authors attribute the relatively high latency primarily to non-optimized signal processing, notably the serial execution of the filter-bank's band-pass filters.

  • MATLAB remains a dependency. The FieldTrip buffer is implemented as a multithreaded application in C/C++ and compiled into a MATLAB mex file, runs within MATLAB, and is accessed via a Python client — a limitation the authors flag.

  • A design limitation of sequences in threads. Sequences are tied to the thread in which they were created and cannot be reused after termination of that thread.

Methodology in Plain English

The authors take a modular approach rather than building a single BCI platform. They split the system into the three conventional BCI components — data acquisition, signal processing, and user application — and used existing tools for each, writing Python libraries only where functionality was missing.

For data acquisition, ECoG signals are recorded with an SD LTM 64 Express amplifier (Micromed, Italy), transmitted via a patch panel (UTP) to a recording PC in a separate control room, and processed and saved by SystemPlus EVOLUTION software. Each session generates a TRC file. The recording PC is remotely controlled from the patient's room through a KVM switch.

For experiments, code written with psychopylib runs on a portable experiment PC in front of the participant using PsychoPy for display, audio, and input collection. Events go to the recording PC over a standard COM-port serial connection using pymarkerlib.

For calibration and closed-loop use, recorded signals and events travel from the recording PC to the experiment PC over WLAN using TCP/IP. A FieldTrip proxy in MATLAB sits between the acquisition system and the FieldTrip buffer, a lightweight, multithreaded C/C++ TCP ring-buffer server. This decoupling means time-consuming computations do not interrupt data acquisition, and multiple clients can access the stream in parallel. pyfieldtriplib on the Python side handles epoching and user-defined processing chains.

To validate the setup, they built two example paradigms. The first (ECoG, movement) has participants open and close their right hand per a text cue, with each training block consisting of 40 trials — 20 open and 20 close — in randomized order; markers 1 and 2 correspond to open and close, training uses 1-second epochs from 0 to 1 s, and asynchronous BCI use extracts 1-second epochs in a sliding window with a 0.1-second hop size, updating the prediction every 0.1 s (a 10 Hz decision rate). The second (EEG, motor imagery) uses a Neuroscan SynAmps RT device (Compumedics, Australia) with 32 active Ag/AgCl electrodes in a QuickCap layout following the international 10–10 system, ground at AFz and reference at POz, impedances kept below 5 kΩ, sampled at 200 Hz by CURRY 9, with markers captured from a VIEWPixx monitor and EEG and events streamed to LabStreamingLayer. Processing there used 0–2 s epochs relative to the go cue, common average referencing, a filter bank of 4 Hz-wide non-overlapping bands between 8 and 40 Hz, a CSP filter per band, and an LDA classifier. Each experimental block was followed by a BCI calibration re-estimating the model from all prior trials — a continual recalibration the authors note blurs the line between training data acquisition and BCI use.

Why This Matters

Impact on research. The paper addresses a gap the authors identify explicitly: to their knowledge, no published works provide a comprehensive overview of a system architecture addressing the hardware and software challenges of closed-loop ECoG BCI under acute-implant, presurgical-monitoring conditions. Because hardware in those settings is predetermined and not originally intended for real-time use, researchers often have to reinvent the integration from scratch. Documenting the architecture and releasing the code lowers that barrier and makes setups more reproducible.

Real-world applications:

  • Restoring communication and muscle control lost to injury or disease — the primary long-term motivation for BCI.
  • Presurgical epilepsy monitoring — acute implants used for clinical mapping offer a temporary window of high-quality cortical recording that researchers can exploit, with the primary objective remaining medical.
  • Permanent medical interventions — ECoG's high spatial and temporal resolution, resistance to noise, and long-term signal stability make it promising for chronically implanted systems.
  • General research tooling — the libraries are not tied to ECoG or to Micromed; pyfieldtriplib works independently and supports alternative signal sources through MNE-LSL.

Industry relevance. The work sits at the intersection of medical device integration (Micromed), research software infrastructure, and interactive experiment design. It shows a concrete path for using a vendor's routine clinical hardware in real-time applications, including the practical caveat that a vendor's BCI licensing mechanism can introduce a 30-second interruption incompatible with continuous clinical monitoring. It also illustrates the trade-offs that matter to anyone building real-time neurotechnology: latency budget decomposition, decision-rate tuning, and the cost of non-optimized processing code.

Future Directions

  1. Eliminating the MATLAB dependency. The stated development focus is translating FieldTrip's Micromed proxy to Python, removing the requirement for MATLAB entirely.

  2. Continuing a minimalist, modular design philosophy. The authors explicitly want to avoid building a large, monolithic system, favoring lightweight, adaptable components suited to varied closed-loop BCI research demands.

  3. Optimizing latency through parallelization. The measured 0.178 s ± 0.016 latency was attributed mainly to the serial execution of the filter-bank's band-pass filters — an obvious target for improvement, and a question of how much latency can be shaved by different implementation choices.

  4. Extending validation beyond the demonstrated paradigms. Both use cases are single demonstrations — one ECoG movement experiment without reported classification accuracy, and one EEG motor-imagery experiment with accuracy from a single subject. Broader validation across participants, tasks, and clinical sites remains open.

Target Audience

Most useful for BCI researchers and engineers with Python experience who implement closed-loop experiments and want low-level control over real-time signal processing. Also relevant for clinicians and lab staff setting up ECoG experiments in epilepsy-monitoring units, and for developers of neurotechnology tooling interested in modular architectures, real-time epoching pipelines, and latency-aware experiment design. The paper reports limited quantitative results (one subject, three test blocks, one latency measurement), so readers seeking decoder performance benchmarks or clinical outcomes will not find them here; the value is in the system architecture, the released libraries, and the practical description of a clinical deployment.

Authors’ abstract

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.

Read the original paper