Exemplo n.º 1
0
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})

# frequency response
for n, H_n in enumerate(H):
    col = colors((n + 3) / (len(H) + 3))
    ax[0].semilogx(w, db(H_n), c=col, **kw)
Exemplo n.º 2
0
Gd = 10 * np.log10(0.5) * BWd
biquad_per_octave = 1
slope = shelving_slope_parameters(BWd=BWd, Gd=Gd)[0]
wl, wh = w0 * 2**(-BWd), w0

# 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
num_biquad, Gb, G = shelving_filter_parameters(
    biquad_per_octave=biquad_per_octave, Gd=Gd, BWd=BWd)
Hmag = np.clip(np.log2(w / w0) * slope, G, 0)  # desired response
sos = low_shelving_2nd_cascade(w0, Gb, num_biquad, biquad_per_octave)
H_biquads = np.stack(
    [sosfreqs(sosi[np.newaxis, :], worN=w)[1] for sosi in sos])
H = sosfreqs(sos, worN=w)[1]

# Plots
Glim = -9.5, 1
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 = dict(lw=2, alpha=1, basex=2)
kw_dotted = dict(color='gray', linestyle=':', linewidth=1)
kw_artist = dict(edgecolor='gray', linestyle=':', linewidth=1)
colors = cm.get_cmap('Blues')

# frequency response
fig, ax = plt.subplots(figsize=(10, 4), ncols=2, gridspec_kw={'wspace': 0.1})