Computational Neuroscience

Teaching two clocks to agree

Trigger synchronization for a transnasal deep-brain BCI · ForAll Lab, CMU

A behavioral task and a brain-recording system kept separate clocks. I aligned them to the millisecond so each neural signal maps to the right event.

< 2 ms alignment error
~0.4 ms/min drift, corrected
100% markers recovered

One clock, aligned to the brain

At CMU's ForAll Lab, on a transnasal deep-brain BCI targeting epilepsy and ADHD. Event-related analysis slices the recording around each event and averages, so a few milliseconds of error cancels the signal instead of finding it. The task PC and the neural recorder never shared a clock, and the gap grew over the session.

Fig 1 — Task events (top) vs raw EEG markers (bottom). The widening offset is uncorrected clock drift.
01

Parse

Python parsers merge task event logs and neural trigger codes into one timestamped table.

02

Cluster

Collapse trigger bursts from noise and switch bounce to one true onset.

03

Fit drift

Fit a line through the per-event offsets; the slope is the drift, and it remaps every sample into a shared time.

04

Validate

Automated checks flag dropped triggers and out-of-tolerance residuals; failing sessions get quarantined.

Fig 2 — Alignment error. Grey: raw offsets. Red: after correction, tight and centered near zero.
<2ms
Final alignment error
~30×
Reduction in timing spread
0
Mismatched triggers, validated sets
100%
Marker recovery after declustering
Python NumPy / SciPy Time-Series Alignment Signal Processing Clock-Drift Correction Marker Clustering Data Validation Serial Communication Deep-Brain BCI