summaryrefslogtreecommitdiff
path: root/gr-digital/python/digital
diff options
context:
space:
mode:
Diffstat (limited to 'gr-digital/python/digital')
-rw-r--r--gr-digital/python/digital/CMakeLists.txt2
-rw-r--r--gr-digital/python/digital/__init__.py66
-rw-r--r--gr-digital/python/digital/bpsk.py7
-rw-r--r--gr-digital/python/digital/constellation_map_generator.py1
-rw-r--r--gr-digital/python/digital/cpm.py121
-rw-r--r--gr-digital/python/digital/crc.py13
-rw-r--r--gr-digital/python/digital/generic_mod_demod.py68
-rw-r--r--gr-digital/python/digital/gfsk.py167
-rw-r--r--gr-digital/python/digital/gmsk.py135
-rw-r--r--gr-digital/python/digital/modulation_utils.py1
-rw-r--r--gr-digital/python/digital/ofdm.py109
-rw-r--r--gr-digital/python/digital/ofdm_packet_utils.py31
-rw-r--r--gr-digital/python/digital/ofdm_receiver.py58
-rw-r--r--gr-digital/python/digital/ofdm_sync_fixed.py1
-rw-r--r--gr-digital/python/digital/ofdm_sync_ml.py50
-rw-r--r--gr-digital/python/digital/ofdm_sync_pn.py31
-rw-r--r--gr-digital/python/digital/ofdm_sync_pnac.py31
-rw-r--r--gr-digital/python/digital/ofdm_txrx.py27
-rw-r--r--gr-digital/python/digital/packet_utils.py52
-rw-r--r--gr-digital/python/digital/pkt.py64
-rw-r--r--gr-digital/python/digital/psk.py32
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/psk_constellations.py4
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_binary_slicer_fb.py20
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_burst_shaper.py9
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_chunks_to_symbols.py7
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_clock_recovery_mm.py1
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_cma_equalizer.py37
-rw-r--r--gr-digital/python/digital/qa_constellation.py18
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_constellation_decoder_cb.py30
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_constellation_receiver.py31
-rw-r--r--gr-digital/python/digital/qa_constellation_soft_decoder_cf.py13
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_correlate_access_code.py3
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_correlate_access_code_XX_ts.py5
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_correlate_access_code_tag.py3
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_costas_loop_cc.py12
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_cpm.py1
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_crc32.py1
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_crc32_bb.py13
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_diff_encoder.py1
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_diff_phasor_cc.py1
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_digital.py1
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_fll_band_edge.py4
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_framer_sink.py3
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_glfsr_source.py19
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_hdlc_framer.py5
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_header_payload_demux.py29
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_lfsr.py3
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_lms_equalizer.py37
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_map.py3
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_mpsk_snr_est.py19
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py17
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_ofdm_chanest_vcvc.py10
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_ofdm_cyclic_prefixer.py16
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_ofdm_frame_equalizer_vcvc.py18
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_ofdm_serializer_vcc.py26
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_ofdm_sync_sc_cfb.py28
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_ofdm_txrx.py1
-rw-r--r--gr-digital/python/digital/qa_packet_format.py19
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_packet_headergenerator_bb.py1
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_packet_headerparser_b.py11
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_pfb_clock_sync.py18
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_pn_correlator_cc.py1
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_probe_density.py4
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_scrambler.py5
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_simple_correlator.py1
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qa_simple_framer.py1
-rw-r--r--gr-digital/python/digital/qam.py77
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/qam_constellations.py11
-rw-r--r--gr-digital/python/digital/qamlike.py19
-rw-r--r--gr-digital/python/digital/qpsk.py8
-rw-r--r--gr-digital/python/digital/soft_dec_lut_gen.py19
-rw-r--r--[-rwxr-xr-x]gr-digital/python/digital/test_soft_decisions.py35
-rw-r--r--gr-digital/python/digital/utils/alignment.py12
-rw-r--r--gr-digital/python/digital/utils/gray_code.py16
-rw-r--r--gr-digital/python/digital/utils/mod_codes.py1
-rw-r--r--gr-digital/python/digital/utils/tagged_streams.py23
76 files changed, 949 insertions, 849 deletions
diff --git a/gr-digital/python/digital/CMakeLists.txt b/gr-digital/python/digital/CMakeLists.txt
index 8f88948a2e..e9d58491c4 100644
--- a/gr-digital/python/digital/CMakeLists.txt
+++ b/gr-digital/python/digital/CMakeLists.txt
@@ -78,6 +78,6 @@ if(ENABLE_TESTING)
file(GLOB py_qa_test_files "qa_*.py")
foreach(py_qa_test_file ${py_qa_test_files})
get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE)
- GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} ${PYTHON_DASH_B} ${py_qa_test_file})
+ GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} -B ${py_qa_test_file})
endforeach(py_qa_test_file)
endif(ENABLE_TESTING)
diff --git a/gr-digital/python/digital/__init__.py b/gr-digital/python/digital/__init__.py
index 79b740644d..90aa413a25 100644
--- a/gr-digital/python/digital/__init__.py
+++ b/gr-digital/python/digital/__init__.py
@@ -1,59 +1,63 @@
# Copyright 2011-2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
'''
Blocks and utilities for digital modulation and demodulation.
'''
+from __future__ import absolute_import
+from __future__ import unicode_literals
+
# The presence of this file turns this directory into a Python package
import os
try:
- from digital_swig import *
+ from .digital_swig import *
except ImportError:
dirname, filename = os.path.split(os.path.abspath(__file__))
__path__.append(os.path.join(dirname, "..", "..", "swig"))
- from digital_swig import *
-from psk import *
-from qam import *
-from qamlike import *
-from bpsk import *
-from qpsk import *
-from gmsk import *
-from gfsk import *
-from cpm import *
-from pkt import *
-from crc import *
-from modulation_utils import *
-from ofdm import *
-from ofdm_receiver import *
-from ofdm_sync_fixed import *
-from ofdm_sync_ml import *
-from ofdm_sync_pnac import *
-from ofdm_sync_pn import *
-from ofdm_txrx import ofdm_tx, ofdm_rx
-from soft_dec_lut_gen import *
-from psk_constellations import *
-from qam_constellations import *
-from constellation_map_generator import *
+ from .digital_swig import *
+
+from .psk import *
+from .qam import *
+from .qamlike import *
+from .bpsk import *
+from .qpsk import *
+from .gmsk import *
+from .gfsk import *
+from .cpm import *
+from .pkt import *
+from .crc import *
+from .modulation_utils import *
+from .ofdm import *
+from .ofdm_receiver import *
+from .ofdm_sync_fixed import *
+from .ofdm_sync_ml import *
+from .ofdm_sync_pnac import *
+from .ofdm_sync_pn import *
+from .ofdm_txrx import ofdm_tx, ofdm_rx
+from .soft_dec_lut_gen import *
+from .psk_constellations import *
+from .qam_constellations import *
+from .constellation_map_generator import *
-import packet_utils
-import ofdm_packet_utils
+from . import packet_utils
+from . import ofdm_packet_utils
diff --git a/gr-digital/python/digital/bpsk.py b/gr-digital/python/digital/bpsk.py
index 2ecaac3386..6193622be8 100644
--- a/gr-digital/python/digital/bpsk.py
+++ b/gr-digital/python/digital/bpsk.py
@@ -23,14 +23,17 @@
BPSK modulation and demodulation.
"""
+from __future__ import absolute_import
+from __future__ import unicode_literals
+
from math import pi, log
from cmath import exp
from gnuradio import gr
from gnuradio.digital.generic_mod_demod import generic_mod, generic_demod
from gnuradio.digital.generic_mod_demod import shared_mod_args, shared_demod_args
-import digital_swig
-import modulation_utils
+from . import digital_swig
+from . import modulation_utils
# /////////////////////////////////////////////////////////////////////////////
# BPSK constellation
diff --git a/gr-digital/python/digital/constellation_map_generator.py b/gr-digital/python/digital/constellation_map_generator.py
index 1dedd81280..bd4158194f 100644
--- a/gr-digital/python/digital/constellation_map_generator.py
+++ b/gr-digital/python/digital/constellation_map_generator.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import unicode_literals
def constellation_map_generator(basis_cpoints, basis_symbols, k, pi):
'''
Uses the a basis constellation provided (e.g., from
diff --git a/gr-digital/python/digital/cpm.py b/gr-digital/python/digital/cpm.py
index 322c3f0bfc..0752f01d66 100644
--- a/gr-digital/python/digital/cpm.py
+++ b/gr-digital/python/digital/cpm.py
@@ -1,37 +1,44 @@
#
-# CPM modulation and demodulation.
+# CPM modulation and demodulation.
#
#
# Copyright 2005-2007,2011 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import unicode_literals
# See gnuradio-examples/python/digital for examples
+
+from math import pi
+import numpy
+
from gnuradio import gr, filter
from gnuradio import analog
from gnuradio import blocks
-from math import pi
-import numpy
+from . import digital_swig
+from . import modulation_utils
-import digital_swig
-import modulation_utils
# default values (used in __init__ and add_options)
_def_samples_per_symbol = 2
@@ -53,16 +60,16 @@ _def_log = False
class cpm_mod(gr.hier_block2):
"""
Hierarchical block for Continuous Phase modulation.
-
+
The input is a byte stream (unsigned char) representing packed
bits and the output is the complex modulated signal at baseband.
-
+
See Proakis for definition of generic CPM signals:
s(t)=exp(j phi(t))
phi(t)= 2 pi h int_0^t f(t') dt'
f(t)=sum_k a_k g(t-kT)
(normalizing assumption: int_0^infty g(t) dt = 1/2)
-
+
Args:
samples_per_symbol: samples per baud >= 2 (integer)
bits_per_symbol: bits per symbol (integer)
@@ -76,21 +83,21 @@ class cpm_mod(gr.hier_block2):
debug: Print modulation data to files? (boolean)
"""
- def __init__(self,
+ def __init__(self,
samples_per_symbol=_def_samples_per_symbol,
bits_per_symbol=_def_bits_per_symbol,
h_numerator=_def_h_numerator,
h_denominator=_def_h_denominator,
cpm_type=_def_cpm_type,
- bt=_def_bt,
- symbols_per_pulse=_def_symbols_per_pulse,
+ bt=_def_bt,
+ symbols_per_pulse=_def_symbols_per_pulse,
generic_taps=_def_generic_taps,
verbose=_def_verbose,
log=_def_log):
- gr.hier_block2.__init__(self, "cpm_mod",
- gr.io_signature(1, 1, gr.sizeof_char), # Input signature
- gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
+ gr.hier_block2.__init__(self, "cpm_mod",
+ 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._bits_per_symbol = bits_per_symbol
@@ -99,29 +106,29 @@ class cpm_mod(gr.hier_block2):
self._cpm_type = cpm_type
self._bt=bt
if cpm_type == 0 or cpm_type == 2 or cpm_type == 3: # CPFSK, RC, Generic
- self._symbols_per_pulse = symbols_per_pulse
+ self._symbols_per_pulse = symbols_per_pulse
elif cpm_type == 1: # GMSK
- self._symbols_per_pulse = 4
+ self._symbols_per_pulse = 4
else:
- raise TypeError, ("cpm_type must be an integer in {0,1,2,3}, is %r" % (cpm_type,))
+ raise TypeError("cpm_type must be an integer in {0,1,2,3}, is %r" % (cpm_type,))
self._generic_taps=numpy.array(generic_taps)
if samples_per_symbol < 2:
- raise TypeError, ("samples_per_symbol must be >= 2, is %r" % (samples_per_symbol,))
+ raise TypeError("samples_per_symbol must be >= 2, is %r" % (samples_per_symbol,))
self.nsymbols = 2**bits_per_symbol
self.sym_alphabet = numpy.arange(-(self.nsymbols-1),self.nsymbols,2).tolist()
- self.ntaps = int(self._symbols_per_pulse * samples_per_symbol)
- sensitivity = 2 * pi * h_numerator / h_denominator / samples_per_symbol
+ self.ntaps = int(self._symbols_per_pulse * samples_per_symbol)
+ sensitivity = 2 * pi * h_numerator / h_denominator / samples_per_symbol
# Unpack Bytes into bits_per_symbol groups
self.B2s = blocks.packed_to_unpacked_bb(bits_per_symbol,gr.GR_MSB_FIRST)
-
-
- # Turn it into symmetric PAM data.
+
+
+ # Turn it into symmetric PAM data.
self.pam = digital_swig.chunks_to_symbols_bf(self.sym_alphabet,1)
# Generate pulse (sum of taps = samples_per_symbol/2)
@@ -129,72 +136,72 @@ class cpm_mod(gr.hier_block2):
self.taps= (1.0/self._symbols_per_pulse/2,) * self.ntaps
elif cpm_type == 1: # GMSK
gaussian_taps = filter.firdes.gaussian(
- 1.0/2, # gain
+ 1.0 / 2, # gain
samples_per_symbol, # symbol_rate
bt, # bandwidth * symbol time
self.ntaps # number of taps
)
- sqwave = (1,) * samples_per_symbol # rectangular window
- self.taps = numpy.convolve(numpy.array(gaussian_taps),numpy.array(sqwave))
+ sqwave = (1,) * samples_per_symbol # rectangular window
+ self.taps = numpy.convolve(numpy.array(gaussian_taps),numpy.array(sqwave))
elif cpm_type == 2: # Raised Cosine
# generalize it for arbitrary roll-off factor
- self.taps = (1-numpy.cos(2*pi*numpy.arange(0,self.ntaps)/samples_per_symbol/self._symbols_per_pulse))/(2*self._symbols_per_pulse)
+ self.taps = (1-numpy.cos(2*pi*numpy.arange(0 / self.ntaps/samples_per_symbol/self._symbols_per_pulse)),(2*self._symbols_per_pulse))
elif cpm_type == 3: # Generic CPM
self.taps = generic_taps
else:
- raise TypeError, ("cpm_type must be an integer in {0,1,2,3}, is %r" % (cpm_type,))
+ raise TypeError("cpm_type must be an integer in {0,1,2,3}, is %r" % (cpm_type,))
self.filter = filter.pfb.arb_resampler_fff(samples_per_symbol, self.taps)
- # FM modulation
- self.fmmod = analog.frequency_modulator_fc(sensitivity)
-
+ # FM modulation
+ self.fmmod = analog.frequency_modulator_fc(sensitivity)
+
if verbose:
self._print_verbage()
-
+
if log:
self._setup_logging()
- # Connect
- self.connect(self, self.B2s, self.pam, self.filter, self.fmmod, self)
+ # Connect
+ self.connect(self, self.B2s, self.pam, self.filter, self.fmmod, self)
def samples_per_symbol(self):
return self._samples_per_symbol
-
- def bits_per_symbol(self):
+
+ def bits_per_symbol(self):
return self._bits_per_symbol
-
- def h_numerator(self):
+
+ def h_numerator(self):
return self._h_numerator
- def h_denominator(self):
+ def h_denominator(self):
return self._h_denominator
- def cpm_type(self):
+ def cpm_type(self):
return self._cpm_type
- def bt(self):
+ def bt(self):
return self._bt
- def symbols_per_pulse(self):
+ def symbols_per_pulse(self):
return self._symbols_per_pulse
def _print_verbage(self):
- print "Samples per symbol = %d" % self._samples_per_symbol
- print "Bits per symbol = %d" % self._bits_per_symbol
- print "h = " , self._h_numerator , " / " , self._h_denominator
- print "Symbol alphabet = " , self.sym_alphabet
- print "Symbols per pulse = %d" % self._symbols_per_pulse
- print "taps = " , self.taps
-
- print "CPM type = %d" % self._cpm_type
+ print("Samples per symbol = %d" % self._samples_per_symbol)
+ print("Bits per symbol = %d" % self._bits_per_symbol)
+ print("h = " , self._h_numerator , " / " , self._h_denominator)
+ print("Symbol alphabet = " , self.sym_alphabet)
+ print("Symbols per pulse = %d" % self._symbols_per_pulse)
+ print("taps = " , self.taps)
+
+ print("CPM type = %d" % self._cpm_type)
if self._cpm_type == 1:
- print "Gaussian filter BT = %.2f" % self._bt
+ print("Gaussian filter BT = %.2f" % self._bt)
def _setup_logging(self):
- print "Modulation logging turned on."
+ print("Modulation logging turned on.")
self.connect(self.B2s,
blocks.file_sink(gr.sizeof_float, "symbols.dat"))
self.connect(self.pam,
diff --git a/gr-digital/python/digital/crc.py b/gr-digital/python/digital/crc.py
index e228faaa98..31e98d368a 100644
--- a/gr-digital/python/digital/crc.py
+++ b/gr-digital/python/digital/crc.py
@@ -1,26 +1,27 @@
+from __future__ import unicode_literals
#
# Copyright 2005,2007,2011 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
from gnuradio import gru
-import digital_swig as digital
+from . import digital_swig as digital
import struct
def gen_and_append_crc32(s):
diff --git a/gr-digital/python/digital/generic_mod_demod.py b/gr-digital/python/digital/generic_mod_demod.py
index b26966fbcf..2a0d2c44ce 100644
--- a/gr-digital/python/digital/generic_mod_demod.py
+++ b/gr-digital/python/digital/generic_mod_demod.py
@@ -19,32 +19,22 @@
# Boston, MA 02110-1301, USA.
#
-# See gnuradio-examples/python/digital for examples
-
"""
Generic modulation and demodulation.
"""
-from gnuradio import gr
-from modulation_utils import extract_kwargs_from_options_for_class
-from utils import mod_codes
-import digital_swig as digital
-import math
+# See gnuradio-examples/python/digital for examples
-try:
- from gnuradio import blocks
-except ImportError:
- import blocks_swig as blocks
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import unicode_literals
-try:
- from gnuradio import filter
-except ImportError:
- import filter_swig as filter
+from gnuradio import gr, blocks, filter, analog
+from .modulation_utils import extract_kwargs_from_options_for_class
+from .utils import mod_codes
+from . import digital_swig as digital
+import math
-try:
- from gnuradio import analog
-except ImportError:
- import analog_swig as analog
# default values (used in __init__ and add_options)
_def_samples_per_symbol = 2
@@ -113,9 +103,9 @@ class generic_mod(gr.hier_block2):
verbose=_def_verbose,
log=_def_log):
- gr.hier_block2.__init__(self, "generic_mod",
- gr.io_signature(1, 1, gr.sizeof_char), # Input signature
- gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
+ gr.hier_block2.__init__(self, "generic_mod",
+ gr.io_signature(1, 1, gr.sizeof_char), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
self._constellation = constellation
self._samples_per_symbol = samples_per_symbol
@@ -125,7 +115,7 @@ class generic_mod(gr.hier_block2):
self.pre_diff_code = pre_diff_code and self._constellation.apply_pre_diff_code()
if self._samples_per_symbol < 2:
- raise TypeError, ("sps must be >= 2, is %f" % self._samples_per_symbol)
+ raise TypeError("sps must be >= 2, is %f" % self._samples_per_symbol)
arity = pow(2,self.bits_per_symbol())
@@ -153,7 +143,7 @@ class generic_mod(gr.hier_block2):
self.rrc_filter = filter.pfb_arb_resampler_ccf(self._samples_per_symbol,
self.rrc_taps)
- # Connect
+ # Connect
self._blocks = [self, self.bytes2chunks]
if self.pre_diff_code:
self._blocks.append(self.symbol_mapper)
@@ -191,12 +181,12 @@ class generic_mod(gr.hier_block2):
def _print_verbage(self):
- print "\nModulator:"
- print "bits per symbol: %d" % self.bits_per_symbol()
- print "RRC roll-off factor: %.2f" % self._excess_bw
+ print("\nModulator:")
+ 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."
+ print("Modulation logging turned on.")
self.connect(self.bytes2chunks,
blocks.file_sink(gr.sizeof_char, "tx_bytes2chunks.8b"))
if self.pre_diff_code:
@@ -249,9 +239,9 @@ class generic_demod(gr.hier_block2):
verbose=_def_verbose,
log=_def_log):
- gr.hier_block2.__init__(self, "generic_demod",
- gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
- gr.io_signature(1, 1, gr.sizeof_char)) # Output signature
+ gr.hier_block2.__init__(self, "generic_demod",
+ gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_char)) # Output signature
self._constellation = constellation
self._samples_per_symbol = samples_per_symbol
@@ -263,7 +253,7 @@ class generic_demod(gr.hier_block2):
self._differential = differential
if self._samples_per_symbol < 2:
- raise TypeError, ("sps must be >= 2, is %d" % self._samples_per_symbol)
+ raise TypeError("sps must be >= 2, is %d" % self._samples_per_symbol)
# Only apply a predifferential coding if the constellation also supports it.
self.pre_diff_code = pre_diff_code and self._constellation.apply_pre_diff_code()
@@ -328,15 +318,15 @@ class generic_demod(gr.hier_block2):
return self._constellation.bits_per_symbol()
def _print_verbage(self):
- print "\nDemodulator:"
- print "bits per symbol: %d" % self.bits_per_symbol()
- print "RRC roll-off factor: %.2f" % self._excess_bw
- print "FLL bandwidth: %.2e" % self._freq_bw
- print "Timing bandwidth: %.2e" % self._timing_bw
- print "Phase bandwidth: %.2e" % self._phase_bw
+ print("\nDemodulator:")
+ print("bits per symbol: %d" % self.bits_per_symbol())
+ print("RRC roll-off factor: %.2f" % self._excess_bw)
+ print("FLL bandwidth: %.2e" % self._freq_bw)
+ print("Timing bandwidth: %.2e" % self._timing_bw)
+ print("Phase bandwidth: %.2e" % self._phase_bw)
def _setup_logging(self):
- print "Modulation logging turned on."
+ print("Modulation logging turned on.")
self.connect(self.agc,
blocks.file_sink(gr.sizeof_gr_complex, "rx_agc.32fc"))
self.connect((self.freq_recov, 0),
diff --git a/gr-digital/python/digital/gfsk.py b/gr-digital/python/digital/gfsk.py
index 032302b103..8b86743bf1 100644
--- a/gr-digital/python/digital/gfsk.py
+++ b/gr-digital/python/digital/gfsk.py
@@ -1,43 +1,42 @@
#
-# GFSK modulation and demodulation.
+# GFSK modulation and demodulation.
#
#
# Copyright 2005-2007,2012 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import unicode_literals
# See gnuradio-examples/python/digital for examples
+import numpy
+
from gnuradio import gr
from gnuradio import analog
-from gnuradio import blocks
-import modulation_utils
-import digital_swig as digital
-from math import pi
-import numpy
-from pprint import pprint
-import inspect
+from gnuradio import blocks, filter
+from . import modulation_utils
+from . import digital_swig as digital
-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
@@ -69,22 +68,22 @@ class gfsk_mod(gr.hier_block2):
verbose=_def_verbose,
log=_def_log):
"""
- Hierarchical block for Gaussian Frequency Shift Key (GFSK)
- modulation.
+ Hierarchical block for Gaussian Frequency Shift Key (GFSK)
+ modulation.
- The input is a byte stream (unsigned char) and the
- output is the complex modulated signal at baseband.
+ The input is a byte stream (unsigned char) and the
+ output is the complex modulated signal at baseband.
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",
- gr.io_signature(1, 1, gr.sizeof_char), # Input signature
- gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
+ gr.hier_block2.__init__(self, "gfsk_mod",
+ gr.io_signature(1, 1, gr.sizeof_char), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
samples_per_symbol = int(samples_per_symbol)
self._samples_per_symbol = samples_per_symbol
@@ -92,43 +91,43 @@ class gfsk_mod(gr.hier_block2):
self._differential = False
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,))
+ 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
+ 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 = digital.bytes_to_syms()
+ # Turn it into NRZ data.
+ #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
+ # Form Gaussian filter
# Generate Gaussian response (Needs to be convolved with window below).
- self.gaussian_taps = filter.firdes.gaussian(
- 1.0, # gain
- samples_per_symbol, # symbol_rate
- bt, # bandwidth * symbol time
- ntaps # number of taps
- )
-
- self.sqwave = (1,) * samples_per_symbol # rectangular window
- self.taps = numpy.convolve(numpy.array(self.gaussian_taps),numpy.array(self.sqwave))
- self.gaussian_filter = filter.interp_fir_filter_fff(samples_per_symbol, self.taps)
-
- # FM modulation
- self.fmmod = analog.frequency_modulator_fc(sensitivity)
-
- # small amount of output attenuation to prevent clipping USRP sink
- self.amp = blocks.multiply_const_cc(0.999)
-
+ self.gaussian_taps = filter.firdes.gaussian(
+ 1.0, # gain
+ samples_per_symbol, # symbol_rate
+ bt, # bandwidth * symbol time
+ ntaps # number of taps
+ )
+
+ self.sqwave = (1,) * samples_per_symbol # rectangular window
+ self.taps = numpy.convolve(numpy.array(self.gaussian_taps),numpy.array(self.sqwave))
+ self.gaussian_filter = filter.interp_fir_filter_fff(samples_per_symbol, self.taps)
+
+ # FM modulation
+ self.fmmod = analog.frequency_modulator_fc(sensitivity)
+
+ # small amount of output attenuation to prevent clipping USRP sink
+ self.amp = blocks.multiply_const_cc(0.999)
+
if verbose:
self._print_verbage()
-
+
if log:
self._setup_logging()
- # Connect & Initialize base class
- self.connect(self, self.unpack, self.nrz, self.gaussian_filter, self.fmmod, self.amp, self)
+ # Connect & Initialize base class
+ 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
@@ -138,12 +137,12 @@ class gfsk_mod(gr.hier_block2):
return 1
def _print_verbage(self):
- print "bits per symbol = %d" % self.bits_per_symbol()
- print "Gaussian filter bt = %.2f" % self._bt
+ 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."
+ print("Modulation logging turned on.")
self.connect(self.nrz,
blocks.file_sink(gr.sizeof_float, "nrz.dat"))
self.connect(self.gaussian_filter,
@@ -184,11 +183,11 @@ class gfsk_demod(gr.hier_block2):
verbose=_def_verbose,
log=_def_log):
"""
- Hierarchical block for Gaussian Minimum Shift Key (GFSK)
- demodulation.
+ Hierarchical block for Gaussian Minimum Shift Key (GFSK)
+ demodulation.
- The input is the complex modulated signal at baseband.
- The output is a stream of bits packed 1 bit per byte (the LSB)
+ The input is the complex modulated signal at baseband.
+ The output is a stream of bits packed 1 bit per byte (the LSB)
Args:
samples_per_symbol: samples per baud (integer)
@@ -196,18 +195,18 @@ class gfsk_demod(gr.hier_block2):
log: Print modualtion data to files? (bool)
Clock recovery parameters. These all have reasonable defaults.
-
+
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:
- """
+ float:
+ """
- gr.hier_block2.__init__(self, "gfsk_demod",
- gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
- gr.io_signature(1, 1, gr.sizeof_char)) # Output signature
+ gr.hier_block2.__init__(self, "gfsk_demod",
+ 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
@@ -215,24 +214,24 @@ class gfsk_demod(gr.hier_block2):
self._omega_relative_limit = omega_relative_limit
self._freq_error = freq_error
self._differential = False
-
+
if samples_per_symbol < 2:
- raise TypeError, "samples_per_symbol >= 2, is %f" % samples_per_symbol
+ raise TypeError("samples_per_symbol >= 2, is %f" % samples_per_symbol)
self._omega = samples_per_symbol*(1+self._freq_error)
if not self._gain_mu:
self._gain_mu = 0.175
-
- self._gain_omega = .25 * self._gain_mu * self._gain_mu # critically damped
- # Demodulate FM
- #sensitivity = (pi / 2) / samples_per_symbol
- self.fmdemod = analog.quadrature_demod_cf(1.0 / sensitivity)
+ self._gain_omega = .25 * self._gain_mu * self._gain_mu # critically damped
- # 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 = digital.clock_recovery_mm_ff(self._omega, self._gain_omega,
+ # Demodulate FM
+ #sensitivity = (pi / 2) / samples_per_symbol
+ 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)
+ self.clock_recovery = digital.clock_recovery_mm_ff(self._omega, self._gain_omega,
self._mu, self._gain_mu,
self._omega_relative_limit)
@@ -241,12 +240,12 @@ class gfsk_demod(gr.hier_block2):
if verbose:
self._print_verbage()
-
+
if log:
self._setup_logging()
- # Connect & Initialize base class
- self.connect(self, self.fmdemod, self.clock_recovery, self.slicer, self)
+ # Connect & Initialize base class
+ self.connect(self, self.fmdemod, self.clock_recovery, self.slicer, self)
def samples_per_symbol(self):
return self._samples_per_symbol
@@ -256,16 +255,16 @@ class gfsk_demod(gr.hier_block2):
return 1
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
+ 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."
+ print("Demodulation logging turned on.")
self.connect(self.fmdemod,
blocks.file_sink(gr.sizeof_float, "fmdemod.dat"))
self.connect(self.clock_recovery,
diff --git a/gr-digital/python/digital/gmsk.py b/gr-digital/python/digital/gmsk.py
index e7a92a95db..5e25a3d3a1 100644
--- a/gr-digital/python/digital/gmsk.py
+++ b/gr-digital/python/digital/gmsk.py
@@ -1,26 +1,31 @@
#
-# GMSK modulation and demodulation.
+# GMSK modulation and demodulation.
#
#
# Copyright 2005-2007,2012 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import unicode_literals
# See gnuradio-examples/python/digital for examples
@@ -31,8 +36,8 @@ import inspect
import numpy
from gnuradio import gr, blocks, analog, filter
-import modulation_utils
-import digital_swig as digital
+from . import modulation_utils
+from . import digital_swig as digital
# default values (used in __init__ and add_options)
_def_samples_per_symbol = 2
@@ -58,10 +63,10 @@ class gmsk_mod(gr.hier_block2):
"""
Hierarchical block for Gaussian Minimum Shift Key (GMSK)
modulation.
-
+
The input is a byte stream (unsigned char with packed bits)
and the output is the complex modulated signal at baseband.
-
+
Args:
samples_per_symbol: samples per baud >= 2 (integer)
bt: Gaussian filter bandwidth * symbol time (float)
@@ -75,9 +80,9 @@ class gmsk_mod(gr.hier_block2):
verbose=_def_verbose,
log=_def_log):
- gr.hier_block2.__init__(self, "gmsk_mod",
- gr.io_signature(1, 1, gr.sizeof_char), # Input signature
- gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
+ gr.hier_block2.__init__(self, "gmsk_mod",
+ gr.io_signature(1, 1, gr.sizeof_char), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
samples_per_symbol = int(samples_per_symbol)
self._samples_per_symbol = samples_per_symbol
@@ -85,40 +90,40 @@ class gmsk_mod(gr.hier_block2):
self._differential = False
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,))
+ 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
+ ntaps = 4 * samples_per_symbol # up to 3 bits in filter at once
+ sensitivity = (old_div(pi / 2), samples_per_symbol) # phase change per bit = pi / 2
- # Turn it into NRZ data.
- #self.nrz = digital.bytes_to_syms()
+ # Turn it into NRZ data.
+ #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], 1)
- # Form Gaussian filter
+ # Form Gaussian filter
# Generate Gaussian response (Needs to be convolved with window below).
- self.gaussian_taps = filter.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 = numpy.convolve(numpy.array(self.gaussian_taps),numpy.array(self.sqwave))
- self.gaussian_filter = filter.interp_fir_filter_fff(samples_per_symbol, self.taps)
-
- # FM modulation
- self.fmmod = analog.frequency_modulator_fc(sensitivity)
-
+ self.gaussian_taps = filter.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 = numpy.convolve(numpy.array(self.gaussian_taps),numpy.array(self.sqwave))
+ self.gaussian_filter = filter.interp_fir_filter_fff(samples_per_symbol, self.taps)
+
+ # FM modulation
+ self.fmmod = analog.frequency_modulator_fc(sensitivity)
+
if verbose:
self._print_verbage()
-
+
if log:
self._setup_logging()
- # Connect & Initialize base class
- self.connect(self, self.unpack, self.nrz, self.gaussian_filter, self.fmmod, self)
+ # Connect & Initialize base class
+ self.connect(self, self.unpack, self.nrz, self.gaussian_filter, self.fmmod, self)
def samples_per_symbol(self):
return self._samples_per_symbol
@@ -128,12 +133,12 @@ class gmsk_mod(gr.hier_block2):
return 1
def _print_verbage(self):
- print "bits per symbol = %d" % self.bits_per_symbol()
- print "Gaussian filter bt = %.2f" % self._bt
+ 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."
+ print("Modulation logging turned on.")
self.connect(self.nrz,
blocks.file_sink(gr.sizeof_float, "nrz.dat"))
self.connect(self.gaussian_filter,
@@ -166,10 +171,10 @@ class gmsk_demod(gr.hier_block2):
"""
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)
-
+
Args:
samples_per_symbol: samples per baud (integer)
gain_mu: controls rate of mu adjustment (float)
@@ -179,7 +184,7 @@ class gmsk_demod(gr.hier_block2):
verbose: Print information about modulator? (boolean)
log: Print modualtion data to files? (boolean)
"""
-
+
def __init__(self,
samples_per_symbol=_def_samples_per_symbol,
gain_mu=_def_gain_mu,
@@ -189,9 +194,9 @@ class gmsk_demod(gr.hier_block2):
verbose=_def_verbose,
log=_def_log):
- gr.hier_block2.__init__(self, "gmsk_demod",
- gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
- gr.io_signature(1, 1, gr.sizeof_char)) # Output signature
+ gr.hier_block2.__init__(self, "gmsk_demod",
+ 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
@@ -199,24 +204,24 @@ class gmsk_demod(gr.hier_block2):
self._omega_relative_limit = omega_relative_limit
self._freq_error = freq_error
self._differential = False
-
+
if samples_per_symbol < 2:
- raise TypeError, "samples_per_symbol >= 2, is %f" % samples_per_symbol
+ raise TypeError("samples_per_symbol >= 2, is %f" % samples_per_symbol)
self._omega = samples_per_symbol*(1+self._freq_error)
if not self._gain_mu:
self._gain_mu = 0.175
-
- self._gain_omega = .25 * self._gain_mu * self._gain_mu # critically damped
- # Demodulate FM
- sensitivity = (pi / 2) / samples_per_symbol
- self.fmdemod = analog.quadrature_demod_cf(1.0 / sensitivity)
+ self._gain_omega = .25 * self._gain_mu * self._gain_mu # critically damped
- # 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 = digital.clock_recovery_mm_ff(self._omega, self._gain_omega,
+ # Demodulate FM
+ sensitivity = (old_div(pi / 2), samples_per_symbol)
+ 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)
+ self.clock_recovery = digital.clock_recovery_mm_ff(self._omega, self._gain_omega,
self._mu, self._gain_mu,
self._omega_relative_limit)
@@ -225,12 +230,12 @@ class gmsk_demod(gr.hier_block2):
if verbose:
self._print_verbage()
-
+
if log:
self._setup_logging()
- # Connect & Initialize base class
- self.connect(self, self.fmdemod, self.clock_recovery, self.slicer, self)
+ # Connect & Initialize base class
+ self.connect(self, self.fmdemod, self.clock_recovery, self.slicer, self)
def samples_per_symbol(self):
return self._samples_per_symbol
@@ -240,16 +245,16 @@ class gmsk_demod(gr.hier_block2):
return 1
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
+ 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."
+ print("Demodulation logging turned on.")
self.connect(self.fmdemod,
blocks.file_sink(gr.sizeof_float, "fmdemod.dat"))
self.connect(self.clock_recovery,
diff --git a/gr-digital/python/digital/modulation_utils.py b/gr-digital/python/digital/modulation_utils.py
index d499094d05..57d7ccdae8 100644
--- a/gr-digital/python/digital/modulation_utils.py
+++ b/gr-digital/python/digital/modulation_utils.py
@@ -22,6 +22,7 @@
Miscellaneous utilities for managing mods and demods, as well as other items
useful in dealing with generalized handling of different modulations and demods.
"""
+from __future__ import unicode_literals
import inspect
diff --git a/gr-digital/python/digital/ofdm.py b/gr-digital/python/digital/ofdm.py
index 563b70ad00..db15a4d3f1 100644
--- a/gr-digital/python/digital/ofdm.py
+++ b/gr-digital/python/digital/ofdm.py
@@ -1,33 +1,38 @@
#!/usr/bin/env python
#
# Copyright 2006-2008,2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import unicode_literals
import math
from gnuradio import gr, fft
from gnuradio import blocks
-import digital_swig as digital
-import ofdm_packet_utils
-from ofdm_receiver import ofdm_receiver
+from . import digital_swig as digital
+from . import ofdm_packet_utils
+from .ofdm_receiver import ofdm_receiver
import gnuradio.gr.gr_threading as _threading
-import psk, qam
+from . import psk, qam
# /////////////////////////////////////////////////////////////////////////////
# mod/demod with packets as i/o
@@ -37,12 +42,12 @@ class ofdm_mod(gr.hier_block2):
"""
Modulates an OFDM stream. Based on the options fft_length, occupied_tones, and
cp_length, this block creates OFDM symbols using a specified modulation option.
-
+
Send packets by calling send_pkt
"""
def __init__(self, options, msgq_limit=2, pad_for_usrp=True):
"""
- Hierarchical block for sending packets
+ Hierarchical block for sending packets
Packets to be sent are enqueued by calling send_pkt.
The output is the complex modulated signal at baseband.
@@ -53,9 +58,9 @@ class ofdm_mod(gr.hier_block2):
pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples
"""
- gr.hier_block2.__init__(self, "ofdm_mod",
- gr.io_signature(0, 0, 0), # Input signature
- gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
+ gr.hier_block2.__init__(self, "ofdm_mod",
+ gr.io_signature(0, 0, 0), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
self._pad_for_usrp = pad_for_usrp
self._modulation = options.modulation
@@ -66,7 +71,7 @@ class ofdm_mod(gr.hier_block2):
win = [] #[1 for i in range(self._fft_length)]
# Use freq domain to get doubled-up known symbol for correlation in time domain
- zeros_on_left = int(math.ceil((self._fft_length - self._occupied_tones)/2.0))
+ zeros_on_left = int(math.ceil((self._fft_length - self._occupied_tones) / 2.0))
ksfreq = known_symbols_4512_3[0:self._occupied_tones]
for i in range(len(ksfreq)):
if((zeros_on_left + i) & 1):
@@ -74,46 +79,46 @@ class ofdm_mod(gr.hier_block2):
# hard-coded known symbols
preambles = (ksfreq,)
-
+
padded_preambles = list()
for pre in preambles:
padded = self._fft_length*[0,]
padded[zeros_on_left : zeros_on_left + self._occupied_tones] = pre
padded_preambles.append(padded)
-
+
symbol_length = options.fft_length + options.cp_length
-
+
mods = {"bpsk": 2, "qpsk": 4, "8psk": 8, "qam8": 8, "qam16": 16, "qam64": 64, "qam256": 256}
arity = mods[self._modulation]
-
+
rot = 1
if self._modulation == "qpsk":
rot = (0.707+0.707j)
-
+
# FIXME: pass the constellation objects instead of just the points
if(self._modulation.find("psk") >= 0):
constel = psk.psk_constellation(arity)
- rotated_const = map(lambda pt: pt * rot, constel.points())
+ rotated_const = [pt * rot for pt in constel.points()]
elif(self._modulation.find("qam") >= 0):
constel = qam.qam_constellation(arity)
- rotated_const = map(lambda pt: pt * rot, constel.points())
- #print rotated_const
+ rotated_const = [pt * rot for pt in constel.points()]
+ #print(rotated_const)
self._pkt_input = digital.ofdm_mapper_bcv(rotated_const,
msgq_limit,
options.occupied_tones,
options.fft_length)
-
+
self.preambles = digital.ofdm_insert_preamble(self._fft_length,
padded_preambles)
self.ifft = fft.fft_vcc(self._fft_length, False, win, True)
self.cp_adder = digital.ofdm_cyclic_prefixer(self._fft_length,
symbol_length)
self.scale = blocks.multiply_const_cc(1.0 / math.sqrt(self._fft_length))
-
+
self.connect((self._pkt_input, 0), (self.preambles, 0))
self.connect((self._pkt_input, 1), (self.preambles, 1))
self.connect(self.preambles, self.ifft, self.cp_adder, self.scale, self)
-
+
if options.verbose:
self._print_verbage()
@@ -137,12 +142,12 @@ class ofdm_mod(gr.hier_block2):
if eof:
msg = gr.message(1) # tell self._pkt_input we're not sending any more packets
else:
- # print "original_payload =", string_to_hex_list(payload)
+ # print("original_payload =", string_to_hex_list(payload))
pkt = ofdm_packet_utils.make_packet(payload, 1, 1,
self._pad_for_usrp,
whitening=True)
-
- #print "pkt =", string_to_hex_list(pkt)
+
+ #print("pkt =", string_to_hex_list(pkt))
msg = gr.message_from_string(pkt)
self._pkt_input.msgq().insert_tail(msg)
@@ -164,11 +169,11 @@ class ofdm_mod(gr.hier_block2):
"""
Prints information about the OFDM modulator
"""
- print "\nOFDM Modulator:"
- print "Modulation Type: %s" % (self._modulation)
- print "FFT length: %3d" % (self._fft_length)
- print "Occupied Tones: %3d" % (self._occupied_tones)
- print "CP length: %3d" % (self._cp_length)
+ print("\nOFDM Modulator:")
+ print("Modulation Type: %s" % (self._modulation))
+ print("FFT length: %3d" % (self._fft_length))
+ print("Occupied Tones: %3d" % (self._occupied_tones))
+ print("CP length: %3d" % (self._cp_length))
class ofdm_demod(gr.hier_block2):
@@ -183,18 +188,18 @@ class ofdm_demod(gr.hier_block2):
def __init__(self, options, callback=None):
"""
- Hierarchical block for demodulating and deframing packets.
+ Hierarchical block for demodulating and deframing packets.
- The input is the complex modulated signal at baseband.
+ The input is the complex modulated signal at baseband.
Demodulated packets are sent to the handler.
Args:
options: pass modulation options from higher layers (fft length, occupied tones, etc.)
callback: function of two args: ok, payload (ok: bool; payload: string)
- """
- gr.hier_block2.__init__(self, "ofdm_demod",
- gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
- gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
+ """
+ gr.hier_block2.__init__(self, "ofdm_demod",
+ gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
self._rcvd_pktq = gr.msg_queue() # holds packets from the PHY
@@ -206,7 +211,7 @@ class ofdm_demod(gr.hier_block2):
self._snr = options.snr
# Use freq domain to get doubled-up known symbol for correlation in time domain
- zeros_on_left = int(math.ceil((self._fft_length - self._occupied_tones)/2.0))
+ zeros_on_left = int(math.ceil((self._fft_length - self._occupied_tones) / 2.0))
ksfreq = known_symbols_4512_3[0:self._occupied_tones]
for i in range(len(ksfreq)):
if((zeros_on_left + i) & 1):
@@ -224,7 +229,7 @@ class ofdm_demod(gr.hier_block2):
mods = {"bpsk": 2, "qpsk": 4, "8psk": 8, "qam8": 8, "qam16": 16, "qam64": 64, "qam256": 256}
arity = mods[self._modulation]
-
+
rot = 1
if self._modulation == "qpsk":
rot = (0.707+0.707j)
@@ -232,15 +237,15 @@ class ofdm_demod(gr.hier_block2):
# FIXME: pass the constellation objects instead of just the points
if(self._modulation.find("psk") >= 0):
constel = psk.psk_constellation(arity)
- rotated_const = map(lambda pt: pt * rot, constel.points())
+ rotated_const = [pt * rot for pt in constel.points()]
elif(self._modulation.find("qam") >= 0):
constel = qam.qam_constellation(arity)
- rotated_const = map(lambda pt: pt * rot, constel.points())
- #print rotated_const
+ rotated_const = [pt * rot for pt in constel.points()]
+ #print(rotated_const)
phgain = 0.25
frgain = phgain*phgain / 4.0
- self.ofdm_demod = digital.ofdm_frame_sink(rotated_const, range(arity),
+ self.ofdm_demod = digital.ofdm_frame_sink(rotated_const, list(range(arity)),
self._rcvd_pktq,
self._occupied_tones,
phgain, frgain)
@@ -263,7 +268,7 @@ class ofdm_demod(gr.hier_block2):
if options.verbose:
self._print_verbage()
-
+
self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback)
@staticmethod
@@ -286,11 +291,11 @@ class ofdm_demod(gr.hier_block2):
"""
Prints information about the OFDM demodulator
"""
- print "\nOFDM Demodulator:"
- print "Modulation Type: %s" % (self._modulation)
- print "FFT length: %3d" % (self._fft_length)
- print "Occupied Tones: %3d" % (self._occupied_tones)
- print "CP length: %3d" % (self._cp_length)
+ print("\nOFDM Demodulator:")
+ print("Modulation Type: %s" % (self._modulation))
+ print("FFT length: %3d" % (self._fft_length))
+ print("Occupied Tones: %3d" % (self._occupied_tones))
+ print("CP length: %3d" % (self._cp_length))
diff --git a/gr-digital/python/digital/ofdm_packet_utils.py b/gr-digital/python/digital/ofdm_packet_utils.py
index e9ca641c7a..e26308a262 100644
--- a/gr-digital/python/digital/ofdm_packet_utils.py
+++ b/gr-digital/python/digital/ofdm_packet_utils.py
@@ -19,10 +19,15 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import unicode_literals
+
import struct
import numpy
from gnuradio import gru
-import crc
+from . import crc
def conv_packed_binary_string_to_1_0_string(s):
"""
@@ -35,7 +40,7 @@ def conv_packed_binary_string_to_1_0_string(s):
t = (x >> i) & 0x1
r.append(t)
- return ''.join(map(lambda x: chr(x + ord('0')), r))
+ return ''.join([chr(x + ord('0')) for x in r])
def conv_1_0_string_to_packed_binary_string(s):
"""
@@ -46,7 +51,7 @@ def conv_1_0_string_to_packed_binary_string(s):
to get to a multiple of 8.
"""
if not is_1_0_string(s):
- raise ValueError, "Input must be a string containing only 0's and 1's"
+ raise ValueError("Input must be a string containing only 0's and 1's")
# pad to multiple of 8
padded = False
@@ -78,7 +83,7 @@ def is_1_0_string(s):
return True
def string_to_hex_list(s):
- return map(lambda x: hex(ord(x)), s)
+ return [hex(ord(x)) for x in s]
def whiten(s, o):
@@ -93,7 +98,7 @@ def dewhiten(s, o):
def make_header(payload_len, whitener_offset=0):
# Upper nibble is offset, lower 12 bits is len
val = ((whitener_offset & 0xf) << 12) | (payload_len & 0x0fff)
- #print "offset =", whitener_offset, " len =", payload_len, " val=", val
+ #print("offset =", whitener_offset, " len =", payload_len, " val=", val)
return struct.pack('!HH', val, val)
def make_packet(payload, samples_per_symbol, bits_per_symbol,
@@ -113,15 +118,15 @@ def make_packet(payload, samples_per_symbol, bits_per_symbol,
"""
if not whitener_offset >=0 and whitener_offset < 16:
- raise ValueError, "whitener_offset must be between 0 and 15, inclusive (%i)" % (whitener_offset,)
+ raise ValueError("whitener_offset must be between 0 and 15, inclusive (%i)" % (whitener_offset,))
payload_with_crc = crc.gen_and_append_crc32(payload)
- #print "outbound crc =", string_to_hex_list(payload_with_crc[-4:])
+ #print("outbound crc =", string_to_hex_list(payload_with_crc[-4:]))
L = len(payload_with_crc)
MAXLEN = len(random_mask_tuple)
if L > MAXLEN:
- raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN,)
+ raise ValueError("len(payload) must be in [0, %d]" % (MAXLEN,))
pkt_hd = make_header(L, whitener_offset)
pkt_dt = ''.join((payload_with_crc, '\x55'))
@@ -136,7 +141,7 @@ def make_packet(payload, samples_per_symbol, bits_per_symbol,
else:
pkt = pkt_hd + pkt_dt
- #print "make_packet: len(pkt) =", len(pkt)
+ #print("make_packet: len(pkt) =", len(pkt))
return pkt
@@ -157,7 +162,7 @@ def _npadding_bytes(pkt_byte_len, samples_per_symbol, bits_per_symbol):
number of bytes of padding to append.
"""
modulus = 128
- byte_modulus = gru.lcm(modulus/8, samples_per_symbol) * bits_per_symbol / samples_per_symbol
+ byte_modulus = gru.lcm(modulus / 8, samples_per_symbol) * bits_per_symbol / samples_per_symbol
r = pkt_byte_len % byte_modulus
if r == 0:
return 0
@@ -182,9 +187,9 @@ def unmake_packet(whitened_payload_with_crc, whitener_offset=0, dewhitening=1):
ok, payload = crc.check_crc32(payload_with_crc)
if 0:
- print "payload_with_crc =", string_to_hex_list(payload_with_crc)
- print "ok = %r, len(payload) = %d" % (ok, len(payload))
- print "payload =", string_to_hex_list(payload)
+ print("payload_with_crc =", string_to_hex_list(payload_with_crc))
+ print("ok = %r, len(payload) = %d" % (ok, len(payload)))
+ print("payload =", string_to_hex_list(payload))
return ok, payload
diff --git a/gr-digital/python/digital/ofdm_receiver.py b/gr-digital/python/digital/ofdm_receiver.py
index 4b7836b43c..d23b338b78 100644
--- a/gr-digital/python/digital/ofdm_receiver.py
+++ b/gr-digital/python/digital/ofdm_receiver.py
@@ -1,24 +1,28 @@
#!/usr/bin/env python
#
# Copyright 2006-2008 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import unicode_literals
import math
from numpy import fft
@@ -28,16 +32,12 @@ from gnuradio import analog
from gnuradio import blocks
from gnuradio import filter
-import digital_swig as digital
-from ofdm_sync_pn import ofdm_sync_pn
-from ofdm_sync_fixed import ofdm_sync_fixed
-from ofdm_sync_pnac import ofdm_sync_pnac
-from ofdm_sync_ml import ofdm_sync_ml
+from . import digital_swig as digital
+from .ofdm_sync_pn import ofdm_sync_pn
+from .ofdm_sync_fixed import ofdm_sync_fixed
+from .ofdm_sync_pnac import ofdm_sync_pnac
+from .ofdm_sync_ml import ofdm_sync_ml
-try:
- from gnuradio import filter
-except ImportError:
- import filter_swig as filter
class ofdm_receiver(gr.hier_block2):
"""
@@ -51,9 +51,9 @@ class ofdm_receiver(gr.hier_block2):
def __init__(self, fft_length, cp_length, occupied_tones, snr, ks, logging=False):
"""
- Hierarchical block for receiving OFDM symbols.
+ Hierarchical block for receiving OFDM symbols.
- The input is the complex modulated signal at baseband.
+ The input is the complex modulated signal at baseband.
Synchronized packets are sent back to the demodulator.
Args:
@@ -63,13 +63,13 @@ class ofdm_receiver(gr.hier_block2):
snr: estimated signal to noise ratio used to guide cyclic prefix synchronizer (float)
ks: known symbols used as preambles to each packet (list of lists)
logging: turn file logging on or off (bool)
- """
+ """
- gr.hier_block2.__init__(self, "ofdm_receiver",
- gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
+ gr.hier_block2.__init__(self, "ofdm_receiver",
+ gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
gr.io_signature2(2, 2, gr.sizeof_gr_complex*occupied_tones, gr.sizeof_char)) # Output signature
-
- bw = (float(occupied_tones) / float(fft_length)) / 2.0
+
+ bw = (old_div(float(occupied_tones) / float(fft_length)), 2.0)
tb = bw*0.08
chan_coeffs = filter.firdes.low_pass (1.0, # gain
1.0, # sampling rate
@@ -77,13 +77,13 @@ class ofdm_receiver(gr.hier_block2):
tb, # width of trans. band
filter.firdes.WIN_HAMMING) # filter type
self.chan_filt = filter.fft_filter_ccc(1, chan_coeffs)
-
+
win = [1 for i in range(fft_length)]
- zeros_on_left = int(math.ceil((fft_length - occupied_tones)/2.0))
+ zeros_on_left = int(math.ceil((fft_length - occupied_tones) / 2.0))
ks0 = fft_length*[0,]
ks0[zeros_on_left : zeros_on_left + occupied_tones] = ks[0]
-
+
ks0 = fft.ifftshift(ks0)
ks0time = fft.ifft(ks0)
# ADD SCALING FACTOR
@@ -91,19 +91,19 @@ class ofdm_receiver(gr.hier_block2):
SYNC = "pn"
if SYNC == "ml":
- nco_sensitivity = -1.0/fft_length # correct for fine frequency
+ nco_sensitivity = -1.0 / fft_length # correct for fine frequency
self.ofdm_sync = ofdm_sync_ml(fft_length,
cp_length,
snr,
ks0time,
logging)
elif SYNC == "pn":
- nco_sensitivity = -2.0/fft_length # correct for fine frequency
+ nco_sensitivity = -2.0 / fft_length # correct for fine frequency
self.ofdm_sync = ofdm_sync_pn(fft_length,
cp_length,
logging)
elif SYNC == "pnac":
- nco_sensitivity = -2.0/fft_length # correct for fine frequency
+ nco_sensitivity = -2.0 / fft_length # correct for fine frequency
self.ofdm_sync = ofdm_sync_pnac(fft_length,
cp_length,
ks0time,
@@ -111,10 +111,10 @@ class ofdm_receiver(gr.hier_block2):
# for testing only; do not user over the air
# remove filter and filter delay for this
elif SYNC == "fixed":
- self.chan_filt = blocks.multiply_const_cc(1.0)
+ self.chan_filt = blocks.multiply_const_cc(1.0)
nsymbols = 18 # enter the number of symbols per packet
freq_offset = 0.0 # if you use a frequency offset, enter it here
- nco_sensitivity = -2.0/fft_length # correct for fine frequency
+ nco_sensitivity = -2.0 / fft_length # correct for fine frequency
self.ofdm_sync = ofdm_sync_fixed(fft_length,
cp_length,
nsymbols,
diff --git a/gr-digital/python/digital/ofdm_sync_fixed.py b/gr-digital/python/digital/ofdm_sync_fixed.py
index 9cbd59b943..891ba17d07 100644
--- a/gr-digital/python/digital/ofdm_sync_fixed.py
+++ b/gr-digital/python/digital/ofdm_sync_fixed.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import unicode_literals
import math
from gnuradio import gr
from gnuradio import blocks
diff --git a/gr-digital/python/digital/ofdm_sync_ml.py b/gr-digital/python/digital/ofdm_sync_ml.py
index 3afd647098..6a03c21639 100644
--- a/gr-digital/python/digital/ofdm_sync_ml.py
+++ b/gr-digital/python/digital/ofdm_sync_ml.py
@@ -1,37 +1,31 @@
#!/usr/bin/env python
#
# Copyright 2007,2008 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import division
+from __future__ import unicode_literals
-import math
-from gnuradio import gr
-try:
- from gnuradio import filter
-except ImportError:
- import filter_swig as filter
+from gnuradio import gr, blocks, filter
-try:
- from gnuradio import blocks
-except ImportError:
- import blocks_swig as blocks
class ofdm_sync_ml(gr.hier_block2):
def __init__(self, fft_length, cp_length, snr, kstime, logging):
@@ -41,13 +35,13 @@ class ofdm_sync_ml(gr.hier_block2):
Signal Processing, vol. 45, no. 7, pp. 1800-1805, 1997.
'''
- gr.hier_block2.__init__(self, "ofdm_sync_ml",
- gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
+ gr.hier_block2.__init__(self, "ofdm_sync_ml",
+ gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_char)) # Output signature
self.input = blocks.add_const_cc(0)
- SNR = 10.0**(snr/10.0)
+ SNR = 10.0**(snr / 10.0)
rho = SNR / (SNR + 1.0)
symbol_length = fft_length + cp_length
@@ -66,15 +60,15 @@ class ofdm_sync_ml(gr.hier_block2):
self.magsqrd2 = blocks.complex_to_mag_squared()
self.adder = blocks.add_ff()
- moving_sum_taps = [rho/2 for i in range(cp_length)]
+ moving_sum_taps = [rho / 2 for i in range(cp_length)]
self.moving_sum_filter = filter.fir_filter_fff(1,moving_sum_taps)
-
+
self.connect(self.input,self.magsqrd1)
self.connect(self.delay,self.magsqrd2)
self.connect(self.magsqrd1,(self.adder,0))
self.connect(self.magsqrd2,(self.adder,1))
self.connect(self.adder,self.moving_sum_filter)
-
+
# Correlation from ML Sync
self.conjg = blocks.conjugate_cc();
@@ -82,7 +76,7 @@ class ofdm_sync_ml(gr.hier_block2):
movingsum2_taps = [1.0 for i in range(cp_length)]
self.movingsum2 = filter.fir_filter_ccf(1,movingsum2_taps)
-
+
# Correlator data handler
self.c2mag = blocks.complex_to_mag()
self.angle = blocks.complex_to_arg()
@@ -104,7 +98,7 @@ class ofdm_sync_ml(gr.hier_block2):
# use the sync loop values to set the sampler and the NCO
# self.diff = theta
# self.angle = epsilon
-
+
self.connect(self.diff, self.pk_detect)
# The DPLL corrects for timing differences between CP correlations
@@ -115,7 +109,7 @@ class ofdm_sync_ml(gr.hier_block2):
self.connect(self.dpll, (self.sample_and_hold,1))
else:
self.connect(self.pk_detect, (self.sample_and_hold,1))
-
+
self.connect(self.angle, (self.sample_and_hold,0))
################################
@@ -130,7 +124,7 @@ class ofdm_sync_ml(gr.hier_block2):
self.div = blocks.divide_ff()
# The output signature of the correlation has a few spikes because the rest of the
- # system uses the repeated preamble symbol. It needs to work that generically if
+ # system uses the repeated preamble symbol. It needs to work that generically if
# anyone wants to use this against a WiMAX-like signal since it, too, repeats.
# The output theta of the correlator above is multiplied with this correlation to
# identify the proper peak and remove other products in this cross-correlation
@@ -139,17 +133,17 @@ class ofdm_sync_ml(gr.hier_block2):
self.f2b = blocks.float_to_char()
self.b2f = blocks.char_to_float()
self.mul = blocks.multiply_ff()
-
+
# Normalize the power of the corr output by the energy. This is not really needed
# and could be removed for performance, but it makes for a cleaner signal.
# if this is removed, the threshold value needs adjustment.
self.connect(self.input, self.kscorr, self.corrmag, (self.div,0))
self.connect(self.moving_sum_filter, (self.div,1))
-
+
self.connect(self.div, (self.mul,0))
self.connect(self.pk_detect, self.b2f, (self.mul,1))
self.connect(self.mul, self.slice)
-
+
# Set output signals
# Output 0: fine frequency correction value
# Output 1: timing signal
diff --git a/gr-digital/python/digital/ofdm_sync_pn.py b/gr-digital/python/digital/ofdm_sync_pn.py
index 0e79c67ca0..1192830679 100644
--- a/gr-digital/python/digital/ofdm_sync_pn.py
+++ b/gr-digital/python/digital/ofdm_sync_pn.py
@@ -1,38 +1,31 @@
#!/usr/bin/env python
#
# Copyright 2007,2008 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import division
+from __future__ import unicode_literals
-import math
-from numpy import fft
-from gnuradio import gr
-try:
- from gnuradio import filter
-except ImportError:
- import filter_swig as filter
+from gnuradio import gr, blocks, filter
-try:
- from gnuradio import blocks
-except ImportError:
- import blocks_swig as blocks
class ofdm_sync_pn(gr.hier_block2):
def __init__(self, fft_length, cp_length, logging=False):
@@ -52,7 +45,7 @@ class ofdm_sync_pn(gr.hier_block2):
# PN Sync
# Create a delay line
- self.delay = blocks.delay(gr.sizeof_gr_complex, fft_length/2)
+ self.delay = blocks.delay(gr.sizeof_gr_complex, fft_length / 2)
# Correlation from ML Sync
self.conjg = blocks.conjugate_cc();
@@ -98,10 +91,10 @@ class ofdm_sync_pn(gr.hier_block2):
self.connect(self.c2mag, (self.normalize,0))
# Create a moving sum filter for the corr output
- matched_filter_taps = [1.0/cp_length for i in range(cp_length)]
+ matched_filter_taps = [1.0 / cp_length for i in range(cp_length)]
self.matched_filter = filter.fir_filter_fff(1,matched_filter_taps)
self.connect(self.normalize, self.matched_filter)
-
+
self.connect(self.matched_filter, self.sub1, self.pk_detect)
#self.connect(self.matched_filter, self.pk_detect)
self.connect(self.pk_detect, (self.sample_and_hold,1))
diff --git a/gr-digital/python/digital/ofdm_sync_pnac.py b/gr-digital/python/digital/ofdm_sync_pnac.py
index 55a6c21f4c..4d756f7ff7 100644
--- a/gr-digital/python/digital/ofdm_sync_pnac.py
+++ b/gr-digital/python/digital/ofdm_sync_pnac.py
@@ -1,38 +1,31 @@
#!/usr/bin/env python
#
# Copyright 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 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import division
+from __future__ import unicode_literals
-import math
-from numpy import fft
-from gnuradio import gr
-try:
- from gnuradio import filter
-except ImportError:
- import filter_swig as filter
+from gnuradio import gr, blocks, filter
-try:
- from gnuradio import blocks
-except ImportError:
- import blocks_swig as blocks
class ofdm_sync_pnac(gr.hier_block2):
def __init__(self, fft_length, cp_length, kstime, logging=False):
@@ -69,9 +62,9 @@ class ofdm_sync_pnac(gr.hier_block2):
kstime = [k.conjugate() for k in kstime[0:fft_length//2]]
kstime.reverse()
self.crosscorr_filter = filter.fir_filter_ccc(1, kstime)
-
+
# Create a delay line
- self.delay = blocks.delay(gr.sizeof_gr_complex, fft_length/2)
+ self.delay = blocks.delay(gr.sizeof_gr_complex, fft_length / 2)
# Correlation from ML Sync
self.conjg = blocks.conjugate_cc();
@@ -105,7 +98,7 @@ class ofdm_sync_pnac(gr.hier_block2):
self.connect(self.corr, self.c2mag)
self.connect(self.corr, self.angle)
self.connect(self.angle, (self.sample_and_hold,0))
-
+
# Get the power of the input signal to compare against the correlation
self.connect(self.crosscorr_filter, self.mag, self.power)
diff --git a/gr-digital/python/digital/ofdm_txrx.py b/gr-digital/python/digital/ofdm_txrx.py
index 6f96fc6287..f90a579385 100644
--- a/gr-digital/python/digital/ofdm_txrx.py
+++ b/gr-digital/python/digital/ofdm_txrx.py
@@ -25,24 +25,21 @@ For simple configurations, no need to connect all the relevant OFDM blocks
to form an OFDM Tx/Rx--simply use these.
"""
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import unicode_literals
+
# Reminder: All frequency-domain stuff is in shifted form, i.e. DC carrier
# in the middle!
+
import numpy
-from gnuradio import gr
-import digital_swig as digital
-from utils import tagged_streams
-try:
- # This will work when feature #505 is added.
- from gnuradio import fft
- from gnuradio import blocks
- from gnuradio import analog
-except ImportError:
- # Until then this will work.
- import fft_swig as fft
- import blocks_swig as blocks
- import analog_swig as analog
+from gnuradio import gr, blocks, fft, analog
+
+from . import digital_swig as digital
+
_def_fft_len = 64
_def_cp_len = 16
@@ -50,7 +47,7 @@ _def_frame_length_tag_key = "frame_length"
_def_packet_length_tag_key = "packet_length"
_def_packet_num_tag_key = "packet_num"
# Data and pilot carriers are same as in 802.11a
-_def_occupied_carriers = (range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),)
+_def_occupied_carriers = (list(range(-26, -21)) + list(range(-20, -7)) + list(range(-6, 0)) + list(range(1, 7)) + list(range(8, 21)) + list(range(22, 27)),)
_def_pilot_carriers=((-21, -7, 7, 21,),)
_pilot_sym_scramble_seq = (
1,1,1,1, -1,-1,-1,1, -1,-1,-1,-1, 1,1,-1,1, -1,-1,1,1, -1,1,1,-1, 1,1,1,1, 1,1,-1,1,
@@ -112,7 +109,7 @@ def _get_constellation(bps):
try:
return constellation[bps]
except KeyError:
- print 'Modulation not supported.'
+ print('Modulation not supported.')
exit(1)
class ofdm_tx(gr.hier_block2):
diff --git a/gr-digital/python/digital/packet_utils.py b/gr-digital/python/digital/packet_utils.py
index de7e2988da..04d27125fa 100644
--- a/gr-digital/python/digital/packet_utils.py
+++ b/gr-digital/python/digital/packet_utils.py
@@ -19,10 +19,18 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import division
+
import struct
+
import numpy
+import six
+
from gnuradio import gru
-import crc
+from . import crc
+
def conv_packed_binary_string_to_1_0_string(s):
"""
@@ -35,7 +43,7 @@ def conv_packed_binary_string_to_1_0_string(s):
t = (x >> i) & 0x1
r.append(t)
- return ''.join(map(lambda x: chr(x + ord('0')), r))
+ return ''.join([chr(x + ord('0')) for x in r])
def conv_1_0_string_to_packed_binary_string(s):
"""
@@ -46,7 +54,7 @@ def conv_1_0_string_to_packed_binary_string(s):
to get to a multiple of 8.
"""
if not is_1_0_string(s):
- raise ValueError, "Input must be a string containing only 0's and 1's"
+ raise ValueError("Input must be a string containing only 0's and 1's")
# pad to multiple of 8
padded = False
@@ -83,7 +91,7 @@ def is_1_0_string(s):
return True
def string_to_hex_list(s):
- return map(lambda x: hex(ord(x)), s)
+ return [hex(ord(x)) for x in s]
def whiten(s, o):
@@ -98,8 +106,8 @@ def dewhiten(s, o):
def make_header(payload_len, whitener_offset=0):
# Upper nibble is offset, lower 12 bits is len
val = ((whitener_offset & 0xf) << 12) | (payload_len & 0x0fff)
- #print "offset =", whitener_offset, " len =", payload_len, " val=", val
- return struct.pack('!HH', val, val)
+ #print("offset =", whitener_offset, " len =", payload_len, " val=", val)
+ return struct.pack(b'!HH', val, val)
def make_packet(payload, samples_per_symbol, bits_per_symbol,
preamble=default_preamble, access_code=default_access_code,
@@ -123,13 +131,13 @@ def make_packet(payload, samples_per_symbol, bits_per_symbol,
and finally CRC-32.
"""
if not is_1_0_string(preamble):
- raise ValueError, "preamble must be a string containing only 0's and 1's (%r)" % (preamble,)
+ raise ValueError("preamble must be a string containing only 0's and 1's (%r)" % (preamble,))
if not is_1_0_string(access_code):
- raise ValueError, "access_code must be a string containing only 0's and 1's (%r)" % (access_code,)
+ raise ValueError("access_code must be a string containing only 0's and 1's (%r)" % (access_code,))
if not whitener_offset >=0 and whitener_offset < 16:
- raise ValueError, "whitener_offset must be between 0 and 15, inclusive (%i)" % (whitener_offset,)
+ raise ValueError("whitener_offset must be between 0 and 15, inclusive (%i)" % (whitener_offset,))
(packed_access_code, padded) = conv_1_0_string_to_packed_binary_string(access_code)
(packed_preamble, ignore) = conv_1_0_string_to_packed_binary_string(preamble)
@@ -138,24 +146,24 @@ def make_packet(payload, samples_per_symbol, bits_per_symbol,
payload_with_crc = crc.gen_and_append_crc32(payload)
else:
payload_with_crc = payload
- #print "outbound crc =", string_to_hex_list(payload_with_crc[-4:])
+ #print("outbound crc =", string_to_hex_list(payload_with_crc[-4:]))
L = len(payload_with_crc)
MAXLEN = len(random_mask_tuple)
if L > MAXLEN:
- raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN,)
+ raise ValueError("len(payload) must be in [0, %d]" % (MAXLEN,))
if whitening:
- pkt = ''.join((packed_preamble, packed_access_code, make_header(L, whitener_offset),
- whiten(payload_with_crc, whitener_offset), '\x55'))
+ pkt = b''.join((packed_preamble, packed_access_code, make_header(L, whitener_offset),
+ whiten(payload_with_crc, whitener_offset), b'\x55'))
else:
- pkt = ''.join((packed_preamble, packed_access_code, make_header(L, whitener_offset),
- (payload_with_crc), '\x55'))
+ pkt = b''.join((packed_preamble, packed_access_code, make_header(L, whitener_offset),
+ (payload_with_crc), b'\x55'))
if pad_for_usrp:
- pkt = pkt + (_npadding_bytes(len(pkt), int(samples_per_symbol), bits_per_symbol) * '\x55')
+ pkt = pkt + (_npadding_bytes(len(pkt), int(samples_per_symbol), bits_per_symbol) * b'\x55')
- #print "make_packet: len(pkt) =", len(pkt)
+ #print("make_packet: len(pkt) =", len(pkt))
return pkt
def _npadding_bytes(pkt_byte_len, samples_per_symbol, bits_per_symbol):
@@ -175,7 +183,7 @@ def _npadding_bytes(pkt_byte_len, samples_per_symbol, bits_per_symbol):
number of bytes of padding to append.
"""
modulus = 128
- byte_modulus = gru.lcm(modulus/8, samples_per_symbol) * bits_per_symbol / samples_per_symbol
+ byte_modulus = gru.lcm(modulus // 8, samples_per_symbol) * bits_per_symbol // samples_per_symbol
r = pkt_byte_len % byte_modulus
if r == 0:
return 0
@@ -206,10 +214,10 @@ def unmake_packet(whitened_payload_with_crc, whitener_offset=0,
ok = True
if 0:
- print "payload_with_crc =", string_to_hex_list(payload_with_crc)
- print "ok = %r, len(payload) = %d" % (ok, len(payload))
- print "payload =", string_to_hex_list(payload)
- print ""
+ print("payload_with_crc =", string_to_hex_list(payload_with_crc))
+ print("ok = %r, len(payload) = %d" % (ok, len(payload)))
+ print("payload =", string_to_hex_list(payload))
+ print("")
return ok, payload
diff --git a/gr-digital/python/digital/pkt.py b/gr-digital/python/digital/pkt.py
index fbdcaa3a66..585a2915c0 100644
--- a/gr-digital/python/digital/pkt.py
+++ b/gr-digital/python/digital/pkt.py
@@ -1,34 +1,34 @@
#
# 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 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import unicode_literals
from math import pi
-from gnuradio import gr
+from gnuradio import gr, blocks
import gnuradio.gr.gr_threading as _threading
-import packet_utils
-import digital_swig as digital
+from . import packet_utils
+from . import digital_swig as digital
-try:
- from gnuradio import blocks
-except ImportError:
- import blocks_swig as blocks
# /////////////////////////////////////////////////////////////////////////////
# mod/demod with packets as i/o
@@ -43,7 +43,7 @@ class mod_pkts(gr.hier_block2):
def __init__(self, modulator, preamble=None, access_code=None, msgq_limit=2,
pad_for_usrp=True, use_whitener_offset=False, modulate=True):
"""
- Hierarchical block for sending packets
+ Hierarchical block for sending packets
Packets to be sent are enqueued by calling send_pkt.
The output is the complex modulated signal at baseband.
@@ -54,29 +54,29 @@ class mod_pkts(gr.hier_block2):
msgq_limit: maximum number of messages in message queue (int)
pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples
use_whitener_offset: If true, start of whitener XOR string is incremented each packet
-
+
See gmsk_mod for remaining parameters
"""
- gr.hier_block2.__init__(self, "mod_pkts",
- gr.io_signature(0, 0, 0), # Input signature
- gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
+ gr.hier_block2.__init__(self, "mod_pkts",
+ gr.io_signature(0, 0, 0), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
self._modulator = modulator
self._pad_for_usrp = pad_for_usrp
self._use_whitener_offset = use_whitener_offset
self._whitener_offset = 0
-
+
if access_code is None:
access_code = packet_utils.default_access_code
if not packet_utils.is_1_0_string(access_code):
- raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,)
+ raise ValueError("Invalid access_code %r. Must be string of 1's and 0's" % (access_code,))
self._access_code = access_code
-
+
if preamble is None:
preamble = packet_utils.default_preamble
if not packet_utils.is_1_0_string(preamble):
- raise ValueError, "Invalid preamble %r. Must be string of 1's and 0's" % (preamble,)
+ raise ValueError("Invalid preamble %r. Must be string of 1's and 0's" % (preamble,))
self._preamble = preamble
# accepts messages from the outside world
@@ -93,7 +93,7 @@ class mod_pkts(gr.hier_block2):
if eof:
msg = gr.message(1) # tell self._pkt_input we're not sending any more packets
else:
- # print "original_payload =", string_to_hex_list(payload)
+ # print("original_payload =", string_to_hex_list(payload))
pkt = packet_utils.make_packet(payload,
self._modulator.samples_per_symbol(),
self._modulator.bits_per_symbol(),
@@ -101,11 +101,11 @@ class mod_pkts(gr.hier_block2):
self._access_code,
self._pad_for_usrp,
self._whitener_offset)
- #print "pkt =", string_to_hex_list(pkt)
+ #print("pkt =", string_to_hex_list(pkt))
msg = gr.message_from_string(pkt)
if self._use_whitener_offset is True:
self._whitener_offset = (self._whitener_offset + 1) % 16
-
+
self._pkt_input.msgq().insert_tail(msg)
@@ -120,9 +120,9 @@ class demod_pkts(gr.hier_block2):
def __init__(self, demodulator, access_code=None, callback=None, threshold=-1):
"""
- Hierarchical block for demodulating and deframing packets.
+ Hierarchical block for demodulating and deframing packets.
- The input is the complex modulated signal at baseband.
+ The input is the complex modulated signal at baseband.
Demodulated packets are sent to the handler.
Args:
@@ -130,17 +130,17 @@ class demod_pkts(gr.hier_block2):
access_code: AKA sync vector (string of 1's and 0's)
callback: function of two args: ok, payload (ok: bool; payload: string)
threshold: detect access_code with up to threshold bits wrong (-1 -> use default) (int)
- """
+ """
- gr.hier_block2.__init__(self, "demod_pkts",
- gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
- gr.io_signature(0, 0, 0)) # Output signature
+ gr.hier_block2.__init__(self, "demod_pkts",
+ gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
+ gr.io_signature(0, 0, 0)) # Output signature
self._demodulator = demodulator
if access_code is None:
access_code = packet_utils.default_access_code
if not packet_utils.is_1_0_string(access_code):
- raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,)
+ raise ValueError("Invalid access_code %r. Must be string of 1's and 0's" % (access_code,))
self._access_code = access_code
if threshold == -1:
@@ -151,7 +151,7 @@ class demod_pkts(gr.hier_block2):
self.framer_sink = digital.framer_sink_1(self._rcvd_pktq)
self.connect(self, self._demodulator, self.correlator, self.framer_sink)
-
+
self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback)
diff --git a/gr-digital/python/digital/psk.py b/gr-digital/python/digital/psk.py
index 0e0c65ea2b..5518ba55f3 100644
--- a/gr-digital/python/digital/psk.py
+++ b/gr-digital/python/digital/psk.py
@@ -1,36 +1,40 @@
#
# Copyright 2005,2006,2011 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
"""
PSK modulation and demodulation.
"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import unicode_literals
+
from math import pi, log
from cmath import exp
-import digital_swig
-import modulation_utils
-from utils import mod_codes, gray_code
-from generic_mod_demod import generic_mod, generic_demod
-from generic_mod_demod import shared_mod_args, shared_demod_args
+from . import digital_swig
+from . import modulation_utils
+from .utils import mod_codes, gray_code
+from .generic_mod_demod import generic_mod, generic_demod
+from .generic_mod_demod import shared_mod_args, shared_demod_args
# Default number of points in constellation.
_def_constellation_points = 4
@@ -56,7 +60,7 @@ def create_encodings(mod_code, arity, differential):
else:
raise ValueError('That modulation code is not implemented for this constellation.')
return (pre_diff_code, post_diff_code)
-
+
# /////////////////////////////////////////////////////////////////////////////
# PSK constellation
# /////////////////////////////////////////////////////////////////////////////
@@ -68,7 +72,7 @@ def psk_constellation(m=_def_constellation_points, mod_code=_def_mod_code,
"""
k = log(m) / log(2.0)
if (k != int(k)):
- raise StandardError('Number of constellation points must be a power of two.')
+ raise Exception('Number of constellation points must be a power of two.')
points = [exp(2*pi*(0+1j)*i/m) for i in range(0,m)]
pre_diff_code, post_diff_code = create_encodings(mod_code, m, differential)
if post_diff_code is not None:
@@ -84,7 +88,7 @@ def psk_constellation(m=_def_constellation_points, mod_code=_def_mod_code,
class psk_mod(generic_mod):
"""
Hierarchical block for RRC-filtered PSK modulation.
-
+
The input is a byte stream (unsigned char), treated as a series of packed
symbols. Symbols are grouped from MSB to LSB.
@@ -118,7 +122,7 @@ class psk_demod(generic_demod):
"""
Hierarchical block for RRC-filtered PSK modulation.
-
+
The input is a complex modulated signal at baseband.
The output is a stream of bytes, each representing a recovered bit.
diff --git a/gr-digital/python/digital/psk_constellations.py b/gr-digital/python/digital/psk_constellations.py
index ee3c2e6070..781b076f18 100755..100644
--- a/gr-digital/python/digital/psk_constellations.py
+++ b/gr-digital/python/digital/psk_constellations.py
@@ -20,8 +20,10 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import absolute_import
+from __future__ import unicode_literals
import numpy
-from constellation_map_generator import constellation_map_generator
+from .constellation_map_generator import constellation_map_generator
'''
Note on the naming scheme. Each constellation is named using a prefix
diff --git a/gr-digital/python/digital/qa_binary_slicer_fb.py b/gr-digital/python/digital/qa_binary_slicer_fb.py
index 93e12dbb8d..0b2879380b 100755..100644
--- a/gr-digital/python/digital/qa_binary_slicer_fb.py
+++ b/gr-digital/python/digital/qa_binary_slicer_fb.py
@@ -1,24 +1,25 @@
#!/usr/bin/env python
#
# Copyright 2011-2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
import random
@@ -33,8 +34,8 @@ class test_binary_slicer_fb(gr_unittest.TestCase):
self.tb = None
def test_binary_slicer_fb(self):
- expected_result = ( 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1)
- src_data = (-1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1)
+ expected_result = ( 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1)
+ src_data = (-1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1)
src_data = [s + (1 - random.random()) for s in src_data] # add some noise
src = blocks.vector_source_f(src_data)
op = digital.binary_slicer_fb()
@@ -45,11 +46,10 @@ class test_binary_slicer_fb(gr_unittest.TestCase):
self.tb.run() # run the graph and wait for it to finish
actual_result = dst.data() # fetch the contents of the sink
- #print "actual result", actual_result
- #print "expected result", expected_result
+ #print "actual result", actual_result
+ #print "expected result", expected_result
self.assertFloatTuplesAlmostEqual(expected_result, actual_result)
if __name__ == '__main__':
gr_unittest.run(test_binary_slicer_fb, "test_binary_slicer_fb.xml")
-
diff --git a/gr-digital/python/digital/qa_burst_shaper.py b/gr-digital/python/digital/qa_burst_shaper.py
index 36c6d06479..949a5f573d 100755..100644
--- a/gr-digital/python/digital/qa_burst_shaper.py
+++ b/gr-digital/python/digital/qa_burst_shaper.py
@@ -21,6 +21,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest
from gnuradio import blocks, digital
import pmt
@@ -121,7 +122,7 @@ class qa_burst_shaper (gr_unittest.TestCase):
window = np.concatenate((-2.0*np.ones(5), -4.0*np.ones(5)))
tags = (make_length_tag(0, length),)
phasing = np.zeros(5)
- for i in xrange(5):
+ for i in range(5):
phasing[i] = ((-1.0)**i)
expected = np.concatenate((np.zeros(prepad), phasing*window[0:5],
np.ones(length), phasing*window[5:10],
@@ -154,7 +155,7 @@ class qa_burst_shaper (gr_unittest.TestCase):
-4.0*np.ones(5, dtype=complex)))
tags = (make_length_tag(0, length),)
phasing = np.zeros(5, dtype=complex)
- for i in xrange(5):
+ for i in range(5):
phasing[i] = complex((-1.0)**i)
expected = np.concatenate((np.zeros(prepad, dtype=complex),
phasing*window[0:5],
@@ -264,7 +265,7 @@ class qa_burst_shaper (gr_unittest.TestCase):
# checks
self.assertFloatTuplesAlmostEqual(sink.data(), expected, 6)
- for i in xrange(len(etags)):
+ for i in range(len(etags)):
self.assertTrue(compare_tags(sink.tags()[i], etags[i]))
def test_tag_gap (self):
@@ -303,7 +304,7 @@ class qa_burst_shaper (gr_unittest.TestCase):
# checks
self.assertFloatTuplesAlmostEqual(sink.data(), expected, 6)
- for i in xrange(len(etags)):
+ for i in range(len(etags)):
self.assertTrue(compare_tags(sink.tags()[i], etags[i]))
def test_tag_propagation (self):
diff --git a/gr-digital/python/digital/qa_chunks_to_symbols.py b/gr-digital/python/digital/qa_chunks_to_symbols.py
index 0d80f71d6c..8a4266617f 100755..100644
--- a/gr-digital/python/digital/qa_chunks_to_symbols.py
+++ b/gr-digital/python/digital/qa_chunks_to_symbols.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
import pmt
from gnuradio import gr, gr_unittest, digital, blocks
@@ -138,12 +139,12 @@ class test_chunks_to_symbols(gr_unittest.TestCase):
def test_sf_callback(self):
- constA = [-3, -1, 1, 3]
+ constA = [-3, -1, 1, 3]
constB = [12, -12, 6, -6]
src_data = (0, 1, 2, 3, 3, 2, 1, 0)
expected_result=(12, -12, 6, -6, -6, 6, -12, 12)
- src = blocks.vector_source_s(src_data, False, 1, "")
+ src = blocks.vector_source_s(src_data, False, 1, "")
op = digital.chunks_to_symbols_sf(constA)
op.set_symbol_table(constB)
dst = blocks.vector_sink_f()
@@ -159,7 +160,7 @@ class test_chunks_to_symbols(gr_unittest.TestCase):
src_data = (0, 1, 2, 3, 3, 2, 1, 0)
expected_result=(12.0+1j, -12.0-1j, 6.0+1j, -6-1j, -6-1j, 6+1j, -12-1j, 12+1j)
- src = blocks.vector_source_s(src_data, False, 1, "")
+ src = blocks.vector_source_s(src_data, False, 1, "")
op = digital.chunks_to_symbols_sc(constA)
op.set_symbol_table(constB)
dst = blocks.vector_sink_c()
diff --git a/gr-digital/python/digital/qa_clock_recovery_mm.py b/gr-digital/python/digital/qa_clock_recovery_mm.py
index 878ea25c6c..0618ec321c 100755..100644
--- a/gr-digital/python/digital/qa_clock_recovery_mm.py
+++ b/gr-digital/python/digital/qa_clock_recovery_mm.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
import random
import cmath
diff --git a/gr-digital/python/digital/qa_cma_equalizer.py b/gr-digital/python/digital/qa_cma_equalizer.py
index 6da391f70c..228d951640 100755..100644
--- a/gr-digital/python/digital/qa_cma_equalizer.py
+++ b/gr-digital/python/digital/qa_cma_equalizer.py
@@ -1,48 +1,49 @@
#!/usr/bin/env python
#
# Copyright 2006,2007,2010,2011,2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
from gnuradio import gr, gr_unittest, digital, blocks
class test_cma_equalizer_fir(gr_unittest.TestCase):
def setUp(self):
- self.tb = gr.top_block()
+ self.tb = gr.top_block()
def tearDown(self):
- self.tb = None
-
+ self.tb = None
+
def transform(self, src_data):
- SRC = blocks.vector_source_c(src_data, False)
- EQU = digital.cma_equalizer_cc(4, 1.0, .001, 1)
- DST = blocks.vector_sink_c()
- self.tb.connect(SRC, EQU, DST)
- self.tb.run()
- return DST.data()
+ SRC = blocks.vector_source_c(src_data, False)
+ EQU = digital.cma_equalizer_cc(4, 1.0, .001, 1)
+ DST = blocks.vector_sink_c()
+ self.tb.connect(SRC, EQU, DST)
+ self.tb.run()
+ return DST.data()
def test_001_identity(self):
- # Constant modulus signal so no adjustments
- src_data = (1+0j, 0+1j, -1+0j, 0-1j)*1000
- expected_data = src_data
- result = self.transform(src_data)
+ # Constant modulus signal so no adjustments
+ src_data = (1+0j, 0+1j, -1+0j, 0-1j)*1000
+ expected_data = src_data
+ result = self.transform(src_data)
N = -500
self.assertComplexTuplesAlmostEqual(expected_data[N:], result[N:])
diff --git a/gr-digital/python/digital/qa_constellation.py b/gr-digital/python/digital/qa_constellation.py
index 42e49bb059..3436ce6f45 100644
--- a/gr-digital/python/digital/qa_constellation.py
+++ b/gr-digital/python/digital/qa_constellation.py
@@ -20,6 +20,8 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import division
+
import random, math
from cmath import exp, pi, log, sqrt
@@ -51,7 +53,7 @@ def twod_constell():
def threed_constell():
oned_points = ((1+0j), (0+1j), (-1+0j), (0-1j))
points = []
- r4 = range(0, 4)
+ r4 = list(range(0, 4))
for ia in r4:
for ib in r4:
for ic in r4:
@@ -143,7 +145,7 @@ def tested_constellations(easy=True, medium=True, difficult=True):
diff_poss = (True, False)
else:
diff_poss = (False,)
- poss_args = [[argname, argvalues, 0] for argname, argvalues in poss_args.items()]
+ poss_args = [[argname, argvalues, 0] for argname, argvalues in list(poss_args.items())]
for current_diff in diff_poss:
# Add an index into args to keep track of current position in argvalues
while True:
@@ -211,7 +213,7 @@ class test_constellation(gr_unittest.TestCase):
table = digital.soft_dec_table_generator(digital.sd_psk_4_0, prec, Es)
c.set_soft_dec_lut(table, prec)
- x = sqrt(2.0)/2.0
+ x = sqrt(2.0) / 2.0
step = (x.real+x.real) / (2**prec - 1)
samples = [ -x-x*1j, -x+x*1j,
x+x*1j, x-x*1j,
@@ -253,7 +255,7 @@ class test_constellation(gr_unittest.TestCase):
table = digital.soft_dec_table(constel, code, prec)
c.gen_soft_dec_lut(prec)
- x = sqrt(2.0)/2.0
+ x = sqrt(2.0) / 2.0
step = (x.real+x.real) / (2**prec - 1)
samples = [ -x-x*1j, -x+x*1j,
x+x*1j, x-x*1j,
@@ -293,7 +295,7 @@ class test_constellation(gr_unittest.TestCase):
table = digital.soft_dec_table(constel, code, prec)
c.gen_soft_dec_lut(prec)
- x = sqrt(2.0)/2.0
+ x = sqrt(2.0) / 2.0
step = (x.real+x.real) / (2**prec - 1)
samples = [ -x-x*1j, -x+x*1j,
x+x*1j, x-x*1j,
@@ -322,9 +324,9 @@ class mod_demod(gr.hier_block2):
# that they can work with shorts and ints as well as chars.
raise ValueError("Constellation cannot contain more than 256 points.")
- gr.hier_block2.__init__(self, "mod_demod",
- gr.io_signature(1, 1, gr.sizeof_char), # Input signature
- gr.io_signature(1, 1, gr.sizeof_char)) # Output signature
+ gr.hier_block2.__init__(self, "mod_demod",
+ gr.io_signature(1, 1, gr.sizeof_char), # Input signature
+ gr.io_signature(1, 1, gr.sizeof_char)) # Output signature
arity = constellation.arity()
diff --git a/gr-digital/python/digital/qa_constellation_decoder_cb.py b/gr-digital/python/digital/qa_constellation_decoder_cb.py
index d3fbce91ba..e7350be553 100755..100644
--- a/gr-digital/python/digital/qa_constellation_decoder_cb.py
+++ b/gr-digital/python/digital/qa_constellation_decoder_cb.py
@@ -1,24 +1,25 @@
#!/usr/bin/env python
#
# Copyright 2004,2007,2010-2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
from gnuradio import gr, gr_unittest, digital, blocks
@@ -32,9 +33,9 @@ class test_constellation_decoder(gr_unittest.TestCase):
def test_constellation_decoder_cb_bpsk(self):
cnst = digital.constellation_bpsk()
- src_data = (0.5 + 0.5j, 0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j,
+ src_data = (0.5 + 0.5j, 0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j,
0.8 + 1.0j, -0.5 + 0.1j, 0.1 - 1.2j)
- expected_result = ( 1, 1, 0, 0,
+ expected_result = ( 1, 1, 0, 0,
1, 0, 1)
src = blocks.vector_source_c(src_data)
op = digital.constellation_decoder_cb(cnst.base())
@@ -45,18 +46,18 @@ class test_constellation_decoder(gr_unittest.TestCase):
self.tb.run() # run the graph and wait for it to finish
actual_result = dst.data() # fetch the contents of the sink
- #print "actual result", actual_result
- #print "expected result", expected_result
+ #print "actual result", actual_result
+ #print "expected result", expected_result
self.assertFloatTuplesAlmostEqual(expected_result, actual_result)
def _test_constellation_decoder_cb_qpsk(self):
cnst = digital.constellation_qpsk()
- src_data = (0.5 + 0.5j, 0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j,
+ src_data = (0.5 + 0.5j, 0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j,
0.8 + 1.0j, -0.5 + 0.1j, 0.1 - 1.2j)
- expected_result = ( 3, 1, 0, 2,
+ expected_result = ( 3, 1, 0, 2,
3, 2, 1)
src = blocks.vector_source_c(src_data)
- op = digital_swig.constellation_decoder_cb(cnst.base())
+ op = digital.constellation_decoder_cb(cnst.base())
dst = blocks.vector_sink_b()
self.tb.connect(src, op)
@@ -64,11 +65,10 @@ class test_constellation_decoder(gr_unittest.TestCase):
self.tb.run() # run the graph and wait for it to finish
actual_result = dst.data() # fetch the contents of the sink
- #print "actual result", actual_result
- #print "expected result", expected_result
+ #print "actual result", actual_result
+ #print "expected result", expected_result
self.assertFloatTuplesAlmostEqual(expected_result, actual_result)
if __name__ == '__main__':
gr_unittest.run(test_constellation_decoder, "test_constellation_decoder.xml")
-
diff --git a/gr-digital/python/digital/qa_constellation_receiver.py b/gr-digital/python/digital/qa_constellation_receiver.py
index f0d7275d34..4850863fa5 100755..100644
--- a/gr-digital/python/digital/qa_constellation_receiver.py
+++ b/gr-digital/python/digital/qa_constellation_receiver.py
@@ -1,24 +1,28 @@
#!/usr/bin/env python
#
# Copyright 2011,2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import print_function
+from __future__ import absolute_import
+
import random
import math
@@ -53,12 +57,13 @@ TIMING_OFFSET = 1.0
FREQ_BW = 2*math.pi/100.0
PHASE_BW = 2*math.pi/100.0
+
class channel_model(gr.hier_block2):
def __init__(self, noise_voltage, freq, timing):
- gr.hier_block2.__init__(self, "channel_model",
- gr.io_signature(1, 1, gr.sizeof_gr_complex),
+ gr.hier_block2.__init__(self, "channel_model",
+ gr.io_signature(1, 1, gr.sizeof_gr_complex),
gr.io_signature(1, 1, gr.sizeof_gr_complex))
-
+
timing_offset = filter.mmse_resampler_cc(0, timing)
noise_adder = blocks.add_cc()
@@ -74,16 +79,16 @@ class channel_model(gr.hier_block2):
self.connect(mixer_offset, (noise_adder,1))
self.connect(noise, (noise_adder,0))
self.connect(noise_adder, self)
-
+
class test_constellation_receiver(gr_unittest.TestCase):
-
+
# We ignore the first half of the output data since often it takes
# a while for the receiver to lock on.
ignore_fraction = 0.8
max_data_length = DATA_LENGTH * 6
max_num_samples = 1000
-
+
def test_basic(self):
"""
Tests a bunch of different constellations by using generic
@@ -172,7 +177,7 @@ class rec_test_tb(gr.top_block):
super(rec_test_tb, self).__init__()
# Transmission Blocks
if src_data is None:
- self.src_data = tuple([rndm.randint(0,1) for i in range(0, data_length)])
+ self.src_data = tuple([random.randint(0,1) for i in range(0, data_length)])
else:
self.src_data = src_data
packer = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
@@ -182,7 +187,7 @@ class rec_test_tb(gr.top_block):
if freq_offset:
channel = channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET, TIMING_OFFSET)
else:
- channel = channel_model(NOISE_VOLTAGE, 0, TIMING_OFFSET)
+ channel = channel_model(NOISE_VOLTAGE, 0, TIMING_OFFSET)
# Receiver Blocks
if freq_offset:
demod = generic_demod(constellation, differential=differential,
diff --git a/gr-digital/python/digital/qa_constellation_soft_decoder_cf.py b/gr-digital/python/digital/qa_constellation_soft_decoder_cf.py
index 872aed0157..629d52c0a4 100644
--- a/gr-digital/python/digital/qa_constellation_soft_decoder_cf.py
+++ b/gr-digital/python/digital/qa_constellation_soft_decoder_cf.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
from math import sqrt
from numpy import random, vectorize
@@ -36,7 +37,7 @@ class test_constellation_soft_decoder(gr_unittest.TestCase):
cnst_pts, code = const_gen()
Es = max([abs(c) for c in cnst_pts])
lut = digital.soft_dec_table_generator(const_sd_gen, prec, Es)
- expected_result = list()
+ expected_result = list()
for s in src_data:
res = digital.calc_soft_dec_from_table(s, lut, prec, sqrt(2.0))
expected_result += res
@@ -52,14 +53,14 @@ class test_constellation_soft_decoder(gr_unittest.TestCase):
self.tb.run()
actual_result = dst.data() # fetch the contents of the sink
- #print "actual result", actual_result
- #print "expected result", expected_result
+ #print "actual result", actual_result
+ #print "expected result", expected_result
self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 5)
def helper_no_lut(self, prec, src_data, const_gen, const_sd_gen):
cnst_pts, code = const_gen()
cnst = digital.constellation_calcdist(cnst_pts, code, 2, 1)
- expected_result = list()
+ expected_result = list()
for s in src_data:
res = digital.calc_soft_dec(s, cnst.points(), code)
expected_result += res
@@ -73,8 +74,8 @@ class test_constellation_soft_decoder(gr_unittest.TestCase):
self.tb.run()
actual_result = dst.data() # fetch the contents of the sink
- #print "actual result", actual_result
- #print "expected result", expected_result
+ #print "actual result", actual_result
+ #print "expected result", expected_result
# Double vs. float precision issues between Python and C++, so
# use only 4 decimals in comparisons.
diff --git a/gr-digital/python/digital/qa_correlate_access_code.py b/gr-digital/python/digital/qa_correlate_access_code.py
index 0302e81313..405147b987 100755..100644
--- a/gr-digital/python/digital/qa_correlate_access_code.py
+++ b/gr-digital/python/digital/qa_correlate_access_code.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
default_access_code = '\xAC\xDD\xA4\xE2\xF2\x8C\x20\xFC'
@@ -35,7 +36,7 @@ def string_to_1_0_list(s):
return r
def to_1_0_string(L):
- return ''.join(map(lambda x: chr(x + ord('0')), L))
+ return ''.join([chr(x + ord('0')) for x in L])
class test_correlate_access_code(gr_unittest.TestCase):
diff --git a/gr-digital/python/digital/qa_correlate_access_code_XX_ts.py b/gr-digital/python/digital/qa_correlate_access_code_XX_ts.py
index 5429ce1e07..7666c3bda8 100755..100644
--- a/gr-digital/python/digital/qa_correlate_access_code_XX_ts.py
+++ b/gr-digital/python/digital/qa_correlate_access_code_XX_ts.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
import pmt
@@ -35,7 +36,7 @@ def string_to_1_0_list(s):
return r
def to_1_0_string(L):
- return ''.join(map(lambda x: chr(x + ord('0')), L))
+ return ''.join([chr(x + ord('0')) for x in L])
class test_correlate_access_code_XX_ts(gr_unittest.TestCase):
@@ -51,7 +52,7 @@ class test_correlate_access_code_XX_ts(gr_unittest.TestCase):
packet = header + payload
pad = (0,) * 64
src_data = (0, 0, 1, 1, 1, 1, 0, 1, 1) + tuple(string_to_1_0_list(packet)) + pad
- expected = tuple(map(long, src_data[9+32:-len(pad)]))
+ expected = tuple(map(int, src_data[9+32:-len(pad)]))
src = blocks.vector_source_b(src_data)
op = digital.correlate_access_code_bb_ts("1011", 0, "sync")
dst = blocks.vector_sink_b()
diff --git a/gr-digital/python/digital/qa_correlate_access_code_tag.py b/gr-digital/python/digital/qa_correlate_access_code_tag.py
index 378333c286..be5848d9a9 100755..100644
--- a/gr-digital/python/digital/qa_correlate_access_code_tag.py
+++ b/gr-digital/python/digital/qa_correlate_access_code_tag.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
default_access_code = '\xAC\xDD\xA4\xE2\xF2\x8C\x20\xFC'
@@ -35,7 +36,7 @@ def string_to_1_0_list(s):
return r
def to_1_0_string(L):
- return ''.join(map(lambda x: chr(x + ord('0')), L))
+ return ''.join([chr(x + ord('0')) for x in L])
class test_correlate_access_code(gr_unittest.TestCase):
diff --git a/gr-digital/python/digital/qa_costas_loop_cc.py b/gr-digital/python/digital/qa_costas_loop_cc.py
index e48f45cc22..283a9199df 100755..100644
--- a/gr-digital/python/digital/qa_costas_loop_cc.py
+++ b/gr-digital/python/digital/qa_costas_loop_cc.py
@@ -20,6 +20,8 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import division
+
import random
import cmath
@@ -57,7 +59,7 @@ class test_costas_loop_cc(gr_unittest.TestCase):
order = 2
self.test = digital.costas_loop_cc(natfreq, order)
- data = [complex(2*random.randint(0,1)-1, 0) for i in xrange(100)]
+ data = [complex(2*random.randint(0,1)-1, 0) for i in range(100)]
self.src = blocks.vector_source_c(data, False)
self.snk = blocks.vector_sink_c()
@@ -76,7 +78,7 @@ class test_costas_loop_cc(gr_unittest.TestCase):
self.test = digital.costas_loop_cc(natfreq, order)
rot = cmath.exp(0.2j) # some small rotation
- data = [complex(2*random.randint(0,1)-1, 0) for i in xrange(100)]
+ data = [complex(2*random.randint(0,1)-1, 0) for i in range(100)]
N = 40 # settling time
expected_result = data[N:]
@@ -102,7 +104,7 @@ class test_costas_loop_cc(gr_unittest.TestCase):
rot = cmath.exp(0.2j) # some small rotation
data = [complex(2*random.randint(0,1)-1, 2*random.randint(0,1)-1)
- for i in xrange(100)]
+ for i in range(100)]
N = 40 # settling time
expected_result = data[N:]
@@ -126,9 +128,9 @@ class test_costas_loop_cc(gr_unittest.TestCase):
order = 8
self.test = digital.costas_loop_cc(natfreq, order)
- rot = cmath.exp(-cmath.pi/8.0j) # rotate to match Costas rotation
+ rot = cmath.exp(-cmath.pi / 8.0j) # rotate to match Costas rotation
const = psk.psk_constellation(order)
- data = [random.randint(0,7) for i in xrange(100)]
+ data = [random.randint(0,7) for i in range(100)]
data = [2*rot*const.points()[d] for d in data]
N = 40 # settling time
diff --git a/gr-digital/python/digital/qa_cpm.py b/gr-digital/python/digital/qa_cpm.py
index 6468ed507b..47a6fa23b4 100755..100644
--- a/gr-digital/python/digital/qa_cpm.py
+++ b/gr-digital/python/digital/qa_cpm.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
import numpy
from gnuradio import gr, gr_unittest, digital, analog, blocks
diff --git a/gr-digital/python/digital/qa_crc32.py b/gr-digital/python/digital/qa_crc32.py
index 9252825ad6..6d3d2fa3ce 100755..100644
--- a/gr-digital/python/digital/qa_crc32.py
+++ b/gr-digital/python/digital/qa_crc32.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
import random
import cmath
diff --git a/gr-digital/python/digital/qa_crc32_bb.py b/gr-digital/python/digital/qa_crc32_bb.py
index 5e45bfb1b0..53ea6f3deb 100755..100644
--- a/gr-digital/python/digital/qa_crc32_bb.py
+++ b/gr-digital/python/digital/qa_crc32_bb.py
@@ -19,6 +19,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, blocks, digital
import pmt
@@ -33,7 +34,7 @@ class qa_crc32_bb (gr_unittest.TestCase):
def test_001_crc_len (self):
""" Make sure the output of a CRC set is 4 bytes longer than the input. """
- data = range(16)
+ data = list(range(16))
src = blocks.vector_source_b(data)
crc = digital.crc32_bb(False, self.tsb_key)
sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
@@ -69,7 +70,7 @@ class qa_crc32_bb (gr_unittest.TestCase):
def test_003_crc_correct_lentag (self):
tag_name = "length"
pack_len = 8
- packets = range(pack_len*2)
+ packets = list(range(pack_len*2))
tag1 = gr.tag_t()
tag1.offset = 0
tag1.key = pmt.string_to_symbol(tag_name)
@@ -107,7 +108,7 @@ class qa_crc32_bb (gr_unittest.TestCase):
tags_found = {'tag1': False, 'tag2': False, 'tag3': False}
for tag in sink.tags():
key = pmt.symbol_to_string(tag.key)
- if key in correct_offsets.keys():
+ if key in list(correct_offsets.keys()):
tags_found[key] = True
self.assertEqual(correct_offsets[key], tag.offset)
self.assertTrue(all(tags_found.values()))
@@ -160,7 +161,7 @@ class qa_crc32_bb (gr_unittest.TestCase):
def test_006_crc_len (self):
""" Make sure the output of a CRC set is 32 (unpacked) bytes longer than the input. """
- data = range(16)
+ data = list(range(16))
src = blocks.vector_source_b(data)
crc = digital.crc32_bb(False, self.tsb_key, False)
sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
@@ -196,7 +197,7 @@ class qa_crc32_bb (gr_unittest.TestCase):
def test_008_crc_correct_lentag (self):
tag_name = "length"
pack_len = 8
- packets = range(pack_len*2)
+ packets = list(range(pack_len*2))
tag1 = gr.tag_t()
tag1.offset = 0
tag1.key = pmt.string_to_symbol(tag_name)
@@ -234,7 +235,7 @@ class qa_crc32_bb (gr_unittest.TestCase):
tags_found = {'tag1': False, 'tag2': False, 'tag3': False}
for tag in sink.tags():
key = pmt.symbol_to_string(tag.key)
- if key in correct_offsets.keys():
+ if key in list(correct_offsets.keys()):
tags_found[key] = True
self.assertEqual(correct_offsets[key], tag.offset)
self.assertTrue(all(tags_found.values()))
diff --git a/gr-digital/python/digital/qa_diff_encoder.py b/gr-digital/python/digital/qa_diff_encoder.py
index 410b937fbc..58d757d0c2 100755..100644
--- a/gr-digital/python/digital/qa_diff_encoder.py
+++ b/gr-digital/python/digital/qa_diff_encoder.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
import random
from gnuradio import gr, gr_unittest, digital, blocks
diff --git a/gr-digital/python/digital/qa_diff_phasor_cc.py b/gr-digital/python/digital/qa_diff_phasor_cc.py
index 7cae4870cc..72063cf92c 100755..100644
--- a/gr-digital/python/digital/qa_diff_phasor_cc.py
+++ b/gr-digital/python/digital/qa_diff_phasor_cc.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
class test_diff_phasor(gr_unittest.TestCase):
diff --git a/gr-digital/python/digital/qa_digital.py b/gr-digital/python/digital/qa_digital.py
index 63a167dece..d443b08fde 100755..100644
--- a/gr-digital/python/digital/qa_digital.py
+++ b/gr-digital/python/digital/qa_digital.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital
class test_digital(gr_unittest.TestCase):
diff --git a/gr-digital/python/digital/qa_fll_band_edge.py b/gr-digital/python/digital/qa_fll_band_edge.py
index 17c5fa85f8..a4859565ec 100755..100644
--- a/gr-digital/python/digital/qa_fll_band_edge.py
+++ b/gr-digital/python/digital/qa_fll_band_edge.py
@@ -20,6 +20,8 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import division
+
import random
import math
@@ -48,7 +50,7 @@ class test_fll_band_edge_cc(gr_unittest.TestCase):
# Create a set of 1's and -1's, pulse shape and interpolate to sps
random.seed(0)
- data = [2.0*random.randint(0, 2) - 1.0 for i in xrange(200)]
+ data = [2.0*random.randint(0, 2) - 1.0 for i in range(200)]
self.src = blocks.vector_source_c(data, False)
self.rrc = filter.interp_fir_filter_ccf(sps, rrc_taps)
diff --git a/gr-digital/python/digital/qa_framer_sink.py b/gr-digital/python/digital/qa_framer_sink.py
index 4b260c14ec..555bc121f8 100755..100644
--- a/gr-digital/python/digital/qa_framer_sink.py
+++ b/gr-digital/python/digital/qa_framer_sink.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
default_access_code = '\xAC\xDD\xA4\xE2\xF2\x8C\x20\xFC'
@@ -34,7 +35,7 @@ def string_to_1_0_list(s):
return r
def to_1_0_string(L):
- return ''.join(map(lambda x: chr(x + ord('0')), L))
+ return ''.join([chr(x + ord('0')) for x in L])
class test_framker_sink(gr_unittest.TestCase):
diff --git a/gr-digital/python/digital/qa_glfsr_source.py b/gr-digital/python/digital/qa_glfsr_source.py
index f39c408198..2c1921e117 100755..100644
--- a/gr-digital/python/digital/qa_glfsr_source.py
+++ b/gr-digital/python/digital/qa_glfsr_source.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
class test_glfsr_source(gr_unittest.TestCase):
@@ -32,8 +33,8 @@ class test_glfsr_source(gr_unittest.TestCase):
def test_000_make_b(self):
src = digital.glfsr_source_b(16)
- self.assertEquals(src.mask(), 0x8016)
- self.assertEquals(src.period(), 2**16-1)
+ self.assertEqual(src.mask(), 0x8016)
+ self.assertEqual(src.period(), 2**16-1)
def test_001_degree_b(self):
self.assertRaises(RuntimeError,
@@ -46,11 +47,11 @@ class test_glfsr_source(gr_unittest.TestCase):
src = digital.glfsr_source_b(degree, False)
b2f = digital.chunks_to_symbols_bf((-1.0,1.0), 1)
dst = blocks.vector_sink_f()
- del self.tb # Discard existing top block
- self.tb = gr.top_block()
+ del self.tb # Discard existing top block
+ self.tb = gr.top_block()
self.tb.connect(src, b2f, dst)
self.tb.run()
- self.tb.disconnect_all()
+ self.tb.disconnect_all()
actual_result = dst.data()
R = auto_correlate(actual_result)
self.assertEqual(R[0], float(len(R))) # Auto-correlation peak at origin
@@ -59,8 +60,8 @@ class test_glfsr_source(gr_unittest.TestCase):
def test_003_make_f(self):
src = digital.glfsr_source_f(16)
- self.assertEquals(src.mask(), 0x8016)
- self.assertEquals(src.period(), 2**16-1)
+ self.assertEqual(src.mask(), 0x8016)
+ self.assertEqual(src.period(), 2**16-1)
def test_004_degree_f(self):
self.assertRaises(RuntimeError,
@@ -71,8 +72,8 @@ class test_glfsr_source(gr_unittest.TestCase):
for degree in range(1,11): # Higher degrees take too long to correlate
src = digital.glfsr_source_f(degree, False)
dst = blocks.vector_sink_f()
- del self.tb # Discard existing top block
- self.tb = gr.top_block()
+ del self.tb # Discard existing top block
+ self.tb = gr.top_block()
self.tb.connect(src, dst)
self.tb.run()
diff --git a/gr-digital/python/digital/qa_hdlc_framer.py b/gr-digital/python/digital/qa_hdlc_framer.py
index 6fed264546..4aa8280e83 100755..100644
--- a/gr-digital/python/digital/qa_hdlc_framer.py
+++ b/gr-digital/python/digital/qa_hdlc_framer.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
import pmt
import numpy
@@ -45,7 +46,7 @@ class test_hdlc_framer(gr_unittest.TestCase):
self.tb.msg_connect(deframe, "out", debug, "store")
self.tb.start()
msg = pmt.cons(pmt.PMT_NIL, pmt.init_u8vector(len(src_data),src_data))
- for i in xrange(npkts):
+ for i in range(npkts):
frame.to_basic_block()._post(pmt.intern("in"), msg)
sleep(0.2)
self.tb.stop()
@@ -53,7 +54,7 @@ class test_hdlc_framer(gr_unittest.TestCase):
rxmsg = debug.get_message(0)
result_len = pmt.blob_length(pmt.cdr(rxmsg))
msg_data = []
- for j in xrange(result_len):
+ for j in range(result_len):
msg_data.append(pmt.u8vector_ref(pmt.cdr(rxmsg), j))
self.assertEqual(src_data, msg_data)
diff --git a/gr-digital/python/digital/qa_header_payload_demux.py b/gr-digital/python/digital/qa_header_payload_demux.py
index f36d71067c..d77f7c689d 100755..100644
--- a/gr-digital/python/digital/qa_header_payload_demux.py
+++ b/gr-digital/python/digital/qa_header_payload_demux.py
@@ -20,15 +20,19 @@
#
from __future__ import print_function
+from __future__ import division
+
import time
import random
import numpy
+
from gnuradio import gr
from gnuradio import gr_unittest
from gnuradio import digital
from gnuradio import blocks
import pmt
+
def make_tag(key, value, offset):
tag = gr.tag_t()
tag.offset = offset
@@ -55,7 +59,7 @@ class HeaderToMessageBlock(gr.sync_block):
self.msg_count = 0
def work(self, input_items, output_items):
- for i in xrange(len(input_items[0])/self.header_len):
+ for i in range(len(input_items[0]) // self.header_len):
msg = self.messages[self.msg_count] or False
#print("Sending message: {0}".format(msg))
self.message_port_pub(pmt.intern('header_data'), pmt.to_pmt(msg))
@@ -227,7 +231,7 @@ class qa_header_payload_demux (gr_unittest.TestCase):
header_padding = 1
payload = tuple(range(5, 20))
data_signal = (0,) * n_zeros + header + payload
- trigger_signal = [0,] * len(data_signal)
+ trigger_signal = [0] * len(data_signal)
trigger_signal[n_zeros] = 1
# This is dropped:
testtag1 = make_tag('tag1', 0, 0)
@@ -296,7 +300,7 @@ class qa_header_payload_demux (gr_unittest.TestCase):
payload_offset = -1
payload = tuple(range(5, 20))
data_signal = (0,) * n_zeros + header + payload + (0,) * 100
- trigger_signal = [0,] * len(data_signal)
+ trigger_signal = [0] * len(data_signal)
trigger_signal[n_zeros] = 1
# This goes on output 1, item 3 + 1 (for payload offset)
testtag4 = make_tag('tag4', 314, n_zeros + len(header) + 3)
@@ -379,13 +383,13 @@ class qa_header_payload_demux (gr_unittest.TestCase):
data_src = blocks.vector_source_f(data_signal, False, tags=(testtag1, testtag2, testtag3, testtag4))
trigger_src = blocks.vector_source_b(trigger_signal, False)
hpd = digital.header_payload_demux(
- len(header) / items_per_symbol, # Header length (in symbols)
- items_per_symbol, # Items per symbols
- gi, # Items per guard time
- "frame_len", # Frame length tag key
- "detect", # Trigger tag key
- True, # Output symbols (not items)
- gr.sizeof_float # Bytes per item
+ len(header) // items_per_symbol, # Header length (in symbols)
+ items_per_symbol, # Items per symbols
+ gi, # Items per guard time
+ "frame_len", # Frame length tag key
+ "detect", # Trigger tag key
+ True, # Output symbols (not items)
+ gr.sizeof_float # Bytes per item
)
self.assertEqual(pmt.length(hpd.message_ports_in()), 2) #extra system port defined for you
header_sink = blocks.vector_sink_f(items_per_symbol)
@@ -548,7 +552,7 @@ class qa_header_payload_demux (gr_unittest.TestCase):
indexes = []
burst_sizes = []
total_payload_len = 0
- for burst_count in xrange(n_bursts):
+ for burst_count in range(n_bursts):
gap_size = random.randint(0, max_gap)
signal += [0] * gap_size
is_failure = random.random() < fail_rate
@@ -577,7 +581,7 @@ class qa_header_payload_demux (gr_unittest.TestCase):
### Go, go, go
# The divide-by-20 means we'll usually get the same random seed
# between the first run and the XML run.
- random_seed = int(time.time()/20)
+ random_seed = int(time.time() / 20)
random.seed(random_seed)
print("Random seed: {0}".format(random_seed))
n_bursts = 400
@@ -621,4 +625,3 @@ class qa_header_payload_demux (gr_unittest.TestCase):
if __name__ == '__main__':
gr_unittest.run(qa_header_payload_demux, "qa_header_payload_demux.xml")
-
diff --git a/gr-digital/python/digital/qa_lfsr.py b/gr-digital/python/digital/qa_lfsr.py
index 8b8872ab3b..8cc97a0185 100755..100644
--- a/gr-digital/python/digital/qa_lfsr.py
+++ b/gr-digital/python/digital/qa_lfsr.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
import math
from gnuradio import gr, gr_unittest, digital
@@ -37,7 +38,7 @@ class test_lfsr(gr_unittest.TestCase):
l = digital.lfsr(1, 1, reglen)
result_data = []
- for i in xrange(4*(reglen+1)):
+ for i in range(4*(reglen+1)):
result_data.append(l.next_bit())
expected_result = 4*([1,] + reglen*[0,])
diff --git a/gr-digital/python/digital/qa_lms_equalizer.py b/gr-digital/python/digital/qa_lms_equalizer.py
index 7768c1f078..fa79993f84 100755..100644
--- a/gr-digital/python/digital/qa_lms_equalizer.py
+++ b/gr-digital/python/digital/qa_lms_equalizer.py
@@ -1,51 +1,52 @@
#!/usr/bin/env python
#
# Copyright 2006,2007,2010,2011,2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
from gnuradio import gr, gr_unittest, digital, blocks
class test_lms_dd_equalizer(gr_unittest.TestCase):
def setUp(self):
- self.tb = gr.top_block()
+ self.tb = gr.top_block()
def tearDown(self):
- self.tb = None
-
+ self.tb = None
+
def transform(self, src_data, gain, const):
- SRC = blocks.vector_source_c(src_data, False)
- EQU = digital.lms_dd_equalizer_cc(4, gain, 1, const.base())
- DST = blocks.vector_sink_c()
- self.tb.connect(SRC, EQU, DST)
- self.tb.run()
- return DST.data()
+ SRC = blocks.vector_source_c(src_data, False)
+ EQU = digital.lms_dd_equalizer_cc(4, gain, 1, const.base())
+ DST = blocks.vector_sink_c()
+ self.tb.connect(SRC, EQU, DST)
+ self.tb.run()
+ return DST.data()
def test_001_identity(self):
- # Constant modulus signal so no adjustments
+ # Constant modulus signal so no adjustments
const = digital.constellation_qpsk()
- src_data = const.points()*1000
+ src_data = const.points()*1000
N = 100 # settling time
- expected_data = src_data[N:]
- result = self.transform(src_data, 0.1, const)[N:]
+ expected_data = src_data[N:]
+ result = self.transform(src_data, 0.1, const)[N:]
N = -500
self.assertComplexTuplesAlmostEqual(expected_data[N:], result[N:], 5)
diff --git a/gr-digital/python/digital/qa_map.py b/gr-digital/python/digital/qa_map.py
index 604fa084d9..0b71b2814a 100755..100644
--- a/gr-digital/python/digital/qa_map.py
+++ b/gr-digital/python/digital/qa_map.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
class test_map(gr_unittest.TestCase):
@@ -32,7 +33,7 @@ class test_map(gr_unittest.TestCase):
def helper(self, symbols):
src_data = [0, 1, 2, 3, 0, 1, 2, 3]
- expected_data = map(lambda x: symbols[x], src_data)
+ expected_data = [symbols[x] for x in src_data]
src = blocks.vector_source_b(src_data)
op = digital.map_bb(symbols)
dst = blocks.vector_sink_b()
diff --git a/gr-digital/python/digital/qa_mpsk_snr_est.py b/gr-digital/python/digital/qa_mpsk_snr_est.py
index 97d31c7686..dcc7dcc694 100755..100644
--- a/gr-digital/python/digital/qa_mpsk_snr_est.py
+++ b/gr-digital/python/digital/qa_mpsk_snr_est.py
@@ -19,6 +19,7 @@
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
+
import random
from gnuradio import gr, gr_unittest, digital, blocks
@@ -34,15 +35,15 @@ class test_mpsk_snr_est(gr_unittest.TestCase):
random.seed(0) # make repeatable
N = 10000
- self._noise = [get_n_cplx() for i in xrange(N)]
- self._bits = [get_cplx() for i in xrange(N)]
+ self._noise = [get_n_cplx() for i in range(N)]
+ self._bits = [get_cplx() for i in range(N)]
def tearDown(self):
self.tb = None
def mpsk_snr_est_setup(self, op):
result = []
- for i in xrange(1,6):
+ for i in range(1,6):
src_data = [b+(i*n) for b,n in zip(self._bits, self._noise)]
src = blocks.vector_source_c(src_data)
@@ -57,7 +58,7 @@ class test_mpsk_snr_est(gr_unittest.TestCase):
return result
def test_mpsk_snr_est_simple(self):
- expected_result = [8.20, 4.99, 3.23, 2.01, 1.03]
+ expected_result = [8.20, 4.99, 3.23, 2.01, 1.03]
N = 10000
alpha = 0.001
@@ -67,7 +68,7 @@ class test_mpsk_snr_est(gr_unittest.TestCase):
self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 2)
def test_mpsk_snr_est_skew(self):
- expected_result = [8.31, 1.83, -1.68, -3.56, -4.68]
+ expected_result = [8.31, 1.83, -1.68, -3.56, -4.68]
N = 10000
alpha = 0.001
@@ -77,7 +78,7 @@ class test_mpsk_snr_est(gr_unittest.TestCase):
self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 2)
def test_mpsk_snr_est_m2m4(self):
- expected_result = [8.01, 3.19, 1.97, 2.15, 2.65]
+ expected_result = [8.01, 3.19, 1.97, 2.15, 2.65]
N = 10000
alpha = 0.001
@@ -87,7 +88,7 @@ class test_mpsk_snr_est(gr_unittest.TestCase):
self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 2)
def test_mpsk_snr_est_svn(self):
- expected_result = [7.91, 3.01, 1.77, 1.97, 2.49]
+ expected_result = [7.91, 3.01, 1.77, 1.97, 2.49]
N = 10000
alpha = 0.001
@@ -97,10 +98,10 @@ class test_mpsk_snr_est(gr_unittest.TestCase):
self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 2)
def test_probe_mpsk_snr_est_m2m4(self):
- expected_result = [8.01, 3.19, 1.97, 2.15, 2.65]
+ expected_result = [8.01, 3.19, 1.97, 2.15, 2.65]
actual_result = []
- for i in xrange(1,6):
+ for i in range(1,6):
src_data = [b+(i*n) for b,n in zip(self._bits, self._noise)]
src = blocks.vector_source_c(src_data)
diff --git a/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py b/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py
index befb15ac4a..4ffe61b8ea 100755..100644
--- a/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py
+++ b/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py
@@ -1,23 +1,24 @@
#!/usr/bin/env python
# Copyright 2012-2014 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
from gnuradio import gr, gr_unittest, digital, blocks
import pmt
@@ -41,7 +42,7 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase):
pilot_symbols = ((1j,),)
occupied_carriers = ((0, 1, 2),)
pilot_carriers = ((3,),)
- sync_word = (range(fft_len),)
+ sync_word = (list(range(fft_len)),)
expected_result = tuple(sync_word[0] + [1j, 0, 0, 1, 2, 3])
# ^ DC carrier
src = blocks.vector_source_c(tx_symbols, False, 1)
@@ -164,7 +165,7 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase):
- add some random tags
- don't shift
"""
- tx_symbols = range(1, 16); # 15 symbols
+ tx_symbols = list(range(1, 16)); # 15 symbols
pilot_symbols = ((1j, 2j), (3j, 4j))
occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
pilot_carriers = ((2, 13), (3, 12))
@@ -203,7 +204,7 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase):
correct_offsets = {'tag1': 0, 'tag2': 1, 'tag3': 3, 'tag4': 5}
for tag in sink.tags():
key = pmt.symbol_to_string(tag.key)
- if key in tags_found.keys():
+ if key in list(tags_found.keys()):
tags_found[key] = True
self.assertEqual(correct_offsets[key], tag.offset)
self.assertTrue(all(tags_found.values()))
diff --git a/gr-digital/python/digital/qa_ofdm_chanest_vcvc.py b/gr-digital/python/digital/qa_ofdm_chanest_vcvc.py
index d63b65d018..e39247da0a 100755..100644
--- a/gr-digital/python/digital/qa_ofdm_chanest_vcvc.py
+++ b/gr-digital/python/digital/qa_ofdm_chanest_vcvc.py
@@ -19,6 +19,8 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import division
+
import sys
import numpy
import random
@@ -203,7 +205,7 @@ class qa_ofdm_chanest_vcvc (gr_unittest.TestCase):
tx_data = shift_tuple(sync_symbol1, carr_offset) + \
shift_tuple(sync_symbol2, carr_offset) + \
shift_tuple(data_symbol, carr_offset)
- channel = range(fft_len)
+ channel = list(range(fft_len))
src = blocks.vector_source_c(tx_data, False, fft_len)
chan = blocks.multiply_const_vcc(channel)
chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
@@ -234,7 +236,7 @@ class qa_ofdm_chanest_vcvc (gr_unittest.TestCase):
n_iter = 20 # The more the accurater
def run_flow_graph(sync_sym1, sync_sym2, data_sym):
top_block = gr.top_block()
- carr_offset = random.randint(-max_offset/2, max_offset/2) * 2
+ carr_offset = random.randint(-max_offset / 2, max_offset / 2) * 2
tx_data = shift_tuple(sync_sym1, carr_offset) + \
shift_tuple(sync_sym2, carr_offset) + \
shift_tuple(data_sym, carr_offset)
@@ -265,14 +267,14 @@ class qa_ofdm_chanest_vcvc (gr_unittest.TestCase):
rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real
return (carr_offset, list(shift_tuple(rx_sym_est, -carr_offset_hat)))
bit_errors = 0
- for k in xrange(n_iter):
+ for k in range(n_iter):
sync_sym = [(random.randint(0, 1) * 2 - 1) * syncsym_mask[i] for i in range(fft_len)]
ref_sym = [(random.randint(0, 1) * 2 - 1) * carrier_mask[i] for i in range(fft_len)]
data_sym = [(random.randint(0, 1) * 2 - 1) * carrier_mask[i] for i in range(fft_len)]
data_sym[26] = 1
(carr_offset, rx_sym) = run_flow_graph(sync_sym, ref_sym, data_sym)
rx_sym_est = [0,] * fft_len
- for i in xrange(fft_len):
+ for i in range(fft_len):
if carrier_mask[i] == 0:
continue
rx_sym_est[i] = {True: 1, False: -1}[rx_sym[i] > 0]
diff --git a/gr-digital/python/digital/qa_ofdm_cyclic_prefixer.py b/gr-digital/python/digital/qa_ofdm_cyclic_prefixer.py
index ecc1c426d6..fc486fa6a2 100755..100644
--- a/gr-digital/python/digital/qa_ofdm_cyclic_prefixer.py
+++ b/gr-digital/python/digital/qa_ofdm_cyclic_prefixer.py
@@ -20,6 +20,8 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import division
+
from gnuradio import gr, gr_unittest, digital, blocks
import pmt
@@ -37,7 +39,7 @@ class test_ofdm_cyclic_prefixer (gr_unittest.TestCase):
cp_len = 2
expected_result = (6, 7, 0, 1, 2, 3, 4, 5, 6, 7,
6, 7, 0, 1, 2, 3, 4, 5, 6, 7)
- src = blocks.vector_source_c(range(fft_len) * 2, False, fft_len)
+ src = blocks.vector_source_c(list(range(fft_len)) * 2, False, fft_len)
cp = digital.ofdm_cyclic_prefixer(fft_len, fft_len + cp_len)
sink = blocks.vector_sink_c()
self.tb.connect(src, cp, sink)
@@ -49,9 +51,9 @@ class test_ofdm_cyclic_prefixer (gr_unittest.TestCase):
fft_len = 8
cp_len = 2
rolloff = 2
- expected_result = (7.0/2, 8, 1, 2, 3, 4, 5, 6, 7, 8, # 1.0/2
- 7.0/2+1.0/2, 8, 1, 2, 3, 4, 5, 6, 7, 8)
- src = blocks.vector_source_c(range(1, fft_len+1) * 2, False, fft_len)
+ expected_result = (7.0 / 2, 8, 1, 2, 3, 4, 5, 6, 7, 8, # 1.0/2
+ 7.0 / 2+1.0 / 2, 8, 1, 2, 3, 4, 5, 6, 7, 8)
+ src = blocks.vector_source_c(list(range(1, fft_len+1)) * 2, False, fft_len)
cp = digital.ofdm_cyclic_prefixer(fft_len, fft_len + cp_len, rolloff)
sink = blocks.vector_sink_c()
self.tb.connect(src, cp, sink)
@@ -63,13 +65,13 @@ class test_ofdm_cyclic_prefixer (gr_unittest.TestCase):
fft_len = 8
cp_len = 2
tag_name = "ts_last"
- expected_result = (7.0/2, 8, 1, 2, 3, 4, 5, 6, 7, 8, # 1.0/2
- 7.0/2+1.0/2, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1.0/2)
+ expected_result = (7.0 / 2, 8, 1, 2, 3, 4, 5, 6, 7, 8, # 1.0/2
+ 7.0 / 2+1.0 / 2, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1.0 / 2)
tag2 = gr.tag_t()
tag2.offset = 1
tag2.key = pmt.string_to_symbol("random_tag")
tag2.value = pmt.from_long(42)
- src = blocks.vector_source_c(range(1, fft_len+1) * 2, False, fft_len, (tag2,))
+ src = blocks.vector_source_c(list(range(1, fft_len+1)) * 2, False, fft_len, (tag2,))
cp = digital.ofdm_cyclic_prefixer(fft_len, fft_len + cp_len, 2, tag_name)
sink = blocks.tsb_vector_sink_c(tsb_key=tag_name)
self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, 2, tag_name), cp, sink)
diff --git a/gr-digital/python/digital/qa_ofdm_frame_equalizer_vcvc.py b/gr-digital/python/digital/qa_ofdm_frame_equalizer_vcvc.py
index 1b3ffb7738..482147e33a 100755..100644
--- a/gr-digital/python/digital/qa_ofdm_frame_equalizer_vcvc.py
+++ b/gr-digital/python/digital/qa_ofdm_frame_equalizer_vcvc.py
@@ -1,23 +1,25 @@
#!/usr/bin/env python
# Copyright 2012,2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import division
import numpy
@@ -220,7 +222,7 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase):
eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, self.tsb_key, True)
self.tb.connect(
src,
- blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, len(tx_data)/fft_len, self.tsb_key),
+ blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, len(tx_data) // fft_len, self.tsb_key),
eq,
sink
)
@@ -278,7 +280,7 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase):
sink = blocks.tsb_vector_sink_c(vlen=fft_len, tsb_key=self.tsb_key)
self.tb.connect(
src,
- blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, len(tx_data)/fft_len, self.tsb_key),
+ blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, len(tx_data) // fft_len, self.tsb_key),
eq,
sink
)
@@ -360,7 +362,7 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase):
sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key)
self.tb.connect(
src,
- blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, len(tx_data)/fft_len, self.tsb_key),
+ blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, len(tx_data) // fft_len, self.tsb_key),
eq,
sink
)
diff --git a/gr-digital/python/digital/qa_ofdm_serializer_vcc.py b/gr-digital/python/digital/qa_ofdm_serializer_vcc.py
index 8a60b97882..a53aafccb6 100755..100644
--- a/gr-digital/python/digital/qa_ofdm_serializer_vcc.py
+++ b/gr-digital/python/digital/qa_ofdm_serializer_vcc.py
@@ -1,24 +1,26 @@
#!/usr/bin/env python
#
# Copyright 2012-2014 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import division
import numpy
@@ -42,7 +44,7 @@ class qa_ofdm_serializer_vcc (gr_unittest.TestCase):
0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 2j, 0, 0)
expected_result = tuple(range(1, 16)) + (0, 0, 0)
occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
- n_syms = len(tx_symbols)/fft_len
+ n_syms = len(tx_symbols) // fft_len
src = blocks.vector_source_c(tx_symbols, False, fft_len)
serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, self.tsb_key, "", 0, "", False)
sink = blocks.tsb_vector_sink_c(tsb_key=self.tsb_key)
@@ -60,7 +62,7 @@ class qa_ofdm_serializer_vcc (gr_unittest.TestCase):
)
expected_result = tuple(range(18))
occupied_carriers = ((13, 14, 15, 1, 2, 3), (-4, -2, -1, 1, 2, 4),)
- n_syms = len(tx_symbols)/fft_len
+ n_syms = len(tx_symbols) // fft_len
src = blocks.vector_source_c(tx_symbols, False, fft_len)
serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, self.tsb_key)
sink = blocks.tsb_vector_sink_c(tsb_key=self.tsb_key)
@@ -71,14 +73,14 @@ class qa_ofdm_serializer_vcc (gr_unittest.TestCase):
def test_002_with_offset (self):
""" Standard test, carrier offset """
fft_len = 16
- tx_symbols = range(1, 16);
+ tx_symbols = list(range(1, 16));
tx_symbols = (0, 0, 1, 1j, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 2j, 6,
0, 0, 7, 8, 3j, 9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12,
0, 0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 2j, 0)
carr_offset = 1 # Compare this with tx_symbols from the previous test
expected_result = tuple(range(1, 16)) + (0, 0, 0)
occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
- n_syms = len(tx_symbols)/fft_len
+ n_syms = len(tx_symbols) // fft_len
offsettag = gr.tag_t()
offsettag.offset = 0
offsettag.key = pmt.string_to_symbol("ofdm_sync_carr_offset")
@@ -156,7 +158,7 @@ class qa_ofdm_serializer_vcc (gr_unittest.TestCase):
pilot_carriers,
pilot_symbols, (),
self.tsb_key)
- tx_ifft = fft.fft_vcc(fft_len, False, (1.0/fft_len,)*fft_len, True)
+ tx_ifft = fft.fft_vcc(fft_len, False, (1.0 / fft_len,)*fft_len, True)
oscillator = analog.sig_source_c(1.0, analog.GR_COS_WAVE, freq_offset, 1.0)
mixer = blocks.multiply_cc()
rx_fft = fft.fft_vcc(fft_len, True, (), True)
@@ -182,13 +184,13 @@ class qa_ofdm_serializer_vcc (gr_unittest.TestCase):
def test_005_packet_len_tag (self):
""" Standard test """
fft_len = 16
- tx_symbols = range(1, 16);
+ tx_symbols = list(range(1, 16));
tx_symbols = (0, 1, 1j, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 2j, 6, 0,
0, 7, 8, 3j, 9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0,
0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 2j, 0, 0)
expected_result = tuple(range(1, 16))
occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
- n_syms = len(tx_symbols)/fft_len
+ n_syms = len(tx_symbols) // fft_len
packet_len_tsb_key = "packet_len"
tag2 = gr.tag_t()
tag2.offset = 0
diff --git a/gr-digital/python/digital/qa_ofdm_sync_sc_cfb.py b/gr-digital/python/digital/qa_ofdm_sync_sc_cfb.py
index 1558c5d51f..610d883b6c 100755..100644
--- a/gr-digital/python/digital/qa_ofdm_sync_sc_cfb.py
+++ b/gr-digital/python/digital/qa_ofdm_sync_sc_cfb.py
@@ -1,24 +1,26 @@
#!/usr/bin/env python
#
# Copyright 2012,2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import division
import numpy
import random
@@ -44,7 +46,7 @@ class qa_ofdm_sync_sc_cfb (gr_unittest.TestCase):
fft_len = 32
cp_len = 4
sig_len = (fft_len + cp_len) * 10
- sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2
+ sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len // 2)] * 2
tx_signal = [0,] * n_zeros + \
sync_symbol[-cp_len:] + \
sync_symbol + \
@@ -60,8 +62,8 @@ class qa_ofdm_sync_sc_cfb (gr_unittest.TestCase):
self.tb.connect((sync, 0), sink_freq)
self.tb.connect((sync, 1), sink_detect)
self.tb.run()
- sig1_detect = sink_detect.data()[0:len(tx_signal)/2]
- sig2_detect = sink_detect.data()[len(tx_signal)/2:]
+ sig1_detect = sink_detect.data()[0:len(tx_signal) // 2]
+ sig2_detect = sink_detect.data()[len(tx_signal) // 2:]
self.assertTrue(abs(sig1_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
self.assertTrue(abs(sig2_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
self.assertEqual(numpy.sum(sig1_detect), 1)
@@ -75,7 +77,7 @@ class qa_ofdm_sync_sc_cfb (gr_unittest.TestCase):
max_freq_offset = 2*numpy.pi/fft_len # Otherwise, it's coarse
freq_offset = ((2 * random.random()) - 1) * max_freq_offset
sig_len = (fft_len + cp_len) * 10
- sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2
+ sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len // 2)] * 2
tx_signal = sync_symbol[-cp_len:] + \
sync_symbol + \
[(random.randint(0, 1)*2)-1 for x in range(sig_len)]
@@ -99,8 +101,8 @@ class qa_ofdm_sync_sc_cfb (gr_unittest.TestCase):
fft_len = 32
cp_len = 4
tx_signal = []
- for i in xrange(n_bursts):
- sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2
+ for i in range(n_bursts):
+ sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len // 2)] * 2
tx_signal += [0,] * random.randint(0, 2*fft_len) + \
sync_symbol[-cp_len:] + \
sync_symbol + \
@@ -139,8 +141,8 @@ Detection error was: %d """ % (numpy.sum(sink_detect.data()) - n_bursts)
tagname = "packet_length"
min_packet_length = 10
max_packet_length = 50
- sync_sequence = [random.randint(0, 1)*2-1 for x in range(fft_len/2)]
- for i in xrange(n_bursts):
+ sync_sequence = [random.randint(0, 1)*2-1 for x in range(fft_len // 2)]
+ for i in range(n_bursts):
packet_length = random.randint(min_packet_length,
max_packet_length+1)
packet = [random.randint(0, 255) for i in range(packet_length)]
diff --git a/gr-digital/python/digital/qa_ofdm_txrx.py b/gr-digital/python/digital/qa_ofdm_txrx.py
index ac267d2389..2e8d101317 100755..100644
--- a/gr-digital/python/digital/qa_ofdm_txrx.py
+++ b/gr-digital/python/digital/qa_ofdm_txrx.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
import random
import numpy
diff --git a/gr-digital/python/digital/qa_packet_format.py b/gr-digital/python/digital/qa_packet_format.py
index ae1a79f1f4..6b2e9e958e 100644
--- a/gr-digital/python/digital/qa_packet_format.py
+++ b/gr-digital/python/digital/qa_packet_format.py
@@ -21,6 +21,8 @@
#
import time, struct
+import six
+
import pmt
from gnuradio import gr, gr_unittest, digital, blocks
from gnuradio.digital import packet_utils
@@ -57,6 +59,7 @@ class test_packet_format_fb(gr_unittest.TestCase):
self.tb.start()
while (snk_hdr.num_messages() < 1) and (snk_pld.num_messages() < 1):
time.sleep(0.1)
+
self.tb.stop()
self.tb.wait()
@@ -65,14 +68,14 @@ class test_packet_format_fb(gr_unittest.TestCase):
result_hdr = pmt.u8vector_elements(result_hdr_pmt)
result_pld = pmt.u8vector_elements(result_pld_pmt)
- header = "".join([chr(r) for r in result_hdr])
- payload = "".join([chr(r) for r in result_pld])
+ header = "".join(chr(r) for r in result_hdr)
+ payload = "".join(chr(r) for r in result_pld)
access_code = packet_utils.conv_1_0_string_to_packed_binary_string(packet_utils.default_access_code)[0]
rx_access_code = header[0:len(access_code)]
length = len(send_str)
- rx_length = struct.unpack_from("!H", header, len(access_code))[0]
+ rx_length = struct.unpack_from(b"!H", six.b(header), len(access_code))[0]
self.assertEqual(access_code, rx_access_code)
self.assertEqual(length, rx_length)
@@ -158,16 +161,16 @@ class test_packet_format_fb(gr_unittest.TestCase):
result_hdr = pmt.u8vector_elements(result_hdr_pmt)
result_pld = pmt.u8vector_elements(result_pld_pmt)
- header = "".join([chr(r) for r in result_hdr])
- payload = "".join([chr(r) for r in result_pld])
+ header = "".join(chr(r) for r in result_hdr)
+ payload = "".join(chr(r) for r in result_pld)
access_code = packet_utils.conv_1_0_string_to_packed_binary_string(packet_utils.default_access_code)[0]
rx_access_code = header[0:len(access_code)]
length = len(send_str)
- rx_length = struct.unpack_from("!H", header, len(access_code))[0]
- rx_bps = struct.unpack_from("!H", header, len(access_code)+4)[0]
- rx_counter = struct.unpack_from("!H", header, len(access_code)+6)[0]
+ rx_length = struct.unpack_from(b"!H", six.b(header), len(access_code))[0]
+ rx_bps = struct.unpack_from(b"!H", six.b(header), len(access_code)+4)[0]
+ rx_counter = struct.unpack_from(b"!H", six.b(header), len(access_code)+6)[0]
self.assertEqual(access_code, rx_access_code)
self.assertEqual(length, rx_length)
diff --git a/gr-digital/python/digital/qa_packet_headergenerator_bb.py b/gr-digital/python/digital/qa_packet_headergenerator_bb.py
index d2677ce220..1ca0e85d8d 100755..100644
--- a/gr-digital/python/digital/qa_packet_headergenerator_bb.py
+++ b/gr-digital/python/digital/qa_packet_headergenerator_bb.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
from gnuradio.gr import packet_utils
import pmt
diff --git a/gr-digital/python/digital/qa_packet_headerparser_b.py b/gr-digital/python/digital/qa_packet_headerparser_b.py
index fb4226d6fd..3e22fa9100 100755..100644
--- a/gr-digital/python/digital/qa_packet_headerparser_b.py
+++ b/gr-digital/python/digital/qa_packet_headerparser_b.py
@@ -19,6 +19,7 @@
# Boston, MA 02110-1301, USA.
#
+
import time
import random
@@ -77,7 +78,7 @@ class qa_packet_headerparser_b (gr_unittest.TestCase):
header_len = 32
packet_len_tagname = "packet_len"
packet_lengths = [random.randint(1, 100) for x in range(N)]
- data, tags = tagged_streams.packets_to_vectors([range(packet_lengths[i]) for i in range(N)], packet_len_tagname)
+ data, tags = tagged_streams.packets_to_vectors([list(range(packet_lengths[i])) for i in range(N)], packet_len_tagname)
src = blocks.vector_source_b(data, False, 1, tags)
header_gen = digital.packet_headergenerator_bb(header_len, packet_len_tagname)
header_parser = digital.packet_headerparser_b(header_len, packet_len_tagname)
@@ -89,7 +90,7 @@ class qa_packet_headerparser_b (gr_unittest.TestCase):
self.tb.stop()
self.tb.wait()
self.assertEqual(sink.num_messages(), N)
- for i in xrange(N):
+ for i in range(N):
msg = pmt.to_python(sink.get_message(i))
self.assertEqual(msg, {'packet_len': packet_lengths[i], 'packet_num': i})
@@ -110,7 +111,7 @@ class qa_packet_headerparser_b (gr_unittest.TestCase):
frame_len_tagname = "frame_len"
src = blocks.vector_source_b(encoded_headers)
header_formatter = digital.packet_header_ofdm(
- (range(32),range(4),range(8)), # 32/4/8 carriers are occupied (which doesn't matter here)
+ (list(range(32)),list(range(4)),list(range(8))), # 32/4/8 carriers are occupied (which doesn't matter here)
1, # 1 OFDM symbol per header (= 32 bits)
packet_len_tagname,
frame_len_tagname,
@@ -141,10 +142,10 @@ class qa_packet_headerparser_b (gr_unittest.TestCase):
packet_length = 23
packet_len_tagname = "packet_len"
frame_len_tagname = "frame_len"
- data, tags = tagged_streams.packets_to_vectors([range(packet_length),range(packet_length),], packet_len_tagname)
+ data, tags = tagged_streams.packets_to_vectors([list(range(packet_length)),list(range(packet_length)),], packet_len_tagname)
src = blocks.vector_source_b(data, False, 1, tags)
header_formatter = digital.packet_header_ofdm(
- (range(32),), # 32 carriers are occupied (which doesn't matter here)
+ (list(range(32)),), # 32 carriers are occupied (which doesn't matter here)
1, # 1 OFDM symbol per header (= 32 bits)
packet_len_tagname,
frame_len_tagname,
diff --git a/gr-digital/python/digital/qa_pfb_clock_sync.py b/gr-digital/python/digital/qa_pfb_clock_sync.py
index e16a99338e..77980d19e5 100755..100644
--- a/gr-digital/python/digital/qa_pfb_clock_sync.py
+++ b/gr-digital/python/digital/qa_pfb_clock_sync.py
@@ -20,6 +20,8 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import division
+
import random
import cmath
import time
@@ -39,9 +41,9 @@ class test_pfb_clock_sync(gr_unittest.TestCase):
excess_bw = 0.35
sps = 4
- loop_bw = cmath.pi/100.0
+ loop_bw = cmath.pi / 100.0
nfilts = 32
- init_phase = nfilts/2
+ init_phase = nfilts / 2
max_rate_deviation = 0.5
osps = 1
@@ -92,9 +94,9 @@ class test_pfb_clock_sync(gr_unittest.TestCase):
excess_bw = 0.35
sps = 4
- loop_bw = cmath.pi/100.0
+ loop_bw = cmath.pi / 100.0
nfilts = 32
- init_phase = nfilts/2
+ init_phase = nfilts / 2
max_rate_deviation = 0.5
osps = 1
@@ -146,9 +148,9 @@ class test_pfb_clock_sync(gr_unittest.TestCase):
excess_bw1 = 0.22
sps = 4
- loop_bw = cmath.pi/100.0
+ loop_bw = cmath.pi / 100.0
nfilts = 32
- init_phase = nfilts/2
+ init_phase = nfilts / 2
max_rate_deviation = 0.5
osps = 1
@@ -184,9 +186,9 @@ class test_pfb_clock_sync(gr_unittest.TestCase):
excess_bw1 = 0.22
sps = 4
- loop_bw = cmath.pi/100.0
+ loop_bw = cmath.pi / 100.0
nfilts = 32
- init_phase = nfilts/2
+ init_phase = nfilts / 2
max_rate_deviation = 0.5
osps = 1
diff --git a/gr-digital/python/digital/qa_pn_correlator_cc.py b/gr-digital/python/digital/qa_pn_correlator_cc.py
index 92041d9eda..111801b5c9 100755..100644
--- a/gr-digital/python/digital/qa_pn_correlator_cc.py
+++ b/gr-digital/python/digital/qa_pn_correlator_cc.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
class test_pn_correlator_cc(gr_unittest.TestCase):
diff --git a/gr-digital/python/digital/qa_probe_density.py b/gr-digital/python/digital/qa_probe_density.py
index 752d95da3e..e4450cd092 100755..100644
--- a/gr-digital/python/digital/qa_probe_density.py
+++ b/gr-digital/python/digital/qa_probe_density.py
@@ -20,6 +20,8 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import print_function
+
from gnuradio import gr, gr_unittest, digital, blocks
class test_probe_density(gr_unittest.TestCase):
@@ -62,7 +64,7 @@ class test_probe_density(gr_unittest.TestCase):
self.tb.run()
result_data = op.density()
- print result_data
+ print(result_data)
self.assertAlmostEqual(expected_data, result_data, 5)
if __name__ == '__main__':
diff --git a/gr-digital/python/digital/qa_scrambler.py b/gr-digital/python/digital/qa_scrambler.py
index 522b23245f..93f77a9ef7 100755..100644
--- a/gr-digital/python/digital/qa_scrambler.py
+++ b/gr-digital/python/digital/qa_scrambler.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
import pmt
@@ -29,7 +30,7 @@ def additive_scramble_lfsr(mask, seed, reglen, bpb, data):
out = []
for d in data:
scramble_word = 0
- for i in xrange(0,bpb):
+ for i in range(0,bpb):
scramble_word ^= l.next_bit() << i
out.append(d ^ scramble_word)
return tuple(out)
@@ -121,7 +122,7 @@ class test_scrambler(gr_unittest.TestCase):
reset_tag3 = gr.tag_t()
reset_tag3.key = pmt.string_to_symbol(reset_tag_key)
reset_tag3.offset = 20
- src = blocks.vector_source_b(src_data * 3, False, 1, (reset_tag1, reset_tag2, reset_tag3))
+ src = blocks.vector_source_b([s * 3 for s in src_data], False, 1, (reset_tag1, reset_tag2, reset_tag3))
scrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7, 0, 8, reset_tag_key)
dst = blocks.vector_sink_b()
self.tb.connect(src, scrambler, dst)
diff --git a/gr-digital/python/digital/qa_simple_correlator.py b/gr-digital/python/digital/qa_simple_correlator.py
index f39fb62dda..9c0352e896 100755..100644
--- a/gr-digital/python/digital/qa_simple_correlator.py
+++ b/gr-digital/python/digital/qa_simple_correlator.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, blocks, filter, digital
class test_simple_correlator(gr_unittest.TestCase):
diff --git a/gr-digital/python/digital/qa_simple_framer.py b/gr-digital/python/digital/qa_simple_framer.py
index cf9934648b..fb1ac0dfd6 100755..100644
--- a/gr-digital/python/digital/qa_simple_framer.py
+++ b/gr-digital/python/digital/qa_simple_framer.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, digital, blocks
class test_simple_framer(gr_unittest.TestCase):
diff --git a/gr-digital/python/digital/qam.py b/gr-digital/python/digital/qam.py
index 518be78941..be4b7efa74 100644
--- a/gr-digital/python/digital/qam.py
+++ b/gr-digital/python/digital/qam.py
@@ -1,37 +1,40 @@
#
# Copyright 2005,2006,2011,2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
"""
QAM modulation and demodulation.
"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import unicode_literals
from math import pi, sqrt, log
from gnuradio import gr
-from generic_mod_demod import generic_mod, generic_demod
-from generic_mod_demod import shared_mod_args, shared_demod_args
-from utils.gray_code import gray_code
-from utils import mod_codes
-import modulation_utils
-import digital_swig as digital
+from .generic_mod_demod import generic_mod, generic_demod
+from .generic_mod_demod import shared_mod_args, shared_demod_args
+from .utils.gray_code import gray_code
+from .utils import mod_codes
+from . import modulation_utils
+from . import digital_swig as digital
# Default number of points in constellation.
_def_constellation_points = 16
@@ -42,7 +45,7 @@ _def_differential = True
_def_mod_code = mod_codes.NO_CODE
def is_power_of_four(x):
- v = log(x)/log(4)
+ v = log(x) / log(4)
return int(v) == v
def get_bit(x, n):
@@ -52,7 +55,7 @@ def get_bit(x, n):
def get_bits(x, n, k):
""" Get the k bits of integer x starting at bit n(from little end)."""
# Remove the n smallest bits
- v = x >> n
+ v = x >> n
# Remove all bits bigger than n+k-1
return v % pow(2, k)
@@ -74,7 +77,7 @@ def make_differential_constellation(m, gray_coded):
k = int(log(m) / log(2.0))
# First create a constellation for one quadrant containing m/4 points.
# The quadrant has 'side' points along each side of a quadrant.
- side = int(sqrtm/2)
+ side = int(sqrtm / 2)
if gray_coded:
# Number rows and columns using gray codes.
gcs = gray_code(side)
@@ -83,7 +86,7 @@ def make_differential_constellation(m, gray_coded):
else:
i_gcs = dict([(i, i) for i in range(0, side)])
# The distance between points is found.
- step = 1/(side-0.5)
+ step = 1 / (side-0.5)
gc_to_x = [(i_gcs[gc]+0.5)*step for gc in range(0, side)]
@@ -100,7 +103,7 @@ def make_differential_constellation(m, gray_coded):
return complex(-gc_to_x[gc_x], -gc_to_x[gc_y])
if quad == 3:
return complex(gc_to_x[gc_y], -gc_to_x[gc_x])
- raise StandardError("Impossible!")
+ raise Exception("Impossible!")
# First two bits determine quadrant.
# Next (k-2)/2 bits determine x position.
@@ -108,8 +111,8 @@ def make_differential_constellation(m, gray_coded):
# How x and y relate to real and imag depends on quadrant (see get_c function).
const_map = []
for i in range(m):
- y = get_bits(i, 0, (k-2)/2)
- x = get_bits(i, (k-2)/2, (k-2)/2)
+ y = get_bits(i, 0, (k-2) // 2)
+ x = get_bits(i, (k-2) // 2, (k-2) // 2)
quad = get_bits(i, k-2, 2)
const_map.append(get_c(x, y, quad))
@@ -127,17 +130,17 @@ def make_non_differential_constellation(m, gray_coded):
# Get inverse gray codes.
i_gcs = mod_codes.invert_code(gcs)
else:
- i_gcs = range(0, side)
+ i_gcs = list(range(0, side))
# The distance between points is found.
- step = 2.0/(side-1)
+ step = 2.0 / (side-1)
gc_to_x = [-1 + i_gcs[gc]*step for gc in range(0, side)]
# First k/2 bits determine x position.
# Following k/2 bits determine y position.
const_map = []
for i in range(m):
- y = gc_to_x[get_bits(i, 0, k/2)]
- x = gc_to_x[get_bits(i, k/2, k/2)]
+ y = gc_to_x[get_bits(i, 0, k // 2)]
+ x = gc_to_x[get_bits(i, k // 2, k // 2)]
const_map.append(complex(x,y))
return const_map
@@ -170,7 +173,7 @@ def qam_constellation(constellation_points=_def_constellation_points,
else:
points = make_non_differential_constellation(constellation_points, gray_coded)
side = int(sqrt(constellation_points))
- width = 2.0/(side-1)
+ width = 2.0 / (side-1)
# No pre-diff code
# Should add one so that we can gray-code the quadrant bits too.
@@ -242,8 +245,8 @@ def large_ampls_to_corners_mapping(side, points, width):
sector = real_x * side + imag_x
# If this sector is a normal constellation sector then
# use the center point.
- c = ((real_x-side/2.0+0.5)*width +
- (imag_x-side/2.0+0.5)*width*1j)
+ c = ((real_x-side / 2.0+0.5)*width +
+ (imag_x-side / 2.0+0.5)*width*1j)
if (real_x >= extra_layers and real_x < side-extra_layers
and imag_x >= extra_layers and imag_x < side-extra_layers):
# This is not an edge row/column. Find closest point.
@@ -254,7 +257,7 @@ def large_ampls_to_corners_mapping(side, points, width):
sector_values.append(index)
return sector_values
-
+
# /////////////////////////////////////////////////////////////////////////////
# QAM modulator
# /////////////////////////////////////////////////////////////////////////////
@@ -262,10 +265,10 @@ def large_ampls_to_corners_mapping(side, points, width):
class qam_mod(generic_mod):
"""
Hierarchical block for RRC-filtered QAM modulation.
-
+
The input is a byte stream (unsigned char) and the
output is the complex modulated signal at baseband.
-
+
Args:
constellation_points: Number of constellation points (must be a power of four) (integer).
mod_code: Whether to use a gray_code (digital.mod_codes.GRAY_CODE) or not (digital.mod_codes.NO_CODE).
@@ -280,10 +283,10 @@ class qam_mod(generic_mod):
*args, **kwargs):
"""
- Hierarchical block for RRC-filtered QAM modulation.
+ Hierarchical block for RRC-filtered QAM modulation.
- The input is a byte stream (unsigned char) and the
- output is the complex modulated signal at baseband.
+ The input is a byte stream (unsigned char) and the
+ output is the complex modulated signal at baseband.
Args:
constellation_points: Number of constellation points.
@@ -292,7 +295,7 @@ class qam_mod(generic_mod):
if we want gray coding, see digital.utils.mod_codes)
See generic_mod block for list of additional parameters.
- """
+ """
constellation = qam_constellation(constellation_points, differential,
mod_code)
@@ -309,10 +312,10 @@ class qam_mod(generic_mod):
class qam_demod(generic_demod):
"""
Hierarchical block for RRC-filtered QAM modulation.
-
+
The input is a byte stream (unsigned char) and the
output is the complex modulated signal at baseband.
-
+
Args:
constellation_points: Number of constellation points (must be a power of four) (integer).
mod_code: Whether to use a gray_code (digital.mod_codes.GRAY_CODE) or not (digital.mod_codes.NO_CODE).
@@ -327,10 +330,10 @@ class qam_demod(generic_demod):
large_ampls_to_corner = False,
*args, **kwargs):
"""
- Hierarchical block for RRC-filtered QAM modulation.
+ Hierarchical block for RRC-filtered QAM modulation.
- The input is a byte stream (unsigned char) and the
- output is the complex modulated signal at baseband.
+ The input is a byte stream (unsigned char) and the
+ output is the complex modulated signal at baseband.
Args:
constellation_points: Number of constellation points.
diff --git a/gr-digital/python/digital/qam_constellations.py b/gr-digital/python/digital/qam_constellations.py
index cd895c590b..c0d7805f87 100755..100644
--- a/gr-digital/python/digital/qam_constellations.py
+++ b/gr-digital/python/digital/qam_constellations.py
@@ -20,8 +20,11 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import unicode_literals
import numpy
-from constellation_map_generator import constellation_map_generator
+from .constellation_map_generator import constellation_map_generator
'''
Note on the naming scheme. Each constellation is named using a prefix
@@ -242,8 +245,8 @@ def sd_qam_16_0x0_0_1_2_3(x, Es=1):
'''
dist = Es*numpy.sqrt(2)
- boundary = dist/3.0
- dist0 = dist/6.0
+ boundary = dist / 3.0
+ dist0 = dist / 6.0
# print "Sample: ", x
# print "Es: ", Es
# print "Distance: ", dist
@@ -270,7 +273,7 @@ def sd_qam_16_0x0_0_1_2_3(x, Es=1):
b2 = -abs(x_re) + boundary
b0 = -abs(x_im) + boundary
- return [(Es/2.0)*b3, (Es/2.0)*b2, (Es/2.0)*b1, (Es/2.0)*b0]
+ return [(Es / 2.0)*b3, (Es / 2.0)*b2, (Es / 2.0)*b1, (Es / 2.0)*b0]
sd_qam_16 = sd_qam_16_0x0_0_1_2_3
sd_qam_16_0 = sd_qam_16
diff --git a/gr-digital/python/digital/qamlike.py b/gr-digital/python/digital/qamlike.py
index 2f8c855339..286eabd898 100644
--- a/gr-digital/python/digital/qamlike.py
+++ b/gr-digital/python/digital/qamlike.py
@@ -1,33 +1,35 @@
# Copyright 2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
"""
This file contains constellations that are similar to QAM, but are not perfect squares.
"""
+from __future__ import absolute_import
+from __future__ import unicode_literals
-import digital_swig
-from qam import large_ampls_to_corners_mapping
+from . import digital_swig
+from .qam import large_ampls_to_corners_mapping
def qam32_holeinside_constellation(large_ampls_to_corners=False):
# First make constellation for one quadrant.
- # 0 1 2
+ # 0 1 2
# 2 - 010 111 110
# 1 - 011 101 100
# 0 - 000 001
@@ -72,4 +74,3 @@ def qam32_holeinside_constellation(large_ampls_to_corners=False):
constellation = digital_swig.constellation_expl_rect(
points, pre_diff_code, 4, side, side, width, width, sector_values)
return constellation
-
diff --git a/gr-digital/python/digital/qpsk.py b/gr-digital/python/digital/qpsk.py
index c5230ef24d..8303883992 100644
--- a/gr-digital/python/digital/qpsk.py
+++ b/gr-digital/python/digital/qpsk.py
@@ -24,13 +24,15 @@ QPSK modulation.
Demodulation is not included since the generic_mod_demod
"""
+from __future__ import absolute_import
+from __future__ import unicode_literals
from gnuradio import gr
from gnuradio.digital.generic_mod_demod import generic_mod, generic_demod
from gnuradio.digital.generic_mod_demod import shared_mod_args, shared_demod_args
-from utils import mod_codes
-import digital_swig as digital
-import modulation_utils
+from .utils import mod_codes
+from . import digital_swig as digital
+from . import modulation_utils
# The default encoding (e.g. gray-code, set-partition)
_def_mod_code = mod_codes.GRAY_CODE
diff --git a/gr-digital/python/digital/soft_dec_lut_gen.py b/gr-digital/python/digital/soft_dec_lut_gen.py
index f517277702..fc69f7f678 100644
--- a/gr-digital/python/digital/soft_dec_lut_gen.py
+++ b/gr-digital/python/digital/soft_dec_lut_gen.py
@@ -20,6 +20,10 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import print_function
+from __future__ import division
+from __future__ import unicode_literals
+
import numpy
def soft_dec_table_generator(soft_dec_gen, prec, Es=1):
@@ -123,6 +127,7 @@ def soft_dec_table(constel, symbols, prec, npwr=1):
xrng = numpy.linspace(re_min, re_max, npts)
table = []
+
for y in yrng:
for x in xrng:
pt = complex(x, y)
@@ -196,8 +201,8 @@ def calc_soft_dec(sample, constel, symbols, npwr=1):
M = len(constel)
k = int(numpy.log2(M))
- tmp = 2*k*[0,]
- s = k*[0,]
+ tmp = 2*k*[0]
+ s = k*[0]
for i in range(M):
# Calculate the distance between the sample and the current
@@ -206,7 +211,7 @@ def calc_soft_dec(sample, constel, symbols, npwr=1):
# Calculate the probability factor from the distance and the
# scaled noise power.
- d = numpy.exp(-dist/npwr)
+ d = numpy.exp(-dist / npwr)
for j in range(k):
# Get the bit at the jth index
@@ -235,21 +240,21 @@ def show_table(table):
pp = ""
subi = 1
subj = 0
- for i in reversed(xrange(prec+1)):
+ for i in reversed(list(range(prec+1))):
if(i == prec//2):
pp += "-----" + prec*((nbits*8)+3)*"-" + "\n"
subi = 0
continue
- for j in xrange(prec+1):
+ for j in range(prec+1):
if(j == prec//2):
pp += "| "
subj = 1
else:
item = table[prec*(i-subi) + (j-subj)]
pp += "( "
- for t in xrange(nbits-1, -1, -1):
+ for t in range(nbits-1, -1, -1):
pp += "{0: .4f} ".format(item[t])
pp += ") "
pp += "\n"
subj = 0
- print pp
+ print(pp)
diff --git a/gr-digital/python/digital/test_soft_decisions.py b/gr-digital/python/digital/test_soft_decisions.py
index 878058ebbc..eba31bab76 100755..100644
--- a/gr-digital/python/digital/test_soft_decisions.py
+++ b/gr-digital/python/digital/test_soft_decisions.py
@@ -1,30 +1,35 @@
#!/usr/bin/env python
#
# Copyright 2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import unicode_literals
import numpy, pylab, sys
from gnuradio import digital
-from soft_dec_lut_gen import soft_dec_table, calc_soft_dec_from_table, calc_soft_dec
-from psk_constellations import psk_4_0, psk_4_1, psk_4_2, psk_4_3, psk_4_4, psk_4_5, psk_4_6, psk_4_7, sd_psk_4_0, sd_psk_4_1, sd_psk_4_2, sd_psk_4_3, sd_psk_4_4, sd_psk_4_5, sd_psk_4_6, sd_psk_4_7
-from qam_constellations import qam_16_0, sd_qam_16_0
+from .soft_dec_lut_gen import soft_dec_table, calc_soft_dec_from_table, calc_soft_dec
+from .psk_constellations import psk_4_0, psk_4_1, psk_4_2, psk_4_3, psk_4_4, psk_4_5, psk_4_6, psk_4_7, sd_psk_4_0, sd_psk_4_1, sd_psk_4_2, sd_psk_4_3, sd_psk_4_4, sd_psk_4_5, sd_psk_4_6, sd_psk_4_7
+from .qam_constellations import qam_16_0, sd_qam_16_0
def test_qpsk(i, sample, prec):
qpsk_const_list = [psk_4_0, psk_4_1, psk_4_2, psk_4_3,
@@ -61,7 +66,7 @@ def test_qpsk(i, sample, prec):
y_cpp_table, y_cpp_raw_calc, constel, code, c)
def test_qam16(i, sample, prec):
- sample = sample/1
+ sample = sample / 1
qam_const_list = [qam_16_0, ]
qam_lut_gen_list = [sd_qam_16_0, ]
@@ -114,12 +119,12 @@ if __name__ == "__main__":
k = numpy.log2(len(constel))
- print "Sample: ", x
- print "Python Generator Calculated: ", (y_python_gen_calc)
- print "Python Generator Table: ", (y_python_table)
- print "Python Raw calc: ", (y_python_raw_calc)
- print "C++ Table calc: ", (y_cpp_table)
- print "C++ Raw calc: ", (y_cpp_raw_calc)
+ print("Sample: ", x)
+ print("Python Generator Calculated: ", (y_python_gen_calc))
+ print("Python Generator Table: ", (y_python_table))
+ print("Python Raw calc: ", (y_python_raw_calc))
+ print("C++ Table calc: ", (y_cpp_table))
+ print("C++ Raw calc: ", (y_cpp_raw_calc))
fig = pylab.figure(1)
sp1 = fig.add_subplot(1,1,1)
diff --git a/gr-digital/python/digital/utils/alignment.py b/gr-digital/python/digital/utils/alignment.py
index f3ad3781e2..e9292a4bcc 100644
--- a/gr-digital/python/digital/utils/alignment.py
+++ b/gr-digital/python/digital/utils/alignment.py
@@ -41,6 +41,8 @@ This module contains functions for aligning sequences.
(100, -20)
"""
+from __future__ import division
+from __future__ import unicode_literals
import random
@@ -63,7 +65,7 @@ def compare_sequences(d1, d2, offset, sample_indices=None):
"""
max_index = min(len(d1), len(d2)+offset)
if sample_indices is None:
- sample_indices = range(0, max_index)
+ sample_indices = list(range(0, max_index))
correct = 0
total = 0
for i in sample_indices:
@@ -84,8 +86,8 @@ def random_sample(size, num_samples=def_num_samples, seed=None):
if num_samples > size:
indices = set(range(0, size))
else:
- if num_samples > size/2:
- num_samples = num_samples/2
+ if num_samples > size / 2:
+ num_samples = num_samples / 2
indices = set([])
while len(indices) < num_samples:
index = rndm.randint(0, size-1)
@@ -119,8 +121,8 @@ def align_sequences(d1, d2,
best_offset = None
best_compared = None
best_correct = None
- pos_range = range(0, min(len(d1), max_offset))
- neg_range = range(-1, -min(len(d2), max_offset), -1)
+ pos_range = list(range(0, min(len(d1), max_offset)))
+ neg_range = list(range(-1, -min(len(d2), max_offset), -1))
# Interleave the positive and negative offsets.
int_range = [item for items in zip(pos_range, neg_range) for item in items]
for offset in int_range:
diff --git a/gr-digital/python/digital/utils/gray_code.py b/gr-digital/python/digital/utils/gray_code.py
index 926a1ded10..ad88274087 100644
--- a/gr-digital/python/digital/utils/gray_code.py
+++ b/gr-digital/python/digital/utils/gray_code.py
@@ -1,25 +1,27 @@
#!/usr/bin/env python
#
# Copyright 2011 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+from __future__ import division
+from __future__ import unicode_literals
class GrayCodeGenerator(object):
"""
Generates and caches gray codes.
@@ -41,7 +43,7 @@ class GrayCodeGenerator(object):
if len(self.gcs) < length:
self.generate_new_gray_code(length)
return self.gcs[:length]
-
+
def generate_new_gray_code(self, length):
"""
Generates new gray code and places into cache.
@@ -49,7 +51,7 @@ class GrayCodeGenerator(object):
while len(self.gcs) < length:
if self.i == self.lp2:
# if i is a power of two then gray number is of form 1100000...
- result = self.i + self.i/2
+ result = self.i + self.i // 2
else:
# if not we take advantage of the symmetry of all but the last bit
# around a power of two.
diff --git a/gr-digital/python/digital/utils/mod_codes.py b/gr-digital/python/digital/utils/mod_codes.py
index f55fe41b8b..586ab1999a 100644
--- a/gr-digital/python/digital/utils/mod_codes.py
+++ b/gr-digital/python/digital/utils/mod_codes.py
@@ -21,6 +21,7 @@
#
# Constants used to represent what coding to use.
+from __future__ import unicode_literals
GRAY_CODE = 'gray'
SET_PARTITION_CODE = 'set-partition'
NO_CODE = 'none'
diff --git a/gr-digital/python/digital/utils/tagged_streams.py b/gr-digital/python/digital/utils/tagged_streams.py
index 4b393bfc20..68267a293e 100644
--- a/gr-digital/python/digital/utils/tagged_streams.py
+++ b/gr-digital/python/digital/utils/tagged_streams.py
@@ -1,27 +1,30 @@
#!/usr/bin/env python
#
# Copyright 2013 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
# DEPRECATED -- Marked for removal in 3.8
+from __future__ import print_function
+from __future__ import division
+from __future__ import unicode_literals
from gnuradio import gr
import pmt
@@ -30,9 +33,9 @@ def make_lengthtags(lengths, offsets, tagname='length', vlen=1):
assert(len(offsets) == len(lengths))
for offset, length in zip(offsets, lengths):
tag = gr.tag_t()
- tag.offset = offset/vlen
+ tag.offset = offset / vlen
tag.key = pmt.string_to_symbol(tagname)
- tag.value = pmt.from_long(length/vlen)
+ tag.value = pmt.from_long(length / vlen)
tags.append(tag)
return tags
@@ -75,7 +78,7 @@ def count_bursts(data, tags, lengthtagname, vlen=1):
if pos in lengths:
if in_packet:
print("Got tag at pos {0} current packet_pos is {1}".format(pos, packet_pos))
- raise StandardError("Received packet tag while in packet.")
+ raise Exception("Received packet tag while in packet.")
packet_pos = -1
packet_length = lengths[pos]
in_packet = True
@@ -127,9 +130,9 @@ def packets_to_vectors(packets, lengthtagname, vlen=1):
for packet in packets:
data.extend(packet)
tag = gr.tag_t()
- tag.offset = offset/vlen
+ tag.offset = offset // vlen
tag.key = pmt.string_to_symbol(lengthtagname)
- tag.value = pmt.from_long(len(packet)/vlen)
+ tag.value = pmt.from_long(len(packet) // vlen)
tags.append(tag)
offset = offset + len(packet)
return data, tags