perf(signals): incremental mains-notch (persist causal filter state) - #16
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
NotchCache+NotchFilter(incremental causal notch that keepszistate and the filtered tail it has produced).Stream.get_raw_snapshot_stable()— a copy tagged with anepoch+ 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.pyupdated and passing (36 tests; benchmark shows ~296× less notch compute).