From 52dbce072e88b728ddc945c76d3feec54287b192 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Mon, 4 Aug 2014 09:27:44 +0300 Subject: [PATCH] config: allow command line modem configuration --- amodem/config.py | 22 ++++++++++++++++------ amodem/configure.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) create mode 100755 amodem/configure.py diff --git a/amodem/config.py b/amodem/config.py index 1391b76..5fc8b65 100644 --- a/amodem/config.py +++ b/amodem/config.py @@ -1,17 +1,27 @@ import numpy as np -Fs = 32e3 +## Parameters +Fs = 32000.0 # sampling frequency [Hz] +Nfreq = 8 # number of frequencies used +Tsym = 0.001 # symbol duration [seconds] +Nx = 8 +Ny = 8 + Ts = 1.0 / Fs -frequencies = (1 + np.arange(8)) * 1e3 +frequencies = (1 + np.arange(Nfreq)) * 1e3 carrier_index = 0 Fc = frequencies[carrier_index] Tc = 1.0 / Fc -symbols = np.array([complex(x, y) - for x in np.linspace(-1, 1, 8) - for y in np.linspace(-1, 1, 8)]) / np.sqrt(2) +assert Nx == 2 ** round(np.log2(Nx)) +assert Ny == 2 ** round(np.log2(Ny)) + +xs = np.linspace(-1, 1, Nx) if Nx > 1 else 0.0 +ys = np.linspace(-1, 1, Ny) if Ny > 1 else 0.0 +symbols = np.array([complex(x, y) for x in xs for y in ys]) +symbols = symbols / np.max(np.abs(symbols)) -Tsym = 1e-3 Nsym = int(Tsym / Ts) baud = int(1/Tsym) + diff --git a/amodem/configure.py b/amodem/configure.py new file mode 100755 index 0000000..afc60af --- /dev/null +++ b/amodem/configure.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +template = '''import numpy as np + +## Parameters +Fs = {Fs} # sampling frequency [Hz] +Nfreq = {Nfreq} # number of frequencies used +Tsym = {Tsym} # symbol duration [seconds] +Nx = {Nx} +Ny = {Ny} + +Ts = 1.0 / Fs + +frequencies = (1 + np.arange(Nfreq)) * 1e3 +carrier_index = 0 +Fc = frequencies[carrier_index] +Tc = 1.0 / Fc + +assert Nx == 2 ** round(np.log2(Nx)) +assert Ny == 2 ** round(np.log2(Ny)) + +xs = np.linspace(-1, 1, Nx) if Nx > 1 else 0.0 +ys = np.linspace(-1, 1, Ny) if Ny > 1 else 0.0 +symbols = np.array([complex(x, y) for x in xs for y in ys]) +symbols = symbols / np.max(np.abs(symbols)) + +Nsym = int(Tsym / Ts) +baud = int(1/Tsym) +''' + +defaults = dict(Fs=32e3, Nx=8, Ny=8, Tsym=1e-3, Nfreq=8) + +import sys +args = sys.argv[1:] +for arg in args: + name, value = arg.split('=') + if name in defaults: + T = type(defaults[name]) + defaults[name] = T(value) + +content = template.format(**defaults) +print(content)