summaryrefslogtreecommitdiff
path: root/gnuradio-examples/python
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-examples/python')
-rw-r--r--gnuradio-examples/python/Makefile.am1
-rwxr-xr-xgnuradio-examples/python/digital/benchmark_qt_loopback2.py25
-rw-r--r--gnuradio-examples/python/digital/simple.py64
-rw-r--r--gnuradio-examples/python/digital/simple_qam.py76
-rw-r--r--gnuradio-examples/python/digital_voice/.gitignore10
-rw-r--r--gnuradio-examples/python/digital_voice/Makefile.am28
-rwxr-xr-xgnuradio-examples/python/digital_voice/cvsd_test.py63
-rwxr-xr-xgnuradio-examples/python/digital_voice/encdec.py58
8 files changed, 161 insertions, 164 deletions
diff --git a/gnuradio-examples/python/Makefile.am b/gnuradio-examples/python/Makefile.am
index 30effdf9a..eba4c14ab 100644
--- a/gnuradio-examples/python/Makefile.am
+++ b/gnuradio-examples/python/Makefile.am
@@ -25,7 +25,6 @@ SUBDIRS = \
apps \
digital \
digital-bert \
- digital_voice \
mp-sched \
multi-antenna \
multi_usrp \
diff --git a/gnuradio-examples/python/digital/benchmark_qt_loopback2.py b/gnuradio-examples/python/digital/benchmark_qt_loopback2.py
index 02ae4b25f..a36f4fbd4 100755
--- a/gnuradio-examples/python/digital/benchmark_qt_loopback2.py
+++ b/gnuradio-examples/python/digital/benchmark_qt_loopback2.py
@@ -20,11 +20,11 @@
# Boston, MA 02110-1301, USA.
#
-from gnuradio import gr, gru, modulation_utils2
+from gnuradio import gr, modulation_utils2
from gnuradio import eng_notation
from gnuradio.eng_option import eng_option
from optparse import OptionParser
-import random, time, struct, sys, os, math
+import struct, sys, math
from threading import Thread
@@ -319,6 +319,13 @@ class my_top_block(gr.top_block):
# Connect components
self.connect(self.txpath, self.throttle, self.rxpath)
+ if options.verbose:
+ self._print_verbage()
+
+ if options.log:
+ self._setup_logging()
+
+
# System Parameters
@@ -396,6 +403,15 @@ class my_top_block(gr.top_block):
self.rxpath.packet_receiver._demodulator.freq_recov.set_beta(self._gain_freq/10.0)
#self.rxpath.packet_receiver._demodulator.freq_recov.set_beta(self._gain_fre_beta)
+ def _print_verbage(self):
+ print "\nChannel:"
+ print "SNR: %d" % self.snr()
+ print "Noise voltage: %.2e" % self.get_noise_voltage(self.snr())
+ print "Frequency offset: %.2e" % self.frequency_offset()
+ print "Timing offset: %.2e" % self.timing_offset()
+
+ def _setup_logging(self):
+ pass
# /////////////////////////////////////////////////////////////////////////////
# Thread to handle the packet sending procedure
@@ -466,7 +482,7 @@ def main():
channel_grp = parser.add_option_group("Channel")
parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
- default='dbpsk2',
+ default='psk',
help="Select modulation from: %s [default=%%default]"
% (', '.join(mods.keys()),))
@@ -512,6 +528,7 @@ def main():
tb = my_top_block(mods[options.modulation],
demods[options.modulation],
rx_callback, options)
+
tb.start()
packet_sender = th_send(send_pkt, options.megabytes, options.size)
@@ -527,7 +544,7 @@ def main():
packet_sender.join(1)
except KeyboardInterrupt:
packet_sender.stop()
-
+
if __name__ == '__main__':
try:
diff --git a/gnuradio-examples/python/digital/simple.py b/gnuradio-examples/python/digital/simple.py
new file mode 100644
index 000000000..6d340db36
--- /dev/null
+++ b/gnuradio-examples/python/digital/simple.py
@@ -0,0 +1,64 @@
+
+from gnuradio import gr, blks2, packet_utils
+
+# Some constants
+TX_AMPLITUDE = 0.25
+SAMPLE_RATE = 1e5
+# NOISE_VOLTAGE = 0.01
+NOISE_VOLTAGE = 0.01
+# FREQUENCY_OFFSET = 0
+FREQUENCY_OFFSET = 0.01
+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.dbpsk2_mod()
+demodulator = blks2.dbpsk2_demod()
+
+#Transmission Blocks
+packet_transmitter = blks2.mod_pkts(modulator, access_code=None, msgq_limit=4,
+ pad_for_usrp=True)
+amp = gr.multiply_const_cc(TX_AMPLITUDE)
+throttle = gr.throttle(gr.sizeof_gr_complex, SAMPLE_RATE)
+# 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, amp, throttle, 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('hello there I wonder how long this needs to be before I start to see any errors.')
+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))
+
diff --git a/gnuradio-examples/python/digital/simple_qam.py b/gnuradio-examples/python/digital/simple_qam.py
new file mode 100644
index 000000000..947d7faad
--- /dev/null
+++ b/gnuradio-examples/python/digital/simple_qam.py
@@ -0,0 +1,76 @@
+
+from gnuradio import gr, blks2, packet_utils
+
+# Some constants
+NOISE_VOLTAGE = 0.1
+FREQUENCY_OFFSET = 0.0000
+TIMING_OFFSET = 1.0
+SAMPLES_PER_SYMBOL = 2
+GAIN = 1.0
+SW_DECIM = 1
+BAND_MIDPOINT = 1.0
+BAND_WIDTH = 0.5
+FREQ_ALPHA = 0.005
+EXCESS_BW = 0.35
+
+# Modulation/Demodulation methods
+modulator = blks2.qam_mod(16, SAMPLES_PER_SYMBOL)
+demodulator = blks2.qam_demod(16, SAMPLES_PER_SYMBOL, freq_alpha=FREQ_ALPHA)
+
+#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.)
+
+# Send some large messages to start off with to let things lock.
+for i in range(0, int(20.0/SAMPLES_PER_SYMBOL)):
+ sender('a'*4000)
+
+sender('hello1')
+sender('hello2')
+sender('hello3')
+sender('hello4')
+sender('hello5')
+sender('hello6')
+sender('hello7')
+sender('hello8')
+sender('hello9')
+sender('hello10')
+sender('hello11')
+sender('hello12')
+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))
+
diff --git a/gnuradio-examples/python/digital_voice/.gitignore b/gnuradio-examples/python/digital_voice/.gitignore
deleted file mode 100644
index c400497f5..000000000
--- a/gnuradio-examples/python/digital_voice/.gitignore
+++ /dev/null
@@ -1,10 +0,0 @@
-/Makefile
-/Makefile.in
-/.la
-/.lo
-/.deps
-/.libs
-/*.la
-/*.lo
-/*.pyc
-/*.pyo
diff --git a/gnuradio-examples/python/digital_voice/Makefile.am b/gnuradio-examples/python/digital_voice/Makefile.am
deleted file mode 100644
index 60f363b90..000000000
--- a/gnuradio-examples/python/digital_voice/Makefile.am
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Copyright 2004,2005,2009 Free Software Foundation, Inc.
-#
-# This file is part of GNU Radio
-#
-# GNU Radio is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3, or (at your option)
-# any later version.
-#
-# GNU Radio is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GNU Radio; see the file COPYING. If not, write to
-# the Free Software Foundation, Inc., 51 Franklin Street,
-# Boston, MA 02110-1301, USA.
-#
-
-include $(top_srcdir)/Makefile.common
-
-ourdatadir = $(exampledir)/digital_voice
-
-dist_ourdata_SCRIPTS = \
- encdec.py \
- cvsd_test.py
diff --git a/gnuradio-examples/python/digital_voice/cvsd_test.py b/gnuradio-examples/python/digital_voice/cvsd_test.py
deleted file mode 100755
index f8f1b9cce..000000000
--- a/gnuradio-examples/python/digital_voice/cvsd_test.py
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2007 Free Software Foundation, Inc.
-#
-# This file is part of GNU Radio
-#
-# GNU Radio is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3, or (at your option)
-# any later version.
-#
-# GNU Radio is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GNU Radio; see the file COPYING. If not, write to
-# the Free Software Foundation, Inc., 51 Franklin Street,
-# Boston, MA 02110-1301, USA.
-#
-
-from gnuradio import gr, blks2
-from gnuradio import audio
-from gnuradio.eng_option import eng_option
-from optparse import OptionParser
-
-def main():
- parser = OptionParser(option_class=eng_option)
- parser.add_option("-I", "--audio-input", type="string", default="",
- help="pcm input device name. E.g., hw:0,0 or /dev/dsp")
- parser.add_option("-O", "--audio-output", type="string", default="",
- help="pcm output device name. E.g., hw:0,0 or /dev/dsp")
- parser.add_option("-r", "--sample-rate", type="eng_float", default="32000",
- help="Audio sampling rate [defaul=%default]")
- parser.add_option("-S", "--resample-rate", type="int", default="8",
- help="Resampling rate in CVSD [default=%default]")
- (options, args) = parser.parse_args ()
-
- if len(args) != 0:
- parser.print_help()
- raise SystemExit, 1
-
- tb = gr.top_block()
-
- src = audio.source(int(options.sample_rate), options.audio_input)
- tx = blks2.cvsd_encode(options.resample_rate)
-
- # todo: add noise
-
- rx = blks2.cvsd_decode(options.resample_rate)
- dst = audio.sink(int(options.sample_rate), options.audio_output)
-
- tb.connect(src, tx, rx, dst)
- tb.run()
-
-if __name__ == '__main__':
- print "Enter CTRL-C to exit"
- try:
- main()
- except KeyboardInterrupt:
- pass
-
diff --git a/gnuradio-examples/python/digital_voice/encdec.py b/gnuradio-examples/python/digital_voice/encdec.py
deleted file mode 100755
index e87d57e2b..000000000
--- a/gnuradio-examples/python/digital_voice/encdec.py
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2005 Free Software Foundation, Inc.
-#
-# This file is part of GNU Radio
-#
-# GNU Radio is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3, or (at your option)
-# any later version.
-#
-# GNU Radio is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GNU Radio; see the file COPYING. If not, write to
-# the Free Software Foundation, Inc., 51 Franklin Street,
-# Boston, MA 02110-1301, USA.
-#
-
-from gnuradio import gr, blks2
-from gnuradio import audio
-from gnuradio.eng_option import eng_option
-from optparse import OptionParser
-
-class my_top_block(gr.top_block):
-
- def __init__(self):
- gr.top_block.__init__(self)
-
- parser = OptionParser(option_class=eng_option)
- parser.add_option("-I", "--audio-input", type="string", default="",
- help="pcm input device name. E.g., hw:0,0 or /dev/dsp")
- parser.add_option("-O", "--audio-output", type="string", default="",
- help="pcm output device name. E.g., hw:0,0 or /dev/dsp")
- (options, args) = parser.parse_args ()
- if len(args) != 0:
- parser.print_help()
- raise SystemExit, 1
-
- sample_rate = 8000
- src = audio.source(sample_rate, options.audio_input)
- tx = blks2.digital_voice_tx(self)
- if_gain = gr.multiply_const_cc(10000)
- # channel simulator here...
- rx = blks2.digital_voice_rx(self)
- dst = audio.sink(sample_rate, options.audio_output)
-
- self.connect(src, tx, if_gain, rx, dst)
-
-
-if __name__ == '__main__':
- try:
- my_top_block().run()
- except KeyboardInterrupt:
- pass