diff options
author | Josh Morman <jmorman@gnuradio.org> | 2021-11-24 12:40:24 -0500 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-11-24 14:41:53 -0500 |
commit | de184bd22f98b714bc2f383d59126cd2510374fe (patch) | |
tree | 87dfc815886175fa59cbb3d6f88978616d810d01 /gr-trellis/python | |
parent | 8ab3e5a686f89ae7711cec9496cdc6598a4ad80b (diff) |
trellis: pep8 formatting
Signed-off-by: Josh Morman <jmorman@gnuradio.org>
Diffstat (limited to 'gr-trellis/python')
-rw-r--r-- | gr-trellis/python/trellis/fsm_utils.py | 169 |
1 files changed, 84 insertions, 85 deletions
diff --git a/gr-trellis/python/trellis/fsm_utils.py b/gr-trellis/python/trellis/fsm_utils.py index 0cbd6b6750..7e78b19fa0 100644 --- a/gr-trellis/python/trellis/fsm_utils.py +++ b/gr-trellis/python/trellis/fsm_utils.py @@ -30,9 +30,9 @@ def dec2base(num, base, 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: + s[l - i - 1] = n % base + n = int(n / base) + if n != 0: print('Number ', num, ' requires more than ', l, 'digits.') return s @@ -68,14 +68,14 @@ def make_isi_lookup(mod, channel, normalize): for i in range(len(channel)): channel[i] = channel[i] / math.sqrt(p) - lookup=list(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): @@ -101,51 +101,50 @@ 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 - #print(psi) - PSI[x]=psi + 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) - + 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) -#return f0 +# return f0 ###################################################################### # A list of common modulations. @@ -155,52 +154,52 @@ 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 - -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), \ - math.cos(2*math.pi*2/8), math.sin(2*math.pi*2/8), \ - math.cos(2*math.pi*3/8), math.sin(2*math.pi*3/8), \ - math.cos(2*math.pi*4/8), math.sin(2*math.pi*4/8), \ - math.cos(2*math.pi*5/8), math.sin(2*math.pi*5/8), \ - math.cos(2*math.pi*6/8), math.sin(2*math.pi*6/8), \ - math.cos(2*math.pi*7/8), math.sin(2*math.pi*7/8)]) - -psk2x3 = (3,[-1,-1,-1, \ - -1,-1,1, \ - -1,1,-1, \ - -1,1,1, \ - 1,-1,-1, \ - 1,-1,1, \ - 1,1,-1, \ - 1,1,1]) - -psk2x4 = (4,[-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, \ - 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]) - -orth2 = (2,[1, 0, \ - 0, 1]) -orth4=(4,[1, 0, 0, 0, \ - 0, 1, 0, 0, \ - 0, 0, 1, 0, \ - 0, 0, 0, 1]) +psk4 = (2, [1, 0, + 0, 1, + 0, -1, + -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), + math.cos(2 * math.pi * 2 / 8), math.sin(2 * math.pi * 2 / 8), + math.cos(2 * math.pi * 3 / 8), math.sin(2 * math.pi * 3 / 8), + math.cos(2 * math.pi * 4 / 8), math.sin(2 * math.pi * 4 / 8), + math.cos(2 * math.pi * 5 / 8), math.sin(2 * math.pi * 5 / 8), + math.cos(2 * math.pi * 6 / 8), math.sin(2 * math.pi * 6 / 8), + math.cos(2 * math.pi * 7 / 8), math.sin(2 * math.pi * 7 / 8)]) + +psk2x3 = (3, [-1, -1, -1, + -1, -1, 1, + -1, 1, -1, + -1, 1, 1, + 1, -1, -1, + 1, -1, 1, + 1, 1, -1, + 1, 1, 1]) + +psk2x4 = (4, [-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, + 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]) + +orth2 = (2, [1, 0, + 0, 1]) +orth4 = (4, [1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1]) ###################################################################### # A list of channels to be tested |