A first BCI on four channels
Decoding re-taught for four channels — what is decodable at rank four, the chance band an accuracy has to clear, the leakage a split can smuggle in — and a calibrate-then-apply classifier for eyes closed against eyes open on the occipitotemporal replica with a time split, the decoder frozen into arrays; the P300 at 16, 8 and 4 channels on one subject; a steady-state response detected by canonical correlation on a planted flicker; a blink switch, labelled EOG; and the decoder run block by block with the same features as offline.
Prerequisites: L7.13 · The feedback signal: band power in a buffer, L2.5 · Artifact rejection strategies, L6.5 · Decoding as inference
What you will be able to do
- Build a calibrate-then-apply classifier for eyes-closed versus eyes-open on a four-channel montage and report accuracy against the chance band
- Explain why motor imagery is unavailable on both montages and P300 only on one that includes a centro-parietal site
- Detect a steady-state response to a periodic stimulus with a spectral or CCA detector
- Run the decoder block by block with the same features as offline
Why this matters
A brain–computer interface on four channels is a smaller problem than the ones L7.1 benchmarks, and the smallness is the lesson. Four channels give four spatial degrees of freedom; a decoder can find a direction in that space that separates two states whose scalp patterns differ, and it cannot find a state whose pattern lives at a site the montage does not have — which is why motor imagery is unavailable on both of the path’s geometries (no C3/C4) and the P300 only on a montage with a centro-parietal site (L7.10’s matrix, now with a decoder behind it). What is left is real and useful: eyes closed against eyes open, a steady-state response to a flicker, and a blink switch that is honestly not EEG. This lesson builds each one the way the rest of the path builds everything — calibrate once, freeze the decoder into arrays the application can run without a classifier library, apply it block by block through the same causal chain the offline features came from — and reports every accuracy beside the band a classifier with no information would reach by luck, because at these trial counts that band is wide.
Concepts
What is decodable at rank four
Every source that reaches the scalp reaches all four electrodes, mixed; a decoder finds a weighting of the four that separates the classes. Eyes closed against eyes open works because posterior alpha appears at O1/O2 when the eyes close and the weighting can find it. A flicker response works because it lives at the stimulus frequency, where a reference sinusoid can find it without any fitting. A blink works because it is a same-sign deflection on the frontal pair. Motor imagery does not work, on either geometry, because the mu rhythm it changes is largest at C3/C4 and neither headband has an electrode there; the P300 does not work on the frontotemporal geometry, and works on an occipitotemporal one only to the extent that Pz’s field reaches its sites. None of that is a judgment of a device; it is the geometry, and the notebook’s numbers say what each geometry supports.
What this lesson connects to
No device is named. The replica is ds-eegbci on O1, O2, T7, T8 — the occipitotemporal-4 geometry cut from a gel research cap, an emulation of the geometry and of nothing else — and the P300 recording is ds-brain-invaders’ dry 16-channel headset, which has Pz. The frontotemporal geometry appears only as the synthetic stream’s frontal pair for the blink switch. The four-site P300 subset is chosen by a stated rule (the four of the headset’s sites nearest Pz on the unit sphere), not by trying subsets until one worked.
The chance band, and why it is wide here
The number a decoder reports is judged against the binomial interval a classifier with no information reaches by luck in n trials. With twelve apply windows per subject the 95 % band is 0.25–0.75; with the 144 windows pooled over twelve subjects it is 0.42–0.58; with the 509 epochs of the P300 recording it is 0.46–0.54. The library’s chance_interval reproduces Level 6’s helper exactly, and every accuracy in the notebook is printed beside its band. A per-subject accuracy of 0.75 on twelve windows sits on the band’s edge and is not evidence about that subject; the pooled number is what the claim rests on.
Calibrate once, freeze, apply — with a time split
The decoder is fitted on the first part of each minute, a window is skipped, and it is applied to the last part. That is the leakage guard, and it is temporal for a reason the lesson states plainly: each ds-eegbci subject has one eyes-open minute and one eyes-closed minute, no shippable four-channel set on this site has two sessions, and a second session is the only better guard. The site’s genuine cross-session case is L7.1’s train-on-one-session, test-on-the-other evaluation of ds-bci-iv-2a — compute-only, because that set is CC BY-ND and twenty-two channels, but the shape of the guard is the one to copy. The alternative — a shuffled split over overlapping windows of the same minute — reports 0.96 where the honest split reports 0.79, and the difference is not skill: adjacent overlapping windows share most of their samples and the minute’s slow state, so the shuffled split scores the copy, not the class (pf-decoding-leakage). Folds inside the calibration are in trial order, never shuffled, for the same reason.
Fitting happens once, through scikit-learn and pyriemann; then the pipeline is frozen — its covariance estimator, spatial filters and linear classifier become numpy arrays that replay the pipeline to floating-point precision, checked against the fitted pipeline before the decoder is returned and saved with nothing pickled. The application runs the arrays. It needs no classifier library, it cannot quietly refit on what it sees, and what was applied is exactly what was reported.
Eyes closed against eyes open on the replica
Twelve subjects, four-second windows through a 4–30 Hz causal FIR — the same chain the online loop runs, so offline and online features are one computation — CSP and LDA on four channels. The median per-subject apply accuracy is 0.79; two subjects sit at 0.50 and four at 0.83 or above; pooled over subjects the decoder is right on 0.76 of 144 windows against a band of 0.42–0.58. The signal is the posterior alpha L7.10 measured on every one of these subjects; the variation across subjects is what twelve windows can and cannot say about one person.
The P300 at 16, 8 and 4 channels
One ds-brain-invaders subject, epoched with the recipe nb-3-2 and nb-7-5 used and resampled to 128 Hz, decoded with Xdawn spatial filters and a shrinkage LDA — the first of nb-7-1’s P300 pipelines, scored by AUC because an oddball is imbalanced and accuracy would reward always answering “non-target”. Folds in trial order. At 16 channels the cross-validated AUC is 0.944; at 8 (the midline-and-posterior subset nb-7-5 used) 0.940; at the four sites nearest Pz — Pz, P3, P4, Oz — 0.846. nb-7-1 reports the same family at 0.912 as a mean over subjects with moabb’s own epoching; this is one subject with a different recipe, and both numbers are stated rather than reconciled. Four channels lose something and keep most of it, when they include the site the component needs; the frontotemporal geometry, which does not, is not tried, and the lesson says why rather than showing a number near chance.
A steady-state response, by canonical correlation
No SSVEP recording exists on this site, so the detector runs on the library’s planted flicker, where the answer is known: 12 Hz from 20 to 40 s, 15 Hz from 60 to 80 s, on the occipital pair. The detector is one QR and one SVD per candidate frequency against sine and cosine references — no fitting, no labels — and it names the planted frequency in every window inside each flicker and nothing in the windows between. The caveat is measurable before it is stated: a standing alpha rhythm correlates with a 10 Hz reference in every window, flicker or not (r ≈ 0.46 throughout), so a stimulus frequency inside the alpha band would report alpha as a response. Stimulus frequencies belong outside 8–12 Hz, and a score needs a no-stimulus baseline before it means anything.
A blink switch, labelled EOG
On a frontal geometry the fastest control there is has nothing to do with the brain: a voluntary blink is a same-sign deflection of a hundred microvolts or more on the frontal pair, and the quality gate of L7.12 already labels it. A switch built on that label catches 16 of 16 planted blinks with no spurious press. It is an electro-oculogram switch and is labelled so on every page of this path; it is honest, it works, and it is not a brain–computer interface.
The decoder block by block
The frozen eyes-closed decoder of one subject is applied to that subject’s held-out stretch as a stream through the library’s BCILoop in sliding mode: the same causal chain, the same four-second window, the same arrays. The posterior the application would show is the one the offline table reported, and the decoder’s latency is stated as such — the window is the delay (four seconds here), the causal filter’s 64 samples on top of it, and the dwell before a decision a choice rather than a cost.
The data behind this lesson
ds-eegbci (ODC-By 1.0): S001–S012, R01 and R02 on O1, O2, T7, T8. ds-brain-invaders (CC BY 4.0): subject 1, all 16 dry channels, the P300 paradigm. The library’s synthetic ssvep and blinks scenarios, seed 20260920, for the flicker detector and the switch. No headset produced anything on this page.
Explore
This lesson has no widget of its own; w-csp-explorer in L7.1 is the place to go further into what a spatial filter is finding.
Practice
A first BCI on four channels: the chance band held to Level 6's helper, eyes closed against eyes open on the occipitotemporal replica with a time-split calibrate-then-apply and the decoder frozen (and the leaky split beside it), the P300 at 16, 8 and 4 channels on one dry-headset subject, a steady-state response by canonical correlation on the planted flicker with the alpha caveat measured, a blink switch labelled EOG, and the decoder run block by block nb-7-15-bci
Downloads from ds-eegbci, ds-brain-invaders.
Exercises
Exercise ex-7-15-ec-eo-accuracy
NumericOn the occipitotemporal-4 replica the notebook fits an eyes-closed versus eyes-open decoder on the first part of each subject's two minutes and applies it to the last part after a skipped window — twelve four-second windows per subject, twelve ds-eegbci subjects. What is the median per-subject apply accuracy? Answer as a fraction between 0 and 1, to two decimals.
Exercise ex-7-15-p300-four
NumericOn ds-brain-invaders subject 1 the notebook decodes the P300 with Xdawn spatial filters and a shrinkage LDA, folds in trial order, on the four of the headset's sites nearest Pz (Pz, P3, P4, Oz). What cross-validated AUC does it report at four channels? Answer to two decimals.
Exercise ex-7-15-overlapping-windows
Multiple choiceA developer cuts a one-minute recording into four-second windows stepping every second, shuffles them, and reports five-fold cross-validated accuracy of 0.96 for eyes closed against eyes open. The time-split number on the same minute is 0.79. Which is the honest number, and why?
Pitfalls
Information leakage across CV folds
- Symptom
- Cross-validated accuracy collapses on a true held-out set.
- Cause
Cross-validation estimates performance on unseen data. The estimate is valid exactly to the extent that the held-out fold is unseen by the whole pipeline, not just by the classifier. Any step fitted on all the data before the split has already looked at the test fold, so the classifier is scored on data it has partly been fitted to.
- Detect
- Move the step inside the fold and re-run. The difference is the leak, measured in the units the paper reports. This is the only test that gives a number, and it takes minutes. - Permutation-test the entire pipeline. Shuffle the labels, re-run cross-validation, spatial filter and classifier together, a few hundred times. If the resulting null distribution is centred above chance, something in th…
- Fix
- Make the pipeline one object and fit it per fold. A Pipeline containing the spatial filter, the scaler and the classifier, passed to the cross-validator, leaks nothing by construction — the fix is structural rather than vigilant, which is what makes it reliable. - Nest the hyperparameter search. An inner cross-validation on the training folds chooses the parameters; the outer fold scores them.…
Site, amplifier or cap confounded with group or time
- Symptom
- Two amplifiers at two sites with different sampling rates; two cap systems over 20 years; 50 vs 60 Hz mains by country.
- Cause
Every acquisition choice leaves a fingerprint in the data (L0.3, L1.3): the hardware bandwidth and filters shape the spectrum, the amplifier’s noise floor sets the high-frequency baseline, the cap’s electrode set and reference change amplitudes and topographies, the sampling rate decides which harmonics are visible and how resampling behaves, and the mains frequency decides where the line and its…
- Detect
- Tabulate hardware per subject (site, amplifier, cap, rate, filters, reference, mains) from the dataset description and the file headers, and cross-tabulate it against the group and against the recording date; any cell imbalance is a confound. - Compute the hardware-sensitive measures (spectral slope over the full band, power above the physiological range, line-noise residue, noise floor) and te…
- Fix
- Design first: balance groups across sites and devices, or record every group on every setup; record era-matched controls in archives. - Harmonize what can be harmonized (resample to a common rate after proper anti-alias filtering, restrict to the common hardware passband, common reference, common channel subset) and state what cannot (noise floors, cap geometry). - Model setup explicitly (as a…
Terms used here
Every term this lesson leans on, with the one-line meaning. Follow a term for its full entry.
- Chance band
- The interval of accuracies a classifier with no information reaches by luck in n trials; an accuracy is evidence only when it clears it.
- Montage
- The set of channel derivations displayed or analysed; also the standard electrode-position layout.