Updated license from GPL version 2 or later to GPL version 3 or later.
[debian/gnuradio] / gr-atsc / src / lib / gen_encoder.py
1 #!/usr/bin/python
2 #
3 # Copyright 2002 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING.  If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 def output(input, state):
24     x2 = (input >> 1) & 0x1
25     x1 = (input >> 0) & 0x1
26     s = (state >> 2) & 0x1
27     t = (state >> 1) & 0x1
28     u = (state >> 0) & 0x1
29
30     z0 = u
31     z1 = x1
32     z2 = x2 ^ s
33     return (z2 << 2) | (z1 << 1) | z0
34
35
36 def next_state(input, state):
37     x2 = (input >> 1) & 0x1
38     x1 = (input >> 0) & 0x1
39     s0 = (state >> 2) & 0x1
40     t0 = (state >> 1) & 0x1
41     u0 = (state >> 0) & 0x1
42
43     s1 = x2 ^ s0
44     t1 = u0
45     u1 = t0 ^ x1
46     
47     return (s1 << 2) | (t1 << 1) | u1
48
49 print "@@@ NEXT @@@"
50
51 for i in range (32):
52     state = (i >> 2) & 0x7
53     input = i & 0x3
54     print next_state (input, state)
55
56
57 print "@@@ OUTPUT @@@"
58
59 for i in range (32):
60     state = (i >> 2) & 0x7
61     input = i & 0x3
62     print output (input, state)
63