diff options
author | Tom Rondeau | 2010-03-14 17:32:23 -0400 |
---|---|---|
committer | Tom Rondeau | 2010-03-14 17:32:23 -0400 |
commit | b53bc1395bd2e8b1ad8a34c583d36fb4ddda7629 (patch) | |
tree | 5f1dd8dff1cabaf055c23097f335e2295c5840df /gnuradio-core/src/python | |
parent | 8c163c9cca7aa39862c8c8eb19a3e0a18c61a661 (diff) | |
download | gnuradio-b53bc1395bd2e8b1ad8a34c583d36fb4ddda7629.tar.gz gnuradio-b53bc1395bd2e8b1ad8a34c583d36fb4ddda7629.tar.bz2 gnuradio-b53bc1395bd2e8b1ad8a34c583d36fb4ddda7629.zip |
Making old and new digital modulations completely seperable by adding modulation_utils2 so only new modulator blocks work with the version 2 of everything. Also changed some internal names for clarity.
Diffstat (limited to 'gnuradio-core/src/python')
4 files changed, 122 insertions, 40 deletions
diff --git a/gnuradio-core/src/python/gnuradio/Makefile.am b/gnuradio-core/src/python/gnuradio/Makefile.am index dcc0017b3..f0516f2fd 100644 --- a/gnuradio-core/src/python/gnuradio/Makefile.am +++ b/gnuradio-core/src/python/gnuradio/Makefile.am @@ -30,6 +30,7 @@ grpython_PYTHON = \ eng_notation.py \ eng_option.py \ modulation_utils.py \ + modulation_utils2.py \ ofdm_packet_utils.py \ packet_utils.py \ gr_unittest.py \ diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/dbpsk2.py b/gnuradio-core/src/python/gnuradio/blks2impl/dbpsk2.py index 135b38e1f..2d073afec 100644 --- a/gnuradio-core/src/python/gnuradio/blks2impl/dbpsk2.py +++ b/gnuradio-core/src/python/gnuradio/blks2impl/dbpsk2.py @@ -25,7 +25,7 @@ differential BPSK modulation and demodulation. """ -from gnuradio import gr, gru, modulation_utils +from gnuradio import gr, gru, modulation_utils2 from math import pi, sqrt, ceil import psk import cmath @@ -39,7 +39,7 @@ _def_verbose = False _def_log = False _def_freq_alpha = 0.010 -_def_costas_alpha = 0.1 +_def_phase_alpha = 0.1 _def_timing_alpha = 0.100 _def_timing_beta = 0.010 _def_timing_max_dev = 1.5 @@ -145,7 +145,7 @@ class dbpsk2_mod(gr.hier_block2): """ Given command line options, create dictionary suitable for passing to __init__ """ - return modulation_utils.extract_kwargs_from_options(dbpsk2_mod.__init__, + return modulation_utils2.extract_kwargs_from_options(dbpsk2_mod.__init__, ('self',), options) extract_kwargs_from_options=staticmethod(extract_kwargs_from_options) @@ -182,7 +182,7 @@ class dbpsk2_demod(gr.hier_block2): samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, freq_alpha=_def_freq_alpha, - costas_alpha=_def_costas_alpha, + phase_alpha=_def_phase_alpha, timing_alpha=_def_timing_alpha, timing_max_dev=_def_timing_max_dev, gray_code=_def_gray_code, @@ -201,8 +201,8 @@ class dbpsk2_demod(gr.hier_block2): @type excess_bw: float @param freq_alpha: loop filter gain for frequency recovery @type freq_alpha: float - @param costas_alpha: loop filter gain for phase/fine frequency recovery - @type costas_alpha: float + @param phase_alpha: loop filter gain for phase/fine frequency recovery + @type phase_alpha: float @param timing_alpha: loop alpha gain for timing recovery @type timing_alpha: float @param timing_max: timing loop maximum rate deviations @@ -227,7 +227,7 @@ class dbpsk2_demod(gr.hier_block2): self._excess_bw = excess_bw self._freq_alpha = freq_alpha self._freq_beta = 0.10*self._freq_alpha - self._costas_alpha = costas_alpha + self._phase_alpha = phase_alpha self._timing_alpha = timing_alpha self._timing_beta = _def_timing_beta self._timing_max_dev=timing_max_dev @@ -259,13 +259,13 @@ class dbpsk2_demod(gr.hier_block2): self.time_recov.set_beta(self._timing_beta) # Perform phase / fine frequency correction - self._costas_beta = 0.25 * self._costas_alpha * self._costas_alpha + self._phase_beta = 0.25 * self._phase_alpha * self._phase_alpha # Allow a frequency swing of +/- half of the sample rate fmin = -0.5 fmax = 0.5 - self.phase_recov = gr.costas_loop_cc(self._costas_alpha, - self._costas_beta, + self.phase_recov = gr.costas_loop_cc(self._phase_alpha, + self._phase_beta, fmax, fmin, arity) # Do differential decoding based on phase change of symbols @@ -309,11 +309,11 @@ class dbpsk2_demod(gr.hier_block2): print "Gray code: %s" % self._gray_code print "RRC roll-off factor: %.2f" % self._excess_bw print "FLL gain: %.2e" % self._freq_alpha - print "Costas Loop alpha: %.2e" % self._costas_alpha - print "Costas Loop beta: %.2e" % self._costas_beta 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 def _setup_logging(self): print "Modulation logging turned on." @@ -328,7 +328,7 @@ class dbpsk2_demod(gr.hier_block2): self.connect(self.diffdec, gr.file_sink(gr.sizeof_gr_complex, "rx_diffdec.dat")) self.connect(self.slicer, - gr.file_sink(gr.sizeof_char, "rx_slicer.dat")) + gr.file_sink(gr.sizeof_char, "rx_slicer.dat")) self.connect(self.symbol_mapper, gr.file_sink(gr.sizeof_char, "rx_symbol_mapper.dat")) self.connect(self.unpack, @@ -345,11 +345,11 @@ class dbpsk2_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("", "--costas-alpha", type="float", default=None, - help="set Costas loop alpha value [default=%default] (PSK)") - parser.add_option("", "--gain-alpha", type="float", default=_def_timing_alpha, + parser.add_option("", "--phase-alpha", type="float", default=_def_phase_alpha, + help="set phase tracking loop alpha value [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("", "--gain-beta", type="float", default=_def_timing_beta, + parser.add_option("", "--timing-beta", type="float", default=_def_timing_beta, help="set timing symbol sync loop gain beta value [default=%default] (GMSK/PSK)") parser.add_option("", "--timing-max-dev", type="float", default=_def_timing_max_dev, help="set timing symbol sync loop maximum deviation [default=%default] (GMSK/PSK)") @@ -359,11 +359,11 @@ class dbpsk2_demod(gr.hier_block2): """ Given command line options, create dictionary suitable for passing to __init__ """ - return modulation_utils.extract_kwargs_from_options( + return modulation_utils2.extract_kwargs_from_options( dbpsk2_demod.__init__, ('self',), options) extract_kwargs_from_options=staticmethod(extract_kwargs_from_options) # # Add these to the mod/demod registry # -modulation_utils.add_type_1_mod('dbpsk2', dbpsk2_mod) -modulation_utils.add_type_1_demod('dbpsk2', dbpsk2_demod) +modulation_utils2.add_type_1_mod('dbpsk2', dbpsk2_mod) +modulation_utils2.add_type_1_demod('dbpsk2', dbpsk2_demod) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/dqpsk2.py b/gnuradio-core/src/python/gnuradio/blks2impl/dqpsk2.py index f852a324c..856b4cb69 100644 --- a/gnuradio-core/src/python/gnuradio/blks2impl/dqpsk2.py +++ b/gnuradio-core/src/python/gnuradio/blks2impl/dqpsk2.py @@ -25,7 +25,7 @@ differential QPSK modulation and demodulation. """ -from gnuradio import gr, gru, modulation_utils +from gnuradio import gr, gru, modulation_utils2 from math import pi, sqrt import psk import cmath @@ -39,7 +39,7 @@ _def_verbose = False _def_log = False _def_freq_alpha = 0.010 -_def_costas_alpha = 0.01 +_def_phase_alpha = 0.01 _def_timing_alpha = 0.100 _def_timing_beta = 0.010 _def_timing_max_dev = 1.5 @@ -168,7 +168,7 @@ class dqpsk2_mod(gr.hier_block2): """ Given command line options, create dictionary suitable for passing to __init__ """ - return modulation_utils.extract_kwargs_from_options(dqpsk2_mod.__init__, + return modulation_utils2.extract_kwargs_from_options(dqpsk2_mod.__init__, ('self',), options) extract_kwargs_from_options=staticmethod(extract_kwargs_from_options) @@ -185,7 +185,7 @@ class dqpsk2_demod(gr.hier_block2): samples_per_symbol=_def_samples_per_symbol, excess_bw=_def_excess_bw, freq_alpha=_def_freq_alpha, - costas_alpha=_def_costas_alpha, + phase_alpha=_def_phase_alpha, timing_alpha=_def_timing_alpha, timing_max_dev=_def_timing_max_dev, gray_code=_def_gray_code, @@ -204,8 +204,8 @@ class dqpsk2_demod(gr.hier_block2): @type excess_bw: float @param freq_alpha: loop filter gain for frequency recovery @type freq_alpha: float - @param costas_alpha: loop filter gain - @type costas_alphas: float + @param phase_alpha: loop filter gain + @type phase_alphas: float @param timing_alpha: timing loop alpha gain @type timing_alpha: float @param timing_max: timing loop maximum rate deviations @@ -230,7 +230,7 @@ class dqpsk2_demod(gr.hier_block2): self._excess_bw = excess_bw self._freq_alpha = freq_alpha self._freq_beta = 0.25*self._freq_alpha**2 - self._costas_alpha = costas_alpha + self._phase_alpha = phase_alpha self._timing_alpha = timing_alpha self._timing_beta = _def_timing_beta self._timing_max_dev=timing_max_dev @@ -264,13 +264,13 @@ class dqpsk2_demod(gr.hier_block2): # Perform phase / fine frequency correction - self._costas_beta = 0.25 * self._costas_alpha * self._costas_alpha + self._phase_beta = 0.25 * self._phase_alpha * self._phase_alpha # Allow a frequency swing of +/- half of the sample rate fmin = -0.5 fmax = 0.5 - self.phase_recov = gr.costas_loop_cc(self._costas_alpha, - self._costas_beta, + self.phase_recov = gr.costas_loop_cc(self._phase_alpha, + self._phase_beta, fmax, fmin, arity) @@ -315,11 +315,11 @@ class dqpsk2_demod(gr.hier_block2): print "Gray code: %s" % self._gray_code print "RRC roll-off factor: %.2f" % self._excess_bw print "FLL gain: %.2f" % self._freq_alpha - print "Costas Loop alpha: %.2e" % self._costas_alpha - print "Costas Loop beta: %.2e" % self._costas_beta 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 def _setup_logging(self): print "Modulation logging turned on." @@ -342,7 +342,7 @@ class dqpsk2_demod(gr.hier_block2): def add_options(parser): """ - Adds modulation-specific options to the standard parser + Adds DQPSK demodulation-specific options to the standard parser """ parser.add_option("", "--excess-bw", type="float", default=_def_excess_bw, help="set RRC excess bandwith factor [default=%default] (PSK)") @@ -351,11 +351,11 @@ class dqpsk2_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("", "--costas-alpha", type="float", default=_def_costas_alpha, - help="set Costas loop alpha value [default=%default] (PSK)") - parser.add_option("", "--gain-alpha", type="float", default=_def_timing_alpha, + parser.add_option("", "--phase-alpha", type="float", default=_def_phase_alpha, + help="set phase tracking loop alpha value [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("", "--gain-beta", type="float", default=_def_timing_beta, + parser.add_option("", "--timing-beta", type="float", default=_def_timing_beta, help="set timing symbol sync loop gain beta value [default=%default] (GMSK/PSK)") parser.add_option("", "--timing-max-dev", type="float", default=_def_timing_max_dev, help="set timing symbol sync loop maximum deviation [default=%default] (GMSK/PSK)") @@ -365,7 +365,7 @@ class dqpsk2_demod(gr.hier_block2): """ Given command line options, create dictionary suitable for passing to __init__ """ - return modulation_utils.extract_kwargs_from_options( + return modulation_utils2.extract_kwargs_from_options( dqpsk2_demod.__init__, ('self',), options) extract_kwargs_from_options=staticmethod(extract_kwargs_from_options) @@ -373,5 +373,5 @@ class dqpsk2_demod(gr.hier_block2): # # Add these to the mod/demod registry # -modulation_utils.add_type_1_mod('dqpsk2', dqpsk2_mod) -modulation_utils.add_type_1_demod('dqpsk2', dqpsk2_demod) +modulation_utils2.add_type_1_mod('dqpsk2', dqpsk2_mod) +modulation_utils2.add_type_1_demod('dqpsk2', dqpsk2_demod) diff --git a/gnuradio-core/src/python/gnuradio/modulation_utils2.py b/gnuradio-core/src/python/gnuradio/modulation_utils2.py new file mode 100644 index 000000000..71ba77389 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/modulation_utils2.py @@ -0,0 +1,81 @@ +# +# Copyright 2006 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 this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +""" +Miscellaneous utilities for managing mods and demods, as well as other items +useful in dealing with generalized handling of different modulations and demods. +""" + +import inspect + + +# Type 1 modulators accept a stream of bytes on their input and produce complex baseband output +_type_1_modulators = {} + +def type_1_mods(): + return _type_1_modulators + +def add_type_1_mod(name, mod_class): + _type_1_modulators[name] = mod_class + + +# Type 1 demodulators accept complex baseband input and produce a stream of bits, packed +# 1 bit / byte as their output. Their output is completely unambiguous. There is no need +# to resolve phase or polarity ambiguities. +_type_1_demodulators = {} + +def type_1_demods(): + return _type_1_demodulators + +def add_type_1_demod(name, demod_class): + _type_1_demodulators[name] = demod_class + + +def extract_kwargs_from_options(function, excluded_args, options): + """ + Given a function, a list of excluded arguments and the result of + parsing command line options, create a dictionary of key word + arguments suitable for passing to the function. The dictionary + will be populated with key/value pairs where the keys are those + that are common to the function's argument list (minus the + excluded_args) and the attributes in options. The values are the + corresponding values from options unless that value is None. + In that case, the corresponding dictionary entry is not populated. + + (This allows different modulations that have the same parameter + names, but different default values to coexist. The downside is + that --help in the option parser will list the default as None, + but in that case the default provided in the __init__ argument + list will be used since there is no kwargs entry.) + + @param function: the function whose parameter list will be examined + @param excluded_args: function arguments that are NOT to be added to the dictionary + @type excluded_args: sequence of strings + @param options: result of command argument parsing + @type options: optparse.Values + """ + # Try this in C++ ;) + args, varargs, varkw, defaults = inspect.getargspec(function) + d = {} + for kw in [a for a in args if a not in excluded_args]: + if hasattr(options, kw): + if getattr(options, kw) is not None: + d[kw] = getattr(options, kw) + return d |