mirror of
https://github.com/romanz/amodem.git
synced 2026-02-06 16:48:06 +08:00
add equalization tests
This commit is contained in:
27
tests/test_equalizer.py
Normal file
27
tests/test_equalizer.py
Normal 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
|
||||
Reference in New Issue
Block a user