Part VII: Health, Biosignals, and Wearable AI
Chapter 31: EEG, Neural Signals, and Brain-Computer Interfaces

Invasive BCI: speech and handwriting decoding (Neuralink, Synchron, cortical arrays)

"A thousand electrodes will happily read your motor cortex. Getting the comma in the right place still takes a language model."

An Implanted AI Agent

The Big Picture

The scalp EEG of the previous sections is a heavily blurred, attenuated shadow of cortical activity, smeared by the skull and reduced to a few frequency bands. Put an electrode inside the skull, next to or into the cortex, and the signal quality jumps by orders of magnitude: single-neuron spikes, sharp high-frequency power, and a spatial resolution measured in millimeters rather than centimeters. That fidelity is what turns a brain-computer interface from a slow menu-selector into a system that reconstructs intended handwriting and attempted speech at conversational rates for people who have lost the ability to move or talk. This section is about the sensors that reach that signal (cortical microelectrode arrays, endovascular stents, and the newest high-channel-count implants) and the sequence models that turn their output into text.

This section builds on the montage-and-band vocabulary of Section 31.1 and the motor-imagery decoding of Section 31.3, but pushes past the scalp. It leans on the sequence-model toolkit of Chapter 14 (RNNs and temporal convolutions) and the language-model reasoning of Chapter 21. No neurosurgery background is assumed; channel counts, firing rates, and typing speeds here are engineering anchors for sizing decoders, not clinical claims. The regulatory and safety weight of putting hardware in a human brain is treated in Chapter 34.

Why go inside the skull: the fidelity ladder

Invasiveness buys signal. Rank the recording modalities and the tradeoff is stark. Scalp EEG sees roughly 1 to 10 microvolts through bone and gives you frequency-band power over centimeters of cortex. Electrocorticography (ECoG), a subdural grid of electrodes resting on the cortical surface, sees millivolt-scale local field potentials and, critically, clean high-gamma power (roughly 70 to 170 Hz) whose amplitude tracks local population firing on a 10-millisecond timescale. Penetrating microelectrode arrays go one level deeper, resolving the action potentials of individual neurons: the classic Utah array (Blackrock Neurotech) is a 4 by 4 millimeter bed of 96 silicon needles, each tip recording spikes from a handful of nearby cells.

The reason this matters for language is bandwidth. Intended movement (whether of a hand, a pen, or the vocal tract) is encoded in the fine-grained, fast-changing firing of motor cortex. Scalp EEG throws almost all of that away, which is why non-invasive BCIs top out at a handful of commands (Section 31.3). An intracortical array preserves enough of it to distinguish 26 imagined letters or dozens of phonemes. The engineering cost is equally stark: surgery, biocompatibility, and slow signal decay as scar tissue encapsulates the electrodes. This is the invasiveness-versus-fidelity dial, and every device below sits at a different point on it.

Key Insight

Invasive speech and handwriting BCIs do not read out words the brain is "thinking." They decode the motor plan: the cortical command that would have moved a pen or the articulators. That is why they are implanted over hand-knob or ventral-sensorimotor (speech-motor) cortex, and why they work for people who are paralyzed or anarthric but whose motor cortex still fires when they attempt the movement. The BCI is an inertial-to-intent translator for a body that no longer responds, not a mind reader.

The hardware zoo: arrays, threads, and a stent

Three sensor architectures dominate the current clinical landscape, and they differ mainly in how they trade channel count against surgical risk.

Cortical microelectrode arrays (BrainGate). The academic workhorse is one or two Utah arrays placed in motor cortex, feeding the long-running BrainGate consortium studies. Roughly 100 to 200 channels of threshold-crossing spikes and spike-band power. High fidelity, decades of results, but rigid needles and a percutaneous connector.

Neuralink N1. Neuralink's implant replaces rigid needles with about 64 flexible polymer threads carrying roughly 1024 electrode contacts, inserted by a surgical robot to dodge blood vessels, and reads out wirelessly with no skull-penetrating connector. Its first human participants (the PRIME study, from 2024) used motor-cortex signals for cursor and click control; the same high channel count is the substrate the company targets for text output.

