summaryrefslogtreecommitdiff
path: root/gr-trellis/python/trellis/fsm_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'gr-trellis/python/trellis/fsm_utils.py')
-rw-r--r--gr-trellis/python/trellis/fsm_utils.py119
1 files changed, 54 insertions, 65 deletions
diff --git a/gr-trellis/python/trellis/fsm_utils.py b/gr-trellis/python/trellis/fsm_utils.py
index efc526c0e7..25c552a226 100644
--- a/gr-trellis/python/trellis/fsm_utils.py
+++ b/gr-trellis/python/trellis/fsm_utils.py
@@ -29,8 +29,6 @@ import sys
import numpy
-#from gnuradio import trellis
-
try:
import scipy.linalg
except ImportError:
@@ -38,15 +36,14 @@ except ImportError:
sys.exit(1)
-
-######################################################################
-# Decimal to any base conversion.
-# Convert 'num' to a list of 'l' numbers representing 'num'
-# to base 'base' (most significant symbol first).
-######################################################################
-def dec2base(num,base,l):
- s=list(range(l))
- n=num
+def dec2base(num, base, l):
+ """
+ Decimal to any base conversion.
+ Convert 'num' to a list of 'l' numbers representing 'num'
+ to base 'base' (most significant symbol first).
+ """
+ s = list(range(l))
+ n = num
for i in range(l):
s[l-i-1]=n%base
n=int(n / base)
@@ -55,30 +52,28 @@ def dec2base(num,base,l):
return s
-######################################################################
-# Conversion from any base to decimal.
-# Convert a list 's' of symbols to a decimal number
-# (most significant symbol first)
-######################################################################
-def base2dec(s,base):
- num=0
+def base2dec(s, base):
+ """
+ Conversion from any base to decimal.
+ Convert a list 's' of symbols to a decimal number
+ (most significant symbol first)
+ """
+ num = 0
for i in range(len(s)):
- num=num*base+s[i]
+ num = num * base + s[i]
return num
-
-
-######################################################################
-# Automatically generate the lookup table that maps the FSM outputs
-# to channel inputs corresponding to a channel 'channel' and a modulation
-# 'mod'. Optional normalization of channel to unit energy.
-# This table is used by the 'metrics' block to translate
-# channel outputs to metrics for use with the Viterbi algorithm.
-# Limitations: currently supports only one-dimensional modulations.
-######################################################################
-def make_isi_lookup(mod,channel,normalize):
- dim=mod[0]
+def make_isi_lookup(mod, channel, normalize):
+ """
+ Automatically generate the lookup table that maps the FSM outputs
+ to channel inputs corresponding to a channel 'channel' and a modulation
+ 'mod'. Optional normalization of channel to unit energy.
+ This table is used by the 'metrics' block to translate
+ channel outputs to metrics for use with the Viterbi algorithm.
+ Limitations: currently supports only one-dimensional modulations.
+ """
+ dim = mod[0]
constellation = mod[1]
if normalize:
@@ -90,39 +85,36 @@ def make_isi_lookup(mod,channel,normalize):
lookup=list(range(len(constellation)**len(channel)))
for o in range(len(constellation)**len(channel)):
- ss=dec2base(o,len(constellation),len(channel))
- ll=0
+ 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)
-
-
-
-
-######################################################################
-# Automatically generate the signals appropriate for CPM
-# decomposition.
-# This decomposition is based on the paper by B. Rimoldi
-# "A decomposition approach to CPM", IEEE Trans. Info Theory, March 1988
-# See also my own notes at http://www.eecs.umich.edu/~anastas/docs/cpm.pdf
-######################################################################
-def make_cpm_signals(K,P,M,L,q,frac):
-
- 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)
- qq=numpy.zeros(Q)
+def make_cpm_signals(K, P, M, L, q, frac):
+ """
+ Automatically generate the signals appropriate for CPM
+ decomposition.
+ This decomposition is based on the paper by B. Rimoldi
+ "A decomposition approach to CPM", IEEE Trans. Info Theory, March 1988
+ See also my own notes at http://www.eecs.umich.edu/~anastas/docs/cpm.pdf
+ """
+ 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
+ qq = numpy.zeros(Q)
for m in range(L):
- qq=qq + q[m*Q:m*Q+Q]
- w=math.pi*h*(M-1)*t-2*math.pi*h*(M-1)*qq+math.pi*h*(L-1)*(M-1)
+ qq = qq + q[m * Q:m * Q + Q]
+ w = math.pi * h * (M - 1) * t - 2 * math.pi * h * (
+ M - 1) * qq + math.pi * h * (L - 1) * (M - 1)
- X=(M**L)*P
- PSI=numpy.empty((X,Q))
+ 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)
@@ -165,25 +157,23 @@ def make_cpm_signals(K,P,M,L,q,frac):
Sf = S[Esi[0:v0+1]]
#print(Sf)
-
- return (f0,SS,S,F,Sf,Ff,N)
- #return f0
-
+ return (f0, SS, S, F, Sf, Ff, N)
+#return f0
######################################################################
# A list of common modulations.
# Format: (dimensionality,constellation)
######################################################################
-pam2 = (1,[-1, 1])
-pam4 = (1,[-3, -1, 3, 1]) # includes Gray mapping
-pam8 = (1,[-7, -5, -3, -1, 1, 3, 5, 7])
+pam2 = (1, [-1, 1])
+pam4 = (1, [-3, -1, 3, 1]) # includes Gray mapping
+pam8 = (1, [-7, -5, -3, -1, 1, 3, 5, 7])
psk4=(2,[1, 0, \
0, 1, \
0, -1,\
- -1, 0]) # includes Gray mapping
+ -1, 0]) # includes Gray mapping
psk8=(2,[math.cos(2*math.pi*0/8), math.sin(2*math.pi*0/8), \
math.cos(2*math.pi*1/8), math.sin(2*math.pi*1/8), \
@@ -233,4 +223,3 @@ orth4=(4,[1, 0, 0, 0, \
# C test channel (J. Proakis, Digital Communications, McGraw-Hill Inc., 2001)
c_channel = [0.227, 0.460, 0.688, 0.460, 0.227]
-