commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r3564 - in gnuradio/branches/developers/eb/digital-wip


From: eb
Subject: [Commit-gnuradio] r3564 - in gnuradio/branches/developers/eb/digital-wip: gnuradio-core/src/python/gnuradio gnuradio-core/src/python/gnuradio/blksimpl gnuradio-examples/python/gmsk2
Date: Mon, 18 Sep 2006 14:15:04 -0600 (MDT)

Author: eb
Date: 2006-09-18 14:15:04 -0600 (Mon, 18 Sep 2006)
New Revision: 3564

Added:
   
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/modulation_utils.py
Removed:
   
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/modulators.py
Modified:
   
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/Makefile.am
   
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/Makefile.am
   
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/dbpsk.py
   
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/gmsk.py
   
gnuradio/branches/developers/eb/digital-wip/gnuradio-examples/python/gmsk2/benchmark_rx.py
   
gnuradio/branches/developers/eb/digital-wip/gnuradio-examples/python/gmsk2/benchmark_tx.py
   
gnuradio/branches/developers/eb/digital-wip/gnuradio-examples/python/gmsk2/transmit_path.py
Log:
work-in-progress

Modified: 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/Makefile.am
   2006-09-18 20:14:32 UTC (rev 3563)
+++ 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/Makefile.am
   2006-09-18 20:15:04 UTC (rev 3564)
@@ -28,6 +28,7 @@
        audio.py                        \
        eng_notation.py                 \
        eng_option.py                   \
+       modulation_utils.py             \
        packet_utils.py                 \
        gr_unittest.py                  \
        optfir.py                       \

Modified: 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/Makefile.am
  2006-09-18 20:14:32 UTC (rev 3563)
+++ 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/Makefile.am
  2006-09-18 20:15:04 UTC (rev 3564)
@@ -36,7 +36,6 @@
        fm_demod.py             \
        fm_emph.py              \
        gmsk.py                 \
-       modulators.py           \
        nbfm_rx.py              \
        nbfm_tx.py              \
        pkt.py                  \

Modified: 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/dbpsk.py
===================================================================
--- 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/dbpsk.py
     2006-09-18 20:14:32 UTC (rev 3563)
+++ 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/dbpsk.py
     2006-09-18 20:15:04 UTC (rev 3564)
@@ -25,7 +25,7 @@
 differential BPSK modulation and demodulation.
 """
 
-from gnuradio import gr, gru
+from gnuradio import gr, gru, modulation_utils
 from math import pi, sqrt
 import psk
 import cmath
@@ -34,11 +34,11 @@
 
 
 # /////////////////////////////////////////////////////////////////////////////
-#            BPSK mod/demod with steams of bytes as data i/o
+#                             DBPSK modulator
 # /////////////////////////////////////////////////////////////////////////////
 
 class dbpsk_mod(gr.hier_block):
-    def __init__(self, fg, spb=2, excess_bw=0.35, gray_code=True, 
verbose=True, debug=False):
+    def __init__(self, fg, samples_per_symbol=2, excess_bw=0.35, 
gray_code=True, verbose=True, debug=False):
         """
        Hierarchical block for RRC-filtered QPSK modulation.
 
@@ -47,32 +47,32 @@
         
        @param fg: flow graph
        @type fg: flow graph
-       @param spb: samples per baud >= 2
-       @type spb: integer
+       @param samples_per_symbol: samples per baud >= 2
+       @type samples_per_symbol: integer
        @param excess_bw: Root-raised cosine filter excess bandwidth
        @type excess_bw: float
         @param gray_code: Tell modulator to Gray code the bits
         @type gray_code: bool
         @param verbose: Print information about modulator?
         @type verbose: bool
