From 89b32316aa46f22a4f967ca7953089a3df0c16e7 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 28 Feb 2020 18:29:41 +0100 Subject: embedded ldpc decoder 50% working --- controller/fw/ldpc_decoder.c | 197 +++++++++++++++++++++++++++++-------------- 1 file changed, 136 insertions(+), 61 deletions(-) (limited to 'controller/fw/ldpc_decoder.c') diff --git a/controller/fw/ldpc_decoder.c b/controller/fw/ldpc_decoder.c index 5200e8f..10b5a08 100644 --- a/controller/fw/ldpc_decoder.c +++ b/controller/fw/ldpc_decoder.c @@ -1,86 +1,160 @@ -"""Decoding module.""" - -/* H: decoding matrix as shape (m, n) array - * m: number of equations represented by H - * n: number of code words - * y: received message in codeword space, length n - * - * out: output array of length n where the solutions in codeword space will be written - * - * maxiter: Maximum iteration number - */ -int decode(uint8_t H[], const int m, n, uint8_t y[], uint8_t out[], int maxiter) { - - /* fixme: preprocess the following. -def bitsandnodes(H): - """Return bits and nodes of a parity-check matrix H.""" - bits_indices, bits = scipy.sparse.find(H)[:2] - nodes_indices, nodes = scipy.sparse.find(H.T)[:2] - bits_histogram = np.bincount(bits_indices) - nodes_histogram = np.bincount(nodes_indices) - return bits_histogram, bits, nodes_histogram, nodes - bits_hist, bits_values, nodes_hist, nodes_values = utils.bitsandnodes(H) - */ +#include +#include +#include +#include +#include + +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[], + int8_t Lc[], + float Lq[], float Lr[], + unsigned int n_iter, + float L_posteriori_out[]); + +//decode(384, 6, 8, ...) +int decode(size_t n, size_t nodes_count, size_t bits_count, uint32_t bits[], int8_t y[], int8_t out[], unsigned int maxiter) { + const size_t m = n * nodes_count / bits_count; float Lq[m*n]; float Lr[m*n]; float L_posteriori[n]; - for (int n_iter=0; n_iter 1000 && i/w > head_tail && i/w < m*n/w-head_tail) { + if (!ellipsis) { + ellipsis = true; + printf("\n ..."); + } + continue; + } + if (i) + printf(", "); + if (i%w == 0) + printf("\n "); + float outf = arrs[j][i]; + char *s = outf < 0 ? "\033[91m" : (outf > 0 ? "\033[92m" : "\033[94m"); + printf("%s% 012.6g\033[38;5;240m", s, outf); + } + printf("\n]\n"); + } + for (size_t i=0; i 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]]); + } } } else { - for (size_t q=bits_counter; q