In short
Clinical-grade sampling on a cheap chip, with a self-calibrating detector that only raises an alarm when a seizure signal persists.
The problem
Brainwave capture needs samples spaced evenly to within microseconds, on hardware cheap enough to be worn. Seizure detection also has to avoid crying wolf: a swallow or a movement spikes the same frequency band a seizure does.
What we built
Sampling runs off a hardware timer interrupt firing every 3,906 microseconds, for an exact 256 Hz rate; a software delay loop cannot hold that precision. Transmitting inside the interrupt would corrupt it, so the system writes into one buffer while sending the other. The pointers swap inside a protected critical section, so the fill cycle never stalls.
Exact sampling, a buffer that never stalls, and an alarm that waits five seconds
Threshold: µ + 3σ of the patient's own 30-second baseline. Detection trace is illustrative.
Source: COEP TU, ESP32 to Python server, 2025
On the server, a zero-phase notch filter and bandpass filter strip mains hum and electrode drift. A rolling five-second window becomes a frequency spectrum every second, and power is measured across the five standard brainwave bands.
The threshold is not fixed. It tracks thirty seconds of the patient’s own high-frequency baseline and triggers at three standard deviations, so it calibrates per person. A seizure is declared only after the threshold holds for five consecutive seconds. We validated the pipeline by replaying an hour of recorded clinical data through it, unmodified.
You are reading a shorter version of this technical edge.