Repository navigation
Evaluate filter gain at the requested frequency - #729
Merged
Merged
Conversation
Add tests for filter gain at various frequencies and coefficients.
Updated filter gain evaluation to handle frequencies more accurately, fixing an IndexError at the Nyquist frequency.
tompollard
approved these changes
Nov 25, 2026
Member
There was a problem hiding this comment.
Thanks @Kulraj69! I reviewed the exact-frequency evaluation and its tests. This fixes the off-grid gain error and the Nyquist failure. The relevant offline tests passed locally (248 passed), and all PR checks are green. Looks good to me.
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.
Problem
processing.get_filter_gainevaluates 512 defaultscipy.signal.freqzgrid points, then takes the first point at or above the requested frequency. This rounds off-grid measurements upward. It also raisesIndexErrorat Nyquist and sufficiently close below Nyquist because the default grid excludes that endpoint.For example, a two-tap moving-average filter has analytic gain
abs(cos(pi * f / fs)). Its gain atf = 0.1234 * fsshould be measured there, rather than at the next grid point.Change
Evaluate
freqzat the requested angular frequency usingworN=[w_gain]. Clarify the frequency units and Nyquist behavior in the docstring, and add a changelog fragment.The 32 parameterized regression cases use analytic identity, moving-average, first-difference and first-order IIR responses at DC, off-grid frequencies and Nyquist for two sample rates. They also check that coefficient inputs are unchanged.
Validation
Against upstream
167f6714aac9b2a8b47bb11ff94c1e3782f02d3a:tests/test_processing.pyandtests/test_hr.py: 248 passed, with network tests excluded.-W --keep-going -E): passed.Python 3.12.16. Full-repository tests, other dependency/Python versions and remote CI were not run. This was prepared and tested with AI assistance, without independent human review.
This intentionally replaces historical grid rounding with exact-frequency evaluation, so callers using the gain for normalization can see small numerical differences. No new validation contract for negative, nonfinite or above-Nyquist inputs is introduced. No clinical validation is claimed.