summaryrefslogtreecommitdiff
path: root/gnuradio-examples/python/digital/simple_qam.py
diff options
context:
space:
mode:
authorBen Reynwar2010-12-09 15:12:14 -0700
committerBen Reynwar2010-12-09 15:12:14 -0700
commit2863f40d5d0bca8713252bb3618f9844fccf673c (patch)
tree9b046d959f028c246b6c4dad523228ada8d9bfc3 /gnuradio-examples/python/digital/simple_qam.py
parent4620927fdf7ddd70e8ddb63cf18b075740a099a5 (diff)
downloadgnuradio-2863f40d5d0bca8713252bb3618f9844fccf673c.tar.gz
gnuradio-2863f40d5d0bca8713252bb3618f9844fccf673c.tar.bz2
gnuradio-2863f40d5d0bca8713252bb3618f9844fccf673c.zip
Added support for modulation/demodulation of a generic constellation.
Not yet robust enough. Inefficient QAM modulation/demodulation also added (via the generic implementation).
Diffstat (limited to 'gnuradio-examples/python/digital/simple_qam.py')
-rw-r--r--gnuradio-examples/python/digital/simple_qam.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/gnuradio-examples/python/digital/simple_qam.py b/gnuradio-examples/python/digital/simple_qam.py
new file mode 100644
index 000000000..dee57baeb
--- /dev/null
+++ b/gnuradio-examples/python/digital/simple_qam.py
@@ -0,0 +1,64 @@
+
+from gnuradio import gr, blks2, packet_utils
+
+# Some constants
+NOISE_VOLTAGE = 0
+FREQUENCY_OFFSET = 0
+TIMING_OFFSET = 1.0
+SAMPLES_PER_SYMBOL = 2
+GAIN = 1.0
+SW_DECIM = 1
+BAND_MIDPOINT = 1.0
+BAND_WIDTH = 0.5
+
+# Modulation/Demodulation methods
+modulator = blks2.qam_mod(4, SAMPLES_PER_SYMBOL)
+demodulator = blks2.qam_demod(4, SAMPLES_PER_SYMBOL)
+
+#Transmission Blocks
+packet_transmitter = blks2.mod_pkts(modulator, access_code=None, msgq_limit=4,
+ pad_for_usrp=True)
+# Channel
+channel = gr.channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET, TIMING_OFFSET)
+# Receiver Blocks
+chan_coeffs = gr.firdes.low_pass(GAIN, SW_DECIM * SAMPLES_PER_SYMBOL,
+ BAND_MIDPOINT, BAND_WIDTH, gr.firdes.WIN_HANN)
+channel_filter = gr.fft_filter_ccc(SW_DECIM, chan_coeffs)
+packet_receiver = blks2.demod_pkts(demodulator, access_code=None, callback=None,
+ threshold=-1)
+# Put it all together and start it up (although nothing will be done
+# until we send some packets).
+tb = gr.top_block()
+tb.connect(packet_transmitter, channel, channel_filter,
+ packet_receiver)
+tb.start()
+
+# The queue into which recieved packets are placed
+pkq = packet_receiver._rcvd_pktq
+
+# The function to create a packet and place it in a queue to be sent.
+sender = packet_transmitter.send_pkt
+
+# Some some packets (The second will not be recieved because it gets cut off
+# before it can finish. I think this occurs during modulation.)
+sender('hello1')
+sender('hello2')
+sender('hello3')
+sender('hello4')
+sender('hello5')
+sender('hello6')
+sender('hello7')
+sender('world')
+sender(eof=True)
+
+# Wait for all the packets to get sent and received.
+tb.wait()
+
+# Check how many messages have been received and print them.
+cnt = pkq.count()
+print('There are %s messages' % cnt)
+for a in range(0, cnt):
+ msg = pkq.delete_head()
+ ok, payload = packet_utils.unmake_packet(msg.to_string(), int(msg.arg1()))
+ print("Message %s is %s" % (a, payload))
+