From a2b220c8e47ac2ddbf6e25c51a10d437f6d4f2af Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Sat, 7 Feb 2015 08:52:27 +0200 Subject: [PATCH] PEP8 fixes lambdas and coverage --- amodem/dsp.py | 4 ++++ amodem/recv.py | 5 ++--- tests/test_common.py | 9 +++++++++ tests/test_dsp.py | 4 +++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/amodem/dsp.py b/amodem/dsp.py index 4a7c671..8280035 100644 --- a/amodem/dsp.py +++ b/amodem/dsp.py @@ -72,6 +72,10 @@ def norm(x): return np.sqrt(np.dot(x.conj(), x).real) +def rms(x): + return np.mean(np.abs(x) ** 2, axis=0) ** 0.5 + + def coherence(x, omega): n = len(x) Hc = exp_iwt(-omega, n) / np.sqrt(0.5*n) diff --git a/amodem/recv.py b/amodem/recv.py index 45409c4..de94776 100644 --- a/amodem/recv.py +++ b/amodem/recv.py @@ -79,10 +79,9 @@ class Receiver(object): error_rate = errors.sum() / errors.size errors = np.array(symbols - train_symbols) - rms = lambda x: (np.mean(np.abs(x) ** 2, axis=0) ** 0.5) - noise_rms = rms(errors) - signal_rms = rms(train_symbols) + noise_rms = dsp.rms(errors) + signal_rms = dsp.rms(train_symbols) SNRs = 20.0 * np.log10(signal_rms / noise_rms) self.plt.figure() diff --git a/tests/test_common.py b/tests/test_common.py index 7a9bd9d..cd49e60 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -1,4 +1,5 @@ from amodem import common +from amodem import config import numpy as np @@ -59,3 +60,11 @@ def test_holder(): assert a.x == d['x'] assert a.y == d['y'] assert repr(a) == 'AttributeHolder(x=1, y=2.3)' + + +def test_configs(): + default = config.Configuration() + fastest = config.fastest() + slowest = config.slowest() + assert slowest.modem_bps <= default.modem_bps + assert fastest.modem_bps >= default.modem_bps diff --git a/tests/test_dsp.py b/tests/test_dsp.py index 8a7b218..6f6f7e5 100644 --- a/tests/test_dsp.py +++ b/tests/test_dsp.py @@ -48,7 +48,9 @@ def test_qam(): decoded = list(q.decode(S)) assert decoded == bits - noise = lambda A: A*(r.uniform(-1, 1) + 1j*r.uniform(-1, 1)) + def noise(A): + return A*(r.uniform(-1, 1) + 1j*r.uniform(-1, 1)) + noised_symbols = [(s + noise(1e-3)) for s in S] decoded = list(q.decode(noised_symbols)) assert decoded == bits