mirror of
https://github.com/romanz/amodem.git
synced 2026-04-05 04:06:24 +08:00
use FIR filter for equalization
as an optimization
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user