Created
February 6, 2019 13:42
-
-
Save SuperShinyEyes/63dc9c64b1efb8100bb014c1ed4450f0 to your computer and use it in GitHub Desktop.
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
def shelving(ys, cut_off, gain, mode='low'): | |
'''Shelving filter for bass | |
Args: | |
ys (numpy.array): 1D signals | |
cut_off (float): Normalized cut-off frequency. 0 < cut_off < 1 | |
gain (float): gain in dB | |
''' | |
gain = 10 ** (gain / 20) # NOTE: is it 20 or 40? | |
wc = 2 * np.pi * cut_off / 44100 # cut_off frequency in radians(0 <= wc <= pi) | |
tan_term = np.tan(wc / 2) | |
gain_sqrt = np.sqrt(gain) | |
if mode == 'low': | |
a0_prime = tan_term + gain_sqrt | |
a1_prime = tan_term - gain_sqrt | |
b0_prime = gain * tan_term + gain_sqrt | |
b1_prime = gain * tan_term - gain_sqrt | |
else: | |
a0_prime = gain_sqrt * tan_term + 1 | |
a1_prime = gain_sqrt * tan_term - 1 | |
b0_prime = gain_sqrt * tan_term + gain | |
b1_prime = gain_sqrt * tan_term - gain | |
a1 = a1_prime / a0_prime | |
b0 = b0_prime / a0_prime | |
b1 = b1_prime / a0_prime | |
return signal.lfilter(b=[b0, b1], a=[1, a1], x=ys) |
Author
SuperShinyEyes
commented
Feb 6, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment