add frequency error scenario to full tests

This commit is contained in:
Roman Zeyde
2014-08-17 09:42:48 +03:00
parent 974df919db
commit eb22b44b90

View File

@@ -7,6 +7,7 @@ from amodem import send
from amodem import recv from amodem import recv
from amodem import common from amodem import common
from amodem import sigproc from amodem import sigproc
from amodem import sampling
import logging import logging
logging.basicConfig(level=logging.DEBUG, logging.basicConfig(level=logging.DEBUG,
@@ -18,7 +19,7 @@ class Args(object):
self.__dict__.update(kwargs) self.__dict__.update(kwargs)
def run(size, chan): def run(size, chan=None, df=0):
tx_data = os.urandom(size) tx_data = os.urandom(size)
tx_audio = BytesIO() tx_audio = BytesIO()
send.main(Args(silence_start=1, silence_stop=1, send.main(Args(silence_start=1, silence_stop=1,
@@ -26,7 +27,13 @@ def run(size, chan):
data = tx_audio.getvalue() data = tx_audio.getvalue()
data = common.loads(data) data = common.loads(data)
data = chan(data) if chan is not None:
data = chan(data)
if df:
sampler = sampling.Sampler(data, sampling.Interpolator())
sampler.freq += df
data = sampler.take(len(data))
data = common.dumps(data) data = common.dumps(data)
rx_audio = BytesIO(data) rx_audio = BytesIO(data)
@@ -37,31 +44,37 @@ def run(size, chan):
assert rx_data == tx_data assert rx_data == tx_data
def test_small():
run(1024, chan=lambda x: x)
def test_frequency_error():
for df in [1, -1, 10, -10]:
run(1024, df=df*1e-6)
def test_lowpass(): def test_lowpass():
run(1024, lambda x: sigproc.lfilter(b=[0.9], a=[1.0, -0.1], x=x)) run(1024, chan=lambda x: sigproc.lfilter(b=[0.9], a=[1.0, -0.1], x=x))
def test_highpass(): def test_highpass():
run(1024, lambda x: sigproc.lfilter(b=[0.9], a=[1.0, 0.1], x=x)) run(1024, chan=lambda x: sigproc.lfilter(b=[0.9], a=[1.0, 0.1], x=x))
def test_small():
run(1024, lambda x: x)
def test_large():
run(54321, lambda x: x)
def test_attenuation(): def test_attenuation():
run(5120, lambda x: x * 0.1) run(5120, chan=lambda x: x * 0.1)
def test_low_noise(): def test_low_noise():
r = np.random.RandomState(seed=0) r = np.random.RandomState(seed=0)
run(5120, lambda x: x + r.normal(size=len(x), scale=0.0001)) run(5120, chan=lambda x: x + r.normal(size=len(x), scale=0.0001))
def test_medium_noise(): def test_medium_noise():
r = np.random.RandomState(seed=0) r = np.random.RandomState(seed=0)
run(5120, lambda x: x + r.normal(size=len(x), scale=0.001)) run(5120, chan=lambda x: x + r.normal(size=len(x), scale=0.001))
def test_large():
run(54321, chan=lambda x: x)