Added first-order HP and LP compensation filters to the biquad class
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Thijs Hekman 2023-03-22 16:23:57 +01:00
parent ad0076e1c9
commit bdef0b45f3

View File

@ -23,7 +23,8 @@ y[n] = 1/ba[3] * ( ba[0] * x[n] + ba[1] * x[n-1] + ba[2] * x[n-2] +
""" """
__all__ = ['peaking', 'biquadTF', 'notch', 'lowpass', 'highpass', __all__ = ['peaking', 'biquadTF', 'notch', 'lowpass', 'highpass',
'highshelf', 'lowshelf', 'LPcompensator', 'HPcompensator'] 'highshelf', 'lowshelf', 'LP1compensator', 'LP2compensator',
'HP1compensator', 'HP2compensator']
from numpy import array, cos, pi, sin, sqrt from numpy import array, cos, pi, sin, sqrt
from scipy.interpolate import interp1d from scipy.interpolate import interp1d
@ -157,7 +158,32 @@ def lowshelf(fs, f0, Q, gain):
a2 = (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha a2 = (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha
return array([b0/a0, b1/a0, b2/a0, a0/a0, a1/a0, a2/a0]) return array([b0/a0, b1/a0, b2/a0, a0/a0, a1/a0, a2/a0])
def LPcompensator(fs, f0o, Qo, f0n, Qn): def LP1compensator(fs, f0o, f0n):
"""
Shelving type filter that, when multiplied with a first-order low-pass
filter, alters the response of that filter to a different first-order
low-pass filter.
Args:
fs: Sampling frequency [Hz]
f0o: Cut-off frequency of the original filter [Hz]
f0n: Desired cut-off frequency [Hz]
"""
omg0o = 2*pi*f0o
omg0n = 2*pi*f0n
z = -omg0o
p = -omg0n
k = p/z
zd, pd, kd = bilinear_zpk(z, p, k, fs)
sos = zpk2sos(zd,pd,kd)
return sos[0]
def LP2compensator(fs, f0o, Qo, f0n, Qn):
""" """
Shelving type filter that, when multiplied with a second-order low-pass Shelving type filter that, when multiplied with a second-order low-pass
filter, alters the response of that filter to a different second-order filter, alters the response of that filter to a different second-order
@ -194,7 +220,32 @@ def LPcompensator(fs, f0o, Qo, f0n, Qn):
return sos[0] return sos[0]
def HPcompensator(fs, f0o, Qo, f0n, Qn): def HP1compensator(fs, f0o, f0n):
"""
Shelving type filter that, when multiplied with a first-order high-pass
filter, alters the response of that filter to a different first-order
high-pass filter.
Args:
fs: Sampling frequency [Hz]
f0o: Cut-on frequency of the original filter [Hz]
f0n: Desired cut-on frequency [Hz]
"""
omg0o = 2*pi*f0o
omg0n = 2*pi*f0n
z = -omg0o
p = -omg0n
k = 1
zd, pd, kd = bilinear_zpk(z, p, k, fs)
sos = zpk2sos(zd,pd,kd)
return sos[0]
def HP2compensator(fs, f0o, Qo, f0n, Qn):
""" """
Shelving type filter that, when multiplied with a second-order high-pass Shelving type filter that, when multiplied with a second-order high-pass
filter, alters the response of that filter to a different second-order filter, alters the response of that filter to a different second-order