From 199ab116e54a5d8b8bf82d0d18569ccfe2114fd8 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Sun, 24 Jul 2011 15:41:36 -0400 Subject: digital: moving Python digital stuff to gr-digital. Fixing some build issues. --- gr-digital/python/pkt.py | 184 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 gr-digital/python/pkt.py (limited to 'gr-digital/python/pkt.py') diff --git a/gr-digital/python/pkt.py b/gr-digital/python/pkt.py new file mode 100644 index 0000000000..aa720d1a52 --- /dev/null +++ b/gr-digital/python/pkt.py @@ -0,0 +1,184 @@ +# +# Copyright 2005, 2006, 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 math import pi +from gnuradio import gr, packet_utils +import gnuradio.gr.gr_threading as _threading + + +# ///////////////////////////////////////////////////////////////////////////// +# mod/demod with packets as i/o +# ///////////////////////////////////////////////////////////////////////////// + +class mod_pkts(gr.hier_block2): + """ + Wrap an arbitrary digital modulator in our packet handling framework. + + Send packets by calling send_pkt + """ + def __init__(self, modulator, access_code=None, msgq_limit=2, pad_for_usrp=True, use_whitener_offset=False, + modulate=True): + """ + Hierarchical block for sending packets + + Packets to be sent are enqueued by calling send_pkt. + The output is the complex modulated signal at baseband. + + @param modulator: instance of modulator class (gr_block or hier_block2) + @type modulator: complex baseband out + @param access_code: AKA sync vector + @type access_code: string of 1's and 0's between 1 and 64 long + @param msgq_limit: maximum number of messages in message queue + @type msgq_limit: int + @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples + @param use_whitener_offset: If true, start of whitener XOR string is incremented each packet + @param modulate: If false, no modulation will be performed. + + See gmsk_mod for remaining parameters + """ + if modulate: + output_size = gr.sizeof_gr_complex + else: + output_size = gr.sizeof_char + + gr.hier_block2.__init__(self, "mod_pkts", + gr.io_signature(0, 0, 0), # Input signature + gr.io_signature(1, 1, output_size)) # Output signature + + self._modulator = modulator + self._pad_for_usrp = pad_for_usrp + self._use_whitener_offset = use_whitener_offset + self._whitener_offset = 0 + + if access_code is None: + access_code = packet_utils.default_access_code + if not packet_utils.is_1_0_string(access_code): + raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,) + self._access_code = access_code + + # accepts messages from the outside world + self._pkt_input = gr.message_source(gr.sizeof_char, msgq_limit) + if modulate: + self.connect(self._pkt_input, self._modulator, self) + else: + self.connect(self._pkt_input, self) + + def send_pkt(self, payload='', eof=False): + """ + Send the payload. + + @param payload: data to send + @type payload: string + """ + if eof: + msg = gr.message(1) # tell self._pkt_input we're not sending any more packets + else: + # print "original_payload =", string_to_hex_list(payload) + pkt = packet_utils.make_packet(payload, + self._modulator.samples_per_symbol(), + self._modulator.bits_per_symbol(), + self._access_code, + self._pad_for_usrp, + self._whitener_offset) + #print "pkt =", string_to_hex_list(pkt) + msg = gr.message_from_string(pkt) + if self._use_whitener_offset is True: + self._whitener_offset = (self._whitener_offset + 1) % 16 + + self._pkt_input.msgq().insert_tail(msg) + + + +class demod_pkts(gr.hier_block2): + """ + Wrap an arbitrary digital demodulator in our packet handling framework. + + The input is complex baseband. When packets are demodulated, they are passed to the + app via the callback. + """ + + def __init__(self, demodulator, access_code=None, callback=None, threshold=-1, demodulate=True): + """ + Hierarchical block for demodulating and deframing packets. + + The input is the complex modulated signal at baseband. + Demodulated packets are sent to the handler. + + If demodulator is None it is assumed the input is already demodulated. + + @param demodulator: instance of demodulator class (gr_block or hier_block2) + @type demodulator: complex baseband in + @param access_code: AKA sync vector + @type access_code: string of 1's and 0's + @param callback: function of two args: ok, payload + @type callback: ok: bool; payload: string + @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default) + @type threshold: int + """ + + if demodulator is not None: + input_size = gr.sizeof_gr_complex + else: + input_size = gr.sizeof_char + + gr.hier_block2.__init__(self, "demod_pkts", + gr.io_signature(1, 1, input_size), # Input signature + gr.io_signature(0, 0, 0)) # Output signature + + self._demodulator = demodulator + if access_code is None: + access_code = packet_utils.default_access_code + if not packet_utils.is_1_0_string(access_code): + raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,) + self._access_code = access_code + + if threshold == -1: + threshold = 12 # FIXME raise exception + + self._rcvd_pktq = gr.msg_queue() # holds packets from the PHY + self.correlator = gr.correlate_access_code_bb(access_code, threshold) + + self.framer_sink = gr.framer_sink_1(self._rcvd_pktq) + if self._demodulator is not None: + self.connect(self, self._demodulator, self.correlator, self.framer_sink) + else: + self.connect(self, self.correlator, self.framer_sink) + + if callback is not None: + self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback) + + +class _queue_watcher_thread(_threading.Thread): + def __init__(self, rcvd_pktq, callback): + _threading.Thread.__init__(self) + self.setDaemon(1) + self.rcvd_pktq = rcvd_pktq + self.callback = callback + self.keep_running = True + self.start() + + + def run(self): + while self.keep_running: + msg = self.rcvd_pktq.delete_head() + ok, payload = packet_utils.unmake_packet(msg.to_string(), int(msg.arg1())) + if self.callback: + self.callback(ok, payload) -- cgit v1.2.3 From 59c20a3fbdb0860ab4d8a14eb39980a6c46087f7 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Sun, 24 Jul 2011 17:46:07 -0400 Subject: digital: modifications to make Python scripts in digital usable. --- gr-digital/Makefile.am | 2 +- gr-digital/python/__init__.py | 3 +++ gr-digital/python/crc.py | 7 ++++--- gr-digital/python/dbpsk.py | 4 ++-- gr-digital/python/packet_utils.py | 4 ++-- gr-digital/python/pkt.py | 3 ++- 6 files changed, 14 insertions(+), 9 deletions(-) (limited to 'gr-digital/python/pkt.py') diff --git a/gr-digital/Makefile.am b/gr-digital/Makefile.am index 62c40f2dfd..f1409793ff 100644 --- a/gr-digital/Makefile.am +++ b/gr-digital/Makefile.am @@ -24,7 +24,7 @@ include $(top_srcdir)/Makefile.common SUBDIRS = lib if PYTHON -SUBDIRS += swig python apps grc +SUBDIRS += swig python apps grc examples endif pkgconfigdir = $(libdir)/pkgconfig diff --git a/gr-digital/python/__init__.py b/gr-digital/python/__init__.py index a17128e7d2..73c69bb27b 100644 --- a/gr-digital/python/__init__.py +++ b/gr-digital/python/__init__.py @@ -27,3 +27,6 @@ from dqpsk import * from d8psk import * from psk2 import * from qam import * +from pkt import * +from packet_utils import * +from crc import * diff --git a/gr-digital/python/crc.py b/gr-digital/python/crc.py index f9d369f4cb..198ab059f5 100644 --- a/gr-digital/python/crc.py +++ b/gr-digital/python/crc.py @@ -19,11 +19,12 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gru +from gnuradio import gru +import digital_swig import struct def gen_and_append_crc32(s): - crc = gr.crc32(s) + crc = digital_swig.crc32(s) return s + struct.pack(">I", gru.hexint(crc) & 0xFFFFFFFF) def check_crc32(s): @@ -31,7 +32,7 @@ def check_crc32(s): return (False, '') msg = s[:-4] #print "msg = '%s'" % (msg,) - actual = gr.crc32(msg) + actual = digital_swig.crc32(msg) (expected,) = struct.unpack(">I", s[-4:]) # print "actual =", hex(actual), "expected =", hex(expected) return (actual == expected, msg) diff --git a/gr-digital/python/dbpsk.py b/gr-digital/python/dbpsk.py index 21ca0474b5..1732c44ea0 100644 --- a/gr-digital/python/dbpsk.py +++ b/gr-digital/python/dbpsk.py @@ -366,5 +366,5 @@ class dbpsk_demod(gr.hier_block2): # # Add these to the mod/demod registry # -modulation_utils2.add_type_1_mod('dbpsk3', dbpsk_mod) -modulation_utils2.add_type_1_demod('dbpsk3', dbpsk_demod) +modulation_utils2.add_type_1_mod('dbpsk', dbpsk_mod) +modulation_utils2.add_type_1_demod('dbpsk', dbpsk_demod) diff --git a/gr-digital/python/packet_utils.py b/gr-digital/python/packet_utils.py index e36b05413e..addbf43f57 100644 --- a/gr-digital/python/packet_utils.py +++ b/gr-digital/python/packet_utils.py @@ -22,7 +22,7 @@ import struct import numpy from gnuradio import gru - +import crc def conv_packed_binary_string_to_1_0_string(s): """ @@ -127,7 +127,7 @@ def make_packet(payload, samples_per_symbol, bits_per_symbol, (packed_access_code, padded) = conv_1_0_string_to_packed_binary_string(access_code) (packed_preamble, ignore) = conv_1_0_string_to_packed_binary_string(preamble) - payload_with_crc = gru.gen_and_append_crc32(payload) + payload_with_crc = crc.gen_and_append_crc32(payload) #print "outbound crc =", string_to_hex_list(payload_with_crc[-4:]) L = len(payload_with_crc) diff --git a/gr-digital/python/pkt.py b/gr-digital/python/pkt.py index aa720d1a52..80001a187b 100644 --- a/gr-digital/python/pkt.py +++ b/gr-digital/python/pkt.py @@ -20,8 +20,9 @@ # from math import pi -from gnuradio import gr, packet_utils +from gnuradio import gr import gnuradio.gr.gr_threading as _threading +import packet_utils # ///////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 8b3c4ccf922c602ae77dad7f3911b16bdd0112d3 Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Tue, 26 Jul 2011 20:59:49 -0400 Subject: digital: reworking code so digital examples work. BPSK seems to work fine offline. --- gr-digital/examples/benchmark_tx.py | 13 ++++++----- gr-digital/examples/receive_path.py | 12 +++++----- gr-digital/python/Makefile.am | 3 --- gr-digital/python/__init__.py | 5 ++--- gr-digital/python/bpsk.py | 12 ++++++---- gr-digital/python/d8psk.py | 11 +++++---- gr-digital/python/dbpsk.py | 16 +++++++------ gr-digital/python/dqpsk.py | 10 +++++---- gr-digital/python/generic_mod_demod.py | 31 ++++++++++++------------- gr-digital/python/packet_utils.py | 2 +- gr-digital/python/pkt.py | 7 +++--- gr-digital/python/psk2.py | 3 +-- gr-digital/python/qam.py | 7 ++---- gr-digital/python/qpsk.py | 41 +++++++++++++++++++++++++++++----- 14 files changed, 105 insertions(+), 68 deletions(-) (limited to 'gr-digital/python/pkt.py') diff --git a/gr-digital/examples/benchmark_tx.py b/gr-digital/examples/benchmark_tx.py index 78c1315666..01902c0e37 100755 --- a/gr-digital/examples/benchmark_tx.py +++ b/gr-digital/examples/benchmark_tx.py @@ -44,8 +44,11 @@ class my_top_block(gr.top_block): self.txpath = transmit_path(modulator, options) - self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) - + if(options.to_file is not None): + self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) + else: + self.sink = gr.null_sink(gr.sizeof_gr_complex) + self.connect(self.txpath, self.sink) # ///////////////////////////////////////////////////////////////////////////// @@ -66,7 +69,7 @@ def main(): expert_grp = parser.add_option_group("Expert") parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(), - default='dbpsk', + default='psk', help="Select modulation from: %s [default=%%default]" % (', '.join(mods.keys()),)) @@ -77,9 +80,9 @@ def main(): parser.add_option("","--discontinuous", action="store_true", default=False, help="enable discontinous transmission (bursts of 5 packets)") parser.add_option("","--from-file", default=None, - help="use file for packet contents") + help="use intput file for packet contents") parser.add_option("","--to-file", default=None, - help="use file sink") + help="Output file for modulated samples") transmit_path.add_options(parser, expert_grp) diff --git a/gr-digital/examples/receive_path.py b/gr-digital/examples/receive_path.py index 0024d6941f..9bc5f7b8f2 100644 --- a/gr-digital/examples/receive_path.py +++ b/gr-digital/examples/receive_path.py @@ -20,8 +20,10 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gru, blks2 +from gnuradio import gr, gru from gnuradio import eng_notation +from gnuradio import digital + import copy import sys @@ -59,10 +61,10 @@ class receive_path(gr.hier_block2): # receiver self.packet_receiver = \ - blks2.demod_pkts(self._demod_class(**demod_kwargs), - access_code=None, - callback=self._rx_callback, - threshold=-1) + digital.demod_pkts(self._demod_class(**demod_kwargs), + access_code=None, + callback=self._rx_callback, + threshold=-1) # Carrier Sensing Blocks alpha = 0.001 diff --git a/gr-digital/python/Makefile.am b/gr-digital/python/Makefile.am index 164bafb998..87752e9ae0 100644 --- a/gr-digital/python/Makefile.am +++ b/gr-digital/python/Makefile.am @@ -49,9 +49,6 @@ digital_PYTHON = \ bpsk.py \ cpm.py \ crc.py \ - d8psk.py \ - dbpsk.py \ - dqpsk.py \ generic_mod_demod.py \ gmsk.py \ modulation_utils.py \ diff --git a/gr-digital/python/__init__.py b/gr-digital/python/__init__.py index 73c69bb27b..4046f7fafe 100644 --- a/gr-digital/python/__init__.py +++ b/gr-digital/python/__init__.py @@ -22,10 +22,9 @@ # The presence of this file turns this directory into a Python package from digital_swig import * -from dbpsk import * -from dqpsk import * -from d8psk import * from psk2 import * +from bpsk import * +from qpsk import * from qam import * from pkt import * from packet_utils import * diff --git a/gr-digital/python/bpsk.py b/gr-digital/python/bpsk.py index 6d2eb5d6d5..51de3ce084 100644 --- a/gr-digital/python/bpsk.py +++ b/gr-digital/python/bpsk.py @@ -26,8 +26,10 @@ BPSK modulation and demodulation. from math import pi, log from cmath import exp -from gnuradio import gr, modulation_utils2 +from gnuradio import gr from gnuradio.digital.generic_mod_demod import generic_mod, generic_demod +import digital_swig +import modulation_utils2 # Default number of points in constellation. _def_constellation_points = 2 @@ -41,7 +43,7 @@ _def_differential = True def bpsk_constellation(m=_def_constellation_points): if m != _def_constellation_points: raise ValueError("BPSK can only have 2 constellation points.") - return gr.constellation_bpsk() + return digital_swig.constellation_bpsk() # ///////////////////////////////////////////////////////////////////////////// # BPSK modulator @@ -61,7 +63,8 @@ class bpsk_mod(generic_mod): See generic_mod block for list of parameters. """ - constellation = gr.constellation_bpsk() + constellation_points = _def_constellation_points + constellation = digital_swig.constellation_bpsk() if constellation_points != 2: raise ValueError('Number of constellation points must be 2 for BPSK.') super(bpsk_mod, self).__init__(constellation, *args, **kwargs) @@ -85,7 +88,8 @@ class bpsk_demod(generic_demod): See generic_demod block for list of parameters. """ - constellation = gr.constellation_bpsk() + constellation_points = _def_constellation_points + constellation = digital_swig.constellation_bpsk() if constellation_points != 2: raise ValueError('Number of constellation points must be 2 for BPSK.') super(bpsk_demod, self).__init__(constellation, *args, **kwargs) diff --git a/gr-digital/python/d8psk.py b/gr-digital/python/d8psk.py index 8bed395a7f..46290faeda 100644 --- a/gr-digital/python/d8psk.py +++ b/gr-digital/python/d8psk.py @@ -310,8 +310,9 @@ class d8psk_demod(gr.hier_block2): print "Timing alpha gain: %.2f" % self._timing_alpha print "Timing beta gain: %.2f" % self._timing_beta print "Timing max dev: %.2f" % self._timing_max_dev - print "Phase track alpha: %.2e" % self._phase_alpha - print "Phase track beta: %.2e" % self._phase_beta + print "Phase damping fact: %.2e" % self._phase_damping + print "Phase natural freq: %.2e" % self._phase_natfreq + def _setup_logging(self): print "Modulation logging turned on." @@ -343,8 +344,10 @@ class d8psk_demod(gr.hier_block2): help="disable gray coding on modulated bits (PSK)") parser.add_option("", "--freq-alpha", type="float", default=_def_freq_alpha, help="set frequency lock loop alpha gain value [default=%default] (PSK)") - parser.add_option("", "--phase-alpha", type="float", default=_def_phase_alpha, - help="set phase tracking loop alpha value [default=%default] (PSK)") + parser.add_option("", "--phase-natfreq", type="float", default=_def_phase_natfreq, + help="set natural frequency of phase tracking loop [default=%default] (PSK)") + parser.add_option("", "--phase-damping", type="float", default=_def_phase_damping, + help="set damping factor of phase tracking loop [default=%default] (PSK)") parser.add_option("", "--timing-alpha", type="float", default=_def_timing_alpha, help="set timing symbol sync loop gain alpha value [default=%default] (GMSK/PSK)") parser.add_option("", "--timing-beta", type="float", default=_def_timing_beta, diff --git a/gr-digital/python/dbpsk.py b/gr-digital/python/dbpsk.py index 1732c44ea0..9e065263f6 100644 --- a/gr-digital/python/dbpsk.py +++ b/gr-digital/python/dbpsk.py @@ -100,6 +100,7 @@ class dbpsk_mod(gr.hier_block2): self.diffenc = gr.diff_encoder_bb(arity) + self.chunks2symbols = gr.chunks_to_symbols_bc(psk.constellation[arity]) # pulse shaping filter @@ -272,9 +273,8 @@ class dbpsk_demod(gr.hier_block2): self.diffdec = gr.diff_phasor_cc() # find closest constellation point - rot = 1 - rotated_const = map(lambda pt: pt * rot, psk.constellation[arity]) - self.slicer = digital.constellation_decoder_cb(rotated_const, range(arity)) + const = digital_swig.constellation_bpsk() + self.slicer = digital_swig.constellation_decoder_cb(const.base()) if self._gray_code: self.symbol_mapper = gr.map_bb(psk.gray_to_binary[arity]) @@ -312,8 +312,8 @@ class dbpsk_demod(gr.hier_block2): print "Timing alpha gain: %.2e" % self._timing_alpha print "Timing beta gain: %.2e" % self._timing_beta print "Timing max dev: %.2f" % self._timing_max_dev - print "Phase track alpha: %.2e" % self._phase_alpha - print "Phase track beta: %.2e" % self._phase_beta + print "Phase damping fact: %.2e" % self._phase_damping + print "Phase natural freq: %.2e" % self._phase_natfreq def _setup_logging(self): print "Modulation logging turned on." @@ -345,8 +345,10 @@ class dbpsk_demod(gr.hier_block2): help="disable gray coding on modulated bits (PSK)") parser.add_option("", "--freq-alpha", type="float", default=_def_freq_alpha, help="set frequency lock loop alpha gain value [default=%default] (PSK)") - parser.add_option("", "--phase-alpha", type="float", default=_def_phase_alpha, - help="set phase tracking loop alpha value [default=%default] (PSK)") + parser.add_option("", "--phase-natfreq", type="float", default=_def_phase_natfreq, + help="set natural frequency of phase tracking loop [default=%default] (PSK)") + parser.add_option("", "--phase-damping", type="float", default=_def_phase_damping, + help="set damping factor of phase tracking loop [default=%default] (PSK)") parser.add_option("", "--timing-alpha", type="float", default=_def_timing_alpha, help="set timing symbol sync loop gain alpha value [default=%default] (GMSK/PSK)") parser.add_option("", "--timing-beta", type="float", default=_def_timing_beta, diff --git a/gr-digital/python/dqpsk.py b/gr-digital/python/dqpsk.py index 29afd55306..5e17d24bcc 100644 --- a/gr-digital/python/dqpsk.py +++ b/gr-digital/python/dqpsk.py @@ -315,8 +315,8 @@ class dqpsk_demod(gr.hier_block2): print "Timing alpha gain: %.2f" % self._timing_alpha print "Timing beta gain: %.2f" % self._timing_beta print "Timing max dev: %.2f" % self._timing_max_dev - print "Phase track alpha: %.2e" % self._phase_alpha - print "Phase track beta: %.2e" % self._phase_beta + print "Phase damping fact: %.2e" % self._phase_damping + print "Phase natural freq: %.2e" % self._phase_natfreq def _setup_logging(self): print "Modulation logging turned on." @@ -348,8 +348,10 @@ class dqpsk_demod(gr.hier_block2): help="disable gray coding on modulated bits (PSK)") parser.add_option("", "--freq-alpha", type="float", default=_def_freq_alpha, help="set frequency lock loop alpha gain value [default=%default] (PSK)") - parser.add_option("", "--phase-alpha", type="float", default=_def_phase_alpha, - help="set phase tracking loop alpha value [default=%default] (PSK)") + parser.add_option("", "--phase-natfreq", type="float", default=_def_phase_natfreq, + help="set natural frequency of phase tracking loop [default=%default] (PSK)") + parser.add_option("", "--phase-damping", type="float", default=_def_phase_damping, + help="set damping factor of phase tracking loop [default=%default] (PSK)") parser.add_option("", "--timing-alpha", type="float", default=_def_timing_alpha, help="set timing symbol sync loop gain alpha value [default=%default] (GMSK/PSK)") parser.add_option("", "--timing-beta", type="float", default=_def_timing_beta, diff --git a/gr-digital/python/generic_mod_demod.py b/gr-digital/python/generic_mod_demod.py index 04302f0a48..1b8603fea6 100644 --- a/gr-digital/python/generic_mod_demod.py +++ b/gr-digital/python/generic_mod_demod.py @@ -26,8 +26,7 @@ Generic modulation and demodulation. """ from gnuradio import gr -from gnuradio.modulation_utils2 import extract_kwargs_from_options_for_class -#from gnuradio.digital.utils import mod_codes +from modulation_utils2 import extract_kwargs_from_options_for_class from utils import mod_codes import digital_swig @@ -106,12 +105,10 @@ class generic_mod(gr.hier_block2): self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._differential = differential - - if not isinstance(self._samples_per_symbol, int) or self._samples_per_symbol < 2: - raise TypeError, ("sbp must be an integer >= 2, is %d" % self._samples_per_symbol) - - ntaps = 11 * self._samples_per_symbol + if self._samples_per_symbol < 2: + raise TypeError, ("sbp must be >= 2, is %d" % self._samples_per_symbol) + arity = pow(2,self.bits_per_symbol()) # turn bytes into k-bit vectors @@ -127,14 +124,15 @@ class generic_mod(gr.hier_block2): self.chunks2symbols = gr.chunks_to_symbols_bc(self._constellation.points()) # pulse shaping filter - self.rrc_taps = gr.firdes.root_raised_cosine( - self._samples_per_symbol, # gain (samples_per_symbol since we're - # interpolating by samples_per_symbol) - self._samples_per_symbol, # sampling rate - 1.0, # symbol rate - self._excess_bw, # excess bandwidth (roll-off factor) + nfilts = 32 + ntaps = nfilts * 11 * int(self._samples_per_symbol) # make nfilts filters of ntaps each + self.rrc_taps = gr.firdes.root_raised_cosine( + nfilts, # gain + nfilts, # sampling rate based on 32 filters in resampler + 1.0, # symbol rate + self._excess_bw, # excess bandwidth (roll-off factor) ntaps) - self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, + self.rrc_filter = gr.pfb_arb_resampler_ccf(self._samples_per_symbol, self.rrc_taps) # Connect @@ -255,8 +253,8 @@ class generic_demod(gr.hier_block2): self._timing_max_dev=timing_max_dev self._differential = differential - if not isinstance(self._samples_per_symbol, int) or self._samples_per_symbol < 2: - raise TypeError, ("sbp must be an integer >= 2, is %d" % self._samples_per_symbol) + if self._samples_per_symbol < 2: + raise TypeError, ("sbp must be >= 2, is %d" % self._samples_per_symbol) arity = pow(2,self.bits_per_symbol()) @@ -279,7 +277,6 @@ class generic_demod(gr.hier_block2): taps, nfilts, nfilts/2, self._timing_max_dev) self.time_recov.set_beta(self._timing_beta) - #self._phase_beta = 0.25 * self._phase_alpha * self._phase_alpha self._phase_beta = 0.25 * self._phase_alpha * self._phase_alpha fmin = -0.25 fmax = 0.25 diff --git a/gr-digital/python/packet_utils.py b/gr-digital/python/packet_utils.py index addbf43f57..2e216ff50e 100644 --- a/gr-digital/python/packet_utils.py +++ b/gr-digital/python/packet_utils.py @@ -184,7 +184,7 @@ def unmake_packet(whitened_payload_with_crc, whitener_offset=0, dewhitening=True else: payload_with_crc = (whitened_payload_with_crc) - ok, payload = gru.check_crc32(payload_with_crc) + ok, payload = crc.check_crc32(payload_with_crc) if 0: print "payload_with_crc =", string_to_hex_list(payload_with_crc) diff --git a/gr-digital/python/pkt.py b/gr-digital/python/pkt.py index 80001a187b..c9b29bd51a 100644 --- a/gr-digital/python/pkt.py +++ b/gr-digital/python/pkt.py @@ -23,6 +23,7 @@ from math import pi from gnuradio import gr import gnuradio.gr.gr_threading as _threading import packet_utils +import digital_swig # ///////////////////////////////////////////////////////////////////////////// @@ -35,8 +36,8 @@ class mod_pkts(gr.hier_block2): Send packets by calling send_pkt """ - def __init__(self, modulator, access_code=None, msgq_limit=2, pad_for_usrp=True, use_whitener_offset=False, - modulate=True): + def __init__(self, modulator, access_code=None, msgq_limit=2, pad_for_usrp=True, + use_whitener_offset=False, modulate=True): """ Hierarchical block for sending packets @@ -155,7 +156,7 @@ class demod_pkts(gr.hier_block2): threshold = 12 # FIXME raise exception self._rcvd_pktq = gr.msg_queue() # holds packets from the PHY - self.correlator = gr.correlate_access_code_bb(access_code, threshold) + self.correlator = digital_swig.correlate_access_code_bb(access_code, threshold) self.framer_sink = gr.framer_sink_1(self._rcvd_pktq) if self._demodulator is not None: diff --git a/gr-digital/python/psk2.py b/gr-digital/python/psk2.py index 6ab398e42c..82781e63b0 100644 --- a/gr-digital/python/psk2.py +++ b/gr-digital/python/psk2.py @@ -26,9 +26,8 @@ PSK modulation and demodulation. from math import pi, log from cmath import exp -from gnuradio import gr, modulation_utils2 import digital_swig -#from gnuradio.digital.generic_mod_demod import generic_mod, generic_demod +import modulation_utils2 from utils import mod_codes, gray_code from generic_mod_demod import generic_mod, generic_demod diff --git a/gr-digital/python/qam.py b/gr-digital/python/qam.py index 5eb34e4b2d..f29291ce89 100644 --- a/gr-digital/python/qam.py +++ b/gr-digital/python/qam.py @@ -25,14 +25,11 @@ QAM modulation and demodulation. from math import pi, sqrt, log -from gnuradio import gr, modulation_utils2 -#from gnuradio.digital.generic_mod_demod import generic_mod, generic_demod -#from gnuradio.digital.utils.gray_code import gray_code -#from gnuradio.digital.utils import mod_codes - +from gnuradio import gr from generic_mod_demod import generic_mod, generic_demod from utils.gray_code import gray_code from utils import mod_codes +import modulation_utils2 # Default number of points in constellation. _def_constellation_points = 16 diff --git a/gr-digital/python/qpsk.py b/gr-digital/python/qpsk.py index ea17244241..91e8b196f4 100644 --- a/gr-digital/python/qpsk.py +++ b/gr-digital/python/qpsk.py @@ -26,9 +26,10 @@ Demodulation is not included since the generic_mod_demod doesn't work for non-differential encodings. """ -from gnuradio import gr, modulation_utils2 -from gnuradio.digital.generic_mod_demod import generic_mod - +from gnuradio import gr +from gnuradio.digital.generic_mod_demod import generic_mod, generic_demod +import digital_swig +import modulation_utils2 # Default number of points in constellation. _def_constellation_points = 4 @@ -43,7 +44,7 @@ _def_gray_coded = True def qpsk_constellation(m=_def_constellation_points): if m != _def_constellation_points: raise ValueError("QPSK can only have 4 constellation points.") - return gr.constellation_qpsk() + return digital_swig.constellation_qpsk() # ///////////////////////////////////////////////////////////////////////////// # QPSK modulator @@ -65,15 +66,45 @@ class qpsk_mod(generic_mod): See generic_mod block for list of parameters. """ - constellation = gr.constellation_qpsk() + constellation_points = _def_constellation_points + constellation = digital_swig.constellation_qpsk() if constellation_points != 4: raise ValueError("QPSK can only have 4 constellation points.") if differential or not gray_coded: raise ValueError("This QPSK mod/demod works only for gray-coded, non-differential.") super(qpsk_mod, self).__init__(constellation, differential, gray_coded, *args, **kwargs) + +# ///////////////////////////////////////////////////////////////////////////// +# QPSK demodulator +# +# ///////////////////////////////////////////////////////////////////////////// + +class qpsk_demod(generic_demod): + + def __init__(self, constellation_points=_def_constellation_points, + *args, **kwargs): + + """ + Hierarchical block for RRC-filtered QPSK modulation. + + The input is a byte stream (unsigned char) and the + output is the complex modulated signal at baseband. + + See generic_demod block for list of parameters. + """ + + constellation_points = _def_constellation_points + constellation = digital_swig.constellation_qpsk() + if constellation_points != 4: + raise ValueError('Number of constellation points must be 4 for QPSK.') + super(qpsk_demod, self).__init__(constellation, *args, **kwargs) + + # # Add these to the mod/demod registry # modulation_utils2.add_type_1_mod('qpsk', qpsk_mod) +modulation_utils2.add_type_1_demod('qpsk', qpsk_demod) modulation_utils2.add_type_1_constellation('qpsk', qpsk_constellation) + -- cgit v1.2.3