diff --git a/amodem/calib.py b/amodem/calib.py index 384f961..57b9c87 100644 --- a/amodem/calib.py +++ b/amodem/calib.py @@ -3,7 +3,7 @@ import numpy as np from . import common from . import config -from . import sigproc +from . import dsp from . import wave Tsample = 1 @@ -39,7 +39,7 @@ def recv(wave_record=wave.record, reporter=sys.stdout.write): continue x = x - np.mean(x) - normalization_factor = np.sqrt(0.5 * len(x)) * sigproc.norm(x) + normalization_factor = np.sqrt(0.5 * len(x)) * dsp.norm(x) coherence = np.abs(np.dot(x, sig)) / normalization_factor z = np.dot(x, sig.conj()) / (0.5 * len(x)) amplitude = np.abs(z) diff --git a/amodem/sigproc.py b/amodem/dsp.py similarity index 100% rename from amodem/sigproc.py rename to amodem/dsp.py diff --git a/amodem/recv.py b/amodem/recv.py index 4b0f147..7c1b33b 100644 --- a/amodem/recv.py +++ b/amodem/recv.py @@ -11,13 +11,13 @@ import bitarray log = logging.getLogger(__name__) from . import stream -from . import sigproc +from . import dsp from . import train from . import common from . import config from . import ecc -modem = sigproc.MODEM(config) +modem = dsp.MODEM(config) if os.environ.get('PYLAB') == '1': import pylab @@ -37,13 +37,13 @@ SEARCH_WINDOW = 10 # symbols def report_carrier(bufs, begin): x = np.concatenate(tuple(bufs)[-CARRIER_THRESHOLD:-1]) - Hc = sigproc.exp_iwt(-config.Fc, len(x)) + Hc = dsp.exp_iwt(-config.Fc, len(x)) Zc = np.dot(Hc, x) / (0.5*len(x)) amp = abs(Zc) log.info('Carrier detected at ~%.1f ms @ %.1f kHz:' ' coherence=%.3f%%, amplitude=%.3f', begin * config.Tsym * 1e3 / config.Nsym, config.Fc / 1e3, - np.abs(sigproc.coherence(x, config.Fc)) * 100, amp) + np.abs(dsp.coherence(x, config.Fc)) * 100, amp) return amp @@ -54,7 +54,7 @@ def detect(samples, freq): for offset, buf in common.iterate(samples, config.Nsym): bufs.append(buf) - coeff = sigproc.coherence(buf, config.Fc) + coeff = dsp.coherence(buf, config.Fc) if abs(coeff) > COHERENCE_THRESHOLD: counter += 1 else: @@ -87,7 +87,7 @@ def detect(samples, freq): def find_start(buf, length): - Hc = sigproc.exp_iwt(config.Fc, len(buf)) + Hc = dsp.exp_iwt(config.Fc, len(buf)) P = np.abs(Hc.conj() * buf) ** 2 cumsumP = P.cumsum() return np.argmax(cumsumP[length:] - cumsumP[:-length]) @@ -109,7 +109,7 @@ def receive_prefix(symbols): pilot_tone = S[nonzeros] phase = np.unwrap(np.angle(pilot_tone)) / (2 * np.pi) indices = np.arange(len(phase)) - a, b = sigproc.linear_regression(indices, phase) + a, b = dsp.linear_regression(indices, phase) freq_err = a / (config.Tsym * config.Fc) last_phase = a * indices[-1] + b @@ -137,7 +137,7 @@ def train_receiver(symbols, freqs): offset = i * size S = symbols[offset:offset+size, i] - filt = sigproc.train(S, training * scaling_factor) + filt = dsp.train(S, training * scaling_factor) filters[freq] = filt Y = list(filt(S)) @@ -153,7 +153,7 @@ def train_receiver(symbols, freqs): raise ValueError('#{} training failed on {} Hz'.format(i, freq)) noise = y - training - Pnoise = sigproc.power(noise) + Pnoise = dsp.power(noise) log.info('%10.1f kHz: Noise sigma=%.4f, SNR=%.1f dB', freq/1e3, Pnoise**0.5, 10*np.log10(1/Pnoise)) @@ -206,7 +206,7 @@ def demodulate(symbols, filters, freqs, sampler): def receive(signal, freqs, gain=1.0): - symbols = sigproc.Demux(signal, freqs) + symbols = dsp.Demux(signal, freqs) symbols.sampler.gain = gain freq_err, offset_err = receive_prefix(symbols) diff --git a/amodem/send.py b/amodem/send.py index eb66f0e..a21c672 100644 --- a/amodem/send.py +++ b/amodem/send.py @@ -10,11 +10,11 @@ from . import wave from . import common from . import config -from . import sigproc +from . import dsp from . import stream from . import ecc -modem = sigproc.MODEM(config) +modem = dsp.MODEM(config) class Symbol(object): diff --git a/tests/test_sigproc.py b/tests/test_dsp.py similarity index 85% rename from tests/test_sigproc.py rename to tests/test_dsp.py index 70d72d7..da03be7 100644 --- a/tests/test_sigproc.py +++ b/tests/test_dsp.py @@ -3,12 +3,12 @@ import itertools import numpy as np from numpy.linalg import norm -from amodem import sigproc +from amodem import dsp from amodem import config def test_qam(): - q = sigproc.QAM(config.symbols) + q = dsp.QAM(config.symbols) r = random.Random(0) m = q.bits_per_symbol bits = [tuple(r.randint(0, 1) for j in range(m)) for i in range(1024)] @@ -32,7 +32,7 @@ def quantize(q, s): def test_overflow(): - q = sigproc.QAM(config.symbols) + q = dsp.QAM(config.symbols) r = np.random.RandomState(seed=0) for i in range(10000): s = 10*(r.normal() + 1j * r.normal()) @@ -43,18 +43,18 @@ def test_linreg(): x = np.array([1, 3, 2, 8, 4, 6, 9, 7, 0, 5]) a, b = 12.3, 4.56 y = a * x + b - a_, b_ = sigproc.linear_regression(x, y) + a_, b_ = dsp.linear_regression(x, y) assert abs(a - a_) < 1e-10 assert abs(b - b_) < 1e-10 def test_filter(): x = range(10) - y = sigproc.lfilter(b=[1], a=[1], x=x) + y = dsp.lfilter(b=[1], a=[1], x=x) assert (np.array(x) == y).all() x = [1] + [0] * 10 - y = sigproc.lfilter(b=[0.5], a=[1, -0.5], x=x) + y = dsp.lfilter(b=[0.5], a=[1, -0.5], x=x) assert list(y) == [0.5 ** (i+1) for i in range(len(x))] @@ -77,8 +77,8 @@ def test_estimate(): h = [0.1, 0.6, 0.9, 0.7, -0.2] L = len(h) // 2 - y = sigproc.lfilter(b=h, a=[1], x=x) - h_ = sigproc.estimate( + y = dsp.lfilter(b=h, a=[1], x=x) + h_ = dsp.estimate( x=x[:len(x)-L], y=y[L:], order=len(h), lookahead=L ) diff --git a/tests/test_full.py b/tests/test_full.py index 6187fb7..19ed299 100644 --- a/tests/test_full.py +++ b/tests/test_full.py @@ -6,7 +6,7 @@ import numpy as np from amodem import send from amodem import recv from amodem import common -from amodem import sigproc +from amodem import dsp from amodem import sampling import logging @@ -54,11 +54,11 @@ def test_frequency_error(): def test_lowpass(): - run(1024, chan=lambda x: sigproc.lfilter(b=[0.9], a=[1.0, -0.1], x=x)) + run(1024, chan=lambda x: dsp.lfilter(b=[0.9], a=[1.0, -0.1], x=x)) def test_highpass(): - run(1024, chan=lambda x: sigproc.lfilter(b=[0.9], a=[1.0, 0.1], x=x)) + run(1024, chan=lambda x: dsp.lfilter(b=[0.9], a=[1.0, 0.1], x=x)) def test_attenuation():