diff options
author | Andrej Rode <mail@andrejro.de> | 2018-06-23 23:41:42 +0200 |
---|---|---|
committer | Andrej Rode <mail@andrejro.de> | 2018-06-24 00:03:35 +0200 |
commit | 167a6152bad060fc53dd29e0fa79ef83eff1be5b (patch) | |
tree | a01049672d9d7d1bf3d295ed96698a323941f8e8 /gr-trellis/python | |
parent | 3c8e6008b092287246234001db7cf1a4038300da (diff) | |
parent | fcd002b6ac82e1e0c1224e24506410ff0833e1aa (diff) |
Merge branch 'python3_fix' into next
Manual merge conflict resolution has been applied to following
conflicts:
* Typos:
* gnuradio-runtime/python/gnuradio/ctrlport/GrDataPlotter.py
* gr-blocks/python/blocks/qa_wavfile.py
* gr-filter/examples/gr_filtdes_api.py
* grc/blocks/parameter.xml
* gr-uhd/python/uhd/__init__.py
* ValueError -> RuntimeError:
* gr-blocks/python/blocks/qa_hier_block2.py
* relative Imports & other Py3k:
* gr-digital/python/digital/psk_constellations.py
* gr-digital/python/digital/qam_constellations.py
* gr-digital/python/digital/test_soft_decisions.py
* gr-digital/python/digital/gfsk.py
* SequenceCompleter:
* gr-utils/python/modtool/modtool_add.py
* gr-utils/python/modtool/modtool_rename.py
* gr-utils/python/modtool/modtool_rm.py
* Updated API on next:
* gr-blocks/grc/blocks_file_source.xml
* gr-blocks/python/blocks/qa_file_source_sink.py
* gr-qtgui/grc/qtgui_time_sink_x.xml
* GRC Py3k Updates:
* grc/core/Block.py
* grc/core/Constants.py
* grc/core/Platform.py
* grc/core/utils/odict.py
* grc/gui/Actions.py
* grc/gui/Block.py
* grc/gui/Executor.py
* grc/gui/Port.py
Diffstat (limited to 'gr-trellis/python')
-rw-r--r-- | gr-trellis/python/trellis/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gr-trellis/python/trellis/__init__.py | 5 | ||||
-rw-r--r--[-rwxr-xr-x] | gr-trellis/python/trellis/fsm_utils.py | 56 | ||||
-rw-r--r--[-rwxr-xr-x] | gr-trellis/python/trellis/qa_trellis.py | 14 |
4 files changed, 41 insertions, 36 deletions
diff --git a/gr-trellis/python/trellis/CMakeLists.txt b/gr-trellis/python/trellis/CMakeLists.txt index 10fd9d5c0e..94a160b310 100644 --- a/gr-trellis/python/trellis/CMakeLists.txt +++ b/gr-trellis/python/trellis/CMakeLists.txt @@ -44,6 +44,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-trellis/python/trellis/__init__.py b/gr-trellis/python/trellis/__init__.py index a6b5ed0038..445a381424 100644 --- a/gr-trellis/python/trellis/__init__.py +++ b/gr-trellis/python/trellis/__init__.py @@ -21,15 +21,16 @@ ''' Blocks and utilities for trellis coding and related. ''' +from __future__ import unicode_literals # The presence of this file turns this directory into a Python package import os try: - from trellis_swig import * + from .trellis_swig import * except ImportError: dirname, filename = os.path.split(os.path.abspath(__file__)) __path__.append(os.path.join(dirname, "..", "..", "swig")) - from trellis_swig import * + from .trellis_swig import * # import any pure python here diff --git a/gr-trellis/python/trellis/fsm_utils.py b/gr-trellis/python/trellis/fsm_utils.py index 72aa1d3660..efc526c0e7 100755..100644 --- a/gr-trellis/python/trellis/fsm_utils.py +++ b/gr-trellis/python/trellis/fsm_utils.py @@ -20,11 +20,13 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function +from __future__ import division +from __future__ import unicode_literals -import re import math import sys -import operator + import numpy #from gnuradio import trellis @@ -32,7 +34,7 @@ import numpy try: import scipy.linalg except ImportError: - print "Error: Program requires scipy (see: www.scipy.org)." + print("Error: Program requires scipy (see: www.scipy.org).") sys.exit(1) @@ -43,13 +45,13 @@ except ImportError: # to base 'base' (most significant symbol first). ###################################################################### def dec2base(num,base,l): - s=range(l) + s=list(range(l)) n=num for i in range(l): s[l-i-1]=n%base - n=int(n/base) + n=int(n / base) if n!=0: - print 'Number ', num, ' requires more than ', l, 'digits.' + print('Number ', num, ' requires more than ', l, 'digits.') return s @@ -84,9 +86,9 @@ def make_isi_lookup(mod,channel,normalize): for i in range(len(channel)): p = p + channel[i]**2 for i in range(len(channel)): - channel[i] = channel[i]/math.sqrt(p) + channel[i] = channel[i] / math.sqrt(p) - lookup=range(len(constellation)**len(channel)) + lookup=list(range(len(constellation)**len(channel))) for o in range(len(constellation)**len(channel)): ss=dec2base(o,len(constellation),len(channel)) ll=0 @@ -109,11 +111,11 @@ def make_isi_lookup(mod,channel,normalize): ###################################################################### def make_cpm_signals(K,P,M,L,q,frac): - Q=numpy.size(q)/L - h=(1.0*K)/P + Q=numpy.size(q) / L + h=(1.0*K) / P f0=-h*(M-1)/2 dt=0.0; # maybe start at t=0.5 - t=(dt+numpy.arange(0,Q))/Q + t=(dt+numpy.arange(0 / Q),Q) qq=numpy.zeros(Q) for m in range(L): qq=qq + q[m*Q:m*Q+Q] @@ -122,46 +124,46 @@ def make_cpm_signals(K,P,M,L,q,frac): X=(M**L)*P PSI=numpy.empty((X,Q)) for x in range(X): - xv=dec2base(x/P,M,L) + xv=dec2base(x / P,M,L) xv=numpy.append(xv, x%P) qq1=numpy.zeros(Q) for m in range(L): qq1=qq1+xv[m]*q[m*Q:m*Q+Q] psi=2*math.pi*h*xv[-1]+4*math.pi*h*qq1+w - #print psi + #print(psi) PSI[x]=psi PSI = numpy.transpose(PSI) SS=numpy.exp(1j*PSI) # contains all signals as columns - #print SS + #print(SS) # Now we need to orthogonalize the signals F = scipy.linalg.orth(SS) # find an orthonormal basis for SS - #print numpy.dot(numpy.transpose(F.conjugate()),F) # check for orthonormality + #print(numpy.dot(numpy.transpose(F.conjugate()),F) # check for orthonormality) S = numpy.dot(numpy.transpose(F.conjugate()),SS) - #print F - #print S + #print(F) + #print(S) # We only want to keep those dimensions that contain most # of the energy of the overall constellation (eg, frac=0.9 ==> 90%) # evaluate mean energy in each dimension - E=numpy.sum(numpy.absolute(S)**2,axis=1)/Q - E=E/numpy.sum(E) - #print E + E=numpy.sum(numpy.absolute(S)**2, axis=1) / Q + E=E / numpy.sum(E) + #print(E) Es = -numpy.sort(-E) Esi = numpy.argsort(-E) - #print Es - #print Esi + #print(Es) + #print(Esi) Ecum=numpy.cumsum(Es) - #print Ecum + #print(Ecum) v0=numpy.searchsorted(Ecum,frac) N = v0+1 - #print v0 - #print Esi[0:v0+1] + #print(v0) + #print(Esi[0:v0+1]) Ff=numpy.transpose(numpy.transpose(F)[Esi[0:v0+1]]) - #print Ff + #print(Ff) Sf = S[Esi[0:v0+1]] - #print Sf + #print(Sf) return (f0,SS,S,F,Sf,Ff,N) diff --git a/gr-trellis/python/trellis/qa_trellis.py b/gr-trellis/python/trellis/qa_trellis.py index 0ed802a0fd..6d14fefe85 100755..100644 --- a/gr-trellis/python/trellis/qa_trellis.py +++ b/gr-trellis/python/trellis/qa_trellis.py @@ -20,6 +20,8 @@ # Boston, MA 02110-1301, USA. # +from __future__ import division + import math import os @@ -71,7 +73,7 @@ class test_trellis (gr_unittest.TestCase): Runs some coding/decoding tests with a few different FSM specs. """ - for name, args in fsm_args.items(): + for name, args in list(fsm_args.items()): constellation = constells[args[2]] fsms = trellis.fsm(*args) noise = 0.1 @@ -85,7 +87,7 @@ class trellis_tb(gr.top_block): """ A simple top block for use testing gr-trellis. """ - def __init__(self, constellation, f, N0=0.25, seed=-666L): + def __init__(self, constellation, f, N0=0.25, seed=-666): """ constellation - a constellation object used for modulation. f - a finite state machine specification used for coding. @@ -96,14 +98,14 @@ class trellis_tb(gr.top_block): # packet size in bits (make it multiple of 16 so it can be packed in a short) packet_size = 1024*16 # bits per FSM input symbol - bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol + bitspersymbol = int(round(math.log(f.I()) / math.log(2))) # bits per FSM input symbol # packet size in trellis steps - K = packet_size/bitspersymbol + K = packet_size // bitspersymbol # TX src = blocks.lfsr_32k_source_s() # packet size in shorts - src_head = blocks.head(gr.sizeof_short, packet_size/16) + src_head = blocks.head(gr.sizeof_short, packet_size // 16) # unpack shorts to symbols compatible with the FSM input cardinality s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol, gr.GR_MSB_FIRST) # initial FSM state = 0 @@ -112,7 +114,7 @@ class trellis_tb(gr.top_block): # CHANNEL add = blocks.add_cc() - noise = analog.noise_source_c(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed) + noise = analog.noise_source_c(analog.GR_GAUSSIAN,math.sqrt(N0 / 2),seed) # RX # data preprocessing to generate metrics for Viterbi |