Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / blksimpl / psk.py
1 #
2 # Copyright 2005,2006 Free Software Foundation, Inc.
3
4 # This file is part of GNU Radio
5
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
10
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING.  If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
20
21
22 from math import pi, sqrt
23 import cmath
24
25 def make_constellation(m):
26     return [cmath.exp(i * 2 * pi / m * 1j) for i in range(m)]
27         
28 # Common definition of constellations for Tx and Rx
29 constellation = {
30     2 : make_constellation(2),           # BPSK
31     4 : make_constellation(4),           # QPSK
32     8 : make_constellation(8)            # 8PSK
33     }
34
35 # -----------------------
36 # Do Gray code
37 # -----------------------
38 # binary to gray coding
39 binary_to_gray = {
40     2 : (0, 1),
41     4 : (0, 1, 3, 2),
42     8 : (0, 1, 3, 2, 7, 6, 4, 5)
43     }
44    
45 # gray to binary
46 gray_to_binary = {
47     2 : (0, 1),
48     4 : (0, 1, 3, 2),
49     8 : (0, 1, 3, 2, 6, 7, 5, 4)
50     }
51
52 # -----------------------
53 # Don't Gray code
54 # -----------------------
55 # identity mapping
56 binary_to_ungray = {
57     2 : (0, 1),
58     4 : (0, 1, 2, 3),
59     8 : (0, 1, 2, 3, 4, 5, 6, 7)
60     }
61     
62 # identity mapping
63 ungray_to_binary = {
64     2 : (0, 1),
65     4 : (0, 1, 2, 3),
66     8 : (0, 1, 2, 3, 4, 5, 6, 7)
67     }