JOVANA
Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
All guides

The Real-Time Decoding Pipeline

How a live stream of brain voltages becomes a usable command, many times a second. We walk the four-stage assembly line from raw signal to action, see why being **real-time** changes every design choice, and read a short pipeline in pseudocode.

Raw signal in, command out

At its heart, decoding is a transformation that runs over and over: a chunk of raw voltage goes in, and a discrete command comes out. Picture a factory assembly line. The conveyor belt never stops — fresh brain signal keeps arriving — and at the far end a finished product (a cursor move, a letter, a robot grip) rolls off. The job of the pipeline is to keep that belt moving smoothly, turning messy electricity into a clean decision dozens of times every second.

The input is whatever your sensor delivers — EEG (electroencephalography) from the scalp, ECoG (electrocorticography) from the cortical surface, or spikes from an intracortical array. The output is an action in the world. Everything between is the pipeline, and a practitioner's craft is in how each stage is built and how fast it all runs.

The four stages

Almost every decoder, simple or fancy, is some version of these four stages in a row. Learn them once and you can read any pipeline you meet.

  1. Preprocess / clean. Take a short window of the raw stream and tidy it: a bandpass filter to keep the useful frequencies, plus rejection or removal of artifacts like blinks and line noise. Garbage in, garbage out — this stage protects the rest.
  2. Extract features. Boil the cleaned window down to a handful of numbers that carry the intent — features such as band power in the mu rhythm or outputs of a spatial filter. You are throwing away everything irrelevant and keeping the signal.
  3. Classify into a choice. Feed the features to a classifier — trained earlier during calibration — which maps them to one of a few intents (left vs. right, click vs. rest, this letter vs. that).
  4. Issue a command. Turn that choice into an action — move the cursor, type the letter, drive the prosthesis — and send it on. The result feeds back to the user, completing the loop.

Online vs offline

There are two worlds for running a decoder. Offline analysis is leisurely: you have a recorded dataset on disk, and you can replay it, peek at the future, try a hundred models, and take all afternoon. Online (real-time) decoding has none of that comfort. The signal arrives live, the user is waiting, and the loop must close before the moment passes.

This single constraint — keep up with the live signal, end to end — shapes everything. You can only use the past, never the future, so non-causal filters are out. Your whole window-to-command latency typically has to land under roughly 100 milliseconds to feel responsive, which caps how heavy your features and model can be. And it must run unattended, so the pipeline has to handle bad samples gracefully instead of crashing.

A pipeline in pseudocode

Here is the whole assembly line as a tiny loop. Intuition first: we grab the latest slice of signal, clean it, squeeze out features, ask the trained classifier what it means, and send the command — then immediately go around again. Notice how every one of the four stages from earlier is exactly one line in the loop.

# Real-time decoding loop. Runs as long as the BCI is on.
while bci_is_running:
    window = stream.read(samples=250)      # newest 1 s @ 250 Hz (past only)
    if has_artifact(window):
        continue                           # skip bad chunk, don't crash
    clean = bandpass(window, low=8, high=30)   # keep mu/beta band (8-30 Hz)
    feats = band_power(clean)              # extract features: power per channel
    intent = classifier.predict(feats)     # classify -> e.g. 'left' / 'right'
    send_command(intent)                   # issue command; user sees feedback
    # loop repeats every step -> a fresh decision many times per second
A minimal online decoding loop: read a past-only window, clean it, extract band-power features, classify, and send a command — repeated continuously.