Synchron Stentrode. Synchron sits at the low-invasiveness end. Its Stentrode is an expandable stent studded with about 16 electrodes, threaded through the jugular vein into the superior sagittal sinus, a vein that runs over motor cortex. No open-brain surgery: it is placed like a cardiac stent. The tradeoff is fewer, vein-wall-distance electrodes and lower spatial resolution, traded for a far lower surgical bar (the COMMAND early-feasibility study).

In Practice: giving speech back after ALS

In a clinical study at Stanford (Willett and colleagues, reported 2023), a participant with ALS had lost intelligible speech but retained the will to talk. Four microelectrode arrays in speech-motor cortex recorded the firing that accompanied her attempts to speak. A recurrent decoder mapped the neural activity to phonemes, and a language model assembled phonemes into words from a 125,000-word vocabulary at about 62 words per minute, roughly half of natural conversational speed and an order of magnitude faster than the eye-tracking keyboards such patients otherwise rely on. A parallel UCSF effort (Metzger, Chang and colleagues) drove a talking avatar from ECoG. In 2024 a related intracortical system (Card and colleagues) reported over 97 percent word accuracy sustained across months. The load-bearing lesson: the electrodes provide the raw motor signal, but conversational usability comes only when a sequence decoder and a language prior are stacked on top.

From imagined handwriting to text

The result that made intracortical text real was handwriting, not typing. Willett and colleagues (Nature, 2021) had a paralyzed BrainGate participant imagine handwriting individual letters. Attempted pen strokes produce richer, more separable motor-cortex trajectories than imagined point-and-click typing, so the neural patterns for "a" versus "b" are easier to tell apart. A recurrent network decoded the array signal into a stream of character probabilities; the raw decoder hit about 94 percent character accuracy at roughly 90 characters per minute, and a language-model autocorrect pass lifted it above 99 percent.

The decoding recipe is worth naming because it recurs across every system above. First, extract a per-channel feature at a modest frame rate (20-millisecond bins of threshold crossings and spike-band power). Second, run a recurrent or temporal-convolutional network (Chapter 14) that emits, at each frame, a distribution over output symbols plus a "blank." Third, collapse that frame-wise output into a symbol string with connectionist temporal classification (CTC), which handles the fact that you never know exactly which frame a letter starts on. Fourth, rescore candidate strings with a language model so that neurally ambiguous decodes resolve toward real words. Listing 31.5.1 shows the feature and CTC-collapse stages on synthetic data so the shapes are concrete.

import numpy as np
rng = np.random.default_rng(0)

# === Stage 1: neural feature extraction (the invasive-BCI primitive) ===
# Simulate 20 ms of raw broadband from 96 channels at 30 kHz.
fs, n_ch, dur = 30_000, 96, 0.20
raw = rng.standard_normal((n_ch, int(fs * dur)))
# Threshold-crossing rate = spikes below -4.5 x RMS, the canonical intracortical feature.
thr = -4.5 * raw.std(axis=1, keepdims=True)
crossings = np.sum(np.diff((raw < thr).astype(int), axis=1) == 1, axis=1)
sbp = np.mean(raw ** 2, axis=1)  # spike-band power, the second standard feature
print("threshold-crossing counts (first 5 ch):", crossings[:5])

# === Stage 4: CTC greedy collapse of a decoder's per-frame symbol argmax ===
# Vocabulary: blank(0), then a,b,c. Suppose the RNN emitted this frame path:
vocab = ["_", "a", "b", "c"]          # "_" is the CTC blank
path  = [1, 1, 0, 1, 2, 2, 0, 2, 3]   # per-frame argmax over 9 frames
def ctc_collapse(seq):
    out, prev = [], None
    for s in seq:
        if s != 0 and s != prev:      # drop blanks and merge repeats
            out.append(vocab[s])
        prev = s
    return "".join(out)
