From b15f891aa0aaa44d6e00f1710cb4b96258574a3d Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 19 Jun 2014 18:58:13 +0300 Subject: [PATCH] Reorganize code. --- common.py | 9 ++------- recv.py | 55 ++++++++++--------------------------------------------- send.py | 2 +- show.py | 9 +++++++++ 4 files changed, 22 insertions(+), 53 deletions(-) create mode 100644 show.py diff --git a/common.py b/common.py index d57e16e..12daa5b 100644 --- a/common.py +++ b/common.py @@ -22,23 +22,18 @@ scaling = 10000.0 LENGTH_FORMAT = ' 0.5 + noise = y[:n] - prefix_bits assert(all(prefix_bits == np.array(prefix))) - log.info( 'Prefix OK, at SNR: {:.1f} dB'.format( 20 * np.log10(np.sqrt(len(prefix_bits)) / norm(noise)) ) ) + log.info( 'Prefix OK') + Pnoise = power(noise) + log.debug('Noise sigma={:.4f}, SNR={:.1f} dB'.format( Pnoise**0.5, 10*np.log10(1/Pnoise) )) data_bits = sigproc.qpsk.decode(y[n:]) data_bits = list(data_bits) return data_bits -def slicer(symbols, threshold): - bits = symbols.real > threshold - noise = symbols - bits - return bits, noise - def constellation(y): theta = np.linspace(0, 2*np.pi, 1000) @@ -139,7 +108,6 @@ def constellation(y): pylab.plot(y.real, y.imag, '.') pylab.plot(np.cos(theta), np.sin(theta), ':') keys = np.array(sigproc.qpsk._enc.values()) - print keys pylab.plot(keys.real, keys.imag, 'o') pylab.grid('on') pylab.axis('equal') @@ -187,13 +155,10 @@ def main(t, x): data = ''.join(c for _, c in data) log.info( 'Demodulated {} payload bydes'.format(len(data)) ) data = unpack(data) - log.info(repr(data)) - - pylab.show() - + with file('data.recv', 'wb') as f: + f.write(data) if __name__ == '__main__': - fname, = sys.argv[1:] - t, x = load(fname) + t, x = load('rx.int16') main(t, x) pylab.show() diff --git a/send.py b/send.py index e8c3f5d..06a4dbb 100644 --- a/send.py +++ b/send.py @@ -45,7 +45,7 @@ class Signal(object): sym = Symbol() -data = os.urandom(1024) +data = open('data.send', 'r').read() data = pack(data) bits = list(to_bits(data)) diff --git a/show.py b/show.py new file mode 100644 index 0000000..55156a3 --- /dev/null +++ b/show.py @@ -0,0 +1,9 @@ +def spectrogram(t, x): + 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.show()