Commit 98ed514c authored by Roberto Louro Magueta's avatar Roberto Louro Magueta Committed by rmagueta

Implementation for de-interleaving of coded bits

parent e5825139
......@@ -612,7 +612,7 @@ uint32_t polar_decoder_int16(int16_t *input,
{
t_nrPolar_params *polarParams=nr_polar_params(messageType, messageLength, aggregation_level, true);
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);
nr_polar_rate_matching_int16(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength, polarParams->i_bil);
for (int i=0; i<polarParams->N; i++) {
if (d_tilde[i]<-128) d_tilde[i]=-128;
......
......@@ -238,10 +238,11 @@ void nr_polar_rate_matching(double *input,
void nr_polar_rate_matching_int16(int16_t *input,
int16_t *output,
uint16_t *rmp,
uint16_t K,
uint16_t N,
uint16_t E);
const uint16_t *rmp,
const uint16_t K,
const uint16_t N,
const uint16_t E,
const uint8_t i_bil);
void nr_polar_interleaving_pattern(uint16_t K,
uint8_t I_IL,
......
......@@ -325,23 +325,75 @@ void nr_polar_rate_matching(double *input,
}
}
/*
* De-interleaving of coded bits implementation
* TS 138.212: Section 5.4.1.3 - Interleaving of coded bits
*/
void nr_polar_rm_deinterleaving_cb(const int16_t *in, int16_t *out, const uint16_t E)
{
int T = ceil((sqrt(8 * E + 1) - 1) / 2);
int v_tab[T][T];
int k = 0;
for (int i = 0; i < T; i++) {
memset(v_tab[i], 0, T * sizeof(int));
for (int j = 0; j < T - i; j++) {
if (k < E) {
v_tab[i][j] = k + 1;
}
k++;
}
}
int v[T][T];
k = 0;
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];
k++;
} else {
v[i][j] = INT_MAX;
}
}
}
k = 0;
memset(out, 0, E * sizeof(int16_t));
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];
k++;
}
}
}
}
void nr_polar_rate_matching_int16(int16_t *input,
int16_t *output,
uint16_t *rmp,
uint16_t K,
uint16_t N,
uint16_t E)
const uint16_t *rmp,
const uint16_t K,
const uint16_t N,
const uint16_t E,
const uint8_t i_bil)
{
if (E>=N) { //repetition
memset((void*)output,0,N*sizeof(int16_t));
for (int i=0; i<=E-1; i++) output[rmp[i]]+=input[i];
} else {
if ( (K/(double)E) <= (7.0/16) ) memset((void*)output,0,N*sizeof(int16_t)); //puncturing
else { //shortening
for (int i=0; i<=N-1; i++) output[i]=32767;//instead of INFINITY, to prevent [-Woverflow]
if (i_bil == 1) {
nr_polar_rm_deinterleaving_cb(input, input, E);
}
for (int i=0; i<=E-1; i++) output[rmp[i]]=input[i];
if (E >= N) { // repetition
memset((void *)output, 0, N * sizeof(int16_t));
for (int i = 0; i <= E - 1; i++)
output[rmp[i]] += input[i];
} else {
if ((K / (double)E) <= (7.0 / 16))
memset((void *)output, 0, N * sizeof(int16_t)); // puncturing
else { // shortening
for (int i = 0; i <= N - 1; i++)
output[i] = 32767; // instead of INFINITY, to prevent [-Woverflow]
}
for (int i = 0; i <= E - 1; i++)
output[rmp[i]] = input[i];
}
}
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