print("decoded string:", ctc_collapse(path))   # -> "abac"
Listing 31.5.1. The two stages a course in scalp EEG never needs. Threshold-crossing counts and spike-band power are the intracortical features; CTC collapse turns a decoder's noisy per-frame symbol path ("aa_a bb_ b c") into the clean string "abac" without knowing where each letter began. A language model would then rescore competing collapses.

As Listing 31.5.1 makes clear, the invasive part is entirely in Stage 1: nothing in the CTC machinery cares whether the frames came from a Utah array or a Stentrode. That modularity is why the same decoder architecture, retuned, drives handwriting, cursor control, and speech.

The Right Tool

Hand-rolling CTC beam search with an integrated language-model prior is roughly 200 lines of careful index bookkeeping and log-domain arithmetic. PyTorch collapses the training loss to one call and a beam decoder with a KenLM prior to a few:

import torch
from torchaudio.models.decoder import ctc_decoder

loss = torch.nn.CTCLoss(blank=0)              # replaces ~120 lines of forward-backward
decoder = ctc_decoder(lexicon="words.txt",    # replaces ~200 lines of beam + LM fusion
                      tokens=["_", "a", "b", "c"],
                      lm="brain_text.bin", beam_size=50)
# hypotheses = decoder(emissions)   # emissions: (batch, time, n_symbols) log-probs
Listing 31.5.2. torchaudio supplies the CTC loss and a lexicon-constrained, language-model-fused beam decoder, cutting roughly 320 lines of numerically delicate code to a handful. It handles the alignment and beam search; choosing the vocabulary and the language-model weight for your participant remains your job.

One methodological warning carries over from the rest of the book. These systems are trained per-participant on limited, expensive sessions, and neural signals drift day to day as electrodes settle and scar. Reporting accuracy on the same block you tuned on is leakage; honest evaluation holds out whole sessions and reports across days, which is exactly the calibration-and-drift discipline of Chapter 18. The 99-percent handwriting number is a held-out-sentence number with the language model in the loop, not a raw single-frame accuracy.

Research Frontier

The state of the art in 2024-2025 is closing on conversational, robust text. Intracortical speech neuroprostheses (Card et al., 2024, NEJM) report over 97 to 99 percent word accuracy across months on a large vocabulary; UCSF's ECoG avatar (Metzger et al., 2023) decodes text, synthesized voice, and facial animation jointly. The open problems are (1) stability: keeping a decoder accurate for years without daily recalibration, which is pushing the field toward self-supervised neural foundation encoders and unsupervised realignment of drifting channels; (2) generality: Neuralink's roughly 1024-channel N1 and Paradromics' high-bandwidth arrays are racing to see whether more electrodes translate into more vocabulary and faster output; and (3) bidirectionality: adding cortical stimulation to write sensory feedback back in. The framing of neural signal as just another sensor stream, aligned with the sensor-foundation-model program of Chapter 21, is increasingly how the decoders are built.

Exercise

Extend ctc_collapse in Listing 31.5.1 to return the number of distinct emitted symbols alongside the string, then feed it the path [1,1,1,2,0,2,2] and predict the output before running it. Next, explain in two sentences why merging repeated symbols is required (what real decoding failure would occur without it) and why the blank symbol is what lets the decoder still output a genuine double letter such as the "ll" in "hello."

Self-Check

1. Why does an intracortical array support letter-by-letter text output while scalp EEG does not, in terms of the signal fidelity ladder?

2. Rank the Utah array, Neuralink N1, and Synchron Stentrode by surgical invasiveness and by channel count. Why do those two orderings not match?

3. A team reports 99 percent character accuracy. What two questions must you ask before believing it generalizes to next week's session?

What's Next

In Section 31.6, we come back out through the skull: non-invasive language and speech decoding, where fMRI and MEG-based systems reconstruct the gist of perceived and imagined language without surgery, at a fraction of the fidelity, and where the privacy and consent questions raised by reading language from the brain get sharper precisely because the sensor no longer requires an operating room.