SK Siddharth Karandikar
Brief

Technical edge · COEP TU — ESP32 to Python server

A commodity microcontroller holds clinical timing if the buffering is designed for it, and false alarms are a design target, not a side effect.

Role
Team member
When
Jul – Dec 2025
Team
Three-person team
Full read
1 min

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.

Exhibit 1 Schematic

Exact sampling, a buffer that never stalls, and an alarm that waits five seconds

Sampling 256 Hz Buffers fill · send Detection band power 3,906 µs A fills B sends A sends B fills A fills B sends A sends B fills pointer swap, never stalls µ + 3σ brief spike: ignored held 5 s → alarm

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.