lasp/examples/example_biquadbank.py

37 lines
816 B
Python
Raw Permalink Normal View History

#!/usr/bin/python3
import numpy as np
from lasp import SeriesBiquad, AvPowerSpectra
from lasp.filter import SPLFilterDesigner
import matplotlib.pyplot as plt
from scipy.signal import sosfreqz
2023-01-12 19:31:55 +00:00
plt.close('all')
fs = 48000
omg = 2*np.pi*1000
filt = SPLFilterDesigner(fs).A_Sos_design()
bq = SeriesBiquad(filt.flatten())
tend=10
t = np.linspace(0, int((tend*fs)//fs), int(tend*fs), endpoint=False)
in_ = np.random.randn(t.size)
out = bq.filter(in_)
from scipy.signal import welch
nfft = 48000
freq, H1 = welch(out,
# scaling
fs=fs,nfft=nfft)
freq, H2 = welch(in_,
# scaling
fs=fs,nfft=nfft)
# plt.figure()
plt.semilogx(freq,10*np.log10(np.abs(H1/H2)))
omg, H_ex = sosfreqz(filt)
plt.semilogx(omg/(2*np.pi)*fs, 20*np.log10(np.abs(H_ex)+1e-80))