-        @param debug: Print modualtion data to files?
+        @param debug: Log modulation data to files?
         @type debug: bool
        """
 
-        self.fg = fg
-        self.spb = spb
-        self.excess_bw = excess_bw
+        self._fg = fg
+        self._samples_per_symbol = samples_per_symbol
+        self._excess_bw = excess_bw
 
-        if not isinstance(self.spb, int) or self.spb < 2:
-            raise TypeError, ("sbp must be an integer >= 2, is %d" % self.spb)
+        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.spb
+       ntaps = 11 * self._samples_per_symbol
 
-        arity = pow(2,self.bits_per_baud())
+        arity = pow(2,self.bits_per_symbol())
        
         # turn bytes into k-bit vectors
         self.bytes2chunks = \
-          gr.packed_to_unpacked_bb(self.bits_per_baud(), gr.GR_MSB_FIRST)
+          gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST)
 
         if gray_code:
             self.gray_coder = gr.map_bb(psk.binary_to_gray[arity])
@@ -85,84 +85,92 @@
 
         # pulse shaping filter
        self.rrc_taps = gr.firdes.root_raised_cosine(
-               self.spb,        # gain  (spb since we're interpolating by spb)
-               self.spb,        # sampling rate
-               1.0,             # symbol rate
-               self.excess_bw,  # excess bandwidth (roll-off factor)
-                ntaps)
+           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)
+            ntaps)
 
-       self.rrc_filter = gr.interp_fir_filter_ccf(self.spb, self.rrc_taps)
+       self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol,
+                                                   self.rrc_taps)
 
        # Connect
         fg.connect(self.bytes2chunks, self.gray_coder, self.diffenc,
                    self.chunks2symbols, self.rrc_filter)
 
         if verbose:
-            self.verbose()
+            self._print_verbage()
             
         if debug:
-            self.debug()
+            self._setup_logging()
             
        # Initialize base class
-       gr.hier_block.__init__(self, self.fg, self.bytes2chunks, 
self.rrc_filter)
+       gr.hier_block.__init__(self, self._fg, self.bytes2chunks, 
self.rrc_filter)
 
     def samples_per_symbol(self):
-        return self.spb
+        return self._samples_per_symbol
 
-    def bits_per_baud(self=None):   # static method that's also callable on an 
instance
+    def bits_per_symbol(self=None):   # static method that's also callable on 
an instance
         return 1
-    bits_per_baud = staticmethod(bits_per_baud)      # make it a static 
method.  RTFM
+    bits_per_symbol = staticmethod(bits_per_symbol)      # make it a static 
method.  RTFM
 
-    def verbose(self):
-        print "bits per symbol = %d" % self.bits_per_baud()
-        print "RRC roll-off factor = %.2f" % self.excess_bw
-
-    def debug(self):
-        print "Modulation debugging turned on."
-        self.fg.connect(self.bytes2chunks,
-                        gr.file_sink(gr.sizeof_char, "bytes2chunks.dat"))
-        self.fg.connect(self.gray_coder,
-                        gr.file_sink(gr.sizeof_char, "graycoder.dat"))
-        self.fg.connect(self.diffenc,
-                        gr.file_sink(gr.sizeof_char, "diffenc.dat"))
-        self.fg.connect(self.chunks2symbols,
-                        gr.file_sink(gr.sizeof_gr_complex, 
"chunks2symbols.dat"))
-        self.fg.connect(self.rrc_filter,
-                      gr.file_sink(gr.sizeof_gr_complex, "rrc_filter.dat"))
-              
-    def arguments(self=None):
-        args = {'spb':2, 'excess_bw':0.3, 'gray_code':True, 'verbose':True, 
'debug':False}
-        return args
-    arguments = staticmethod(arguments)
-
     def add_options(parser):
         """
