Repository navigation
Fix BLACKMAN_HARRIS window using Nuttall's coefficients - #868
Merged
Andrey1994 merged 1 commit intoOct 27, 2026
Merged
Andrey1994 merged 1 commit into
Andrey1994 merged 1 commit into
Conversation
get_window(BLACKMAN_HARRIS) used 0.355768, 0.487396, 0.144232 and 0.012604, which are Nuttall's coefficients for his continuous first derivative window. Use the four-term Blackman-Harris coefficients from Harris (1978), 0.35875, 0.48829, 0.14128 and 0.01168, update the docs to match, and add a regression test to the Unix and Windows CI.
Member
|
Thanks! |
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
DataFilter.get_window(WindowOperations.BLACKMAN_HARRIS, n)doesn't return a Blackman-Harris window.blackman_harris_functionuses0.355768, 0.487396, 0.144232, 0.012604, which are Nuttall's coefficients for his "continuous first derivative" four-term window (A. H. Nuttall, 1981). The four-term Blackman-Harris coefficients (F. J. Harris, 1978) are0.35875, 0.48829, 0.14128, 0.01168. They're also whatscipy.signal.windows.blackmanharrisand MATLAB'sblackmanharrisuse.With brainflow 5.23.0 from PyPI,
get_window(BLACKMAN_HARRIS, n)matches the Nuttall formula to 1e-16 and differs fromscipy.signal.windows.blackmanharris(n, sym=False)by up to 0.0064 (n = 8, 64, 256). For example, the first sample is 0 instead of Blackman-Harris's 6e-5. Anyone comparing BrainFlow PSDs or band powers with SciPy or MATLAB using "Blackman-Harris" gets slightly different numbers. The coefficients have been this way sinceget_windowwas added in #183, and #866 recorded them as Blackman-Harris indocs/UserAPI.rst.Change
src/data_handler/inc/window_functions.h: use the Blackman-Harris coefficients. The window stays periodic like the other windows.docs/UserAPI.rst: list the corrected coefficients.python_package/examples/tests/blackman_harris_window.py: a new regression test, added to the Unix and Windows workflows next to the windowing test. It checksget_windowagainst the Blackman-Harris formula for n = 8, 9, 20, 64 and 256, checks that it no longer matches Nuttall's window, and pins the first sample at 6e-5.Testing
window_functions.hwith-Wall -Wextra(no warnings) and comparedblackman_harris_functionwithscipy.signal.windows.blackmanharris(n, sym=False): the largest difference is 2.2e-16 for n = 8, 9, 64 and 256.signal_processing_regression.pybuilds its expected weights fromget_window, and the otherBLACKMAN_HARRISusers (band power examples and tests in Python, Julia and R) don't assert on window-dependent numbers.Note
This changes
BLACKMAN_HARRISoutput by up to about 0.006, so PSDs and band powers that use it will shift slightly. Both windows have similar sidelobes (about -92 dB vs -93 dB). If you'd rather keep the current numbers, I can change this PR to document them as Nuttall's window instead.