add equalization tests

This commit is contained in:
Roman Zeyde
2014-08-17 18:12:23 +03:00
parent ae2e3c8724
commit 61b8b6015e

27
tests/test_equalizer.py Normal file
View File

@@ -0,0 +1,27 @@
from amodem import train
from amodem import dsp
from numpy.linalg import norm
import numpy as np
def test_fir():
a = [1, 0.8, -0.1, 0, 0]
tx = train.equalizer
rx = dsp.lfilter(x=tx, b=[1], a=a)
h_ = dsp.estimate(x=rx, y=tx, order=len(a))
tx_ = dsp.lfilter(x=rx, b=h_, a=[1])
assert norm(h_ - a) < 1e-12
assert (norm(tx - tx_) / norm(tx)) < 1e-12
def test_iir():
alpha = 0.1
b = [1, -alpha]
tx = train.equalizer
rx = dsp.lfilter(x=tx, b=b, a=[1])
h_ = dsp.estimate(x=rx, y=tx, order=20)
tx_ = dsp.lfilter(x=rx, b=h_, a=[1])
h_expected = np.array([alpha ** i for i in range(len(h_))])
assert norm(h_ - h_expected) < 1e-12
assert (norm(tx - tx_) / norm(tx)) < 1e-12