summaryrefslogtreecommitdiff
path: root/gr-trellis/python
diff options
context:
space:
mode:
authorMarcus Müller <marcus@hostalia.de>2018-08-31 23:02:22 +0200
committerMarcus Müller <marcus@hostalia.de>2018-08-31 23:02:22 +0200
commit254fe5e89403d4de1fa6663d09efdf946996aff3 (patch)
tree62877d7ac7fdedf6c397c51e22ac6f97eba97ddf /gr-trellis/python
parent896d1c9da31963ecf5b0d90942c2af51ca998a69 (diff)
parent5ad935c3a3dd46ce2860b13e2b774e4841784616 (diff)
Merge remote-tracking branch 'origin/next' into merge_next
Diffstat (limited to 'gr-trellis/python')
-rw-r--r--gr-trellis/python/trellis/CMakeLists.txt3
-rw-r--r--gr-trellis/python/trellis/__init__.py5
-rw-r--r--[-rwxr-xr-x]gr-trellis/python/trellis/fsm_utils.py90
-rw-r--r--[-rwxr-xr-x]gr-trellis/python/trellis/qa_trellis.py14
4 files changed, 59 insertions, 53 deletions
diff --git a/gr-trellis/python/trellis/CMakeLists.txt b/gr-trellis/python/trellis/CMakeLists.txt
index d38267d155..862a274248 100644
--- a/gr-trellis/python/trellis/CMakeLists.txt
+++ b/gr-trellis/python/trellis/CMakeLists.txt
@@ -27,7 +27,6 @@ GR_PYTHON_INSTALL(
__init__.py
fsm_utils.py
DESTINATION ${GR_PYTHON_DIR}/gnuradio/trellis
- COMPONENT "trellis_python"
)
########################################################################
@@ -52,6 +51,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 f4076623a5..25c552a226 100755..100644
--- a/gr-trellis/python/trellis/fsm_utils.py
+++ b/gr-trellis/python/trellis/fsm_utils.py
@@ -20,18 +20,19 @@
# Boston, MA 02110-1301, USA.
#
-import re
+from __future__ import print_function
+from __future__ import division
+from __future__ import unicode_literals
+
import math
import sys
-import operator
-import numpy
-#from gnuradio import trellis
+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)
@@ -41,13 +42,13 @@ def dec2base(num, base, l):
Convert 'num' to a list of 'l' numbers representing 'num'
to base 'base' (most significant symbol first).
"""
- s = range(l)
+ s = list(range(l))
n = num
for i in range(l):
- s[l - i - 1] = n % base
- n = int(n / base)
- if n != 0:
- print 'Number ', num, ' requires more than ', l, 'digits.'
+ s[l-i-1]=n%base
+ n=int(n / base)
+ if n!=0:
+ print('Number ', num, ' requires more than ', l, 'digits.')
return s
@@ -82,14 +83,14 @@ def make_isi_lookup(mod, channel, normalize):
for i in range(len(channel)):
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
for i in range(len(channel)):
- ll = ll + constellation[ss[i]] * channel[i]
- lookup[o] = ll
- return (1, lookup)
+ ll=ll+constellation[ss[i]]*channel[i]
+ lookup[o]=ll
+ return (1,lookup)
def make_cpm_signals(K, P, M, L, q, frac):
@@ -115,43 +116,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 = 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
- PSI[x] = psi
- PSI = numpy.transpose(PSI)
- SS = numpy.exp(1j * PSI) # contains all signals as columns
+ 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)
+ PSI[x]=psi
+ PSI = numpy.transpose(PSI)
+ SS=numpy.exp(1j*PSI) # contains all signals as columns
+ #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
- S = numpy.dot(numpy.transpose(F.conjugate()), SS)
- #print F
- #print S
+ F = scipy.linalg.orth(SS) # find an orthonormal basis for SS
+ #print(numpy.dot(numpy.transpose(F.conjugate()),F) # check for orthonormality)
+ S = numpy.dot(numpy.transpose(F.conjugate()),SS)
+ #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
- Ecum = numpy.cumsum(Es)
- #print Ecum
- v0 = numpy.searchsorted(Ecum, frac)
- N = v0 + 1
- #print v0
- #print Esi[0:v0+1]
- Ff = numpy.transpose(numpy.transpose(F)[Esi[0:v0 + 1]])
- #print Ff
- Sf = S[Esi[0:v0 + 1]]
- #print Sf
+ #print(Es)
+ #print(Esi)
+ Ecum=numpy.cumsum(Es)
+ #print(Ecum)
+ v0=numpy.searchsorted(Ecum,frac)
+ N = v0+1
+ #print(v0)
+ #print(Esi[0:v0+1])
+ Ff=numpy.transpose(numpy.transpose(F)[Esi[0:v0+1]])
+ #print(Ff)
+ Sf = S[Esi[0:v0+1]]
+ #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