Signal quality you can act on live
Offline you inspect what a cleaner removed and run again; online you get one pass, so the honest move is to detect a bad stretch and suspend the feedback. A per-channel quality gate on the raw block, three states with a hold, blinks on a frontal montage and not on an occipital one, the gate scored against the offline artifact timeline on the same recording, and a consumer export's own quality columns — shown, never used as truth.
Prerequisites: L7.11 · Getting a stream: timestamps, dropped samples, drift, recording, L0.5 · The artifact atlas, L2.7 · ASR, SSP and alternatives
What you will be able to do
- Compute per-channel quality on each raw block
- Build a three-state gate (good / suspect / unusable) with hysteresis and a stated hold
- Detect blinks on a frontal montage and explain why an occipital montage cannot
- Compare the online gate against the offline artifact timeline on the same recording
Why this matters
L7.3 ended its section on artifacts with one rule: gate rather than clean. Offline, you can inspect what a cleaner removed, disagree with it, and run again. Online, there is one pass and nobody looking, and a feedback signal driven by a blink is worse than no feedback at all — the participant is being rewarded for blinking. So the online policy is to detect a bad stretch and suspend the display, never to feed it a cleaned estimate of something that was not measurable. This lesson builds that gate for four channels, and then does the thing a gate’s author owes the reader: measures how good it is, on planted answers where the truth is known, on a real replica where it is not, and against the site’s own offline detector on the same minute of recording. It ends with the consumer export’s own idea of quality — a column of numbers on a scale nobody published — and what to do with it, which is to look and not to trust.
Concepts
Quality is measured on the raw block, first
The gate runs first in the chain, on the raw block, before the band-pass that produces the feedback signal — because every criterion it uses needs exactly what a band-pass removes. The mains line at 50 or 60 Hz tells a coupled electrode from a clean one; the 25–100 Hz band tells muscle from EEG; the DC level and the spread of a window tell a flat or railed channel. L7.10 measured what an on-device notch and a 1–40 Hz filter do to those diagnostics: they remove them. The library’s chain refuses a filter placed before the gate for the same reason (CANONICAL_ONLINE_ORDER begins with quality), and the rule is in the step contract, not in prose.
The criteria, ported and cited
Every threshold the gate uses comes from data/scripts/detectors.py — the detectors that produced this site’s shipped artifact annotations — made causal, and the gate’s describe() prints where each one came from:
- flat: a window’s standard deviation below 0.5 µV, or a run of unchanging samples;
- pop: an abrupt step between the two halves of the window on one channel, above 6 robust standard deviations and 100 µV, that its neighbours do not share — or a sample-to-sample jump above 100 µV on one channel with every other channel below 30 % of it. A pop is a local event, so on a one-channel stream the gate makes no pop claim at all (L7.11’s report says so);
- blink: on a frontal channel, a same-sign 0.5–15 Hz deflection above 4 robust standard deviations and 50 µV;
- emg: 25–100 Hz RMS above 3 times its running median and 4 µV;
- line-noise: Welch power at the mains more than ten times the median 2–8 Hz away;
- gap: the block arrived after a loss the source reported (L7.11).
The gate reads a one-second window and decides once per block. Its delay is a decision delay — the signal itself is not delayed — which is why the latency budget (L7.13) lists the window under “decision” rather than adding it to a total that means something else.
Three states, and a hold
The verdict has three states, and the difference between the second and the third is the whole policy. Unusable — a flat, popped, blinking or muscle-laden channel, or a block after a loss — closes the gate: the display is frozen or zeroed for the block and for a stated hold afterwards (half a second by default), so the display does not flicker at the edge of an artifact and a blink’s tail is not rewarded. Suspect — a visible mains line — is fed back and labelled: a line at the mains is the normal state of an un-notched recording, the band-pass removes it, and closing on it would close forever; the label travels with the session log, so an analysis can see how much of a session was suspect. Good is the rest. A channel’s state and the block’s verdict are both logged, per block.
Planted answers: how sensitive is the gate?
A gate’s author owes the reader a number, and the only place a sensitivity can be verified rather than merely reported is a stream where the truth is planted. The library’s synthetic stream plants frontal blinks, single-channel pops, a flat channel and a mains line with a truth dict; the notebook runs the gate over each and scores it. On 27 planted blinks on the frontal pair the gate labels 27 of 27 within 1.5 s of onset, with no blink window outside a planted one; both planted pops are labelled on their channel and nowhere else; the flat channel is flat in every decision and the others in none; the mains line is suspect in every decision and unusable in none. Those are the numbers for planted artifacts of the shapes the detectors define. A real blink on a dry electrode is not a planted Gaussian, which is why the next two sections exist.
The replica: how often is a second unusable?
On the occipitotemporal-4 replica — twelve ds-eegbci subjects, one eyes-open minute each, gel electrodes, no hardware filters — the gate calls a median of about 5 % of one-second decisions unusable, with a range from under 1 % to 100 %: one subject’s replica has a channel that is unusable for the whole minute, and the gate reports that rather than averaging it away. No frontal site exists on this geometry, so no blink label can occur; what closes the gate is muscle at the temporal sites, a pop, or a flat channel. About half of all decisions are suspect — the mains line of an un-notched research cap — and are fed back. Those fractions are facts about this replica; on a dry headband at the same sites they are measured the same way and belong in that recording’s log, and nothing here says what they would be.
Online against offline, on the same minute
The site’s offline detector (helpers.detect_artifacts) sees all 64 channels and labels blinks from Fp1 and Fp2, the sites where a blink is largest. The online gate sees four. The notebook runs both on the same minute, twice. On the occipitotemporal replica the gate’s describe() says no frontal channel in this montage and produces no blink window, because it has nothing to read one from. On a four-channel set whose frontal pair is the exact AF7/AF8 of the frontotemporal geometry — the cap has those two; TP7/TP8 stand in for the TP9/TP10 it lacks, a stated substitution used for nothing but the gate’s non-frontal channels — the gate’s blink windows match 11 of 18 offline blink events, with one online window matching no offline event. The two detectors use different sites, different windows (0.4-s events against 1-s decisions with a hold) and the same amplitude criterion in spirit; the gap between them is a fact about what four channels at those sites can see, which is L7.5’s point restated with a number.
What the consumer export’s quality columns are
The directory’s only downloadable consumer front-end (ds-areeg, CC BY 4.0) exports a CSV whose 67 columns include 14 electrodes beside contact-quality (CQ.*), signal-quality (EQ.*) and motion (MOT.*) families. The notebook fetches one participant’s first recordings by HTTP range request and runs the same acceptance report as every other stream on this site: the spectrum falls 20 dB below its 4–20 Hz level from about 50 Hz of a 64 Hz Nyquist on every channel, and the line ratio at 50 Hz is in the fifties while at 60 Hz it is below one — the front-end’s own roll-off and the mains of the room where it was recorded, read off the signal. Beside that, the EQ.O1 column: a periodic firmware report on a unitless scale, written on a fraction of rows and padded with blanks, plotted next to an 8–12 Hz power the notebook computes from the raw EEG.O1 column with a stated method. The two rise and fall at different times. The column is shown; nothing derives from it (pf-vendor-derived-features, whose figure is this).
Why ICA is not an option at rank four
Independent component analysis returns at most as many components as there are channels. On a 64-channel cap a blink has a component of its own, the analyst inspects it, and removing it costs the EEG little (L2.6). On four channels there are four components to hold a blink, a muscle burst, the mains line, the alpha rhythm and everything else at once, so every component is a mixture and “the blink component” is whatever mixture the fit found on the minute it was given. The notebook measures what that mixture does on the same minute as the offline reference: it picks the component whose time course follows the offline blink events (at both ranks the best correlation is a modest 0.39), removes it, and reports two numbers — how much of the blink amplitude at AF7 went, and how much of the 8–12 Hz power at TP7/TP8 stayed. On this minute the two ranks come out comparable: about two thirds of the blink amplitude removed and essentially all of the temporal alpha kept at rank four, a little less removed and the same alpha kept at rank 64. The numbers are printed as they come and are not tuned to make a point.
The objection to online ICA at rank four is therefore not that it always destroys the signal on a one-minute test. It is structural — four components for every source, so what a component contains cannot be known from its index — and procedural — a fit chosen by a 0.39 correlation with a reference that does not exist online, applied with nobody watching, is a cleaner nobody inspected. L7.3’s rule was written for exactly that situation: gate rather than clean. The gate labels the block and freezes the display, and what it did is in the log.
The data behind this lesson
ds-eegbci (ODC-By 1.0): S001–S012 R01 on O1, O2, T7, T8 for the replica; S001 R01 on all 64 channels for the offline reference and on AF7, AF8, TP7, TP8 for the frontal-pair gate. ds-areeg (CC BY 4.0): participant 1’s first three recordings, fetched by range request, inflated in memory, never written to disk; its EQ.* columns shown and used for nothing. The library’s synthetic scenarios blinks (27 planted blinks), pops, flat-channel and line-noise, seed 20260920, for every sensitivity number. No headset produced anything on this page.
Explore
Widen and narrow the notch on the eyes-open trace and watch the spectrum around the mains. Then ask which of the gate’s criteria above could still be evaluated on the notched output.
Practice
Signal quality you can act on live: the gate's criteria cited, its sensitivity on planted blinks, pops, a flat channel and a mains line, three states and a hold, how often a second is unusable on the occipitotemporal replica, the online gate against the offline artifact timeline on the same minute, one consumer export's edge, hole and quality columns, and ICA at rank four measured nb-7-12-quality
Exercises
Exercise ex-7-12-unusable-fraction
NumericOn the occipitotemporal-4 replica — O1, O2, T7, T8 of ds-eegbci subjects S001 to S012, run R01 (eyes open) — the notebook runs the quality gate with a one-second window and a half-second hold at 60 Hz mains. What is the median fraction of one-second decisions the gate calls unusable, across the twelve subjects? Answer as a fraction between 0 and 1, to three decimals.
Exercise ex-7-12-blink-sensitivity
NumericThe notebook plants 27 blinks on the frontal pair of the library's synthetic frontotemporal-4 stream and runs the gate over it. What fraction of the planted blinks does the gate label within 1.5 s of onset? Answer as a fraction between 0 and 1.
Exercise ex-7-12-ica-rank
Multiple choiceA developer proposes running ICA on the four-channel stream to remove blinks before computing the feedback signal, as the offline pipelines of Level 2 do on a 64-channel cap. Why is that not the online policy here?
Pitfalls
EMG reported as gamma
- Symptom
- Broadband high-frequency power over temporal/frontal sites tied to jaw or neck.
- Cause
Scalp muscles (temporalis, frontalis, masseter, the neck extensors) produce electrical activity that is large compared with cortical gamma, broadband from roughly 20 Hz upward with no single peak, and sits directly under the electrodes that “show the effect”. Its amplitude is modulated by anything that changes muscle tone — and many experimental manipulations do. The spectrum of EMG overlaps the…
- Detect
- Topography: cortical gamma from a focal source is rarely largest at the edge of the montage; EMG is. Look at T7/T8, F7/F8, FT sites and the occipital rim. - Spectral shape: EMG raises the floor across a wide range with no peak; a genuine oscillation has a peak above the aperiodic background (L1.7, L4.6). - Time course: EMG turns on and off with muscle events (swallows, jaw movement, blinks with…
- Fix
- Instruct and monitor: relaxed jaw, no talking, breaks; record a facial EMG channel where high frequencies matter. - Clean before measuring: ICA with muscle-component removal, or rejection of segments with high-frequency power above a threshold (L2.5, L2.6); state what was removed. - Report a peak, not a band: use spectral parameterization to show a gamma peak above the aperiodic background befo…
A green contact indicator is not a signal
- Symptom
- Every electrode's contact indicator is green, and the trace under it is mains, muscle or a railed amplifier.
- Cause
A contact indicator is an impedance measurement: the device drives a small current through the electrode and reports whether the return path is low enough. That says the electrode touches skin. It does not say what the electrode is recording. A dry electrode on hair with a good contact reading picks up whatever is largest at that site — mains coupling through a poor reference, the temporalis and…
- Detect
- Line ratio. Welch power at the mains frequency against the median power 2–8 Hz away. A ratio far above ten on one channel, not shared by its neighbours, is coupling on that electrode, whatever the indicator says. - High-frequency ratio. RMS in 25–100 Hz against RMS in 1–25 Hz. Muscle raises it; EEG does not. Ask the participant to clench and watch which channel answers. - Flatness. A window’s s…
- Fix
- Measure quality from the signal, not from the indicator, and gate feedback on what you measured: a channel labelled unusable freezes the display rather than feeding it. - Reseat the electrode, part the hair, moisten a dry contact; re-check by the signal criteria, not by the colour. - Keep the device’s own filters off if it lets you, so the diagnostics stay checkable; if it does not, record that…
A vendor-derived column is not the signal
- Symptom
- A "focus", "calm" or band-power column from the headset's export is used as the feedback signal or as a feature, and nobody can say how it was computed.
- Cause
A consumer export is a vendor product, not a raw file with metadata attached. Most of its columns are computed on the device or in its app from the electrodes, through a pipeline whose parameters are proprietary, may change with a firmware update, and may already include a notch, a smoothing and a per-user normalisation that nobody wrote down. A quality score is an impedance-like indicator on the…
- Detect
- Can you write the computation down — band, window, filter, reference, normalisation, update rate? If not, it is a vendor column. - Is the column written on every row, or only when the firmware updates it? A periodic report padded with blanks is not a per-sample signal. - Does its scale have units? A number from 0 to 100 or 0 to 4 with no unit is a score, not a power. - Compute the quantity you…
- Fix
- Compute the feedback signal, the features and the outcome from the raw electrode columns, with the band, the window, the filter and the reference stated — L7.13’s SignalSpec is the shape of that statement — and log the parameters with the session. - Keep the vendor columns as what they are: a description of the device’s own view, useful for reading and never used as truth. Show them next to you…
Terms used here
Every term this lesson leans on, with the one-line meaning. Follow a term for its full entry.