Skip to content

Commit 2e698d5

Browse files
committed
Added min sum algorithm option for LDPC BP decoder.
1 parent b800392 commit 2e698d5

File tree

1 file changed

+46
-11
lines changed

1 file changed

+46
-11
lines changed

commpy/channelcoding/ldpc.py

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,38 @@ def _limit_llr(in_llr):
9494

9595
return out_llr
9696

97-
98-
def ldpc_bp_decode(llr_vec, ldpc_code_params, n_iters):
97+
def sum_product_update(cnode_idx, cnode_adj_list, cnode_deg_list, cnode_msgs,
98+
vnode_msgs, cnode_vnode_map, max_cnode_deg, max_vnode_deg):
99+
100+
start_idx = cnode_idx*max_cnode_deg
101+
offset = cnode_deg_list[cnode_idx]
102+
vnode_list = cnode_adj_list[start_idx:start_idx+offset]
103+
vnode_list_msgs_tanh = np.tanh(vnode_msgs[vnode_list*max_vnode_deg +
104+
cnode_vnode_map[start_idx:start_idx+offset]]/2.0)
105+
msg_prod = np.prod(vnode_list_msgs_tanh)
106+
107+
# Compute messages on outgoing edges using the incoming message product
108+
cnode_msgs[start_idx:start_idx+offset]= 2.0*np.arctanh(msg_prod/vnode_list_msgs_tanh)
109+
110+
111+
def min_sum_update(cnode_idx, cnode_adj_list, cnode_deg_list, cnode_msgs,
112+
vnode_msgs, cnode_vnode_map, max_cnode_deg, max_vnode_deg):
113+
114+
start_idx = cnode_idx*max_cnode_deg
115+
offset = cnode_deg_list[cnode_idx]
116+
vnode_list = cnode_adj_list[start_idx:start_idx+offset]
117+
vnode_list_msgs = vnode_msgs[vnode_list*max_vnode_deg +
118+
cnode_vnode_map[start_idx:start_idx+offset]]
119+
vnode_list_msgs = np.ma.array(vnode_list_msgs, mask=False)
120+
121+
# Compute messages on outgoing edges using the incoming messages
122+
for i in xrange(start_idx, start_idx+offset):
123+
vnode_list_msgs.mask[i-start_idx] = True
124+
cnode_msgs[i] = np.prod(np.sign(vnode_list_msgs))*np.min(np.abs(vnode_list_msgs))
125+
vnode_list_msgs.mask[i-start_idx] = False
126+
#print cnode_msgs[i]
127+
128+
def ldpc_bp_decode(llr_vec, ldpc_code_params, decoder_algorithm, n_iters):
99129
"""
100130
LDPC Decoder using Belief Propagation (BP).
101131
@@ -107,6 +137,11 @@ def ldpc_bp_decode(llr_vec, ldpc_code_params, n_iters):
107137
ldpc_code_params : dictionary
108138
Parameters of the LDPC code.
109139
140+
decoder_algorithm: string
141+
Specify the decoder algorithm type.
142+
SPA for Sum-Product Algorithm
143+
MSA for Min-Sum Algorithm
144+
110145
n_iters : int
111146
Max. number of iterations of decoding to be done.
112147
@@ -138,6 +173,13 @@ def ldpc_bp_decode(llr_vec, ldpc_code_params, n_iters):
138173

139174
_limit_llr_v = np.vectorize(_limit_llr)
140175

176+
if decoder_algorithm == 'SPA':
177+
check_node_update = sum_product_update
178+
elif decoder_algorithm == 'MSA':
179+
check_node_update = min_sum_update
180+
else:
181+
raise NameError('Please input a valid decoder_algorithm string.')
182+
141183
# Initialize vnode messages with the LLR values received
142184
for vnode_idx in xrange(n_vnodes):
143185
start_idx = vnode_idx*max_vnode_deg
@@ -152,15 +194,8 @@ def ldpc_bp_decode(llr_vec, ldpc_code_params, n_iters):
152194
# Check Node Update
153195
for cnode_idx in xrange(n_cnodes):
154196

155-
start_idx = cnode_idx*max_cnode_deg
156-
offset = cnode_deg_list[cnode_idx]
157-
vnode_list = cnode_adj_list[start_idx:start_idx+offset]
158-
vnode_list_msgs_tanh = np.tanh(vnode_msgs[vnode_list*max_vnode_deg +
159-
cnode_vnode_map[start_idx:start_idx+offset]]/2.0)
160-
msg_prod = np.prod(vnode_list_msgs_tanh)
161-
162-
# Compute messages on outgoing edges using the incoming message product
163-
cnode_msgs[start_idx:start_idx+offset]= 2.0*np.arctanh(msg_prod/vnode_list_msgs_tanh)
197+
check_node_update(cnode_idx, cnode_adj_list, cnode_deg_list, cnode_msgs,
198+
vnode_msgs, cnode_vnode_map, max_cnode_deg, max_vnode_deg)
164199

165200
# Variable Node Update
166201
for vnode_idx in xrange(n_vnodes):

0 commit comments

Comments
 (0)