summaryrefslogtreecommitdiff
path: root/gnuradio-examples/python/digital/limbo/mpsk_test.py
diff options
context:
space:
mode:
authoreb2006-09-27 05:14:03 +0000
committereb2006-09-27 05:14:03 +0000
commitf1c41f807cb29472d0924149e39d6ec8ad90e6a2 (patch)
tree47e42f8cdfc83aaa3b706e06862c3efa4ba16745 /gnuradio-examples/python/digital/limbo/mpsk_test.py
parent04bb51ec4f1539c51c861b7fcad2ca8047a872a3 (diff)
downloadgnuradio-f1c41f807cb29472d0924149e39d6ec8ad90e6a2.tar.gz
gnuradio-f1c41f807cb29472d0924149e39d6ec8ad90e6a2.tar.bz2
gnuradio-f1c41f807cb29472d0924149e39d6ec8ad90e6a2.zip
Merged changes from eb/digital-wip into trunk.
This includes: * renaming gnuradio-examples/python/gmsk2 to gnuradio-examples/python/digital * refactoring the digital data tx and rx test code into benchmark_tx and benchmark_rx. These accept a -m <modulation> argument. <modulation> can currently be selected from gmsk, dbpsk, dqpsk * Two new AGC blocks: gr_agc2: separate attack and delay rates; gr_feedforward_agc: FIR-ish compressor. Normalizes to peak envelope. * Working DBPSK mod/demod (works fine) * Working DQPSK mod/demod (works, but still needs more work) git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3662 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-examples/python/digital/limbo/mpsk_test.py')
-rwxr-xr-xgnuradio-examples/python/digital/limbo/mpsk_test.py125
1 files changed, 125 insertions, 0 deletions
diff --git a/gnuradio-examples/python/digital/limbo/mpsk_test.py b/gnuradio-examples/python/digital/limbo/mpsk_test.py
new file mode 100755
index 000000000..1f257d9c5
--- /dev/null
+++ b/gnuradio-examples/python/digital/limbo/mpsk_test.py
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+
+from gnuradio import gr, blks
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
+import random
+import struct
+from mpsk_pkt import *
+import cmath
+
+class my_graph(gr.flow_graph):
+
+ def __init__(self, rx_callback, spb, excess_bw, SNR, freq_error, arity):
+ gr.flow_graph.__init__(self)
+
+ fg = self
+
+ # Tuning Parameters
+ gain_mu = 0.05/spb
+
+ # transmitter
+ self.packet_transmitter = \
+ mpsk_mod_pkts(fg, spb=spb, excess_bw=excess_bw, diff=True, arity=arity)
+
+ # ----------------------------------------------------------------
+ # Channel model
+ # ----------------------------------------------------------------
+
+ awgn = gr.noise_source_c(gr.GR_GAUSSIAN, pow(10.0,-SNR/20.0))
+ add = gr.add_cc() # add some noise
+ fg.connect(awgn, (add,1))
+ radians = 17*pi/180
+ phase_rotate = gr.multiply_const_cc(cmath.exp(radians * 1j))
+
+ # ----------------------------------------------------------------
+
+ # channel filter
+ rx_filt_taps = gr.firdes.low_pass(1,spb,0.8,0.1,gr.firdes.WIN_HANN)
+ #rx_filt_taps = (1,)
+ rx_filt = gr.fir_filter_ccf(1,rx_filt_taps)
+
+ # receiver
+ self.packet_receiver = \
+ mpsk_demod_pkts(fg, callback=rx_callback,
+ excess_bw=excess_bw, arity=arity, diff=True,
+ costas_alpha=.005, gain_mu=gain_mu, spb=spb)
+
+ fg.connect (self.packet_transmitter, (add,0))
+ fg.connect(add, phase_rotate, rx_filt, self.packet_receiver)
+
+
+class stats(object):
+ def __init__(self):
+ self.npkts = 0
+ self.nright = 0
+
+def main():
+ st = stats()
+
+ def send_pkt(payload='', eof=False):
+ fg.packet_transmitter.send_pkt(payload, eof)
+
+ def rx_callback(ok, payload):
+ st.npkts += 1
+ if ok:
+ st.nright += 1
+ if len(payload) <= 16:
+ print "ok = %5r payload = '%s' %d/%d" % (ok, payload, st.nright, st.npkts)
+ else:
+ (pktno,) = struct.unpack('!H', payload[0:2])
+ print "ok = %5r pktno = %4d len(payload) = %4d %d/%d" % (ok, pktno, len(payload),
+ st.nright, st.npkts)
+
+
+ parser = OptionParser (option_class=eng_option)
+ parser.add_option("-M", "--megabytes", type="eng_float", default=1,
+ help="set megabytes to transmit [default=%default]")
+ parser.add_option("-s", "--size", type="eng_float", default=1500,
+ help="set packet size [default=%default]")
+ parser.add_option("","--spb", type=int, default=4,
+ help="set samples per baud to SPB [default=%default]")
+ parser.add_option("", "--excess-bw", type="eng_float", default=0.4,
+ help="set excess bandwidth for RRC filter [default=%default]")
+ parser.add_option("", "--snr", type="eng_float", default=40,
+ help="set SNR in dB for simulation [default=%default]")
+ parser.add_option("", "--m-arity", type=int, default=4,
+ help="PSK arity [default=%default]")
+ parser.add_option("", "--freq-error", type="eng_float", default=0,
+ help="set frequency error for simulation [default=%default]")
+
+ (options, args) = parser.parse_args ()
+
+ if len(args) != 0:
+ parser.print_help()
+ sys.exit(1)
+
+ pkt_size = int(options.size)
+
+ fg = my_graph(rx_callback, options.spb, options.excess_bw, options.snr,
+ options.freq_error, options.m_arity)
+ fg.start()
+
+ nbytes = int(1e6 * options.megabytes)
+ n = 0
+ pktno = 0
+
+ send_pkt('Hello World')
+
+ # generate and send packets
+ while n < nbytes:
+ send_pkt(struct.pack('!H', pktno) + (pkt_size - 2) * chr(pktno & 0xff))
+ n += pkt_size
+ pktno += 1
+
+ send_pkt('Goodbye World')
+ send_pkt(eof=True) # tell modulator we're not sending any more pkts
+
+ fg.wait()
+
+
+if __name__ == '__main__':
+ try:
+ main()
+ except KeyboardInterrupt:
+ pass