-        Adds modulation-specific options to the standard parser
+        Adds DBPSK modulation-specific options to the standard parser
         """
         from optparse import OptionConflictError
-        try:
-            parser.add_option("", "--excess-bw", type="float", default=0.3,
-                              help="set RRC excess bandwith factor 
[default=%default]")
-            parser.add_option("", "--no-gray-code", action="store_false", 
default=True,
-                              help="Don't use gray coding on modulated bits 
[default=%default]")
-        except OptionConflictError:
-            pass
+        parser.add_option("", "--excess-bw", type="float", default=0.3,
+                          help="set RRC excess bandwith factor 
[default=%default]")
+        parser.add_option("", "--no-gray-code", action="store_false", 
default=True,
+                          help="Don't use gray coding on modulated bits 
[default=%default]")
     add_options=staticmethod(add_options)
 
+    def extract_kwargs_from_options(options):
+        """
+        Given command line options, create dictionary suitable for passing to 
__init__
+        """
+        return modulation_utils.extract_kwargs_from_options(dbpsk_mod.__init__,
+                                                            ('self', 'fg'), 
options)
+    extract_kwargs_from_options=staticmethod(extract_kwargs_from_options)
 
-class 
dbpsk_demod__coherent_detection_of_differentially_encoded_psk(gr.hier_block):
-    def __init__(self, fg, spb, excess_bw=0.35, costas_alpha=0.005, 
gain_mu=0.05, mu=0.5,
+
+    def _print_verbage(self):
+        print "bits per symbol = %d" % self.bits_per_symbol()
+        print "RRC roll-off factor = %.2f" % self._excess_bw
+
+    def _setup_logging(self):
+        print "Modulation logging turned on."
+        self._fg.connect(self.bytes2chunks,
+                         gr.file_sink(gr.sizeof_char, "bytes2chunks.dat"))
+        self._fg.connect(self.gray_coder,
+                         gr.file_sink(gr.sizeof_char, "graycoder.dat"))
+        self._fg.connect(self.diffenc,
+                         gr.file_sink(gr.sizeof_char, "diffenc.dat"))
+        self._fg.connect(self.chunks2symbols,
+                         gr.file_sink(gr.sizeof_gr_complex, 
"chunks2symbols.dat"))
+        self._fg.connect(self.rrc_filter,
+                         gr.file_sink(gr.sizeof_gr_complex, "rrc_filter.dat"))
+              
+
+# /////////////////////////////////////////////////////////////////////////////
+#                             DBPSK demodulator
+# /////////////////////////////////////////////////////////////////////////////
+
+class 
dbpsk_demod__differentially_coherent_detection_of_differentially_encoded_psk(gr.hier_block):
+    def __init__(self, fg, samples_per_symbol, excess_bw=0.35,
+                 costas_alpha=0.005, gain_mu=0.05, mu=0.5,
                  gray_code=True, verbose=True, debug=False):
         """
-       Hierarchical block for RRC-filtered BPSK demodulation
+       Hierarchical block for RRC-filtered dBPSK demodulation
 
        The input is the complex modulated signal at baseband.
        The output is a stream of bits packed 1 bit per byte (LSB)
 
        @param fg: flow graph
        @type fg: flow graph
-       @param spb: samples per baud >= 2
-       @type spb: float
+       @param samples_per_symbol: samples per baud >= 2
+       @type samples_per_symbol: float
        @param excess_bw: Root-raised cosine filter excess bandwidth
        @type excess_bw: float
         @param costas_alpha: loop filter gain
@@ -177,16 +185,16 @@
         @type debug: bool
        """
         
-        self.fg = fg
-        self.spb = spb
-        self.excess_bw = excess_bw
-        self.costas_alpha = costas_alpha
-        self.gain_mu = gain_mu
+        self._fg = fg
+        self._samples_per_symbol = samples_per_symbol
+        self._excess_bw = excess_bw
+        self._costas_alpha = costas_alpha
+        self._gain_mu = gain_mu
         
-        if spb < 2:
-            raise TypeError, "sbp must be >= 2, is %d" % sbp
+        if samples_per_symbol < 2:
+            raise TypeError, "samples_per_symbol must be >= 2, is %r" % 
(samples_per_symbol,)
 
-        arity = pow(2,self.bits_per_baud())
+        arity = pow(2,self.bits_per_symbol())
 
         # Automatic gain control
         self.preamp = gr.multiply_const_cc(10e-5)
@@ -195,28 +203,28 @@
         # Costas loop (carrier tracking)
         # FIXME: need to decide how to handle this more generally; do we pull 
it from higher layer?
         costas_order = 2
-        self.costas_alpha *= 15   # 2nd order loop needs more gain
+        self._costas_alpha *= 15   # 2nd order loop needs more gain
         beta = .25 * costas_alpha * costas_alpha
-        self.costas_loop = gr.costas_loop_cc(self.costas_alpha, beta, 0.5, 
-0.5, costas_order)
+        self.costas_loop = gr.costas_loop_cc(self._costas_alpha, beta, 0.5, 
-0.5, costas_order)
 
         # RRC data filter
-        ntaps = 11 * self.spb
+        ntaps = 11 * self._samples_per_symbol
         self.rrc_taps = gr.firdes.root_raised_cosine(
-            1.0,                # gain 
-            spb,                # sampling rate
-            1.0,                # symbol rate
-            self.excess_bw,     # excess bandwidth (roll-off factor)
+            1.0,                      # gain 
+            self._samples_per_symbol, # sampling rate
+            1.0,                      # symbol rate
+            self._excess_bw,          # excess bandwidth (roll-off factor)
             ntaps)
 
         self.rrc_filter=gr.fir_filter_ccf(1, self.rrc_taps)
 
         # symbol clock recovery
-        omega = spb
-        gain_omega = .25 * self.gain_mu * self.gain_mu
+        omega = self._samples_per_symbol
+        gain_omega = .25 * self._gain_mu * self._gain_mu
         omega_rel_limit = 0.5
         mu = 0.05
         self.clock_recovery=gr.clock_recovery_mm_cc(omega, gain_omega,
-                                                    mu, self.gain_mu,
+                                                    mu, self._gain_mu,
                                                     omega_rel_limit)
 
         # find closest constellation point
@@ -232,81 +240,83 @@
         self.gray_decoder = gr.map_bb(psk.gray_to_binary[arity])
         
         # unpack the k bit vector into a stream of bits
-        self.unpack = gr.unpack_k_bits_bb(self.bits_per_baud())
+        self.unpack = gr.unpack_k_bits_bb(self.bits_per_symbol())
 
         if verbose:
-            self.verbose()
+            self._print_verbage()
 
         if debug:
-            self.debug()
+            self._enable_logging()
 
         # Connect and Initialize base class
-        self.fg.connect(self.preamp, self.agc, self.costas_loop, 
self.rrc_filter, self.clock_recovery,
-                        self.diffdec, self.slicer, self.gray_decoder, 
self.unpack)
-        #self.fg.connect(self.preamp, self.agc, self.costas_loop, 
self.rrc_filter, self.clock_recovery,
-        #           self.slicer, self.diffdec, self.gray_decoder, self.unpack)
-        gr.hier_block.__init__(self, self.fg, self.preamp, self.unpack)
+        self._fg.connect(self.preamp, self.agc, self.costas_loop, 
self.rrc_filter, self.clock_recovery,
+                         self.diffdec, self.slicer, self.gray_decoder, 
self.unpack)
+        gr.hier_block.__init__(self, self._fg, self.preamp, self.unpack)
 
     def samples_per_symbol(self):
-        return self.spb
+        return self._samples_per_symbol
 
-    def bits_per_baud(self=None):   # staticmethod that's also callable on an 
instance
+    def bits_per_symbol(self=None):   # staticmethod that's also callable on 
an instance
         return 1
-    bits_per_baud = staticmethod(bits_per_baud)      # make it a static 
method.  RTFM
+    bits_per_symbol = staticmethod(bits_per_symbol)      # make it a static 
method.  RTFM
 
-    def verbose(self):
-        print "bits per symbol = %d"         % self.bits_per_baud()
-        print "RRC roll-off factor = %.2f"  % self.excess_bw
-        print "Costas Loop alpha = %.5f"     % self.costas_alpha
-        print "M&M symbol sync gain  = %.5f" % self.gain_mu
+    def _print_verbage(self):
+        print "bits per symbol = %d"         % self.bits_per_symbol()
+        print "RRC roll-off factor = %.2f"   % self._excess_bw
+        print "Costas Loop alpha = %.5f"     % self._costas_alpha
+        print "M&M symbol sync gain  = %.5f" % self._gain_mu
 
-    def debug(self):
-        print "Modulation debugging turned on."
-        self.fg.connect(self.agc,
+    def _setup_logging(self):
+        print "Modulation logging turned on."
+        self._fg.connect(self.agc,
                         gr.file_sink(gr.sizeof_gr_complex, "agc.dat"))
-        self.fg.connect(self.costas_loop,
+        self._fg.connect(self.costas_loop,
                         gr.file_sink(gr.sizeof_gr_complex, "costas_loop.dat"))
-        self.fg.connect(self.rrc_filter,
+        self._fg.connect(self.rrc_filter,
                         gr.file_sink(gr.sizeof_gr_complex, "rrc.dat"))
-        self.fg.connect(self.clock_recovery,
+        self._fg.connect(self.clock_recovery,
                         gr.file_sink(gr.sizeof_gr_complex, 
"clock_recovery.dat"))
-        self.fg.connect(self.diffdec,
+        self._fg.connect(self.diffdec,
                         gr.file_sink(gr.sizeof_gr_complex, "diffdec.dat"))     
   
-        self.fg.connect(self.slicer,
+        self._fg.connect(self.slicer,
                         gr.file_sink(gr.sizeof_char, "slicer.dat"))
-        self.fg.connect(self.gray_decoder,
+        self._fg.connect(self.gray_decoder,
                         gr.file_sink(gr.sizeof_char, "gray_decoder.dat"))
-        self.fg.connect(self.unpack,
+        self._fg.connect(self.unpack,
                         gr.file_sink(gr.sizeof_char, "unpack.dat"))
-        self.fg.connect((self.costas_loop,1),
+        self._fg.connect((self.costas_loop,1),
                         gr.file_sink(gr.sizeof_gr_complex, "costas.dat"))
         
-
-    def arguments(self=None):
-        args = {'spb':2, 'excess_bw':0.3, 'costas_alpha':0.005, 
'gain_mu':0.05, 'mu':0.5,
-                'gray_code':True, 'verbose':True, 'debug':False}
-        return args
-    arguments = staticmethod(arguments)
-
     def add_options(parser):
         """
