Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_resample():
x = np.sin(2*np.pi * 10 * np.linspace(0, 1, 1001))
src = BytesIO(common.dumps(x))
dst = BytesIO()
sampling.resample(src=src, dst=dst, df=0.0)
y = common.loads(dst.getvalue())
err = x[:len(y)] - y
assert np.max(np.abs(err)) < 1e-4
dst = BytesIO()
sampling.resample(src=BytesIO(b'\x00\x00'), dst=dst, df=0.0)
assert dst.tell() == 0
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
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 write(self, sym):
sym = np.array(sym) * self.gain
data = common.dumps(sym)
self.fd.write(data)
self.offset += len(sym)
def send(config, dst, volume_cmd=None, gain=1.0, limit=None):
volume_ctl = volume_controller(volume_cmd)
volume_ctl(1.0) # full scale output volume
calibration_symbols = int(1.0 * config.Fs)
t = np.arange(0, calibration_symbols) * config.Ts
signals = [gain * np.sin(2 * np.pi * f * t) for f in config.frequencies]
signals = [common.dumps(s) for s in signals]
for signal in itertools.islice(itertools.cycle(signals), limit):
dst.write(signal)
def resample(src, dst, df=0.0):
x = common.load(src)
sampler = Sampler(x, Interpolator())
sampler.freq += df
y = sampler.take(len(x))
dst.write(common.dumps(y))