diff options
author | Tom Rondeau | 2011-07-26 20:59:49 -0400 |
---|---|---|
committer | Tom Rondeau | 2011-07-26 20:59:49 -0400 |
commit | 8b3c4ccf922c602ae77dad7f3911b16bdd0112d3 (patch) | |
tree | e87bdb4b6cddfe1ab4721736c0a95185eb95253d /gr-digital/python | |
parent | ebcf1e9e180c7a8e9147ce441c5e9ab9056ecb13 (diff) | |
download | gnuradio-8b3c4ccf922c602ae77dad7f3911b16bdd0112d3.tar.gz gnuradio-8b3c4ccf922c602ae77dad7f3911b16bdd0112d3.tar.bz2 gnuradio-8b3c4ccf922c602ae77dad7f3911b16bdd0112d3.zip |
digital: reworking code so digital examples work. BPSK seems to work fine offline.
Diffstat (limited to 'gr-digital/python')
-rw-r--r-- | gr-digital/python/Makefile.am | 3 | ||||
-rw-r--r-- | gr-digital/python/__init__.py | 5 | ||||
-rw-r--r-- | gr-digital/python/bpsk.py | 12 | ||||
-rw-r--r-- | gr-digital/python/d8psk.py | 11 | ||||
-rw-r--r-- | gr-digital/python/dbpsk.py | 16 | ||||
-rw-r--r-- | gr-digital/python/dqpsk.py | 10 | ||||
-rw-r--r-- | gr-digital/python/generic_mod_demod.py | 31 | ||||
-rw-r--r-- | gr-digital/python/packet_utils.py | 2 | ||||
-rw-r--r-- | gr-digital/python/pkt.py | 7 | ||||
-rw-r--r-- | gr-digital/python/psk2.py | 3 | ||||
-rw-r--r-- | gr-digital/python/qam.py | 7 | ||||
-rw-r--r-- | gr-digital/python/qpsk.py | 41 |
12 files changed, 90 insertions, 58 deletions
diff --git a/gr-digital/python/Makefile.am b/gr-digital/python/Makefile.am index 164bafb99..87752e9ae 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 73c69bb27..4046f7faf 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 6d2eb5d6d..51de3ce08 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 8bed395a7..46290faed 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 1732c44ea..9e065263f 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 29afd5530..5e17d24bc 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 04302f0a4..1b8603fea 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 addbf43f5..2e216ff50 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 80001a187..c9b29bd51 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 6ab398e42..82781e63b 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 5eb34e4b2..f29291ce8 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 ea1724424..91e8b196f 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) + |