Expand description
Noise filters applied to exported data (never to the archive).
The same pipeline, with the same arithmetic, runs in the webapp’s live plot
(webapp/src/lib/filters.ts); the shared vectors in testdata/filter-vectors.json
check that both give the same output. Per sample, in order:
- Despike (raw volts): grey opening, a running minimum then a running maximum over
w = ceil(2.5 ms × fs)samples. It removes upward spikes narrower thanwand keeps wider pulses and anything downward. Outputjneeds inputj + w - 1. - and 3. Remove the 10 Hz and 11.906 Hz square waves (raw volts): subtract running templates of one period in phase bins, indexed by the sample count since the segment started (both sources run on the LabJack clock). Each bin keeps a running mean (cumulative at first, then exponential with a 30 s memory); the template is the bin mean minus the running mean of all samples. Templates are read before the sample updates them, and each learns from the sample minus the other’s current template.
- Calibration.
- High-pass, then low-pass: 2nd-order Butterworth biquads. The live plot runs them
causally; exports run them forward and backward (
ExportFilter).
The channel settings come from the export request (the webapp copies them from the
channel’s sensor_settings.filters entry); see docs/src/reference/kv-config.md.
Structs§
- Biquad 🔒
- One biquad, transposed direct form II. The first finite sample after a reset sets
the steady state for that value;
NaNin givesNaNout and keeps the state. - Biquad
Coefficients 🔒 - Normalised biquad coefficients (
a0 = 1). - Channel
Filter Settings - Filters of one channel, cleaned:
trueswitches and positive cutoffs only. - Despiker 🔒
- Streaming grey opening over
wsamples: outputjis the largest of the minima of thew-sample windows containingj, windows cut at the segment’s ends andNaNleft out. Emitted once inputj + w - 1has arrived, or bySelf::flush. - Entry 🔒
- One queued sample of
ExportFilter. - Export
Filter - Rows of one channel, in time order, filtered with the zero-phase pipeline.
- Filter
Plan - What runs for one channel at one sample rate; from
plan_filters. - Filtered
Row - A filtered row handed back by
ExportFilter. - Linear
Filter Chain - High-pass then low-pass on calibrated values.
- Periodic
Template 🔒 - Running template in phase bins; see the module documentation. A bin with no sample
yet uses the mean of its group of
groupbins (the coarse bin). - RawFilter
Chain - Despike and template stages, on raw volts. Appends outputs in input order: none for
the first
despike_window - 1inputs of a segment, then one per input;Self::flushappends the rest. - Segment 🔒
- Filter state of one contiguous segment.
Constants§
- DESPIKE_
WINDOW_ MS - Length of the despike window, ms.
- ELEVEN_
NINE_ HZ - Frequency of the second square wave, Hz, measured on MU1 and MU2 (lines at 11.906, 35.72 and 59.53 Hz). It also runs on the LabJack clock.
- FRACTIONAL_
BINS_ PER_ SAMPLE - Phase bins per sample of period in the fractional template.
- MAX_
CUTOFF_ FRACTION - Highest usable cutoff, as a fraction of the sample rate.
- MAX_
FILLED_ GAP_ SAMPLES - Longest run of missing samples filtered through as
NaN. A longer gap ends the segment and every filter starts over. - MIN_
FRACTIONAL_ BINS - Fewest phase bins of the fractional (11.9 Hz) template.
- MIN_
TEMPLATE_ PERIOD_ SAMPLES - Fewest samples per period for a template.
- PERIOD_
TOLERANCE_ SAMPLES - How far
fs / 10may be from a whole number of samples. - PROBE_
ROWS 🔒 - Rows used to estimate the sample interval of a segment.
- TEMPLATE_
MEMORY_ S - Memory of the template running means, seconds.
- TEN_HZ
- Frequency of the first square wave, Hz. Its period must be a whole number of samples.
Functions§
- butterworth 🔒
- 2nd-order Butterworth by the bilinear transform with prewarping (the audio-EQ cookbook with Q = 1/√2).
- cutoff 🔒
- Reads a cutoff: a finite number above 0, or a string holding one.
- plan_
filters - Works out which filters run at a sample rate; filters that cannot run (too low a
rate, a 10 Hz period that is not a whole number of samples, a cutoff at or above
0.45 × the rate) are left off. Same rules as
planFiltersin the webapp. - settle_
seconds - Samples the backward pass needs past a sample for the result to have settled:
twenty time constants of the lowest cutoff (a 2nd-order Butterworth pole decays
with time constant
√2 / (2π fc)), at least one second and at most two minutes.