diff options
Diffstat (limited to 'gr-digital/python/gfsk.py')
-rw-r--r-- | gr-digital/python/gfsk.py | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/gr-digital/python/gfsk.py b/gr-digital/python/gfsk.py index c85fdf0e00..54c94b88fd 100644 --- a/gr-digital/python/gfsk.py +++ b/gr-digital/python/gfsk.py @@ -2,7 +2,7 @@ # GFSK modulation and demodulation. # # -# Copyright 2005,2006,2007 Free Software Foundation, Inc. +# Copyright 2005-2007,2012 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -25,6 +25,8 @@ # See gnuradio-examples/python/digital for examples from gnuradio import gr +from gnuradio import analog +from gnuradio import blocks import modulation_utils import digital_swig as digital from math import pi @@ -32,6 +34,11 @@ import numpy from pprint import pprint import inspect +try: + from gnuradio import filter +except ImportError: + import filter_swig as filter + # default values (used in __init__ and add_options) _def_samples_per_symbol = 2 _def_sensitivity = 1 @@ -68,14 +75,11 @@ class gfsk_mod(gr.hier_block2): 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 + Args: + samples_per_symbol: samples per baud >= 2 (integer) + bt: Gaussian filter bandwidth * symbol time (float) + verbose: Print information about modulator? (bool) + debug: Print modualtion data to files? (bool) """ gr.hier_block2.__init__(self, "gfsk_mod", @@ -94,11 +98,13 @@ class gfsk_mod(gr.hier_block2): #sensitivity = (pi / 2) / samples_per_symbol # phase change per bit = pi / 2 # Turn it into NRZ data. - self.nrz = gr.bytes_to_syms() + #self.nrz = digital.bytes_to_syms() + self.unpack = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) + self.nrz = digital.chunks_to_symbols_bf([-1, 1]) # Form Gaussian filter # Generate Gaussian response (Needs to be convolved with window below). - self.gaussian_taps = gr.firdes.gaussian( + self.gaussian_taps = filter.firdes.gaussian( 1.0, # gain samples_per_symbol, # symbol_rate bt, # bandwidth * symbol time @@ -107,13 +113,13 @@ class gfsk_mod(gr.hier_block2): self.sqwave = (1,) * samples_per_symbol # rectangular window self.taps = numpy.convolve(numpy.array(self.gaussian_taps),numpy.array(self.sqwave)) - self.gaussian_filter = gr.interp_fir_filter_fff(samples_per_symbol, self.taps) + self.gaussian_filter = filter.interp_fir_filter_fff(samples_per_symbol, self.taps) # FM modulation - self.fmmod = gr.frequency_modulator_fc(sensitivity) + self.fmmod = frequency.frequency_modulator_fc(sensitivity) # small amount of output attenuation to prevent clipping USRP sink - self.amp = gr.multiply_const_cc(0.999) + self.amp = blocks.multiply_const_cc(0.999) if verbose: self._print_verbage() @@ -122,7 +128,7 @@ class gfsk_mod(gr.hier_block2): self._setup_logging() # Connect & Initialize base class - self.connect(self, self.nrz, self.gaussian_filter, self.fmmod, self.amp, self) + self.connect(self, self.unpack, self.nrz, self.gaussian_filter, self.fmmod, self.amp, self) def samples_per_symbol(self): return self._samples_per_symbol @@ -140,11 +146,11 @@ class gfsk_mod(gr.hier_block2): def _setup_logging(self): print "Modulation logging turned on." self.connect(self.nrz, - gr.file_sink(gr.sizeof_float, "nrz.dat")) + blocks.file_sink(gr.sizeof_float, "nrz.dat")) self.connect(self.gaussian_filter, - gr.file_sink(gr.sizeof_float, "gaussian_filter.dat")) + blocks.file_sink(gr.sizeof_float, "gaussian_filter.dat")) self.connect(self.fmmod, - gr.file_sink(gr.sizeof_gr_complex, "fmmod.dat")) + blocks.file_sink(gr.sizeof_gr_complex, "fmmod.dat")) def add_options(parser): @@ -188,23 +194,19 @@ class gfsk_demod(gr.hier_block2): 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 + Args: + samples_per_symbol: samples per baud (integer) + verbose: Print information about modulator? (bool) + log: Print modualtion data to files? (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 + Args: + gain_mu: controls rate of mu adjustment (float) + mu: fractional delay [0.0, 1.0] (float) + omega_relative_limit: sets max variation in omega (float, typically 0.000200 (200 ppm)) + freq_error: bit rate error as a fraction + float: """ gr.hier_block2.__init__(self, "gfsk_demod", @@ -230,7 +232,7 @@ class gfsk_demod(gr.hier_block2): # Demodulate FM #sensitivity = (pi / 2) / samples_per_symbol - self.fmdemod = gr.quadrature_demod_cf(1.0 / sensitivity) + self.fmdemod = analog.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) @@ -270,11 +272,11 @@ class gfsk_demod(gr.hier_block2): def _setup_logging(self): print "Demodulation logging turned on." self.connect(self.fmdemod, - gr.file_sink(gr.sizeof_float, "fmdemod.dat")) + blocks.file_sink(gr.sizeof_float, "fmdemod.dat")) self.connect(self.clock_recovery, - gr.file_sink(gr.sizeof_float, "clock_recovery.dat")) + blocks.file_sink(gr.sizeof_float, "clock_recovery.dat")) self.connect(self.slicer, - gr.file_sink(gr.sizeof_char, "slicer.dat")) + blocks.file_sink(gr.sizeof_char, "slicer.dat")) def add_options(parser): """ |