equalizer: fix gain handling and remove dead code

This commit is contained in:
Roman Zeyde
2014-08-26 17:28:01 +03:00
parent 9579b3d825
commit 819ca7464c
4 changed files with 13 additions and 46 deletions

View File

@@ -1,7 +1,9 @@
import numpy as np import numpy as np
from numpy.linalg import lstsq from numpy.linalg import lstsq
from amodem import dsp, config from amodem import dsp
from amodem import config
from amodem import sampling
import itertools import itertools
import random import random
@@ -40,7 +42,7 @@ def equalize(signal, symbols, order):
assert symbols.shape[1] == Nfreq assert symbols.shape[1] == Nfreq
length = symbols.shape[0] length = symbols.shape[0]
matched = np.array(carriers) * Nfreq / (0.5*Nsym) matched = np.array(carriers) / (0.5*Nsym)
matched = matched[:, ::-1].transpose().conj() matched = matched[:, ::-1].transpose().conj()
y = dsp.lfilter(x=signal, b=matched, a=[1]) y = dsp.lfilter(x=signal, b=matched, a=[1])

View File

@@ -30,7 +30,7 @@ class Interpolator(object):
class Sampler(object): class Sampler(object):
def __init__(self, src, interp=None): def __init__(self, src, interp=None):
self.freq = 1.0 self.freq = 1.0
self.gain = 1.0 self.equalizer = lambda x: x
if interp is not None: if interp is not None:
self.interp = interp self.interp = interp
self.resolution = self.interp.resolution self.resolution = self.interp.resolution
@@ -71,7 +71,7 @@ class Sampler(object):
except StopIteration: except StopIteration:
pass pass
return frame[:count] * self.gain return self.equalizer(frame[:count])
def resample(src, dst, df=0.0): def resample(src, dst, df=0.0):

View File

@@ -1,16 +1,3 @@
import itertools
prefix = [1]*400 + [0]*50 prefix = [1]*400 + [0]*50
equalizer_length = 500
silence_length = 100
def _equalizer_sequence():
res = []
symbols = [1, 1j, -1, -1j]
for s in itertools.islice(itertools.cycle(symbols), 100):
res.extend([s]*1 + [0]*1)
res.extend([0]*20)
return res
equalizer = _equalizer_sequence()

View File

@@ -1,7 +1,8 @@
from numpy.linalg import norm from numpy.linalg import norm
import numpy as np import numpy as np
from amodem import train, dsp, config from amodem import dsp
from amodem import config
from amodem import equalizer from amodem import equalizer
@@ -9,29 +10,6 @@ def assert_approx(x, y, e=1e-12):
assert norm(x - y) < e * norm(x) assert norm(x - y) < e * norm(x)
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_approx(h_, a)
assert_approx(tx, tx_)
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_approx(h_, h_expected)
assert_approx(tx, tx_)
def test_training(): def test_training():
L = 1000 L = 1000
t1 = equalizer.train_symbols(L) t1 = equalizer.train_symbols(L)
@@ -68,8 +46,8 @@ def test_isi():
gain = float(config.Nfreq) gain = float(config.Nfreq)
symbols = equalizer.train_symbols(length=length) symbols = equalizer.train_symbols(length=length)
x = equalizer.modulator(symbols) x = equalizer.modulator(symbols) * gain
assert_approx(equalizer.demodulator(gain * x, size=length), symbols) assert_approx(equalizer.demodulator(x, size=length), symbols)
den = np.array([1, -0.6, 0.1]) den = np.array([1, -0.6, 0.1])
num = np.array([0.5]) num = np.array([0.5])
@@ -79,5 +57,5 @@ def test_isi():
assert_approx(h, den / num) assert_approx(h, den / num)
y = dsp.lfilter(x=y, b=h, a=[1]) y = dsp.lfilter(x=y, b=h, a=[1])
z = equalizer.demodulator(gain * y, size=length) z = equalizer.demodulator(y, size=length)
assert_approx(z, symbols) assert_approx(z, symbols)