The feedback signal: band power in a buffer
"Alpha at Pz" is not a definition. A feedback signal is a band, a set of channels and how they are combined, a reference, a filter and its length, a derivation and a smoothing — each either exact in time or measured. Three ways to a band-power feature per block and what each costs; smoothing quantified as measured latency with the loopback probe; a baseline from calibration and what an adaptive threshold does to a learning claim; the channels of a montage combined with the combination stated.
Prerequisites: L7.3 · Real-time processing and neurofeedback, L7.12 · Signal quality you can act on live, L1.3 · Power spectral density, L4.4 · Baseline normalization and ERD/ERS
What you will be able to do
- Compute a band-power feature per block by three methods and state what each adds to the budget
- Choose smoothing and quantify it as measured latency with the loopback probe
- Set a baseline from a calibration block and explain what an adaptive threshold does to a learning claim
- Combine the channels of a montage into one feedback value with the combination stated
Why this matters
L7.3 listed five decisions a neurofeedback protocol has to state, and the first was the one most often left as a phrase: what the signal is. “Alpha at Pz” names a band and a site and says nothing about the reference, the filter and its length, whether the value is a root-mean-square over a block or a Welch estimate over a window, how many channels went into it and how, and how much it was smoothed — and every one of those is a decision with a cost in time, some of them exact and some of them not. This lesson is the statement of the signal, made as a data structure the library can print in one sentence, and then the costing: what each choice adds to the latency budget, with the exact rows summed and the inexact ones measured by the same loopback probe L7.3 used. It ends with the two decisions the rest of the path needs settled — how the baseline is fixed, and how a montage’s channels become one number — because L7.14’s claim about learning depends on both.
Concepts
The signal, stated once
The library’s SignalSpec is the first of L7.3’s five decisions as data: the band, the channels and how they are combined, the reference, the filter’s tap count, the derivation (RMS per block, or log power), and the smoothing time constant. Its describe() is one sentence — for the occipital pair of the four-channel replica at 160 Hz with 32-sample blocks: 8–12 Hz at O1, O2 with no re-referencing, a causal linear-phase FIR of 129 taps (group delay 400.0 ms), the root-mean-square per block averaged over those channels, updated every 200 ms (5.0 Hz), unsmoothed. That sentence is what CRED-nf item 4 asks a report to contain, and it is what the session log stores beside every value the participant saw. A signal that cannot be written that way is not yet a signal (pf-vendor-derived-features).
What this lesson connects to
No device is named here. The loop runs at the two rates the consumer path’s geometries deliver — 256 Hz and 250 Hz, per the board table in L7.10 — and the notebook uses 256 Hz with 64-sample blocks for the four-channel loop; the L7.3 pipeline at 160 Hz with 32-sample blocks is the one every implementation is cross-checked on, because that is the rate of the replica the widget replays. Nothing in the budget depends on which headset produced the samples; everything depends on the rate, the taps and the block, which is the point.
Three implementations, one budget
The latency arithmetic exists three times on this site on purpose: in the course library, in the L7.3 notebook helpers it was ported from, and as a SciPy-computed reference shipped beside the widget’s traces so its TypeScript can be checked rather than trusted. Three copies are a liability unless something holds them together, and the notebook’s first section is that something: every quantity for the L7.3 pipeline — the worst case under both buffer conventions (610.00 and 603.75 ms), the mean over block position (510.00), the filter row (400.00), the zero-phase-live total (1010.00) and its look-ahead (128 samples), a fourth-order Butterworth’s group delay at 10 Hz (32.727 samples), and the probe’s measured filter and value delays — is computed by all three, and the largest disagreement is 4.6 × 10⁻⁴ ms, which is the probe’s own accuracy in milliseconds and not a looser tolerance that would hide one. On the shipped eyes-closed trace the library’s offline loop and helpers_l7.alpha_feedback agree to 10⁻¹² µV on every block, with and without smoothing — a tolerance that is a fact about floating point.
Three ways to a band-power feature per block, and what each costs
Level 4 taught time-frequency analysis; a feedback signal needs only as much of it as fits in a buffer, and the honest question about each method is not which is best but what it costs and whether the cost is a number:
- RMS of the filtered block. The block is the delay, and it is already the buffer row; the step adds an exact zero on top. The probe measures the value delay at 503.1 ms for the L7.3 pipeline, against the exact expectation of 503.13 — the group delay plus (B + 1)/2 samples, the block’s own centre of mass plus the wait for it to complete.
- A filter-Hilbert envelope of the block. The analytic amplitude over the block, averaged. The block is still the delay and the probe lands in the same place; what changes is that the Hilbert transform of a finite block is not the Hilbert transform of the stream, which matters at the block’s edges and is measured, not assumed.
- Welch band power over a window. A two-second window’s centroid sits near half its length; the probe reads 1400 ms — a second on top of the filter — and that is not a defect but a definition. A window says what it means.
None of the three is “the” band power. The one chosen is part of the signal’s statement, and the budget lists it as an exact row or as a measured delay accordingly.
Smoothing is latency, measured
A one-pole smoother on the per-block value buys a steadier bar and costs time, and there is no single number for that cost: the impulse response never ends, so any delay quoted for it is a criterion. The budget therefore does not add a row; it lists the smoother under measured and the probe fills it in. On the four-channel loop — 256 Hz, 129 taps, 64-sample blocks, 10 ms of stated processing — the exact rows are 250.00 (filter) + 250.00 (buffer) + 10.00 (processing) = 510.00 ms worst case under the block-period convention (506.09 first-to-last; 385.00 mean over block position). The probe’s value delay is 377.0 ms without smoothing, against 376.95 expected; 615.9 ms with a 0.5-s smoother, and 477.8 ms with 0.25 s, each averaged over every alignment of the block grid with a spread of about ±8 ms. The smoothing cost — 239 ms at τ = 0.5 s — sits beside the exact total, never inside it. The widget’s feedback mode prints the same row in the same place, and its numbers are held to the library’s on the shipped asset.
The baseline: fixed, or adaptive
Decision 3 of L7.3. A fixed baseline is set once from a calibration block — the median and a robust spread of the first ten seconds, say — and does not move, so a later change in the signal is a change relative to something and “improvement” has a definition. An adaptive baseline follows the participant, re-fixed from the last thirty seconds; it keeps the display responsive, and it makes the reward rate a property of the rule. The notebook runs both on the same synthetic signal with a planted 60 % rise: under the fixed baseline the reward rate climbs from 0.23 to 0.81; under the adaptive one it stays at 0.24 → 0.21 while the signal rises by more than half. The library carries both, each with a note on what it does to a learning claim, and the session log records the raw value and the threshold as separate columns so the outcome can be computed on the raw signal whatever rule drove the display (pf-adaptive-threshold-moving-target).
Combining the channels of a montage
Decision 1 again, on four channels: which of them go into the value, and how. On the four-channel replica asset the same chain gives a calibration median of 38.6 µV for the occipital pair, 6.6 µV for the temporal pair and 23.1 µV for all four averaged, with correspondingly different spreads and a different fraction of blocks above threshold; the temporal pair carries less of the eyes-closed alpha, which is the montage fact L7.10 made before this lesson used it. The combination — the mean of the per-channel block RMS over the channels named — is in the spec’s sentence, and the widget’s feedback mode lets you switch it and watch the value change. The notebook also recomputes the reference the widget ships (feedback.json, written by the library on this asset) and finds it reproducible to 2 × 10⁻⁶ µV, which is the check that the widget is being held to something real.
The data behind this lesson
The shipped latency-widget assets: alpha-ec (ds-eegbci S001 R02, O1, 10 s at 160 Hz, ODC-By 1.0) for the block-by-block comparison, and oc4-ec (the same subject and run on O1, O2, T7, T8, 60 s — the occipitotemporal-4 replica, a montage emulation on a gel research recording, not a consumer recording) for the channel combination; the SciPy reference in traces.json; the library’s synthetic alpha-schedule stream with a planted rise for the baseline; and the loopback probe for every measured delay. No headset produced anything on this page.
Explore
Raise the smoothing and watch the measured row grow while the exact total does not. Change the calibration length and only the threshold moves; change the channel set and the value itself changes. Then switch through the four control conditions and notice that every one of them looks like feedback.
Practice
The feedback signal: three implementations of the latency budget held to each other and to the SciPy reference, the library's loop against helpers_l7 to 1e-12 on the shipped trace, three band-power derivations per block and what each costs, smoothing measured by the loopback probe on the four-channel loop, a fixed against an adaptive baseline on a planted rise, and the channels of a montage combined with the combination stated nb-7-13-feedback
Downloads from ds-eegbci.
Exercises
Exercise ex-7-13-smoothed-delay
NumericThe four-channel loop runs at 256 Hz with a 129-tap linear-phase FIR band-pass and 64-sample blocks, and a one-pole smoother with a 0.5-second time constant on the per-block value. The notebook measures the loop's value delay with the loopback probe, averaged over every alignment of the block grid. What did it measure, in milliseconds?
Exercise ex-7-13-exact-rows
NumericSame loop — 256 Hz, a 129-tap linear-phase FIR, 64-sample blocks, 10 ms of stated processing — with no smoothing. Using the BLOCK-PERIOD convention for the buffer term, what is the worst-case end-to-end latency of the exact rows, in milliseconds?
Exercise ex-7-13-adaptive-threshold
Multiple choiceA protocol re-sets the reward threshold every thirty seconds to the 50th percentile of the last thirty seconds of the feedback signal, and reports that participants were above threshold about half the time in every session. What does that reward rate tell you about whether the signal changed?
Pitfalls
Filtering across discontinuities
- Symptom
- Ringing at file joins, breaks, or buffer edges.
- Cause
At a discontinuity the signal jumps: from the last sample of one run to the first sample of the next, from a value to zero padding at the file edge, or from the DC offset of one recording to that of another. To a filter a jump is a step, and a step response with overshoot or a long settling time produces ringing (for sharp FIR and high-order IIR filters) or a slow exponential swing (for a high-pa…
- Detect
- Keep a list of boundary events (MNE annotations of type BADboundary or equivalent) and inspect the filtered data around each one. - Look at the start and end of every file after filtering; compare with the unfiltered data. - Compute the impulse-response length of your filter and mark that much data on each side of every boundary as suspect. - In real-time pipelines, filter a test signal with a…
- Fix
- Filter each continuous run separately, then concatenate; never filter across a join. - Where a join is unavoidable, annotate the boundary and exclude epochs that overlap the boundary plus the filter’s impulse-response length. - Pad sensibly at file edges (MNE reflects the data by default; state the padding method) and discard the padded region’s worth of data from analysis. - Real-time: carry f…
An adaptive threshold is a moving target
- Symptom
- Reward rate is the same in every session, whatever the signal did, and 'improvement' has no definition.
- Cause
An adaptive threshold — re-fixed from the last thirty seconds, the last block of trials, or the previous session — keeps the participant near threshold by construction. That is its purpose: it makes the display feel responsive and keeps the reward rate in a band the protocol designer chose. But the reward rate is then a property of the rule, not of the signal. A participant whose alpha doubled an…
- Detect
- Read the protocol for the threshold rule. “Adjusted to maintain a reward rate of about x %” is the sentence. - Plot the reward rate across sessions. Flat at the target rate, whatever the signal did, is the signature. - Check whether the raw feature and the threshold were logged separately. If only the reward events survive, the outcome cannot be recovered. - Ask whether the pre-registered outco…
- Fix
- Separate the two jobs. Let the display use whatever rule trains best, and define the outcome on the raw feature against a baseline fixed once, before training, and never re-fixed. - Log the raw per-block value and the threshold as two columns (the library’s session log does), so the outcome can be computed after the fact even if the display rule changes. - Pre-specify the learning outcome on th…
Terms used here
Every term this lesson leans on, with the one-line meaning. Follow a term for its full entry.
- Group delay
- The delay a filter imposes on the envelope of a signal at each frequency; constant for linear-phase filters.
- Montage
- The set of channel derivations displayed or analysed; also the standard electrode-position layout.