From 5effadcbaf66f476c8fffefa2c349676f41c3f52 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 28 Feb 2020 19:30:27 +0100 Subject: LDPC decoder fully working --- controller/fw/ldpc_decoder.c | 94 +++++++++++++++++++++++++++----------- controller/fw/ldpc_decoder_test.py | 35 ++++++++++---- controller/fw/test_decoder.py | 27 +++++------ 3 files changed, 108 insertions(+), 48 deletions(-) (limited to 'controller') diff --git a/controller/fw/ldpc_decoder.c b/controller/fw/ldpc_decoder.c index 10b5a08..fe59d77 100644 --- a/controller/fw/ldpc_decoder.c +++ b/controller/fw/ldpc_decoder.c @@ -5,6 +5,9 @@ #include #include + +void gausselimination(size_t n, size_t k, int8_t *A, int8_t *b); + void inner_logbp( size_t m, size_t n, size_t bits_count, size_t nodes_count, const uint32_t bits_values[], const uint32_t nodes_values[], @@ -60,6 +63,7 @@ int decode(size_t n, size_t nodes_count, size_t bits_count, uint32_t bits[], int for (unsigned int n_iter=0; n_iter 0 ? "\033[92m" : "\033[94m"); - printf("nij=%04u Lc=%s%3d\033[38;5;240m ", bits_values[q], s, lcv); + //int lcv = Lc[bits_values[q]]; + //char *s = lcv < 0 ? "\033[91m" : (lcv > 0 ? "\033[92m" : "\033[94m"); + //printf("nij=%04u Lc=%s%3d\033[38;5;240m ", bits_values[q], s, lcv); x *= tanhf(0.5f * Lc[bits_values[q]]); } } @@ -153,7 +158,7 @@ void inner_logbp( } } - printf("\n==== i=%03zd p=%01zd x=%08f\n", i, p-bits_counter, x); + //printf("\n==== i=%03zd p=%01zd x=%08f\n", i, p-bits_counter, x); float num = 1 + x; float denom = 1 - x; @@ -197,31 +202,66 @@ void inner_logbp( } } -/* TODO -def get_message(tG, x): - """Compute the original `n_bits` message from a `n_code` codeword `x`. +/* Compute the original (k) bit message from a (n) bit codeword x. + * + * tG: (n, k)-matrix + * x: (n)-vector + * out: (k)-vector + */ +void get_message(size_t n, size_t k, int8_t *tG, int8_t *x, int8_t *out) { - Parameters - ---------- - tG: array (n_code, n_bits) coding matrix tG. - x: array (n_code,) decoded codeword of length `n_code`. + gausselimination(n, k, tG, x); - Returns - ------- - message: array (n_bits,). Original binary message. + out[k - 1] = x[k - 1]; + for (ssize_t i=k-2; i>=0; i--) { + out[i] = x[i]; - """ - n, k = tG.shape + uint8_t sum = 0; + for (size_t j=i+1; j 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): -- cgit