From c03f16dc4c823f7a18340a45105dd40424cbe1bf Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Wed, 1 May 2024 18:58:38 +0000 Subject: [PATCH 1/6] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index f6d6cb463faa..4a053a3f1b7f 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -773,6 +773,7 @@ * [Inverse Of Matrix](matrix/inverse_of_matrix.py) * [Largest Square Area In Matrix](matrix/largest_square_area_in_matrix.py) * [Matrix Class](matrix/matrix_class.py) + * [Matrix Equalization](matrix/matrix_equalization.py) * [Matrix Multiplication Recursion](matrix/matrix_multiplication_recursion.py) * [Matrix Operation](matrix/matrix_operation.py) * [Max Area Of Island](matrix/max_area_of_island.py) From e3482edde7a0ae4f2072efe099573cf3991643de Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Sun, 22 Dec 2024 15:04:14 +0300 Subject: [PATCH 2/6] Fix sphinx/build_docs warnings for audio_filters --- audio_filters/iir_filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/audio_filters/iir_filter.py b/audio_filters/iir_filter.py index f3c1ad43b001..458a5fca8fee 100644 --- a/audio_filters/iir_filter.py +++ b/audio_filters/iir_filter.py @@ -10,7 +10,7 @@ class IIRFilter: Implementation details: Based on the 2nd-order function from - https://en.wikipedia.org/wiki/Digital_biquad_filter, + https://en.wikipedia.org/wiki/Digital_biquad_filter, this generalized N-order function was made. Using the following transfer function From 79e94779dd5458a82bfa21dcd55f0299f691be4f Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Sun, 22 Dec 2024 23:00:06 +0300 Subject: [PATCH 3/6] Improve --- audio_filters/iir_filter.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/audio_filters/iir_filter.py b/audio_filters/iir_filter.py index 458a5fca8fee..9cc4e720bbf1 100644 --- a/audio_filters/iir_filter.py +++ b/audio_filters/iir_filter.py @@ -9,14 +9,13 @@ class IIRFilter: --- Implementation details: - Based on the 2nd-order function from - https://en.wikipedia.org/wiki/Digital_biquad_filter, - this generalized N-order function was made. + Based on the 2nd-order function from https://en.wikipedia.org/wiki/Digital_biquad_filter, this generalized N-order function was made. Using the following transfer function - H(z)=\frac{b_{0}+b_{1}z^{-1}+b_{2}z^{-2}+...+b_{k}z^{-k}}{a_{0}+a_{1}z^{-1}+a_{2}z^{-2}+...+a_{k}z^{-k}} + .. math:: H(z)=\frac{b_{0}+b_{1}z^{-1}+b_{2}z^{-2}+...+b_{k}z^{-k}}{a_{0}+a_{1}z^{-1}+a_{2}z^{-2}+...+a_{k}z^{-k}} + we can rewrite this to - y[n]={\frac{1}{a_{0}}}\left(\left(b_{0}x[n]+b_{1}x[n-1]+b_{2}x[n-2]+...+b_{k}x[n-k]\right)-\left(a_{1}y[n-1]+a_{2}y[n-2]+...+a_{k}y[n-k]\right)\right) + .. math:: y[n]={\frac{1}{a_{0}}}\left(\left(b_{0}x[n]+b_{1}x[n-1]+b_{2}x[n-2]+...+b_{k}x[n-k]\right)-\left(a_{1}y[n-1]+a_{2}y[n-2]+...+a_{k}y[n-k]\right)\right) """ def __init__(self, order: int) -> None: @@ -34,17 +33,18 @@ def __init__(self, order: int) -> None: def set_coefficients(self, a_coeffs: list[float], b_coeffs: list[float]) -> None: """ - Set the coefficients for the IIR filter. These should both be of size order + 1. - a_0 may be left out, and it will use 1.0 as default value. + Set the coefficients for the IIR filter. These should both be of size `order` + 1. + :math:`a_0` may be left out, and it will use 1.0 as default value. This method works well with scipy's filter design functions - >>> # Make a 2nd-order 1000Hz butterworth lowpass filter - >>> import scipy.signal - >>> b_coeffs, a_coeffs = scipy.signal.butter(2, 1000, - ... btype='lowpass', - ... fs=48000) - >>> filt = IIRFilter(2) - >>> filt.set_coefficients(a_coeffs, b_coeffs) + + >>> # Make a 2nd-order 1000Hz butterworth lowpass filter + >>> import scipy.signal + >>> b_coeffs, a_coeffs = scipy.signal.butter(2, 1000, + ... btype='lowpass', + ... fs=48000) + >>> filt = IIRFilter(2) + >>> filt.set_coefficients(a_coeffs, b_coeffs) """ if len(a_coeffs) < self.order: a_coeffs = [1.0, *a_coeffs] @@ -68,7 +68,7 @@ def set_coefficients(self, a_coeffs: list[float], b_coeffs: list[float]) -> None def process(self, sample: float) -> float: """ - Calculate y[n] + Calculate :math:`y[n]` >>> filt = IIRFilter(2) >>> filt.process(0) From 8d32927ef3bf7ab7a4b1dc0101d64dd4dc5f76ef Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Sun, 22 Dec 2024 23:01:51 +0300 Subject: [PATCH 4/6] Fix --- audio_filters/iir_filter.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/audio_filters/iir_filter.py b/audio_filters/iir_filter.py index 9cc4e720bbf1..e5088c8ab9b3 100644 --- a/audio_filters/iir_filter.py +++ b/audio_filters/iir_filter.py @@ -9,7 +9,9 @@ class IIRFilter: --- Implementation details: - Based on the 2nd-order function from https://en.wikipedia.org/wiki/Digital_biquad_filter, this generalized N-order function was made. + Based on the 2nd-order function from + https://en.wikipedia.org/wiki/Digital_biquad_filter, + this generalized N-order function was made. Using the following transfer function .. math:: H(z)=\frac{b_{0}+b_{1}z^{-1}+b_{2}z^{-2}+...+b_{k}z^{-k}}{a_{0}+a_{1}z^{-1}+a_{2}z^{-2}+...+a_{k}z^{-k}} From 31839b8c9ded6896804f4d92a04240ec2d242153 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Sun, 22 Dec 2024 23:04:42 +0300 Subject: [PATCH 5/6] Fix --- audio_filters/iir_filter.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/audio_filters/iir_filter.py b/audio_filters/iir_filter.py index e5088c8ab9b3..91972945fc74 100644 --- a/audio_filters/iir_filter.py +++ b/audio_filters/iir_filter.py @@ -14,10 +14,12 @@ class IIRFilter: this generalized N-order function was made. Using the following transfer function - .. math:: H(z)=\frac{b_{0}+b_{1}z^{-1}+b_{2}z^{-2}+...+b_{k}z^{-k}}{a_{0}+a_{1}z^{-1}+a_{2}z^{-2}+...+a_{k}z^{-k}} + .. math:: H(z)=\frac{b_{0}+b_{1}z^{-1}+b_{2}z^{-2}+...+b_{k}z^{-k}} + {a_{0}+a_{1}z^{-1}+a_{2}z^{-2}+...+a_{k}z^{-k}} we can rewrite this to - .. math:: y[n]={\frac{1}{a_{0}}}\left(\left(b_{0}x[n]+b_{1}x[n-1]+b_{2}x[n-2]+...+b_{k}x[n-k]\right)-\left(a_{1}y[n-1]+a_{2}y[n-2]+...+a_{k}y[n-k]\right)\right) + .. math:: y[n]={\frac{1}{a_{0}}}\left(\left(b_{0}x[n]+b_{1}x[n-1]+b_{2}x[n-2]+...+b_{k}x[n-k]\right)- + \left(a_{1}y[n-1]+a_{2}y[n-2]+...+a_{k}y[n-k]\right)\right) """ def __init__(self, order: int) -> None: @@ -35,7 +37,8 @@ def __init__(self, order: int) -> None: def set_coefficients(self, a_coeffs: list[float], b_coeffs: list[float]) -> None: """ - Set the coefficients for the IIR filter. These should both be of size `order` + 1. + Set the coefficients for the IIR filter. + These should both be of size `order` + 1. :math:`a_0` may be left out, and it will use 1.0 as default value. This method works well with scipy's filter design functions From db22f35f6eb407e1614e5f9913a16dda95b2d94f Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Sun, 22 Dec 2024 23:07:44 +0300 Subject: [PATCH 6/6] Fix --- audio_filters/iir_filter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/audio_filters/iir_filter.py b/audio_filters/iir_filter.py index 91972945fc74..fa3e6c54b33f 100644 --- a/audio_filters/iir_filter.py +++ b/audio_filters/iir_filter.py @@ -18,7 +18,8 @@ class IIRFilter: {a_{0}+a_{1}z^{-1}+a_{2}z^{-2}+...+a_{k}z^{-k}} we can rewrite this to - .. math:: y[n]={\frac{1}{a_{0}}}\left(\left(b_{0}x[n]+b_{1}x[n-1]+b_{2}x[n-2]+...+b_{k}x[n-k]\right)- + .. math:: y[n]={\frac{1}{a_{0}}} + \left(\left(b_{0}x[n]+b_{1}x[n-1]+b_{2}x[n-2]+...+b_{k}x[n-k]\right)- \left(a_{1}y[n-1]+a_{2}y[n-2]+...+a_{k}y[n-k]\right)\right) """