diff options
author | trondeau <trondeau@221aa14e-8319-0410-a670-987f0aec2ac5> | 2007-03-07 04:31:19 +0000 |
---|---|---|
committer | trondeau <trondeau@221aa14e-8319-0410-a670-987f0aec2ac5> | 2007-03-07 04:31:19 +0000 |
commit | 28e086141aead2e43f958f0ae14d58cac557fa2d (patch) | |
tree | 1ae54b3d508506d4ea25c7e8a335c5e2cd56dcef /gnuradio-core/src/python/gnuradio/blksimpl/psk.py | |
parent | 224434889bf564a4456011180c62a58e0ca55c8f (diff) |
merged trondeau/digital-wip2 r4193:4730 into trunk - improves digital receiver and fixes ticket:72
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4731 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-core/src/python/gnuradio/blksimpl/psk.py')
-rw-r--r-- | gnuradio-core/src/python/gnuradio/blksimpl/psk.py | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/gnuradio-core/src/python/gnuradio/blksimpl/psk.py b/gnuradio-core/src/python/gnuradio/blksimpl/psk.py index fdb6c9e693..58677b29d0 100644 --- a/gnuradio-core/src/python/gnuradio/blksimpl/psk.py +++ b/gnuradio-core/src/python/gnuradio/blksimpl/psk.py @@ -19,12 +19,33 @@ # Boston, MA 02110-1301, USA. # -from math import pi, sqrt -import cmath +from math import pi, sqrt, log10 +import math, cmath +# The following algorithm generates Gray coded constellations for M-PSK for M=[2,4,8] +def make_gray_constellation(m): + # number of bits/symbol (log2(M)) + k = int(log10(m) / log10(2.0)) + + coeff = 1 + const_map = [] + bits = [0]*3 + for i in range(m): + # get a vector of the k bits to use in this mapping + bits[3-k:3] = [((i&(0x01 << k-j-1)) >> k-j-1) for j in range(k)] + + theta = -(2*bits[0]-1)*(2*pi/m)*(bits[0]+abs(bits[1]-bits[2])+2*bits[1]) + re = math.cos(theta) + im = math.sin(theta) + const_map.append(complex(re, im)) # plug it into the constellation + + # return the constellation; by default, it is normalized + return const_map + +# This makes a constellation that increments around the unit circle def make_constellation(m): return [cmath.exp(i * 2 * pi / m * 1j) for i in range(m)] - + # Common definition of constellations for Tx and Rx constellation = { 2 : make_constellation(2), # BPSK @@ -35,18 +56,18 @@ constellation = { # ----------------------- # Do Gray code # ----------------------- -# binary to gray coding +# binary to gray coding -- constellation does Gray coding binary_to_gray = { - 2 : (0, 1), - 4 : (0, 1, 3, 2), - 8 : (0, 1, 3, 2, 7, 6, 4, 5) + 2 : range(2), + 4 : [0,1,3,2], + 8 : [0, 1, 3, 2, 7, 6, 4, 5] } - + # gray to binary gray_to_binary = { - 2 : (0, 1), - 4 : (0, 1, 3, 2), - 8 : (0, 1, 3, 2, 6, 7, 5, 4) + 2 : range(2), + 4 : [0,1,3,2], + 8 : [0, 1, 3, 2, 6, 7, 5, 4] } # ----------------------- @@ -54,14 +75,14 @@ gray_to_binary = { # ----------------------- # identity mapping binary_to_ungray = { - 2 : (0, 1), - 4 : (0, 1, 2, 3), - 8 : (0, 1, 2, 3, 4, 5, 6, 7) + 2 : range(2), + 4 : range(4), + 8 : range(8) } - + # identity mapping ungray_to_binary = { - 2 : (0, 1), - 4 : (0, 1, 2, 3), - 8 : (0, 1, 2, 3, 4, 5, 6, 7) + 2 : range(2), + 4 : range(4), + 8 : range(8) } |