Skip to content

perf(signals): incremental mains-notch (persist causal filter state) - #16

Merged
RaulSimpetru merged 1 commit into
mainfrom
perf/signals-incremental-notch
Jul 23, 2026
Merged

perf(signals): incremental mains-notch (persist causal filter state)#16
RaulSimpetru merged 1 commit into
mainfrom
perf/signals-incremental-notch

Conversation

@RaulSimpetru

Copy link
Copy Markdown
Member

What

The signal-viewer display notch now filters only the newly-arrived samples each frame, persisting the causal IIR filter state on the viewer, instead of re-filtering the whole visible window every frame.

Why

Re-filtering the full window each frame was "super slow" at high sample rates. At 10240 Hz × 16 channels this is ~300× less notch compute per frame (~40 ms → ~0.15 ms). The drawn trace is unchanged except for a microscopic improvement at the far-left settling edge — persistent state means an already-drawn sample is never revised as the window scrolls.

How

  • Adds NotchCache + NotchFilter (incremental causal notch that keeps zi state and the filtered tail it has produced).
  • Adds a locked Stream.get_raw_snapshot_stable() — a copy tagged with an epoch + absolute sample sequence — so the stateful filter can distinguish new samples from ones already filtered and never tears on a concurrent buffer refresh.

Verified

  • tests/test_mains_notch.py + tests/test_signal_viewer_decimation.py updated and passing (36 tests; benchmark shows ~296× less notch compute).
  • Full suite: 487 passed.

The display notch now filters only the newly-arrived samples each frame,
persisting the causal IIR state on the viewer, instead of re-filtering the whole
visible window — which made the notch "super slow" at high sample rates. At
10240 Hz x 16 channels this is ~300x less notch compute per frame (~40 ms ->
~0.15 ms). The drawn trace is unchanged bar a microscopic improvement at the
far-left settling edge (persistent state never revises an already-drawn sample).

Adds `NotchCache` + `NotchFilter`, and a locked `Stream.get_raw_snapshot_stable()`
(a copy tagged with an `epoch` + absolute sample sequence) so the stateful filter
tells new samples from seen ones and never tears on a concurrent buffer refresh.
@RaulSimpetru
RaulSimpetru merged commit 4feedc0 into main Jul 23, 2026
4 checks passed
@RaulSimpetru
RaulSimpetru deleted the perf/signals-incremental-notch branch July 23, 2026 16:39
RaulSimpetru added a commit that referenced this pull request Jul 23, 2026
Cut 2.3.2 — the incremental display mains-notch (#16) and its
reconnect / pause / replay-loop hardening (#17). Perf improvement to an
existing feature plus edge-case fixes; no new user-facing feature and no
breaking changes, hence a patch bump.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant