LDPC decoder fully working
This commit is contained in:
parent
89b32316aa
commit
5effadcbaf
3 changed files with 108 additions and 48 deletions
|
|
@ -43,23 +43,24 @@ def decode(H, y, snr, maxiter=100):
|
|||
Lr = np.zeros(shape=(m, n, n_messages))
|
||||
|
||||
for n_iter in range(maxiter):
|
||||
print(f'============================ iteration {n_iter} ============================')
|
||||
#print(f'============================ iteration {n_iter} ============================')
|
||||
Lq, Lr, L_posteriori = _logbp_numba(bits_hist, bits_values, nodes_hist,
|
||||
nodes_values, Lc, Lq, Lr, n_iter)
|
||||
print("Lq=", Lq.flatten())
|
||||
print("Lr=", Lr.flatten())
|
||||
#print("Lq=", Lq.flatten())
|
||||
#print("Lr=", Lr.flatten())
|
||||
#print("L_posteriori=", L_posteriori.flatten())
|
||||
print('L_posteriori=[')
|
||||
for row in L_posteriori.reshape([-1, 16]):
|
||||
for val in row:
|
||||
cc = '\033[91m' if val < 0 else ('\033[92m' if val > 0 else '\033[94m')
|
||||
print(f"{cc}{val: 012.6g}\033[38;5;240m", end=', ')
|
||||
print()
|
||||
#print('L_posteriori=[')
|
||||
#for row in L_posteriori.reshape([-1, 16]):
|
||||
# for val in row:
|
||||
# cc = '\033[91m' if val < 0 else ('\033[92m' if val > 0 else '\033[94m')
|
||||
# print(f"{cc}{val: 012.6g}\033[38;5;240m", end=', ')
|
||||
# print()
|
||||
x = np.array(L_posteriori <= 0).astype(int)
|
||||
|
||||
product = utils.incode(H, x)
|
||||
|
||||
if product:
|
||||
print(f'found, n_iter={n_iter}')
|
||||
break
|
||||
|
||||
if n_iter == maxiter - 1:
|
||||
|
|
@ -83,13 +84,13 @@ def _logbp_numba(bits_hist, bits_values, nodes_hist, nodes_values, Lc, Lq, Lr,
|
|||
bits_counter = 0
|
||||
nodes_counter = 0
|
||||
for i in range(m):
|
||||
print(f'=== i={i}')
|
||||
#print(f'=== i={i}')
|
||||
ff = bits_hist[i]
|
||||
ni = bits_values[bits_counter: bits_counter + ff]
|
||||
bits_counter += ff
|
||||
for j_iter, j in enumerate(ni):
|
||||
nij = ni[:]
|
||||
print(f'\033[38;5;240mj={j:04d}', end=' ')
|
||||
#print(f'\033[38;5;240mj={j:04d}', end=' ')
|
||||
|
||||
X = np.ones(n_messages)
|
||||
if n_iter == 0:
|
||||
|
|
@ -97,13 +98,13 @@ def _logbp_numba(bits_hist, bits_values, nodes_hist, nodes_values, Lc, Lq, Lr,
|
|||
if nij[kk] != j:
|
||||
lcv = Lc[nij[kk],0]
|
||||
lcc = '\033[91m' if lcv < 0 else ('\033[92m' if lcv > 0 else '\033[94m')
|
||||
print(f'nij={nij[kk]:04d} Lc={lcc}{lcv:> 8f}\033[38;5;240m', end=' ')
|
||||
#print(f'nij={nij[kk]:04d} Lc={lcc}{lcv:> 8f}\033[38;5;240m', end=' ')
|
||||
X *= np.tanh(0.5 * Lc[nij[kk]])
|
||||
else:
|
||||
for kk in range(len(nij)):
|
||||
if nij[kk] != j:
|
||||
X *= np.tanh(0.5 * Lq[i, nij[kk]])
|
||||
print(f'\n==== {i:03d} {j_iter:01d} {X[0]:> 8f}')
|
||||
#print(f'\n==== {i:03d} {j_iter:01d} {X[0]:> 8f}')
|
||||
num = 1 + X
|
||||
denom = 1 - X
|
||||
for ll in range(n_messages):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue