[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r4442 - gnuradio/branches/developers/jcorgan/dect/gnur
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r4442 - gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect |
Date: |
Sun, 11 Feb 2007 02:30:44 -0700 (MST) |
Author: jcorgan
Date: 2007-02-11 02:30:44 -0700 (Sun, 11 Feb 2007)
New Revision: 4442
Added:
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/gmsk2.py
Modified:
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/README
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/dect_receiver.py
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/usrp_dect.py
Log:
Work in progress. Added GMSK demodulator and option to log to file.
Modified:
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/README
===================================================================
---
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/README
2007-02-11 07:44:21 UTC (rev 4441)
+++
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/README
2007-02-11 09:30:44 UTC (rev 4442)
@@ -5,12 +5,15 @@
Status
------
+2007 Feb 11 - Added GMSK demodulation and option to log to file
2007 Feb 10 - Able to tune and log filtered baseband to file
Files
-----
+usrp_dect.py - DECT receiver application
+
dect_receiver.py - Top-level hierarchical block (new type) implementing
receiver
@@ -18,9 +21,10 @@
complex source, with convenience functions for tuning,
gain, decimation, etc.
-usrp_dect.py - DECT receiver application
+gmsk2.py - Hierarchical block (new type) implementing GMSK
+ modulation and demodulation. This will eventually go
+ into the core blksimpl directory
-
DECT Modulation Details
-----------------------
Modified:
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/dect_receiver.py
===================================================================
---
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/dect_receiver.py
2007-02-11 07:44:21 UTC (rev 4441)
+++
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/dect_receiver.py
2007-02-11 09:30:44 UTC (rev 4442)
@@ -22,7 +22,10 @@
from gnuradio import gr, optfir
from usrp_source import usrp_source_c
+from gmsk2 import gmsk2_demod
+_dect_symbol_rate = 1.152e6
+
# Top-level hierarchical block that implements DECT demodulation and
# decoding.
class dect_receiver(gr.hier_block2):
@@ -33,8 +36,9 @@
gr.io_signature(0,0,0)) # Output signature
self._options = options
- # Get 2 MHz swath at channel frequency
- if_rate = 2e6
+ # Need greater than 2 samples per symbol. This makes a decimation
+ # rate of 26 and a samples per symbol of 2.136752
+ if_rate = 2.461538e6
self._usrp = usrp_source_c(self,
which=0,
subdev_spec=options.rx_subdev_spec,
@@ -56,19 +60,30 @@
self._channel_filter = gr.freq_xlating_fir_filter_ccf(1, #
Decimation rate
chan_taps, #
Filter taps
0.0, #
Offset frequency
- 2e6) #
Sample rate
+ if_rate) #
Sample rate
+ self._demod = gmsk2_demod(samples_per_symbol=if_rate/_dect_symbol_rate,
+ verbose=options.verbose)
+
+ # Define and connect components
+ self.define_component("usrp", self._usrp)
+ self.define_component("channel", self._channel_filter)
+ self.define_component("demod", self._demod)
+ self.define_component("sink", gr.null_sink(gr.sizeof_char))
+ self.connect("usrp", 0, "channel", 0)
+ self.connect("channel", 0, "demod", 0)
+ self.connect("demod", 0, "sink", 0)
+
# Log baseband to file if requested
if options.log_baseband is not None:
- self._sink = gr.file_sink(gr.sizeof_gr_complex,
options.log_baseband)
if options.verbose:
print "Logging baseband to file", options.log_baseband
- else:
- self._sink = gr.null_sink(gr.sizeof_gr_complex)
+ self.define_component("baseband_log",
gr.file_sink(gr.sizeof_gr_complex, options.log_baseband))
+ self.connect("channel", 0, "baseband_log", 0)
- self.define_component("usrp", self._usrp)
- self.define_component("channel", self._channel_filter)
- self.define_component("sink", self._sink)
-
- self.connect("usrp", 0, "channel", 0)
- self.connect("channel", 0, "sink", 0)
+ # Log demodulator output to file if requested
+ if options.log_demod is not None:
+ if options.verbose:
+ print "Logging demodulator to file", options.log_demod
+ self.define_component("demod_log", gr.file_sink(gr.sizeof_char,
options.log_demod))
+ self.connect("demod", 0, "demod_log", 0)
Copied:
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/gmsk2.py
(from rev 4429,
gnuradio/branches/developers/jcorgan/dect/gnuradio-core/src/python/gnuradio/blksimpl/gmsk.py)
===================================================================
---
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/gmsk2.py
(rev 0)
+++
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/gmsk2.py
2007-02-11 09:30:44 UTC (rev 4442)
@@ -0,0 +1,300 @@
+#
+# GMSK modulation and demodulation.
+#
+#
+# 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 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 GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+# See gnuradio-examples/python/digital for examples
+
+from gnuradio import gr
+from gnuradio import modulation_utils
+from math import pi
+import Numeric
+from pprint import pprint
+import inspect
+
+# default values (used in __init__ and add_options)
+_def_samples_per_symbol = 2
+_def_bt = 0.35
+_def_verbose = False
+_def_log = False
+
+_def_gain_mu = 0.05
+_def_mu = 0.5
+_def_freq_error = 0.0
+_def_omega_relative_limit = 0.005
+
+
+# /////////////////////////////////////////////////////////////////////////////
+# GMSK modulator
+# /////////////////////////////////////////////////////////////////////////////
+
+class gmsk2_mod(gr.hier_block2):
+
+ def __init__(self,
+ samples_per_symbol=_def_samples_per_symbol,
+ bt=_def_bt,
+ verbose=_def_verbose,
+ log=_def_log):
+ """
+ Hierarchical block for Gaussian Minimum Shift Key (GMSK)
+ modulation.
+
+ The input is a byte stream (unsigned char) and the
+ output is the complex modulated signal at baseband.
+
+ @param samples_per_symbol: samples per baud >= 2
+ @type samples_per_symbol: integer
+ @param bt: Gaussian filter bandwidth * symbol time
+ @type bt: float
+ @param verbose: Print information about modulator?
+ @type verbose: bool
+ @param debug: Print modualtion data to files?
+ @type debug: bool
+ """
+ gr.hier_block2.__init__(self,
+ "gmsk2_mod", #
Block typename
+ gr.io_signature(1,1,gr.sizeof_char), #
Input signature
+ gr.io_signature(1,1,gr.sizeof_gr_complex)) #
Output signature
+
+ self._samples_per_symbol = samples_per_symbol
+ self._bt = bt
+
+ if not isinstance(samples_per_symbol, int) or samples_per_symbol < 2:
+ raise TypeError, ("samples_per_symbol must be an integer >= 2, is
%r" % (samples_per_symbol,))
+
+ ntaps = 4 * samples_per_symbol # up to 3 bits in
filter at once
+ sensitivity = (pi / 2) / samples_per_symbol # phase change per bit
= pi / 2
+
+ # Turn it into NRZ data.
+ self.nrz = gr.bytes_to_syms()
+
+ # Form Gaussian filter
+ # Generate Gaussian response (Needs to be convolved with window below).
+ self.gaussian_taps = gr.firdes.gaussian(
+ 1, # gain
+ samples_per_symbol, # symbol_rate
+ bt, # bandwidth * symbol time
+ ntaps # number of taps
+ )
+
+ self.sqwave = (1,) * samples_per_symbol # rectangular window
+ self.taps =
Numeric.convolve(Numeric.array(self.gaussian_taps),Numeric.array(self.sqwave))
+ self.gaussian_filter = gr.interp_fir_filter_fff(samples_per_symbol,
self.taps)
+
+ # FM modulation
+ self.fmmod = gr.frequency_modulator_fc(sensitivity)
+
+ if verbose:
+ self._print_verbage()
+
+ # Define and connect components
+ self.define_component("nrz", self.nrz)
+ self.define_component("filter", self.gaussian_filter)
+ self.define_component("fmmod", self.fmmod)
+ self.connect("self", 0, "nrz", 0)
+ self.connect("nrz", 0, "filter", 0)
+ self.connect("filter", 0, "fmmod", 0)
+ self.connect("fmmod", 0, "self", 0)
+
+ if log:
+ self._setup_logging()
+
+ def samples_per_symbol(self):
+ return self._samples_per_symbol
+
+ def bits_per_symbol(self=None): # staticmethod that's also callable on
an instance
+ return 1
+ 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.define_component("nrz_log", gr.file_sink(gr.sizeof_float,
"nrz.dat"))
+ self.define_component("filter_log", gr.file_sink(gr.sizeof_float,
"gaussian_filter.dat"))
+ self.define_component("fmmod_log", gr.file_sink(gr.sizeof_gr_complex,
"fmmod.dat"))
+ self.connect("nrz", 0, "nrz_log", 0)
+ self.connect("filter", 0, "filter_log", 0)
+ self.connect("fmmod", 0, "fmmod_log", 0)
+
+ def add_options(parser):
+ """
+ Adds GMSK modulation-specific options to the standard parser
+ """
+ parser.add_option("", "--bt", type="float", default=_def_bt,
+ help="set bandwidth-time product [default=%default]
(GMSK)")
+ add_options=staticmethod(add_options)
+
+ # FIXME: figure out what has to change for gr.hier_block2 version
+ #def extract_kwargs_from_options(options):
+ # """
+ # Given command line options, create dictionary suitable for passing to
__init__
+ # """
+ # return modulation_utils.extract_kwargs_from_options(gmsk_mod.__init__,
+ # ('self', 'fg'),
options)
+ #extract_kwargs_from_options=staticmethod(extract_kwargs_from_options)
+
+
+# /////////////////////////////////////////////////////////////////////////////
+# GMSK demodulator
+# /////////////////////////////////////////////////////////////////////////////
+
+class gmsk2_demod(gr.hier_block2):
+
+ def __init__(self,
+ samples_per_symbol=_def_samples_per_symbol,
+ gain_mu=_def_gain_mu,
+ mu=_def_mu,
+ omega_relative_limit=_def_omega_relative_limit,
+ freq_error=_def_freq_error,
+ verbose=_def_verbose,
+ log=_def_log):
+ """
+ Hierarchical block for Gaussian Minimum Shift Key (GMSK)
+ demodulation.
+
+ The input is the complex modulated signal at baseband.
+ The output is a stream of bits packed 1 bit per byte (the LSB)
+
+ @param samples_per_symbol: samples per baud
+ @type samples_per_symbol: integer
+ @param verbose: Print information about modulator?
+ @type verbose: bool
+ @param log: Print modualtion data to files?
+ @type log: bool
+
+ Clock recovery parameters. These all have reasonble defaults.
+
+ @param gain_mu: controls rate of mu adjustment
+ @type gain_mu: float
+ @param mu: fractional delay [0.0, 1.0]
+ @type mu: float
+ @param omega_relative_limit: sets max variation in omega
+ @type omega_relative_limit: float, typically 0.000200 (200 ppm)
+ @param freq_error: bit rate error as a fraction
+ @param float
+ """
+
+ gr.hier_block2.__init__(self,
+ "gmsk2_demod", #
Block typename
+ gr.io_signature(1,1,gr.sizeof_gr_complex), #
Input signature
+ gr.io_signature(1,1,gr.sizeof_char)) #
Output signature
+
+ self._samples_per_symbol = samples_per_symbol
+ self._gain_mu = gain_mu
+ self._mu = mu
+ self._omega_relative_limit = omega_relative_limit
+ self._freq_error = freq_error
+
+ if samples_per_symbol < 2:
+ raise TypeError, "samples_per_symbol >= 2, is %f" %
samples_per_symbol
+
+ self._omega = samples_per_symbol*(1+self._freq_error)
+
+ self._gain_omega = .25 * self._gain_mu * self._gain_mu #
critically damped
+
+ # Demodulate FM
+ sensitivity = (pi / 2) / samples_per_symbol
+ self.fmdemod = gr.quadrature_demod_cf(1.0 / sensitivity)
+
+ # the clock recovery block tracks the symbol clock and resamples as
needed.
+ # the output of the block is a stream of soft symbols (float)
+ self.clock_recovery = gr.clock_recovery_mm_ff(self._omega,
self._gain_omega,
+ self._mu, self._gain_mu,
+
self._omega_relative_limit)
+
+ # slice the floats at 0, outputting 1 bit (the LSB of the output byte)
per sample
+ self.slicer = gr.binary_slicer_fb()
+
+ if verbose:
+ self._print_verbage()
+
+ # Define and connect components
+ self.define_component("fmdemod", self.fmdemod)
+ self.define_component("clock_recovery", self.clock_recovery)
+ self.define_component("slicer", self.slicer)
+ self.connect("self", 0, "fmdemod", 0)
+ self.connect("fmdemod", 0, "clock_recovery", 0)
+ self.connect("clock_recovery", 0, "slicer", 0)
+ self.connect("slicer", 0, "self", 0)
+
+ if log:
+ self._setup_logging()
+
+ def samples_per_symbol(self):
+ return self._samples_per_symbol
+
+ def bits_per_symbol(self=None): # staticmethod that's also callable on
an instance
+ return 1
+ 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.define_component("fmdemod_log", gr.file_sink(gr.sizeof_float,
"fmdemod.dat"))
+ self.define_component("clock_recovery_log",
gr.file_sink(gr.sizeof_float, "clock_recovery.dat"))
+ self.define_component("slicer_log", gr.file_sink(gr.sizeof_char,
"slicer.dat"))
+ self.connect("fmdemod", 0, "fmdemod_log", 0)
+ self.connect("clock_recovery", 0, "clock_recovery_log", 0)
+ self.connect("slicer", 0, "slicer_log", 0)
+
+ def add_options(parser):
+ """
+ Adds GMSK demodulation-specific options to the standard parser
+ """
+ parser.add_option("", "--gain-mu", type="float", default=_def_gain_mu,
+ help="M&M clock recovery gain mu [default=%default]
(GMSK/PSK)")
+ parser.add_option("", "--mu", type="float", default=_def_mu,
+ help="M&M clock recovery mu [default=%default]
(GMSK/PSK)")
+ parser.add_option("", "--omega-relative-limit", type="float",
default=_def_omega_relative_limit,
+ help="M&M clock recovery omega relative limit
[default=%default] (GMSK/PSK)")
+ parser.add_option("", "--freq-error", type="float",
default=_def_freq_error,
+ help="M&M clock recovery frequency error
[default=%default] (GMSK)")
+ add_options=staticmethod(add_options)
+
+ # FIXME: figure out what this is for gr.hier_block2 version
+ #def extract_kwargs_from_options(options):
+ # """
+ # Given command line options, create dictionary suitable for passing to
__init__
+ # """
+ # return
modulation_utils.extract_kwargs_from_options(gmsk_demod.__init__,
+ # ('self', 'fg'),
options)
+ #extract_kwargs_from_options=staticmethod(extract_kwargs_from_options)
+
+#
+# Add these to the mod/demod registry
+#
+modulation_utils.add_type_1_mod('gmsk2', gmsk2_mod)
+modulation_utils.add_type_1_demod('gmsk2', gmsk2_demod)
Modified:
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/usrp_dect.py
===================================================================
---
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/usrp_dect.py
2007-02-11 07:44:21 UTC (rev 4441)
+++
gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect/usrp_dect.py
2007-02-11 09:30:44 UTC (rev 4442)
@@ -39,7 +39,9 @@
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="print extra debugging info")
parser.add_option("", "--log-baseband", default=None,
- help="log filtered basedband to file")
+ help="log filtered baseband to file")
+ parser.add_option("", "--log-demod", default=None,
+ help="log demodulator output to file")
(options, args) = parser.parse_args()
if len(sys.argv) == 1 or len(args) != 0:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r4442 - gnuradio/branches/developers/jcorgan/dect/gnuradio-examples/python/dect,
jcorgan <=