From 6537c6a02e82027ce94a9f7d59749160c7183f9d Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 28 Aug 2014 18:57:02 +0300 Subject: [PATCH] use FIR filter for equalization as an optimization --- amodem/dsp.py | 18 ++++++++++++++++-- amodem/recv.py | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/amodem/dsp.py b/amodem/dsp.py index 45a0d56..68e0b21 100644 --- a/amodem/dsp.py +++ b/amodem/dsp.py @@ -8,7 +8,7 @@ from . import common from .config import Ts, Nsym -class Filter(object): +class IIR(object): def __init__(self, b, a): self.b = np.array(b) / a[0] self.a = np.array(a[1:]) / a[0] @@ -28,8 +28,22 @@ class Filter(object): self.x_state, self.y_state = x_, y_ +class FIR(object): + def __init__(self, h): + self.h = np.array(h) + self.x_state = [0] * len(self.h) + + def __call__(self, x): + x_ = self.x_state + h = self.h + for v in x: + x_ = [v] + x_[:-1] + yield np.dot(x_, h) + self.x_state = x_ + + def lfilter(b, a, x): - f = Filter(b=b, a=a) + f = IIR(b=b, a=a) y = list(f(x)) return np.array(y) diff --git a/amodem/recv.py b/amodem/recv.py index ea4c530..1e147d9 100644 --- a/amodem/recv.py +++ b/amodem/recv.py @@ -132,7 +132,7 @@ def train_receiver(sampler, order, lookahead): unequalized = signal[prefix:-postfix] coeffs = equalizer.equalize(unequalized, train_symbols, order, lookahead) - equalization_filter = dsp.Filter(b=coeffs, a=[1]) + equalization_filter = dsp.FIR(h=coeffs) equalized = list(equalization_filter(signal)) equalized = equalized[prefix+lookahead:-postfix+lookahead]