From b722d92fa0a9cdd553b45d5b7c4f3194930f2780 Mon Sep 17 00:00:00 2001 From: rmagueta Date: Thu, 25 May 2023 19:15:18 +0100 Subject: [PATCH] Extract the information bits from U --- .../CODING/nrPolar_tools/nr_polar_decoder.c | 98 +++++++++++++++++-- .../PHY/CODING/nrPolar_tools/nr_polar_defs.h | 7 ++ .../nrPolar_tools/nr_polar_procedures.c | 37 ++++++- openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c | 15 ++- 4 files changed, 148 insertions(+), 9 deletions(-) diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c index 289a9fe51d..18de88db79 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c @@ -39,6 +39,8 @@ #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" #include "assertions.h" +//#define POLAR_CODING_DEBUG + static inline void updateCrcChecksum2(int xlen, int ylen, uint8_t crcChecksum[xlen][ylen], @@ -611,6 +613,19 @@ uint32_t polar_decoder_int16(int16_t *input, uint8_t aggregation_level ) { t_nrPolar_params *polarParams=nr_polar_params(messageType, messageLength, aggregation_level, true); + +#ifdef POLAR_CODING_DEBUG + printf("\nRX\n"); + printf("rm:"); + for (int i = 0; i < polarParams->N; i++) { + if (i % 4 == 0) { + printf(" "); + } + printf("%i", input[i] < 0 ? 1 : 0); + } + printf("\n"); +#endif + int16_t d_tilde[polarParams->N];// = malloc(sizeof(double) * polarParams->N); nr_polar_rate_matching_int16(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength, polarParams->i_bil); @@ -619,16 +634,57 @@ uint32_t polar_decoder_int16(int16_t *input, else if (d_tilde[i]>127) d_tilde[i]=128; } - memcpy((void *)&polarParams->tree.root->alpha[0],(void *)&d_tilde[0],sizeof(int16_t)*polarParams->N); - generic_polar_decoder(polarParams,polarParams->tree.root); - //Extract the information bits (û to ĉ) - uint64_t Cprime[4]= {0,0,0,0}; - uint64_t B[4]= {0,0,0,0}; +#ifdef POLAR_CODING_DEBUG + printf("d: "); + for (int i = 0; i < polarParams->N; i++) { + if (i % 4 == 0) { + printf(" "); + } + printf("%i", d_tilde[i] < 0 ? 1 : 0); + } + printf("\n"); +#endif - for (int i=0; iK; i++) Cprime[i>>6] = Cprime[i>>6] | ((uint64_t)polarParams->nr_polar_U[polarParams->Q_I_N[i]])<<(i&63); + memcpy((void *)&polarParams->tree.root->alpha[0], (void *)&d_tilde[0], sizeof(int16_t) * polarParams->N); + memset(polarParams->nr_polar_U, 0, polarParams->N * sizeof(uint8_t)); + generic_polar_decoder(polarParams, polarParams->tree.root); + +#ifdef POLAR_CODING_DEBUG + printf("u: "); + for (int i = 0; i < polarParams->N; i++) { + if (i % 4 == 0) { + printf(" "); + } + printf("%i", polarParams->nr_polar_U[i]); + } + printf("\n"); +#endif + + // Extract the information bits (û to ĉ) + uint64_t Cprime[4]= {0}; + nr_polar_info_extraction_from_u(Cprime, + polarParams->nr_polar_U, + polarParams->information_bit_pattern, + polarParams->parity_check_bit_pattern, + polarParams->N, + polarParams->n_pc); + +#ifdef POLAR_CODING_DEBUG + printf("c: "); + for (int n = 0; n < polarParams->K; n++) { + if (n % 4 == 0) { + printf(" "); + } + int n1 = n >> 6; + int n2 = n - (n1 << 6); + printf("%lu", (Cprime[n1] >> n2) & 1); + } + printf("\n"); +#endif //Deinterleaving (ĉ to b) uint8_t *Cprimebyte = (uint8_t *)Cprime; + uint64_t B[4] = {0}; if (polarParams->K<65) { B[0] = polarParams->B_tab0[0][Cprimebyte[0]] | @@ -650,6 +706,21 @@ uint32_t polar_decoder_int16(int16_t *input, } } +#ifdef POLAR_CODING_DEBUG + int B_array = (polarParams->K + 63) >> 6; + int n_start = (B_array << 6) - polarParams->K; + printf("b: "); + for (int n = 0; n < polarParams->K; n++) { + if (n % 4 == 0) { + printf(" "); + } + int n1 = (n + n_start) >> 6; + int n2 = (n + n_start) - (n1 << 6); + printf("%lu", (B[B_array - 1 - n1] >> (63 - n2)) & 1); + } + printf("\n"); +#endif + int len=polarParams->payloadBits; //int len_mod64=len&63; int crclen = polarParams->crcParityBits; @@ -700,6 +771,21 @@ uint32_t polar_decoder_int16(int16_t *input, else if (crclen==6) crc = (uint64_t)(crc6(A64_flip,8*offset+len)>>26)&0x3f; } +#ifdef POLAR_CODING_DEBUG + int A_array = (len + 63) >> 6; + printf("a: "); + for (int n = 0; n < len; n++) { + if (n % 4 == 0) { + printf(" "); + } + int n1 = n >> 6; + int n2 = n - (n1 << 6); + int alen = n1 == 0 ? len - (A_array << 6) : 64; + printf("%lu", (Ar >> (alen - 1 - n2)) & 1); + } + printf("\n\n"); +#endif + #if 0 printf("A %llx B %llx|%llx Cprime %llx|%llx (crc %x,rxcrc %llx %d)\n", Ar, diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h index 4d389e9468..e48a205889 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h @@ -286,6 +286,13 @@ void nr_polar_generate_u(uint64_t *u, void nr_polar_uxG(uint64_t *D, const uint64_t *u, const uint64_t **G_N_tab, uint16_t N); +void nr_polar_info_extraction_from_u(uint64_t *Cprime, + const uint8_t *u, + const uint8_t *information_bit_pattern, + const uint8_t *parity_check_bit_pattern, + uint16_t N, + uint8_t n_pc); + void nr_polar_bit_insertion(uint8_t *input, uint8_t *output, uint16_t N, diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c index 85e32a033f..4df7557495 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c @@ -86,6 +86,39 @@ void nr_polar_generate_u(uint64_t *u, } } +void nr_polar_info_extraction_from_u(uint64_t *Cprime, + const uint8_t *u, + const uint8_t *information_bit_pattern, + const uint8_t *parity_check_bit_pattern, + uint16_t N, + uint8_t n_pc) +{ + int k = 0; + + if (n_pc > 0) { + for (int n = 0; n < N; n++) { + if (information_bit_pattern[n] == 1) { + if (parity_check_bit_pattern[n] == 0) { + int k1 = k >> 6; + int k2 = k - (k1 << 6); + Cprime[k1] |= (uint64_t)u[n] << k2; + k++; + } + } + } + + } else { + for (int n = 0; n < N; n++) { + if (information_bit_pattern[n] == 1) { + int k1 = k >> 6; + int k2 = k - (k1 << 6); + Cprime[k1] |= (uint64_t)u[n] << k2; + k++; + } + } + } +} + void nr_polar_uxG(uint64_t *D, const uint64_t *u, const uint64_t **G_N_tab, uint16_t N) { int N_array = N >> 6; @@ -446,7 +479,7 @@ void nr_polar_rm_deinterleaving_cb(const int16_t *in, int16_t *out, const uint16 for (int j = 0; j < T; j++) { for (int i = 0; i < T - j; i++) { if (k < E && v_tab[i][j] != 0) { - v[i][j] = in[E - 1 - k]; + v[i][j] = in[k]; k++; } else { v[i][j] = INT_MAX; @@ -459,7 +492,7 @@ void nr_polar_rm_deinterleaving_cb(const int16_t *in, int16_t *out, const uint16 for (int i = 0; i < T; i++) { for (int j = 0; j < T - i; j++) { if (v[i][j] != INT_MAX) { - out[E - 1 - k] = v[i][j]; + out[k] = v[i][j]; k++; } } diff --git a/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c b/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c index 818954bc29..139f1b7005 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c @@ -49,6 +49,7 @@ #endif //#define ONE_OVER_SQRT2 23170 // 32767/sqrt(2) = 23170 (ONE_OVER_SQRT2) +//#define POLAR_CODING_DEBUG void nr_generate_pucch0(PHY_VARS_NR_UE *ue, c16_t **txdataF, @@ -692,7 +693,19 @@ void nr_generate_pucch2(PHY_VARS_NR_UE *ue, /* * Implementing TS 38.211 Subclause 6.3.2.5.1 scrambling format 2 */ - nr_pucch2_3_4_scrambling(M_bit,rnti,pucch_pdu->data_scrambling_id,&b[0],btilde); + nr_pucch2_3_4_scrambling(M_bit, rnti, pucch_pdu->data_scrambling_id, b, btilde); + +#ifdef POLAR_CODING_DEBUG + printf("bt:"); + for (int n = 0; n < M_bit; n++) { + if (n % 4 == 0) { + printf(" "); + } + printf("%u", btilde[n]); + } + printf("\n"); +#endif + /* * Implementing TS 38.211 Subclause 6.3.2.5.2 modulation format 2 * btilde shall be modulated as described in subclause 5.1 using QPSK