1
1
2
- # Copyright 2012 Veeresh Taranalli <[email protected] >
3
- #
4
- # This file is part of CommPy.
5
- #
6
- # CommPy 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 3 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # CommPy 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 this program. If not, see <http://www.gnu.org/licenses/>.
2
+
3
+ # Authors: Veeresh Taranalli <[email protected] >
4
+ # License: BSD 3-Clause
18
5
19
6
""" LDPC Codes """
20
7
from numpy import zeros , shape , tanh , arctanh , array , delete , prod , dot
21
8
22
9
__all__ = ['ldpc_decode' ]
23
10
24
11
def ldpc_decode (pcheck_matrix , rx_codeword , n_iters ):
25
- """
12
+ """
26
13
LDPC Decoder using belief propagation for an AWGN channel.
27
14
28
15
Parameters
@@ -53,10 +40,10 @@ def ldpc_decode(pcheck_matrix, rx_codeword, n_iters):
53
40
prev_llrs = delete (llr_vals , v_node )
54
41
prev_llrs = prev_llrs [delete (pcheck_matrix [c_node , :], v_node ) == 1 ]
55
42
prev_compvals = delete (comp_mat [c_node , :], v_node )
56
- prev_compvals = prev_compvals [delete (pcheck_matrix [c_node , :], v_node ) == 1 ]
43
+ prev_compvals = prev_compvals [delete (pcheck_matrix [c_node , :], v_node ) == 1 ]
57
44
llr_prod = prod (tanh (- (prev_llrs - prev_compvals )/ 2 ))
58
45
comp_mat [c_node , v_node ] = - 2 * arctanh (llr_prod )
59
-
46
+
60
47
# Variable Node Update
61
48
for v_node in xrange (n_v_nodes ):
62
49
llr_vals [v_node ] = llr_vals [v_node ] + sum (comp_mat [:,v_node ][pcheck_matrix [:,v_node ]== 1 ])
@@ -65,20 +52,18 @@ def ldpc_decode(pcheck_matrix, rx_codeword, n_iters):
65
52
if not (dot (pcheck_matrix , decoded_bits )% 2 ).any ():
66
53
print "Perfect Decoding, # Iterations: " + str (i + 1 )
67
54
break
68
-
55
+
69
56
return decoded_bits
70
57
71
58
if __name__ == '__main__' :
72
59
73
- pcheck_matrix = array ([[1 , 1 , 1 , 0 , 0 , 1 , 1 , 0 , 0 , 1 ],
60
+ pcheck_matrix = array ([[1 , 1 , 1 , 0 , 0 , 1 , 1 , 0 , 0 , 1 ],
74
61
[1 , 0 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 ],
75
62
[0 , 0 , 1 , 1 , 1 , 0 , 1 , 0 , 1 , 1 ],
76
63
[0 , 1 , 0 , 1 , 1 , 1 , 0 , 1 , 0 , 1 ],
77
64
[1 , 1 , 0 , 1 , 0 , 0 , 1 , 1 , 1 , 0 ]])
78
65
rx_codeword = array ([- 1.3 , - 1.7 , - 1.5 , - 0.08 , 0.2 , 1.9 , - 1.5 , 1.3 , - 1.1 , 1.2 ])
79
66
n_iters = 10
80
67
decoded_bits = ldpc_decode (pcheck_matrix , rx_codeword , n_iters )
81
-
82
- print decoded_bits
83
-
84
68
69
+ print decoded_bits
0 commit comments