commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r4057 - gnuradio/branches/developers/trondeau/digital-


From: trondeau
Subject: [Commit-gnuradio] r4057 - gnuradio/branches/developers/trondeau/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl
Date: Mon, 11 Dec 2006 10:17:24 -0700 (MST)

Author: trondeau
Date: 2006-12-11 10:17:24 -0700 (Mon, 11 Dec 2006)
New Revision: 4057

Modified:
   
gnuradio/branches/developers/trondeau/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/psk.py
Log:
signal constellations for M-PSK are now automatically generated using Gray 
coding

Modified: 
gnuradio/branches/developers/trondeau/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/psk.py
===================================================================
--- 
gnuradio/branches/developers/trondeau/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/psk.py
 2006-12-05 02:12:02 UTC (rev 4056)
+++ 
gnuradio/branches/developers/trondeau/digital-wip/gnuradio-core/src/python/gnuradio/blksimpl/psk.py
 2006-12-11 17:17:24 UTC (rev 4057)
@@ -19,12 +19,30 @@
 # Boston, MA 02110-1301, USA.
 # 
 
-from math import pi, sqrt
-import cmath
+from math import pi, sqrt, log10
+import math
 
+# The following algorithm generates Gray coded constellations for M-PSK for 
M=[2,4,8]
 def make_constellation(m):
-    return [cmath.exp(i * 2 * pi / m * 1j) for i in range(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
+
+        
 # Common definition of constellations for Tx and Rx
 constellation = {
     2 : make_constellation(2),           # BPSK
@@ -35,18 +53,18 @@
 # -----------------------
 # 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 : range(4),
+    8 : range(8)
     }
    
 # 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 : range(4),
+    8 : range(8)
     }
 
 # -----------------------
@@ -54,14 +72,14 @@
 # -----------------------
 # 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)
     }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]