-        Adds modulation-specific options to the standard parser
+        Adds DBPSK demodulation-specific options to the standard parser
         """
-        from optparse import OptionConflictError
-        try:
-            parser.add_option("", "--excess-bw", type="float", default=0.3,
-                              help="set RRC excess bandwith factor 
[default=%default]")
-            parser.add_option("", "--no-gray-code", action="store_false", 
default=True,
-                              help="Don't use gray coding on modulated bits 
[default=%default]")
-            parser.add_option("", "--costas-alpha", type="float", 
default=0.005,
-                              help="set Costas loop alpha value 
[default=%default]")
-            parser.add_option("", "--gain-mu", type="float", default=0.05,
-                              help="set M&M symbol sync loop gain mu value 
[default=%default]")
-            parser.add_option("", "--mu", type="float", default=0.5,
-                              help="set M&M symbol sync loop mu value 
[default=%default]")
-        except OptionConflictError:
-            pass
+        parser.add_option("", "--excess-bw", type="float", default=0.3,
+                          help="set RRC excess bandwith factor 
[default=%default] (PSK)")
+        parser.add_option("", "--no-gray-code", action="store_false", 
default=True,
+                          help="Don't use gray coding on modulated bits 
[default=%default] (PSK)")
+        parser.add_option("", "--costas-alpha", type="float", default=0.005,
+                          help="set Costas loop alpha value [default=%default] 
(PSK)")
+        parser.add_option("", "--gain-mu", type="float", default=0.05,
+                          help="set M&M symbol sync loop gain mu value 
[default=%default] (PSK)")
+        parser.add_option("", "--mu", type="float", default=0.5,
+                          help="set M&M symbol sync loop mu value 
[default=%default] (PSK)")
     add_options=staticmethod(add_options)
     
-dbpsk_demod = dbpsk_demod__coherent_detection_of_differentially_encoded_psk
+    def extract_kwargs_from_options(options):
+        """
+        Given command line options, create dictionary suitable for passing to 
__init__
+        """
+        return modulation_utils.extract_kwargs_from_options(
+                 
dbpsk_demod__differentially_coherent_detection_of_differentially_encoded_psk.__init__,
+                 ('self', 'fg'), options)
+    extract_kwargs_from_options=staticmethod(extract_kwargs_from_options)
 
+
+dbpsk_demod = 
dbpsk_demod__differentially_coherent_detection_of_differentially_encoded_psk
+
+#
+# Add these to the mod/demod registry
+#
+modulation_utils.add_type_1_mod('dbpsk', dbpsk_mod)
+modulation_utils.add_type_1_demod('dbpsk', dbpsk_demod)

Modified: 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/gmsk.py
===================================================================
--- 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/gmsk.py
      2006-09-18 20:14:32 UTC (rev 3563)
+++ 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/gmsk.py
      2006-09-18 20:15:04 UTC (rev 3564)
@@ -25,6 +25,7 @@
 # See gnuradio-examples/python/gmsk2 for examples
 
 from gnuradio import gr
+from gnuradio import modulation_utils
 from math import pi
 import Numeric
 from pprint import pprint
@@ -103,6 +104,21 @@
     bits_per_symbol = staticmethod(bits_per_symbol)      # make it a static 
method.
 
 
+    def _print_verbage(self):
+        print "bits per symbol = %d" % self.bits_per_symbol()
+        print "Gaussian filter bt = %.2f" % self._bt
+
+
+    def _setup_logging(self):
+        print "Modulation logging turned on."
+        self._fg.connect(self.nrz,
+                         gr.file_sink(gr.sizeof_float, "nrz.dat"))
+        self._fg.connect(self.gaussian_filter,
+                         gr.file_sink(gr.sizeof_float, "gaussian_filter.dat"))
+        self._fg.connect(self.fmmod,
+                         gr.file_sink(gr.sizeof_gr_complex, "fmmod.dat"))
+
+
     def add_options(parser):
         """
         Adds GMSK modulation-specific options to the standard parser
