def test_too_noisy(): r = random.Random(0) # generate random binary signal signal = np.array([r.choice([-1, 1]) for i in range(int(config.Fs))]) src = BytesIO(common.dumps(signal * 0.5)) for r in calib.detector(config, src=src): assert not r['success'] assert r['msg'] == 'too noisy signal'
def test_too_weak(): p = ProcessMock() calib.send(config, p, gain=0.01, limit=32) p.buf.seek(0) for r in calib.detector(config, src=p): assert not r['success'] assert r['msg'] == 'too weak signal'
def test_too_strong(): p = ProcessMock() calib.send(config, p, gain=1.001, limit=32) p.buf.seek(0) for r in calib.detector(config, src=p): assert not r.success assert r.msg == 'too strong signal'
def test_drift(freq_err): freq = config.Fc * (1 + freq_err / 1e6) t = np.arange(int(1.0 * config.Fs)) * config.Ts frame_length = 100 rms = 0.5 signal = rms * np.cos(2 * np.pi * freq * t) src = BytesIO(common.dumps(signal)) iters = 0 for r in calib.detector(config, src, frame_length=frame_length): assert r['success'] is True assert abs(r['rms'] - rms) < 1e-3 assert abs(r['total'] - rms) < 1e-3 iters += 1 assert iters > 0 assert iters == config.baud / frame_length