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

Automated and Real-Time Cleaning

ASR, bad-channel detection, line-noise regression and stimulation-artifact handling — cleaning when you cannot epoch-reject offline.

The online constraint changes everything

The methods so far are mostly offline: ICA needs a batch, epoch rejection looks across trials, SSP is fit on calibration data. A closed-loop BCI cannot wait — it must clean each sample causally, within a latency budget of milliseconds, with no future data and no human in the loop. That constraint rules out anything non-causal and rewards methods that are unsupervised, incremental and bounded in cost. Online decoding therefore uses a different, leaner toolkit.

Artifact Subspace Reconstruction

ASR is the workhorse of real-time EEG cleaning. It learns the statistics of clean data, then continuously removes transient high-variance intrusions. In a sliding window it takes the PCA of the channel covariance and flags any principal direction whose variance exceeds a threshold set from calibration:

\text{reject } c \ \text{ if }\ \operatorname{Var}(y_c) > \big(k\,\sigma_c^{\text{clean}}\big)^2

A component direction is rejected when its windowed variance exceeds k standard deviations of the clean calibration statistics.

During clean calibration, learn how loud each signal direction normally is. In real time, if a direction suddenly gets much louder than that, flag it as an artifact and rebuild it from the good directions.

\operatorname{Var}(y_c)
Current windowed variance (power) in component direction c.
\sigma_c^{\text{clean}}
That direction's normal standard deviation, measured on clean data.
k
How many standard deviations of loudness you tolerate before rejecting.
c
The component direction being tested this window.

With k around 3, a direction carrying about 9 times its usual power gets removed. This is Artifact Subspace Reconstruction.

Rejected directions are not blanked; they are reconstructed from the retained (clean) subspace using the calibration mixing matrix, so the output keeps its full channel count and dimensionality. The cutoff k is the one knob that matters: too small and ASR eats real neural bursts, too large and it lets artifacts through. Typical values sit in a mid-range that is best tuned on held-out data, never on the data you will report.

Bad channels and line noise

Before any spatial method runs, a single dead or railing channel can poison a common average reference or an ICA. Automatic bad-channel detection flags channels by low correlation with their neighbours, extreme deviation, excessive high-frequency noise, or RANSAC-style prediction from the rest of the montage, then interpolates them from neighbours. For mains interference, the crude notch filter carves a permanent hole in the spectrum — a problem if you study the very band you are gouging. Spectral-regression approaches (CleanLine/Zapline) instead estimate and subtract the sinusoidal line component, preserving the surrounding spectrum.

Stimulation artifacts: the read–write collision

Bidirectional and neuromodulation systems create the hardest artifact of all. A DBS or ICMS pulse is orders of magnitude larger than any neural signal and can saturate the amplifier, blinding the front end for milliseconds. No downstream algorithm recovers information from a rail. The layered defence:

  1. Hardware: fast-settling, high-dynamic-range front ends and, where possible, DC-servo / AC coupling to keep the amplifier out of saturation.
  2. Blanking: disconnect or ignore the input during the pulse — read–write interleaving schedules recording between stimulation pulses.
  3. Subtraction: fit and remove a stimulus-locked artifact template from the residual, exploiting its stereotyped shape.

The same template logic rescues EEG recorded inside an MRI scanner: the gradient switching induces a huge but highly repeatable artifact, so average artifact subtraction estimates a template from many volumes and subtracts it, leaving the EEG beneath.

Pipelines, provenance and the over-cleaning trap

Real cleaning is a pipeline — bad-channel repair, filtering, line removal, ASR/ICA, re-referencing, epoch rejection — and each stage carries hyperparameters. Two disciplines keep it honest. First, provenance: log every parameter and the fraction of data/channels removed, because a pipeline that quietly discards 40% of trials is reporting on a different dataset than it claims. Second, fit on calibration, apply to test: any statistic (clean covariance, ICA weights, a bad-channel list) estimated on data that later enters evaluation is leakage. Automated, versioned pipelines in the spirit of PREP exist precisely so these choices are explicit and reproducible.