@@ -9,14 +9,13 @@ class IIRFilter:
99 ---
1010
1111 Implementation details:
12- Based on the 2nd-order function from
13- https://en.wikipedia.org/wiki/Digital_biquad_filter,
14- this generalized N-order function was made.
12+ Based on the 2nd-order function from https://en.wikipedia.org/wiki/Digital_biquad_filter, this generalized N-order function was made.
1513
1614 Using the following transfer function
17- 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}}
15+ .. 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}}
16+
1817 we can rewrite this to
19- 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)
18+ .. 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)
2019 """
2120
2221 def __init__ (self , order : int ) -> None :
@@ -34,17 +33,18 @@ def __init__(self, order: int) -> None:
3433
3534 def set_coefficients (self , a_coeffs : list [float ], b_coeffs : list [float ]) -> None :
3635 """
37- Set the coefficients for the IIR filter. These should both be of size order + 1.
38- a_0 may be left out, and it will use 1.0 as default value.
36+ Set the coefficients for the IIR filter. These should both be of size ` order` + 1.
37+ :math:` a_0` may be left out, and it will use 1.0 as default value.
3938
4039 This method works well with scipy's filter design functions
41- >>> # Make a 2nd-order 1000Hz butterworth lowpass filter
42- >>> import scipy.signal
43- >>> b_coeffs, a_coeffs = scipy.signal.butter(2, 1000,
44- ... btype='lowpass',
45- ... fs=48000)
46- >>> filt = IIRFilter(2)
47- >>> filt.set_coefficients(a_coeffs, b_coeffs)
40+
41+ >>> # Make a 2nd-order 1000Hz butterworth lowpass filter
42+ >>> import scipy.signal
43+ >>> b_coeffs, a_coeffs = scipy.signal.butter(2, 1000,
44+ ... btype='lowpass',
45+ ... fs=48000)
46+ >>> filt = IIRFilter(2)
47+ >>> filt.set_coefficients(a_coeffs, b_coeffs)
4848 """
4949 if len (a_coeffs ) < self .order :
5050 a_coeffs = [1.0 , * a_coeffs ]
@@ -68,7 +68,7 @@ def set_coefficients(self, a_coeffs: list[float], b_coeffs: list[float]) -> None
6868
6969 def process (self , sample : float ) -> float :
7070 """
71- Calculate y[n]
71+ Calculate :math:` y[n]`
7272
7373 >>> filt = IIRFilter(2)
7474 >>> filt.process(0)
0 commit comments