Ejemplo n.º 1
0
Q = 1 / np.sqrt(2)
Gd = -3 * 120 * np.log10(2)
slope = shelving_slope_parameters(BWd=BWd, Gd=Gd)[0]

# Frequency-domain evaluation
wmin, wmax, num_w = 2**-9.5, 2**4.5, 1000
w = np.logspace(np.log10(wmin), np.log10(wmax), num=num_w)

# Filter design
shelving_filters = []
H = np.zeros((len(Biquad_per_octave), num_w), dtype='complex')
Gain = np.zeros(len(Biquad_per_octave))
Gain_biquad = np.zeros(len(Biquad_per_octave))
for n, biquad_per_octave in enumerate(Biquad_per_octave):
    num_biquad, Gb, G = \
        shelving_filter_parameters(biquad_per_octave=biquad_per_octave,
                                   Gd=Gd, BWd=BWd)
    Gain[n] = G
    Gain_biquad[n] = Gb
    sos = low_shelving_2nd_cascade(w0, Gb, num_biquad, biquad_per_octave)
    H[n] = sosfreqs(sos, worN=w)[1]
    shelving_filters.append(sos)

# Plots
wlim = wmin, wmax
wticks = 2**(np.arange(np.ceil(np.log2(w)[0]/2)*2,
                       np.floor(np.log2(w[-1])/2)*2 + 2, 2))
kw = {'lw': 2, 'alpha': 1, 'basex': 2}
colors = cm.get_cmap('Blues')

fig, ax = plt.subplots(figsize=(10, 4), ncols=2, gridspec_kw={'wspace': 0.25})
Ejemplo n.º 2
0
# Frequency-domain evaluation
wmin, wmax, num_w = 2**-9.5, 2**4.5, 1000
w = np.logspace(np.log10(wmin), np.log10(wmax), num=num_w)

# Different slopes
biquad_per_octave = 3
BWd = 6
Desired_gain = -8, -4, 3, 7
Slope = np.zeros(len(Desired_gain))

# Filter design
H = np.zeros((len(Desired_gain), num_w), dtype='complex')
for n, Gd in enumerate(Desired_gain):
    num_biquad, Gb, G = shelving_filter_parameters(
                biquad_per_octave=biquad_per_octave,
                BWd=BWd,
                Gd=Gd)
    Slope[n] = shelving_slope_parameters(BWd=BWd, Gd=Gd)[0]
    sos = low_shelving_2nd_cascade(w0, Gb, num_biquad, biquad_per_octave)
    H[n] = sosfreqs(sos, worN=w)[1]

# Plots
Glim = -9.5, 9.5
philim = -21, 21
wlim = wmin, wmax
wticks = 2**(np.arange(np.ceil(np.log2(w)[0]/2)*2,
                       np.floor(np.log2(w[-1])/2)*2 + 2, 2))
kw_pos = dict(lw=1.5, c='C3', alpha=0.5, basex=2)
kw_neg = dict(lw=1.5, c='C0', alpha=1, basex=2)

fig, ax = plt.subplots(figsize=(10, 4), ncols=2, gridspec_kw={'wspace': 0.25})
Ejemplo n.º 3
0
slope = 10 * np.log10(2)
BWd = 6

# Time-domain evaluation
fs = 48000
ws = 2 * np.pi * fs
Lh = 1500
t = np.arange(Lh) / fs
xin = unit_impulse(Lh)
t = np.arange(Lh) / fs
s2z = matchedz_zpk
# s2z = bilinear_zpk

# Analog filter
H = np.zeros(num_w, dtype='complex')
num_biquad, Gb, G = shelving_filter_parameters(
    biquad_per_octave=biquad_per_octave, slope=slope, BWd=BWd)
sos_sdomain = low_shelving_2nd_cascade(w0, Gb, num_biquad, biquad_per_octave)
zs, ps, ks = sos2zpk(sos_sdomain)

# Digital filter
zpk = s2z(zs * 2 * np.pi * fc, ps * 2 * np.pi * fc, ks, fs=fs)
sos_zdomain = zpk2sos(*zpk)
H = sosfreqz(sos_zdomain, worN=f, fs=fs)[1]
h = sosfilt(sos_zdomain, xin)

# Plots
flim = fmin, fmax
fticks = fc * 2.**np.arange(-8, 4, 2)
fticklabels = ['7.8', '31.3', '125', '500', '2k', '8k']
fticks = 1000 * 2.**np.arange(-6, 6, 2)
fticklabels = ['15.6', '62.5', '250', '1k', '4k', '16k']
Ejemplo n.º 4
0
# Frequency-domain evaluation
wmin, wmax, num_w = 2**-9.5, 2**4.5, 1000
w = np.logspace(np.log10(wmin), np.log10(wmax), num=num_w)

# Different slopes
Gd = 12
biquad_per_octave = 3
Slope = 10 * np.log10(2.**np.array([2, 1, 0.5, -0.5, -1, -2]))
Bandwidth = np.zeros(len(Slope))
Gain = np.zeros(len(Slope))

# Filter design
H = np.zeros((len(Slope), num_w), dtype='complex')
for n, slope in enumerate(Slope):
    num_biquad, Gb, G = shelving_filter_parameters(
        biquad_per_octave=biquad_per_octave,
        slope=slope,
        Gd=-Gd * np.sign(slope))
    Gain[n] = -Gd * np.sign(slope)
    Bandwidth[n] = shelving_slope_parameters(slope=slope,
                                             Gd=-Gd * np.sign(slope))[1]
    sos = low_shelving_2nd_cascade(w0, Gb, num_biquad, biquad_per_octave)
    H[n] = sosfreqs(sos, worN=w)[1]

# Plots
wlim = wmin, wmax
Glim = -13, 14.8
philim = -54, 54
wticks = 2**(np.arange(
    np.ceil(np.log2(w)[0] / 2) * 2,
    np.floor(np.log2(w[-1]) / 2) * 2 + 2, 2))
kw_pos = dict(lw=1.5, c='C3', alpha=0.5, basex=2)