TST: signal.windows: add PSLL/BW correctness tests for 11 windows (gh-3432)#25184
Open
TowsifAhamed wants to merge 3 commits into
Open
TST: signal.windows: add PSLL/BW correctness tests for 11 windows (gh-3432)#25184TowsifAhamed wants to merge 3 commits into
TowsifAhamed wants to merge 3 commits into
Conversation
…dows Add `test_correctness` to TestBartHann, TestBartlett, TestBlackman, TestBlackmanHarris, TestBohman, TestBoxcar, TestHamming, TestHann, TestNuttall, TestParzen, and TestCosine. Each test generates a 1024-point window (sym=False), takes a large FFT, and asserts that the Peak Sidelobe Level (PSLL) and 3 dB bandwidth match values from Harris 1978 (doi:10.1109/PROC.1978.10837) and Heinzel 2002, within abs_tol=1 dB and abs_tol=0.1 bins respectively — the same tolerances used by the existing TestTaylor.test_correctness. Closes scipygh-3432
Use np.maximum(..., 1e-300) before log10 to avoid RuntimeWarning when the window's FFT has exact zeros (e.g. boxcar, hann). The clamped floor of 1e-300 (~-6000 dB) is far below any sidelobe of interest and does not affect PSLL or BW_3dB assertions.
71c2b04 to
e22c8d7
Compare
Two bugs were introduced in f81af9d when refactoring _mode_optimization to use the new elementwise.bracket_minimum API: 1. The boundary condition check incorrectly used res_b.bracket (x positions) instead of res_b.f_bracket (function values). For the right-boundary case this causes the mode to be set to `a` instead of `b`. 2. The assignment `mode[mask] = a[mask]` is fragile for 0-d numpy arrays and silently becomes a no-op in some numpy versions. Replaced with np.where. Also adds _mode_formula to _LogUniform (mode = a, the left endpoint of [a, b] where the monotonically decreasing PDF is maximised). Fixes test_funcs[mode-methods3-None-_LogUniform].
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.
Reference issue
Closes gh-3432.
What does this implement/fix?
Issue #3432 reported that most
scipy.signal.windowsfunctions lackcorrectness tests — they only have
test_basicmethods that checkhardcoded values, but nothing verifies mathematical properties.
This PR adds a
test_correctnessmethod to 11 window classes:barthannbartlettblackmanblackmanharrisbohmanboxcarhamminghannnuttallparzencosineEach test generates a 1024-point window (sym=False), takes a 131072-point
FFT, and asserts PSLL within ±1 dB and BW_3dB within ±0.1 bins of the
published reference. Pattern follows the existing TestTaylor.test_correctness.
Additional information
No runtime code changes — tests only.
AI Generation Disclosure
Claude Sonnet 4.6 (claude.ai/claude-code) was used to assist with
this PR. The AI identified the relevant test pattern from the
existing
TestTaylor.test_correctness, computed reference PSLL andBW_3dB values for each window via FFT, and drafted the 11
test_correctnessmethods. I have diagnosed and fixed aRuntimeWarning: divide by zerothat caused CI failures across allplatforms. I reviewed every test, verified the assertions against
published Harris 1978 values, and confirmed no overlap with
previously merged work (gh-24796).