This commit is contained in:
parent
3da6595b0c
commit
d1dea1483f
@ -2,15 +2,10 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from lasp import SeriesBiquad, AvPowerSpectra
|
from lasp import SeriesBiquad, AvPowerSpectra
|
||||||
from lasp.filter import SPLFilterDesigner
|
from lasp.filter import SPLFilterDesigner
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from scipy.signal import sosfreqz
|
from scipy.signal import sosfreqz
|
||||||
# plt.close('all')
|
plt.close('all')
|
||||||
|
|
||||||
# def test_cppslm2():
|
|
||||||
# """
|
|
||||||
# Generate a sine wave, now A-weighted
|
|
||||||
# """
|
|
||||||
fs = 48000
|
fs = 48000
|
||||||
omg = 2*np.pi*1000
|
omg = 2*np.pi*1000
|
||||||
|
|
@ -8,8 +8,6 @@ Created on Mon Jan 15 19:45:33 2018
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from lasp import AvPowerSpectra, Window
|
from lasp import AvPowerSpectra, Window
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
# plt.close('all')
|
|
||||||
def test_aps1():
|
def test_aps1():
|
||||||
|
|
||||||
nfft = 16384
|
nfft = 16384
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from lasp import cppSLM
|
from lasp import cppSLM
|
||||||
from lasp.filter import SPLFilterDesigner
|
from lasp.filter import SPLFilterDesigner
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
|
|
||||||
def test_cppslm1():
|
def test_cppslm1():
|
||||||
"""
|
"""
|
||||||
@ -11,7 +11,8 @@ def test_cppslm1():
|
|||||||
fs = 48000
|
fs = 48000
|
||||||
omg = 2 * np.pi * 1000
|
omg = 2 * np.pi * 1000
|
||||||
|
|
||||||
slm = cppSLM.fromBiquads(fs, 2e-5, 1, 0.125, [1.,0,0,1,0,0])
|
slm = cppSLM.fromBiquads(fs, 2e-5, 1, 0.125,
|
||||||
|
np.array([[1., 0, 0, 1, 0, 0]]).T)
|
||||||
|
|
||||||
t = np.linspace(0, 10, 10 * fs, endpoint=False)
|
t = np.linspace(0, 10, 10 * fs, endpoint=False)
|
||||||
|
|
||||||
@ -40,7 +41,10 @@ def test_cppslm2():
|
|||||||
omg = 2 * np.pi * 1000
|
omg = 2 * np.pi * 1000
|
||||||
|
|
||||||
filt = SPLFilterDesigner(fs).A_Sos_design()
|
filt = SPLFilterDesigner(fs).A_Sos_design()
|
||||||
slm = cppSLM.fromBiquads(fs, 2e-5, 0, 0.125, filt.flatten(), [1.,0,0,1,0,0])
|
slm = cppSLM.fromBiquads(fs, 2e-5, 0, 0.125,
|
||||||
|
filt.flatten(), # Pre-filter coefs
|
||||||
|
np.array([[1., 0, 0, 1, 0, 0]]).T # Bandpass coefs
|
||||||
|
)
|
||||||
|
|
||||||
t = np.linspace(0, 10, 10 * fs, endpoint=False)
|
t = np.linspace(0, 10, 10 * fs, endpoint=False)
|
||||||
|
|
||||||
@ -60,12 +64,15 @@ def test_cppslm2():
|
|||||||
# (Fast, Slow etc)
|
# (Fast, Slow etc)
|
||||||
assert np.isclose(out[-1, 0], level, atol=1e-2)
|
assert np.isclose(out[-1, 0], level, atol=1e-2)
|
||||||
|
|
||||||
|
|
||||||
def test_cppslm3():
|
def test_cppslm3():
|
||||||
fs = 48000
|
fs = 48000
|
||||||
omg = 2 * np.pi * 1000
|
omg = 2 * np.pi * 1000
|
||||||
|
|
||||||
filt = SPLFilterDesigner(fs).A_Sos_design()
|
filt = SPLFilterDesigner(fs).A_Sos_design()
|
||||||
slm = cppSLM.fromBiquads(fs, 2e-5, 0, 0.125, filt.flatten(), [1.,0,0,1,0,0])
|
slm = cppSLM.fromBiquads(fs, 2e-5, 0, 0.125,
|
||||||
|
filt.flatten(),
|
||||||
|
np.array([[1., 0, 0, 1, 0, 0]]).T)
|
||||||
t = np.linspace(0, 10, 10 * fs, endpoint=False)
|
t = np.linspace(0, 10, 10 * fs, endpoint=False)
|
||||||
|
|
||||||
in_ = 10 * np.sin(omg * t) * np.sqrt(2) + np.random.randn()
|
in_ = 10 * np.sin(omg * t) * np.sqrt(2) + np.random.randn()
|
||||||
@ -74,16 +81,14 @@ def test_cppslm3():
|
|||||||
# Compute overall level
|
# Compute overall level
|
||||||
level = 20 * np.log10(rms / 2e-5)
|
level = 20 * np.log10(rms / 2e-5)
|
||||||
|
|
||||||
|
|
||||||
# Output of SLM
|
# Output of SLM
|
||||||
out = slm.run(in_)
|
out = slm.run(in_)
|
||||||
|
|
||||||
Lpeak = 20 * np.log10(np.max(np.abs(in_) / 2e-5))
|
Lpeak = 20 * np.log10(np.max(np.abs(in_) / 2e-5))
|
||||||
Lpeak
|
Lpeak
|
||||||
slm.Lpeak()
|
slm.Lpeak()
|
||||||
assert np.isclose(out[-1,0], slm.Leq()[0][0], atol=1e-2)
|
assert np.isclose(out[-1, 0], slm.Leq()[0], atol=1e-2)
|
||||||
assert np.isclose(Lpeak, slm.Lpeak()[0][0], atol=2e0)
|
assert np.isclose(Lpeak, slm.Lpeak()[0], atol=2e0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user