Skip to content

Added safety checks for filter stability #12562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 5, 2025
commit 9977d00baf12229ba04e90b9b2de494f0002cef5
18 changes: 10 additions & 8 deletions audio_filters/butterworth_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
Alternatively you can use scipy.signal.butter, which should yield the same results.
"""


# All calls to filter creators must have keyword arguments
def safe_checks(filter_creator):
def safe_filter_creator(**kwargs):
if not isinstance(kwargs['frequency'], int) or kwargs['frequency'] <= 0:
raise ValueError('Frequency must be a positive integer.')
if not isinstance(kwargs['samplerate'], int) or kwargs['samplerate'] <= 0:
raise ValueError('Samplerate must be a positive integer.')
if not (0 < kwargs['frequency'] < kwargs['samplerate'] / 2):
raise ValueError('Frequency must be less than half of the samplerate.')
if kwargs['q_factor'] <= 0:
raise ValueError('Q factor must be positive.')
if not isinstance(kwargs["frequency"], int) or kwargs["frequency"] <= 0:
raise ValueError("Frequency must be a positive integer.")
if not isinstance(kwargs["samplerate"], int) or kwargs["samplerate"] <= 0:
raise ValueError("Samplerate must be a positive integer.")
if not (0 < kwargs["frequency"] < kwargs["samplerate"] / 2):
raise ValueError("Frequency must be less than half of the samplerate.")
if kwargs["q_factor"] <= 0:
raise ValueError("Q factor must be positive.")
return filter_creator(**kwargs)

return safe_filter_creator


Expand Down