Commit b722d92f authored by rmagueta's avatar rmagueta

Extract the information bits from U

parent fb7d4dc4
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
#include "assertions.h" #include "assertions.h"
//#define POLAR_CODING_DEBUG
static inline void updateCrcChecksum2(int xlen, static inline void updateCrcChecksum2(int xlen,
int ylen, int ylen,
uint8_t crcChecksum[xlen][ylen], uint8_t crcChecksum[xlen][ylen],
...@@ -611,6 +613,19 @@ uint32_t polar_decoder_int16(int16_t *input, ...@@ -611,6 +613,19 @@ uint32_t polar_decoder_int16(int16_t *input,
uint8_t aggregation_level ) uint8_t aggregation_level )
{ {
t_nrPolar_params *polarParams=nr_polar_params(messageType, messageLength, aggregation_level, true); 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); 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); 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, ...@@ -619,16 +634,57 @@ uint32_t polar_decoder_int16(int16_t *input,
else if (d_tilde[i]>127) d_tilde[i]=128; 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); #ifdef POLAR_CODING_DEBUG
generic_polar_decoder(polarParams,polarParams->tree.root); printf("d: ");
//Extract the information bits (û to ĉ) for (int i = 0; i < polarParams->N; i++) {
uint64_t Cprime[4]= {0,0,0,0}; if (i % 4 == 0) {
uint64_t B[4]= {0,0,0,0}; printf(" ");
}
printf("%i", d_tilde[i] < 0 ? 1 : 0);
}
printf("\n");
#endif
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);
for (int i=0; i<polarParams->K; i++) Cprime[i>>6] = Cprime[i>>6] | ((uint64_t)polarParams->nr_polar_U[polarParams->Q_I_N[i]])<<(i&63); #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) //Deinterleaving (ĉ to b)
uint8_t *Cprimebyte = (uint8_t *)Cprime; uint8_t *Cprimebyte = (uint8_t *)Cprime;
uint64_t B[4] = {0};
if (polarParams->K<65) { if (polarParams->K<65) {
B[0] = polarParams->B_tab0[0][Cprimebyte[0]] | B[0] = polarParams->B_tab0[0][Cprimebyte[0]] |
...@@ -650,6 +706,21 @@ uint32_t polar_decoder_int16(int16_t *input, ...@@ -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=polarParams->payloadBits;
//int len_mod64=len&63; //int len_mod64=len&63;
int crclen = polarParams->crcParityBits; int crclen = polarParams->crcParityBits;
...@@ -700,6 +771,21 @@ uint32_t polar_decoder_int16(int16_t *input, ...@@ -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; 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 #if 0
printf("A %llx B %llx|%llx Cprime %llx|%llx (crc %x,rxcrc %llx %d)\n", printf("A %llx B %llx|%llx Cprime %llx|%llx (crc %x,rxcrc %llx %d)\n",
Ar, Ar,
......
...@@ -286,6 +286,13 @@ void nr_polar_generate_u(uint64_t *u, ...@@ -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_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, void nr_polar_bit_insertion(uint8_t *input,
uint8_t *output, uint8_t *output,
uint16_t N, uint16_t N,
......
...@@ -86,6 +86,39 @@ void nr_polar_generate_u(uint64_t *u, ...@@ -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) 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; int N_array = N >> 6;
...@@ -446,7 +479,7 @@ void nr_polar_rm_deinterleaving_cb(const int16_t *in, int16_t *out, const uint16 ...@@ -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 j = 0; j < T; j++) {
for (int i = 0; i < T - j; i++) { for (int i = 0; i < T - j; i++) {
if (k < E && v_tab[i][j] != 0) { if (k < E && v_tab[i][j] != 0) {
v[i][j] = in[E - 1 - k]; v[i][j] = in[k];
k++; k++;
} else { } else {
v[i][j] = INT_MAX; v[i][j] = INT_MAX;
...@@ -459,7 +492,7 @@ void nr_polar_rm_deinterleaving_cb(const int16_t *in, int16_t *out, const uint16 ...@@ -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 i = 0; i < T; i++) {
for (int j = 0; j < T - i; j++) { for (int j = 0; j < T - i; j++) {
if (v[i][j] != INT_MAX) { if (v[i][j] != INT_MAX) {
out[E - 1 - k] = v[i][j]; out[k] = v[i][j];
k++; k++;
} }
} }
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#endif #endif
//#define ONE_OVER_SQRT2 23170 // 32767/sqrt(2) = 23170 (ONE_OVER_SQRT2) //#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, void nr_generate_pucch0(PHY_VARS_NR_UE *ue,
c16_t **txdataF, c16_t **txdataF,
...@@ -692,7 +693,19 @@ void nr_generate_pucch2(PHY_VARS_NR_UE *ue, ...@@ -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 * 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 * 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 * btilde shall be modulated as described in subclause 5.1 using QPSK
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment