fix training to include [1,i,-1,-i] symbols

This commit is contained in:
Roman Zeyde
2014-07-12 09:55:45 +03:00
parent e2266f603f
commit 8c0f19d0d5
3 changed files with 36 additions and 18 deletions

29
recv.py
View File

@@ -79,8 +79,8 @@ def receive_prefix(symbols):
def train_receiver(symbols, freqs):
filters = {}
full_scale = len(freqs)
training_bits = np.array(train.equalizer)
expected = full_scale * training_bits
training = np.array(train.equalizer)
expected = full_scale * training
if pylab:
pylab.figure()
@@ -90,16 +90,15 @@ def train_receiver(symbols, freqs):
filt = sigproc.train(S, expected)
filters[freq] = filt
S = filt(S)
y = np.array(list(S)).real
S = list(filt(S))
y = np.array(S)
if pylab:
pylab.subplot(HEIGHT, WIDTH, i+1)
pylab.plot(y, '-', expected, '-')
pylab.title('Train: $F_c = {}Hz$'.format(freq))
show.constellation(y, 'Train: $F_c = {}Hz$'.format(freq))
train_result = y > 0.5 * full_scale
if not all(train_result == training_bits):
return ValueError('#{} training failed on {} Hz'.format(i, freq))
train_result = np.round(y)
if not all(train_result == training):
raise ValueError('#{} training failed on {} Hz'.format(i, freq))
noise = y - expected
Pnoise = sigproc.power(noise)
@@ -114,6 +113,7 @@ def demodulate(symbols, filters, freqs):
symbol_list = []
generators = split(symbols, n=len(freqs))
print filters
for freq, S in zip(freqs, generators):
S = filters[freq](S)
@@ -204,7 +204,10 @@ if __name__ == '__main__':
p = argparse.ArgumentParser()
p.add_argument('fname')
args = p.parse_args()
main(fname=args.fname)
if pylab:
pylab.show()
try:
main(fname=args.fname)
except Exception as e:
log.exception(e)
finally:
if pylab:
pylab.show()

View File

@@ -4,23 +4,25 @@ import numpy as np
import sigproc
def constellation(y, title):
theta = np.linspace(0, 2*np.pi, 1000)
pylab.plot(y.real, y.imag, '.')
pylab.plot(np.cos(theta), np.sin(theta), ':')
points = np.array(sigproc.modulator.symbols)
pylab.plot(points.real, points.imag, 'o')
pylab.plot(points.real, points.imag, '+')
pylab.grid('on')
pylab.axis('equal')
pylab.title(title)
def spectrogram(t, x, Fs, NFFT=256):
ax1 = pylab.subplot(211)
pylab.plot(t, x)
pylab.subplot(212, sharex=ax1)
Pxx, freqs, bins, im = pylab.specgram(x,
NFFT=NFFT, Fs=Fs, noverlap=NFFT/2, cmap=pylab.cm.gist_heat)
pylab.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=NFFT/2,
cmap=pylab.cm.gist_heat)
if __name__ == '__main__':
import sys
@@ -33,4 +35,3 @@ if __name__ == '__main__':
spectrogram(t, x, common.Fs)
pylab.show()

View File

@@ -1,2 +1,16 @@
import itertools
prefix = [1]*400 + [0]*50
equalizer = ([1]*10 + [0]*10)*10 + [0]*20
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()