From 8b38bfc7c56da61022cec95b44ee3063e2e03463 Mon Sep 17 00:00:00 2001
From: yilmazt <yilmazt@eurecom.fr>
Date: Thu, 24 May 2018 18:44:01 +0200
Subject: [PATCH] General modifications for polar coding, and deleting
 duplicate functions.

---
 cmake_targets/CMakeLists.txt                  |   6 +-
 openair1/PHY/CODING/TESTBENCH/ldpctest.c      |   2 +-
 openair1/PHY/CODING/nrPolar_init.c            |  40 ++-
 .../nrPolar_tools/get_3GPP_info_bit_pattern.c | 200 --------------
 .../CODING/nrPolar_tools/get_PC_bit_pattern.c | 259 ------------------
 .../nrPolar_tools/get_crc_generator_matrix.c  |  79 ------
 .../nrPolar_tools/nr_bitwise_operations.c     |  21 ++
 .../PHY/CODING/nrPolar_tools/nr_crc_byte.c    | 172 ++----------
 .../nrPolar_tools/nr_polar_bit_insertion.c    |  23 +-
 .../nrPolar_tools/nr_polar_bit_insertion_2.c  |  63 -----
 .../nr_polar_channel_interleaver_pattern.c    |  21 ++
 .../CODING/nrPolar_tools/nr_polar_dci_defs.h  |  46 ++++
 .../CODING/nrPolar_tools/nr_polar_decoder.c   |  59 ++--
 .../nrPolar_tools/nr_polar_decoding_tools.c   |  21 ++
 .../PHY/CODING/nrPolar_tools/nr_polar_defs.h  |  72 +++--
 .../CODING/nrPolar_tools/nr_polar_encoder.c   |  69 ++---
 .../nrPolar_tools/nr_polar_info_bit_pattern.c |  25 +-
 ...eave.c => nr_polar_interleaving_pattern.c} |  29 +-
 .../nr_polar_kronecker_power_matrices.c       |  21 ++
 .../nrPolar_tools/nr_polar_matrix_and_array.c |  21 ++
 .../nrPolar_tools/nr_polar_output_length.c    |  21 ++
 .../CODING/nrPolar_tools/nr_polar_pbch_defs.h |  35 ++-
 .../nrPolar_tools/nr_polar_rate_match.c       |  27 +-
 .../nrPolar_tools/nr_polar_sequence_pattern.c |  23 +-
 .../CODING/nrPolar_tools/nr_polar_uci_defs.h  |  36 +++
 openair1/PHY/TOOLS/file_output.c              |   3 -
 26 files changed, 540 insertions(+), 854 deletions(-)
 delete mode 100644 openair1/PHY/CODING/nrPolar_tools/get_3GPP_info_bit_pattern.c
 delete mode 100644 openair1/PHY/CODING/nrPolar_tools/get_PC_bit_pattern.c
 delete mode 100644 openair1/PHY/CODING/nrPolar_tools/get_crc_generator_matrix.c
 delete mode 100644 openair1/PHY/CODING/nrPolar_tools/nr_polar_bit_insertion_2.c
 create mode 100644 openair1/PHY/CODING/nrPolar_tools/nr_polar_dci_defs.h
 rename openair1/PHY/CODING/nrPolar_tools/{nr_polar_interleave.c => nr_polar_interleaving_pattern.c} (53%)
 create mode 100644 openair1/PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h

diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index f7b50a3328..70c2d88e82 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -1063,18 +1063,14 @@ set(PHY_LDPCSRC
 )
 set(PHY_POLARSRC
   ${OPENAIR1_DIR}/PHY/CODING/nrPolar_init.c
-  ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/get_3GPP_info_bit_pattern.c
-  ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/get_crc_generator_matrix.c
-  ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/get_PC_bit_pattern.c
   ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c
   ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_crc_byte.c
-  ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_bit_insertion_2.c
   ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_bit_insertion.c
   ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_channel_interleaver_pattern.c
   ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_crc.c
   ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c
   ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_info_bit_pattern.c
-  ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_interleave.c
+  ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_interleaving_pattern.c
   ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_kernal_operation.c
   ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_kronecker_power_matrices.c
   ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_matrix_and_array.c
diff --git a/openair1/PHY/CODING/TESTBENCH/ldpctest.c b/openair1/PHY/CODING/TESTBENCH/ldpctest.c
index 13c23cb956..33c51386ba 100644
--- a/openair1/PHY/CODING/TESTBENCH/ldpctest.c
+++ b/openair1/PHY/CODING/TESTBENCH/ldpctest.c
@@ -24,7 +24,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#include "SIMULATION/TOOLS/defs.h"
+#include "SIMULATION/TOOLS/sim.h"
 
 
 
diff --git a/openair1/PHY/CODING/nrPolar_init.c b/openair1/PHY/CODING/nrPolar_init.c
index cf788bae22..6f5b167c0e 100644
--- a/openair1/PHY/CODING/nrPolar_init.c
+++ b/openair1/PHY/CODING/nrPolar_init.c
@@ -1,3 +1,24 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include "nrPolar_tools/nr_polar_defs.h"
 #include "nrPolar_tools/nr_polar_pbch_defs.h"
 
@@ -8,6 +29,7 @@ void nr_polar_init(t_nrPolar_params* polarParams, int messageType) {
 	} else if (messageType == 1) { //PBCH
 		polarParams->n_max = NR_POLAR_PBCH_N_MAX;
 		polarParams->i_il = NR_POLAR_PBCH_I_IL;
+		polarParams->i_seg = NR_POLAR_PBCH_I_SEG;
 		polarParams->n_pc = NR_POLAR_PBCH_N_PC;
 		polarParams->n_pc_wm = NR_POLAR_PBCH_N_PC_WM;
 		polarParams->i_bil = NR_POLAR_PBCH_I_BIL;
@@ -22,19 +44,29 @@ void nr_polar_init(t_nrPolar_params* polarParams, int messageType) {
 
 		polarParams->crc_generator_matrix=crc24c_generator_matrix(polarParams->payloadBits);
 		polarParams->G_N = nr_polar_kronecker_power_matrices(polarParams->n);
+
+		//polar_encoder vectors:
+		polarParams->nr_polar_crc = malloc(sizeof(uint8_t) * polarParams->crcParityBits);
+		polarParams->nr_polar_cPrime = malloc(sizeof(uint8_t) * polarParams->K);
+		polarParams->nr_polar_d = malloc(sizeof(uint8_t) * polarParams->N);
+
+		//Polar Coding vectors
+		polarParams->nr_polar_u = malloc(sizeof(uint8_t) * polarParams->N); //Decoder: nr_polar_uHat
+		polarParams->nr_polar_cPrime = malloc(sizeof(uint8_t) * polarParams->K); //Decoder: nr_polar_cHat
+		polarParams->nr_polar_b = malloc(sizeof(uint8_t) * polarParams->K); //Decoder: nr_polar_bHat
 	} else if (messageType == 2) { //UCI
 
 	}
 
 	polarParams->Q_0_Nminus1 = nr_polar_sequence_pattern(polarParams->n);
 
-	polarParams->interleaving_pattern = (uint16_t *)malloc(sizeof(uint16_t) * polarParams->K);
+	polarParams->interleaving_pattern = malloc(sizeof(uint16_t) * polarParams->K);
 	nr_polar_interleaving_pattern(polarParams->K, polarParams->i_il, polarParams->interleaving_pattern);
 
-	polarParams->rate_matching_pattern = (uint16_t *)malloc(sizeof(uint16_t) * polarParams->encoderLength);
+	polarParams->rate_matching_pattern = malloc(sizeof(uint16_t) * polarParams->encoderLength);
 	uint16_t *J = malloc(sizeof(uint16_t) * polarParams->N);
-	nr_polar_rate_matching_pattern(polarParams->rate_matching_pattern, J, nr_polar_subblock_interleaver_pattern,
-			polarParams->K, polarParams->N, polarParams->encoderLength);
+	nr_polar_rate_matching_pattern(polarParams->rate_matching_pattern, J,
+		nr_polar_subblock_interleaver_pattern, polarParams->K, polarParams->N, polarParams->encoderLength);
 
 
 	polarParams->information_bit_pattern = malloc(sizeof(uint8_t) * polarParams->N);
diff --git a/openair1/PHY/CODING/nrPolar_tools/get_3GPP_info_bit_pattern.c b/openair1/PHY/CODING/nrPolar_tools/get_3GPP_info_bit_pattern.c
deleted file mode 100644
index 0e20b2c8f9..0000000000
--- a/openair1/PHY/CODING/nrPolar_tools/get_3GPP_info_bit_pattern.c
+++ /dev/null
@@ -1,200 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <stdint.h>
-
-void get_3GPP_info_bit_pattern(uint16_t K, uint16_t n_PC, uint16_t Q_N_length, uint8_t E_r, uint8_t* P, uint16_t* Q_N, uint8_t** info_bit_pattern)
-{
-//   GET_3GPP_INFO_BIT_PATTERN Obtain the 3GPP information bit pattern,
-//   according to Section 5.4.1.1 of 3GPP TS 38.212
-//
-//   I should be an integer scalar. It specifies the number of bits in the
-//   information, CRC and PC bit sequence. It should be no greater than N or E.
-//
-//   Q_N should be a row vector comprising N number of unique integers in the
-//   range 1 to N. Each successive element of Q_N provides the index of the
-//   next most reliable input to the polar encoder kernal, where the first
-//   element of Q_N gives the index of the least reliable bit and the last
-//   element gives the index of the most reliable bit.
-//
-//   rate_matching_pattern should be a vector comprising E_r number of
-//   integers, each having a value in the range 1 to N. Each integer
-//   identifies which one of the N outputs from the polar encoder kernal
-//   provides the corresponding bit in the encoded bit sequence e.
-//
-//   mode should have the value 'repetition', 'puncturing' or 'shortening'.
-//   This specifies how the rate matching has been achieved. 'repetition'
-//   indicates that some outputs of the polar encoder kernal are repeated in
-//   the encoded bit sequence two or more times. 'puncturing' and
-//   'shortening' indicate that some outputs of the polar encoder kernal
-//   have been excluded from the encoded bit sequence. In the case of
-//   'puncturing' these excluded bits could have values of 0 or 1. In the
-//   case of 'shortening' these excluded bits are guaranteed to have values
-//   of 0.
-//
-//   info_bit_pattern will be a vector comprising N number of logical
-//   elements, each having the value true or false. The number of elements
-//   in info_bit_pattern having the value true will be I. These elements
-//   having the value true identify the positions of the information and
-//   CRC bits within the input to the polar encoder kernal. The
-//   information bit arrangement can be achieved according to
-//   u(info_bit_pattern) = a.
-
-int I=K+n_PC;
-
-        if (I > Q_N_length) //I=K+n_PC
-        {
-            fprintf(stderr, "I=K+n_PC should be no greater than N.");
-            exit(-1);
-        }
-        if (I > E_r)
-        {
-            fprintf(stderr, "I=K+n_PC should be no greater than E.");
-            exit(-1);
-        }
-
-        //This is how the rate matching is described in TS 38.212
-        int J[Q_N_length];
-        int i,j;
-        for (j=0; j<Q_N_length; j++)
-        {
-            i=floor(32*(double)j/Q_N_length);
-            J[j] = P[i]*(Q_N_length/32)+(j%(Q_N_length/32));
-        }
-
-        //Q_Ftmp_N = [];
-        int Q_Ftmp_N_length= Q_N_length-E_r;
-        if (E_r < Q_N_length)
-        {
-            if ((double)(I)/E_r <= (double)7/16) // puncturing
-            {
-                //Q_Ftmp_N_length = Q_Ftmp_N_length + N-E;
-                if (E_r >= (double)3*Q_N_length/4)
-                {
-                    //Q_Ftmp_N = [Q_Ftmp_N,0:ceil(3*N/4-E/2)-1];
-                    Q_Ftmp_N_length = Q_Ftmp_N_length + ceil(3*Q_N_length/4-(double)E_r/2);
-                } else
-                {
-                    //Q_Ftmp_N = [Q_Ftmp_N,0:ceil(9*N/16-E/4)-1];
-                    Q_Ftmp_N_length = Q_Ftmp_N_length + ceil(9*Q_N_length/16-(double)E_r/4);
-                }
-            }
-        }
-
-        int* Q_Ftmp_N = (int *)malloc(sizeof(int)*Q_Ftmp_N_length);
-        if (Q_Ftmp_N == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        if (E_r < Q_N_length)
-        {
-            if ((double)I/E_r <= 7/16) // puncturing
-            {
-                for (j=0; j<Q_N_length-E_r; j++)
-                {
-                    Q_Ftmp_N[j] = J[j];
-                }
-
-                if (E_r >= 3*Q_N_length/4)
-                {
-                    for (j=0; j<ceil(3*Q_N_length/4-(double)E_r/2); j++)
-                    {
-                        Q_Ftmp_N[Q_N_length-E_r+1+j] = j;
-                    }
-                } else
-                {
-                    for (j=0; j<ceil(9*Q_N_length/16-(double)E_r/4); j++)
-                    {
-                        Q_Ftmp_N[Q_N_length-E_r+1+j] = j;
-                    }
-                }
-            } else // shortening
-            {
-                for (j=E_r; j<Q_N_length; j++)
-                {
-                    Q_Ftmp_N[j-E_r] = J[j];
-                }
-
-            }
-        }
-
-        //Q_Itmp_N = setdiff(Q_N-1,Q_Ftmp_N,'stable'); // -1 because TS 38.212 assumes that indices start at 0, not 1 like in Matlab
-        int Q_Itmp_N_length = Q_N_length;
-        int Q_Itmp_N_common[Q_N_length];
-
-        for(i=0; i<Q_N_length; i++)
-        {
-            Q_Itmp_N_common[i]=0; //1 if in common, otherwise 0
-
-            for (j=0; j<Q_Ftmp_N_length; j++)
-            {
-                if((int)Q_N[i]==Q_Ftmp_N[j])
-                {
-                    Q_Itmp_N_common[i]=1;
-                    Q_Itmp_N_length--;
-                    break;
-                }
-            }
-        }
-
-        free(Q_Ftmp_N);
-
-        if (Q_Itmp_N_length < I)
-        {
-            fprintf(stderr, "Too many pre-frozen bits.");
-            exit(-1);
-        }
-
-        int* Q_Itmp_N = (int *)malloc(sizeof(int)*Q_Itmp_N_length);
-        if (Q_Itmp_N == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        j=0;
-        for(i=0; i<Q_N_length; i++)
-        {
-            if(!Q_Itmp_N_common[i]) //if not commonc
-            {
-                Q_Itmp_N[j]=(int)Q_N[i];
-                j++;
-            }
-        }
-
-        int* Q_I_N = (int *)malloc(sizeof(int)*(I));
-        if (Q_I_N == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        //Q_I_N=Q_Itmp_N(end-I+1:end);
-        for (j=Q_Itmp_N_length-(I); j<Q_Itmp_N_length; j++)
-        {
-            Q_I_N[j-(Q_Itmp_N_length-(I))]=Q_Itmp_N[j];
-        }
-
-        free(Q_Itmp_N);
-
-        //info_bit_pattern(Q_I_N+1) = true;
-        *info_bit_pattern = (uint8_t *)malloc(sizeof(uint8_t)*Q_N_length);
-        if (*info_bit_pattern == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        for(j=0; j<Q_N_length; j++)
-        {
-            (*info_bit_pattern)[j]=0;
-            for(i=0; i<I; i++)
-            {
-                if(Q_I_N[i]==j)
-                {
-                    (*info_bit_pattern)[j]=1;
-                    break;
-                }
-            }
-        }
-
-        free(Q_I_N);
-}
diff --git a/openair1/PHY/CODING/nrPolar_tools/get_PC_bit_pattern.c b/openair1/PHY/CODING/nrPolar_tools/get_PC_bit_pattern.c
deleted file mode 100644
index d00a9f48ed..0000000000
--- a/openair1/PHY/CODING/nrPolar_tools/get_PC_bit_pattern.c
+++ /dev/null
@@ -1,259 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <stdint.h>
-
-void get_PC_bit_pattern(uint16_t Q_N_length, uint16_t n_PC, uint8_t n_PC_wm, uint16_t* Q_N, uint8_t* info_bit_pattern, uint8_t** PC_bit_pattern)
-{
-//   GET_PC_BIT_PATTERN Obtain the Parity Check (PC) bit pattern,
-//   according to Section 5.3.1.2 of 3GPP TS 38.212
-//
-//   info_bit_pattern should be a vector comprising N number of logical
-//   elements, each having the value true or false. The number of elements
-//   in info_bit_pattern having the value true should be I, where
-//   I = A+P+n_PC. These elements having the value true identify the
-//   positions of the information, CRC and PC bits within the input to the
-//   polar encoder kernal.
-//
-//   Q_N should be a row vector comprising N number of unique integers in the
-//   range 1 to N. Each successive element of Q_N provides the index of the
-//   next most reliable input to the polar encoder kernal, where the first
-//   element of Q_N gives the index of the least reliable bit and the last
-//   element gives the index of the most reliable bit.
-//
-//   n_PC should be an integer scalar. It specifies the number of PC bits to
-//   use, where n_PC should be no greater than I.
-//
-//   n_PC_wm should be an integer scalar. It specifies the number of PC bits
-//   that occupy some of the most reliable positions at the input to the
-//   polar encoder kernal. The remaining n_PC-n_PC_wm PC bits occupy some of
-//   the least reliable positions at the input to the polar encoder kernal.
-//   n_PC_wm should be no greater than n_PC.
-//
-//   PC_bit_pattern will be a vector comprising N number of logical
-//   elements, each having the value true or false. The number of elements
-//   in PC_bit_pattern having the value true will be n_PC.
-//   These elements having the value true identify the positions of the
-//   PC bits within the input to the polar encoder kernal.
-
-        //N = length(info_bit_pattern); -> Q_N_length
-        //I = sum(info_bit_pattern);
-        int totInfoBit =0;
-        int j,i;
-        for (j=0; j<Q_N_length; j++)
-        {
-            if(info_bit_pattern[j])
-                totInfoBit++;
-        }
-
-        if (n_PC > totInfoBit)
-        {
-            fprintf(stderr, "n_PC should be no greater than totInfoBit.");
-            exit(-1);
-        }
-
-        if (n_PC_wm > n_PC)
-        {
-            fprintf(stderr, "n_PC_wm should be no greater than n_PC.");
-            exit(-1);
-        }
-        //Q_I = 1:N;
-        int* Q_I = (int*) malloc(sizeof(int)*Q_N_length);
-        if (Q_I == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        for (j=0; j<Q_N_length; j++)
-        {
-            Q_I[j]=j+1;
-        }
-
-        //Q_N_I = intersect(Q_N, Q_I(info_bit_pattern), 'stable');
-        int Q_N_I_length=0;
-        int* Q_N_common = (int*) malloc(sizeof(int)*Q_N_length);
-        if (Q_N_common == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-
-        for (j=0; j<Q_N_length; j++) //init
-        {
-            Q_N_common[j]=0;
-        }
-
-        for (j=0; j<Q_N_length; j++) //look in Q_I
-        {
-            if(info_bit_pattern[j])
-            {
-                //Q_I(info_bit_pattern)
-                for (i=0; i<Q_N_length; i++) //look in Q_N
-                {
-                    if(Q_N[i]+1==Q_I[j])
-                    {
-                        Q_N_common[i]=1;
-                        Q_N_I_length++;
-                        break;
-                    }
-                }
-            }
-        }
-        free(Q_I);
-
-        int* Q_N_I =  (int*) malloc(sizeof(int)*Q_N_I_length);
-        if (Q_N_I == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        i=0;
-        for(j=0; j<Q_N_length; j++)
-        {
-            if(Q_N_common[j])
-            {
-                Q_N_I[i]=Q_N[j]+1;
-                i++;
-            }
-        }
-
-        free(Q_N_common);
-
-        //int G_N = get_G_N(N);
-        //int w_g = sum(G_N,2);
-        //useless, I do this
-        int* w_g = (int*) malloc(sizeof(int)*Q_N_length);
-        if (w_g == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        w_g[0]=1;
-        w_g[1]=2;
-        int counter=2;
-        int n = log2(Q_N_length);
-
-        for(i=0; i<n-1; i++) //n=log2(N)
-        {
-            for(j=0; j<counter; j++)
-            {
-                w_g[counter+j]=w_g[j]*2;
-            }
-            counter = counter*2;
-        }
-
-        //Q_tilde_N_I = Q_N_I(n_PC+1:end); % This is what it says in TS 38.212
-        int* Q_tilde_N_I = (int*) malloc(sizeof(int)*(Q_N_I_length-n_PC));
-        if (Q_tilde_N_I == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        int* Q_tilde_N_I_flip = (int*) malloc(sizeof(int)*(Q_N_I_length-n_PC));
-        if (Q_tilde_N_I_flip == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        for (i=0; i<Q_N_I_length-n_PC; i++)
-        {
-            Q_tilde_N_I[i]=Q_N_I[n_PC+i];
-            //Q_tilde_N_I_flip = fliplr(Q_tilde_N_I);
-            Q_tilde_N_I_flip[Q_N_I_length-n_PC-i-1] = Q_tilde_N_I[i];
-        }
-        //%Q_tilde_N_I = Q_N_I(n_PC-n_PC_wm+1:end); % I think that this would be slightly more elegant
-
-        //[w_g_sorted, indices] = sort(w_g(Q_tilde_N_I_flip));
-        int* w_g_sorted =  (int*) malloc(sizeof(int)*(Q_N_I_length-n_PC));
-        if (w_g_sorted == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        int* indices =  (int*) malloc(sizeof(int)*(Q_N_I_length-n_PC));
-        if (indices == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        for (i=0; i<Q_N_I_length-n_PC; i++)
-        {
-            w_g_sorted[i]=w_g[Q_tilde_N_I_flip[i]-1]; // w_g(Q_tilde_N_I_flip), yet to sort
-            indices[i] = i;
-        }
-        free(Q_tilde_N_I);
-        free(w_g);
-
-        //bubble sort
-        int tempToSwap=0;
-        for (i = 0; i < (Q_N_I_length-n_PC)-1; i++)
-        {
-            for (j = 0; j < (Q_N_I_length-n_PC)-i-1; j++)
-            {
-                 if (w_g_sorted[j] > w_g_sorted[j+1]) //then swap
-                 {
-                     tempToSwap = w_g_sorted[j];
-                     w_g_sorted[j] = w_g_sorted[j+1];
-                     w_g_sorted[j+1] = tempToSwap;
-
-                     tempToSwap = indices[j];
-                     indices[j] = indices[j+1];
-                     indices[j+1] = tempToSwap;
-                 }
-            }
-        }
-        free(w_g_sorted);
-
-        //Q_N_PC = [Q_N_I(1:n_PC-n_PC_wm), Q_tilde_N_I_flip(indices(1:n_PC_wm))];
-        int* Q_N_PC = (int*) malloc(sizeof(int)*(n_PC));
-        if (Q_N_PC == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-
-        for (i=0; i<n_PC-n_PC_wm; i++)
-        {
-            Q_N_PC[i]=Q_N_I[i]; //Q_N_PC = [Q_N_I(1:n_PC-n_PC_wm), ...
-        }
-        free(Q_N_I);
-
-        for (i=0; i<n_PC_wm; i++)
-        {
-            Q_N_PC[n_PC-n_PC_wm+i] = Q_tilde_N_I_flip[indices[i]];//... Q_tilde_N_I_flip(indices(1:n_PC_wm))];
-        }
-        free(Q_tilde_N_I_flip);
-        free(indices);
-
-        //PC_bit_pattern = false(1,N);
-        //PC_bit_pattern(Q_N_PC) = true;
-        *PC_bit_pattern =  (uint8_t*) malloc(sizeof(uint8_t)*(Q_N_length));
-        if (*PC_bit_pattern == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-
-        for (i=0; i<Q_N_length; i++)
-        {
-            (*PC_bit_pattern)[i]=0;
-            for (j=0; j<n_PC; j++)
-            {
-                if (Q_N_PC[j]-1==i)
-                {
-                    (*PC_bit_pattern)[i]=1;
-                    break;
-                }
-            }
-        }
-
-        //free(Q_I);
-        //free(Q_N_common);
-        //free(Q_N_I);
-        //free(w_g);
-        //free(Q_tilde_N_I);
-        //free(Q_tilde_N_I_flip);
-        //free(w_g_sorted);
-        //free(indices);
-        free(Q_N_PC);
-}
diff --git a/openair1/PHY/CODING/nrPolar_tools/get_crc_generator_matrix.c b/openair1/PHY/CODING/nrPolar_tools/get_crc_generator_matrix.c
deleted file mode 100644
index 31a4cd9756..0000000000
--- a/openair1/PHY/CODING/nrPolar_tools/get_crc_generator_matrix.c
+++ /dev/null
@@ -1,79 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <stdint.h>
-
-void get_crc_generator_matrix(uint8_t A, uint8_t P, uint8_t* crc_polynomial_pattern, uint8_t*** G_P)
-{
-//   GET_CRC_GENERATOR_MATRIX Obtain a Cyclic Redudancy Check (CRC) generator
-//   matrix.
-//
-//   A should be an integer scalar. It specifies the number of bits in the
-//   information bit sequence.
-//
-//   crc_polynomial_pattern should be a binary row vector comprising P+1
-//   number of bits, each having the value 0 or 1. These bits parameterise a
-//   Cyclic Redundancy Check (CRC) comprising P bits. Each bit provides the
-//   coefficient of the corresponding element in the CRC generator
-//   polynomial. From left to right, the bits provide the coefficients for
-//   the elements D^P, D^P-1, D^P-2, ..., D^2, D, 1.
-//
-//   G_P will be a K by P binary matrix. The CRC bits can be generated
-//   according to mod(a*G_P,2).
-
-        *G_P = (uint8_t **)malloc(A * sizeof(uint8_t *));
-        if (*G_P == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        int i,j;
-        for (i=0; i<A; i++)
-        {
-            (*G_P)[i] = (uint8_t *)malloc(P * sizeof(uint8_t));
-            if ((*G_P)[i] == NULL)
-            {
-                fprintf(stderr, "malloc failed\n");
-                exit(-1);
-            }
-        }
-
-        if(A>0)
-        {
-            //G_P(end,:) = crc_polynomial_pattern(2:end);
-            for(i=0; i<P; i++)
-            {
-                (*G_P)[A-1][i] = crc_polynomial_pattern[i+1];
-            }
-
-            //for k = A-1:-1:1
-            //    G_P(k,:) = xor([G_P(k+1,2:end),0],G_P(k+1,1)*crc_polynomial_pattern(2:end));
-            //end
-            for(j=A-2; j>-1; j--)
-            {
-                for(i=0; i<P; i++)
-                {
-                    (*G_P)[j][i]=0; //init with zeros
-                }
-
-                for(i=1; i<P; i++)
-                {
-                    if( (*G_P)[j+1][i] != ( (*G_P)[j+1][0])*crc_polynomial_pattern[i]) //xor
-                        (*G_P)[j][i-1]=1;
-                }
-
-                if(0 != ( (*G_P)[j+1][0])*crc_polynomial_pattern[P]) //xor
-                        (*G_P)[j][P-1]=1;
-            }
-        }
-printf("G_P=\n");
-        for(i=0; i<A; i++)
-        {
-            for(j=0; j<P; j++)
-            {
-                printf("%i ", (int)(*G_P)[i][j]);
-            }
-            printf("\n");
-        }
-
-}
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c b/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c
index 6e17386ca6..8e4953574c 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c
@@ -1,3 +1,24 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 
 void nr_byte2bit(uint8_t *array, uint8_t arraySize, uint8_t *bitArray){//First 2 parameters are in bytes.
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c b/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c
index b594147169..18d416b980 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c
@@ -1,135 +1,25 @@
-#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
-
-
-
-/*********************************************************
-
-crc table initialization
-
-*********************************************************/
-/*static unsigned int      crc24cTable[256];
-static unsigned short    crc11Table[256];
-static unsigned char     crc6Table[256];
-
-
-unsigned int crc24c (unsigned char * inptr, int bitlen)
-{
-
-  int octetlen, resbit;
-  unsigned int  crc = 0;
-  octetlen = bitlen / 8;
-  resbit = (bitlen % 8);
-
-  while (octetlen-- > 0) {
-    crc = (crc << 8) ^ crc24cTable[(*inptr++) ^ (crc >> 24)];
-  }
-
-  if (resbit > 0)
-    crc = (crc << resbit) ^ crc24cTable[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))];
-
-  return crc;
-}
-
-
-
-unsigned int crc11 (unsigned char * inptr, int bitlen)
-{
-  int octetlen, resbit;
-  unsigned int             crc = 0;
-  octetlen = bitlen / 8;        // Change in octets
-  resbit = (bitlen % 8);
-
-  while (octetlen-- > 0) {
-    crc = (crc << 8) ^ (crc11Table[(*inptr++) ^ (crc >> 24)] << 16);
-  }
-
-  if (resbit > 0)
-    crc = (crc << resbit) ^ (crc11Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))] << 16);
-
-  return crc;
-}
-
-unsigned int crc6 (unsigned char * inptr, int bitlen)
-{
-  int octetlen, resbit;
-  unsigned int crc = 0;
-  octetlen = bitlen / 8;        // Change in octets
-  resbit = (bitlen % 8);
-
-  while (octetlen-- > 0) {
-    crc = crc6Table[(*inptr++) ^ (crc >> 24)] << 24;
-  }
-
-  if (resbit > 0)
-    crc = (crc << resbit) ^ (crc6Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))] << 24);
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
 
-  return crc;
-}
-
-uint8_t check_crc(uint8_t *decoded_bytes, uint16_t len, uint8_t crc_type)
-{
-  uint8_t crc_len,temp;
-  uint16_t oldcrc,crc;
-
-  switch (crc_type) {
-
-  case 0: //CRC24_A:
-  case 1: //CRC24_B:
-    crc_len=3;
-    break;
-
-  case 2: //CRC16:
-    crc_len=2;
-    break;
-
-  case 3: //CRC8:
-    crc_len=1;
-    break;
-
-  default:
-    crc_len=3;
-  }
-
-  // check the CRC
-  oldcrc= *((unsigned int *)(&decoded_bytes[(len>>3)-crc_len]));
-
-      switch (crc_type) {
-
-      case 0: //CRC24_A:
-        oldcrc&=0x00ffffff;
-        crc = crc24a(decoded_bytes,len-24)>>8;
-        temp=((uint8_t *)&crc)[2];
-        ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
-        ((uint8_t *)&crc)[0] = temp;
-        break;
-
-      case 1: //CRC24_B:
-        oldcrc&=0x00ffffff;
-        crc = crc24b(decoded_bytes,len-24)>>8;
-        temp=((uint8_t *)&crc)[2];
-        ((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
-        ((uint8_t *)&crc)[0] = temp;
-        break;
-
-      case 2: //CRC16:
-        oldcrc&=0x0000ffff;
-        crc = crc16(decoded_bytes,len-16)>>16;
-        break;
-
-      case 3: //CRC8:
-        oldcrc&=0x000000ff;
-        crc = crc6(decoded_bytes,len-8)>>24;
-        break;
-
-      default:
-        printf("FATAL: Unknown CRC\n");
-        return(255);
-        break;
-      }
-
-      printf("old CRC %x, CRC %x \n",oldcrc,crc);
-      return (crc == oldcrc); 
-}*/
+#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 
 uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits){
 
@@ -244,23 +134,3 @@ uint8_t **crc6_generator_matrix(uint16_t payloadSizeBits){
 
 	return crc_generator_matrix;
 }
-
-
-#ifdef DEBUG_CRC
-/*******************************************************************/
-/**   Test code
-/*******************************************************************/
-
-#include <stdio.h>
-
-main()
-{
-  unsigned char test[] = "Thebigredfox";
-  crcTableInit();
-  //printf("%x\n", crcbit(test, sizeof(test) - 1, poly24a));
-  //printf("%x\n", crc24a(test, (sizeof(test) - 1)*8));
-  printf("%x\n", crcbit(test, sizeof(test) - 1, poly6));
-  printf("%x\n", crc6(test, (sizeof(test) - 1)*8));
-}
-#endif
-
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_bit_insertion.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_bit_insertion.c
index 52fdf6ca46..4c1c2bbce5 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_bit_insertion.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_bit_insertion.c
@@ -1,7 +1,28 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 
 void nr_polar_bit_insertion(uint8_t *input, uint8_t *output, uint16_t N, uint16_t K,
-		uint16_t *Q_I_N, uint16_t *Q_PC_N, uint8_t n_PC){
+		int16_t *Q_I_N, int16_t *Q_PC_N, uint8_t n_PC){
 
 	uint16_t k=0;
 	uint8_t flag;
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_bit_insertion_2.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_bit_insertion_2.c
deleted file mode 100644
index 1a7c1264b5..0000000000
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_bit_insertion_2.c
+++ /dev/null
@@ -1,63 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <stdint.h>
-
-void nr_polar_bit_insertion_2(uint8_t* u, uint8_t* b, uint8_t* info_bit_pattern, uint8_t* PC_bit_pattern, uint16_t N)
-{
-        int PC_circular_buffer_length=5;
-
-        int i, j;
-        int k=0;
-
-        int* y = (int*) malloc(sizeof(int)*PC_circular_buffer_length);
-        if (y == NULL)
-        {
-            fprintf(stderr, "malloc failed\n");
-            exit(-1);
-        }
-        for(i=0; i<PC_circular_buffer_length; i++)
-        {
-            y[i]=0;
-        }
-
-        int tempToShift;
-        //for n=0:N-1
-        printf("u = ");
-        for(i=0; i<N; i++)
-        {
-            //y = [y(2:end),y(1)];
-            tempToShift=y[0];
-            for (j=0; j<PC_circular_buffer_length-1; j++)
-            {
-                y[j]=y[j+1];
-            }
-            y[PC_circular_buffer_length-1]=tempToShift;
-
-            //if info_bit_pattern(n+1)
-            //    if PC_bit_pattern(n+1)
-            //        u(n+1) = y(1);
-            //    else
-            //        u(n+1) = b(k+1);
-            //        k=k+1;
-            //        y(1) = xor(y(1),u(n+1));
-            if (info_bit_pattern[i])
-            {
-                if (PC_bit_pattern[i])
-                {
-                    u[i] = y[1];
-                } else
-                {
-                    u[i] = b[k];
-                    k++;
-                    y[1] = ( y[1]!=u[i]);
-                }
-            } else
-            {
-                u[i]=0;
-            }
-            printf("%i ", u[i]);
-        }
-
-        free(y);
-}
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_channel_interleaver_pattern.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_channel_interleaver_pattern.c
index c0dce671bf..35e7585e1a 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_channel_interleaver_pattern.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_channel_interleaver_pattern.c
@@ -1,3 +1,24 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 
 void nr_polar_channel_interleaver_pattern(uint16_t *cip, uint8_t I_BIL, uint16_t E){
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_dci_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_dci_defs.h
new file mode 100644
index 0000000000..6c28a594f2
--- /dev/null
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_dci_defs.h
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file PHY/CODING/nrPolar_tools/nr_polar_dci_defs.h
+* \brief Defines the constant variables for polar coding of the DCI from 38-212, V15.1.1 2018-04.
+* \author
+* \date 2018
+* \version 0.1
+* \company Eurecom
+* \email:
+* \note
+* \warning
+*/
+
+#ifndef __NR_POLAR_DCI_DEFS__H__
+#define __NR_POLAR_DCI_DEFS__H__
+
+//Sec. 7.3.3: Channel Coding
+#define NR_POLAR_DCI_N_MAX 9   //uint8_t
+#define NR_POLAR_DCI_I_IL 1    //uint8_t
+//#define NR_POLAR_DCI_I_SEG 0   //uint8_t
+#define NR_POLAR_DCI_N_PC 0    //uint8_t
+#define NR_POLAR_DCI_N_PC_WM 0 //uint8_t
+
+//Sec. 7.3.4: Rate Matching
+#define NR_POLAR_DCI_I_BIL 0 //uint8_t
+
+#endif
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c
index 63248c6162..3d076296d0 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c
@@ -1,5 +1,23 @@
-#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
-#include "PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h"
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
 
 /*
  * Return values:
@@ -7,8 +25,17 @@
  * -1 --> All list entries have failed the CRC checks
  */
 
-int8_t polar_decoder(double *input, uint8_t *output, t_nrPolar_params *polarParams, uint8_t listSize,
-		double *aPrioriPayload, uint8_t pathMetricAppr){
+#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
+#include "PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h"
+
+int8_t polar_decoder(
+		double *input,
+		uint8_t *output,
+		t_nrPolar_params *polarParams,
+		uint8_t listSize,
+		double *aPrioriPayload,
+		uint8_t pathMetricAppr)
+{
 
 	uint8_t ***bit = nr_alloc_uint8_t_3D_array(polarParams->N, (polarParams->n+1), 2*listSize);
 	uint8_t **bitUpdated = nr_alloc_uint8_t_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
@@ -27,8 +54,6 @@ int8_t polar_decoder(double *input, uint8_t *output, t_nrPolar_params *polarPara
 		bitUpdated[i][0]=((polarParams->information_bit_pattern[i]+1) % 2);
 	}
 
-	uint8_t **crc_generator_matrix=crc24c_generator_matrix(polarParams->payloadBits); //G_P
-
 	uint8_t **extended_crc_generator_matrix = malloc(polarParams->K * sizeof(uint8_t *)); //G_P3
 	uint8_t **tempECGM = malloc(polarParams->K * sizeof(uint8_t *)); //G_P2
 	for (int i = 0; i < polarParams->K; i++){
@@ -38,7 +63,7 @@ int8_t polar_decoder(double *input, uint8_t *output, t_nrPolar_params *polarPara
 
 	for (int i=0; i<polarParams->payloadBits; i++) {
 		for (int j=0; j<polarParams->crcParityBits; j++) {
-			tempECGM[i][j]=crc_generator_matrix[i][j];
+			tempECGM[i][j]=polarParams->crc_generator_matrix[i][j];
 		}
 	}
 	for (int i=polarParams->payloadBits; i<polarParams->K; i++) {
@@ -203,9 +228,9 @@ int8_t polar_decoder(double *input, uint8_t *output, t_nrPolar_params *polarPara
 			for (uint8_t i = 0; i < currentListSize; i++) decoderIterationCheck+=crcState[i];
 			if (decoderIterationCheck==0) {
 				//perror("[SCL polar decoder] All list entries have failed the CRC checks.");
-				free(crc_generator_matrix);
 				free(d_tilde);
 				free(pathMetric);
+				free(crcState);
 				nr_free_uint8_t_3D_array(bit, polarParams->N, (polarParams->n+1));
 				nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1));
 				nr_free_uint8_t_2D_array(crcChecksum, polarParams->crcParityBits);
@@ -221,34 +246,30 @@ int8_t polar_decoder(double *input, uint8_t *output, t_nrPolar_params *polarPara
 	for (uint8_t i = 0; i < 2*listSize; i++) listIndex[i]=i;
 	nr_sort_asc_double_1D_array_ind(pathMetric, listIndex, currentListSize);
 
-	uint8_t *nr_polar_uHat = malloc(sizeof(uint8_t) * polarParams->N);
-	uint8_t *nr_polar_cHat = malloc(sizeof(uint8_t) * polarParams->K);
-	uint8_t *nr_polar_bHat = malloc(sizeof(uint8_t) * polarParams->K);
 	for (uint8_t i = 0; i < fmin(listSize, (pow(2,polarParams->crcCorrectionBits)) ); i++) {
 		if ( crcState[listIndex[i]] == 1 ) {
-			for (int j = 0; j < polarParams->N; j++) nr_polar_uHat[j]=bit[j][0][listIndex[i]];
+			for (int j = 0; j < polarParams->N; j++) polarParams->nr_polar_u[j]=bit[j][0][listIndex[i]];
 
 			//Extract the information bits (û to ĉ)
-			nr_polar_info_bit_extraction(nr_polar_uHat, nr_polar_cHat, polarParams->information_bit_pattern, polarParams->N);
+			nr_polar_info_bit_extraction(polarParams->nr_polar_u, polarParams->nr_polar_cPrime, polarParams->information_bit_pattern, polarParams->N);
 
 			//Deinterleaving (ĉ to b)
-			nr_polar_deinterleaver(nr_polar_cHat, nr_polar_bHat, polarParams->interleaving_pattern, polarParams->K);
+			nr_polar_deinterleaver(polarParams->nr_polar_cPrime, polarParams->nr_polar_b, polarParams->interleaving_pattern, polarParams->K);
 
 			//Remove the CRC (â)
-			for (int j = 0; j < polarParams->payloadBits; j++) output[j]=nr_polar_bHat[j];
+			for (int j = 0; j < polarParams->payloadBits; j++) output[j]=polarParams->nr_polar_b[j];
 
 			break;
 		}
 	}
 
-	free(crc_generator_matrix);
 	free(d_tilde);
 	free(pathMetric);
-	free(nr_polar_uHat);
-	free(nr_polar_cHat);
-	free(nr_polar_bHat);
+	free(crcState);
 	nr_free_uint8_t_3D_array(bit, polarParams->N, (polarParams->n+1));
 	nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1));
 	nr_free_uint8_t_2D_array(crcChecksum, polarParams->crcParityBits);
+	nr_free_uint8_t_2D_array(extended_crc_generator_matrix, polarParams->K);
+	nr_free_uint8_t_2D_array(tempECGM, polarParams->K);
 	return(0);
 }
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c
index 4555f8c3ba..0b010131cd 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c
@@ -1,3 +1,24 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 
 void updateLLR(double ***llr, uint8_t **llrU, uint8_t ***bit, uint8_t **bitU,
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h
index 9c3393adba..0db26f6f35 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h
@@ -1,3 +1,24 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #ifndef __NR_POLAR_DEFS__H__
 #define __NR_POLAR_DEFS__H__
 
@@ -9,9 +30,10 @@
 
 static const uint8_t nr_polar_subblock_interleaver_pattern[32] = { 0, 1, 2, 4, 3, 5, 6, 7, 8, 16, 9, 17, 10, 18, 11, 19, 12, 20, 13, 21, 14, 22, 15, 23, 24, 25, 26, 28, 27, 29, 30, 31 };
 
-typedef struct nrPolar_params {
+struct nrPolar_params {
 	uint8_t n_max;
 	uint8_t i_il;
+	uint8_t i_seg;
 	uint8_t n_pc;
 	uint8_t n_pc_wm;
 	uint8_t i_bil;
@@ -25,7 +47,7 @@ typedef struct nrPolar_params {
 
 	uint16_t *interleaving_pattern;
 	uint16_t *rate_matching_pattern;
-	uint16_t *Q_0_Nminus1;
+	const uint16_t *Q_0_Nminus1;
 	int16_t *Q_I_N;
 	int16_t *Q_F_N;
 	int16_t *Q_PC_N;
@@ -34,9 +56,17 @@ typedef struct nrPolar_params {
 
 	uint8_t **crc_generator_matrix; //G_P
 	uint8_t **G_N;
-} t_nrPolar_params;
 
-void polar_encoder(uint8_t *input, uint8_t *channel_input, t_nrPolar_params* polarParams);
+	//polar_encoder vectors:
+	uint8_t *nr_polar_crc;
+	uint8_t *nr_polar_b;
+	uint8_t *nr_polar_cPrime;
+	uint8_t *nr_polar_u;
+	uint8_t *nr_polar_d;
+} __attribute__ ((__packed__));
+typedef struct nrPolar_params t_nrPolar_params;
+
+void polar_encoder(uint8_t *input, uint8_t *output, t_nrPolar_params* polarParams);
 
 int8_t polar_decoder(double *input, uint8_t *output, t_nrPolar_params *polarParams,
 		uint8_t listSize, double *aPrioriPayload, uint8_t pathMetricAppr);
@@ -45,31 +75,23 @@ void nr_polar_init(t_nrPolar_params* polarParams, int messageType);
 
 uint8_t** nr_polar_kronecker_power_matrices(uint8_t n);
 
-uint16_t* nr_polar_sequence_pattern(uint8_t n);
+const uint16_t* nr_polar_sequence_pattern(uint8_t n);
 
 uint32_t nr_polar_output_length(uint16_t K, uint16_t E, uint8_t n_max);
 
 void nr_polar_channel_interleaver_pattern(uint16_t *cip, uint8_t I_BIL,
 		uint16_t E);
 
-void nr_polar_rate_matching_pattern(uint16_t *rmp, uint16_t *J, uint8_t *P_i_,
+void nr_polar_rate_matching_pattern(uint16_t *rmp, uint16_t *J, const uint8_t *P_i_,
 		uint16_t K, uint16_t N, uint16_t E);
 
 void nr_polar_rate_matching(double *input, double *output, uint16_t *rmp,
 		uint16_t K, uint16_t N, uint16_t E);
 
-void nr_polar_rate_matcher(uint8_t *input, unsigned char *output, uint16_t *pattern, uint16_t size);
-
 void nr_polar_interleaving_pattern(uint16_t K, uint8_t I_IL, uint16_t *PI_k_);
 
-void nr_polar_interleaver(uint8_t *input, uint8_t *output, uint16_t *pattern,
-		uint16_t size);
-
-void nr_polar_deinterleaver(uint8_t *input, uint8_t *output, uint16_t *pattern,
-		uint16_t size);
-
-void nr_polar_info_bit_pattern(uint8_t *ibp, uint16_t *Q_I_N, int16_t *Q_F_N,
-		uint16_t *J, uint16_t *Q_0_Nminus1, uint16_t K, uint16_t N, uint16_t E,
+void nr_polar_info_bit_pattern(uint8_t *ibp, int16_t *Q_I_N, int16_t *Q_F_N,
+		uint16_t *J, const uint16_t *Q_0_Nminus1, uint16_t K, uint16_t N, uint16_t E,
 		uint8_t n_PC);
 
 void nr_polar_info_bit_extraction(uint8_t *input, uint8_t *output,
@@ -78,7 +100,7 @@ void nr_polar_info_bit_extraction(uint8_t *input, uint8_t *output,
 void nr_byte2bit(uint8_t *array, uint8_t arraySize, uint8_t *bitArray);
 
 void nr_polar_bit_insertion(uint8_t *input, uint8_t *output, uint16_t N,
-		uint16_t K, uint16_t *Q_I_N, uint16_t *Q_PC_N, uint8_t n_PC);
+		uint16_t K, int16_t *Q_I_N, int16_t *Q_PC_N, uint8_t n_PC);
 
 void nr_matrix_multiplication_uint8_t_1D_uint8_t_2D(uint8_t *matrix1, uint8_t **matrix2,
 		uint8_t *output, uint16_t row, uint16_t col);
@@ -109,4 +131,20 @@ void updateCrcChecksum2(uint8_t **crcChecksum, uint8_t **crcGen,
 		uint8_t listSize, uint32_t i2, uint8_t len);
 void nr_sort_asc_double_1D_array_ind(double *matrix, uint8_t *ind, uint8_t len);
 
+uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits);
+uint8_t **crc11_generator_matrix(uint16_t payloadSizeBits);
+uint8_t **crc6_generator_matrix(uint16_t payloadSizeBits);
+
+static inline void nr_polar_rate_matcher(uint8_t *input, unsigned char *output, uint16_t *pattern, uint16_t size) {
+	for (int i=0; i<size; i++) output[i]=input[pattern[i]];
+}
+
+static inline void nr_polar_interleaver(uint8_t *input, uint8_t *output, uint16_t *pattern, uint16_t size) {
+	for (int i=0; i<size; i++) output[i]=input[pattern[i]];
+}
+
+static inline void nr_polar_deinterleaver(uint8_t *input, uint8_t *output, uint16_t *pattern, uint16_t size) {
+	for (int i=0; i<size; i++) output[pattern[i]]=input[i];
+}
+
 #endif
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c
index 680d0d718a..f1bfb37a62 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c
@@ -1,56 +1,59 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 #include "PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h"
 
-void polar_encoder(uint8_t *input, uint8_t *channel_input, t_nrPolar_params *polarParams){
-	/*//Create the Transport Block.
-	unsigned int payload=0xb3f02c82;
-	uint8_t pbchTransportBlockSize = ( polarParams->K / (8*sizeof(uint8_t)) );
-	uint8_t *pbchTransportBlock = malloc(pbchTransportBlockSize);
-	memcpy(pbchTransportBlock,&payload,sizeof(payload));
-
-	//Attach CRC to the Transport Block. (a to b)
-	uint32_t crc = crc24c(&payload, NR_POLAR_PBCH_PAYLOAD_BITS)>>8;
-	pbchTransportBlock[NR_POLAR_PBCH_PAYLOAD_BITS>>3] = ((uint8_t*)&crc)[2];
-	pbchTransportBlock[1+(NR_POLAR_PBCH_PAYLOAD_BITS>>3)] = ((uint8_t*)&crc)[1];
-	pbchTransportBlock[2+(NR_POLAR_PBCH_PAYLOAD_BITS>>3)] = ((uint8_t*)&crc)[0];*/
+void polar_encoder(
+		uint8_t *input,
+		uint8_t *output,
+		t_nrPolar_params *polarParams)
+{
 
 	/*
 	 * Bytewise operations
 	 */
 
 	//Calculate CRC.
-	uint8_t *nr_polar_crc = malloc(sizeof(uint8_t) * polarParams->crcParityBits);
 	nr_matrix_multiplication_uint8_t_1D_uint8_t_2D(input, polarParams->crc_generator_matrix,
-			nr_polar_crc, polarParams->payloadBits, polarParams->crcParityBits);
-	for (uint8_t i = 0; i < polarParams->crcParityBits; i++) nr_polar_crc[i] = (nr_polar_crc[i] % 2);
+			polarParams->nr_polar_crc, polarParams->payloadBits, polarParams->crcParityBits);
+	for (uint8_t i = 0; i < polarParams->crcParityBits; i++) polarParams->nr_polar_crc[i] = (polarParams->nr_polar_crc[i] % 2);
 
 	//Attach CRC to the Transport Block. (a to b)
-	uint8_t *nr_polar_b = malloc(sizeof(uint8_t) * polarParams->K);
-	for (uint16_t i = 0; i < polarParams->payloadBits; i++) nr_polar_b[i] = input[i];
-	for (uint16_t i = polarParams->payloadBits; i < polarParams->K; i++) nr_polar_b[i]= nr_polar_crc[i-(polarParams->payloadBits)];
+	for (uint16_t i = 0; i < polarParams->payloadBits; i++) polarParams->nr_polar_b[i] = input[i];
+	for (uint16_t i = polarParams->payloadBits; i < polarParams->K; i++)
+		polarParams->nr_polar_b[i]= polarParams->nr_polar_crc[i-(polarParams->payloadBits)];
 
 	//Interleaving (c to c')
-	uint8_t *nr_polar_cPrime = malloc(sizeof(uint8_t) * polarParams->K);
-	nr_polar_interleaver(nr_polar_b, nr_polar_cPrime, polarParams->interleaving_pattern, polarParams->K);
+	nr_polar_interleaver(polarParams->nr_polar_b, polarParams->nr_polar_cPrime, polarParams->interleaving_pattern, polarParams->K);
 
 	//Bit insertion (c' to u)
-	uint8_t *nr_polar_u = malloc(sizeof(uint8_t) * polarParams->N);
-	nr_polar_bit_insertion(nr_polar_cPrime, nr_polar_u, polarParams->N, polarParams->K,
+	nr_polar_bit_insertion(polarParams->nr_polar_cPrime, polarParams->nr_polar_u, polarParams->N, polarParams->K,
 			polarParams->Q_I_N, polarParams->Q_PC_N, polarParams->n_pc);
 
 	//Encoding (u to d)
-	uint8_t *pbch_polar_encoder_output = malloc(sizeof(uint8_t) * polarParams->N);
-	nr_matrix_multiplication_uint8_t_1D_uint8_t_2D(nr_polar_u, polarParams->G_N, pbch_polar_encoder_output, polarParams->N, polarParams->N);
-	for (uint16_t i = 0; i < polarParams->N; i++) pbch_polar_encoder_output[i] = (pbch_polar_encoder_output[i] % 2);
+	nr_matrix_multiplication_uint8_t_1D_uint8_t_2D(polarParams->nr_polar_u, polarParams->G_N, polarParams->nr_polar_d, polarParams->N, polarParams->N);
+	for (uint16_t i = 0; i < polarParams->N; i++) polarParams->nr_polar_d[i] = (polarParams->nr_polar_d[i] % 2);
 
 	//Rate matching
 	//Sub-block interleaving (d to y) and Bit selection (y to e)
-	nr_polar_rate_matcher(pbch_polar_encoder_output, channel_input, polarParams->rate_matching_pattern, polarParams->encoderLength);
-
-	//free(pbchTransportBlock);
-	free(nr_polar_crc);
-	free(nr_polar_b);
-	free(nr_polar_cPrime);
-	free(nr_polar_u);
-	free(pbch_polar_encoder_output);
+	nr_polar_rate_matcher(polarParams->nr_polar_d, output, polarParams->rate_matching_pattern, polarParams->encoderLength);
 }
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_info_bit_pattern.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_info_bit_pattern.c
index f311571c99..a46c427b81 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_info_bit_pattern.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_info_bit_pattern.c
@@ -1,7 +1,28 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 
-void nr_polar_info_bit_pattern(uint8_t *ibp, uint16_t *Q_I_N, int16_t *Q_F_N,
-		uint16_t *J, uint16_t *Q_0_Nminus1, uint16_t K, uint16_t N, uint16_t E,
+void nr_polar_info_bit_pattern(uint8_t *ibp, int16_t *Q_I_N, int16_t *Q_F_N,
+		uint16_t *J, const uint16_t *Q_0_Nminus1, uint16_t K, uint16_t N, uint16_t E,
 		uint8_t n_PC) {
 
 	int16_t *Q_Ftmp_N = malloc(sizeof(int16_t) * (N + 1)); // Last element shows the final
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_interleave.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_interleaving_pattern.c
similarity index 53%
rename from openair1/PHY/CODING/nrPolar_tools/nr_polar_interleave.c
rename to openair1/PHY/CODING/nrPolar_tools/nr_polar_interleaving_pattern.c
index 643b5fd034..da9c51085f 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_interleave.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_interleaving_pattern.c
@@ -1,3 +1,24 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 
 void nr_polar_interleaving_pattern(uint16_t K, uint8_t I_IL, uint16_t *PI_k_){
@@ -27,11 +48,3 @@ void nr_polar_interleaving_pattern(uint16_t K, uint8_t I_IL, uint16_t *PI_k_){
 		}
 	}
 }
-
-void nr_polar_interleaver(uint8_t *input, uint8_t *output, uint16_t *pattern, uint16_t size) {
-	for (int i=0; i<size; i++) output[i]=input[pattern[i]];
-}
-
-void nr_polar_deinterleaver(uint8_t *input, uint8_t *output, uint16_t *pattern, uint16_t size) {
-	for (int i=0; i<size; i++) output[pattern[i]]=input[i];
-}
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_kronecker_power_matrices.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_kronecker_power_matrices.c
index 749e37f125..ba72cd8b11 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_kronecker_power_matrices.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_kronecker_power_matrices.c
@@ -1,3 +1,24 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 
 uint8_t (*const(G_N_1[])) = {
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_matrix_and_array.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_matrix_and_array.c
index 7561776d05..572b016cfa 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_matrix_and_array.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_matrix_and_array.c
@@ -1,3 +1,24 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 
 void nr_matrix_multiplication_uint8_t_1D_uint8_t_2D(uint8_t *matrix1, uint8_t **matrix2,
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_output_length.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_output_length.c
index bbb6c8b3b8..e2d65c22fc 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_output_length.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_output_length.c
@@ -1,3 +1,24 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include <math.h>
 #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h
index 5f6dcce19d..85b20f90fc 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h
@@ -1,7 +1,35 @@
 /*
- * Defines the constant variables for polar coding of the PBCH.
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
  */
 
+/*! \file PHY/CODING/nrPolar_tools/nr_polar_dci_defs.h
+* \brief Defines the constant variables for polar coding of the PBCH from 38-212, V15.1.1 2018-04.
+* \author
+* \date 2018
+* \version 0.1
+* \company Eurecom
+* \email:
+* \note
+* \warning
+*/
+
 #ifndef __NR_POLAR_PBCH_DEFS__H__
 #define __NR_POLAR_PBCH_DEFS__H__
 
@@ -10,14 +38,15 @@
 #define NR_POLAR_PBCH_CRC_ERROR_CORRECTION_BITS 3
 //Assumed 3 by 3GPP when NR_POLAR_PBCH_L>8 to meet false alarm rate requirements.
 
-//Ref. 38-212 v15.0.1, Section 7.1.4: Channel Coding
+//Sec. 7.1.4: Channel Coding
 #define NR_POLAR_PBCH_N_MAX 9   //uint8_t
 #define NR_POLAR_PBCH_I_IL 1    //uint8_t
+#define NR_POLAR_PBCH_I_SEG 0   //uint8_t
 #define NR_POLAR_PBCH_N_PC 0    //uint8_t
 #define NR_POLAR_PBCH_N_PC_WM 0 //uint8_t
 //#define NR_POLAR_PBCH_N 512     //uint16_t
 
-//Ref. 38-212 v15.0.1, Section 7.1.5: Rate Matching
+//Sec. 7.1.5: Rate Matching
 #define NR_POLAR_PBCH_I_BIL 0 //uint8_t
 #define NR_POLAR_PBCH_E 864   //uint16_t
 
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_rate_match.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_rate_match.c
index 13e0e1a6d4..90f16183c8 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_rate_match.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_rate_match.c
@@ -1,7 +1,28 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include <math.h>
 #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 
-void nr_polar_rate_matching_pattern(uint16_t *rmp, uint16_t *J, uint8_t *P_i_, uint16_t K, uint16_t N, uint16_t E){
+void nr_polar_rate_matching_pattern(uint16_t *rmp, uint16_t *J, const uint8_t *P_i_, uint16_t K, uint16_t N, uint16_t E){
 	
 	uint8_t i;
 	uint16_t *d, *y, ind;
@@ -58,7 +79,3 @@ void nr_polar_rate_matching(double *input, double *output, uint16_t *rmp, uint16
 	}
 
 }
-
-void nr_polar_rate_matcher(uint8_t *input, unsigned char *output, uint16_t *pattern, uint16_t size) {
-	for (int i=0; i<size; i++) output[i]=input[pattern[i]];
-}
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_sequence_pattern.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_sequence_pattern.c
index 5ccfd8aeb1..94f73f3783 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_sequence_pattern.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_sequence_pattern.c
@@ -1,3 +1,24 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
 #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
 
 static const uint16_t Q_0_Nminus1_1[2] = { 0, 1 };
@@ -14,6 +35,6 @@ static const uint16_t Q_0_Nminus1_10[1024] = { 0, 1, 2, 4, 8, 16, 32, 3, 5, 64,
 static const uint16_t *Q_0_Nminus1[11] = { NULL, Q_0_Nminus1_1, Q_0_Nminus1_2, Q_0_Nminus1_3, Q_0_Nminus1_4,
 		Q_0_Nminus1_5, Q_0_Nminus1_6, Q_0_Nminus1_7, Q_0_Nminus1_8, Q_0_Nminus1_9, Q_0_Nminus1_10 };
 
-uint16_t* nr_polar_sequence_pattern(uint8_t n){
+const uint16_t* nr_polar_sequence_pattern(uint8_t n){
 	return Q_0_Nminus1[n];
 }
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h
new file mode 100644
index 0000000000..214267d94c
--- /dev/null
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h
+* \brief Defines the constant variables for polar coding of the UCI from 38-212, V15.1.1 2018-04.
+* \author
+* \date 2018
+* \version 0.1
+* \company Eurecom
+* \email:
+* \note
+* \warning
+*/
+
+#ifndef __NR_POLAR_UCI_DEFS__H__
+#define __NR_POLAR_UCI_DEFS__H__
+
+#endif
diff --git a/openair1/PHY/TOOLS/file_output.c b/openair1/PHY/TOOLS/file_output.c
index 1e0b31a47f..c76812ae8c 100644
--- a/openair1/PHY/TOOLS/file_output.c
+++ b/openair1/PHY/TOOLS/file_output.c
@@ -158,7 +158,6 @@ int write_output(const char *fname,const char *vname,void *data,int length,int d
         fprintf(fp,"\n%d,",((short *)data)[i]);
     }
 
-    printf("\n erennnnnnnnnnnnnnn: length :%d",length);
     break;
 
   case 12 : // case eren for log2_maxh real unsigned 8 bit
@@ -170,10 +169,8 @@ int write_output(const char *fname,const char *vname,void *data,int length,int d
   if (format != 10 && format !=11 && format !=12 && format != 13 && format != 15) {
     fprintf(fp,"];\n");
     fclose(fp);
-    return(0);
   } else if (format == 10 || format ==11 || format == 12 || format == 13 || format == 15) {
     fclose(fp);
-    return(0);
   }
 
   return 0;
-- 
GitLab