11
2- # Copyright 2012 Veeresh Taranalli <veeresht@gmail.com>
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 <veeresht@gmail.com>
4+ # License: BSD 3-Clause
185
196""" LDPC Codes """
207from numpy import zeros , shape , tanh , arctanh , array , delete , prod , dot
218
229__all__ = ['ldpc_decode' ]
2310
2411def ldpc_decode (pcheck_matrix , rx_codeword , n_iters ):
25- """
12+ """
2613 LDPC Decoder using belief propagation for an AWGN channel.
2714
2815 Parameters
@@ -53,10 +40,10 @@ def ldpc_decode(pcheck_matrix, rx_codeword, n_iters):
5340 prev_llrs = delete (llr_vals , v_node )
5441 prev_llrs = prev_llrs [delete (pcheck_matrix [c_node , :], v_node ) == 1 ]
5542 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 ]
5744 llr_prod = prod (tanh (- (prev_llrs - prev_compvals )/ 2 ))
5845 comp_mat [c_node , v_node ] = - 2 * arctanh (llr_prod )
59-
46+
6047 # Variable Node Update
6148 for v_node in xrange (n_v_nodes ):
6249 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):
6552 if not (dot (pcheck_matrix , decoded_bits )% 2 ).any ():
6653 print "Perfect Decoding, # Iterations: " + str (i + 1 )
6754 break
68-
55+
6956 return decoded_bits
7057
7158if __name__ == '__main__' :
7259
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 ],
7461 [1 , 0 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 ],
7562 [0 , 0 , 1 , 1 , 1 , 0 , 1 , 0 , 1 , 1 ],
7663 [0 , 1 , 0 , 1 , 1 , 1 , 0 , 1 , 0 , 1 ],
7764 [1 , 1 , 0 , 1 , 0 , 0 , 1 , 1 , 1 , 0 ]])
7865 rx_codeword = array ([- 1.3 , - 1.7 , - 1.5 , - 0.08 , 0.2 , 1.9 , - 1.5 , 1.3 , - 1.1 , 1.2 ])
7966 n_iters = 10
8067 decoded_bits = ldpc_decode (pcheck_matrix , rx_codeword , n_iters )
81-
82- print decoded_bits
83-
8468
69+ print decoded_bits
0 commit comments