@@ -112,38 +128,16 @@
     add_options=staticmethod(add_options)
 
 
-    # FIXME factor out the common part and put into another file
     def extract_kwargs_from_options(options):
         """
         Given command line options, create dictionary suitable for passing to 
__init__
         """
-        args, varargs, varkw, defaults = inspect.getargspec(gmsk_mod.__init__)
-        assert(args[0] == 'self')
-        assert(args[1] == 'fg')
-        d = {}
-        for kw in args[2:]:
-            if hasattr(options, kw):
-                d[kw] = getattr(options, kw)
-        return d
+        return modulation_utils.extract_kwargs_from_options(gmsk_mod.__init__,
+                                                            ('self', 'fg'), 
options)
     extract_kwargs_from_options=staticmethod(extract_kwargs_from_options)
 
 
-    def _print_verbage(self):
-        print "bits per symbol = %d" % self.bits_per_symbol()
-        print "Gaussian filter bt = %.2f" % self._bt
 
-
-    def _setup_logging(self):
-        print "Modulation logging turned on."
-        self._fg.connect(self.nrz,
-                         gr.file_sink(gr.sizeof_float, "nrz.dat"))
-        self._fg.connect(self.gaussian_filter,
-                         gr.file_sink(gr.sizeof_float, "gaussian_filter.dat"))
-        self._fg.connect(self.fmmod,
-                         gr.file_sink(gr.sizeof_gr_complex, "fmmod.dat"))
-
-
-
 # /////////////////////////////////////////////////////////////////////////////
 #                            GMSK demodulator
 # /////////////////////////////////////////////////////////////////////////////
@@ -234,6 +228,26 @@
     bits_per_symbol = staticmethod(bits_per_symbol)      # make it a static 
method.
 
 
+    def _print_verbage(self):
+        print "bits per symbol = %d" % self.bits_per_symbol()
+        print "M&M clock recovery omega = %f" % self._omega
+        print "M&M clock recovery gain mu = %f" % self._gain_mu
+        print "M&M clock recovery mu = %f" % self._mu
+        print "M&M clock recovery omega rel. limit = %f" % 
self._omega_relative_limit
+        print "frequency error = %f" % self._freq_error
+
+
+    def _setup_logging(self):
+        print "Demodulation logging turned on."
+        self._fg.connect(self.agc,
+                        gr.file_sink(gr.sizeof_gr_complex, "agc.dat"))
+        self._fg.connect(self.fmdemod,
+                        gr.file_sink(gr.sizeof_float, "fmdemod.dat"))
+        self._fg.connect(self.clock_recovery,
+                        gr.file_sink(gr.sizeof_float, "clock_recovery.dat"))
+        self._fg.connect(self.slicer,
+                        gr.file_sink(gr.sizeof_char, "slicer.dat"))
+
     def add_options(parser):
         """
         Adds GMSK demodulation-specific options to the standard parser
@@ -250,36 +264,17 @@
                           help="M&M clock recovery frequency error 
[default=%default] (GMSK)")
     add_options=staticmethod(add_options)
 
-    # FIXME factor out the common part and put into another file
     def extract_kwargs_from_options(options):
         """
         Given command line options, create dictionary suitable for passing to 
