40 lines
901 B
Python
40 lines
901 B
Python
#!/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_)
|
|
|
|
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)
|
|
plt.semilogx(omg/(2*np.pi)*fs, 20*np.log10(np.abs(H_ex))) |