From 2030b0942f219917d4792f6eab99dc5a7b5c8ea0 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 7 Aug 2014 17:04:16 +0300 Subject: [PATCH] fix whitespace and styling --- amodem/calib.py | 11 +++++++---- tests/test_full.py | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/amodem/calib.py b/amodem/calib.py index 25e0643..06197f7 100755 --- a/amodem/calib.py +++ b/amodem/calib.py @@ -23,6 +23,7 @@ def send(): except KeyboardInterrupt: p.kill() + def recv(): p = wave.record('-', stdout=wave.sp.PIPE) try: @@ -37,13 +38,15 @@ def recv(): continue x = x - np.mean(x) - c = np.abs(np.dot(x, sig)) / (np.sqrt(0.5 * len(x)) * sigproc.norm(x)) + normalization_factor = np.sqrt(0.5 * len(x)) * sigproc.norm(x) + coherence = np.abs(np.dot(x, sig)) / normalization_factor z = np.dot(x, sig.conj()) / (0.5 * len(x)) - amp = np.abs(z) + amplitude = np.abs(z) phase = np.angle(z) peak = np.max(np.abs(x)) - print('coherence={:.3f} amp={:.3f} phase={:.1f} peak={:.3f}'.format( - c, amp, phase * 180 / np.pi, peak)) + + fmt = 'coherence={:.3f} amplitude={:.3f} phase={:+.1f} peak={:.3f}' + print(fmt.format(coherence, amplitude, phase * 180 / np.pi, peak)) except KeyboardInterrupt: p.kill() diff --git a/tests/test_full.py b/tests/test_full.py index aa6c14d..3c1a533 100644 --- a/tests/test_full.py +++ b/tests/test_full.py @@ -14,6 +14,7 @@ import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-12s %(message)s') + class Args(object): def __init__(self, **kwargs): self.__dict__.update(kwargs) @@ -37,19 +38,24 @@ def run(size, chan): assert rx_data == tx_data + def test_small(): run(1024, lambda x: x) + def test_large(): run(54321, lambda x: x) + def test_attenuation(): run(5120, lambda x: x * 0.1) + def test_low_noise(): r = np.random.RandomState(seed=0) run(5120, lambda x: x + r.normal(size=len(x), scale=0.0001)) + def test_medium_noise(): r = np.random.RandomState(seed=0) run(5120, lambda x: x + r.normal(size=len(x), scale=0.001))