__init__
         """
-        args, varargs, varkw, defaults = 
inspect.getargspec(gmsk_demod.__init__)
-        assert(args[0] == 'self')
-        assert(args[1] == 'fg')
-        d = {}
-        for kw in args[2:]:
-            if hasattr(options, kw):
-                d[kw] = getattr(options, kw)
-        return d
+        return 
modulation_utils.extract_kwargs_from_options(gmsk_demod.__init__,
+                                                            ('self', 'fg'), 
options)
     extract_kwargs_from_options=staticmethod(extract_kwargs_from_options)
 
-    def _print_verbage(self):
-        print "bits per symbol = %d" % self.bits_per_symbol()
-        print "M&M clock recovery omega = %f" % self._omega
-        print "M&M clock recovery gain mu = %f" % self._gain_mu
-        print "M&M clock recovery mu = %f" % self._mu
-        print "M&M clock recovery omega rel. limit = %f" % 
self._omega_relative_limit
-        print "frequency error = %f" % self._freq_error
 
-    def _setup_logging(self):
-        print "Demodulation logging turned on."
-        self._fg.connect(self.agc,
-                        gr.file_sink(gr.sizeof_gr_complex, "agc.dat"))
-        self._fg.connect(self.fmdemod,
-                        gr.file_sink(gr.sizeof_float, "fmdemod.dat"))
-        self._fg.connect(self.clock_recovery,
-                        gr.file_sink(gr.sizeof_float, "clock_recovery.dat"))
-        self._fg.connect(self.slicer,
-                        gr.file_sink(gr.sizeof_char, "slicer.dat"))
+#
+# Add these to the mod/demod registry
+#
+modulation_utils.add_type_1_mod('gmsk', gmsk_mod)
+modulation_utils.add_type_1_demod('gmsk', gmsk_demod)

Deleted: 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/modulators.py

Added: 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/modulation_utils.py
===================================================================
--- 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/modulation_utils.py
                           (rev 0)
+++ 
gnuradio/branches/developers/eb/digital-wip/gnuradio-core/src/python/gnuradio/modulation_utils.py
   2006-09-18 20:15:04 UTC (rev 3564)
@@ -0,0 +1,73 @@
+#
+# 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 2, 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.
+
+    @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):
+            d[kw] = getattr(options, kw)
+    return d

Modified: 
gnuradio/branches/developers/eb/digital-wip/gnuradio-examples/python/gmsk2/benchmark_rx.py
===================================================================
--- 
gnuradio/branches/developers/eb/digital-wip/gnuradio-examples/python/gmsk2/benchmark_rx.py
  2006-09-18 20:14:32 UTC (rev 3563)
+++ 
gnuradio/branches/developers/eb/digital-wip/gnuradio-examples/python/gmsk2/benchmark_rx.py
  2006-09-18 20:15:04 UTC (rev 3564)
@@ -20,7 +20,7 @@
 # Boston, MA 02110-1301, USA.
 # 
 
-from gnuradio import gr, gru, blks
+from gnuradio import gr, gru, modulation_utils
 from gnuradio import usrp
 from gnuradio import eng_notation
 from gnuradio.eng_option import eng_option
@@ -35,7 +35,7 @@
 
 #import os
 #print os.getpid()
-#raw_input('Attach and press enter')
+#raw_input('Attach and press enter: ')
 
 
 class my_graph(gr.flow_graph):
@@ -68,15 +68,17 @@
 
     # Create Options Parser:
     parser = OptionParser (option_class=eng_option, conflict_handler="resolve")
-    parser.add_option("-m", "--modulation", type="choice", 
choices=blks.demodulators.keys(),
+
+    demods = modulation_utils.type_1_demods()
+    parser.add_option("-m", "--modulation", type="choice", 
choices=demods.keys(), 
                       default='dbpsk',
                       help="Select modulation from %s [default=%%default]"
-                            % (', '.join(blks.demodulators.keys()),))
+                            % (', '.join(demods.keys()),))
 
     receive_path.add_options(parser)
 
     mod_grp = parser.add_option_group("Modulation")
-    for mod in blks.demodulators.values():
+    for mod in demods.values():
         mod.add_options(mod_grp)
 
     fusb_options.add_options(parser)
@@ -90,7 +92,7 @@
     #    options.freq *= 1e6
 
     # build the graph
-    fg = my_graph(blks.demodulators[options.modulation], rx_callback, options)
+    fg = my_graph(demods[options.modulation], rx_callback, options)
 
     r = gr.enable_realtime_scheduling()
     if r != gr.RT_OK:

Modified: 
gnuradio/branches/developers/eb/digital-wip/gnuradio-examples/python/gmsk2/benchmark_tx.py
===================================================================
--- 
gnuradio/branches/developers/eb/digital-wip/gnuradio-examples/python/gmsk2/benchmark_tx.py
  2006-09-18 20:14:32 UTC (rev 3563)
+++ 
gnuradio/branches/developers/eb/digital-wip/gnuradio-examples/python/gmsk2/benchmark_tx.py
  2006-09-18 20:15:04 UTC (rev 3564)
@@ -20,7 +20,7 @@
 # Boston, MA 02110-1301, USA.
 # 
 
-from gnuradio import gr, gru, blks
+from gnuradio import gr, gru, modulation_utils
 from gnuradio import usrp
 from gnuradio import eng_notation
 from gnuradio.eng_option import eng_option
@@ -56,10 +56,12 @@
         print "ok = %r, payload = '%s'" % (ok, payload)
 
     parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
-    parser.add_option("-m", "--modulation", type="choice", 
choices=blks.modulators.keys(),
+
+    mods = modulation_utils.type_1_mods()
+    parser.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
                       default='dbpsk',
                       help="Select modulation from %s [default=%%default]"
-                            % (', '.join(blks.modulators.keys()),))
+                            % (', '.join(mods.keys()),))
 
     parser.add_option("-s", "--size", type="eng_float", default=1500,
                       help="set packet size [default=%default]")
@@ -71,7 +73,7 @@
     transmit_path.add_options(parser)
 
     mod_grp = parser.add_option_group("Modulation")
-    for mod in blks.modulators.values():
+    for mod in mods.values():
         mod.add_options(mod_grp)
 
     fusb_options.add_options(parser)
@@ -87,7 +89,7 @@
     pkt_size = int(options.size)
 
     # build the graph
-    fg = my_graph(blks.modulators[options.modulation], options)
+    fg = my_graph(mods[options.modulation], options)
 
     r = gr.enable_realtime_scheduling()
     if r != gr.RT_OK:
@@ -110,9 +112,7 @@
         
     send_pkt(eof=True)
     fg.wait()                       # wait for it to finish
-    fg.txpath.set_auto_tr(False)
 
-
 if __name__ == '__main__':
     try:
         main()

Modified: 
gnuradio/branches/developers/eb/digital-wip/gnuradio-examples/python/gmsk2/transmit_path.py
===================================================================
--- 
gnuradio/branches/developers/eb/digital-wip/gnuradio-examples/python/gmsk2/transmit_path.py
 2006-09-18 20:14:32 UTC (rev 3563)
+++ 
gnuradio/branches/developers/eb/digital-wip/gnuradio-examples/python/gmsk2/transmit_path.py
 2006-09-18 20:15:04 UTC (rev 3564)
@@ -42,7 +42,7 @@
 
         self._verbose            = options.verbose
         self._tx_freq            = options.tx_freq         # tranmitter's 
center frequency
-        self._gain               = options.gain            # transmitter's 
digital gain
+        self._tx_amplitude       = options.tx_amplitude    # digital amplitude 
sent to USRP
         self._tx_subdev_spec     = options.tx_subdev_spec  # daughterboard to 
use
         self._bitrate            = options.bitrate         # desired bit rate
         self._interp             = options.interp          # interpolating 
rate for the USRP (prelim)
@@ -77,12 +77,14 @@
                           msgq_limit=4,
                           pad_for_usrp=True)
 
-        # Set gains: digital and USRP
-        self.amp = gr.multiply_const_cc(self._gain)
-        print  self.subdev.gain_range()
-        self.set_gain(self.subdev.gain_range()[0])    # set max Tx gain
-        self.set_gain(0)
 
+        # Set the USRP for maximum transmit gain
+        # (Note that on the RFX cards this is a nop.)
+        self.set_gain(self.subdev.gain_range()[0])
+
+        self.amp = gr.multiply_const_cc(1)
+        self.set_tx_amplitude(self._tx_amplitude)
+
         # enable Auto Transmit/Receive switching
         self.set_auto_tr(True)
 
@@ -142,6 +144,14 @@
         self.gain = gain
         self.subdev.set_gain(gain)
 
+    def set_tx_amplitude(self, ampl):
+        """
+        Sets the transmit amplitude sent to the USRP
+        @param: ampl 0 <= ampl < 32768.  Try 8000
+        """
+        self._tx_amplitude = max(0.0, min(ampl, 32767.0))
+        self.amp.set_k(self._tx_amplitude)
+        
     def set_auto_tr(self, enable):
         """
         Turns on auto transmit/receive of USRP daughterboard (if exits; else 
ignored)
@@ -179,8 +189,8 @@
                           help="set samples/symbol [default=%default]")
         tx_grp.add_option("-i", "--interp", type="intx", default=None,
                           help="set fpga interpolation rate to INTERP 
[default=%default]")
-        tx_grp.add_option("", "--tx-gain", type="eng_float", default=100.0, 
metavar="GAIN",
-                          help="normalized transmitter gain: 0 <= GAIN <= 100 
[default=%default]")
+        tx_grp.add_option("", "--tx-amplitude", type="eng_float", 
default=12000, metavar="AMPL",
+                          help="set transmitter digital amplitude: 0 <= AMPL < 
32768 [default=%default]")
     # Make a static method to call before instantiation
     add_options = staticmethod(add_options)
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]