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
|
|
|
|
# plt.close('all')
|
|
|
|
|
|
|
|
# def test_cppslm2():
|
|
|
|
# """
|
|
|
|
# Generate a sine wave, now A-weighted
|
|
|
|
# """
|
|
|
|
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
|
|
|
|
freq, H1 = welch(out[:,0],
|
|
|
|
# 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))
|