2022-09-03 18:59:14 +00:00
|
|
|
#!/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')
|
2022-09-03 18:59:14 +00:00
|
|
|
|
|
|
|
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_)
|
|
|
|
|
2022-10-04 07:27:27 +00:00
|
|
|
|
2022-09-03 18:59:14 +00:00
|
|
|
from scipy.signal import welch
|
|
|
|
nfft = 48000
|
2022-10-11 12:50:44 +00:00
|
|
|
freq, H1 = welch(out,
|
2022-09-03 18:59:14 +00:00
|
|
|
# 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)
|
2022-10-05 11:39:45 +00:00
|
|
|
plt.semilogx(omg/(2*np.pi)*fs, 20*np.log10(np.abs(H_ex)+1e-80))
|