By Janet Shin jshin@openwater.cc
What if a neuromodulation system could listen before it acted?
That was the idea behind my twelve-week project with Openwater. I worked with the open-source OpenLIFU platform to build a system that could read EEG in real time, detect a defined brain state, and trigger ultrasound only when that state was detected.
Getting it to work meant solving a lot of less glamorous problems: timing drift, signal artifacts, device communication, and latency between the EEG and ultrasound.
By the end, we had a working two-subject feasibility demonstration. It doesn't show that LIFU changes brain activity or improves cognition. Instead, it is a two-subject feasibility demonstration that answers a narrower foundational question: can OpenLIFU support a real-time EEG-driven closed loop within explicit, auditable bounds?
Here's what we built, what went wrong, and what I learned along the way.
Most neuromodulation experiments are open-loop: researchers define the stimulation parameters and timing in advance, then observe what happens. A closed-loop system adds a sensing-and-decision layer. It measures a physiological signal, interprets that signal against a predefined rule, and uses the result to decide whether an intervention is permitted.
For this project, the signal was EEG theta-band power during a 2-back working-memory task. The system compared the live theta signal with a resting baseline collected from the same subject. The goal was not to prove that a particular brain state should be stimulated. It was to demonstrate that sensing, signal processing, decision logic, sonication, and logging could operate together in real time.
That distinction matters. Closed loop is not simply “EEG connected to ultrasound.” The useful scientific artifact is the complete decision path: what the system measured, how it transformed the signal, why it allowed or refused a sonication, and whether that decision can be reconstructed afterward.
The implementation connects four main components through the Lab Streaming Layer, which provides a shared clock across the system.
EEG is acquired from a g.tec amplifier through the g.Pipe SDK. A median-absolute-deviation gate suppresses contaminated samples before they can influence the decision. Clean samples feed into a running theta-band calculation, which is then converted to a Z-score relative to a 100-second per-subject baseline. A PsychoPy 2-back task publishes task-state markers. The trigger module then evaluates the EEG state, task state, and safety bounds before openlifu-python is allowed to issue a sonication.
Every task event, gate state, trigger decision, and sonication event is timestamped. That made the system's behavior inspectable after a session and allowed us to measure end-to-end latency rather than assume it.
I deliberately kept the safety-critical logic in one readable module. The trigger conditions are grouped together, and each has its own test. If another researcher changes a threshold or adds a condition, the code, test, and protocol documentation should be updated accordingly.
A sonication is permitted only when all six conditions are true:
The gate is conjunctive and fail-closed. If a required input is missing, stale, contaminated, or outside its permitted range, the system refuses to sonicate. The ceiling, cooldown, and session cap bound system behavior independently of the EEG signal.
This design does not establish that these thresholds are therapeutically meaningful. It establishes that the decision logic can be made explicit, tested, logged, and inspected rather than hidden inside a black box.
The complete pipeline ran end-to-end: EEG acquisition, artifact gating, theta Z-score calculation, task-state tracking, six-condition gating, sonication control, and timestamped logging.
The safety envelope also behaved as specified. Every decision, whether permitted or refused, was recorded along with the state of all six conditions. That traceability may be less visually dramatic than a live demo, but it is essential if researchers want to reproduce, challenge, or improve the system.
We also made the pipeline runnable without human recordings. A synthetic theta-signal generator can exercise calibration, signal processing, trigger logic, and logging in dry-run mode without an amplifier, a subject, or a sonication. That gives outside developers a practical way to inspect the loop and contribute without needing access to the full experimental setup.
The most portable technical finding was not about theta. It was about latency.
Running the trigger logic directly in Python produced an end-to-end latency of approximately 170 milliseconds. Running the same logic through the 3D Slicer GUI path produced approximately 422 milliseconds. The roughly 250-millisecond difference was attributable to the Slicer-Python bridge rather than to the trigger logic itself.
That does not make the GUI path unusable. It tells us where to investigate, what to measure, and why interface architecture matters in real-time research systems. The finding is reproducible with the synthetic fixture, so it can be examined without using human-subject data.
It also reinforced a broader lesson: timing should be measured across the complete system. A fast algorithm can still live inside a slower operational path.
This project involved two participants under a two-subject research authorization. It was designed to test feasibility, not efficacy, and it was not designed to measure a physiological or clinical effect.
The current implementation also has deliberate limits. Targeting was manual and anatomical; the pipeline did not use MRI-guided targeting or acoustic skull correction. It was validated with one amplifier. No raw EEG or subject-derived data from the study is published in the repository.
Those limitations are not footnotes to hide. They define the boundary of the result. The project shows that an EEG-driven OpenLIFU loop can run within specified software bounds. It does not show that the system treats a condition, improves an outcome, or is ready for clinical use.
The repository is meant to be extended. The most useful next contributions include:
Other directions such as MRI-guided targeting and acoustic skull correction require design decisions before implementation. That is part of working in the open: not every visible gap should immediately become code. Some need scientific and platform-level agreement first.
The most important outcome of this project would be another researcher or developer doing something with the work.
You can run the pipeline against synthetic EEG in dry-run mode, inspect the trigger module, reproduce the latency measurement, propose an experiment, implement a hardware adapter, or open an issue explaining where the architecture does not fit your use case.
The repository documents what worked, what did not, and what remains unanswered. That is intentional. Open-source research moves forward when the unfinished edges are visible enough for someone else to test, question, and improve.
Where would you take closed-loop OpenLIFU next?
Research-use note: This project and the OpenLIFU platform are intended exclusively for research use. They are not cleared or approved by the FDA for clinical use, and their safety and effectiveness have not been established through the FDA's formal review process.