diff --git a/recv.py b/recv.py index 4b38b96..dd58214 100755 --- a/recv.py +++ b/recv.py @@ -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() diff --git a/show.py b/show.py index 7edfb0a..145a530 100755 --- a/show.py +++ b/show.py @@ -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() - diff --git a/train.py b/train.py index f6bf6cb..5a6d852 100644 --- a/train.py +++ b/train.py @@ -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()