diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index fce3b2d76cb93ce219c6bee9166da5c10ac3c653..5647f28837d3a8c31af5bc9d0445dde2d573d425 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -550,7 +550,9 @@ set (CONFIG_SOURCES
    )
 set (CONFIG_LIBCONFIG_SOURCES
     ${CONFIG_ROOTDIR}/libconfig/config_libconfig.c
-   )
+    )
+add_library(CONFIG_LIB ${CONFIG_SOURCES})
+set(CONFIG_LIBRARIES CONFIG_LIB)  
 add_library(params_libconfig MODULE ${CONFIG_LIBCONFIG_SOURCES} )
 target_link_libraries(params_libconfig config)
 # shared library loader
@@ -1305,7 +1307,7 @@ set(PHY_SRC_UE
   ${OPENAIR1_DIR}/PHY/NR_REFSIG/nr_gold.c
   ${OPENAIR1_DIR}/PHY/TOOLS/file_output.c
   ${OPENAIR1_DIR}/PHY/TOOLS/cadd_vv.c
-  ${OPENAIR1_DIR}/PHY/TOOLS/lte_dfts.c
+  #${OPENAIR1_DIR}/PHY/TOOLS/lte_dfts.c
   ${OPENAIR1_DIR}/PHY/TOOLS/log2_approx.c
   ${OPENAIR1_DIR}/PHY/TOOLS/cmult_sv.c
   ${OPENAIR1_DIR}/PHY/TOOLS/cmult_vv.c
@@ -1341,9 +1343,10 @@ set(PHY_SRC_UE
   ${OPENAIR1_DIR}/PHY/NR_REFSIG/nr_dmrs_rx.c
   ${OPENAIR1_DIR}/PHY/NR_REFSIG/nr_gold_ue.c
   ${OPENAIR1_DIR}/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c
+  ${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/lte_ue_measurements.c
   ${OPENAIR1_DIR}/PHY/TOOLS/file_output.c
   ${OPENAIR1_DIR}/PHY/TOOLS/cadd_vv.c
-  ${OPENAIR1_DIR}/PHY/TOOLS/lte_dfts.c
+ # ${OPENAIR1_DIR}/PHY/TOOLS/lte_dfts.c
   ${OPENAIR1_DIR}/PHY/TOOLS/log2_approx.c
   ${OPENAIR1_DIR}/PHY/TOOLS/cmult_sv.c
   ${OPENAIR1_DIR}/PHY/TOOLS/cmult_vv.c
@@ -2450,7 +2453,7 @@ add_executable(nr-uesoftmodem
 
 target_link_libraries (nr-uesoftmodem
   -Wl,--start-group
-  RRC_LIB NR_RRC_LIB SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT UDP SCHED_RU_LIB SCHED_UE_LIB SCHED_NR_UE_LIB PHY_COMMON PHY_UE PHY_NR_UE PHY_RU LFDS NR_L2_UE #NR_LTE_UE_REUSE_LIB 
+  RRC_LIB NR_RRC_LIB SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT UDP SCHED_RU_LIB SCHED_UE_LIB SCHED_NR_UE_LIB PHY_COMMON PHY_NR_UE PHY_RU LFDS NR_L2_UE #NR_LTE_UE_REUSE_LIB 
   ${MSC_LIB} ${RAL_LIB} ${NAS_UE_LIB} ${ITTI_LIB} ${FLPT_MSG_LIB} ${ASYNC_IF_LIB} LFDS7 ${ATLAS_LIBRARIES}
   -Wl,--end-group z dl)
 
@@ -2536,10 +2539,14 @@ target_link_libraries (dlsim_tm4
   )
 
 add_executable(polartest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/polartest.c)
-target_link_libraries(polartest m SIMU PHY PHY_NR PHY_COMMON -lm ${ATLAS_LIBRARIES})
+target_link_libraries(polartest SIMU PHY PHY_NR PHY_COMMON m ${ATLAS_LIBRARIES})
 
 add_executable(ldpctest  ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/ldpctest.c)
-target_link_libraries(ldpctest m SIMU PHY PHY_NR ${ATLAS_LIBRARIES})
+target_link_libraries(ldpctest SIMU PHY PHY_NR m ${ATLAS_LIBRARIES})
+
+add_executable(nr_pbchsim  ${OPENAIR1_DIR}/SIMULATION/NR_PHY/pbchsim.c )
+target_link_libraries(nr_pbchsim  -Wl,--start-group UTIL SIMU PHY PHY_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB ${CONFIG_LIBRARIES} -Wl,--end-group m pthread dl ${ATLAS_LIBRARIES})
+
 
 foreach(myExe dlsim dlsim_tm7 ulsim pbchsim scansim mbmssim pdcchsim pucchsim prachsim syncsim)
 
diff --git a/cmake_targets/autotests/test_case_list.xml b/cmake_targets/autotests/test_case_list.xml
index 774c33a7a05ca48c2e1650b343537ffd4e0cd9a3..57b16bcca42b8d653e49a54f751d2a5ad5ebcd72 100644
--- a/cmake_targets/autotests/test_case_list.xml
+++ b/cmake_targets/autotests/test_case_list.xml
@@ -1041,7 +1041,25 @@
       <search_expr_true>BLER= 0.000000</search_expr_true>
       <search_expr_false>segmentation fault|assertion|exiting|fatal</search_expr_false>
       <nruns>3</nruns>
+    </testCase>
+
+     <testCase id="015104">
+      <class>execution</class>
+      <desc>nr_pbchsim test cases.</desc>
+      <pre_compile_prog></pre_compile_prog>
+      <compile_prog>$OPENAIR_DIR/cmake_targets/build_oai</compile_prog>
+      <compile_prog_args> --phy_simulators  -c </compile_prog_args>
+      <pre_exec>$OPENAIR_DIR/cmake_targets/autotests/tools/free_mem.bash</pre_exec>
+      <pre_exec_args></pre_exec_args>
+      <main_exec> $OPENAIR_DIR/targets/bin/nr_pbchsim.Rel15</main_exec>
+      <main_exec_args>-s-11 -S-10 -n1000
+                      -s-11 -S-10 -n10 -I</main_exec_args>
+      <tags>nr_pbchsim.test1</tags>
+      <search_expr_true>n_errors \(negative CRC\) = 0</search_expr_true>
+      <search_expr_false>segmentation fault|assertion|exiting|fatal</search_expr_false>
+      <nruns>3</nruns>
     </testCase> 
+ 
     
     <testCase id="015110">
       <class>execution</class>
diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai
index f4c2cb6c9663750af592d36afb0bac981b5661ec..56f53000518393b083f828d385ca7116580b57f1 100755
--- a/cmake_targets/build_oai
+++ b/cmake_targets/build_oai
@@ -679,7 +679,7 @@ function main() {
   fi
 
   if [ "$SIMUS_PHY" = "1" -o "$SIMUS_CORE" = "1" ] ; then
-    cd $OPENAIR_DIR/cmake_targets/lte-simulators
+    cd $OPENAIR_DIR/cmake_targets/phy_simulators
     [ "$CLEAN" = "1" ] && rm -rf build
     mkdir -p build
     cd build
@@ -692,14 +692,14 @@ function main() {
     echo_info "Compiling unitary tests simulators"
     # TODO: fix: dlsim_tm4 pucchsim prachsim pdcchsim pbchsim mbmssim
     #simlist="dlsim_tm4 dlsim ulsim pucchsim prachsim pdcchsim pbchsim mbmssim"
-    simlist="dlsim ulsim polartest ldpctest"
+    simlist="dlsim ulsim polartest ldpctest nr_pbchsim"
     for f in $simlist ; do
       compilations \
-      lte-simulators $f \
+      phy_simulators $f \
 	  $f $dbin/$f.$REL
     done
     compilations \
-          lte-simulators coding \
+          phy_simulators coding \
           libcoding.so $dbin/libcoding.so
   fi
 
@@ -711,7 +711,7 @@ function main() {
     simlist="secu_knas_encrypt_eia1 secu_kenb aes128_ctr_encrypt aes128_ctr_decrypt secu_knas_encrypt_eea2 secu_knas secu_knas_encrypt_eea1 kdf aes128_cmac_encrypt secu_knas_encrypt_eia2"
     for f in $simlist ; do
       compilations \
-	  lte-simulators test_$f \
+	  phy_simulators test_$f \
 	  test_$f $dbin/test_$f.$REL
     done
   fi
diff --git a/cmake_targets/lte-simulators/CMakeLists.txt b/cmake_targets/phy_simulators/CMakeLists.txt
similarity index 94%
rename from cmake_targets/lte-simulators/CMakeLists.txt
rename to cmake_targets/phy_simulators/CMakeLists.txt
index b7e83a92a03282f9dfae9b54633a8ea745763cee..83b292eed5999d960026083d2874514d56020534 100644
--- a/cmake_targets/lte-simulators/CMakeLists.txt
+++ b/cmake_targets/phy_simulators/CMakeLists.txt
@@ -9,4 +9,5 @@ set(MU_RECIEVER False)
 set(NAS_UE False)
 set(MESSAGE_CHART_GENERATOR False)
 set(RRC_ASN1_VERSION "Rel14")
+set(T_TRACER False)
 include(${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists.txt)
diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h
index bc8f379f645492e83b0f530b9d06377167d06eba..db73bd7f5bc980b9f4c86d35336f0f9362e51455 100644
--- a/common/utils/LOG/log.h
+++ b/common/utils/LOG/log.h
@@ -378,17 +378,17 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
      /* define variable only used in LOG macro's */
 #    define LOG_VAR(A,B) A B
 #  else /* T_TRACER: remove all debugging and tracing messages, except errors */
-#    define LOG_I(c, x...) /* */
-#    define LOG_W(c, x...) /* */
-#    define LOG_E(c, x...) /* */
-#    define LOG_D(c, x...) /* */
+#    define LOG_I(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ; } while(0)/* */
+#    define LOG_W(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ; } while(0)/* */
+#    define LOG_E(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ; } while(0)/* */
+#    define LOG_D(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x) ; } while(0)/* */
 #    define LOG_T(c, x...) /* */
 
 #    define LOG_DUMPMSG(c, b, s, x...) /* */
 #    define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...) 
 #    define LOG_DEBUGFLAG(D)  ( 0 )
 #    define LOG_DUMPFLAG(D) ( 0 ) 
-#    define LOG_M(file, vector, data, len, dec, format) 
+#    define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)
 #    define LOG_VAR(A,B)
 #  endif /* T_TRACER */
 /* avoid warnings for variables only used in LOG macro's but set outside debug section */
diff --git a/oaienv b/oaienv
index 4dfc5f8cb59dd6ad417f97fa12007c2fe2d4a97a..d9a540697b445bba06e5686718bc0380dabcc44c 100644
--- a/oaienv
+++ b/oaienv
@@ -18,5 +18,5 @@ alias oailte='cd $OPENAIR_TARGETS/RT/USER'
 alias oais='cd $OPENAIR_TARGETS/SIMU/USER'
 alias oaiex='cd $OPENAIR_TARGETS/SIMU/EXAMPLES'
 
-export IIOD_REMOTE=192.168.1.2
+export IIOD_REMOTE=192.168.121.32
 
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c
index f1b72ae897125607d897af90fde67e043bbe2e0d..776cfbbae28116cb221fd8c84be2745fd043594f 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c
@@ -1069,9 +1069,17 @@ int8_t polar_decoder_int16(int16_t *input,
   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++) polarParams->nr_polar_A[j]=polarParams->nr_polar_B[j];  
-
-  nr_byte2bit_uint8_32_t(polarParams->nr_polar_A, polarParams->payloadBits, out);
-  
+  //for (int j = 0; j < polarParams->payloadBits; j++) polarParams->nr_polar_A[j]=polarParams->nr_polar_B[j];  
+
+  // Check the CRC
+  for (int j=0;j<polarParams->crcParityBits;j++) {
+    int crcbit=0;
+    for (int i=0;i<polarParams->payloadBits;i++)
+      crcbit = crcbit ^ (polarParams->crc_generator_matrix[i][j] & polarParams->nr_polar_B[i]);
+    if (crcbit != polarParams->nr_polar_B[polarParams->payloadBits+j]) return(-1); 
+  }
+  // pack into ceil(payloadBits/32) 32 bit words, lowest index in MSB
+  //  nr_byte2bit_uint8_32_t(polarParams->nr_polar_A, polarParams->payloadBits, out);
+  nr_byte2bit_uint8_32_t(polarParams->nr_polar_B, polarParams->payloadBits, out);
   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 b79739e98d536235829cf8e37c2ffb9653408c23..1967d3934c19d321f2f8622942a4d702ec758b3b 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c
@@ -443,7 +443,7 @@ void applyGtoright(t_nrPolar_params *pp,decoder_node_t *node) {
     }
     else 
 #endif
-      {// equvalent scalar code to above, activated only on non x86/ARM architectures
+      {// equvalent scalar code to above, activated only on non x86/ARM architectures or Nv=1,2
 	for (int i=0;i<node->Nv/2;i++) {
 	  alpha_r[i] = alpha_v[i+(node->Nv/2)] - (betal[i]*alpha_v[i]);
 	}
diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h
index 396f662289fec4df1a670c1fb19887421650a249..6d145741b2ea45d42b4722d75bfc163845c436c0 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h
@@ -361,11 +361,13 @@ static inline void nr_polar_interleaver(uint8_t *input,
 }
 
 static inline void nr_polar_deinterleaver(uint8_t *input,
-										  uint8_t *output,
-										  uint16_t *pattern,
-										  uint16_t size)
+					  uint8_t *output,
+					  uint16_t *pattern,
+					  uint16_t size)
 {
-	for (int i=0; i<size; i++) output[pattern[i]]=input[i];
+  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 99f77b9397e09ab7677e8ed49d33bd34204a77f1..fb2723f7b005e828fcd43a582229055aa152265b 100644
--- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c
+++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c
@@ -54,7 +54,7 @@ void polar_encoder(uint32_t *in,
 													   polarParams->nr_polar_crc,
 													   polarParams->payloadBits,
 													   polarParams->crcParityBits);
-		for (uint8_t i = 0; i < polarParams->crcParityBits; i++)
+		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)
diff --git a/openair1/PHY/CODING/nr_polar_init.c b/openair1/PHY/CODING/nr_polar_init.c
index e238c7b84f3c911671529dd37a73f5bd2bc7397d..72e487a738020160b2660f677580dc638d8f9e7e 100644
--- a/openair1/PHY/CODING/nr_polar_init.c
+++ b/openair1/PHY/CODING/nr_polar_init.c
@@ -185,9 +185,9 @@ void nr_polar_print_polarParams(t_nrPolar_paramsPtr polarParams)
 }
 
 t_nrPolar_paramsPtr nr_polar_params (t_nrPolar_paramsPtr polarParams,
-									 int8_t messageType,
-									 uint16_t messageLength,
-									 uint8_t aggregation_level)
+				     int8_t messageType,
+				     uint16_t messageLength,
+				     uint8_t aggregation_level)
 {
 	t_nrPolar_paramsPtr currentPtr = NULL;
 
diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index a67645eef422ee7acc1dba19cd4fff772e2b300b..6082cb757cc01f02f57dcf8f91fe98d193ae5d4f 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -92,7 +92,7 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
 
   int i, UE_id; 
 
-  LOG_I(PHY,"[gNB %d] %s() About to wait for gNB to be configured", gNB->Mod_id, __FUNCTION__);
+  LOG_I(PHY,"[gNB %d] %s() About to wait for gNB to be configured\n", gNB->Mod_id, __FUNCTION__);
 
   gNB->total_dlsch_bitrate = 0;
   gNB->total_transmitted_bits = 0;
@@ -100,6 +100,8 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
   gNB->check_for_MUMIMO_transmissions=0;
  
   while(gNB->configured == 0) usleep(10000);
+
+  init_dfts();
 /*
   LOG_I(PHY,"[gNB %"PRIu8"] Initializing DL_FRAME_PARMS : N_RB_DL %"PRIu8", PHICH Resource %d, PHICH Duration %d nb_antennas_tx:%u nb_antennas_rx:%u PRACH[rootSequenceIndex:%u prach_Config_enabled:%u configIndex:%u highSpeed:%u zeroCorrelationZoneConfig:%u freqOffset:%u]\n",
         gNB->Mod_id,
@@ -324,7 +326,7 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
     free_and_zero(srs_vars[UE_id].srs_ch_estimates_time);
   } //UE_id
 
-  free_ul_ref_sigs();
+  //free_ul_ref_sigs();
 
   for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) free_and_zero(srs_vars[UE_id].srs);
 
@@ -367,7 +369,7 @@ void install_schedule_handlers(IF_Module_t *if_inst)
 
 /// this function is a temporary addition for NR configuration
 
-/*void nr_phy_config_request(PHY_VARS_gNB *gNB)
+void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,int N_RB_DL,int N_RB_UL,int mu)
 {
   NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
   nfapi_nr_config_request_t *gNB_config = &gNB->gNB_config;
@@ -375,14 +377,14 @@ void install_schedule_handlers(IF_Module_t *if_inst)
   //overwrite for new NR parameters
   gNB_config->nfapi_config.rf_bands.rf_band[0] = 22;
   gNB_config->nfapi_config.earfcn.value = 6600;
-  gNB_config->subframe_config.numerology_index_mu.value = 1;
-  gNB_config->subframe_config.duplex_mode.value = FDD;
+  gNB_config->subframe_config.numerology_index_mu.value = mu;
+  gNB_config->subframe_config.duplex_mode.value = TDD;
   gNB_config->rf_config.tx_antenna_ports.value = 1;
-  gNB_config->rf_config.dl_carrier_bandwidth.value = 106;
-  gNB_config->rf_config.ul_carrier_bandwidth.value = 106;
+  gNB_config->rf_config.dl_carrier_bandwidth.value = N_RB_DL;
+  gNB_config->rf_config.ul_carrier_bandwidth.value = N_RB_UL;
   gNB_config->sch_config.half_frame_index.value = 0;
   gNB_config->sch_config.ssb_subcarrier_offset.value = 0;
-  gNB_config->sch_config.n_ssb_crb.value = 86;
+  gNB_config->sch_config.n_ssb_crb.value = (N_RB_DL-20)>>1;
   gNB_config->sch_config.ssb_subcarrier_offset.value = 0;
 
 
@@ -396,7 +398,7 @@ void install_schedule_handlers(IF_Module_t *if_inst)
 
   gNB->configured                                   = 1;
   LOG_I(PHY,"gNB configured\n");
-}*/
+}
 
 
 void nr_phy_config_request(NR_PHY_Config_t *phy_config)
diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c
index dfbbb25d06f065d4c420d321872c5e854a4e4dea..4286f4359ad4a682ba317a6faf24c00633ef6679 100644
--- a/openair1/PHY/INIT/nr_init_ue.c
+++ b/openair1/PHY/INIT/nr_init_ue.c
@@ -655,15 +655,16 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue,
   int i,j,k,l;
   int eNB_id;
   int th_id;
-
+  int n_ssb_crb=(fp->N_RB_DL-20)>>1;
   abstraction_flag = 0;
   fp->nb_antennas_tx = 1;
   fp->nb_antennas_rx=1;
 
+
   printf("Initializing UE vars (abstraction %"PRIu8") for eNB TXant %"PRIu8", UE RXant %"PRIu8"\n",abstraction_flag,fp->nb_antennas_tx,fp->nb_antennas_rx);
   //LOG_D(PHY,"[MSC_NEW][FRAME 00000][PHY_UE][MOD %02u][]\n", ue->Mod_id+NB_eNB_INST);
   
-  nr_init_frame_parms_ue(&ue->frame_parms);
+  nr_init_frame_parms_ue(&ue->frame_parms,NR_MU_1,NORMAL,n_ssb_crb,0);
   phy_init_nr_top(ue);
 
   // many memory allocation sizes are hard coded
@@ -699,7 +700,7 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue,
     for (i=0; i<fp->nb_antennas_tx; i++) {
 
       common_vars->txdata[i]  = (int32_t*)malloc16_clear( fp->samples_per_subframe*10*sizeof(int32_t) );
-      common_vars->txdataF[i] = (int32_t *)malloc16_clear( fp->ofdm_symbol_size*fp->symbols_per_tti*10*sizeof(int32_t) );
+      common_vars->txdataF[i] = (int32_t *)malloc16_clear( fp->ofdm_symbol_size*fp->symbols_per_slot*10*sizeof(int32_t) );
     }
 
     // init RX buffers
@@ -728,7 +729,7 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue,
       for (j=0; j<4; j++) {
         int idx = (j<<1) + i;
         for (th_id=0; th_id<RX_NB_TH_MAX; th_id++) {
-            common_vars->common_vars_rx_data_per_thread[th_id].dl_ch_estimates[eNB_id][idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->symbols_per_tti*(fp->ofdm_symbol_size+LTE_CE_FILTER_LENGTH) );
+            common_vars->common_vars_rx_data_per_thread[th_id].dl_ch_estimates[eNB_id][idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->symbols_per_slot*(fp->ofdm_symbol_size+LTE_CE_FILTER_LENGTH) );
             common_vars->common_vars_rx_data_per_thread[th_id].dl_ch_estimates_time[eNB_id][idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size*2 );
         }
       }
@@ -850,7 +851,7 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue,
       pbch_vars[eNB_id]->rxdataF_ext         = (int32_t**)malloc16( fp->nb_antennas_rx*sizeof(int32_t*) );
       pbch_vars[eNB_id]->rxdataF_comp        = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) );
       pbch_vars[eNB_id]->dl_ch_estimates_ext = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) );
-      pbch_vars[eNB_id]->llr                 = (int8_t*)malloc16_clear( 1920 );//
+      pbch_vars[eNB_id]->llr                 = (int16_t*)malloc16_clear( 1920 );//
       prach_vars[eNB_id]->prachF             = (int16_t*)malloc16_clear( sizeof(int)*(7*2*sizeof(int)*(fp->ofdm_symbol_size*12)) );
       prach_vars[eNB_id]->prach              = (int16_t*)malloc16_clear( sizeof(int)*(7*2*sizeof(int)*(fp->ofdm_symbol_size*12)) );
 
@@ -941,43 +942,25 @@ void init_nr_ue_transport(PHY_VARS_NR_UE *ue,int abstraction_flag) {
 
 void phy_init_nr_top(PHY_VARS_NR_UE *ue)
 {
-	NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
-	NR_UE_DLSCH_t *dlsch0 = ue->dlsch[0][0][0];
-	dlsch0 =(NR_UE_DLSCH_t *)malloc16(sizeof(NR_UE_DLSCH_t));
-
+  NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
+  NR_UE_DLSCH_t *dlsch0 = ue->dlsch[0][0][0];
+  dlsch0 =(NR_UE_DLSCH_t *)malloc16(sizeof(NR_UE_DLSCH_t));
+  
   crcTableInit();
 
   init_dfts();
-  
-  ccodedot11_init();
-  ccodedot11_init_inv();
-
-  ccodelte_init();
-  ccodelte_init_inv();
-
-  //treillis_table_init();
-
-  phy_generate_viterbi_tables();
-  phy_generate_viterbi_tables_lte();
-
-  //init_td8();
-  //init_td16();
-#ifdef __AVX2__
-  //init_td16avx2();
-#endif
 
   init_context_synchro_nr(frame_parms);
 
   generate_ul_reference_signal_sequences(SHRT_MAX);
 
   // Polar encoder init for PBCH
-  //nr_polar_init(&frame_parms->pbch_polar_params, 1);
-  /*t_nrPolar_paramsPtr nrPolar_params = NULL, currentPtr = NULL;
-  nr_polar_init(&ue->nrPolar_params,
-    		  	  	NR_POLAR_PBCH_MESSAGE_TYPE,
-					NR_POLAR_PBCH_PAYLOAD_BITS,
-					NR_POLAR_PBCH_AGGREGATION_LEVEL);*/
 
+  ue->nrPolar_params = NULL;
+  nr_polar_init(&ue->nrPolar_params,
+		NR_POLAR_PBCH_MESSAGE_TYPE,
+		NR_POLAR_PBCH_PAYLOAD_BITS,
+		NR_POLAR_PBCH_AGGREGATION_LEVEL);
   //lte_sync_time_init(frame_parms);
 
   //generate_ul_ref_sigs();
@@ -993,3 +976,64 @@ void phy_init_nr_top(PHY_VARS_NR_UE *ue)
   //set_taus_seed(1328);
 
 }
+
+void set_default_frame_parms_single(nfapi_nr_config_request_t *config, NR_DL_FRAME_PARMS *frame_parms) {
+
+  //int CC_id;
+
+  //for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+        /* Set some default values that may be overwritten while reading options */
+        frame_parms = (NR_DL_FRAME_PARMS*) malloc(sizeof(NR_DL_FRAME_PARMS));
+        config = (nfapi_nr_config_request_t*) malloc(sizeof(nfapi_nr_config_request_t));
+        config->subframe_config.numerology_index_mu.value =1;
+        config->subframe_config.duplex_mode.value = 1; //FDD
+        config->subframe_config.dl_cyclic_prefix_type.value = 0; //NORMAL
+        config->rf_config.dl_carrier_bandwidth.value = 106;
+        config->rf_config.ul_carrier_bandwidth.value = 106;
+        config->rf_config.tx_antenna_ports.value = 1;
+        config->rf_config.rx_antenna_ports.value = 1;
+        config->sch_config.physical_cell_id.value = 0;
+
+        frame_parms->frame_type          = FDD;
+        frame_parms->tdd_config          = 3;
+        //frame_parms[CC_id]->tdd_config_S        = 0;
+        frame_parms->N_RB_DL             = 100;
+        frame_parms->N_RB_UL             = 100;
+        frame_parms->Ncp                 = NORMAL;
+        //frame_parms[CC_id]->Ncp_UL              = NORMAL;
+        frame_parms->Nid_cell            = 0;
+        //frame_parms[CC_id]->num_MBSFN_config    = 0;
+        frame_parms->nb_antenna_ports_eNB  = 1;
+        frame_parms->nb_antennas_tx      = 1;
+        frame_parms->nb_antennas_rx      = 1;
+
+        //frame_parms[CC_id]->nushift             = 0;
+
+        ///frame_parms[CC_id]->phich_config_common.phich_resource = oneSixth;
+        //frame_parms[CC_id]->phich_config_common.phich_duration = normal;
+	
+	// UL RS Config
+        /*frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = 1;//n_DMRS1 set to 0
+        frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 1;
+        frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0;
+        frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0;
+
+	frame_parms[CC_id]->pusch_config_common.n_SB = 1;
+	frame_parms[CC_id]->pusch_config_common.hoppingMode = 0;
+	frame_parms[CC_id]->pusch_config_common.pusch_HoppingOffset = 0;
+	frame_parms[CC_id]->pusch_config_common.enable64QAM = 0;
+		
+        frame_parms[CC_id]->prach_config_common.rootSequenceIndex=22;
+        frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=1;
+        frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_ConfigIndex=0;
+        frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.highSpeedFlag=0;
+        frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_FreqOffset=0;*/
+
+        // NR: Init to legacy LTE 20Mhz params
+        frame_parms->numerology_index	= 0;
+        frame_parms->ttis_per_subframe	= 1;
+        frame_parms->slots_per_tti		= 2;
+
+    //}
+
+}
diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c
index 2083acbeda4cfe09962e0eb23516e9fdb3ed915e..d114f0ef60d4c50334f3ade34ea57e4adba25107 100644
--- a/openair1/PHY/INIT/nr_parms.c
+++ b/openair1/PHY/INIT/nr_parms.c
@@ -26,18 +26,20 @@
 uint32_t nr_subcarrier_spacing[MAX_NUM_SUBCARRIER_SPACING] = {15e3, 30e3, 60e3, 120e3, 240e3};
 uint16_t nr_slots_per_subframe[MAX_NUM_SUBCARRIER_SPACING] = {1, 2, 4, 16, 32};
 
-int nr_init_frame_parms(nfapi_nr_config_request_t* config,
-                        NR_DL_FRAME_PARMS *frame_parms)
+
+int nr_init_frame_parms0(
+			 NR_DL_FRAME_PARMS *fp,
+			 int mu,
+			 int Ncp)
+
 {
 
-  int N_RB = config->rf_config.dl_carrier_bandwidth.value;
-  int Ncp = config->subframe_config.dl_cyclic_prefix_type.value;
-  int mu = config->subframe_config.numerology_index_mu.value;
+
 
 #if DISABLE_LOG_X
-  printf("Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, N_RB, Ncp);
+  printf("Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, fp->N_RB_DL, Ncp);
 #else
-  LOG_I(PHY,"Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, N_RB, Ncp);
+  LOG_I(PHY,"Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, fp->N_RB_DL, Ncp);
 #endif
 
   if (Ncp == NFAPI_CP_EXTENDED)
@@ -46,15 +48,15 @@ int nr_init_frame_parms(nfapi_nr_config_request_t* config,
   switch(mu) {
 
     case NR_MU_0: //15kHz scs
-      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_0];
-      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_0];
+      fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_0];
+      fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_0];
       break;
 
     case NR_MU_1: //30kHz scs
-      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_1];
-      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_1];
+      fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_1];
+      fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_1];
 
-      switch(N_RB){
+      switch(fp->N_RB_DL){
         case 11:
         case 24:
         case 38:
@@ -63,17 +65,17 @@ int nr_init_frame_parms(nfapi_nr_config_request_t* config,
         case 65:
 
         case 106: //40 MHz
-          if (frame_parms->threequarter_fs) {
-            frame_parms->ofdm_symbol_size = 1536;
-            frame_parms->first_carrier_offset = 900; //1536 - 636
-            frame_parms->nb_prefix_samples0 = 132;
-            frame_parms->nb_prefix_samples = 108;
+          if (fp->threequarter_fs) {
+            fp->ofdm_symbol_size = 1536;
+            fp->first_carrier_offset = 900; //1536 - 636
+            fp->nb_prefix_samples0 = 132;
+            fp->nb_prefix_samples = 108;
           }
           else {
-            frame_parms->ofdm_symbol_size = 2048;
-            frame_parms->first_carrier_offset = 1412; //2048 - 636
-            frame_parms->nb_prefix_samples0 = 176;
-            frame_parms->nb_prefix_samples = 144;
+            fp->ofdm_symbol_size = 2048;
+            fp->first_carrier_offset = 1412; //2048 - 636
+            fp->nb_prefix_samples0 = 176;
+            fp->nb_prefix_samples = 144;
           }
           break;
 
@@ -82,32 +84,44 @@ int nr_init_frame_parms(nfapi_nr_config_request_t* config,
         case 189:
 
         case 217: //80 MHz
-          if (frame_parms->threequarter_fs) {
-            frame_parms->ofdm_symbol_size = 3072;
-            frame_parms->first_carrier_offset = 1770; //3072 - 1302
-            frame_parms->nb_prefix_samples0 = 264;
-            frame_parms->nb_prefix_samples = 216;
-          }
-          else {
-            frame_parms->ofdm_symbol_size = 4096;
-            frame_parms->first_carrier_offset = 2794; //4096 - 1302
-            frame_parms->nb_prefix_samples0 = 352;
-            frame_parms->nb_prefix_samples = 288;
+          if (fp->threequarter_fs) {
+            fp->ofdm_symbol_size = 3072;
+            fp->first_carrier_offset = 1770; //3072 - 1302
+            fp->nb_prefix_samples0 = 264;
+            fp->nb_prefix_samples = 216;
           }
+	  else {
+	    fp->ofdm_symbol_size = 4096;
+	    fp->first_carrier_offset = 2794; //4096 - 1302
+	    fp->nb_prefix_samples0 = 352;
+	    fp->nb_prefix_samples = 288;
+	  }
           break;
 
         case 245:
+	  AssertFatal(fp->threequarter_fs==0,"3/4 sampling impossible for N_RB %d and MU %d\n",fp->N_RB_DL,mu); 
+	  fp->ofdm_symbol_size = 4096;
+	  fp->first_carrier_offset = 2626; //4096 - 1478
+	  fp->nb_prefix_samples0 = 352;
+	  fp->nb_prefix_samples = 288;
+	  break;
         case 273:
+	  AssertFatal(fp->threequarter_fs==0,"3/4 sampling impossible for N_RB %d and MU %d\n",fp->N_RB_DL,mu); 
+	  fp->ofdm_symbol_size = 4096;
+	  fp->first_carrier_offset = 2458; //4096 - 1638
+	  fp->nb_prefix_samples0 = 352;
+	  fp->nb_prefix_samples = 288;
+	  break;
       default:
-        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", N_RB, mu, frame_parms);
+        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", fp->N_RB_DL, mu, fp);
       }
       break;
 
     case NR_MU_2: //60kHz scs
-      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_2];
-      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_2];
+      fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_2];
+      fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_2];
 
-      switch(N_RB){ //FR1 bands only
+      switch(fp->N_RB_DL){ //FR1 bands only
         case 11:
         case 18:
         case 38:
@@ -121,196 +135,80 @@ int nr_init_frame_parms(nfapi_nr_config_request_t* config,
         case 121:
         case 135:
       default:
-        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", N_RB, mu, frame_parms);
+        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", fp->N_RB_DL, mu, fp);
       }
       break;
 
     case NR_MU_3:
-      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_3];
-      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_3];
+      fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_3];
+      fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_3];
       break;
 
     case NR_MU_4:
-      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_4];
-      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_4];
+      fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_4];
+      fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_4];
       break;
 
   default:
     AssertFatal(1==0,"Invalid numerology index %d", mu);
   }
 
-  frame_parms->slots_per_frame = 10* frame_parms->slots_per_subframe;
-  frame_parms->symbols_per_slot = ((Ncp == NORMAL)? 14 : 12); // to redefine for different slot formats
-  frame_parms->samples_per_subframe_wCP = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_slot * frame_parms->slots_per_subframe;
-  frame_parms->samples_per_frame_wCP = 10 * frame_parms->samples_per_subframe_wCP;
-  frame_parms->samples_per_subframe = (frame_parms->samples_per_subframe_wCP + (frame_parms->nb_prefix_samples0 * frame_parms->slots_per_subframe) +
-                                      (frame_parms->nb_prefix_samples * frame_parms->slots_per_subframe * (frame_parms->symbols_per_slot - 1)));
-  frame_parms->samples_per_frame = 10 * frame_parms->samples_per_subframe;
-  frame_parms->freq_range = (frame_parms->dl_CarrierFreq < 6e9)? nr_FR1 : nr_FR2;
+  fp->slots_per_frame = 10* fp->slots_per_subframe;
+  fp->symbols_per_slot = ((Ncp == NORMAL)? 14 : 12); // to redefine for different slot formats
+  fp->samples_per_subframe_wCP = fp->ofdm_symbol_size * fp->symbols_per_slot * fp->slots_per_subframe;
+  fp->samples_per_frame_wCP = 10 * fp->samples_per_subframe_wCP;
+  fp->samples_per_subframe = (fp->samples_per_subframe_wCP + (fp->nb_prefix_samples0 * fp->slots_per_subframe) +
+                                      (fp->nb_prefix_samples * fp->slots_per_subframe * (fp->symbols_per_slot - 1)));
+  fp->samples_per_frame = 10 * fp->samples_per_subframe;
+  fp->freq_range = (fp->dl_CarrierFreq < 6e9)? nr_FR1 : nr_FR2;
 
   // Initial bandwidth part configuration -- full carrier bandwidth
-  frame_parms->initial_bwp_dl.bwp_id = 0;
-  frame_parms->initial_bwp_dl.scs = frame_parms->subcarrier_spacing;
-  frame_parms->initial_bwp_dl.location = 0;
-  frame_parms->initial_bwp_dl.N_RB = N_RB;
-  frame_parms->initial_bwp_dl.cyclic_prefix = Ncp;
-  frame_parms->initial_bwp_dl.ofdm_symbol_size = frame_parms->ofdm_symbol_size;
+  fp->initial_bwp_dl.bwp_id = 0;
+  fp->initial_bwp_dl.scs = fp->subcarrier_spacing;
+  fp->initial_bwp_dl.location = 0;
+  fp->initial_bwp_dl.N_RB = fp->N_RB_DL;
+  fp->initial_bwp_dl.cyclic_prefix = Ncp;
+  fp->initial_bwp_dl.ofdm_symbol_size = fp->ofdm_symbol_size;
 
   return 0;
 }
 
-int nr_init_frame_parms_ue(NR_DL_FRAME_PARMS *frame_parms)
-{
-
-  int N_RB = 106;
-  int Ncp = 0;
-  int mu = 1;
-
-#if DISABLE_LOG_X
-  printf("Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, N_RB, Ncp);
-#else
-  LOG_I(PHY,"Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, N_RB, Ncp);
-#endif
-
-
-  if (Ncp == EXTENDED)
-    AssertFatal(mu == NR_MU_2,"Invalid cyclic prefix %d for numerology index %d\n", Ncp, mu);
-
-  switch(mu) {
-
-    case NR_MU_0: //15kHz scs
-      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_0];
-      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_0];
-      break;
-
-    case NR_MU_1: //30kHz scs
-      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_1];
-      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_1];
-
-      switch(N_RB){
-        case 11:
-        case 24:
-        case 38:
-        case 78:
-        case 51:
-        case 65:
-
-        case 106: //40 MHz
-          if (frame_parms->threequarter_fs) {
-            frame_parms->ofdm_symbol_size = 1536;
-            frame_parms->first_carrier_offset = 900; //1536 - 636
-            frame_parms->nb_prefix_samples0 = 132;
-            frame_parms->nb_prefix_samples = 108;
-          }
-          else {
-            frame_parms->ofdm_symbol_size = 2048;
-            frame_parms->first_carrier_offset = 1412; //2048 - 636
-            frame_parms->nb_prefix_samples0 = 176;
-            frame_parms->nb_prefix_samples = 144;
-          }
-          break;
-
-        case 133:
-        case 162:
-        case 189:
-
-        case 217: //80 MHz
-          if (frame_parms->threequarter_fs) {
-            frame_parms->ofdm_symbol_size = 3072;
-            frame_parms->first_carrier_offset = 1770; //3072 - 1302
-            frame_parms->nb_prefix_samples0 = 264;
-            frame_parms->nb_prefix_samples = 216;
-          }
-          else {
-            frame_parms->ofdm_symbol_size = 4096;
-            frame_parms->first_carrier_offset = 2794; //4096 - 1302
-            frame_parms->nb_prefix_samples0 = 352;
-            frame_parms->nb_prefix_samples = 288;
-          }
-          break;
-
-        case 245:
-        case 273:
-      default:
-        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", N_RB, mu, frame_parms);
-      }
-      break;
-
-    case NR_MU_2: //60kHz scs
-      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_2];
-      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_2];
-
-      switch(N_RB){ //FR1 bands only
-        case 11:
-        case 18:
-        case 38:
-        case 24:
-        case 31:
-        case 51:
-        case 65:
-        case 79:
-        case 93:
-        case 107:
-        case 121:
-        case 135:
-      default:
-        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", N_RB, mu, frame_parms);
-      }
-      break;
-
-    case NR_MU_3:
-      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_3];
-      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_3];
-      break;
-
-    case NR_MU_4:
-      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_4];
-      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_4];
-      break;
-
-  default:
-    AssertFatal(1==0,"Invalid numerology index %d", mu);
-  }
-
-    frame_parms->nb_prefix_samples0 = 160;
-    frame_parms->nb_prefix_samples = 144;
-    frame_parms->symbols_per_tti = 14;
-    frame_parms->numerology_index = 0;
-    frame_parms->ttis_per_subframe = 1;
-    frame_parms->slots_per_tti = 2; //only slot config 1 is supported     
+int nr_init_frame_parms(nfapi_nr_config_request_t* config,
+                        NR_DL_FRAME_PARMS *fp) {
 
-    frame_parms->ofdm_symbol_size = 2048;
-    frame_parms->samples_per_tti = 30720;
-    frame_parms->samples_per_subframe = 30720 * frame_parms->ttis_per_subframe;
-    //frame_parms->first_carrier_offset = 2048-600;
+  nr_init_frame_parms0(fp,
+		       config->subframe_config.numerology_index_mu.value,
+		       config->subframe_config.dl_cyclic_prefix_type.value);
+}
 
-  frame_parms->slots_per_frame = 10* frame_parms->slots_per_subframe;
-  frame_parms->symbols_per_slot = ((Ncp == NORMAL)? 14 : 12); // to redefine for different slot formats
-  frame_parms->samples_per_subframe_wCP = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_slot * frame_parms->slots_per_subframe;
-  frame_parms->samples_per_frame_wCP = 10 * frame_parms->samples_per_subframe_wCP;
-  //frame_parms->samples_per_subframe = (frame_parms->samples_per_subframe_wCP + (frame_parms->nb_prefix_samples0 * frame_parms->slots_per_subframe) +
-  //                                    (frame_parms->nb_prefix_samples * frame_parms->slots_per_subframe * (frame_parms->symbols_per_slot - 1)));
-  frame_parms->samples_per_frame = 10 * frame_parms->samples_per_subframe;
-  frame_parms->freq_range = (frame_parms->dl_CarrierFreq < 6e9)? nr_FR1 : nr_FR2;
+int nr_init_frame_parms_ue(NR_DL_FRAME_PARMS *fp,
+			   int mu, 
+			   int Ncp,
+			   int n_ssb_crb,
+			   int ssb_subcarrier_offset) 
+{
 
+  nr_init_frame_parms0(fp,mu,Ncp);
+  int start_rb = n_ssb_crb / (1<<mu);
+  fp->ssb_start_subcarrier = 12 * start_rb + ssb_subcarrier_offset;
   return 0;
 }
 
-void nr_dump_frame_parms(NR_DL_FRAME_PARMS *frame_parms)
+void nr_dump_frame_parms(NR_DL_FRAME_PARMS *fp)
 {
-  LOG_I(PHY,"frame_parms->scs=%d\n",frame_parms->subcarrier_spacing);
-  LOG_I(PHY,"frame_parms->ofdm_symbol_size=%d\n",frame_parms->ofdm_symbol_size);
-  LOG_I(PHY,"frame_parms->nb_prefix_samples0=%d\n",frame_parms->nb_prefix_samples0);
-  LOG_I(PHY,"frame_parms->nb_prefix_samples=%d\n",frame_parms->nb_prefix_samples);
-  LOG_I(PHY,"frame_parms->slots_per_subframe=%d\n",frame_parms->slots_per_subframe);
-  LOG_I(PHY,"frame_parms->samples_per_subframe_wCP=%d\n",frame_parms->samples_per_subframe_wCP);
-  LOG_I(PHY,"frame_parms->samples_per_frame_wCP=%d\n",frame_parms->samples_per_frame_wCP);
-  LOG_I(PHY,"frame_parms->samples_per_subframe=%d\n",frame_parms->samples_per_subframe);
-  LOG_I(PHY,"frame_parms->samples_per_frame=%d\n",frame_parms->samples_per_frame);
-  LOG_I(PHY,"frame_parms->initial_bwp_dl.bwp_id=%d\n",frame_parms->initial_bwp_dl.bwp_id);
-  LOG_I(PHY,"frame_parms->initial_bwp_dl.scs=%d\n",frame_parms->initial_bwp_dl.scs);
-  LOG_I(PHY,"frame_parms->initial_bwp_dl.N_RB=%d\n",frame_parms->initial_bwp_dl.N_RB);
-  LOG_I(PHY,"frame_parms->initial_bwp_dl.cyclic_prefix=%d\n",frame_parms->initial_bwp_dl.cyclic_prefix);
-  LOG_I(PHY,"frame_parms->initial_bwp_dl.location=%d\n",frame_parms->initial_bwp_dl.location);
-  LOG_I(PHY,"frame_parms->initial_bwp_dl.ofdm_symbol_size=%d\n",frame_parms->initial_bwp_dl.ofdm_symbol_size);
+  LOG_I(PHY,"fp->scs=%d\n",fp->subcarrier_spacing);
+  LOG_I(PHY,"fp->ofdm_symbol_size=%d\n",fp->ofdm_symbol_size);
+  LOG_I(PHY,"fp->nb_prefix_samples0=%d\n",fp->nb_prefix_samples0);
+  LOG_I(PHY,"fp->nb_prefix_samples=%d\n",fp->nb_prefix_samples);
+  LOG_I(PHY,"fp->slots_per_subframe=%d\n",fp->slots_per_subframe);
+  LOG_I(PHY,"fp->samples_per_subframe_wCP=%d\n",fp->samples_per_subframe_wCP);
+  LOG_I(PHY,"fp->samples_per_frame_wCP=%d\n",fp->samples_per_frame_wCP);
+  LOG_I(PHY,"fp->samples_per_subframe=%d\n",fp->samples_per_subframe);
+  LOG_I(PHY,"fp->samples_per_frame=%d\n",fp->samples_per_frame);
+  LOG_I(PHY,"fp->initial_bwp_dl.bwp_id=%d\n",fp->initial_bwp_dl.bwp_id);
+  LOG_I(PHY,"fp->initial_bwp_dl.scs=%d\n",fp->initial_bwp_dl.scs);
+  LOG_I(PHY,"fp->initial_bwp_dl.N_RB=%d\n",fp->initial_bwp_dl.N_RB);
+  LOG_I(PHY,"fp->initial_bwp_dl.cyclic_prefix=%d\n",fp->initial_bwp_dl.cyclic_prefix);
+  LOG_I(PHY,"fp->initial_bwp_dl.location=%d\n",fp->initial_bwp_dl.location);
+  LOG_I(PHY,"fp->initial_bwp_dl.ofdm_symbol_size=%d\n",fp->initial_bwp_dl.ofdm_symbol_size);
 }
diff --git a/openair1/PHY/INIT/phy_init.h b/openair1/PHY/INIT/phy_init.h
index 84a2925a827a4ad69ae4412faddf3adb100543d0..1631e091883e69f6c9d4f914476b5fe7235b2767 100644
--- a/openair1/PHY/INIT/phy_init.h
+++ b/openair1/PHY/INIT/phy_init.h
@@ -377,11 +377,12 @@ void phy_config_request(PHY_Config_t *phy_config);
 int init_frame_parms(LTE_DL_FRAME_PARMS *frame_parms,uint8_t osf);
 void dump_frame_parms(LTE_DL_FRAME_PARMS *frame_parms);
 int nr_init_frame_parms(nfapi_nr_config_request_t* config, NR_DL_FRAME_PARMS *frame_parms);
-int nr_init_frame_parms_ue(NR_DL_FRAME_PARMS *frame_parms);
+int nr_init_frame_parms_ue(NR_DL_FRAME_PARMS *frame_parms,int mu,int Ncp,int n_ssb_crb,int ssb_subcarrier_offset);
 int init_nr_ue_signal(PHY_VARS_NR_UE *ue,int nb_connected_eNB,uint8_t abstraction_flag);
 void nr_dump_frame_parms(NR_DL_FRAME_PARMS *frame_parms);
 int phy_init_nr_gNB(PHY_VARS_gNB *gNB, unsigned char is_secondary_gNB, unsigned char abstraction_flag);
 void nr_phy_config_request(NR_PHY_Config_t *gNB);
+void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,int N_RB_DL,int N_RB_UL,int mu);
 void phy_free_nr_gNB(PHY_VARS_gNB *gNB);
 int l1_north_init_gNB(void);
 
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/initial_sync.c b/openair1/PHY/LTE_UE_TRANSPORT/initial_sync.c
index 2fa57d0e14932a197799663d1fbb288740ae5698..594a10da9539cc7ce68f248ff2f3961c6d88895d 100644
--- a/openair1/PHY/LTE_UE_TRANSPORT/initial_sync.c
+++ b/openair1/PHY/LTE_UE_TRANSPORT/initial_sync.c
@@ -285,6 +285,7 @@ int initial_sync(PHY_VARS_UE *ue, runmode_t mode)
   init_frame_parms(frame_parms,1);
   /*
   LOG_M("rxdata0.m","rxd0",ue->common_vars.rxdata[0],10*frame_parms->samples_per_tti,1,1);
+
   exit(-1);
   */
   sync_pos = lte_sync_time(ue->common_vars.rxdata,
diff --git a/openair1/PHY/MODULATION/modulation_common.h b/openair1/PHY/MODULATION/modulation_common.h
index 2ac0dc23b3012b5bc76aa8ad7acbdf9f4fedd318..f550eeca5f6c7f9b483e13c5a44b33eb41f1abd5 100644
--- a/openair1/PHY/MODULATION/modulation_common.h
+++ b/openair1/PHY/MODULATION/modulation_common.h
@@ -22,6 +22,7 @@
 #ifndef __MODULATION_COMMON__H__
 #define __MODULATION_COMMON__H__
 #include "PHY/defs_common.h"
+#include "PHY/defs_nr_common.h"
 /** @addtogroup _PHY_MODULATION_
  * @{
 */
@@ -48,6 +49,7 @@ void PHY_ofdm_mod(int *input,
 
 
 void normal_prefix_mod(int32_t *txdataF,int32_t *txdata,uint8_t nsymb,LTE_DL_FRAME_PARMS *frame_parms);
+void nr_normal_prefix_mod(int32_t *txdataF,int32_t *txdata,uint8_t nsymb,NR_DL_FRAME_PARMS *frame_parms);
 
 void do_OFDM_mod(int32_t **txdataF, int32_t **txdata, uint32_t frame,uint16_t next_slot, LTE_DL_FRAME_PARMS *frame_parms);
 
diff --git a/openair1/PHY/MODULATION/ofdm_mod.c b/openair1/PHY/MODULATION/ofdm_mod.c
index f8b058935c1a52c108bbee68100e3f4f2208aebb..b23fd2e2bfb8c9e53c12f43dba024e8756497e61 100644
--- a/openair1/PHY/MODULATION/ofdm_mod.c
+++ b/openair1/PHY/MODULATION/ofdm_mod.c
@@ -122,10 +122,10 @@ void PHY_ofdm_mod(int *input,                       /// pointer to complex input
 
   case 3072:
     idft = idft3072;
-
+    break;
   case 4096:
     idft = idft4096;
-
+    break;
   default:
     idft = idft512;
     break;
diff --git a/openair1/PHY/MODULATION/slot_fep_nr.c b/openair1/PHY/MODULATION/slot_fep_nr.c
index c3e49a42df14263bd3abc0b8020fe40b42d14bf3..f1f2a94b93d0e1f344ec276346eee717afeb4be1 100644
--- a/openair1/PHY/MODULATION/slot_fep_nr.c
+++ b/openair1/PHY/MODULATION/slot_fep_nr.c
@@ -30,12 +30,12 @@
 #define SOFFSET 0
 
 int nr_slot_fep(PHY_VARS_NR_UE *ue,
-             unsigned char l,
-             unsigned char Ns,
-             int sample_offset,
-             int no_prefix,
-			 int reset_freq_est,
-			 NR_CHANNEL_EST_t channel)
+		unsigned char l,
+		unsigned char Ns,
+		int sample_offset,
+		int no_prefix,
+		int reset_freq_est,
+		NR_CHANNEL_EST_t channel)
 {
   NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
   NR_UE_COMMON *common_vars   = &ue->common_vars;
@@ -61,7 +61,7 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue,
   int uespec_pilot[9][1200];*/
 
   void (*dft)(int16_t *,int16_t *, int);
-  int tmp_dft_in[2048] __attribute__ ((aligned (32)));  // This is for misalignment issues for 6 and 15 PRBs
+  int tmp_dft_in[8192] __attribute__ ((aligned (32)));  // This is for misalignment issues for 6 and 15 PRBs
 
   switch (frame_parms->ofdm_symbol_size) {
   case 128:
@@ -88,6 +88,14 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue,
     dft = dft2048;
     break;
 
+  case 4096:
+    dft = dft4096;
+    break;
+
+  case 8192:
+    dft = dft8192;
+    break;
+
   default:
     dft = dft512;
     break;
@@ -143,7 +151,6 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue,
 #if UE_TIMING_TRACE
         stop_meas(&ue->rx_dft_stats);
 #endif
-
       }
     } else {
       rx_offset += (frame_parms->ofdm_symbol_size+nb_prefix_samples)*l;// +
@@ -191,20 +198,17 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue,
 
   switch(channel){
   case NR_PBCH_EST:
-    //if ((l>4) && (l<8)) {
-      for (aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
 
-//#ifdef DEBUG_FEP
-        printf("Channel estimation eNB %d, aatx %d, slot %d, symbol %d\n",eNB_id,aa,Ns,l);
-//#endif
+#ifdef DEBUG_FEP
+    printf("Channel estimation eNB %d, slot %d, symbol %d\n",eNB_id,Ns,l);
+#endif
 #if UE_TIMING_TRACE
-        start_meas(&ue->dlsch_channel_estimation_stats);
+    start_meas(&ue->dlsch_channel_estimation_stats);
 #endif
-        nr_pbch_channel_estimation(ue,eNB_id,0,
-                                  Ns,
-                                  aa,
-                                  l,
-                                  symbol);
+    nr_pbch_channel_estimation(ue,eNB_id,0,
+			       Ns,
+			       l,
+			       symbol);
       //}
 #if UE_TIMING_TRACE
         stop_meas(&ue->dlsch_channel_estimation_stats);
@@ -232,53 +236,48 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue,
 #endif
 
       }
-    }
+
   break;
 
   case NR_PDCCH_EST:
-      for (aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
 
 #ifdef DEBUG_FEP
-          printf("PDCCH Channel estimation eNB %d, aatx %d, slot %d, symbol %d start_sc %d\n",eNB_id,aa,Ns,l,coreset_start_subcarrier);
+    printf("PDCCH Channel estimation eNB %d, aatx %d, slot %d, symbol %d start_sc %d\n",eNB_id,aa,Ns,l,coreset_start_subcarrier);
 #endif
 #if UE_TIMING_TRACE
-          start_meas(&ue->dlsch_channel_estimation_stats);
+    start_meas(&ue->dlsch_channel_estimation_stats);
 #endif
-          nr_pdcch_channel_estimation(ue,eNB_id,0,
-                                    Ns,
-                                    aa,
-                                    l,
-                                    symbol,
-									coreset_start_subcarrier,
-									nb_rb_coreset);
+    nr_pdcch_channel_estimation(ue,eNB_id,0,
+				Ns,
+				l,
+				symbol,
+				coreset_start_subcarrier,
+				nb_rb_coreset);
 #if UE_TIMING_TRACE
-        stop_meas(&ue->dlsch_channel_estimation_stats);
+    stop_meas(&ue->dlsch_channel_estimation_stats);
 #endif
-      }
+    
     break;
-
+    
   case NR_PDSCH_EST:
-      for (aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
-
 #ifdef DEBUG_FEP
-          printf("Channel estimation eNB %d, aatx %d, slot %d, symbol %d\n",eNB_id,aa,Ns,l);
+    printf("Channel estimation eNB %d, aatx %d, slot %d, symbol %d\n",eNB_id,aa,Ns,l);
 #endif
 #if UE_TIMING_TRACE
-          start_meas(&ue->dlsch_channel_estimation_stats);
+    start_meas(&ue->dlsch_channel_estimation_stats);
 #endif
-          nr_pdsch_channel_estimation(ue,eNB_id,0,
-                                    Ns,
-                                    aa,
-                                    l,
-                                    symbol,
-									bwp_start_subcarrier,
-									nb_rb_pdsch);
+    nr_pdsch_channel_estimation(ue,eNB_id,0,
+				Ns,
+				l,
+				symbol,
+				bwp_start_subcarrier,
+				nb_rb_pdsch);
 #if UE_TIMING_TRACE
-        stop_meas(&ue->dlsch_channel_estimation_stats);
+    stop_meas(&ue->dlsch_channel_estimation_stats);
 #endif
-      }
+    
     break;
-
+    
   case NR_SSS_EST:
   break;
 
diff --git a/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c b/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c
index f3c5da0fd5264d68d99efbf4b60aeb0f256ee1ce..7472501316b418eb18d823d317267af916e66d1f 100644
--- a/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c
+++ b/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c
@@ -41,7 +41,7 @@
 
 #include "refsig_defs_ue.h"
 #include "PHY/defs_nr_UE.h"
-#include "nr_mod_table.h"
+//#include "nr_mod_table.h"
 #include "common/utils/LOG/log.h"
 
 /*Table 7.4.1.1.2-1/2 from 38.211 */
@@ -106,13 +106,13 @@ short nr_rx_mod_table[NR_MOD_TABLE_SIZE_SHORT] = {0,0,23170,-23170,-23170,23170,
 }*/
 
 int nr_pdsch_dmrs_rx(PHY_VARS_NR_UE *ue,
-						uint8_t eNB_offset,
-						unsigned int Ns,
-						unsigned int nr_gold_pdsch[2][20][2][21],
-						int32_t *output,
-						unsigned short p,
-						int length_dmrs,
-						unsigned short nb_rb_pdsch)
+		     uint8_t eNB_offset,
+		     unsigned int Ns,
+		     unsigned int nr_gold_pdsch[2][20][2][21],
+		     int32_t *output,
+		     unsigned short p,
+		     int length_dmrs,
+		     unsigned short nb_rb_pdsch)
 {
   int32_t qpsk[4],nqpsk[4],*qpsk_p, n;
   //int w,mprime,ind,l,ind_dword,ind_qpsk_symb,kp,lp, config_type, k;
@@ -216,26 +216,38 @@ int nr_pdcch_dmrs_rx(PHY_VARS_NR_UE *ue,
 	return(0);
 }
 
-int nr_pbch_dmrs_rx(unsigned int *nr_gold_pbch,
-					int32_t *output	)
+int nr_pbch_dmrs_rx(int symbol,unsigned int *nr_gold_pbch,int32_t *output	)
 {
-    int m;
-    uint8_t idx=0;
-
-    /// QPSK modulation
-    for (m=0; m<NR_PBCH_DMRS_LENGTH>>1; m++) {
-      idx = ((((nr_gold_pbch[(m<<1)>>5])>>((m<<1)&0x1f))&1)<<1) ^ (((nr_gold_pbch[((m<<1)+1)>>5])>>(((m<<1)+1)&0x1f))&1);
-      ((int16_t*)output)[m<<1] = nr_rx_mod_table[(NR_MOD_TABLE_QPSK_OFFSET + idx)<<1];
-      ((int16_t*)output)[(m<<1)+1] = nr_rx_mod_table[((NR_MOD_TABLE_QPSK_OFFSET + idx)<<1) + 1];
-
+  int m,m0,m1;
+  uint8_t idx=0;
+  AssertFatal(symbol>=0 && symbol <3,"illegal symbol %d\n",symbol);
+  if (symbol == 0) {
+    m0=0;
+    m1=60;
+  }
+  else if (symbol == 1) {
+    m0=60;
+    m1=84;
+  }
+  else {
+    m0=84;
+    m1=144;
+  }
+  //    printf("Generating pilots symbol %d, m0 %d, m1 %d\n",symbol,m0,m1);
+  /// QPSK modulation
+  for (m=m0; m<m1; m++) {
+    idx = ((((nr_gold_pbch[(m<<1)>>5])>>((m<<1)&0x1f))&1)<<1) ^ (((nr_gold_pbch[((m<<1)+1)>>5])>>(((m<<1)+1)&0x1f))&1);
+    ((int16_t*)output)[(m-m0)<<1] = nr_rx_mod_table[(NR_MOD_TABLE_QPSK_OFFSET + idx)<<1];
+    ((int16_t*)output)[((m-m0)<<1)+1] = nr_rx_mod_table[((NR_MOD_TABLE_QPSK_OFFSET + idx)<<1) + 1];
+    
 #ifdef DEBUG_PBCH
-       if (m<16)
-        {printf("nr_gold_pbch[(m<<1)>>5] %x\n",nr_gold_pbch[(m<<1)>>5]);
+    if (m<16)
+      {printf("nr_gold_pbch[(m<<1)>>5] %x\n",nr_gold_pbch[(m<<1)>>5]);
 	printf("m %d  output %d %d addr %p\n", m, ((int16_t*)output)[m<<1], ((int16_t*)output)[(m<<1)+1],&output[0]);
-	}
+      }
 #endif
-    }
-
+  }
+  
   return(0);
 }
 
diff --git a/openair1/PHY/NR_REFSIG/pss_nr.h b/openair1/PHY/NR_REFSIG/pss_nr.h
index 2d7d11cb704019c9b6c6236baed53a264dcc4972..2f39f26ee475d2fcc1f2032d065bd438fa721be6 100644
--- a/openair1/PHY/NR_REFSIG/pss_nr.h
+++ b/openair1/PHY/NR_REFSIG/pss_nr.h
@@ -63,7 +63,7 @@
 
 /* PSS configuration */
 
-#define SYNCHRO_FFT_SIZE_MAX           (2048)                       /* maximum size of fft for synchronisation */
+#define SYNCHRO_FFT_SIZE_MAX           (8192)                       /* maximum size of fft for synchronisation */
 
 #define  NO_RATE_CHANGE                (1)
 
@@ -102,13 +102,18 @@ EXTERN int16_t *primary_synchro_nr[NUMBER_PSS_SEQUENCE]
 = { NULL, NULL, NULL}
 #endif
 ;
+EXTERN int16_t *primary_synchro_nr2[NUMBER_PSS_SEQUENCE]
+#ifdef INIT_VARIABLES_PSS_NR_H
+= { NULL, NULL, NULL}
+#endif
+;
 EXTERN int16_t *primary_synchro_time_nr[NUMBER_PSS_SEQUENCE]
 #ifdef INIT_VARIABLES_PSS_NR_H
 = { NULL, NULL, NULL}
 #endif
 ;
 
-EXTERN int *pss_corr_ue[NUMBER_PSS_SEQUENCE]
+EXTERN int64_t *pss_corr_ue[NUMBER_PSS_SEQUENCE]
 #ifdef INIT_VARIABLES_PSS_NR_H
 = { NULL, NULL, NULL}
 #endif
diff --git a/openair1/PHY/NR_REFSIG/refsig_defs_ue.h b/openair1/PHY/NR_REFSIG/refsig_defs_ue.h
index 0da7bb154ff58885da4fc2d34f468f3bd63732b3..a4cb2be7b8f90faa5712fb44e495d9d98f7ad360 100644
--- a/openair1/PHY/NR_REFSIG/refsig_defs_ue.h
+++ b/openair1/PHY/NR_REFSIG/refsig_defs_ue.h
@@ -29,7 +29,7 @@
 /*!\brief This function generates the NR Gold sequence (38-211, Sec 5.2.1) for the PBCH DMRS.
 @param PHY_VARS_NR_UE* ue structure provides configuration, frame parameters and the pointers to the 32 bits sequence storage tables
  */
-int nr_pbch_dmrs_rx(unsigned int *nr_gold_pbch,	int32_t *output	);
+int nr_pbch_dmrs_rx(int dmrss,unsigned int *nr_gold_pbch,	int32_t *output	);
 
 /*!\brief This function generates the NR Gold sequence (38-211, Sec 5.2.1) for the PDCCH DMRS.
 @param PHY_VARS_NR_UE* ue structure provides configuration, frame parameters and the pointers to the 32 bits sequence storage tables
diff --git a/openair1/PHY/NR_REFSIG/sss_nr.h b/openair1/PHY/NR_REFSIG/sss_nr.h
index 64200deb314492b6b3dad6d470e3a547fd3b0e1c..c260abd071624263c7cefd542284e82da07a6b8d 100644
--- a/openair1/PHY/NR_REFSIG/sss_nr.h
+++ b/openair1/PHY/NR_REFSIG/sss_nr.h
@@ -51,7 +51,7 @@
 #define  NUMBER_SSS_SEQUENCE          (336)
 #define  INVALID_SSS_SEQUENCE         (NUMBER_SSS_SEQUENCE)
 #define  LENGTH_SSS_NR                (127)
-#define  SCALING_METRIC_SSS_NR        (19)
+#define  SCALING_METRIC_SSS_NR        (15)//(19)
 
 #define  N_ID_2_NUMBER                (NUMBER_PSS_SEQUENCE)
 #define  N_ID_1_NUMBER                (NUMBER_SSS_SEQUENCE)
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dci.c b/openair1/PHY/NR_TRANSPORT/nr_dci.c
index ed2cb5950d16c97212b3c3747de37474a92ba7e6..0224d821dcdae8798312ab2da5b22ea81bbf9012 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dci.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dci.c
@@ -133,7 +133,7 @@ uint16_t nr_get_dci_size(nfapi_nr_dci_format_e format,
 }
 
 void nr_pdcch_scrambling(uint32_t *in,
-                         uint8_t size,
+                         uint16_t size,
                          uint32_t Nid,
                          uint32_t n_RNTI,
                          uint32_t* out) {
@@ -148,8 +148,12 @@ void nr_pdcch_scrambling(uint32_t *in,
     if ((i&0x1f)==0) {
       s = lte_gold_generic(&x1, &x2, reset);
       reset = 0;
+      if (i){
+      in++;
+      out++;
+	}
     }
-    *out ^= (((*in)>>i)&1) ^ ((s>>i)&1);
+    (*out) ^= ((((*in)>>(i&0x1f))&1) ^ ((s>>(i&0x1f))&1))<<(i&0x1f);
   }
 
 }
@@ -217,9 +221,13 @@ uint8_t nr_generate_dci_top(NR_gNB_PDCCH pdcch_vars,
   nr_polar_init(nrPolar_params, NR_POLAR_DCI_MESSAGE_TYPE, dci_alloc.size, dci_alloc.L);
   t_nrPolar_paramsPtr currentPtr = nr_polar_params(*nrPolar_params, NR_POLAR_DCI_MESSAGE_TYPE, dci_alloc.size, dci_alloc.L);
 #endif
-  polar_encoder_dci(dci_alloc.dci_pdu, encoder_output, currentPtr, pdcch_params.rnti);
+
+polar_encoder_dci(dci_alloc.dci_pdu, encoder_output, currentPtr, pdcch_params.rnti);
 
 #ifdef DEBUG_CHANNEL_CODING
+  printf("polar rnti %d\n",pdcch_params.rnti);
+  for (int i=0;i<54;i++) printf("Encoded Payload: [%d]->0x%08x \n", i,encoder_output[i]);
+
   printf("DCI PDU: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n",
     		  dci_alloc.dci_pdu[0], dci_alloc.dci_pdu[1], dci_alloc.dci_pdu[2], dci_alloc.dci_pdu[3]);
   printf("Encoded Payload: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n",
@@ -227,8 +235,14 @@ uint8_t nr_generate_dci_top(NR_gNB_PDCCH pdcch_vars,
 #endif
 
   /// Scrambling
-  uint32_t scrambled_output[NR_MAX_DCI_SIZE_DWORD];
+  uint32_t scrambled_output[NR_MAX_DCI_SIZE_DWORD]={0};
   nr_pdcch_scrambling(encoder_output, encoded_length, Nid, n_RNTI, scrambled_output);
+#ifdef DEBUG_CHANNEL_CODING
+printf("scrambled output: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\t [4]->0x%08x\t [5]->0x%08x\t \
+[6]->0x%08x \t [7]->0x%08x \t [8]->0x%08x \t [9]->0x%08x\t [10]->0x%08x\t [11]->0x%08x\n",
+		  scrambled_output[0], scrambled_output[1], scrambled_output[2], scrambled_output[3], scrambled_output[4],scrambled_output[5],
+		  scrambled_output[6], scrambled_output[7], scrambled_output[8], scrambled_output[9], scrambled_output[10],scrambled_output[11] );	
+#endif
 
     // QPSK modulation
   int16_t mod_dci[NR_MAX_DCI_SIZE>>1];
@@ -237,8 +251,8 @@ uint8_t nr_generate_dci_top(NR_gNB_PDCCH pdcch_vars,
     mod_dci[i<<1] = nr_mod_table[(NR_MOD_TABLE_QPSK_OFFSET + idx)<<1];
     mod_dci[(i<<1)+1] = nr_mod_table[((NR_MOD_TABLE_QPSK_OFFSET + idx)<<1) + 1];
 #ifdef DEBUG_DCI
-  printf("i %d idx %d b0-b1 %d-%d mod_dci %d %d\n", i, idx, (((encoder_output[(i<<1)>>5])>>((i<<1)&0x1f))&1),
-  (((encoder_output[((i<<1)+1)>>5])>>(((i<<1)+1)&0x1f))&1), mod_dci[(i<<1)], mod_dci[(i<<1)+1]);
+  printf("i %d idx %d b0-b1 %d-%d mod_dci %d %d\n", i, idx, (((scrambled_output[(i<<1)>>5])>>((i<<1)&0x1f))&1),
+  (((scrambled_output[((i<<1)+1)>>5])>>(((i<<1)+1)&0x1f))&1), mod_dci[(i<<1)], mod_dci[(i<<1)+1]);
 #endif
   }
 
@@ -307,6 +321,7 @@ printf("\n");
         else { // DCI payload
           ((int16_t*)txdataF[aa])[(l*frame_parms.ofdm_symbol_size + k)<<1] = (a * mod_dci[dci_idx<<1]) >> 15;
           ((int16_t*)txdataF[aa])[((l*frame_parms.ofdm_symbol_size + k)<<1) + 1] = (a * mod_dci[(dci_idx<<1) + 1]) >> 15;
+          //printf("dci output %d %d\n",(a * mod_dci[dci_idx<<1]) >> 15, (a * mod_dci[(dci_idx<<1) + 1]) >> 15);
           dci_idx++;
         }
         k++;
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dci.h b/openair1/PHY/NR_TRANSPORT/nr_dci.h
index f7c885b49944fb2c3e3138ca24198b574a1fcb4d..62236eff327c1bd99f5adc847ec17392ca2c2734 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dci.h
+++ b/openair1/PHY/NR_TRANSPORT/nr_dci.h
@@ -41,7 +41,7 @@ uint8_t nr_generate_dci_top(NR_gNB_PDCCH pdcch_vars,
                             nfapi_nr_config_request_t config);
 
 void nr_pdcch_scrambling(uint32_t *in,
-                         uint8_t size,
+                         uint16_t size,
                          uint32_t Nid,
                          uint32_t n_RNTI,
                          uint32_t* out);
diff --git a/openair1/PHY/NR_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_TRANSPORT/nr_pbch.c
index 3e8a17aec659d283276a80a8f88707d36e4d9110..99a243e0aebb09bb11440385ae7c50512ebbeec1 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_pbch.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_pbch.c
@@ -39,7 +39,8 @@
 //#define DEBUG_PBCH_ENCODING
 //#define DEBUG_PBCH_DMRS
 
-extern short nr_mod_table[NR_MOD_TABLE_SIZE_SHORT];
+//extern short nr_mod_table[NR_MOD_TABLE_SIZE_SHORT];
+#include "PHY/NR_REFSIG/nr_mod_table.h"
 
 int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs,
                           int32_t **txdataF,
@@ -54,7 +55,7 @@ int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs,
   uint8_t idx=0;
   uint8_t nushift = config->sch_config.physical_cell_id.value &3;
 
-  LOG_I(PHY, "PBCH DMRS mapping started at symbol %d shift %d\n", ssb_start_symbol+1, nushift);
+  LOG_D(PHY, "PBCH DMRS mapping started at symbol %d shift %d\n", ssb_start_symbol+1, nushift);
 
   /// QPSK modulation
   for (int m=0; m<NR_PBCH_DMRS_LENGTH; m++) {
@@ -84,6 +85,11 @@ int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs,
 #endif
       ((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_dmrs[m<<1]) >> 15;
       ((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_dmrs[(m<<1) + 1]) >> 15;
+#ifdef DEBUG_PBCH_DMRS
+      printf("(%d,%d)\n",
+	((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1],
+	((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1)+1]);
+#endif
       k+=4;
 
       if (k >= frame_parms->ofdm_symbol_size)
@@ -100,6 +106,11 @@ int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs,
 #endif
       ((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_dmrs[m<<1]) >> 15;
       ((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_dmrs[(m<<1) + 1]) >> 15;
+#ifdef DEBUG_PBCH_DMRS
+      printf("(%d,%d)\n",
+	((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1],
+	((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1)+1]);
+#endif
       k+=(m==71)?148:4; // Jump from 44+nu to 192+nu
 
       if (k >= frame_parms->ofdm_symbol_size)
@@ -116,6 +127,11 @@ int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs,
 #endif
       ((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_dmrs[m<<1]) >> 15;
       ((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_dmrs[(m<<1) + 1]) >> 15;
+#ifdef DEBUG_PBCH_DMRS
+      printf("(%d,%d)\n",
+	((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1],
+	((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1)+1]);
+#endif
       k+=4;
 
       if (k >= frame_parms->ofdm_symbol_size)
@@ -217,7 +233,7 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch,
   memset((void*) xbyte, 0, 1);
   //uint8_t pbch_a_b[32];
 
-  LOG_I(PHY, "PBCH generation started\n");
+  //  LOG_D(PHY, "PBCH generation started\n");
 
   memset((void*)pbch, 0, sizeof(NR_gNB_PBCH));
   ///Payload generation
diff --git a/openair1/PHY/NR_TRANSPORT/nr_pss.c b/openair1/PHY/NR_TRANSPORT/nr_pss.c
index 3c4f296cd616794c7dc190e1b408033fde04082a..f91f14f8a21ff9bfa0ad50355a84eca79c228736 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_pss.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_pss.c
@@ -52,7 +52,8 @@ int nr_generate_pss(  int16_t *d_pss,
   }
 
 #ifdef NR_PSS_DEBUG
-  write_output("d_pss.m", "d_pss", (void*)d_pss, NR_PSS_LENGTH, 1, 1);
+  write_output("d_pss.m", "d_pss", (void*)d_pss, NR_PSS_LENGTH, 1, 0);
+  printf("PSS: ofdm_symbol_size %d, first_carrier_offset %d\n",frame_parms->ofdm_symbol_size,frame_parms->first_carrier_offset);
 #endif
 
   /// Resource mapping
@@ -63,9 +64,12 @@ int nr_generate_pss(  int16_t *d_pss,
 
     // PSS occupies a predefined position (subcarriers 56-182, symbol 0) within the SSB block starting from
     k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier + 56; //and
+    if (k>= frame_parms->ofdm_symbol_size) k-=frame_parms->ofdm_symbol_size;
+
     l = ssb_start_symbol;
 
     for (m = 0; m < NR_PSS_LENGTH; m++) {
+      //      printf("pss: writing position k %d / %d\n",k,frame_parms->ofdm_symbol_size);
       ((int16_t*)txdataF[aa])[2*(l*frame_parms->ofdm_symbol_size + k)] = (a * d_pss[m]) >> 15;
       k++;
 
@@ -75,7 +79,9 @@ int nr_generate_pss(  int16_t *d_pss,
   }
 
 #ifdef NR_PSS_DEBUG
-  write_output("pss_0.m", "pss_0", (void*)txdataF[0][2*l*frame_parms->ofdm_symbol_size], frame_parms->ofdm_symbol_size, 1, 1);
+  LOG_M("pss_0.m", "pss_0", 
+	(void*)&txdataF[0][ssb_start_symbol*frame_parms->ofdm_symbol_size], 
+	frame_parms->ofdm_symbol_size, 1, 1);
 #endif
 
   return 0;
diff --git a/openair1/PHY/NR_TRANSPORT/nr_sss.c b/openair1/PHY/NR_TRANSPORT/nr_sss.c
index 9b318d74ef9d8016ad3d18fab04bbf07df025582..023279f39ebf852612c4429649e815a16e8e9dbc 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_sss.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_sss.c
@@ -83,7 +83,7 @@ int nr_generate_sss(  int16_t *d_sss,
     }
   }
 #ifdef NR_SSS_DEBUG
-  write_output("sss_0.m", "sss_0", (void*)txdataF[0][2*l*frame_parms->ofdm_symbol_size], frame_parms->ofdm_symbol_size, 1, 1);
+  //  write_output("sss_0.m", "sss_0", (void*)txdataF[0][l*frame_parms->ofdm_symbol_size], frame_parms->ofdm_symbol_size, 1, 1);
 #endif
 
   return 0;
diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c
index 7385267dd12a272a5e6aa072f19b6f886a70f59a..27b11bba7d296aca6beb272135e3ffa0daa2db65 100644
--- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c
+++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c
@@ -19,78 +19,92 @@
  *      contact@openairinterface.org
  */
 
-#ifdef USER_MODE
+
 #include <string.h>
-#endif
+
 //#include "defs.h"
 //#include "SCHED/defs.h"
 #include "PHY/defs_nr_UE.h"
+#include "PHY/NR_REFSIG/refsig_defs_ue.h"
 #include "filt16a_32.h"
 #include "T.h"
 //#define DEBUG_CH
 
+
 int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
-                              uint8_t eNB_id,
-                              uint8_t eNB_offset,
-                              unsigned char Ns,
-                              unsigned char p,
-                              unsigned char l,
-                              unsigned char symbol)
+			       uint8_t eNB_id,
+			       uint8_t eNB_offset,
+			       unsigned char Ns,
+			       unsigned char l,
+			       unsigned char symbol)
 {
-  int pilot[2][200] __attribute__((aligned(16)));
+  int pilot[200] __attribute__((aligned(16)));
   unsigned char aarx;
   unsigned short k;
   unsigned int pilot_cnt;
   int16_t ch[2],*pil,*rxF,*dl_ch,*fl,*fm,*fr;
   int ch_offset,symbol_offset;
+  int dmrss;
 
   //uint16_t Nid_cell = (eNB_offset == 0) ? ue->frame_parms.Nid_cell : ue->measurements.adj_cell_id[eNB_offset-1];
 
-  uint8_t nushift, ssb_index=0, n_hf=0;
+  uint8_t nushift,ssb_index=0, n_hf=0;
   int **dl_ch_estimates  =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[eNB_offset];
   int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF;
 
   nushift =  ue->frame_parms.Nid_cell%4;
   ue->frame_parms.nushift = nushift;
- 
+
+  unsigned int  ssb_offset = ue->frame_parms.first_carrier_offset + ue->frame_parms.ssb_start_subcarrier;
+  if (ssb_offset>= ue->frame_parms.ofdm_symbol_size) ssb_offset-=ue->frame_parms.ofdm_symbol_size;
+
+  if (ue->is_synchronized ==0 ) dmrss = symbol-1;
+  else dmrss = symbol-5;
+
   if (ue->high_speed_flag == 0) // use second channel estimate position for temporary storage
     ch_offset     = ue->frame_parms.ofdm_symbol_size ;
   else
     ch_offset     = ue->frame_parms.ofdm_symbol_size*symbol;
 
+  AssertFatal((symbol > 0 && symbol < 4 && ue->is_synchronized == 0) || 
+	      (symbol > 4 && symbol < 8 && ue->is_synchronized == 1),
+	      "symbol %d is illegal for PBCH DM-RS (is_synchronized %d)\n",
+	      symbol,ue->is_synchronized);
+
   symbol_offset = ue->frame_parms.ofdm_symbol_size*symbol;
 
+
   k = nushift;
 
 #ifdef DEBUG_CH
-  printf("PBCH Channel Estimation : ThreadId %d, eNB_offset %d cell_id %d ch_offset %d, OFDM size %d, Ncp=%d, l=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns>>1], eNB_offset,Nid_cell,ch_offset,ue->frame_parms.ofdm_symbol_size,
+  printf("PBCH Channel Estimation : ThreadId %d, eNB_offset %d ch_offset %d, OFDM size %d, Ncp=%d, l=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns>>1], eNB_offset,ch_offset,ue->frame_parms.ofdm_symbol_size,
          ue->frame_parms.Ncp,l,Ns,k, symbol);
 #endif
 
   switch (k) {
   case 0:
-        fl = filt16a_l0;
-        fm = filt16a_m0;
-        fr = filt16a_r0;
-        break;
+    fl = filt16a_l0;
+    fm = filt16a_m0;
+    fr = filt16a_r0;
+    break;
 
   case 1:
-        fl = filt16a_l1;
-        fm = filt16a_m1;
-        fr = filt16a_r1;
-        break;
+    fl = filt16a_l1;
+    fm = filt16a_m1;
+    fr = filt16a_r1;
+    break;
 
   case 2:
-        fl = filt16a_l2;
-        fm = filt16a_m2;
-        fr = filt16a_r2;
-        break;
+    fl = filt16a_l2;
+    fm = filt16a_m2;
+    fr = filt16a_r2;
+    break;
 
   case 3:
-        fl = filt16a_l3;
-        fm = filt16a_m3;
-        fr = filt16a_r3;
-        break;
+    fl = filt16a_l3;
+    fm = filt16a_m3;
+    fr = filt16a_r3;
+    break;
 
   default:
     msg("pbch_channel_estimation: k=%d -> ERROR\n",k);
@@ -99,119 +113,136 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
   }
 
   // generate pilot
-  nr_pbch_dmrs_rx(ue->nr_gold_pbch[n_hf][ssb_index], &pilot[p][0]);
+  nr_pbch_dmrs_rx(dmrss,ue->nr_gold_pbch[n_hf][ssb_index], &pilot[0]);
 
+  int re_offset = ssb_offset;
   for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++) {
 
-    pil   = (int16_t *)&pilot[p][0];
-    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+(ue->frame_parms.ofdm_symbol_size-10*12))];
-    dl_ch = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][ch_offset];
-
+    pil   = (int16_t *)&pilot[0];
+    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
+    dl_ch = (int16_t *)&dl_ch_estimates[aarx][ch_offset];
+ 
     memset(dl_ch,0,4*(ue->frame_parms.ofdm_symbol_size));
     if (ue->high_speed_flag==0) // multiply previous channel estimate by ch_est_alpha
       multadd_complex_vector_real_scalar(dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                          ue->ch_est_alpha,dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                          1,ue->frame_parms.ofdm_symbol_size);
 #ifdef DEBUG_CH
-    printf("pbch ch est pilot addr %p RB_DL %d\n",&pilot[p][0], ue->frame_parms.N_RB_DL);
+    printf("pbch ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL);
     printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset);
     printf("rxF addr %p\n", rxF);
     printf("dl_ch addr %p\n",dl_ch);
 #endif
     //if ((ue->frame_parms.N_RB_DL&1)==0) {
 
-      // Treat first 2 pilots specially (left edge)
+    // Treat first 2 pilots specially (left edge)
+    ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
+    ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
+#ifdef DEBUG_CH
+    printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1]));
+    printf("pilot 0 : rxF - > (%d,%d) addr %p  ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]);
+#endif
+    multadd_real_vector_complex_scalar(fl,
+				       ch,
+				       dl_ch,
+				       16);
+    pil+=2;
+    re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
+    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
+
+    //for (int i= 0; i<8; i++)
+    //printf("dl_ch addr %p %d\n", dl_ch+i, *(dl_ch+i));
+
+    ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
+    ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
+#ifdef DEBUG_CH
+    printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
+#endif
+    multadd_real_vector_complex_scalar(fm,
+				       ch,
+				       dl_ch,
+				       16);
+    pil+=2;
+    re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
+    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
+
+    ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
+    ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
+
+#ifdef DEBUG_CH
+    printf("pilot 2 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
+#endif
+
+    multadd_real_vector_complex_scalar(fr,
+				       ch,
+				       dl_ch,
+				       16);
+    pil+=2;
+    re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
+    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
+    dl_ch+=24;
+
+    for (pilot_cnt=3; pilot_cnt<(3*20); pilot_cnt+=3) {
+
+      //	if (pilot_cnt == 30)
+      //	  rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k)];
+
+      // in 2nd symbol, skip middle  REs (48 with DMRS,  144 for SSS, and another 48 with DMRS) 
+      if (dmrss == 1 && pilot_cnt == 12) {
+	pilot_cnt=48;
+	re_offset = (re_offset+144)&(ue->frame_parms.ofdm_symbol_size-1);
+	rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
+	dl_ch += 288;
+      }
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_CH
-      printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1]));
-      printf("pilot 0 : rxF - > (%d,%d) addr %p  ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]);
+      printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
 #endif
       multadd_real_vector_complex_scalar(fl,
-                                         ch,
-                                         dl_ch,
-                                         16);
-      pil+=2;
-      rxF+=8;
+					 ch,
+					 dl_ch,
+					 16);
+
       //for (int i= 0; i<8; i++)
-      //printf("dl_ch addr %p %d\n", dl_ch+i, *(dl_ch+i));
+      //            printf("pilot_cnt %d dl_ch %d %d\n", pilot_cnt, dl_ch+i, *(dl_ch+i));
 
+      pil+=2;
+      re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
+      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
+        
+  
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_CH
-      printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
+      printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
 #endif
       multadd_real_vector_complex_scalar(fm,
-                                         ch,
-                                         dl_ch,
-                                         16);
+					 ch,
+					 dl_ch,
+					 16);
       pil+=2;
-      rxF+=8;
+      re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
+      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
+        
 
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 
 #ifdef DEBUG_CH
-      printf("pilot 2 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
+      printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+2,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
 #endif
 
       multadd_real_vector_complex_scalar(fr,
-                                         ch,
-                                         dl_ch,
-                                         16);
+					 ch,
+					 dl_ch,
+					 16);
       pil+=2;
-      rxF+=8;
+      re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
+      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
       dl_ch+=24;
 
-      for (pilot_cnt=3; pilot_cnt<(3*20); pilot_cnt+=3) {
-
-	if (pilot_cnt == 30)
-	  rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k)];
-
-        ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
-        ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
-#ifdef DEBUG_CH
-	printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-#endif
-        multadd_real_vector_complex_scalar(fl,
-                                           ch,
-                                           dl_ch,
-                                           16);
-
-        //for (int i= 0; i<8; i++)
-        //            printf("pilot_cnt %d dl_ch %d %d\n", pilot_cnt, dl_ch+i, *(dl_ch+i));
-
-        pil+=2;
-        rxF+=8;
-  
-        ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
-        ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
-#ifdef DEBUG_CH
-	printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-#endif
-        multadd_real_vector_complex_scalar(fm,
-                                           ch,
-                                           dl_ch,
-                                           16);
-        pil+=2;
-        rxF+=8;
-
-        ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
-        ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
-
-#ifdef DEBUG_CH
-	printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
-#endif
-
-        multadd_real_vector_complex_scalar(fr,
-                                           ch,
-                                           dl_ch,
-                                           16);
-        pil+=2;
-        rxF+=8;
-        dl_ch+=24;
-
-      }
+    }
 
 
     //}
@@ -222,16 +253,15 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
 }
 
 int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue,
-                              uint8_t eNB_id,
-                              uint8_t eNB_offset,
-                              unsigned char Ns,
-                              unsigned char p,
-                              unsigned char l,
-                              unsigned char symbol,
-							  unsigned short coreset_start_subcarrier,
-							  unsigned short nb_rb_coreset)
+				uint8_t eNB_id,
+				uint8_t eNB_offset,
+				unsigned char Ns,
+				unsigned char l,
+				unsigned char symbol,
+				unsigned short coreset_start_subcarrier,
+				unsigned short nb_rb_coreset)
 {
-  int pilot[2][200] __attribute__((aligned(16)));
+  int pilot[200] __attribute__((aligned(16)));
   unsigned char aarx;
   unsigned short k;
   unsigned int pilot_cnt;
@@ -266,25 +296,25 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue,
   fr = filt16a_r1;
 
   // generate pilot
-  nr_pdcch_dmrs_rx(ue,eNB_offset,Ns,ue->nr_gold_pdcch[eNB_offset][Ns][symbol], &pilot[p][0],2000,nb_rb_coreset);
+  nr_pdcch_dmrs_rx(ue,eNB_offset,Ns,ue->nr_gold_pdcch[eNB_offset][Ns][symbol], &pilot[0],2000,nb_rb_coreset);
 
   for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++) {
 
-    pil   = (int16_t *)&pilot[p][0];
+    pil   = (int16_t *)&pilot[0];
     rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+nushift)];
-    dl_ch = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][ch_offset];
+    dl_ch = (int16_t *)&dl_ch_estimates[aarx][ch_offset];
 
     memset(dl_ch,0,4*(ue->frame_parms.ofdm_symbol_size));
     if (ue->high_speed_flag==0) // multiply previous channel estimate by ch_est_alpha
       multadd_complex_vector_real_scalar(dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                          ue->ch_est_alpha,dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                          1,ue->frame_parms.ofdm_symbol_size);
-//#ifdef DEBUG_CH
-    printf("pdcch ch est pilot addr %p RB_DL %d\n",&pilot[p][0], ue->frame_parms.N_RB_DL);
+    //#ifdef DEBUG_CH
+    printf("pdcch ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL);
     printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset);
     printf("rxF addr %p\n", rxF);
     printf("dl_ch addr %p\n",dl_ch);
-//#endif
+    //#endif
     if ((ue->frame_parms.N_RB_DL&1)==0) {
 
       // Treat first 2 pilots specially (left edge)
@@ -329,7 +359,7 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue,
                                          
 #ifdef DEBUG_CH       
       for (int m =0; m<12; m++)
-      printf("data :  dl_ch -> (%d,%d)\n",dl_ch[0+2*m],dl_ch[1+2*m]);
+	printf("data :  dl_ch -> (%d,%d)\n",dl_ch[0+2*m],dl_ch[1+2*m]);
 #endif      
       pil+=2;
       rxF+=8;
@@ -341,8 +371,8 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue,
       for (pilot_cnt=3; pilot_cnt<(3*nb_rb_coreset); pilot_cnt+=3) {
 
         if (k >= ue->frame_parms.ofdm_symbol_size){
-    		 k-=ue->frame_parms.ofdm_symbol_size;
-    		 rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+nushift)];}
+	  k-=ue->frame_parms.ofdm_symbol_size;
+	  rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+nushift)];}
 
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
@@ -399,30 +429,28 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue,
 }
 
 int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue,
-                              uint8_t eNB_id,
-                              uint8_t eNB_offset,
-                              unsigned char Ns,
-                              unsigned char p,
-                              unsigned char l,
-                              unsigned char symbol,
-							  unsigned short bwp_start_subcarrier,
-							  unsigned short nb_rb_pdsch)
+				uint8_t eNB_id,
+				uint8_t eNB_offset,
+				unsigned char Ns,
+				unsigned char l,
+				unsigned char symbol,
+				unsigned short bwp_start_subcarrier,
+				unsigned short nb_rb_pdsch)
 {
-  int pilot[2][200] __attribute__((aligned(16)));
+  int pilot[200] __attribute__((aligned(16)));
   unsigned char aarx;
   unsigned short k;
   unsigned int pilot_cnt;
   int16_t ch[2],*pil,*rxF,*dl_ch,*fl,*fm,*fr,*fml,*fmr;
   int ch_offset,symbol_offset;
 
+
   //uint16_t Nid_cell = (eNB_offset == 0) ? ue->frame_parms.Nid_cell : ue->measurements.adj_cell_id[eNB_offset-1];
 
-  uint8_t nushift;
+  uint8_t nushift=0;
   int **dl_ch_estimates  =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[eNB_offset];
   int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF;
 
-  nushift = (p>>1)&1;
-  ue->frame_parms.nushift = nushift;
 
   if (ue->high_speed_flag == 0) // use second channel estimate position for temporary storage
     ch_offset     = ue->frame_parms.ofdm_symbol_size ;
@@ -434,42 +462,42 @@ int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue,
   k = bwp_start_subcarrier;
 
 #ifdef DEBUG_CH
-  printf("PBCH Channel Estimation : ThreadId %d, eNB_offset %d cell_id %d ch_offset %d, OFDM size %d, Ncp=%d, l=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns>>1], eNB_offset,Nid_cell,ch_offset,ue->frame_parms.ofdm_symbol_size,
+  printf("PBCH Channel Estimation : ThreadId %d, eNB_offset %d ch_offset %d, OFDM size %d, Ncp=%d, l=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns>>1], eNB_offset,ch_offset,ue->frame_parms.ofdm_symbol_size,
          ue->frame_parms.Ncp,l,Ns,k, symbol);
 #endif
 
   switch (nushift) {
-   case 0:
-         fl = filt8_l0;
-         fm = filt8_m0;
-         fr = filt8_r0;
-         fml = filt8_m0;
-         fmr = filt8_mr0;
-         break;
-
-   case 1:
-         fl = filt8_l1;
-         fm = filt8_m1;
-         fr = filt8_r1;
-         fml = filt8_ml1;
-         fmr = filt8_m1;
-         break;
-
-   default:
-     msg("pdsch_channel_estimation: nushift=%d -> ERROR\n",nushift);
-     return(-1);
-     break;
-   }
+  case 0:
+    fl = filt8_l0;
+    fm = filt8_m0;
+    fr = filt8_r0;
+    fml = filt8_m0;
+    fmr = filt8_mr0;
+    break;
+
+  case 1:
+    fl = filt8_l1;
+    fm = filt8_m1;
+    fr = filt8_r1;
+    fml = filt8_ml1;
+    fmr = filt8_m1;
+    break;
+
+  default:
+    msg("pdsch_channel_estimation: nushift=%d -> ERROR\n",nushift);
+    return(-1);
+    break;
+  }
 
 
   // generate pilot
-  nr_pdsch_dmrs_rx(ue,eNB_offset,Ns,ue->nr_gold_pdsch[eNB_offset][Ns][symbol], &pilot[p][0],1000,1,nb_rb_pdsch);
+  nr_pdsch_dmrs_rx(ue,eNB_offset,Ns,ue->nr_gold_pdsch[eNB_offset][Ns][symbol], &pilot[0],1000,1,nb_rb_pdsch);
 
   for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++) {
 
-    pil   = (int16_t *)&pilot[p][0];
+    pil   = (int16_t *)&pilot[0];
     rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+nushift)];
-    dl_ch = (int16_t *)&dl_ch_estimates[(p<<1)+aarx][ch_offset];
+    dl_ch = (int16_t *)&dl_ch_estimates[aarx][ch_offset];
 
     memset(dl_ch,0,4*(ue->frame_parms.ofdm_symbol_size));
     if (ue->high_speed_flag==0) // multiply previous channel estimate by ch_est_alpha
@@ -477,7 +505,7 @@ int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue,
                                          ue->ch_est_alpha,dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                          1,ue->frame_parms.ofdm_symbol_size);
 #ifdef DEBUG_CH
-    printf("ch est pilot addr %p RB_DL %d\n",&pilot[p][0], ue->frame_parms.N_RB_DL);
+    printf("ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL);
     printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset);
     printf("rxF addr %p\n", rxF);
     printf("dl_ch addr %p\n",dl_ch);
@@ -516,11 +544,11 @@ int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue,
 
       for (pilot_cnt=2; pilot_cnt<(6*(nb_rb_pdsch-1)+4); pilot_cnt+=2) {
     	if ((pilot_cnt%6)==0)
-    		dl_ch+=4;
+	  dl_ch+=4;
 
         if (k >= ue->frame_parms.ofdm_symbol_size){
-    		 k-=ue->frame_parms.ofdm_symbol_size;
-    		 rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+nushift)];}
+	  k-=ue->frame_parms.ofdm_symbol_size;
+	  rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+nushift)];}
 
         ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
         ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h
index ec761660e4bf2f2f012fd153d99b09f0ac86b08a..25d6755723e605935cd361fd76d6dd8b374c5f0b 100644
--- a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h
+++ b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h
@@ -46,7 +46,6 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue,
 				uint8_t eNB_id,
 				uint8_t eNB_offset,
 				unsigned char Ns,
-				unsigned char p,
 				unsigned char l,
 				unsigned char symbol,
 				unsigned short coreset_start_subcarrier,
@@ -56,7 +55,6 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
                               uint8_t eNB_id,
                               uint8_t eNB_offset,
                               unsigned char Ns,
-                              unsigned char p,
                               unsigned char l,
                               unsigned char symbol);
 
@@ -64,7 +62,6 @@ int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue,
                               uint8_t eNB_id,
                               uint8_t eNB_offset,
                               unsigned char Ns,
-                              unsigned char p,
                               unsigned char l,
                               unsigned char symbol,
 							  unsigned short bwp_start_subcarrier,
diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
index cb30ae7c21ae2439987293cd5f6cd4e46ec6370f..abf7856dbc3d3be92dab3b43f11b667eb04ecd71 100755
--- a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
@@ -58,233 +58,13 @@
 #define NR_NBR_SEARCHSPACE_ACT_BWP 10 // The number of SearSpaces per BWP is limited to 10 (including initial SEARCHSPACE: SearchSpaceId 0)
 #define PDCCH_TEST_POLAR_TEMP_FIX
 
-//#undef ALL_AGGREGATION
 
-//extern uint16_t phich_reg[MAX_NUM_PHICH_GROUPS][3];
-//extern uint16_t pcfich_reg[4];
 
-uint16_t extract_crc(uint8_t *dci,uint8_t dci_len)
-{
-
-  uint16_t crc16;
-  //  uint8_t i;
-
-  /*
-  uint8_t crc;
-  crc = ((uint16_t *)dci)[DCI_LENGTH>>4];
-  printf("crc1: %x, shift %d (DCI_LENGTH %d)\n",crc,DCI_LENGTH&0xf,DCI_LENGTH);
-  crc = (crc>>(DCI_LENGTH&0xf));
-  // clear crc bits
-  ((uint16_t *)dci)[DCI_LENGTH>>4] &= (0xffff>>(16-(DCI_LENGTH&0xf)));
-  printf("crc2: %x, dci0 %x\n",crc,((int16_t *)dci)[DCI_LENGTH>>4]);
-  crc |= (((uint16_t *)dci)[1+(DCI_LENGTH>>4)])<<(16-(DCI_LENGTH&0xf));
-  // clear crc bits
-  (((uint16_t *)dci)[1+(DCI_LENGTH>>4)]) = 0;
-  printf("extract_crc: crc %x\n",crc);
-  */
-#ifdef DEBUG_DCI_DECODING
-  LOG_I(PHY,"dci_crc (%x,%x,%x), dci_len&0x7=%d\n",dci[dci_len>>3],dci[1+(dci_len>>3)],dci[2+(dci_len>>3)],
-      dci_len&0x7);
-#endif
-
-  if ((dci_len&0x7) > 0) {
-    ((uint8_t *)&crc16)[0] = dci[1+(dci_len>>3)]<<(dci_len&0x7) | dci[2+(dci_len>>3)]>>(8-(dci_len&0x7));
-    ((uint8_t *)&crc16)[1] = dci[(dci_len>>3)]<<(dci_len&0x7) | dci[1+(dci_len>>3)]>>(8-(dci_len&0x7));
-  } else {
-    ((uint8_t *)&crc16)[0] = dci[1+(dci_len>>3)];
-    ((uint8_t *)&crc16)[1] = dci[(dci_len>>3)];
-  }
-
-#ifdef DEBUG_DCI_DECODING
-  LOG_I(PHY,"dci_crc =>%x\n",crc16);
-#endif
-
-  //  dci[(dci_len>>3)]&=(0xffff<<(dci_len&0xf));
-  //  dci[(dci_len>>3)+1] = 0;
-  //  dci[(dci_len>>3)+2] = 0;
-  return((uint16_t)crc16);
-  
-}
-
-
-
-static uint8_t d[3*(MAX_DCI_SIZE_BITS + 16) + 96];
-static uint8_t w[3*3*(MAX_DCI_SIZE_BITS+16)];
-
-void dci_encoding(uint8_t *a,
-                  uint8_t A,
-                  uint16_t E,
-                  uint8_t *e,
-                  uint16_t rnti)
-{
-
-
-  uint8_t D = (A + 16);
-  uint32_t RCC;
-
-#ifdef DEBUG_DCI_ENCODING
-  int32_t i;
-#endif
-  // encode dci
-
-#ifdef DEBUG_DCI_ENCODING
-  printf("Doing DCI encoding for %d bits, e %p, rnti %x\n",A,e,rnti);
-#endif
-
-  memset((void *)d,LTE_NULL,96);
-
-  ccodelte_encode(A,2,a,d+96,rnti);
-
-#ifdef DEBUG_DCI_ENCODING
-
-  for (i=0; i<16+A; i++)
-    printf("%d : (%d,%d,%d)\n",i,*(d+96+(3*i)),*(d+97+(3*i)),*(d+98+(3*i)));
-
-#endif
-
-#ifdef DEBUG_DCI_ENCODING
-  printf("Doing DCI interleaving for %d coded bits, e %p\n",D*3,e);
-#endif
-  RCC = sub_block_interleaving_cc(D,d+96,w);
-
-#ifdef DEBUG_DCI_ENCODING
-  printf("Doing DCI rate matching for %d channel bits, RCC %d, e %p\n",E,RCC,e);
-#endif
-  lte_rate_matching_cc(RCC,E,w,e);
-
-
-}
-
-
-uint8_t *generate_dci0(uint8_t *dci,
-                       uint8_t *e,
-                       uint8_t DCI_LENGTH,
-                       uint8_t aggregation_level,
-                       uint16_t rnti)
-{
-
-  uint16_t coded_bits;
-  uint8_t dci_flip[8];
-
-  if (aggregation_level>3) {
-    printf("dci.c: generate_dci FATAL, illegal aggregation_level %d\n",aggregation_level);
-    return NULL;
-  }
-
-  coded_bits = 72 * (1<<aggregation_level);
-
-  /*
-
-  #ifdef DEBUG_DCI_ENCODING
-  for (i=0;i<1+((DCI_LENGTH+16)/8);i++)
-    printf("i %d : %x\n",i,dci[i]);
-  #endif
-  */
-  if (DCI_LENGTH<=32) {
-    dci_flip[0] = dci[3];
-    dci_flip[1] = dci[2];
-    dci_flip[2] = dci[1];
-    dci_flip[3] = dci[0];
-  } else {
-    dci_flip[0] = dci[7];
-    dci_flip[1] = dci[6];
-    dci_flip[2] = dci[5];
-    dci_flip[3] = dci[4];
-    dci_flip[4] = dci[3];
-    dci_flip[5] = dci[2];
-    dci_flip[6] = dci[1];
-    dci_flip[7] = dci[0];
-#ifdef DEBUG_DCI_ENCODING
-    printf("DCI => %x,%x,%x,%x,%x,%x,%x,%x\n",
-        dci_flip[0],dci_flip[1],dci_flip[2],dci_flip[3],
-        dci_flip[4],dci_flip[5],dci_flip[6],dci_flip[7]);
-#endif
-  }
-
-  dci_encoding(dci_flip,DCI_LENGTH,coded_bits,e,rnti);
-
-  return(e+coded_bits);
-}
-
-uint32_t Y;
-
-#define CCEBITS 72
-#define CCEPERSYMBOL 33  // This is for 1200 RE
-#define CCEPERSYMBOL0 22  // This is for 1200 RE
-#define DCI_BITS_MAX ((2*CCEPERSYMBOL+CCEPERSYMBOL0)*CCEBITS)
-#define Msymb (DCI_BITS_MAX/2)
-//#define Mquad (Msymb/4)
-
-static int32_t wtemp[2][Msymb];
-
-void pdcch_interleaving(NR_DL_FRAME_PARMS *frame_parms,int32_t **z, int32_t **wbar,uint8_t n_symbols_pdcch,uint8_t mi)
-{
-
-  int32_t *wptr,*wptr2,*zptr;
-  uint32_t Mquad = get_nquad(n_symbols_pdcch,frame_parms,mi);
-  uint32_t RCC = (Mquad>>5), ND;
-  uint32_t row,col,Kpi,index;
-  int32_t i,k,a;
-#ifdef RM_DEBUG
-  int32_t nulled=0;
-#endif
-
-  //  printf("[PHY] PDCCH Interleaving Mquad %d (Nsymb %d)\n",Mquad,n_symbols_pdcch);
-  if ((Mquad&0x1f) > 0)
-    RCC++;
-
-  Kpi = (RCC<<5);
-  ND = Kpi - Mquad;
-
-  k=0;
-
-  for (col=0; col<32; col++) {
-    index = bitrev_cc_dci[col];
-
-    for (row=0; row<RCC; row++) {
-      //printf("col %d, index %d, row %d\n",col,index,row);
-      if (index>=ND) {
-        for (a=0; a<frame_parms->nb_antenna_ports_eNB; a++) {
-          //printf("a %d k %d\n",a,k);
-
-          wptr = &wtemp[a][k<<2];
-          zptr = &z[a][(index-ND)<<2];
-
-          //printf("wptr=%p, zptr=%p\n",wptr,zptr);
-
-          wptr[0] = zptr[0];
-          wptr[1] = zptr[1];
-          wptr[2] = zptr[2];
-          wptr[3] = zptr[3];
-        }
-
-        k++;
-      }
-
-      index+=32;
-    }
-  }
-
-  // permutation
-  for (i=0; i<Mquad; i++) {
-
-    for (a=0; a<frame_parms->nb_antenna_ports_eNB; a++) {
-
-      //wptr  = &wtemp[a][i<<2];
-      //wptr2 = &wbar[a][((i+frame_parms->Nid_cell)%Mquad)<<2];
-      wptr = &wtemp[a][((i+frame_parms->Nid_cell)%Mquad)<<2];
-      wptr2 = &wbar[a][i<<2];
-      wptr2[0] = wptr[0];
-      wptr2[1] = wptr[1];
-      wptr2[2] = wptr[2];
-      wptr2[3] = wptr[3];
-    }
-  }
-}
 
+#ifdef NR_PDCCH_DCI_RUN
 
+static const uint16_t conjugate[8]__attribute__((aligned(32))) = {-1,1,-1,1,-1,1,-1,1};
 
-#ifdef NR_PDCCH_DCI_RUN
 
 void nr_pdcch_demapping_deinterleaving(uint16_t *llr,
                                        uint16_t *z,
@@ -866,480 +646,6 @@ void nr_pdcch_extract_rbs_single(int32_t **rxdataF,
 #endif
 
 
-void pdcch_extract_rbs_single(int32_t **rxdataF,
-                              int32_t **dl_ch_estimates,
-                              int32_t **rxdataF_ext,
-                              int32_t **dl_ch_estimates_ext,
-                              uint8_t symbol,
-                              uint32_t high_speed_flag,
-                              NR_DL_FRAME_PARMS *frame_parms)
-{
-
-
-  uint16_t rb,nb_rb=0;
-  uint8_t i,j,aarx;
-  int32_t *dl_ch0,*dl_ch0_ext,*rxF,*rxF_ext;
-
-
-  int nushiftmod3 = frame_parms->nushift%3;
-  uint8_t symbol_mod;
-
-  symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
-#ifdef DEBUG_DCI_DECODING
-  LOG_I(PHY, "extract_rbs_single: symbol_mod %d\n",symbol_mod);
-#endif
-
-  for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-
-    if (high_speed_flag == 1)
-      dl_ch0     = &dl_ch_estimates[aarx][5+(symbol*(frame_parms->ofdm_symbol_size))];
-    else
-      dl_ch0     = &dl_ch_estimates[aarx][5];
-
-    dl_ch0_ext = &dl_ch_estimates_ext[aarx][symbol*(frame_parms->N_RB_DL*12)];
-
-    rxF_ext   = &rxdataF_ext[aarx][symbol*(frame_parms->N_RB_DL*12)];
-
-    rxF       = &rxdataF[aarx][(frame_parms->first_carrier_offset + (symbol*(frame_parms->ofdm_symbol_size)))];
-
-    if ((frame_parms->N_RB_DL&1) == 0)  { // even number of RBs
-      for (rb=0; rb<frame_parms->N_RB_DL; rb++) {
-
-        // For second half of RBs skip DC carrier
-        if (rb==(frame_parms->N_RB_DL>>1)) {
-          rxF       = &rxdataF[aarx][(1 + (symbol*(frame_parms->ofdm_symbol_size)))];
-
-          //dl_ch0++;
-        }
-
-        if (symbol_mod>0) {
-          memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int32_t));
-
-          for (i=0; i<12; i++) {
-
-            rxF_ext[i]=rxF[i];
-
-          }
-
-          nb_rb++;
-          dl_ch0_ext+=12;
-          rxF_ext+=12;
-
-          dl_ch0+=12;
-          rxF+=12;
-        } else {
-          j=0;
-
-          for (i=0; i<12; i++) {
-            if ((i!=nushiftmod3) &&
-                (i!=(nushiftmod3+3)) &&
-                (i!=(nushiftmod3+6)) &&
-                (i!=(nushiftmod3+9))) {
-              rxF_ext[j]=rxF[i];
-              //                        printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
-              dl_ch0_ext[j++]=dl_ch0[i];
-              //                printf("ch %d => (%d,%d)\n",i,*(short *)&dl_ch0[i],*(1+(short*)&dl_ch0[i]));
-            }
-          }
-
-          nb_rb++;
-          dl_ch0_ext+=8;
-          rxF_ext+=8;
-
-          dl_ch0+=12;
-          rxF+=12;
-        }
-      }
-    } else { // Odd number of RBs
-      for (rb=0; rb<frame_parms->N_RB_DL>>1; rb++) {
-
-        if (symbol_mod>0) {
-          memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int32_t));
-
-          for (i=0; i<12; i++)
-            rxF_ext[i]=rxF[i];
-
-          nb_rb++;
-          dl_ch0_ext+=12;
-          rxF_ext+=12;
-
-          dl_ch0+=12;
-          rxF+=12;
-        } else {
-          j=0;
-
-          for (i=0; i<12; i++) {
-            if ((i!=nushiftmod3) &&
-                (i!=(nushiftmod3+3)) &&
-                (i!=(nushiftmod3+6)) &&
-                (i!=(nushiftmod3+9))) {
-              rxF_ext[j]=rxF[i];
-              //                        printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
-              dl_ch0_ext[j++]=dl_ch0[i];
-              //                printf("ch %d => (%d,%d)\n",i,*(short *)&dl_ch0[i],*(1+(short*)&dl_ch0[i]));
-            }
-          }
-
-          nb_rb++;
-          dl_ch0_ext+=8;
-          rxF_ext+=8;
-
-          dl_ch0+=12;
-          rxF+=12;
-        }
-      }
-
-      // Do middle RB (around DC)
-      //  printf("dlch_ext %d\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]);
-
-      if (symbol_mod==0) {
-        j=0;
-
-        for (i=0; i<6; i++) {
-          if ((i!=nushiftmod3) &&
-              (i!=(nushiftmod3+3))) {
-            dl_ch0_ext[j]=dl_ch0[i];
-            rxF_ext[j++]=rxF[i];
-            //              printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short*)&rxF_ext[j-1]));
-          }
-        }
-
-        rxF       = &rxdataF[aarx][((symbol*(frame_parms->ofdm_symbol_size)))];
-
-        for (; i<12; i++) {
-          if ((i!=(nushiftmod3+6)) &&
-              (i!=(nushiftmod3+9))) {
-            dl_ch0_ext[j]=dl_ch0[i];
-            rxF_ext[j++]=rxF[(1+i-6)];
-            //              printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short*)&rxF_ext[j-1]));
-          }
-        }
-
-
-        nb_rb++;
-        dl_ch0_ext+=8;
-        rxF_ext+=8;
-        dl_ch0+=12;
-        rxF+=7;
-        rb++;
-      } else {
-        for (i=0; i<6; i++) {
-          dl_ch0_ext[i]=dl_ch0[i];
-          rxF_ext[i]=rxF[i];
-        }
-
-        rxF       = &rxdataF[aarx][((symbol*(frame_parms->ofdm_symbol_size)))];
-
-        for (; i<12; i++) {
-          dl_ch0_ext[i]=dl_ch0[i];
-          rxF_ext[i]=rxF[(1+i-6)];
-        }
-
-
-        nb_rb++;
-        dl_ch0_ext+=12;
-        rxF_ext+=12;
-        dl_ch0+=12;
-        rxF+=7;
-        rb++;
-      }
-
-      for (; rb<frame_parms->N_RB_DL; rb++) {
-        if (symbol_mod > 0) {
-          memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int32_t));
-
-          for (i=0; i<12; i++)
-            rxF_ext[i]=rxF[i];
-
-          nb_rb++;
-          dl_ch0_ext+=12;
-          rxF_ext+=12;
-
-          dl_ch0+=12;
-          rxF+=12;
-        } else {
-          j=0;
-
-          for (i=0; i<12; i++) {
-            if ((i!=(nushiftmod3)) &&
-                (i!=(nushiftmod3+3)) &&
-                (i!=(nushiftmod3+6)) &&
-                (i!=(nushiftmod3+9))) {
-              rxF_ext[j]=rxF[i];
-              //                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
-              dl_ch0_ext[j++]=dl_ch0[i];
-            }
-          }
-
-          nb_rb++;
-          dl_ch0_ext+=8;
-          rxF_ext+=8;
-
-          dl_ch0+=12;
-          rxF+=12;
-        }
-      }
-    }
-  }
-}
-
-void pdcch_extract_rbs_dual(int32_t **rxdataF,
-                            int32_t **dl_ch_estimates,
-                            int32_t **rxdataF_ext,
-                            int32_t **dl_ch_estimates_ext,
-                            uint8_t symbol,
-                            uint32_t high_speed_flag,
-                            NR_DL_FRAME_PARMS *frame_parms)
-{
-
-
-  uint16_t rb,nb_rb=0;
-  uint8_t i,aarx,j;
-  int32_t *dl_ch0,*dl_ch0_ext,*dl_ch1,*dl_ch1_ext,*rxF,*rxF_ext;
-  uint8_t symbol_mod;
-  int nushiftmod3 = frame_parms->nushift%3;
-
-  symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
-#ifdef DEBUG_DCI_DECODING
-  LOG_I(PHY, "extract_rbs_dual: symbol_mod %d\n",symbol_mod);
-#endif
-
-  for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-
-    if (high_speed_flag==1) {
-      dl_ch0     = &dl_ch_estimates[aarx][5+(symbol*(frame_parms->ofdm_symbol_size))];
-      dl_ch1     = &dl_ch_estimates[2+aarx][5+(symbol*(frame_parms->ofdm_symbol_size))];
-    } else {
-      dl_ch0     = &dl_ch_estimates[aarx][5];
-      dl_ch1     = &dl_ch_estimates[2+aarx][5];
-    }
-
-    dl_ch0_ext = &dl_ch_estimates_ext[aarx][symbol*(frame_parms->N_RB_DL*12)];
-    dl_ch1_ext = &dl_ch_estimates_ext[2+aarx][symbol*(frame_parms->N_RB_DL*12)];
-
-    //    printf("pdcch extract_rbs: rxF_ext pos %d\n",symbol*(frame_parms->N_RB_DL*12));
-    rxF_ext   = &rxdataF_ext[aarx][symbol*(frame_parms->N_RB_DL*12)];
-
-    rxF       = &rxdataF[aarx][(frame_parms->first_carrier_offset + (symbol*(frame_parms->ofdm_symbol_size)))];
-
-    if ((frame_parms->N_RB_DL&1) == 0)  // even number of RBs
-      for (rb=0; rb<frame_parms->N_RB_DL; rb++) {
-
-        // For second half of RBs skip DC carrier
-        if (rb==(frame_parms->N_RB_DL>>1)) {
-          rxF       = &rxdataF[aarx][(1 + (symbol*(frame_parms->ofdm_symbol_size)))];
-          //    dl_ch0++;
-          //dl_ch1++;
-        }
-
-        if (symbol_mod>0) {
-          memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int32_t));
-          memcpy(dl_ch1_ext,dl_ch1,12*sizeof(int32_t));
-
-          /*
-            printf("rb %d\n",rb);
-            for (i=0;i<12;i++)
-            printf("(%d %d)",((int16_t *)dl_ch0)[i<<1],((int16_t*)dl_ch0)[1+(i<<1)]);
-            printf("\n");
-          */
-          for (i=0; i<12; i++) {
-            rxF_ext[i]=rxF[i];
-            //      printf("%d : (%d,%d)\n",(rxF+(2*i)-&rxdataF[aarx][( (symbol*(frame_parms->ofdm_symbol_size)))*2])/2,
-            //  ((int16_t*)&rxF[i<<1])[0],((int16_t*)&rxF[i<<1])[0]);
-          }
-
-          nb_rb++;
-          dl_ch0_ext+=12;
-          dl_ch1_ext+=12;
-          rxF_ext+=12;
-        } else {
-          j=0;
-
-          for (i=0; i<12; i++) {
-            if ((i!=nushiftmod3) &&
-                (i!=nushiftmod3+3) &&
-                (i!=nushiftmod3+6) &&
-                (i!=nushiftmod3+9)) {
-              rxF_ext[j]=rxF[i];
-              //                            printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
-              dl_ch0_ext[j]  =dl_ch0[i];
-              dl_ch1_ext[j++]=dl_ch1[i];
-            }
-          }
-
-          nb_rb++;
-          dl_ch0_ext+=8;
-          dl_ch1_ext+=8;
-          rxF_ext+=8;
-        }
-
-        dl_ch0+=12;
-        dl_ch1+=12;
-        rxF+=12;
-      }
-
-    else {  // Odd number of RBs
-      for (rb=0; rb<frame_parms->N_RB_DL>>1; rb++) {
-
-        //  printf("rb %d: %d\n",rb,rxF-&rxdataF[aarx][(symbol*(frame_parms->ofdm_symbol_size))*2]);
-
-        if (symbol_mod>0) {
-          memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int32_t));
-          memcpy(dl_ch1_ext,dl_ch1,12*sizeof(int32_t));
-
-          for (i=0; i<12; i++)
-            rxF_ext[i]=rxF[i];
-
-          nb_rb++;
-          dl_ch0_ext+=12;
-          dl_ch1_ext+=12;
-          rxF_ext+=12;
-
-          dl_ch0+=12;
-          dl_ch1+=12;
-          rxF+=12;
-
-        } else {
-          j=0;
-
-          for (i=0; i<12; i++) {
-            if ((i!=nushiftmod3) &&
-                (i!=nushiftmod3+3) &&
-                (i!=nushiftmod3+6) &&
-                (i!=nushiftmod3+9)) {
-              rxF_ext[j]=rxF[i];
-              //                        printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
-              dl_ch0_ext[j]=dl_ch0[i];
-              dl_ch1_ext[j++]=dl_ch1[i];
-              //                printf("ch %d => (%d,%d)\n",i,*(short *)&dl_ch0[i],*(1+(short*)&dl_ch0[i]));
-            }
-          }
-
-          nb_rb++;
-          dl_ch0_ext+=8;
-          dl_ch1_ext+=8;
-          rxF_ext+=8;
-
-
-          dl_ch0+=12;
-          dl_ch1+=12;
-          rxF+=12;
-        }
-      }
-
-      // Do middle RB (around DC)
-
-      if (symbol_mod > 0) {
-        for (i=0; i<6; i++) {
-          dl_ch0_ext[i]=dl_ch0[i];
-          dl_ch1_ext[i]=dl_ch1[i];
-          rxF_ext[i]=rxF[i];
-        }
-
-        rxF       = &rxdataF[aarx][((symbol*(frame_parms->ofdm_symbol_size)))];
-
-        for (; i<12; i++) {
-          dl_ch0_ext[i]=dl_ch0[i];
-          dl_ch1_ext[i]=dl_ch1[i];
-          rxF_ext[i]=rxF[(1+i)];
-        }
-
-        nb_rb++;
-        dl_ch0_ext+=12;
-        dl_ch1_ext+=12;
-        rxF_ext+=12;
-
-        dl_ch0+=12;
-        dl_ch1+=12;
-        rxF+=7;
-        rb++;
-      } else {
-        j=0;
-
-        for (i=0; i<6; i++) {
-          if ((i!=nushiftmod3) &&
-              (i!=nushiftmod3+3)) {
-            dl_ch0_ext[j]=dl_ch0[i];
-            dl_ch1_ext[j]=dl_ch1[i];
-            rxF_ext[j++]=rxF[i];
-            //              printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short*)&rxF_ext[j-1]));
-          }
-        }
-
-        rxF       = &rxdataF[aarx][((symbol*(frame_parms->ofdm_symbol_size)))];
-
-        for (; i<12; i++) {
-          if ((i!=nushiftmod3+6) &&
-              (i!=nushiftmod3+9)) {
-            dl_ch0_ext[j]=dl_ch0[i];
-            dl_ch1_ext[j]=dl_ch1[i];
-            rxF_ext[j++]=rxF[(1+i-6)];
-            //              printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short*)&rxF_ext[j-1]));
-          }
-        }
-
-
-        nb_rb++;
-        dl_ch0_ext+=8;
-        dl_ch1_ext+=8;
-        rxF_ext+=8;
-        dl_ch0+=12;
-        dl_ch1+=12;
-        rxF+=7;
-        rb++;
-      }
-
-      for (; rb<frame_parms->N_RB_DL; rb++) {
-
-        if (symbol_mod>0) {
-          //  printf("rb %d: %d\n",rb,rxF-&rxdataF[aarx][(symbol*(frame_parms->ofdm_symbol_size))*2]);
-          memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int32_t));
-          memcpy(dl_ch1_ext,dl_ch1,12*sizeof(int32_t));
-
-          for (i=0; i<12; i++)
-            rxF_ext[i]=rxF[i];
-
-          nb_rb++;
-          dl_ch0_ext+=12;
-          dl_ch1_ext+=12;
-          rxF_ext+=12;
-
-          dl_ch0+=12;
-          dl_ch1+=12;
-          rxF+=12;
-        } else {
-          j=0;
-
-          for (i=0; i<12; i++) {
-            if ((i!=nushiftmod3) &&
-                (i!=nushiftmod3+3) &&
-                (i!=nushiftmod3+6) &&
-                (i!=nushiftmod3+9)) {
-              rxF_ext[j]=rxF[i];
-              //                printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
-              dl_ch0_ext[j]=dl_ch0[i];
-              dl_ch1_ext[j++]=dl_ch1[i];
-            }
-          }
-
-          nb_rb++;
-          dl_ch0_ext+=8;
-          dl_ch1_ext+=8;
-          rxF_ext+=8;
-
-          dl_ch0+=12;
-          dl_ch1+=12;
-          rxF+=12;
-        }
-      }
-    }
-  }
-}
-#if defined(__x86_64__) || defined(__i386__)
-__m128i mmtmpP0,mmtmpP1,mmtmpP2,mmtmpP3;
-#elif defined(__arm__)
-int16x8_t mmtmpP0,mmtmpP1,mmtmpP2,mmtmpP3;
-#endif
 
 void nr_pdcch_channel_compensation(int32_t **rxdataF_ext,
                                    int32_t **dl_ch_estimates_ext,
@@ -1353,6 +659,13 @@ void nr_pdcch_channel_compensation(int32_t **rxdataF_ext,
 
   uint16_t rb; //,nb_rb=20;
   uint8_t aatx,aarx;
+
+#if defined(__x86_64__) || defined(__i386__)
+__m128i mmtmpP0,mmtmpP1,mmtmpP2,mmtmpP3;
+#elif defined(__arm__)
+int16x8_t mmtmpP0,mmtmpP1,mmtmpP2,mmtmpP3;
+#endif
+
 #if defined(__x86_64__) || defined(__i386__)
   __m128i *dl_ch128,*rxdataF128,*rxdataF_comp128;
 #elif defined(__arm__)
@@ -1522,39 +835,6 @@ void pdcch_siso(NR_DL_FRAME_PARMS *frame_parms,
 }
 
 
-void pdcch_alamouti(NR_DL_FRAME_PARMS *frame_parms,
-                    int32_t **rxdataF_comp,
-                    uint8_t symbol)
-{
-
-
-  int16_t *rxF0,*rxF1;
-  uint8_t rb,re;
-  int32_t jj=(symbol*frame_parms->N_RB_DL*12);
-
-  rxF0     = (int16_t*)&rxdataF_comp[0][jj];  //tx antenna 0  h0*y
-  rxF1     = (int16_t*)&rxdataF_comp[2][jj];  //tx antenna 1  h1*y
-
-  for (rb=0; rb<frame_parms->N_RB_DL; rb++) {
-
-    for (re=0; re<12; re+=2) {
-
-      // Alamouti RX combining
-
-      rxF0[0] = rxF0[0] + rxF1[2];
-      rxF0[1] = rxF0[1] - rxF1[3];
-
-      rxF0[2] = rxF0[2] - rxF1[0];
-      rxF0[3] = rxF0[3] + rxF1[1];
-
-      rxF0+=4;
-      rxF1+=4;
-    }
-  }
-
-
-}
-
 int32_t avgP[4];
 
 
@@ -1775,12 +1055,6 @@ T(T_UE_PHY_PDCCH_ENERGY, T_INT(eNB_id), T_INT(0), T_INT(frame%1024), T_INT(nr_tt
       #endif
       pdcch_detection_mrc(frame_parms, pdcch_vars[eNB_id]->rxdataF_comp,s);
     }
-    if (mimo_mode == SISO) {
-      #ifdef NR_PDCCH_DCI_DEBUG
-       printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> we enter pdcch_siso ---> pdcch_vars[eNB_id]->rxdataF_comp Nothing to do here. TO BE REMOVED!!!\n");
-      #endif
-      //pdcch_siso(frame_parms, pdcch_vars[eNB_id]->rxdataF_comp,s);
-    } else pdcch_alamouti(frame_parms, pdcch_vars[eNB_id]->rxdataF_comp,s);
 
 #ifdef MU_RECEIVER
 
@@ -1952,259 +1226,6 @@ printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_unscrambling)->  (c_init=%d, n_id=%d,
 #endif
 
 
-#ifdef PHY_ABSTRACTION
-uint8_t generate_dci_top_emul(PHY_VARS_eNB *phy_vars_eNB,
-                              int num_dci,
-                              DCI_ALLOC_t *dci_alloc,
-                              uint8_t subframe)
-{
-  int n_dci, n_dci_dl;
-  uint8_t ue_id;
-  LTE_eNB_DLSCH_t *dlsch_eNB;
-  int num_ue_spec_dci;
-  int num_common_dci;
-  int i;
-  uint8_t num_pdcch_symbols = get_num_pdcch_symbols(num_dci,
-                              dci_alloc,
-                              &phy_vars_eNB->frame_parms,
-                              subframe);
-  eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].cntl.cfi=num_pdcch_symbols;
-
-  num_ue_spec_dci = 0;
-  num_common_dci = 0;
-  for (i = 0; i < num_dci; i++) {
-    /* TODO: maybe useless test, to remove? */
-    if (!(dci_alloc[i].firstCCE>=0)) abort();
-    if (dci_alloc[i].search_space == DCI_COMMON_SPACE)
-      num_common_dci++;
-    else
-      num_ue_spec_dci++;
-  }
-
-  memcpy(phy_vars_eNB->dci_alloc[subframe&1],dci_alloc,sizeof(DCI_ALLOC_t)*(num_dci));
-  phy_vars_eNB->num_ue_spec_dci[subframe&1]=num_ue_spec_dci;
-  phy_vars_eNB->num_common_dci[subframe&1]=num_common_dci;
-  eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_ue_spec_dci = num_ue_spec_dci;
-  eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_common_dci = num_common_dci;
-
-  LOG_D(PHY,"[eNB %d][DCI][EMUL] CC id %d:  num spec dci %d num comm dci %d num PMCH %d \n",
-        phy_vars_eNB->Mod_id, phy_vars_eNB->CC_id, num_ue_spec_dci,num_common_dci,
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_pmch);
-
-  if (eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].cntl.pmch_flag == 1 )
-    n_dci_dl = eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_pmch;
-  else
-    n_dci_dl = 0;
-
-  for (n_dci =0 ;
-       n_dci < (eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_ue_spec_dci+ eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_common_dci);
-       n_dci++) {
-
-    if (dci_alloc[n_dci].format > 0) { // exclude the uplink dci
-
-      if (dci_alloc[n_dci].rnti == SI_RNTI) {
-        dlsch_eNB = PHY_vars_eNB_g[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id]->dlsch_SI;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].dlsch_type[n_dci_dl] = 0;//SI;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[n_dci_dl] = 0;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[n_dci_dl] = dlsch_eNB->harq_processes[0]->TBS>>3;
-        LOG_D(PHY,"[DCI][EMUL]SI tbs is %d and dci index %d harq pid is %d \n",eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[n_dci_dl],n_dci_dl,
-              eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[n_dci_dl]);
-      } else if (dci_alloc[n_dci_dl].ra_flag == 1) {
-        dlsch_eNB = PHY_vars_eNB_g[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id]->dlsch_ra;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].dlsch_type[n_dci_dl] = 1;//RA;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[n_dci_dl] = 0;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[n_dci_dl] = dlsch_eNB->harq_processes[0]->TBS>>3;
-        LOG_D(PHY,"[DCI][EMUL] RA  tbs is %d and dci index %d harq pid is %d \n",eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[n_dci_dl],n_dci_dl,
-              eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[n_dci_dl]);
-      } else {
-        ue_id = find_ue(dci_alloc[n_dci_dl].rnti,PHY_vars_eNB_g[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id]);
-        DevAssert( ue_id != (uint8_t)-1 );
-        dlsch_eNB = PHY_vars_eNB_g[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id]->dlsch[ue_id][0];
-
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].dlsch_type[n_dci_dl] = 2;//TB0;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[n_dci_dl] = dlsch_eNB->current_harq_pid;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].ue_id[n_dci_dl] = ue_id;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[n_dci_dl] = dlsch_eNB->harq_processes[dlsch_eNB->current_harq_pid]->TBS>>3;
-        LOG_D(PHY,"[DCI][EMUL] TB1 tbs is %d and dci index %d harq pid is %d \n",eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[n_dci_dl],n_dci_dl,
-              eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[n_dci_dl]);
-        // check for TB1 later
-
-      }
-    }
-
-    n_dci_dl++;
-  }
-
-  memcpy((void *)&eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].dci_alloc,
-         (void *)dci_alloc,
-         n_dci*sizeof(DCI_ALLOC_t));
-
-  return(num_pdcch_symbols);
-}
-#endif
-
-
-//static uint8_t dci_decoded_output[RX_NB_TH][(MAX_DCI_SIZE_BITS+64)/8];
-
-/*uint16_t get_nCCE(uint8_t num_pdcch_symbols,NR_DL_FRAME_PARMS *frame_parms,uint8_t mi)
-{
-  return(get_nquad(num_pdcch_symbols,frame_parms,mi)/9);
-}
-
-uint16_t get_nquad(uint8_t num_pdcch_symbols,NR_DL_FRAME_PARMS *frame_parms,uint8_t mi)
-{
-
-  uint16_t Nreg=0;
-  uint8_t Ngroup_PHICH = (frame_parms->phich_config_common.phich_resource*frame_parms->N_RB_DL)/48;
-
-  if (((frame_parms->phich_config_common.phich_resource*frame_parms->N_RB_DL)%48) > 0)
-    Ngroup_PHICH++;
-
-  if (frame_parms->Ncp == 1) {
-    Ngroup_PHICH<<=1;
-  }
-
-  Ngroup_PHICH*=mi;
-
-  if ((num_pdcch_symbols>0) && (num_pdcch_symbols<4))
-    switch (frame_parms->N_RB_DL) {
-    case 6:
-      Nreg=12+(num_pdcch_symbols-1)*18;
-      break;
-
-    case 25:
-      Nreg=50+(num_pdcch_symbols-1)*75;
-      break;
-
-    case 50:
-      Nreg=100+(num_pdcch_symbols-1)*150;
-      break;
-
-    case 100:
-      Nreg=200+(num_pdcch_symbols-1)*300;
-      break;
-
-    default:
-      return(0);
-    }
-
-  //   printf("Nreg %d (%d)\n",Nreg,Nreg - 4 - (3*Ngroup_PHICH));
-  return(Nreg - 4 - (3*Ngroup_PHICH));
-}
-
-uint16_t get_nCCE_mac(uint8_t Mod_id,uint8_t CC_id,int num_pdcch_symbols,int nr_tti_rx)
-{
-
-  // check for eNB only !
-  return(get_nCCE(num_pdcch_symbols,
-		  &PHY_vars_eNB_g[Mod_id][CC_id]->frame_parms,
-		  get_mi(&PHY_vars_eNB_g[Mod_id][CC_id]->frame_parms,nr_tti_rx)));
-}
-*/
-
-int get_nCCE_offset_l1(int *CCE_table,
-		       const unsigned char L, 
-		       const int nCCE, 
-		       const int common_dci, 
-		       const unsigned short rnti, 
-		       const unsigned char nr_tti_rx)
-{
-
-  int search_space_free,m,nb_candidates = 0,l,i;
-  unsigned int Yk;
-   /*
-    printf("CCE Allocation: ");
-    for (i=0;i<nCCE;i++)
-    printf("%d.",CCE_table[i]);
-    printf("\n");
-  */
-  if (common_dci == 1) {
-    // check CCE(0 ... L-1)
-    nb_candidates = (L==4) ? 4 : 2;
-    nb_candidates = min(nb_candidates,nCCE/L);
-
-    //    printf("Common DCI nb_candidates %d, L %d\n",nb_candidates,L);
-
-    for (m = nb_candidates-1 ; m >=0 ; m--) {
-
-      search_space_free = 1;
-      for (l=0; l<L; l++) {
-
-	//	printf("CCE_table[%d] %d\n",(m*L)+l,CCE_table[(m*L)+l]);
-        if (CCE_table[(m*L) + l] == 1) {
-          search_space_free = 0;
-          break;
-        }
-      }
-     
-      if (search_space_free == 1) {
-
-	//	printf("returning %d\n",m*L);
-
-        for (l=0; l<L; l++)
-          CCE_table[(m*L)+l]=1;
-        return(m*L);
-      }
-    }
-
-    return(-1);
-
-  } else { // Find first available in ue specific search space
-    // according to procedure in Section 9.1.1 of 36.213 (v. 8.6)
-    // compute Yk
-    Yk = (unsigned int)rnti;
-
-    for (i=0; i<=nr_tti_rx; i++)
-      Yk = (Yk*39827)%65537;
-
-    Yk = Yk % (nCCE/L);
-
-
-    switch (L) {
-    case 1:
-    case 2:
-      nb_candidates = 6;
-      break;
-
-    case 4:
-    case 8:
-      nb_candidates = 2;
-      break;
-
-    default:
-      DevParam(L, nCCE, rnti);
-      break;
-    }
-
-
-    LOG_D(MAC,"rnti %x, Yk = %d, nCCE %d (nCCE/L %d),nb_cand %d\n",rnti,Yk,nCCE,nCCE/L,nb_candidates);
-
-    for (m = 0 ; m < nb_candidates ; m++) {
-      search_space_free = 1;
-
-      for (l=0; l<L; l++) {
-        int cce = (((Yk+m)%(nCCE/L))*L) + l;
-        if (cce >= nCCE || CCE_table[cce] == 1) {
-          search_space_free = 0;
-          break;
-        }
-      }
-
-      if (search_space_free == 1) {
-        for (l=0; l<L; l++)
-          CCE_table[(((Yk+m)%(nCCE/L))*L)+l]=1;
-
-        return(((Yk+m)%(nCCE/L))*L);
-      }
-    }
-
-    return(-1);
-  }
-}
-
-
-
-
 #ifdef NR_PDCCH_DCI_RUN
 void nr_dci_decoding_procedure0(int s,                                                                        
                                 int p,
@@ -4022,32 +3043,4 @@ uint8_t nr_dci_decoding_procedure(int s,
 #endif
 
 
-#ifdef PHY_ABSTRACTION
-uint16_t dci_decoding_procedure_emul(NR_UE_PDCCH **pdcch_vars,
-                                     uint8_t num_ue_spec_dci,
-                                     uint8_t num_common_dci,
-                                     DCI_ALLOC_t *dci_alloc_tx,
-                                     DCI_ALLOC_t *dci_alloc_rx,
-                                     int16_t eNB_id)
-{
-
-  uint8_t  dci_cnt=0,i;
-
-  memcpy(dci_alloc_rx,dci_alloc_tx,num_common_dci*sizeof(DCI_ALLOC_t));
-  dci_cnt = num_common_dci;
-  LOG_D(PHY,"[DCI][EMUL] : num_common_dci %d\n",num_common_dci);
-
-  for (i=num_common_dci; i<(num_ue_spec_dci+num_common_dci); i++) {
-    LOG_D(PHY,"[DCI][EMUL] Checking dci %d => %x format %d (bit 0 %d)\n",i,pdcch_vars[eNB_id]->crnti,dci_alloc_tx[i].format,
-          dci_alloc_tx[i].dci_pdu[0]&0x80);
-
-    if (dci_alloc_tx[i].rnti == pdcch_vars[eNB_id]->crnti) {
-      memcpy(dci_alloc_rx+dci_cnt,dci_alloc_tx+i,sizeof(DCI_ALLOC_t));
-      dci_cnt++;
-    }
-  }
-
 
-  return(dci_cnt);
-}
-#endif
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c
index 1d992b096a8cdc672e887bae549e2f2fec343eee..52594f9fd22e52d0bb429d557bc3982d692dc6fc 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c
@@ -53,7 +53,6 @@ int cnt=0;
 
 int nr_pbch_detection(PHY_VARS_NR_UE *ue, runmode_t mode)
 {
-  printf("nr pbch detec RB_DL %d\n", ue->frame_parms.N_RB_DL);
   NR_DL_FRAME_PARMS *frame_parms=&ue->frame_parms;
   int ret =-1;
 
@@ -62,53 +61,54 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, runmode_t mode)
         ue->rx_offset);
 #endif
 
+  // save the nb_prefix_samples0 since we are not synchronized to subframes yet and the SSB has all symbols with nb_prefix_samples
   int nb_prefix_samples0 = frame_parms->nb_prefix_samples0;
-  frame_parms->nb_prefix_samples0 = 0;
+  frame_parms->nb_prefix_samples0 = frame_parms->nb_prefix_samples;
 
   //symbol 1
   nr_slot_fep(ue,
-    	   5,
-    	   0,
-    	   ue->rx_offset,
-    	   0,
-    	   1,
-		   NR_PBCH_EST);
-
+	      1,
+	      0,
+	      ue->ssb_offset,
+	      0,
+	      1,
+	      NR_PBCH_EST);
+  
   //symbol 2
   nr_slot_fep(ue,
-    	   6,
-    	   0,
-    	   ue->rx_offset,
-    	   0,
-    	   1,
-		   NR_PBCH_EST);
+	      2,
+	      0,
+	      ue->ssb_offset,
+	      0,
+	      1,
+	      NR_PBCH_EST);
 
   //symbol 3
   nr_slot_fep(ue,
-    	   7,
-    	   0,
-    	   ue->rx_offset,
-    	   0,
-    	   1,
-		   NR_PBCH_EST);
-
+	      3,
+	      0,
+	      ue->ssb_offset,
+	      0,
+	      1,
+	      NR_PBCH_EST);
+
+  //put back nb_prefix_samples0
   frame_parms->nb_prefix_samples0 = nb_prefix_samples0;
-
-  printf("pbch_detection nid_cell %d\n",frame_parms->Nid_cell);
   
-    ret = nr_rx_pbch(ue,
-						  &ue->proc.proc_rxtx[0],
-                          ue->pbch_vars[0],
-                          frame_parms,
-                          0,
-                          SISO,
-                          ue->high_speed_flag);
-
-
+  
+  ret = nr_rx_pbch(ue,
+		   &ue->proc.proc_rxtx[0],
+		   ue->pbch_vars[0],
+		   frame_parms,
+		   0,
+		   SISO,
+		   ue->high_speed_flag);
+  
+  
   if (ret==0) {
-
+    
     frame_parms->nb_antenna_ports_eNB = 1; //pbch_tx_ant;
-
+    
     // set initial transmission mode to 1 or 2 depending on number of detected TX antennas
     //frame_parms->mode1_flag = (pbch_tx_ant==1);
     // openair_daq_vars.dlsch_transmission_mode = (pbch_tx_ant>1) ? 2 : 1;
@@ -145,29 +145,22 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode)
 {
 
   int32_t sync_pos, sync_pos2, sync_pos_slot; // k_ssb, N_ssb_crb,
-  int32_t metric_fdd_ncp=0;
-  uint8_t phase_fdd_ncp;
+  int32_t metric_tdd_ncp=0;
+  uint8_t phase_tdd_ncp;
 
-  NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
+  NR_DL_FRAME_PARMS *fp = &ue->frame_parms;
   int ret=-1;
   int rx_power=0; //aarx,
   //nfapi_nr_config_request_t* config;
 
-  /*offset parameters to be updated from higher layer */
-  //k_ssb =0;
-  //N_ssb_crb = 0;
-
-  /*#ifdef OAI_USRP
-  __m128i *rxdata128;
-  #endif*/
-  //  LOG_I(PHY,"**************************************************************\n");
-  // First try FDD normal prefix
-  frame_parms->Ncp=NORMAL;
-  frame_parms->frame_type=TDD;
-  nr_init_frame_parms_ue(frame_parms);
-  LOG_D(PHY,"nr_initial sync ue RB_DL %d\n", ue->frame_parms.N_RB_DL);
+  int n_ssb_crb=(fp->N_RB_DL-20)>>1;
+  // First try TDD normal prefix, mu 1
+  fp->Ncp=NORMAL;
+  fp->frame_type=TDD;
+  nr_init_frame_parms_ue(fp,NR_MU_1,NORMAL,n_ssb_crb,0);
+  LOG_D(PHY,"nr_initial sync ue RB_DL %d\n", fp->N_RB_DL);
   /*
-  write_output("rxdata0.m","rxd0",ue->common_vars.rxdata[0],10*frame_parms->samples_per_tti,1,1);
+  write_output("rxdata0.m","rxd0",ue->common_vars.rxdata[0],10*fp->samples_per_tti,1,1);
   exit(-1);
   */
 
@@ -183,54 +176,51 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode)
   *                     --------------------------
   *          sync_pos            SS/PBCH block
   */
-  cnt++;
-  if (cnt >100){
-  	  cnt =0;
-  /* process pss search on received buffer */
-  sync_pos = pss_synchro_nr(ue, NO_RATE_CHANGE);
 
-  sync_pos_slot = (frame_parms->samples_per_tti>>1) - 3*(frame_parms->ofdm_symbol_size + frame_parms->nb_prefix_samples);
 
-  if (sync_pos >= frame_parms->nb_prefix_samples)
-      sync_pos2 = sync_pos - frame_parms->nb_prefix_samples;
-    else
-      sync_pos2 = sync_pos + FRAME_LENGTH_COMPLEX_SAMPLES - frame_parms->nb_prefix_samples;
+  cnt++;
+  if (1){ // (cnt>100)
+    cnt =0;
 
-  /* offset is used by sss serach as it is returned from pss search */
-  if (sync_pos2 >= sync_pos_slot)
-      ue->rx_offset = sync_pos2 - sync_pos_slot;
-    else
-      ue->rx_offset = FRAME_LENGTH_COMPLEX_SAMPLES + sync_pos2 - sync_pos_slot;
+  /* process pss search on received buffer */
+  sync_pos = pss_synchro_nr(ue, NO_RATE_CHANGE);
 
-  LOG_D(PHY,"sync_pos %d sync_pos_slot %d rx_offset %d\n",sync_pos,sync_pos_slot, ue->rx_offset);
+  
+  if (sync_pos >= fp->nb_prefix_samples)
+      ue->ssb_offset = sync_pos - fp->nb_prefix_samples;
+  else
+    ue->ssb_offset = sync_pos + (fp->samples_per_tti * 10) - fp->nb_prefix_samples;
+  
+  LOG_D(PHY,"sync_pos %d ssb_offset %d\n",sync_pos,ue->ssb_offset);
 
 
-  //  write_output("rxdata1.m","rxd1",ue->common_vars.rxdata[0],10*frame_parms->samples_per_tti,1,1);
+  //  write_output("rxdata1.m","rxd1",ue->common_vars.rxdata[0],10*fp->samples_per_tti,1,1);
 
 #ifdef DEBUG_INITIAL_SYNCH
   LOG_I(PHY,"[UE%d] Initial sync : Estimated PSS position %d, Nid2 %d\n", ue->Mod_id, sync_pos,ue->common_vars.eNb_id);
 #endif
 
   /* check that SSS/PBCH block is continuous inside the received buffer */
-  if (sync_pos < (LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->ttis_per_subframe*frame_parms->samples_per_tti - (NB_SYMBOLS_PBCH * frame_parms->ofdm_symbol_size))) {
+  if (sync_pos < (10*fp->ttis_per_subframe*fp->samples_per_tti - (NB_SYMBOLS_PBCH * fp->ofdm_symbol_size))) {
 
 #ifdef DEBUG_INITIAL_SYNCH
     LOG_I(PHY,"Calling sss detection (normal CP)\n");
 #endif
 
-    rx_sss_nr(ue,&metric_fdd_ncp,&phase_fdd_ncp);
+    rx_sss_nr(ue,&metric_tdd_ncp,&phase_tdd_ncp);
 
-    nr_init_frame_parms_ue(&ue->frame_parms);
+    nr_init_frame_parms_ue(fp,NR_MU_1,NORMAL,n_ssb_crb,0);
 
     nr_gold_pbch(ue);
     ret = nr_pbch_detection(ue,mode);
     
     nr_gold_pdcch(ue,0, 2);
+    /*
     int nb_prefix_samples0 = frame_parms->nb_prefix_samples0;
-	frame_parms->nb_prefix_samples0 = 0;
-  
-    nr_slot_fep(ue,0, 0, ue->rx_offset, 0, 1, NR_PDCCH_EST);
-    nr_slot_fep(ue,1, 0, ue->rx_offset, 0, 1, NR_PDCCH_EST);
+    frame_parms->nb_prefix_samples0 = frame_parms->nb_prefix_samples.
+	  
+    nr_slot_fep(ue,0, 0, ue->ssb_offset, 0, 1, NR_PDCCH_EST);
+    nr_slot_fep(ue,1, 0, ue->ssb_offset, 0, 1, NR_PDCCH_EST);
     frame_parms->nb_prefix_samples0 = nb_prefix_samples0;	
 
     LOG_I(PHY,"[UE  %d] AUTOTEST Cell Sync : frame = %d, rx_offset %d, freq_offset %d \n",
@@ -238,18 +228,16 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode)
               ue->proc.proc_rxtx[0].frame_rx,
               ue->rx_offset,
               ue->common_vars.freq_offset );
-
-    //ret = -1;  //to be deleted
-    //   write_output("rxdata2.m","rxd2",ue->common_vars.rxdata[0],10*frame_parms->samples_per_tti,1,1);
+    */
 
 #ifdef DEBUG_INITIAL_SYNCH
-    LOG_I(PHY,"FDD Normal prefix: CellId %d metric %d, phase %d, flip %d, pbch %d\n",
-          frame_parms->Nid_cell,metric_fdd_ncp,phase_fdd_ncp,flip_fdd_ncp,ret);
+    LOG_I(PHY,"TDD Normal prefix: CellId %d metric %d, phase %d, flip %d, pbch %d\n",
+          frame_parms->Nid_cell,metric_tdd_ncp,phase_tdd_ncp,flip_tdd_ncp,ret);
 #endif
   }
   else {
 #ifdef DEBUG_INITIAL_SYNCH
-    LOG_I(PHY,"FDD Normal prefix: SSS error condition: sync_pos %d, sync_pos_slot %d\n", sync_pos, sync_pos_slot);
+    LOG_I(PHY,"TDD Normal prefix: SSS error condition: sync_pos %d, sync_pos_slot %d\n", sync_pos, sync_pos_slot);
 #endif
   }
   }
@@ -289,17 +277,6 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode)
     #endif
 
 // send sync status to higher layers later when timing offset converge to target timing
-#if OAISIM
-      if (ue->mac_enabled==1) {
-	LOG_I(PHY,"[UE%d] Sending synch status to higher layers\n",ue->Mod_id);
-	//mac_resynch();
-	mac_xface->dl_phy_sync_success(ue->Mod_id,ue->proc.proc_rxtx[0].frame_rx,0,1);//ue->common_vars.eNb_id);
-	ue->UE_mode[0] = PRACH;
-      }
-      else {
-	ue->UE_mode[0] = PUSCH;
-      }
-#endif
 
       ue->pbch_vars[0]->pdu_errors_conseq=0;
 
@@ -319,13 +296,13 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode)
     printf("[UE %d] Frame %d MIB Information => %s, %s, NidCell %d, N_RB_DL %d, PHICH DURATION %d, PHICH RESOURCE %s, TX_ANT %d\n",
 	  ue->Mod_id,
 	  ue->proc.proc_rxtx[0].frame_rx,
-	  duplex_string[ue->frame_parms.frame_type],
-	  prefix_string[ue->frame_parms.Ncp],
-	  ue->frame_parms.Nid_cell,
-	  ue->frame_parms.N_RB_DL,
-	  ue->frame_parms.phich_config_common.phich_duration,
-	  phich_string[ue->frame_parms.phich_config_common.phich_resource],
-	  ue->frame_parms.nb_antenna_ports_eNB);
+	  duplex_string[fp->frame_type],
+	  prefix_string[fp->Ncp],
+	  fp->Nid_cell,
+	  fp->N_RB_DL,
+	  fp->phich_config_common.phich_duration,
+	  phich_string[fp->phich_config_common.phich_resource],
+	  fp->nb_antenna_ports_eNB);
 #else
     LOG_I(PHY, "[UE %d] Frame %d RRC Measurements => rssi %3.1f dBm (dig %3.1f dB, gain %d), N0 %d dBm,  rsrp %3.1f dBm/RE, rsrq %3.1f dB\n",ue->Mod_id,
 	  ue->proc.proc_rxtx[0].frame_rx,
@@ -339,13 +316,13 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode)
 /*    LOG_I(PHY, "[UE %d] Frame %d MIB Information => %s, %s, NidCell %d, N_RB_DL %d, PHICH DURATION %d, PHICH RESOURCE %s, TX_ANT %d\n",
 	  ue->Mod_id,
 	  ue->proc.proc_rxtx[0].frame_rx,
-	  duplex_string[ue->frame_parms.frame_type],
-	  prefix_string[ue->frame_parms.Ncp],
-	  ue->frame_parms.Nid_cell,
-	  ue->frame_parms.N_RB_DL,
-	  ue->frame_parms.phich_config_common.phich_duration,
-	  phich_string[ue->frame_parms.phich_config_common.phich_resource],
-	  ue->frame_parms.nb_antenna_ports_eNB);*/
+	  duplex_string[fp->frame_type],
+	  prefix_string[fp->Ncp],
+	  fp->Nid_cell,
+	  fp->N_RB_DL,
+	  fp->phich_config_common.phich_duration,
+	  phich_string[fp->phich_config_common.phich_resource],
+	  fp->nb_antenna_ports_eNB);*/
 #endif
 
 #if defined(OAI_USRP) || defined(EXMIMO) || defined(OAI_BLADERF) || defined(OAI_LMSSDR) || defined(OAI_ADRV9371_ZC706)
@@ -367,12 +344,6 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode)
 #ifdef DEBUG_INITIAL_SYNC
     LOG_I(PHY,"[UE%d] Initial sync : PBCH not ok\n",ue->Mod_id);
     LOG_I(PHY,"[UE%d] Initial sync : Estimated PSS position %d, Nid2 %d\n",ue->Mod_id,sync_pos,ue->common_vars.eNb_id);
-    /*      LOG_I(PHY,"[UE%d] Initial sync: (metric fdd_ncp %d (%d), metric fdd_ecp %d (%d), metric_tdd_ncp %d (%d), metric_tdd_ecp %d (%d))\n",
-          ue->Mod_id,
-          metric_fdd_ncp,Nid_cell_fdd_ncp,
-          metric_fdd_ecp,Nid_cell_fdd_ecp,
-          metric_tdd_ncp,Nid_cell_tdd_ncp,
-          metric_tdd_ecp,Nid_cell_tdd_ecp);*/
     LOG_I(PHY,"[UE%d] Initial sync : Estimated Nid_cell %d, Frame_type %d\n",ue->Mod_id,
           frame_parms->Nid_cell,frame_parms->frame_type);
 #endif
@@ -401,7 +372,7 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode)
     */
 
     // we might add a low-pass filter here later
-    ue->measurements.rx_power_avg[0] = rx_power/frame_parms->nb_antennas_rx;
+    ue->measurements.rx_power_avg[0] = rx_power/fp->nb_antennas_rx;
 
     ue->measurements.rx_power_avg_dB[0] = dB_fixed(ue->measurements.rx_power_avg[0]);
 
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c
index 24641a6e6a6f4f69ee043a0658d724e8f9a0a6d3..747f3de769e6ce4a5c5ccecc44944fc85e8aa597 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c
@@ -44,31 +44,42 @@
 
 #define PBCH_A 24
 
+#define print_shorts(s,x) printf("%s : %d,%d,%d,%d,%d,%d,%d,%d\n",s,((int16_t*)x)[0],((int16_t*)x)[1],((int16_t*)x)[2],((int16_t*)x)[3],((int16_t*)x)[4],((int16_t*)x)[5],((int16_t*)x)[6],((int16_t*)x)[7])
 
 uint16_t nr_pbch_extract(int **rxdataF,
-                      int **dl_ch_estimates,
-                      int **rxdataF_ext,
-                      int **dl_ch_estimates_ext,
-                      uint32_t symbol,
-                      uint32_t high_speed_flag,
-                      NR_DL_FRAME_PARMS *frame_parms)
+			 int **dl_ch_estimates,
+			 int **rxdataF_ext,
+			 int **dl_ch_estimates_ext,
+			 uint32_t symbol,
+			 uint32_t high_speed_flag,
+			 int is_synchronized,
+			 NR_DL_FRAME_PARMS *frame_parms)
 {
 
 
   uint16_t rb;
-  uint8_t i,j,aarx,aatx;
+  uint8_t i,j,aarx;
   int32_t *dl_ch0,*dl_ch0_ext,*rxF,*rxF_ext;
 
-  int rx_offset = frame_parms->ofdm_symbol_size-10*12;
   int nushiftmod4 = frame_parms->nushift;
 
+  unsigned int  rx_offset = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier; //and
+  if (rx_offset>= frame_parms->ofdm_symbol_size) rx_offset-=frame_parms->ofdm_symbol_size;
+  int s_offset=0;
+ 
+  AssertFatal(symbol>=1 && symbol<5, 
+	      "symbol %d illegal for PBCH extraction\n",
+	      symbol);
+
+  if (is_synchronized==1) s_offset=4;
+
   for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
         
-    rxF        = &rxdataF[aarx][(rx_offset + (symbol*(frame_parms->ofdm_symbol_size)))];
-    rxF_ext    = &rxdataF_ext[aarx][symbol*(20*12)];
+    rxF        = &rxdataF[aarx][(symbol+s_offset)*frame_parms->ofdm_symbol_size];
+    rxF_ext    = &rxdataF_ext[aarx][(symbol+s_offset)*(20*12)];
 #ifdef DEBUG_PBCH
      printf("extract_rbs (nushift %d): rx_offset=%d, symbol %d\n",frame_parms->nushift,
-     (rx_offset + (symbol*(frame_parms->ofdm_symbol_size))),symbol);
+	    (rx_offset + ((symbol+s_offset)*(frame_parms->ofdm_symbol_size))),symbol);
      int16_t *p = (int16_t *)rxF;
      for (int i =0; i<8;i++){
         printf("rxF [%d]= %d\n",i,rxF[i]);
@@ -78,89 +89,109 @@ uint16_t nr_pbch_extract(int **rxdataF,
 #endif
 
     for (rb=0; rb<20; rb++) {
-      if (rb==10) {
-        rxF       = &rxdataF[aarx][((symbol*(frame_parms->ofdm_symbol_size)))];
-      }
-
       j=0;
-      if ((symbol==5) || (symbol==7)) {
+
+      if (symbol==1 || symbol==7) {
         for (i=0; i<12; i++) {
           if ((i!=nushiftmod4) &&
               (i!=(nushiftmod4+4)) &&
               (i!=(nushiftmod4+8))) {
-            rxF_ext[j]=rxF[i];
-	    //printf("rxF ext[%d] = %d rxF [%d]= %d\n",j,rxF_ext[j],i,rxF[i]);
+            rxF_ext[j]=rxF[rx_offset];
+#ifdef DEBUG_PBCH
+	    printf("rxF ext[%d] = (%d,%d) rxF [%d]= (%d,%d)\n",(9*rb) + j,
+		   ((int16_t*)&rxF_ext[j])[0],
+		   ((int16_t*)&rxF_ext[j])[1],
+		   rx_offset,
+		   ((int16_t*)&rxF[rx_offset])[0],
+		   ((int16_t*)&rxF[rx_offset])[1]);
+#endif
 	    j++;
           }
+	  rx_offset=(rx_offset+1)&(frame_parms->ofdm_symbol_size-1);
         }
-
-        rxF+=12;
         rxF_ext+=9;
       } else { //symbol 2
     	if ((rb < 4) || (rb >15)){
     	  for (i=0; i<12; i++) {
-        	if ((i!=nushiftmod4) &&
-        	    (i!=(nushiftmod4+4)) &&
-        	    (i!=(nushiftmod4+8))) {
-        	  rxF_ext[j]=rxF[i];
-		  //printf("symbol2 rxF ext[%d] = %d at %p\n",j,rxF_ext[j],&rxF[i]);
-		  j++;
-        	}
+	    if ((i!=nushiftmod4) &&
+		(i!=(nushiftmod4+4)) &&
+		(i!=(nushiftmod4+8))) {
+	      rxF_ext[j]=rxF[rx_offset];
+#ifdef DEBUG_PBCH
+	      printf("rxF ext[%d] = (%d,%d) rxF [%d]= (%d,%d)\n",(rb<4) ? (9*rb) + j : (9*(rb-12))+j,
+		     ((int16_t*)&rxF_ext[j])[0],
+		     ((int16_t*)&rxF_ext[j])[1],
+		     rx_offset,
+		     ((int16_t*)&rxF[rx_offset])[0],
+		     ((int16_t*)&rxF[rx_offset])[1]);
+#endif    
+	      j++;
+	    }
+	    rx_offset=(rx_offset+1)&(frame_parms->ofdm_symbol_size-1);
     	  }
+	  rxF_ext+=9;
 	}
-
-        rxF+=12;
-        rxF_ext+=9;
+	else rx_offset = (rx_offset+12)&(frame_parms->ofdm_symbol_size-1);
+        
       }
     }
 
-    for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB;aatx++) {
-      if (high_speed_flag == 1)
-        dl_ch0     = &dl_ch_estimates[(aatx<<1)+aarx][(symbol*(frame_parms->ofdm_symbol_size))];
-      else
-        dl_ch0     = &dl_ch_estimates[(aatx<<1)+aarx][0];
-
-      //printf("dl_ch0 addr %p\n",dl_ch0);
-
-      dl_ch0_ext = &dl_ch_estimates_ext[(aatx<<1)+aarx][symbol*(20*12)];
-
-      for (rb=0; rb<20; rb++) {
-	j=0;
-        if ((symbol==5) || (symbol==7)) {
-              	  for (i=0; i<12; i++) {
-                    if ((i!=nushiftmod4) &&
-                        (i!=(nushiftmod4+4)) &&
-                        (i!=(nushiftmod4+8))) {
-                           dl_ch0_ext[j]=dl_ch0[i];
-			   if ((rb==0) && (i<2))
-			     printf("dl ch0 ext[%d] = %d dl_ch0 [%d]= %d\n",j,dl_ch0_ext[j],i,dl_ch0[i]);
-		           j++;
-                    }
-          	  }
-
-          dl_ch0+=12;
-          dl_ch0_ext+=9;
-        }
-        else { 
-              if ((rb < 4) || (rb >15)){
-              	  for (i=0; i<12; i++) {
-                    if ((i!=nushiftmod4) &&
-                        (i!=(nushiftmod4+4)) &&
-                        (i!=(nushiftmod4+8))) {
-		           dl_ch0_ext[j]=dl_ch0[i];
-			   //printf("symbol2 dl ch0 ext[%d] = %d dl_ch0 [%d]= %d\n",j,dl_ch0_ext[j],i,dl_ch0[i]);
-			   j++;
-                       	}
-               	  }
-              }
-
-              dl_ch0+=12;
-              dl_ch0_ext+=9;
-
-         }
+    if (high_speed_flag == 1)
+      dl_ch0     = &dl_ch_estimates[aarx][((symbol+s_offset)*(frame_parms->ofdm_symbol_size))];
+    else
+      dl_ch0     = &dl_ch_estimates[aarx][0];
+    
+    //printf("dl_ch0 addr %p\n",dl_ch0);
+    
+    dl_ch0_ext = &dl_ch_estimates_ext[aarx][(symbol+s_offset)*(20*12)];
+    
+    for (rb=0; rb<20; rb++) {
+      j=0;
+      if (symbol==1 || symbol==7) {
+	for (i=0; i<12; i++) {
+	  if ((i!=nushiftmod4) &&
+	      (i!=(nushiftmod4+4)) &&
+	      (i!=(nushiftmod4+8))) {
+	    dl_ch0_ext[j]=dl_ch0[i];
+#ifdef DEBUG_PBCH
+	    if ((rb==0) && (i<2))
+	      printf("dl ch0 ext[%d] = (%d,%d)  dl_ch0 [%d]= (%d,%d)\n",j,
+		     ((int16_t*)&dl_ch0_ext[j])[0],
+		     ((int16_t*)&dl_ch0_ext[j])[1],
+		     i,
+		     ((int16_t*)&dl_ch0[i])[0],
+		     ((int16_t*)&dl_ch0[i])[1]);
+#endif
+	    j++;
+	  }
+	}
+	
+	dl_ch0+=12;
+	dl_ch0_ext+=9;
       }
-    }  //tx antenna loop
-
+      else { 
+	if ((rb < 4) || (rb >15)){
+	  for (i=0; i<12; i++) {
+	    if ((i!=nushiftmod4) &&
+		(i!=(nushiftmod4+4)) &&
+		(i!=(nushiftmod4+8))) {
+	      dl_ch0_ext[j]=dl_ch0[i];
+#ifdef DEBUG_PBCH
+	      printf("dl ch0 ext[%d] = (%d,%d)  dl_ch0 [%d]= (%d,%d)\n",j,
+		     ((int16_t*)&dl_ch0_ext[j])[0],
+		     ((int16_t*)&dl_ch0_ext[j])[1],
+		     i,
+		     ((int16_t*)&dl_ch0[i])[0],
+		     ((int16_t*)&dl_ch0[i])[1]);
+#endif
+	      j++;
+	    }
+	  }
+	  dl_ch0_ext+=9;
+	}
+	dl_ch0+=12;
+      }
+    }
   }
 
   return(0);
@@ -170,12 +201,12 @@ uint16_t nr_pbch_extract(int **rxdataF,
 
 //compute average channel_level on each (TX,RX) antenna pair
 int nr_pbch_channel_level(int **dl_ch_estimates_ext,
-                       NR_DL_FRAME_PARMS *frame_parms,
-                       uint32_t symbol)
+			  NR_DL_FRAME_PARMS *frame_parms,
+			  uint32_t symbol)
 {
 
   int16_t rb, nb_rb=20;
-  uint8_t aatx,aarx;
+  uint8_t aarx;
 
 #if defined(__x86_64__) || defined(__i386__)
   __m128i avg128;
@@ -186,46 +217,45 @@ int nr_pbch_channel_level(int **dl_ch_estimates_ext,
 #endif
   int avg1=0,avg2=0;
 
-  for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB;aatx++)
-    for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
-      //clear average level
-
+  for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
+    //clear average level
+    
 #if defined(__x86_64__) || defined(__i386__)
-      avg128 = _mm_setzero_si128();
-      dl_ch128=(__m128i *)&dl_ch_estimates_ext[(aatx<<1)+aarx][symbol*20*12];
+    avg128 = _mm_setzero_si128();
+    dl_ch128=(__m128i *)&dl_ch_estimates_ext[aarx][symbol*20*12];
 #elif defined(__arm__)
-      avg128 = vdupq_n_s32(0);
-      dl_ch128=(int16x8_t *)&dl_ch_estimates_ext[(aatx<<1)+aarx][symbol*20*12];
-
+    avg128 = vdupq_n_s32(0);
+    dl_ch128=(int16x8_t *)&dl_ch_estimates_ext[aarx][symbol*20*12];
+    
 #endif
-      for (rb=0; rb<nb_rb; rb++) {
+    for (rb=0; rb<nb_rb; rb++) {
 #if defined(__x86_64__) || defined(__i386__)
-        avg128 = _mm_add_epi32(avg128,_mm_madd_epi16(dl_ch128[0],dl_ch128[0]));
-        avg128 = _mm_add_epi32(avg128,_mm_madd_epi16(dl_ch128[1],dl_ch128[1]));
-        avg128 = _mm_add_epi32(avg128,_mm_madd_epi16(dl_ch128[2],dl_ch128[2]));
+      avg128 = _mm_add_epi32(avg128,_mm_madd_epi16(dl_ch128[0],dl_ch128[0]));
+      avg128 = _mm_add_epi32(avg128,_mm_madd_epi16(dl_ch128[1],dl_ch128[1]));
+      avg128 = _mm_add_epi32(avg128,_mm_madd_epi16(dl_ch128[2],dl_ch128[2]));
 #elif defined(__arm__)
 // to be filled in
 #endif
-        dl_ch128+=3;
-        /*
-          if (rb==0) {
-          print_shorts("dl_ch128",&dl_ch128[0]);
-          print_shorts("dl_ch128",&dl_ch128[1]);
-          print_shorts("dl_ch128",&dl_ch128[2]);
-          }
-        */
-      }
-
-      avg1 = (((int*)&avg128)[0] +
-              ((int*)&avg128)[1] +
-              ((int*)&avg128)[2] +
-              ((int*)&avg128)[3])/(nb_rb*12);
-
-      if (avg1>avg2)
-        avg2 = avg1;
-
-      //msg("Channel level : %d, %d\n",avg1, avg2);
+      dl_ch128+=3;
+      /*
+      if (rb==0) {
+	print_shorts("dl_ch128",&dl_ch128[0]);
+	print_shorts("dl_ch128",&dl_ch128[1]);
+	print_shorts("dl_ch128",&dl_ch128[2]);
+	}*/
+      
     }
+    
+    avg1 = (((int*)&avg128)[0] +
+	    ((int*)&avg128)[1] +
+	    ((int*)&avg128)[2] +
+	    ((int*)&avg128)[3])/(nb_rb*12);
+    
+    if (avg1>avg2)
+      avg2 = avg1;
+    
+    //LOG_I(PHY,"Channel level : %d, %d\n",avg1, avg2);
+  }
 #if defined(__x86_64__) || defined(__i386__)
   _mm_empty();
   _m_empty();
@@ -234,111 +264,127 @@ int nr_pbch_channel_level(int **dl_ch_estimates_ext,
 
 }
 
+void nr_pbch_channel_compensation(int **rxdataF_ext,
+				  int **dl_ch_estimates_ext,
+				  int **rxdataF_comp,
+				  NR_DL_FRAME_PARMS *frame_parms,
+				  uint8_t symbol,
+				  int is_synchronized,
+				  uint8_t output_shift)
+{
+
+  short conjugate[8]__attribute__((aligned(16))) = {-1,1,-1,1,-1,1,-1,1};
+  short conjugate2[8]__attribute__((aligned(16))) = {1,-1,1,-1,1,-1,1,-1};
 #if defined(__x86_64__) || defined(__i386__)
-__m128i mmtmpP0,mmtmpP1,mmtmpP2,mmtmpP3;
+  __m128i mmtmpP0,mmtmpP1,mmtmpP2,mmtmpP3;
 #elif defined(__arm__)
-int16x8_t mmtmpP0,mmtmpP1,mmtmpP2,mmtmpP3;
+  int16x8_t mmtmpP0,mmtmpP1,mmtmpP2,mmtmpP3;
 #endif
-void nr_pbch_channel_compensation(int **rxdataF_ext,
-                               int **dl_ch_estimates_ext,
-                               int **rxdataF_comp,
-                               NR_DL_FRAME_PARMS *frame_parms,
-                               uint8_t symbol,
-                               uint8_t output_shift)
-{
 
-  uint16_t rb,nb_rb=20;
-  uint8_t aatx,aarx;
+  uint16_t nb_re=180;
+  uint8_t aarx;
 #if defined(__x86_64__) || defined(__i386__)
   __m128i *dl_ch128,*rxdataF128,*rxdataF_comp128;
 #elif defined(__arm__)
 
 #endif
 
-  for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB;aatx++)
-    for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
+  AssertFatal((symbol > 0 && symbol < 4 && is_synchronized == 0) || 
+	      (symbol > 4 && symbol < 8 && is_synchronized == 1),
+	      "symbol %d is illegal for PBCH DM-RS (is_synchronized %d)\n",
+	      symbol,is_synchronized);
 
-#if defined(__x86_64__) || defined(__i386__)
-      dl_ch128          = (__m128i *)&dl_ch_estimates_ext[(aatx<<1)+aarx][symbol*20*12];
-      rxdataF128        = (__m128i *)&rxdataF_ext[aarx][symbol*20*12];
-      rxdataF_comp128   = (__m128i *)&rxdataF_comp[(aatx<<1)+aarx][symbol*20*12];
-      //printf("ch compensation dl_ch ext addr %p \n", &dl_ch_estimates_ext[(aatx<<1)+aarx][symbol*20*12]);
-      //printf("rxdataf ext addr %p symbol %d\n", &rxdataF_ext[aarx][symbol*20*12], symbol);
-      //printf("rxdataf_comp addr %p\n",&rxdataF_comp[(aatx<<1)+aarx][symbol*20*12]); 
 
+
+  if (symbol == 2 || symbol == 6) nb_re = 72;
+
+  //  printf("comp: symbol %d : nb_re %d\n",symbol,nb_re);
+
+  for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
+    
+#if defined(__x86_64__) || defined(__i386__)
+    dl_ch128          = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*20*12];
+    rxdataF128        = (__m128i *)&rxdataF_ext[aarx][symbol*20*12];
+    rxdataF_comp128   = (__m128i *)&rxdataF_comp[aarx][symbol*20*12];
+    /*
+    printf("ch compensation dl_ch ext addr %p \n", &dl_ch_estimates_ext[aarx][symbol*20*12]);
+    printf("rxdataf ext addr %p symbol %d\n", &rxdataF_ext[aarx][symbol*20*12], symbol);
+    printf("rxdataf_comp addr %p\n",&rxdataF_comp[aarx][symbol*20*12]); 
+    */
 #elif defined(__arm__)
 // to be filled in
 #endif
 
-      for (rb=0; rb<nb_rb; rb++) {
-        //printf("rb %d\n",rb);
+    for (int re=0; re<nb_re; re+=12) {
+      //            printf("******re %d\n",re);
 #if defined(__x86_64__) || defined(__i386__)
-        // multiply by conjugated channel
-        mmtmpP0 = _mm_madd_epi16(dl_ch128[0],rxdataF128[0]);
-        //  print_ints("re",&mmtmpP0);
-        // mmtmpP0 contains real part of 4 consecutive outputs (32-bit)
-        mmtmpP1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1));
-        mmtmpP1 = _mm_shufflehi_epi16(mmtmpP1,_MM_SHUFFLE(2,3,0,1));
-        mmtmpP1 = _mm_sign_epi16(mmtmpP1,*(__m128i*)&conjugate[0]);
-        //  print_ints("im",&mmtmpP1);
-        mmtmpP1 = _mm_madd_epi16(mmtmpP1,rxdataF128[0]);
-        // mmtmpP1 contains imag part of 4 consecutive outputs (32-bit)
-        mmtmpP0 = _mm_srai_epi32(mmtmpP0,output_shift);
-        //  print_ints("re(shift)",&mmtmpP0);
-        mmtmpP1 = _mm_srai_epi32(mmtmpP1,output_shift);
-        //  print_ints("im(shift)",&mmtmpP1);
-        mmtmpP2 = _mm_unpacklo_epi32(mmtmpP0,mmtmpP1);
-        mmtmpP3 = _mm_unpackhi_epi32(mmtmpP0,mmtmpP1);
-        //      print_ints("c0",&mmtmpP2);
-        //  print_ints("c1",&mmtmpP3);
-        rxdataF_comp128[0] = _mm_packs_epi32(mmtmpP2,mmtmpP3);
-        //  print_shorts("rx:",rxdataF128);
-        //  print_shorts("ch:",dl_ch128);
-        //  print_shorts("pack:",rxdataF_comp128);
-
-        // multiply by conjugated channel
-        mmtmpP0 = _mm_madd_epi16(dl_ch128[1],rxdataF128[1]);
-        // mmtmpP0 contains real part of 4 consecutive outputs (32-bit)
-        mmtmpP1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1));
-        mmtmpP1 = _mm_shufflehi_epi16(mmtmpP1,_MM_SHUFFLE(2,3,0,1));
-        mmtmpP1 = _mm_sign_epi16(mmtmpP1,*(__m128i*)&conjugate[0]);
-        mmtmpP1 = _mm_madd_epi16(mmtmpP1,rxdataF128[1]);
-        // mmtmpP1 contains imag part of 4 consecutive outputs (32-bit)
-        mmtmpP0 = _mm_srai_epi32(mmtmpP0,output_shift);
-        mmtmpP1 = _mm_srai_epi32(mmtmpP1,output_shift);
-        mmtmpP2 = _mm_unpacklo_epi32(mmtmpP0,mmtmpP1);
-        mmtmpP3 = _mm_unpackhi_epi32(mmtmpP0,mmtmpP1);
-        rxdataF_comp128[1] = _mm_packs_epi32(mmtmpP2,mmtmpP3);
-        //  print_shorts("rx:",rxdataF128+1);
-        //  print_shorts("ch:",dl_ch128+1);
-        //  print_shorts("pack:",rxdataF_comp128+1);
-
-          // multiply by conjugated channel
-          mmtmpP0 = _mm_madd_epi16(dl_ch128[2],rxdataF128[2]);
-          // mmtmpP0 contains real part of 4 consecutive outputs (32-bit)
-          mmtmpP1 = _mm_shufflelo_epi16(dl_ch128[2],_MM_SHUFFLE(2,3,0,1));
-          mmtmpP1 = _mm_shufflehi_epi16(mmtmpP1,_MM_SHUFFLE(2,3,0,1));
-          mmtmpP1 = _mm_sign_epi16(mmtmpP1,*(__m128i*)&conjugate[0]);
-          mmtmpP1 = _mm_madd_epi16(mmtmpP1,rxdataF128[2]);
-          // mmtmpP1 contains imag part of 4 consecutive outputs (32-bit)
-          mmtmpP0 = _mm_srai_epi32(mmtmpP0,output_shift);
-          mmtmpP1 = _mm_srai_epi32(mmtmpP1,output_shift);
-          mmtmpP2 = _mm_unpacklo_epi32(mmtmpP0,mmtmpP1);
-          mmtmpP3 = _mm_unpackhi_epi32(mmtmpP0,mmtmpP1);
-          rxdataF_comp128[2] = _mm_packs_epi32(mmtmpP2,mmtmpP3);
-          //  print_shorts("rx:",rxdataF128+2);
-          //  print_shorts("ch:",dl_ch128+2);
-          //      print_shorts("pack:",rxdataF_comp128+2);
-
-          dl_ch128+=3;
-          rxdataF128+=3;
-          rxdataF_comp128+=3;
-        
+      // multiply by conjugated channel
+      mmtmpP0 = _mm_madd_epi16(dl_ch128[0],rxdataF128[0]);
+      //  print_ints("re",&mmtmpP0);
+      // mmtmpP0 contains real part of 4 consecutive outputs (32-bit)
+      mmtmpP1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1));
+      mmtmpP1 = _mm_shufflehi_epi16(mmtmpP1,_MM_SHUFFLE(2,3,0,1));
+      mmtmpP1 = _mm_sign_epi16(mmtmpP1,*(__m128i*)&conjugate[0]);
+      //  print_ints("im",&mmtmpP1);
+      mmtmpP1 = _mm_madd_epi16(mmtmpP1,rxdataF128[0]);
+      // mmtmpP1 contains imag part of 4 consecutive outputs (32-bit)
+      mmtmpP0 = _mm_srai_epi32(mmtmpP0,output_shift);
+      //  print_ints("re(shift)",&mmtmpP0);
+      mmtmpP1 = _mm_srai_epi32(mmtmpP1,output_shift);
+      //  print_ints("im(shift)",&mmtmpP1);
+      mmtmpP2 = _mm_unpacklo_epi32(mmtmpP0,mmtmpP1);
+      mmtmpP3 = _mm_unpackhi_epi32(mmtmpP0,mmtmpP1);
+      //      print_ints("c0",&mmtmpP2);
+      //  print_ints("c1",&mmtmpP3);
+      rxdataF_comp128[0] = _mm_packs_epi32(mmtmpP2,mmtmpP3);
+      /*
+        print_shorts("rx:",rxdataF128);
+        print_shorts("ch:",dl_ch128);
+        print_shorts("pack:",rxdataF_comp128);
+      */
+      // multiply by conjugated channel
+      mmtmpP0 = _mm_madd_epi16(dl_ch128[1],rxdataF128[1]);
+      // mmtmpP0 contains real part of 4 consecutive outputs (32-bit)
+      mmtmpP1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1));
+      mmtmpP1 = _mm_shufflehi_epi16(mmtmpP1,_MM_SHUFFLE(2,3,0,1));
+      mmtmpP1 = _mm_sign_epi16(mmtmpP1,*(__m128i*)&conjugate[0]);
+      mmtmpP1 = _mm_madd_epi16(mmtmpP1,rxdataF128[1]);
+      // mmtmpP1 contains imag part of 4 consecutive outputs (32-bit)
+      mmtmpP0 = _mm_srai_epi32(mmtmpP0,output_shift);
+      mmtmpP1 = _mm_srai_epi32(mmtmpP1,output_shift);
+      mmtmpP2 = _mm_unpacklo_epi32(mmtmpP0,mmtmpP1);
+      mmtmpP3 = _mm_unpackhi_epi32(mmtmpP0,mmtmpP1);
+      rxdataF_comp128[1] = _mm_packs_epi32(mmtmpP2,mmtmpP3);
+      //  print_shorts("rx:",rxdataF128+1);
+      //  print_shorts("ch:",dl_ch128+1);
+      //  print_shorts("pack:",rxdataF_comp128+1);
+      
+      // multiply by conjugated channel
+      mmtmpP0 = _mm_madd_epi16(dl_ch128[2],rxdataF128[2]);
+      // mmtmpP0 contains real part of 4 consecutive outputs (32-bit)
+      mmtmpP1 = _mm_shufflelo_epi16(dl_ch128[2],_MM_SHUFFLE(2,3,0,1));
+      mmtmpP1 = _mm_shufflehi_epi16(mmtmpP1,_MM_SHUFFLE(2,3,0,1));
+      mmtmpP1 = _mm_sign_epi16(mmtmpP1,*(__m128i*)&conjugate[0]);
+      mmtmpP1 = _mm_madd_epi16(mmtmpP1,rxdataF128[2]);
+      // mmtmpP1 contains imag part of 4 consecutive outputs (32-bit)
+      mmtmpP0 = _mm_srai_epi32(mmtmpP0,output_shift);
+      mmtmpP1 = _mm_srai_epi32(mmtmpP1,output_shift);
+      mmtmpP2 = _mm_unpacklo_epi32(mmtmpP0,mmtmpP1);
+      mmtmpP3 = _mm_unpackhi_epi32(mmtmpP0,mmtmpP1);
+      rxdataF_comp128[2] = _mm_packs_epi32(mmtmpP2,mmtmpP3);
+      //  print_shorts("rx:",rxdataF128+2);
+      //  print_shorts("ch:",dl_ch128+2);
+      //      print_shorts("pack:",rxdataF_comp128+2);
+      
+      dl_ch128+=3;
+      rxdataF128+=3;
+      rxdataF_comp128+=3;
+      
 #elif defined(__arm__)
-// to be filled in
+      // to be filled in
 #endif
-      }
     }
+  }
 #if defined(__x86_64__) || defined(__i386__)
   _mm_empty();
   _m_empty();
@@ -350,7 +396,7 @@ void nr_pbch_detection_mrc(NR_DL_FRAME_PARMS *frame_parms,
                         uint8_t symbol)
 {
 
-  uint8_t aatx, symbol_mod;
+  uint8_t symbol_mod;
   int i, nb_rb=6;
 #if defined(__x86_64__) || defined(__i386__)
   __m128i *rxdataF_comp128_0,*rxdataF_comp128_1;
@@ -360,13 +406,12 @@ void nr_pbch_detection_mrc(NR_DL_FRAME_PARMS *frame_parms,
   symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
 
   if (frame_parms->nb_antennas_rx>1) {
-    for (aatx=0; aatx<4; aatx++) { //frame_parms->nb_antenna_ports_eNB;aatx++) {
 #if defined(__x86_64__) || defined(__i386__)
-      rxdataF_comp128_0   = (__m128i *)&rxdataF_comp[(aatx<<1)][symbol_mod*6*12];
-      rxdataF_comp128_1   = (__m128i *)&rxdataF_comp[(aatx<<1)+1][symbol_mod*6*12];
+      rxdataF_comp128_0   = (__m128i *)&rxdataF_comp[0][symbol_mod*6*12];
+      rxdataF_comp128_1   = (__m128i *)&rxdataF_comp[1][symbol_mod*6*12];
 #elif defined(__arm__)
-      rxdataF_comp128_0   = (int16x8_t *)&rxdataF_comp[(aatx<<1)][symbol_mod*6*12];
-      rxdataF_comp128_1   = (int16x8_t *)&rxdataF_comp[(aatx<<1)+1][symbol_mod*6*12];
+      rxdataF_comp128_0   = (int16x8_t *)&rxdataF_comp[0][symbol_mod*6*12];
+      rxdataF_comp128_1   = (int16x8_t *)&rxdataF_comp[1][symbol_mod*6*12];
 
 #endif
       // MRC on each re of rb, both on MF output and magnitude (for 16QAM/64QAM llr computation)
@@ -379,7 +424,7 @@ void nr_pbch_detection_mrc(NR_DL_FRAME_PARMS *frame_parms,
 #endif
       }
     }
-  }
+
 #if defined(__x86_64__) || defined(__i386__)
   _mm_empty();
   _m_empty();
@@ -387,18 +432,20 @@ void nr_pbch_detection_mrc(NR_DL_FRAME_PARMS *frame_parms,
 }
 
 void nr_pbch_unscrambling(NR_UE_PBCH *pbch,
-					   uint16_t Nid,
-					   uint8_t nushift,
-					   uint16_t M,
-					   uint16_t length,
-					   uint8_t bitwise)
+			  uint16_t Nid,
+			  uint8_t nushift,
+			  uint16_t M,
+			  uint16_t length,
+			  uint8_t bitwise)
 {
   uint8_t reset, offset;
   uint32_t x1, x2, s=0;
-  double *demod_pbch_e = pbch->demod_pbch_e;
+  int16_t *demod_pbch_e = pbch->llr;
+  uint32_t *pbch_a_prime = (uint32_t*)pbch->pbch_a_prime;
+  uint32_t *pbch_a_interleaved = (uint32_t*)pbch->pbch_a_interleaved;
+
   uint32_t unscrambling_mask = 0x100006D;
 
-  printf("unscramb nid_cell %d\n",Nid);
 
   reset = 1;
   // x1 is set in first call to lte_gold_generic
@@ -417,11 +464,11 @@ void nr_pbch_unscrambling(NR_UE_PBCH *pbch,
         s = lte_gold_generic(&x1, &x2, reset);
         reset = 0;
       }
-  #ifdef DEBUG_PBCH_ENCODING
+#ifdef DEBUG_PBCH_ENCODING
       if (i<8)
-    printf("s: %04x\t", s);
-    printf("pbch_a_interleaved 0x%08x\n", pbch->pbch_a_interleaved);
-  #endif
+	printf("s: %04x\t", s);
+      printf("pbch_a_interleaved 0x%08x\n", pbch->pbch_a_interleaved);
+#endif
       if (bitwise) {
 	
         (pbch->pbch_a_interleaved) ^= ((unscrambling_mask>>i)&1)? ((pbch->pbch_a_prime>>i)&1)<<i : (((pbch->pbch_a_prime>>i)&1) ^ ((s>>((i+offset)&0x1f))&1))<<i;
@@ -439,165 +486,131 @@ void nr_pbch_unscrambling(NR_UE_PBCH *pbch,
 
 }
 
-void nr_pbch_alamouti(NR_DL_FRAME_PARMS *frame_parms,
-                   int **rxdataF_comp,
-                   uint8_t symbol)
-{
-
-
-  int16_t *rxF0,*rxF1;
-  //  __m128i *ch_mag0,*ch_mag1,*ch_mag0b,*ch_mag1b;
-  uint8_t rb,re,symbol_mod;
-  int jj;
-
-  //  printf("Doing alamouti\n");
-  symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
-  jj         = (symbol_mod*6*12);
-
-  rxF0     = (int16_t*)&rxdataF_comp[0][jj];  //tx antenna 0  h0*y
-  rxF1     = (int16_t*)&rxdataF_comp[2][jj];  //tx antenna 1  h1*y
-
-  for (rb=0; rb<6; rb++) {
-
-    for (re=0; re<12; re+=2) {
-
-      // Alamouti RX combining
-
-      rxF0[0] = rxF0[0] + rxF1[2];
-      rxF0[1] = rxF0[1] - rxF1[3];
-
-      rxF0[2] = rxF0[2] - rxF1[0];
-      rxF0[3] = rxF0[3] + rxF1[1];
-
-      rxF0+=4;
-      rxF1+=4;
-    }
-
-  }
-
-}
-
-void nr_pbch_quantize(int8_t *pbch_llr8,
-                   int16_t *pbch_llr,
-                   uint16_t len)
+void nr_pbch_quantize(int16_t *pbch_llr8,
+                      int16_t *pbch_llr,
+                      uint16_t len)
 {
 
   uint16_t i;
 
   for (i=0; i<len; i++) {
-    if (pbch_llr[i]>127)
-      pbch_llr8[i]=127;
-    else if (pbch_llr[i]<-128)
-      pbch_llr8[i]=-128;
+    if (pbch_llr[i]>31)
+      pbch_llr8[i]=32;
+    else if (pbch_llr[i]<-31)
+      pbch_llr8[i]=-32;
     else
       pbch_llr8[i] = (char)(pbch_llr[i]);
 
   }
 }
-
+/*
 unsigned char sign(int8_t x) {
   return (unsigned char)x >> 7;
 }
+*/
 
 uint8_t pbch_deinterleaving_pattern[32] = {28,0,31,30,1,29,25,27,22,2,24,3,4,5,6,7,18,21,20,8,9,10,11,19,26,12,13,14,15,16,23,17};
 
 int nr_rx_pbch( PHY_VARS_NR_UE *ue,
-		     UE_nr_rxtx_proc_t *proc,
-		     NR_UE_PBCH *nr_ue_pbch_vars,
-		     NR_DL_FRAME_PARMS *frame_parms,
-		     uint8_t eNB_id,
-		     MIMO_mode_t mimo_mode,
-		     uint32_t high_speed_flag)
+		UE_nr_rxtx_proc_t *proc,
+		NR_UE_PBCH *nr_ue_pbch_vars,
+		NR_DL_FRAME_PARMS *frame_parms,
+		uint8_t eNB_id,
+		MIMO_mode_t mimo_mode,
+		uint32_t high_speed_flag)
 {
 
   NR_UE_COMMON *nr_ue_common_vars = &ue->common_vars;
 
-  uint8_t log2_maxh;
   int max_h=0;
 
   int symbol,i;
   //uint8_t pbch_a[64];
   uint8_t *pbch_a = malloc(sizeof(uint8_t) * 32);
   uint32_t pbch_a_prime;
-  int8_t *pbch_e_rx;
+  int16_t *pbch_e_rx;
   uint8_t *decoded_output = nr_ue_pbch_vars->decoded_output;
   uint8_t nushift;
   uint16_t M;
   uint8_t Lmax=8; //to update
   uint8_t ssb_index=0;
   //uint16_t crc;
-  //short nr_demod_table[8] = {0,0,0,1,1,0,1,1};
-  double nr_demod_table[8] = {0.707,0.707,-0.707,0.707,0.707,-0.707,-0.707,-0.707};
-  double *demod_pbch_e  = malloc (sizeof(double) * 864); 
   unsigned short idx_demod =0;
   int8_t decoderState=0;
   uint8_t decoderListSize = 8, pathMetricAppr = 0;
-  //double aPrioriArray[frame_parms->pbch_polar_params.payloadBits];  // assume no a priori knowledge available about the payload.
 
+  time_stats_t polar_decoder_init,polar_rate_matching,decoding,bit_extraction,deinterleaving;
+  time_stats_t path_metric,sorting,update_LLR;
   memset(&pbch_a[0], 0, sizeof(uint8_t) * NR_POLAR_PBCH_PAYLOAD_BITS);
 
   //printf("nr_pbch_ue nid_cell %d\n",frame_parms->Nid_cell);
 
-  //for (int i=0; i<frame_parms->pbch_polar_params.payloadBits; i++) aPrioriArray[i] = NAN;
 
   int subframe_rx = proc->subframe_rx;
   
-  printf("ue->current_thread_id[subframe_rx] %d subframe_rx %d\n",ue->current_thread_id[subframe_rx], subframe_rx);
-
   pbch_e_rx = &nr_ue_pbch_vars->llr[0];
 
   // clear LLR buffer
   memset(nr_ue_pbch_vars->llr,0,NR_POLAR_PBCH_E);
 
-  for (symbol=5; symbol<8; symbol++) {
+  int first_symbol=1;
+  if (ue->is_synchronized > 0) first_symbol+=4;
 
+#ifdef DEBUG_PBCH
     //printf("address dataf %p",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF);
-    //write_output("rxdataF0_pbch.m","rxF0pbch",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF,frame_parms->ofdm_symbol_size*4,2,1);
+    write_output("rxdataF0_pbch.m","rxF0pbch",
+		 &nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF[0][first_symbol*frame_parms->ofdm_symbol_size],frame_parms->ofdm_symbol_size*3,1,1);
+#endif
+
+  for (symbol=first_symbol; symbol<(first_symbol+3); symbol++) {
+
   
     nr_pbch_extract(nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF,
-                 nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].dl_ch_estimates[eNB_id],
-                 nr_ue_pbch_vars->rxdataF_ext,
-                 nr_ue_pbch_vars->dl_ch_estimates_ext,
-                 symbol,
-                 high_speed_flag,
-                 frame_parms);
+		    nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].dl_ch_estimates[eNB_id],
+		    nr_ue_pbch_vars->rxdataF_ext,
+		    nr_ue_pbch_vars->dl_ch_estimates_ext,
+		    symbol-first_symbol+1,
+		    high_speed_flag,
+		    ue->is_synchronized,
+		    frame_parms);
 #ifdef DEBUG_PBCH
-    msg("[PHY] PBCH Symbol %d ofdm size %d\n",symbol, frame_parms->ofdm_symbol_size );
-    msg("[PHY] PBCH starting channel_level\n");
+    LOG_I(PHY,"[PHY] PBCH Symbol %d ofdm size %d\n",symbol, frame_parms->ofdm_symbol_size );
+    LOG_I(PHY,"[PHY] PBCH starting channel_level\n");
 #endif
 
-    max_h = nr_pbch_channel_level(nr_ue_pbch_vars->dl_ch_estimates_ext,
-                               frame_parms,
-                               symbol);
-    log2_maxh = 3+(log2_approx(max_h)/2);
+    if (symbol == 1 || symbol == 5) {
+      max_h = nr_pbch_channel_level(nr_ue_pbch_vars->dl_ch_estimates_ext,
+				    frame_parms,
+				    symbol);
+      nr_ue_pbch_vars->log2_maxh = 3+(log2_approx(max_h)/2);
+    }
 
 #ifdef DEBUG_PBCH
-    msg("[PHY] PBCH log2_maxh = %d (%d)\n",log2_maxh,max_h);
+    LOG_I(PHY,"[PHY] PBCH log2_maxh = %d (%d)\n",nr_ue_pbch_vars->log2_maxh,max_h);
 #endif
 
     nr_pbch_channel_compensation(nr_ue_pbch_vars->rxdataF_ext,
-                              nr_ue_pbch_vars->dl_ch_estimates_ext,
-                              nr_ue_pbch_vars->rxdataF_comp,
-                              frame_parms,
-                              symbol,
-                              log2_maxh); // log2_maxh+I0_shift
+				 nr_ue_pbch_vars->dl_ch_estimates_ext,
+				 nr_ue_pbch_vars->rxdataF_comp,
+				 frame_parms,
+				 symbol,
+				 ue->is_synchronized,
+				 nr_ue_pbch_vars->log2_maxh); // log2_maxh+I0_shift
 
-    //write_output("rxdataF_comp.m","rxFcomp",nr_ue_pbch_vars->rxdataF_comp,180,2,1);
-  
     /*if (frame_parms->nb_antennas_rx > 1)
       pbch_detection_mrc(frame_parms,
                          nr_ue_pbch_vars->rxdataF_comp,
                          symbol);*/
 
-
+/*
     if (mimo_mode == ALAMOUTI) {
       nr_pbch_alamouti(frame_parms,nr_ue_pbch_vars->rxdataF_comp,symbol);
     } else if (mimo_mode != SISO) {
-      msg("[PBCH][RX] Unsupported MIMO mode\n");
+      LOG_I(PHY,"[PBCH][RX] Unsupported MIMO mode\n");
       return(-1);
     }
-
-    if (symbol==6) {
+*/
+    if (symbol==(first_symbol+1)) {
       nr_pbch_quantize(pbch_e_rx,
                     (short*)&(nr_ue_pbch_vars->rxdataF_comp[0][symbol*240]),
                     144);
@@ -614,51 +627,42 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue,
 
   }
 
+#ifdef DEBUG_PBCH
+  write_output("rxdataF_comp.m","rxFcomp",&nr_ue_pbch_vars->rxdataF_comp[0][240*first_symbol],240*3,1,1);
+#endif
+    
+
   pbch_e_rx = nr_ue_pbch_vars->llr;
-  demod_pbch_e = nr_ue_pbch_vars->demod_pbch_e;
+  //demod_pbch_e = nr_ue_pbch_vars->demod_pbch_e;
   pbch_a = nr_ue_pbch_vars->pbch_a;
 
 #ifdef DEBUG_PBCH
   //pbch_e_rx = &nr_ue_pbch_vars->llr[0];
 
-  short *p = (short *)&(nr_ue_pbch_vars->rxdataF_comp[0][5*20*12]);
-  for (int cnt = 0; cnt < 32 ; cnt++)
-    printf("pbch rx llr %d rxdata_comp %d addr %p\n",*(pbch_e_rx+cnt), p[cnt], &p[0]);
-#endif
+  short *p = (short *)&(nr_ue_pbch_vars->rxdataF_comp[0][first_symbol*20*12]);
+  for (int cnt = 0; cnt < 864  ; cnt++)
+    printf("pbch rx llr %d\n",*(pbch_e_rx+cnt));
 
-  for (i=0; i<NR_POLAR_PBCH_E/2; i++){
-    idx_demod = (sign(pbch_e_rx[i<<1])&1) ^ ((sign(pbch_e_rx[(i<<1)+1])&1)<<1);
-    demod_pbch_e[i<<1] = nr_demod_table[(idx_demod)<<1];
-    demod_pbch_e[(i<<1)+1] = nr_demod_table[((idx_demod)<<1)+1];
-#ifdef DEBUG_PBCH
-    if (i<16){
-    printf("idx[%d]= %d\n", i , idx_demod);
-    printf("sign[%d]= %d sign[%d]= %d\n", i<<1 , sign(pbch_e_rx[i<<1]), (i<<1)+1 , sign(pbch_e_rx[(i<<1)+1]));
-    printf("demod_pbch_e[%d] r = %2.3f i = %2.3f\n", i<<1 , demod_pbch_e[i<<1], demod_pbch_e[(i<<1)+1]);}
 #endif
-  }
+
 
   //un-scrambling
   M =  NR_POLAR_PBCH_E;
   nushift = (Lmax==4)? ssb_index&3 : ssb_index&7;
   nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_E,0);
 
-//#ifdef DEBUG_PBCH
-    for (i=0; i<16; i++){
-    printf("unscrambling demod_pbch_e[%d] r = %2.3f i = %2.3f\n", i<<1 , demod_pbch_e[i<<1], demod_pbch_e[(i<<1)+1]);}
-//#endif
-//		uint32_t pbch_out;
+
+
   //polar decoding de-rate matching
-  t_nrPolar_paramsPtr nrPolar_params = NULL, currentPtr = NULL;
-   nr_polar_init(&nrPolar_params,
-    		  	  	NR_POLAR_PBCH_MESSAGE_TYPE,
-					NR_POLAR_PBCH_PAYLOAD_BITS,
-					NR_POLAR_PBCH_AGGREGATION_LEVEL);
-  currentPtr = nr_polar_params(nrPolar_params, NR_POLAR_PBCH_MESSAGE_TYPE, NR_POLAR_PBCH_PAYLOAD_BITS, NR_POLAR_PBCH_AGGREGATION_LEVEL);
-  double aPrioriArray[currentPtr->payloadBits];
-  for (int i=0; i<currentPtr->payloadBits; i++) aPrioriArray[i] = NAN;
-  decoderState = polar_decoder_aPriori(demod_pbch_e,&nr_ue_pbch_vars->pbch_a_prime, currentPtr, decoderListSize, pathMetricAppr,aPrioriArray);
-  printf("polar decoder state %d\n", decoderState);
+
+
+  AssertFatal(ue->nrPolar_params != NULL,"ue->nrPolar_params is null\n");
+
+  t_nrPolar_params *currentPtr = nr_polar_params(ue->nrPolar_params, NR_POLAR_PBCH_MESSAGE_TYPE, NR_POLAR_PBCH_PAYLOAD_BITS, NR_POLAR_PBCH_AGGREGATION_LEVEL);
+
+  decoderState = polar_decoder_int16(pbch_e_rx,&nr_ue_pbch_vars->pbch_a_prime,currentPtr);
+
+
   if(decoderState == -1)
   	return(decoderState);
   	
@@ -668,7 +672,6 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue,
   memset(&nr_ue_pbch_vars->pbch_a_interleaved, 0, sizeof(uint32_t) );
   M = (Lmax == 64)? (NR_POLAR_PBCH_PAYLOAD_BITS - 6) : (NR_POLAR_PBCH_PAYLOAD_BITS - 3);
   nushift = ((nr_ue_pbch_vars->pbch_a_prime>>6)&1) ^ (((nr_ue_pbch_vars->pbch_a_prime>>24)&1)<<1);
-  printf("payload unscrambling nushift %d sfn3 %d sfn2 %d M %d\n",nushift, ((nr_ue_pbch_vars->pbch_a_prime>>6)&1),((nr_ue_pbch_vars->pbch_a_prime>>24)&1),M);
   nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_PAYLOAD_BITS,1);
 
   //payload deinterleaving
@@ -678,35 +681,37 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue,
   for (int i=0; i<32; i++) {
     out |= ((nr_ue_pbch_vars->pbch_a_interleaved>>i)&1)<<(pbch_deinterleaving_pattern[i]);
 #ifdef DEBUG_PBCH
-  printf("i %d in 0x%08x out 0x%08x ilv %d (in>>i)&1) 0x%08x\n", i, nr_ue_pbch_vars->pbch_a_interleaved, out, pbch_deinterleaving_pattern[i], (in>>i)&1);
+    printf("i %d in 0x%08x out 0x%08x ilv %d (in>>i)&1) 0x%08x\n", i, nr_ue_pbch_vars->pbch_a_interleaved, out, pbch_deinterleaving_pattern[i], (nr_ue_pbch_vars->pbch_a_interleaved>>i)&1);
 #endif
   }
 
   for (int i=0; i<NR_POLAR_PBCH_PAYLOAD_BITS>>3; i++)
-	  pbch_a[i] = (uint8_t)((out>>(i<<3))&0xff);
+	  decoded_output[i] = (uint8_t)((out>>(i<<3))&0xff);
 
   // Fix byte endian
-  for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS>>3); i++)
-     decoded_output[(NR_POLAR_PBCH_PAYLOAD_BITS>>3)-i-1] = pbch_a[i];
+  //  for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS>>3); i++)
+  //     decoded_output[(NR_POLAR_PBCH_PAYLOAD_BITS>>3)-i-1] = pbch_a[i];
      
-  //#ifdef DEBUG_PBCH
+#ifdef DEBUG_PBCH
   for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS>>3); i++){
-  	  //printf("unscrambling pbch_a[%d] = %x \n", i,pbch_a[i]);
+    //  	  printf("unscrambling pbch_a[%d] = %x \n", i,pbch_a[i]);
   	  printf("[PBCH] decoder payload[%d] = %x\n",i,decoded_output[i]);
   }
-	  //#endif
+#endif
+
     ue->dl_indication.rx_ind = &ue->rx_ind; //  hang on rx_ind instance
     //ue->rx_ind.sfn_slot = 0;  //should be set by higher-1-layer, i.e. clean_and_set_if_instance()
     ue->rx_ind.number_pdus = ue->rx_ind.number_pdus + 1;
     ue->rx_ind.rx_indication_body = (fapi_nr_rx_indication_body_t *)malloc(sizeof(fapi_nr_rx_indication_body_t));
     ue->rx_ind.rx_indication_body->pdu_type = FAPI_NR_RX_PDU_TYPE_MIB;
-    ue->rx_ind.rx_indication_body->mib_pdu.pdu = &decoded_output[1];
-    ue->rx_ind.rx_indication_body->mib_pdu.additional_bits = decoded_output[0];
+    ue->rx_ind.rx_indication_body->mib_pdu.pdu = &decoded_output[0];
+    ue->rx_ind.rx_indication_body->mib_pdu.additional_bits = decoded_output[3];
     ue->rx_ind.rx_indication_body->mib_pdu.ssb_index = ssb_index;            //  confirm with TCL
     ue->rx_ind.rx_indication_body->mib_pdu.ssb_length = Lmax;                //  confirm with TCL
     ue->rx_ind.rx_indication_body->mib_pdu.cell_id = frame_parms->Nid_cell;  //  confirm with TCL
 
-    ue->if_inst->dl_indication(&ue->dl_indication);
+    if (ue->if_inst && ue->if_inst->dl_indication)
+      ue->if_inst->dl_indication(&ue->dl_indication);
 
     return 0;    
 }
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h
index 954099410f9d5c4a99a0093c6391c55e2b332b42..c361daab017b0fc79507e300f5cc853bafc177b9 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h
@@ -1362,6 +1362,7 @@ void generate_RIV_tables(void);
   N_RB_DL, PHICH_CONFIG and Nid_cell) and the UE can begin decoding PDCCH and DLSCH SI to retrieve the rest.  Once these
   parameters are know, the routine calls some basic initialization routines (cell-specific reference signals, etc.)
   @param phy_vars_ue Pointer to UE variables
+  @param mode current running mode
 */
 int nr_initial_sync(PHY_VARS_NR_UE *phy_vars_ue, runmode_t mode);
 
diff --git a/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c b/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c
index 32f906c1d9424a68d031449848fc06a1b9dbc31c..de9b90f993b368e8cc099915d0a95b17668f54fa 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c
@@ -57,6 +57,8 @@
 *
 *********************************************************************/
 
+//#define DBG_PSS_NR
+
 void *get_idft(int ofdm_symbol_size)
 {
   void (*idft)(int16_t *,int16_t *, int);
@@ -86,6 +88,14 @@ void *get_idft(int ofdm_symbol_size)
       idft = idft2048;
       break;
 
+    case 4096:
+      idft = idft4096;
+      break;
+
+    case 8192:
+      idft = idft8192;
+      break;
+
     default:
       printf("function get_idft : unsupported ofdm symbol size \n");
       assert(0);
@@ -135,6 +145,14 @@ void *get_dft(int ofdm_symbol_size)
       dft = dft2048;
       break;
 
+    case 4096:
+      dft = dft4096;
+      break;
+
+    case 8192:
+      dft = dft8192;
+      break;
+
     default:
       printf("function get_dft : unsupported ofdm symbol size \n");
       assert(0);
@@ -157,14 +175,17 @@ void *get_dft(int ofdm_symbol_size)
 *
 *********************************************************************/
 
-void generate_pss_nr(int N_ID_2, int ofdm_symbol_size)
+void generate_pss_nr(NR_DL_FRAME_PARMS *fp,int N_ID_2)
 {
+  AssertFatal(fp->ofdm_symbol_size > 127,"Illegal ofdm_symbol_size %d\n",fp->ofdm_symbol_size);
+  AssertFatal(N_ID_2>=0 && N_ID_2 <=2,"Illegal N_ID_2 %d\n",N_ID_2);
   int16_t d_pss[LENGTH_PSS_NR];
   int16_t x[LENGTH_PSS_NR];
   int16_t *primary_synchro_time = primary_synchro_time_nr[N_ID_2];
-  unsigned int length = ofdm_symbol_size;
+  unsigned int length = fp->ofdm_symbol_size;
   unsigned int size = length * IQ_SIZE; /* i & q */
   int16_t *primary_synchro = primary_synchro_nr[N_ID_2]; /* pss in complex with alternatively i then q */
+  int16_t *primary_synchro2 = primary_synchro_nr2[N_ID_2]; /* pss in complex with alternatively i then q */
   void (*idft)(int16_t *,int16_t *, int);
 
   #define INITIAL_PSS_NR    (7)
@@ -195,9 +216,11 @@ void generate_pss_nr(int N_ID_2, int ofdm_symbol_size)
 #if 1
     primary_synchro[2*i] = (d_pss[i] * SHRT_MAX)>>SCALING_PSS_NR; /* Maximum value for type short int ie int16_t */
     primary_synchro[2*i+1] = 0;
+    primary_synchro2[i] = d_pss[i];
 #else
     primary_synchro[2*i] = d_pss[i] * AMP;
     primary_synchro[2*i+1] = 0;
+    primary_synchro2[i] = d_pss[i];
 #endif
   }
 
@@ -210,7 +233,7 @@ void generate_pss_nr(int N_ID_2, int ofdm_symbol_size)
     sprintf(sequence_name, "pss_seq_%d_%d", N_ID_2, length);
     printf("file %s sequence %s\n", output_file, sequence_name);
 
-    write_output(output_file, sequence_name, primary_synchro, LENGTH_PSS_NR, 1, 1);
+    LOG_M(output_file, sequence_name, primary_synchro, LENGTH_PSS_NR, 1, 1);
   }
 
 #endif
@@ -237,7 +260,10 @@ void generate_pss_nr(int N_ID_2, int ofdm_symbol_size)
   * sample 0 is for continuous frequency which is used here
   */
 
-  unsigned int k = length - (LENGTH_PSS_NR/2+1);
+  unsigned int  k = fp->first_carrier_offset + fp->ssb_start_subcarrier + 56; //and
+  if (k>= fp->ofdm_symbol_size) k-=fp->ofdm_symbol_size;
+
+
 
   for (int i=0; i < LENGTH_PSS_NR; i++) {
     synchroF_tmp[2*k] = primary_synchro[2*i];
@@ -245,10 +271,8 @@ void generate_pss_nr(int N_ID_2, int ofdm_symbol_size)
 
     k++;
 
-    if (k >= length) {
-      k++;
-      k-=length;
-    }
+    if (k == length) k=0;
+    
   }
 
   /* IFFT will give temporal signal of Pss */
@@ -274,7 +298,10 @@ void generate_pss_nr(int N_ID_2, int ofdm_symbol_size)
 
     printf("file %s sequence %s\n", output_file, sequence_name);
 
-    write_output(output_file, sequence_name, primary_synchro_time, length, 1, 1);
+    LOG_M(output_file, sequence_name, primary_synchro_time, length, 1, 1);
+    sprintf(output_file, "%s%d_%d%s","pss_seq_f_", N_ID_2, length, ".m");
+    sprintf(sequence_name, "%s%d_%d","pss_seq_f_", N_ID_2, length);
+    LOG_M(output_file, sequence_name, synchroF_tmp, length, 1, 1);
   }
 
 #endif
@@ -286,7 +313,7 @@ void generate_pss_nr(int N_ID_2, int ofdm_symbol_size)
 
   if ((N_ID_2 == 0) && (length == 256)) {
 
-    write_output("pss_f00.m","pss_f00",synchro_tmp,length,1,1);
+    LOG_M("pss_f00.m","pss_f00",synchro_tmp,length,1,1);
 
 
     bzero(synchroF_tmp, size);
@@ -299,7 +326,7 @@ void generate_pss_nr(int N_ID_2, int ofdm_symbol_size)
         1);                 /* scaling factor */
 
     if ((N_ID_2 == 0) && (length == 256)) {
-      write_output("pss_f_0.m","pss_f_0",synchroF_tmp,length,1,1);
+      LOG_M("pss_f_0.m","pss_f_0",synchroF_tmp,length,1,1);
     }
 
     /* check Pss */
@@ -345,8 +372,9 @@ void init_context_pss_nr(NR_DL_FRAME_PARMS *frame_parms_ue)
   int sizePss = LENGTH_PSS_NR * IQ_SIZE;  /* complex value i & q signed 16 bits */
   int size = ofdm_symbol_size * IQ_SIZE; /* i and q samples signed 16 bits */
   int16_t *p = NULL;
-  int *q = NULL;
+  int64_t *q = NULL;
 
+  AssertFatal(ofdm_symbol_size > 127, "illegal ofdm_symbol_size %d\n",ofdm_symbol_size);
   for (int i = 0; i < NUMBER_PSS_SEQUENCE; i++) {
 
     p = malloc16(sizePss); /* pss in complex with alternatively i then q */
@@ -358,7 +386,11 @@ void init_context_pss_nr(NR_DL_FRAME_PARMS *frame_parms_ue)
      msg("Fatal memory allocation problem \n");
      assert(0);
     }
-
+    p = malloc(LENGTH_PSS_NR*2);
+    if (p != NULL) {
+      primary_synchro_nr2[i] = p;
+      bzero( primary_synchro_nr2[i],LENGTH_PSS_NR*2);
+    }
     p = malloc16(size);
     if (p != NULL) {
       primary_synchro_time_nr[i] = p;
@@ -369,8 +401,8 @@ void init_context_pss_nr(NR_DL_FRAME_PARMS *frame_parms_ue)
      assert(0);
     }
 
-    size = NR_NUMBER_OF_SUBFRAMES_PER_FRAME*sizeof(int)*frame_parms_ue->samples_per_subframe;
-    q = malloc16(size);
+    size = NR_NUMBER_OF_SUBFRAMES_PER_FRAME*sizeof(int64_t)*frame_parms_ue->samples_per_subframe;
+    q = (int64_t*)malloc16(size);
     if (q != NULL) {
       pss_corr_ue[i] = q;
       bzero( pss_corr_ue[i], size);
@@ -380,7 +412,7 @@ void init_context_pss_nr(NR_DL_FRAME_PARMS *frame_parms_ue)
       assert(0);
     }
 
-    generate_pss_nr(i, ofdm_symbol_size);
+    generate_pss_nr(frame_parms_ue,i);
   }
 }
 
@@ -580,6 +612,8 @@ void decimation_synchro_nr(PHY_VARS_NR_UE *PHY_vars_UE, int rate_change, int **r
   NR_DL_FRAME_PARMS *frame_parms = &(PHY_vars_UE->frame_parms);
   int samples_for_frame = NR_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti;
 
+  AssertFatal(frame_parms->samples_per_tti > 3839,"Illegal samples_per_tti %d\n",frame_parms->samples_per_tti);
+
 #if TEST_SYNCHRO_TIMING_PSS
 
   opp_enabled = 1;
@@ -633,7 +667,7 @@ int pss_synchro_nr(PHY_VARS_NR_UE *PHY_vars_UE, int rate_change)
 
   int samples_for_frame = frame_parms->samples_per_subframe*NR_NUMBER_OF_SUBFRAMES_PER_FRAME;
 
-  write_output("rxdata0_rand.m","rxd0_rand", &PHY_vars_UE->common_vars.rxdata[0][0], samples_for_frame, 1, 1);
+  LOG_M("rxdata0_rand.m","rxd0_rand", &PHY_vars_UE->common_vars.rxdata[0][0], samples_for_frame, 1, 1);
 
 #endif
 
@@ -642,7 +676,7 @@ int pss_synchro_nr(PHY_VARS_NR_UE *PHY_vars_UE, int rate_change)
     rxdata = (int32_t**)malloc16(frame_parms->nb_antennas_rx*sizeof(int32_t*));
 
     for (int aa=0; aa < frame_parms->nb_antennas_rx; aa++) {
-      rxdata[aa] = (int32_t*) malloc16_clear( (frame_parms->samples_per_subframe*10+2048)*sizeof(int32_t));
+      rxdata[aa] = (int32_t*) malloc16_clear( (frame_parms->samples_per_subframe*10+8192)*sizeof(int32_t));
     }
 #ifdef SYNCHRO_DECIMAT
 
@@ -657,7 +691,7 @@ int pss_synchro_nr(PHY_VARS_NR_UE *PHY_vars_UE, int rate_change)
 
 #ifdef DBG_PSS_NR
 
-  write_output("rxdata0_des.m","rxd0_des", &rxdata[0][0], samples_for_frame,1,1);
+  LOG_M("rxdata0_des.m","rxd0_des", &rxdata[0][0], samples_for_frame,1,1);
 
 #endif
 
@@ -712,6 +746,11 @@ static inline int abs32(int x)
   return (((int)((short*)&x)[0])*((int)((short*)&x)[0]) + ((int)((short*)&x)[1])*((int)((short*)&x)[1]));
 }
 
+static inline int64_t abs64(int64_t x)
+{
+  return (((int64_t)((int32_t*)&x)[0])*((int64_t)((int32_t*)&x)[0]) + ((int64_t)((int32_t*)&x)[1])*((int64_t)((int32_t*)&x)[1]));
+}
+
 /*******************************************************************
 *
 * NAME :         pss_search_time_nr
@@ -768,87 +807,91 @@ int pss_search_time_nr(int **rxdata, ///rx data in time domain
                        NR_DL_FRAME_PARMS *frame_parms,
                        int *eNB_id)
 {
-  unsigned int n, ar, peak_position, peak_value, pss_source;
-  int result;
-  int synchro_out;
-  unsigned int tmp[NUMBER_PSS_SEQUENCE];
-  unsigned int length = (NR_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->ttis_per_subframe*frame_parms->samples_per_tti);  /* 1 frame for now, it should be 2 TODO_NR */
+  unsigned int n, ar, peak_position, pss_source;
+  int64_t peak_value;
+  int64_t result;
+  int64_t avg[NUMBER_PSS_SEQUENCE];
 
-  for (int i = 0; i < NUMBER_PSS_SEQUENCE; i++) {
-	  tmp[i] = 0;
-    if (pss_corr_ue[i] == NULL) {
-      msg("[SYNC TIME] pss_corr_ue[%d] not yet allocated! Exiting.\n", i);
-      return(-1);
-    }
-  }
 
+  unsigned int length = (NR_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_subframe);  /* 1 frame for now, it should be 2 TODO_NR */
+
+  AssertFatal(length>0,"illegal length %d\n",length);
+  for (int i = 0; i < NUMBER_PSS_SEQUENCE; i++) AssertFatal(pss_corr_ue[i] != NULL,"pss_corr_ue[%d] not yet allocated! Exiting.\n", i);
+
+    
   peak_value = 0;
   peak_position = 0;
   pss_source = 0;
 
+  int maxval=0;
+  for (int i=0;i<2*(frame_parms->ofdm_symbol_size);i++) {
+    maxval = max(maxval,primary_synchro_time_nr[0][i]);
+    maxval = max(maxval,-primary_synchro_time_nr[0][i]);
+    maxval = max(maxval,primary_synchro_time_nr[1][i]);
+    maxval = max(maxval,-primary_synchro_time_nr[1][i]);
+    maxval = max(maxval,primary_synchro_time_nr[2][i]);
+    maxval = max(maxval,-primary_synchro_time_nr[2][i]);
+
+  }
+  int shift = log2_approx(maxval);//*(frame_parms->ofdm_symbol_size+frame_parms->nb_prefix_samples)*2);
+
   /* Search pss in the received buffer each 4 samples which ensures a memory alignment on 128 bits (32 bits x 4 ) */
   /* This is required by SIMD (single instruction Multiple Data) Extensions of Intel processors. */
   /* Correlation computation is based on a a dot product which is realized thank to SIMS extensions */
-  for (n=0; n < length; n+=4) {
-
-#ifdef RTAI_ENABLED
+  for (int pss_index = 0; pss_index < NUMBER_PSS_SEQUENCE; pss_index++) avg[pss_index]=0;
 
-    // This is necessary since the sync takes a long time and it seems to block all other threads thus screwing up RTAI. If we pause it for a little while during its execution we give RTAI a chance to catch up with its other tasks.
-    if ((n%frame_parms->samples_per_subframe == 0) && (n>0) && (openair_daq_vars.sync_state==0)) {
-#ifdef DEBUG_PHY
-      msg("[SYNC TIME] pausing for 1000ns, n=%d\n",n);
-#endif
-      rt_sleep(nano2count(1000));
-    }
-
-#endif
+  for (n=0; n < length; n+=4) {
 
     for (int pss_index = 0; pss_index < NUMBER_PSS_SEQUENCE; pss_index++) {
 
       pss_corr_ue[pss_index][n] = 0; /* clean correlation for position n */
 
-      synchro_out = 0;
-
       if ( n < (length - frame_parms->ofdm_symbol_size)) {
 
         /* calculate dot product of primary_synchro_time_nr and rxdata[ar][n] (ar=0..nb_ant_rx) and store the sum in temp[n]; */
         for (ar=0; ar<frame_parms->nb_antennas_rx; ar++) {
 
           /* perform correlation of rx data and pss sequence ie it is a dot product */
-          result  = dot_product((short*)primary_synchro_time_nr[pss_index], (short*) &(rxdata[ar][n]), frame_parms->ofdm_symbol_size, DOT_PRODUCT_SCALING_SHIFT);
+          result  = dot_product64((short*)primary_synchro_time_nr[pss_index], 
+				  (short*) &(rxdata[ar][n]), 
+				  frame_parms->ofdm_symbol_size, 
+				  shift);
+	  pss_corr_ue[pss_index][n] += abs64(result);
+	  
+          //((short*)pss_corr_ue[pss_index])[2*n] += ((short*) &result)[0];   /* real part */
+          //((short*)pss_corr_ue[pss_index])[2*n+1] += ((short*) &result)[1]; /* imaginary part */
+          //((short*)&synchro_out)[0] += ((short*) &result)[0];               /* real part */
+          //((short*)&synchro_out)[1] += ((short*) &result)[1];               /* imaginary part */
 
-          ((short*)pss_corr_ue[pss_index])[2*n] += ((short*) &result)[0];   /* real part */
-          ((short*)pss_corr_ue[pss_index])[2*n+1] += ((short*) &result)[1]; /* imaginary part */
-          ((short*)&synchro_out)[0] += ((short*) &result)[0];               /* real part */
-          ((short*)&synchro_out)[1] += ((short*) &result)[1];               /* imaginary part */
         }
       }
 
-      pss_corr_ue[pss_index][n] = abs32(pss_corr_ue[pss_index][n]);
-
       /* calculate the absolute value of sync_corr[n] */
-      tmp[pss_index] = (abs32(synchro_out)) ;
-
-      if (tmp[pss_index] > peak_value) {
-        peak_value = tmp[pss_index];
+      avg[pss_index]+=pss_corr_ue[pss_index][n];
+      if (pss_corr_ue[pss_index][n] > peak_value) {
+        peak_value = pss_corr_ue[pss_index][n];
         peak_position = n;
         pss_source = pss_index;
 
-        //printf("pss_index %d: n %6d peak_value %10d, synchro_out (% 6d,% 6d) \n", pss_index, n, abs32(synchro_out),((int16_t*)&synchro_out)[0],((int16_t*)&synchro_out)[1]);
+#ifdef DEBUG_PSS_NR
+        printf("pss_index %d: n %6d peak_value %15llu\n", pss_index, n, (unsigned long long)pss_corr_ue[pss_index][n]);
+#endif
       }
     }
   }
 
+  for (int pss_index = 0; pss_index < NUMBER_PSS_SEQUENCE; pss_index++) avg[pss_index]/=(length/4);
+
   *eNB_id = pss_source;
 
-  LOG_I(PHY,"[UE] nr_synchro_time: Sync source = %d, Peak found at pos %d, val = %d (%d dB)\n", pss_source, peak_position, peak_value, dB_fixed(peak_value)/2);
+  LOG_I(PHY,"[UE] nr_synchro_time: Sync source = %d, Peak found at pos %d, val = %llu (%d dB) avg %d dB\n", pss_source, peak_position, (unsigned long long)peak_value, dB_fixed64(peak_value),dB_fixed64(avg[pss_source]));
 
 //#ifdef DEBUG_PSS_NR
 
 #define  PSS_DETECTION_FLOOR_NR     (31)
-  if ((dB_fixed(peak_value)/2) > PSS_DETECTION_FLOOR_NR) {
+  if (peak_value < 5*avg[pss_source]) { //PSS_DETECTION_FLOOR_NR)
 
-    printf("[UE] nr_synchro_time: Sync source = %d, Peak found at pos %d, val = %d (%d dB)\n", pss_source, peak_position, peak_value,dB_fixed(peak_value)/2);
+    return(-1);
   }
 //#endif
 
@@ -857,10 +900,10 @@ int pss_search_time_nr(int **rxdata, ///rx data in time domain
   static debug_cnt = 0;
 
   if (debug_cnt == 0) {
-    write_output("pss_corr_ue0.m","pss_corr_ue0",pss_corr_ue[0],length,1,2);
-    write_output("pss_corr_ue1.m","pss_corr_ue1",pss_corr_ue[1],length,1,2);
-    write_output("pss_corr_ue2.m","pss_corr_ue2",pss_corr_ue[2],length,1,2);
-    write_output("rxdata0.m","rxd0",rxdata[0],length,1,1);
+    /*    LOG_M("pss_corr_ue0.m","pss_corr_ue0",pss_corr_ue[0],length,1,6);
+    LOG_M("pss_corr_ue1.m","pss_corr_ue1",pss_corr_ue[1],length,1,6);
+    LOG_M("pss_corr_ue2.m","pss_corr_ue2",pss_corr_ue[2],length,1,6);
+    LOG_M("rxdata0.m","rxd0",rxdata[0],length,1,1); */
   } else {
     debug_cnt++;
   }
diff --git a/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c b/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c
index 3231e8203545daf2762a3fb3c821666242230522..26639a51344101e7906a9216757aa274a1698b12 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c
@@ -96,7 +96,8 @@ void init_context_sss_nr(int amp)
 
       /* Modulation of SSS is a BPSK TS 36.211 chapter 5.1.2 BPSK */
 #if 1
-        d_sss[N_ID_2][N_ID_1][n]   = dss_current * amp;
+        d_sss[N_ID_2][N_ID_1][n]   = dss_current;// * amp;
+	(void) amp;
 #else
         (void) amp;
         d_sss[N_ID_2][N_ID_1][n]   = (dss_current * SHRT_MAX)>>SCALING_PSS_NR;
@@ -126,6 +127,8 @@ void init_context_sss_nr(int amp)
 *
 *********************************************************************/
 
+//#define DEBUG_SSS_NR
+//#define DEBUG_PLOT_SSS
 void insert_sss_nr(int16_t *sss_time,
                    NR_DL_FRAME_PARMS *frame_parms)
 {
@@ -210,10 +213,14 @@ int pss_ch_est_nr(PHY_VARS_NR_UE *ue,
   uint8_t aarx,i;
   NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
 
-  pss = primary_synchro_nr[ue->common_vars.eNb_id];
+  pss = primary_synchro_nr2[ue->common_vars.eNb_id];
 
   sss_ext3 = (int16_t*)&sss_ext[0][0];
 
+#if 0
+  int16_t chest[2*LENGTH_PSS_NR];
+#endif
+
   for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
 
     sss_ext2 = (int16_t*)&sss_ext[aarx][0];
@@ -240,18 +247,28 @@ int pss_ch_est_nr(PHY_VARS_NR_UE *ue,
 
 #endif
 
+  int32_t amp;
+  int shift;
     for (i = 0; i < LENGTH_PSS_NR; i++) {
 
       // This is H*(PSS) = R* \cdot PSS
-      tmp_re = (int16_t)(((pss_ext2[i*2] * (int32_t)pss[i*2])>>SCALING_CE_PSS_NR)   + ((pss_ext2[i*2+1] * (int32_t)pss[i*2+1])>>SCALING_CE_PSS_NR));
-      tmp_im = (int16_t)(((pss_ext2[i*2] * (int32_t)pss[i*2+1])>>SCALING_CE_PSS_NR) - ((pss_ext2[i*2+1] * (int32_t)pss[i*2])>>SCALING_CE_PSS_NR));
-      //printf("H*(%d,%d) : (%d,%d)\n",aarx,i,tmp_re,tmp_im);
-      //printf("pss(%d,%d) : (%d,%d)\n",aarx,i,pss[2*i],pss[2*i+1]);
-      //printf("pss_ext(%d,%d) : (%d,%d)\n",aarx,i,pss_ext2[2*i],pss_ext2[2*i+1]);
-
+      tmp_re = pss_ext2[i*2] * pss[i];
+      tmp_im = -pss_ext2[i*2+1] * pss[i];
+      
+      amp = (((int32_t)tmp_re)*tmp_re) + ((int32_t)tmp_im)*tmp_im;
+      shift = log2_approx(amp)/2;
+#if 0
+      printf("H*(%d,%d) : (%d,%d)\n",aarx,i,tmp_re,tmp_im);
+      printf("pss(%d,%d) : (%d,%d)\n",aarx,i,pss[2*i],pss[2*i+1]);
+      printf("pss_ext(%d,%d) : (%d,%d)\n",aarx,i,pss_ext2[2*i],pss_ext2[2*i+1]);
+      if (aarx==0) {
+       chest[i<<1]=tmp_re;
+       chest[1+(i<<1)]=tmp_im;
+      }
+#endif      
       // This is R(SSS) \cdot H*(PSS)
-      tmp_re2 = (int16_t)(((tmp_re * (int32_t)sss_ext2[i*2])>>SCALING_CE_PSS_NR)    - ((tmp_im * (int32_t)sss_ext2[i*2+1]>>SCALING_CE_PSS_NR)));
-      tmp_im2 = (int16_t)(((tmp_re * (int32_t)sss_ext2[i*2+1])>>SCALING_CE_PSS_NR)  + ((tmp_im * (int32_t)sss_ext2[i*2]>>SCALING_CE_PSS_NR)));
+      tmp_re2 = (int16_t)(((tmp_re * (int32_t)sss_ext2[i*2])>>shift)    - ((tmp_im * (int32_t)sss_ext2[i*2+1]>>shift)));
+      tmp_im2 = (int16_t)(((tmp_re * (int32_t)sss_ext2[i*2+1])>>shift)  + ((tmp_im * (int32_t)sss_ext2[i*2]>>shift)));
 
       // printf("SSSi(%d,%d) : (%d,%d)\n",aarx,i,sss_ext2[i<<1],sss_ext2[1+(i<<1)]);
       // printf("SSSo(%d,%d) : (%d,%d)\n",aarx,i,tmp_re2,tmp_im2);
@@ -265,7 +282,11 @@ int pss_ch_est_nr(PHY_VARS_NR_UE *ue,
       }
     }
   }
-
+#if 0
+  LOG_M("pssrx.m","pssrx",pss,LENGTH_PSS_NR,1,1);
+  LOG_M("pss_ext.m","pssext",pss_ext2,LENGTH_PSS_NR,1,1);
+  LOG_M("psschest.m","pssch",chest,LENGTH_PSS_NR,1,1);
+#endif
 #if 0
 
   for (int i = 0; i < LENGTH_PSS_NR; i++) {
@@ -307,8 +328,8 @@ int do_pss_sss_extract_nr(PHY_VARS_NR_UE *ue,
 
   for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
 
-    pss_symbol = PSS_SYMBOL_NB;  /* symbol position */
-    sss_symbol = SSS_SYMBOL_NB;
+  pss_symbol = 0;
+  sss_symbol = SSS_SYMBOL_NB-PSS_SYMBOL_NB;
 
     rxdataF  =  ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF;
 
@@ -320,7 +341,8 @@ int do_pss_sss_extract_nr(PHY_VARS_NR_UE *ue,
     pss_rxF_ext = &pss_ext[aarx][0];
     sss_rxF_ext = &sss_ext[aarx][0];
 
-    unsigned int k = ofdm_symbol_size - ((LENGTH_PSS_NR/2)+1);
+    unsigned int k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier + 56; 
+    if (k>= frame_parms->ofdm_symbol_size) k-=frame_parms->ofdm_symbol_size;
 
     for (int i=0; i < LENGTH_PSS_NR; i++) {
       if (doPss) {		  
@@ -333,10 +355,8 @@ int do_pss_sss_extract_nr(PHY_VARS_NR_UE *ue,
 
       k++;
 
-      if (k >= ofdm_symbol_size) {
-	    k++;
-        k-=ofdm_symbol_size;
-      }
+      if (k == ofdm_symbol_size) k=0;
+      
     }
   }
 
@@ -420,26 +440,27 @@ int rx_sss_nr(PHY_VARS_NR_UE *ue, int32_t *tot_metric,uint8_t *phase_max)
   /* rxdataF stores SS/PBCH from beginning of buffers in the same symbol order as in time domain */
 
   int nb_prefix_samples0 = frame_parms->nb_prefix_samples0;
-  frame_parms->nb_prefix_samples0 = 0;
+  // For now, symbol 0 = PSS/PBCH and it is never in symbol 0 or 7*2^mu (i.e. always shorter prefix)
+  frame_parms->nb_prefix_samples0 = frame_parms->nb_prefix_samples;
 
   // Do FFTs for SSS/PSS
   // SSS
   nr_slot_fep(ue,
-           SSS_SYMBOL_NB,      // symbol number
-           0,                  // Ns slot number
-           ue->rx_offset,      // sample_offset of int16_t
-           0,                  // no_prefix
-           1,                  // reset frequency estimation
-		   NR_SSS_EST);
+	      SSS_SYMBOL_NB-PSS_SYMBOL_NB,      // symbol number w.r.t. PSS
+	      0,                  // Ns slot number
+	      ue->ssb_offset,      // sample_offset of int16_t
+	      0,                  // no_prefix
+	      1,                  // reset frequency estimation
+	      NR_SSS_EST);
 
   // PSS
   nr_slot_fep(ue,
-           PSS_SYMBOL_NB,
-           0,
-           ue->rx_offset,
-           0,
-           1,
-		   NR_SSS_EST);
+	      0,
+	      0,
+	      ue->ssb_offset,
+	      0,
+	      1,
+	      NR_SSS_EST);
 
   frame_parms->nb_prefix_samples0 = nb_prefix_samples0;
 
@@ -451,19 +472,13 @@ int rx_sss_nr(PHY_VARS_NR_UE *ue, int32_t *tot_metric,uint8_t *phase_max)
 
 #ifdef DEBUG_PLOT_SSS
 
-  write_output("rxsig0.m","rxs0",&ue->common_vars.rxdata[0][0],ue->frame_parms.samples_per_tti,1,1);
-  write_output("rxdataF0.m","rxF0",&ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[0]].rxdataF[0],frame_parms->ofdm_symbol_size,2,1);
+  write_output("rxsig0.m","rxs0",&ue->common_vars.rxdata[0][0],ue->frame_parms.samples_per_subframe,1,1);
+  write_output("rxdataF0_pss.m","rxF0_pss",&ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[0]].rxdataF[0][0],frame_parms->ofdm_symbol_size,1,1);
+  write_output("rxdataF0_sss.m","rxF0_sss",&ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[0]].rxdataF[0][(SSS_SYMBOL_NB-PSS_SYMBOL_NB)*frame_parms->ofdm_symbol_size],frame_parms->ofdm_symbol_size,1,1);
   write_output("pss_ext.m","pss_ext",pss_ext,LENGTH_PSS_NR,1,1);
 
 #endif
 
-#if 0
-
-  write_output("sss_ext.m","sss_ext",sss_ext,LENGTH_SSS_NR,1,1);
-  write_output("sss_ref.m","sss_ref", d_sss,LENGTH_SSS_NR,1,1);
-
-#endif
-
 #if 0
   int16_t *p = (int16_t *)sss_ext[0];
   int16_t *p2 = (int16_t *)pss_ext[0];
@@ -472,7 +487,7 @@ int rx_sss_nr(PHY_VARS_NR_UE *ue, int32_t *tot_metric,uint8_t *phase_max)
     printf("sss ref  [%i] : %d %d \n", i, d_sss[0][0][i], d_sss[0][0][i]);
     printf("sss ext  [%i] : %d %d \n", i, p[2*i], p[2*i+1]);
 
-    printf("pss ref [%i] : %d %d \n", i, primary_synchro_nr[0][2*i], primary_synchro_nr[0][2*i+1]);
+    printf("pss ref [%i] : %d %d \n", i, primary_synchro_nr2[0][2*i], primary_synchro_nr2[0][2*i+1]);
     printf("pss ext [%i] : %d %d \n", i, p2[2*i], p2[2*i+1]);
   }
 #endif
@@ -489,6 +504,14 @@ int rx_sss_nr(PHY_VARS_NR_UE *ue, int32_t *tot_metric,uint8_t *phase_max)
 
   sss = (int16_t*)&sss_ext[0][0];
 
+#ifdef DEBUG_PLOT_SSS
+
+  write_output("sss_ext.m","sss_ext",sss_ext[0],LENGTH_SSS_NR,1,1);
+  write_output("sss_ref.m","sss_ref", d_sss,LENGTH_SSS_NR,1,1);
+
+#endif
+
+
 #if 0
 
   /* simulate of a phase shift on the signal */
@@ -503,10 +526,10 @@ int rx_sss_nr(PHY_VARS_NR_UE *ue, int32_t *tot_metric,uint8_t *phase_max)
         int16_t *ps = (int16_t *)pss_ext;
 
         for (int i = 0; i < LENGTH_SSS_NR; i++) {
-          printf("sss ref  [%i] : %d %d \n", i, d_sss[0][0][i], d_sss[0][0][i]);
+          printf("sss ref  [%i] : %d \n", i, d_sss[0][0][i]);
           printf("sss ext  [%i] : %d %d \n", i, sss[2*i], sss[2*i+1]);
 
-          printf("pss ref [%i] : %d %d \n", i, primary_synchro_nr[0][2*i], primary_synchro_nr[0][2*i+1]);
+          printf("pss ref [%i] : %d %d \n", i, primary_synchro_nr2[0][2*i], primary_synchro_nr2[0][2*i+1]);
           printf("pss ext [%i] : %d %d \n", i, ps[2*i], ps[2*i+1]);
         }
 #endif
@@ -517,8 +540,9 @@ int rx_sss_nr(PHY_VARS_NR_UE *ue, int32_t *tot_metric,uint8_t *phase_max)
   /* cosinus cos(x + y) = cos(x)cos(y) - sin(x)sin(y) */
   /* sinus   sin(x + y) = sin(x)cos(y) + cos(x)sin(y) */
 
-  for (phase=0; phase < PHASE_HYPOTHESIS_NUMBER; phase++) {  // phase offset between PSS and SSS
-    for (Nid1 = 0 ; Nid1 < N_ID_1_NUMBER; Nid1++) {          // all possible Nid1 values
+   for (Nid1 = 0 ; Nid1 < N_ID_1_NUMBER; Nid1++) {          // all possible Nid1 values
+      for (phase=0; phase < PHASE_HYPOTHESIS_NUMBER; phase++) {  // phase offset between PSS and SSS
+
 
       metric = 0;
       metric_re = 0;
@@ -528,8 +552,12 @@ int rx_sss_nr(PHY_VARS_NR_UE *ue, int32_t *tot_metric,uint8_t *phase_max)
       // This is the inner product using one particular value of each unknown parameter
       for (i=0; i < LENGTH_SSS_NR; i++) {
 
-        metric_re += d[i]*(((phase_re_nr[phase]*sss[2*i])>>SCALING_METRIC_SSS_NR) - ((phase_im_nr[phase]*sss[2*i+1])>>SCALING_METRIC_SSS_NR))
-                   + d[i]*(((phase_im_nr[phase]*sss[2*i])>>SCALING_METRIC_SSS_NR) + ((phase_re_nr[phase]*sss[2*i+1])>>SCALING_METRIC_SSS_NR));
+	
+        metric_re += d[i]*(((phase_re_nr[phase]*sss[2*i])>>SCALING_METRIC_SSS_NR) - ((phase_im_nr[phase]*sss[2*i+1])>>SCALING_METRIC_SSS_NR));
+                   
+#if 0
+	  printf("i %d, phase %d/%d: metric %d, phase (%d,%d) sss (%d,%d) d %d\n",i,phase,PHASE_HYPOTHESIS_NUMBER,metric_re,phase_re_nr[phase],phase_im_nr[phase],sss[2*i],sss[1+(2*i)],d[i]);
+#endif
       }
 
       metric = metric_re;
@@ -550,14 +578,14 @@ int rx_sss_nr(PHY_VARS_NR_UE *ue, int32_t *tot_metric,uint8_t *phase_max)
   }
 
 //#ifdef DEBUG_SSS_NR
-
+  
 #define SSS_METRIC_FLOOR_NR   (30000)
-if (*tot_metric > SSS_METRIC_FLOOR_NR) {	
+  if (*tot_metric > SSS_METRIC_FLOOR_NR) {	
     Nid2 = GET_NID2(frame_parms->Nid_cell);
     Nid1 = GET_NID1(frame_parms->Nid_cell);
     printf("Nid2 %d Nid1 %d tot_metric %d, phase_max %d \n", Nid2, Nid1, *tot_metric, *phase_max);
-}
-//#endif
+  }
+  //#endif
 
   return(0);
 }
diff --git a/openair1/PHY/TOOLS/cdot_prod.c b/openair1/PHY/TOOLS/cdot_prod.c
index 60bdcf45dd722f98a3eccab80a76963e01f9db1a..63b74afe6d02c07fb74f3b36f2d2e16b673862ae 100644
--- a/openair1/PHY/TOOLS/cdot_prod.c
+++ b/openair1/PHY/TOOLS/cdot_prod.c
@@ -158,6 +158,128 @@ int32_t dot_product(int16_t *x,
 #endif
 }
 
+int64_t dot_product64(int16_t *x,
+		      int16_t *y,
+		      uint32_t N, //must be a multiple of 8
+		      uint8_t output_shift)
+{
+
+  uint32_t n;
+
+#if defined(__x86_64__) || defined(__i386__)
+  __m128i *x128,*y128,mmtmp1,mmtmp2,mmtmp3,mmcumul,mmcumul_re,mmcumul_im;
+  __m128i minus_i = _mm_set_epi16(-1,1,-1,1,-1,1,-1,1);
+  int32_t result;
+
+  x128 = (__m128i*) x;
+  y128 = (__m128i*) y;
+
+  mmcumul_re = _mm_setzero_si128();
+  mmcumul_im = _mm_setzero_si128();
+
+  for (n=0; n<(N>>2); n++) {
+
+//    printf("n=%d, x128=%p, y128=%p\n",n,x128,y128);
+  //      print_shorts("x",&x128[0]);
+    //    print_shorts("y",&y128[0]);
+
+    // this computes Re(z) = Re(x)*Re(y) + Im(x)*Im(y)
+    mmtmp1 = _mm_madd_epi16(x128[0],y128[0]);
+      //  print_ints("retmp",&mmtmp1);
+    // mmtmp1 contains real part of 4 consecutive outputs (32-bit)
+
+    // shift and accumulate results
+    mmtmp1 = _mm_srai_epi32(mmtmp1,output_shift);
+    mmcumul_re = _mm_add_epi32(mmcumul_re,mmtmp1);
+        //print_ints("re",&mmcumul_re);
+
+
+    // this computes Im(z) = Re(x)*Im(y) - Re(y)*Im(x)
+    mmtmp2 = _mm_shufflelo_epi16(y128[0],_MM_SHUFFLE(2,3,0,1));
+        //print_shorts("y",&mmtmp2);
+    mmtmp2 = _mm_shufflehi_epi16(mmtmp2,_MM_SHUFFLE(2,3,0,1));
+        //print_shorts("y",&mmtmp2);
+    mmtmp2 = _mm_sign_epi16(mmtmp2,minus_i);
+          //  print_shorts("y",&mmtmp2);
+
+    mmtmp3 = _mm_madd_epi16(x128[0],mmtmp2);
+            //print_ints("imtmp",&mmtmp3);
+    // mmtmp3 contains imag part of 4 consecutive outputs (32-bit)
+
+    // shift and accumulate results
+    mmtmp3 = _mm_srai_epi32(mmtmp3,output_shift);
+    mmcumul_im = _mm_add_epi32(mmcumul_im,mmtmp3);
+        //print_ints("im",&mmcumul_im);
+
+    x128++;
+    y128++;
+  }
+
+  // this gives Re Re Im Im
+  mmcumul = _mm_hadd_epi32(mmcumul_re,mmcumul_im);
+    //print_ints("cumul1",&mmcumul);
+
+  // this gives Re Im Re Im
+  mmcumul = _mm_hadd_epi32(mmcumul,mmcumul);
+
+    //print_ints("cumul2",&mmcumul);
+
+
+  //mmcumul = _mm_srai_epi32(mmcumul,output_shift);
+  // extract the lower half
+  result = _mm_extract_epi64(mmcumul,0);
+  //printf("result: (%d,%d)\n",((int32_t*)&result)[0],((int32_t*)&result)[1]); 
+  _mm_empty();
+  _m_empty();
+ 
+  return(result);
+
+#elif defined(__arm__)
+  int16x4_t *x_128=(int16x4_t*)x;
+  int16x4_t *y_128=(int16x4_t*)y;
+  int32x4_t tmp_re,tmp_im;
+  int32x4_t tmp_re1,tmp_im1;
+  int32x4_t re_cumul,im_cumul;
+  int32x2_t re_cumul2,im_cumul2;
+  int32x4_t shift = vdupq_n_s32(-output_shift); 
+  int32x2x2_t result2;
+  int16_t conjug[4]__attribute__((aligned(16))) = {-1,1,-1,1} ;
+
+  re_cumul = vdupq_n_s32(0);
+  im_cumul = vdupq_n_s32(0); 
+
+  for (n=0; n<(N>>2); n++) {
+
+    tmp_re  = vmull_s16(*x_128++, *y_128++);
+    //tmp_re = [Re(x[0])Re(y[0]) Im(x[0])Im(y[0]) Re(x[1])Re(y[1]) Im(x[1])Im(y[1])] 
+    tmp_re1 = vmull_s16(*x_128++, *y_128++);
+    //tmp_re1 = [Re(x1[1])Re(x2[1]) Im(x1[1])Im(x2[1]) Re(x1[1])Re(x2[2]) Im(x1[1])Im(x2[2])] 
+    tmp_re  = vcombine_s32(vpadd_s32(vget_low_s32(tmp_re),vget_high_s32(tmp_re)),
+                           vpadd_s32(vget_low_s32(tmp_re1),vget_high_s32(tmp_re1)));
+    //tmp_re = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2]) Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])] 
+
+    tmp_im  = vmull_s16(vrev32_s16(vmul_s16(*x_128++,*(int16x4_t*)conjug)),*y_128++);
+    //tmp_im = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])]
+    tmp_im1 = vmull_s16(vrev32_s16(vmul_s16(*x_128++,*(int16x4_t*)conjug)),*y_128++);
+    //tmp_im1 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])]
+    tmp_im  = vcombine_s32(vpadd_s32(vget_low_s32(tmp_im),vget_high_s32(tmp_im)),
+                           vpadd_s32(vget_low_s32(tmp_im1),vget_high_s32(tmp_im1)));
+    //tmp_im = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])]
+
+    re_cumul = vqaddq_s32(re_cumul,vqshlq_s32(tmp_re,shift));
+    im_cumul = vqaddq_s32(im_cumul,vqshlq_s32(tmp_im,shift));
+  }
+  
+  re_cumul2 = vpadd_s32(vget_low_s32(re_cumul),vget_high_s32(re_cumul));
+  im_cumul2 = vpadd_s32(vget_low_s32(im_cumul),vget_high_s32(im_cumul));
+  re_cumul2 = vpadd_s32(re_cumul2,re_cumul2);
+  im_cumul2 = vpadd_s32(im_cumul2,im_cumul2);
+  result2   = vzip_s32(re_cumul2,im_cumul2);
+  return(vget_lane_s32(result2.val[0],0));
+#endif
+}
+
+
 
 #ifdef MAIN
 void print_bytes(char *s,__m128i *x)
diff --git a/openair1/PHY/TOOLS/dB_routines.c b/openair1/PHY/TOOLS/dB_routines.c
index 572759a68ca14ed47c4ba785816dc3ddf99f27c2..5826640b1f58e8d954dfc56a7b36102f479818a8 100644
--- a/openair1/PHY/TOOLS/dB_routines.c
+++ b/openair1/PHY/TOOLS/dB_routines.c
@@ -624,6 +624,14 @@ int8_t dB_fixed(uint32_t x)
   return dB_power;
 }
 
+uint8_t dB_fixed64(uint64_t x)
+{
+
+  if (x<(((uint64_t)1)<<32)) return(dB_fixed((uint32_t)x));
+  else                       return(4*dB_table[255] + dB_fixed(x>>32)); 
+ 
+}
+
 int8_t dB_fixed2(uint32_t x, uint32_t y)
 {
 
diff --git a/openair1/PHY/TOOLS/lte_dfts.c b/openair1/PHY/TOOLS/lte_dfts.c
index 9a1380414a40bba693d9a62c3af7709e3429cc04..e91197e1802a48f49057e8db98831aa4c358fcb7 100644
--- a/openair1/PHY/TOOLS/lte_dfts.c
+++ b/openair1/PHY/TOOLS/lte_dfts.c
@@ -74,7 +74,7 @@ static inline void cmac(__m128i a,__m128i b, __m128i *re32, __m128i *im32)
   cmac_tmp    = _mm_sign_epi16(b,*(__m128i*)reflip);
   cmac_tmp_re32  = _mm_madd_epi16(a,cmac_tmp);
 
-
+ 
   //  cmac_tmp    = _mm_shufflelo_epi16(b,_MM_SHUFFLE(2,3,0,1));
   //  cmac_tmp    = _mm_shufflehi_epi16(cmac_tmp,_MM_SHUFFLE(2,3,0,1));
   cmac_tmp = _mm_shuffle_epi8(b,_mm_set_epi8(13,12,15,14,9,8,11,10,5,4,7,6,1,0,3,2));
@@ -4466,6 +4466,7 @@ void dft2048(int16_t *x,int16_t *y,int scale)
   _mm_empty();
   _m_empty();
 
+
 }
 
 void idft2048(int16_t *x,int16_t *y,int scale)
@@ -4569,6 +4570,7 @@ void dft2048(int16_t *x,int16_t *y,int scale)
   int i;
   simd256_q15_t ONE_OVER_SQRT2_Q15_128 = set1_int16_simd256(ONE_OVER_SQRT2_Q15);
 
+
   xtmpp = xtmp;
 
   for (i=0; i<4; i++) {
@@ -4660,7 +4662,7 @@ void idft2048(int16_t *x,int16_t *y,int scale)
   simd256_q15_t ONE_OVER_SQRT2_Q15_128 = set1_int16_simd256(ONE_OVER_SQRT2_Q15);
 
   xtmpp = xtmp;
-
+  
   for (i=0; i<4; i++) {
     transpose4_ooff_simd256(x256  ,xtmpp,128);
     transpose4_ooff_simd256(x256+2,xtmpp+1,128);
@@ -4803,7 +4805,7 @@ void dft4096(int16_t *x,int16_t *y,int scale)
 
 }
 
-
+ 
 
 void idft4096(int16_t *x,int16_t *y,int scale)
 {
@@ -4853,7 +4855,7 @@ void idft4096(int16_t *x,int16_t *y,int scale)
 
       y128+=16;
     }
-
+ 
   }
 
   _mm_empty();
diff --git a/openair1/PHY/TOOLS/tools_defs.h b/openair1/PHY/TOOLS/tools_defs.h
index 66ac80cb1336c18c20a5af70851e1915ea47bc59..5a7874a1412e007dc76cff42c9e94dddbf76456e 100644
--- a/openair1/PHY/TOOLS/tools_defs.h
+++ b/openair1/PHY/TOOLS/tools_defs.h
@@ -350,6 +350,11 @@ int32_t dot_product(int16_t *x,
                     uint32_t N, //must be a multiple of 8
                     uint8_t output_shift);
 
+int64_t dot_product64(int16_t *x,
+		      int16_t *y,
+		      uint32_t N, //must be a multiple of 8
+		      uint8_t output_shift);
+
 void dft12(int16_t *x,int16_t *y);
 void dft24(int16_t *x,int16_t *y,uint8_t scale_flag);
 void dft36(int16_t *x,int16_t *y,uint8_t scale_flag);
diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h
index 6deddc57b43060b2d9151918d005705ea9c8ca2e..456ac0816f3d0a780b06e5a1e3350bb99629b296 100644
--- a/openair1/PHY/defs_nr_UE.h
+++ b/openair1/PHY/defs_nr_UE.h
@@ -920,14 +920,15 @@ typedef struct {
   /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx
   /// - second index: ? [0..287] (hard coded)
   int32_t **dl_ch_estimates_ext;
+  int log2_maxh;
   uint8_t pbch_a[NR_POLAR_PBCH_PAYLOAD_BITS>>3];
   uint32_t pbch_a_interleaved;
   uint32_t pbch_a_prime;
   uint8_t pbch_e[NR_POLAR_PBCH_E];
-  double  demod_pbch_e[NR_POLAR_PBCH_E];
+  int16_t  demod_pbch_e[NR_POLAR_PBCH_E];
   /// \brief Pointer to PBCH llrs.
   /// - first index: ? [0..1919] (hard coded)
-  int8_t *llr;
+  int16_t *llr;
   /// \brief Pointer to PBCH decoded output.
   /// - first index: ? [0..63] (hard coded)
   uint8_t *decoded_output;
@@ -1061,7 +1062,7 @@ typedef struct {
   uint32_t dmrs_pbch_bitmap_nr[DMRS_PBCH_I_SSB][DMRS_PBCH_N_HF][DMRS_BITMAP_SIZE];
 
 #endif
-  t_nrPolar_paramsPtr nrPolar_params;
+  t_nrPolar_params  *nrPolar_params;
 
   /// PBCH DMRS sequence
   uint32_t nr_gold_pbch[2][64][NR_PBCH_DMRS_LENGTH_DWORD];
@@ -1129,6 +1130,8 @@ typedef struct {
   //  uint8_t               prach_timer;
   uint8_t               decode_SIB;
   uint8_t               decode_MIB;
+  /// temporary offset during cell search prior to MIB decoding
+  int              ssb_offset;
   int              rx_offset; /// Timing offset
   int              rx_offset_diff; /// Timing adjustment for ofdm symbol0 on HW USRP
   int              time_sync_cell;
diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h
index b488d00e35ab69168a9913c03f57399287ca6efb..cc0717347311ca70bac8b0d32c3aa6ba9d01f5aa 100644
--- a/openair1/PHY/defs_nr_common.h
+++ b/openair1/PHY/defs_nr_common.h
@@ -160,10 +160,14 @@ typedef struct {
 typedef struct NR_DL_FRAME_PARMS {
   /// frequency range
   nr_frequency_range_e freq_range;
+  /// Placeholder to replace overlapping fields below
+  nfapi_nr_rf_config_t rf_config;
+  /// Placeholder to replace SSB overlapping fields below
+  nfapi_nr_sch_config_t sch_config;
   /// Number of resource blocks (RB) in DL
-  uint8_t N_RB_DL;
+  int N_RB_DL;
   /// Number of resource blocks (RB) in UL
-  uint8_t N_RB_UL;
+  int N_RB_UL;
   ///  total Number of Resource Block Groups: this is ceil(N_PRB/P)
   uint8_t N_RBG;
   /// Total Number of Resource Block Groups SubSets: this is P
diff --git a/openair1/PHY/phy_extern_nr_ue.h b/openair1/PHY/phy_extern_nr_ue.h
index 253c5b7fb90d1a7efe6b039133499c6fb7284131..2fa9ef511e5afc35300ec68152defda18d87602a 100644
--- a/openair1/PHY/phy_extern_nr_ue.h
+++ b/openair1/PHY/phy_extern_nr_ue.h
@@ -32,7 +32,7 @@ extern  char fmageren_name2[512];
 extern unsigned int RX_DMA_BUFFER[4][NB_ANTENNAS_RX];
 extern unsigned int TX_DMA_BUFFER[4][NB_ANTENNAS_TX];
 
-#include "PHY/LTE_TRANSPORT/transport_extern.h"
+//#include "PHY/LTE_TRANSPORT/transport_extern.h"
 
 extern int number_of_cards;
 
diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
index a5a111c26d53e134d26b6b84b6be2d2c32e0f3cb..27b892c4257063a9990209f490023337c2cad0d7 100644
--- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c
+++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
@@ -111,9 +111,9 @@ int nr_get_ssb_start_symbol(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *f
 
 void nr_set_ssb_first_subcarrier(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *fp)
 {
-  int start_rb = cfg->sch_config.n_ssb_crb.value / pow(2,cfg->subframe_config.numerology_index_mu.value);
+  int start_rb = cfg->sch_config.n_ssb_crb.value / (1<<cfg->subframe_config.numerology_index_mu.value);
   fp->ssb_start_subcarrier = 12 * start_rb + cfg->sch_config.ssb_subcarrier_offset.value;
-  LOG_D(PHY, "SSB first subcarrier %d\n", fp->ssb_start_subcarrier);
+  LOG_D(PHY, "SSB first subcarrier %d (%d,%d)\n", fp->ssb_start_subcarrier,start_rb,cfg->sch_config.ssb_subcarrier_offset.value);
 }
 
 void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int subframe) {
@@ -135,12 +135,13 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int subframe) {
   if (subframe == ss_subframe)
   {
     // Current implementation is based on SSB in first half frame, first candidate
-    LOG_I(PHY,"SS TX: frame %d, subframe %d, start_symbol %d\n",frame,subframe, ssb_start_symbol);
+    LOG_D(PHY,"SS TX: frame %d, subframe %d, start_symbol %d\n",frame,subframe, ssb_start_symbol);
 
     nr_generate_pss(gNB->d_pss, txdataF, AMP, ssb_start_symbol, cfg, fp);
     nr_generate_sss(gNB->d_sss, txdataF, AMP_OVER_2, ssb_start_symbol, cfg, fp);
 
     if (!(frame&7)){
+      LOG_D(PHY,"%d.%d : pbch_configured %d\n",frame,subframe,gNB->pbch_configured);
       if (gNB->pbch_configured != 1)return;
       gNB->pbch_configured = 0;
     }
@@ -182,7 +183,7 @@ void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB,
 
   num_dci = gNB->pdcch_vars.num_dci;
   if (num_dci) {
-    LOG_I(PHY, "[gNB %d] Frame %d subframe %d \
+    LOG_D(PHY, "[gNB %d] Frame %d subframe %d \
     Calling nr_generate_dci_top (number of DCI %d)\n", gNB->Mod_id, frame, subframe, num_dci);
 
     uint8_t slot_idx = gNB->pdcch_vars.dci_alloc[0].pdcch_params.first_slot;
diff --git a/openair1/SCHED_NR/sched_nr.h b/openair1/SCHED_NR/sched_nr.h
index 1e27c926f1ce2b07dac1a3ea3b18354c93951c4a..f962575a2a18250ccae87c73d4d5366586228e00 100644
--- a/openair1/SCHED_NR/sched_nr.h
+++ b/openair1/SCHED_NR/sched_nr.h
@@ -37,6 +37,7 @@
 lte_subframe_t nr_subframe_select (nfapi_nr_config_request_t *cfg, unsigned char subframe);
 void nr_set_ssb_first_subcarrier(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *fp);
 void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB, gNB_rxtx_proc_t *proc, int do_meas);
+void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int subframe);
 void nr_init_feptx_thread(RU_t *ru,pthread_attr_t *attr_feptx);
 void nr_feptx_ofdm(RU_t *ru);
 void nr_feptx_ofdm_2thread(RU_t *ru);
diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c
new file mode 100644
index 0000000000000000000000000000000000000000..d67841fb70424e5e19834877796a1c403365edb6
--- /dev/null
+++ b/openair1/SIMULATION/NR_PHY/pbchsim.c
@@ -0,0 +1,574 @@
+/*
+ * 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 <string.h>
+#include <math.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+
+#include "SIMULATION/TOOLS/sim.h"
+#include "SIMULATION/RF/rf.h"
+#include "PHY/types.h"
+#include "PHY/defs_nr_common.h"
+#include "PHY/defs_nr_UE.h"
+#include "PHY/defs_gNB.h"
+
+#include "PHY/INIT/phy_init.h"
+#include "SCHED_NR/sched_nr.h"
+
+#include "PHY/MODULATION/modulation_common.h"
+
+#include "common/ran_context.h" 
+
+PHY_VARS_gNB *gNB;
+PHY_VARS_NR_UE *UE;
+RAN_CONTEXT_t RC;
+
+
+double cpuf;
+
+// dummy functions
+int nfapi_mode=0;
+int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req) { return(0);}
+int oai_nfapi_tx_req(nfapi_tx_request_t *tx_req) { return(0); }
+
+int oai_nfapi_dl_config_req(nfapi_dl_config_request_t *dl_config_req) { return(0); }
+
+int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req) { return(0); }
+
+int oai_nfapi_nr_dl_config_req(nfapi_nr_dl_config_request_t *dl_config_req) {return(0);}
+
+uint32_t from_earfcn(int eutra_bandP,uint32_t dl_earfcn) {return(0);}
+int32_t get_uldl_offset(int eutra_bandP) {return(0);}
+
+NR_IF_Module_t *NR_IF_Module_init(int Mod_id){return(NULL);}
+
+void exit_function(const char* file, const char* function, const int line,const char *s) { 
+   const char * msg= s==NULL ? "no comment": s;
+   printf("Exiting at: %s:%d %s(), %s\n", file, line, function, msg); 
+   exit(-1); 
+}
+
+// needed for some functions
+PHY_VARS_NR_UE * PHY_vars_UE_g[1][1]={NULL};
+
+int main(int argc, char **argv)
+{
+
+  char c;
+
+  int i,l,aa;
+  double sigma2, sigma2_dB=10,SNR,snr0=-2.0,snr1=2.0;
+  uint8_t snr1set=0;
+  int **txdata;
+  double **s_re,**s_im,**r_re,**r_im;
+  double iqim = 0.0;
+  unsigned char pbch_pdu[6];
+  //  int sync_pos, sync_pos_slot;
+  //  FILE *rx_frame_file;
+  FILE *output_fd = NULL;
+  uint8_t write_output_file=0;
+  //int result;
+  int freq_offset;
+  //  int subframe_offset;
+  //  char fname[40], vname[40];
+  int trial,n_trials=1,n_errors,n_errors2,n_alamouti;
+  uint8_t transmission_mode = 1,n_tx=1,n_rx=1;
+  uint16_t Nid_cell=0;
+
+  channel_desc_t *gNB2UE;
+  uint32_t nsymb,tx_lev,tx_lev1 = 0,tx_lev2 = 0;
+  uint8_t extended_prefix_flag=0;
+  int8_t interf1=-21,interf2=-21;
+
+  FILE *input_fd=NULL,*pbch_file_fd=NULL;
+  char input_val_str[50],input_val_str2[50];
+
+  uint8_t frame_mod4,num_pdcch_symbols = 0;
+
+  SCM_t channel_model=AWGN;//Rayleigh1_anticorr;
+
+  double pbch_sinr;
+  int pbch_tx_ant;
+  int N_RB_DL=273,mu=1;
+
+  unsigned char frame_type = 0;
+  unsigned char pbch_phase = 0;
+
+  int frame=0,subframe=0;
+  int frame_length_complex_samples;
+  int frame_length_complex_samples_no_prefix;
+  NR_DL_FRAME_PARMS *frame_parms;
+  nfapi_nr_config_request_t *gNB_config;
+
+  int ret;
+  int run_initial_sync=0;
+
+  cpuf = get_cpu_freq_GHz();
+
+  /*
+  if ( load_configmodule(argc,argv) == 0) {
+    exit_fun("[SOFTMODEM] Error, configuration module init failed\n");
+  }
+  */
+
+  logInit();
+  randominit(0);
+
+  while ((c = getopt (argc, argv, "f:hA:pf:g:i:j:n:s:S:t:x:y:z:N:F:GR:dP:I")) != -1) {
+    switch (c) {
+    case 'f':
+      write_output_file=1;
+      output_fd = fopen(optarg,"w");
+
+      if (output_fd==NULL) {
+        printf("Error opening %s\n",optarg);
+        exit(-1);
+      }
+
+      break;
+
+    case 'd':
+      frame_type = 1;
+      break;
+
+    case 'g':
+      switch((char)*optarg) {
+      case 'A':
+        channel_model=SCM_A;
+        break;
+
+      case 'B':
+        channel_model=SCM_B;
+        break;
+
+      case 'C':
+        channel_model=SCM_C;
+        break;
+
+      case 'D':
+        channel_model=SCM_D;
+        break;
+
+      case 'E':
+        channel_model=EPA;
+        break;
+
+      case 'F':
+        channel_model=EVA;
+        break;
+
+      case 'G':
+        channel_model=ETU;
+        break;
+
+      default:
+        msg("Unsupported channel model!\n");
+        exit(-1);
+      }
+
+      break;
+
+    case 'i':
+      interf1=atoi(optarg);
+      break;
+
+    case 'j':
+      interf2=atoi(optarg);
+      break;
+
+    case 'n':
+      n_trials = atoi(optarg);
+      break;
+
+    case 's':
+      snr0 = atof(optarg);
+      msg("Setting SNR0 to %f\n",snr0);
+      break;
+
+    case 'S':
+      snr1 = atof(optarg);
+      snr1set=1;
+      msg("Setting SNR1 to %f\n",snr1);
+      break;
+
+      /*
+      case 't':
+      Td= atof(optarg);
+      break;
+      */
+    case 'p':
+      extended_prefix_flag=1;
+      break;
+
+      /*
+      case 'r':
+      ricean_factor = pow(10,-.1*atof(optarg));
+      if (ricean_factor>1) {
+        printf("Ricean factor must be between 0 and 1\n");
+        exit(-1);
+      }
+      break;
+      */
+    case 'x':
+      transmission_mode=atoi(optarg);
+
+      if ((transmission_mode!=1) &&
+          (transmission_mode!=2) &&
+          (transmission_mode!=6)) {
+        msg("Unsupported transmission mode %d\n",transmission_mode);
+        exit(-1);
+      }
+
+      break;
+
+    case 'y':
+      n_tx=atoi(optarg);
+
+      if ((n_tx==0) || (n_tx>2)) {
+        msg("Unsupported number of tx antennas %d\n",n_tx);
+        exit(-1);
+      }
+
+      break;
+
+    case 'z':
+      n_rx=atoi(optarg);
+
+      if ((n_rx==0) || (n_rx>2)) {
+        msg("Unsupported number of rx antennas %d\n",n_rx);
+        exit(-1);
+      }
+
+      break;
+
+    case 'N':
+      Nid_cell = atoi(optarg);
+      break;
+
+    case 'R':
+      N_RB_DL = atoi(optarg);
+      break;
+
+    case 'F':
+      input_fd = fopen(optarg,"r");
+
+      if (input_fd==NULL) {
+        printf("Problem with filename %s\n",optarg);
+        exit(-1);
+      }
+
+      break;
+
+    case 'P':
+      pbch_phase = atoi(optarg);
+
+      if (pbch_phase>3)
+        printf("Illegal PBCH phase (0-3) got %d\n",pbch_phase);
+
+      break;
+      
+    case 'I':
+      run_initial_sync=1;
+      break;
+    default:
+    case 'h':
+      printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n",
+             argv[0]);
+      printf("-h This message\n");
+      printf("-p Use extended prefix mode\n");
+      printf("-d Use TDD\n");
+      printf("-n Number of frames to simulate\n");
+      printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
+      printf("-S Ending SNR, runs from SNR0 to SNR1\n");
+      printf("-t Delay spread for multipath channel\n");
+      printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n");
+      printf("-x Transmission mode (1,2,6 for the moment)\n");
+      printf("-y Number of TX antennas used in eNB\n");
+      printf("-z Number of RX antennas used in UE\n");
+      printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n");
+      printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n");
+      printf("-N Nid_cell\n");
+      printf("-R N_RB_DL\n");
+      printf("-O oversampling factor (1,2,4,8,16)\n");
+      printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n");
+      //    printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n");
+      printf("-f Output filename (.txt format) for Pe/SNR results\n");
+      printf("-F Input filename (.txt format) for RX conformance testing\n");
+      exit (-1);
+      break;
+    }
+  }
+
+  if (snr1set==0)
+    snr1 = snr0+10;
+
+
+  printf("Initializing gNodeB for mu %d, N_RB_DL %d\n",mu,N_RB_DL);
+
+  RC.gNB = (PHY_VARS_gNB***) malloc(sizeof(PHY_VARS_gNB **));
+  RC.gNB[0] = (PHY_VARS_gNB**) malloc(sizeof(PHY_VARS_gNB *));
+  RC.gNB[0][0] = malloc(sizeof(PHY_VARS_gNB));
+  gNB = RC.gNB[0][0];
+  gNB_config = &gNB->gNB_config;
+  frame_parms = &gNB->frame_parms; //to be initialized I suppose (maybe not necessary for PBCH)
+  frame_parms->nb_antennas_tx = n_tx;
+  frame_parms->nb_antennas_rx = n_rx;
+  frame_parms->N_RB_DL = N_RB_DL;
+  frame_parms->N_RB_UL = N_RB_DL;
+
+  nr_phy_config_request_sim(gNB,N_RB_DL,N_RB_DL,mu);
+  phy_init_nr_gNB(gNB,0,0);
+
+  double fs,bw;
+
+  if (mu == 1 && N_RB_DL == 217) { 
+    fs = 122.88e6;
+    bw = 80e6;
+  }					       
+  else if (mu == 1 && N_RB_DL == 245) {
+    fs = 122.88e6;
+    bw = 90e6;
+  }
+  else if (mu == 1 && N_RB_DL == 273) {
+    fs = 122.88e6;
+    bw = 100e6;
+  }
+  else if (mu == 1 && N_RB_DL == 106) { 
+    fs = 61.44e6;
+    bw = 40e6;
+  }
+  else AssertFatal(1==0,"Unsupported numerology for mu %d, N_RB %d\n",mu, N_RB_DL);
+
+  gNB2UE = new_channel_desc_scm(n_tx,
+                                n_rx,
+                                channel_model,
+ 				fs, 
+				bw, 
+                                0,
+                                0,
+                                0);
+
+  if (gNB2UE==NULL) {
+    msg("Problem generating channel model. Exiting.\n");
+    exit(-1);
+  }
+
+  frame_length_complex_samples = frame_parms->samples_per_subframe;
+  frame_length_complex_samples_no_prefix = frame_parms->samples_per_subframe_wCP;
+
+  s_re = malloc(2*sizeof(double*));
+  s_im = malloc(2*sizeof(double*));
+  r_re = malloc(2*sizeof(double*));
+  r_im = malloc(2*sizeof(double*));
+  txdata = malloc(2*sizeof(int*));
+
+  for (i=0; i<2; i++) {
+
+    s_re[i] = malloc(frame_length_complex_samples*sizeof(double));
+    bzero(s_re[i],frame_length_complex_samples*sizeof(double));
+    s_im[i] = malloc(frame_length_complex_samples*sizeof(double));
+    bzero(s_im[i],frame_length_complex_samples*sizeof(double));
+
+    r_re[i] = malloc(frame_length_complex_samples*sizeof(double));
+    bzero(r_re[i],frame_length_complex_samples*sizeof(double));
+    r_im[i] = malloc(frame_length_complex_samples*sizeof(double));
+    bzero(r_im[i],frame_length_complex_samples*sizeof(double));
+
+    printf("Allocating %d samples for txdata\n",frame_length_complex_samples);
+    txdata[i] = malloc(frame_length_complex_samples*sizeof(int));
+    bzero(r_re[i],frame_length_complex_samples*sizeof(int));
+  
+  }
+
+  if (pbch_file_fd!=NULL) {
+    load_pbch_desc(pbch_file_fd);
+  }
+
+
+  //configure UE
+  UE = malloc(sizeof(PHY_VARS_NR_UE));
+  memcpy(&UE->frame_parms,frame_parms,sizeof(NR_DL_FRAME_PARMS));
+  phy_init_nr_top(UE);
+  if (run_initial_sync==1)  UE->is_synchronized = 0;
+  else                      UE->is_synchronized = 1;
+                      
+  UE->perfect_ce = 0;
+
+  if (init_nr_ue_signal(UE, 1, 0) != 0)
+  {
+    printf("Error at UE NR initialisation\n");
+    exit(-1);
+  }
+
+  nr_gold_pbch(UE);
+  // generate signal
+  if (input_fd==NULL) {
+    gNB->pbch_configured = 1;
+    for (int i=0;i<4;i++) gNB->pbch_pdu[i]=i+1;
+    nr_common_signal_procedures (gNB,frame,subframe);
+  }
+
+  /*  
+  LOG_M("txsigF0.m","txsF0", gNB->common_vars.txdataF[0],frame_length_complex_samples_no_prefix,1,1);
+  if (gNB->frame_parms.nb_antennas_tx>1)
+    LOG_M("txsigF1.m","txsF1", gNB->common_vars.txdataF[1],frame_length_complex_samples_no_prefix,1,1);
+  */
+  //TODO: loop over slots
+  for (aa=0; aa<gNB->frame_parms.nb_antennas_tx; aa++) {
+    if (gNB_config->subframe_config.dl_cyclic_prefix_type.value == 1) {
+      PHY_ofdm_mod(gNB->common_vars.txdataF[aa],
+		   txdata[aa],
+		   frame_parms->ofdm_symbol_size,
+		   12,
+		   frame_parms->nb_prefix_samples,
+		   CYCLIC_PREFIX);
+    } else {
+      nr_normal_prefix_mod(gNB->common_vars.txdataF[aa],
+			   txdata[aa],
+			   14,
+			   frame_parms);
+    }
+  }
+  /*
+  LOG_M("txsig0.m","txs0", txdata[0],frame_length_complex_samples,1,1);
+  if (gNB->frame_parms.nb_antennas_tx>1)
+    LOG_M("txsig1.m","txs1", txdata[1],frame_length_complex_samples,1,1);
+  */
+  int txlev = signal_energy(&txdata[0][5*frame_parms->ofdm_symbol_size + 4*frame_parms->nb_prefix_samples + frame_parms->nb_prefix_samples0],
+			    frame_parms->ofdm_symbol_size + frame_parms->nb_prefix_samples);
+
+  //  printf("txlev %d (%f)\n",txlev,10*log10(txlev));
+
+  for (i=0; i<frame_length_complex_samples; i++) {
+    for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
+      r_re[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)]);
+      r_im[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)+1]);
+    }
+  }
+  
+  for (SNR=snr0; SNR<snr1; SNR+=.2) {
+
+    n_errors = 0;
+    n_errors2 = 0;
+    n_alamouti = 0;
+
+    for (trial=0; trial<n_trials; trial++) {
+
+      // multipath channel
+      //multipath_channel(gNB2UE,s_re,s_im,r_re,r_im,frame_length_complex_samples,0);
+      
+      //AWGN
+      sigma2_dB = 10*log10((double)txlev)-SNR;
+      sigma2 = pow(10,sigma2_dB/10);
+      //      printf("sigma2 %f (%f dB)\n",sigma2,sigma2_dB);
+
+      for (i=0; i<frame_length_complex_samples; i++) {
+	for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
+	  
+	  ((short*) UE->common_vars.rxdata[aa])[2*i]   = (short) ((r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+	  ((short*) UE->common_vars.rxdata[aa])[2*i+1] = (short) ((r_im[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+	}
+      }
+
+      if (n_trials==1) {
+	LOG_M("rxsig0.m","rxs0", UE->common_vars.rxdata[0],frame_length_complex_samples,1,1);
+	if (gNB->frame_parms.nb_antennas_tx>1)
+	  LOG_M("rxsig1.m","rxs1", UE->common_vars.rxdata[1],frame_length_complex_samples,1,1);
+      }
+      if (UE->is_synchronized == 0) {
+	ret = nr_initial_sync(UE, normal_txrx);
+	printf("nr_initial_sync1 returns %d\n",ret);
+	if (ret<0) n_errors++;
+      }
+      else {
+	UE->rx_offset=0;
+	//symbol 1
+	nr_slot_fep(UE,
+		    5,
+		    0,
+		    0,
+		    0,
+		    1,
+		    NR_PBCH_EST);
+	
+	//symbol 2
+	nr_slot_fep(UE,
+		    6,
+		    0,
+		    0,
+		    0,
+		    1,
+		    NR_PBCH_EST);
+	
+	//symbol 3
+	nr_slot_fep(UE,
+		    7,
+		    0,
+		    0,
+		    0,
+		    1,
+		    NR_PBCH_EST);
+	
+	ret = nr_rx_pbch(UE,
+			 &UE->proc.proc_rxtx[0],
+			 UE->pbch_vars[0],
+			 frame_parms,
+			 0,
+			 SISO,
+			 UE->high_speed_flag);
+
+	if (ret<0) n_errors++;
+      }
+    } //noise trials
+
+    printf("SNR %f : n_errors (negative CRC) = %d/%d\n", SNR,n_errors,n_trials);
+
+    if (n_trials==1)
+      break;
+
+  } // NSR
+
+  for (i=0; i<2; i++) {
+    free(s_re[i]);
+    free(s_im[i]);
+    free(r_re[i]);
+    free(r_im[i]);
+    free(txdata[i]);
+  }
+
+  free(s_re);
+  free(s_im);
+  free(r_re);
+  free(r_im);
+  free(txdata);
+
+  if (write_output_file)
+    fclose(output_fd);
+
+  return(n_errors);
+
+}
+
+
+
diff --git a/openair1/SIMULATION/NR_UE_PHY/unit_tests/src/pbch_test.c b/openair1/SIMULATION/NR_UE_PHY/unit_tests/src/pbch_test.c
index f1913f0371815b07641f2902c54499fea4a83f33..fc5360848c7ee95ac72bba77acd9dc0593bd1956 100644
--- a/openair1/SIMULATION/NR_UE_PHY/unit_tests/src/pbch_test.c
+++ b/openair1/SIMULATION/NR_UE_PHY/unit_tests/src/pbch_test.c
@@ -39,9 +39,10 @@ typedef int nfapi_nr_pfcch_commonSearchSpaces_t;
 #include "../nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h"
 
 #include "PHY/defs_nr_UE.h"
-#include "PHY/INIT/init_extern.h"
 #include "PHY/phy_extern_nr_ue.h"
-#include "PHY/NR_TRANSPORT/nr_transport.h"
+#include "PHY/INIT/init_extern.h"
+#include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h"
+#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h"
 
 #include "PHY/NR_REFSIG/ss_pbch_nr.h"
 #include "PHY/NR_REFSIG/pss_nr.h"
@@ -222,7 +223,7 @@ void set_sequence_sss(PHY_VARS_NR_UE *PHY_vars_UE, int offset, int slot_offset)
   }
 #else
 
-  insert_sss_nr(&tmp, frame_parms);
+ insert_sss_nr(tmp, frame_parms);
 
 #endif
 }
@@ -393,7 +394,7 @@ int main(int argc, char *argv[])
   int size_test_position;
 
   /* this is a pointer to the function in charge of the test */
-  int (*p_test_synchro_pss_sss)(PHY_VARS_NR_UE *PHY_vars_UE, int position_symbol, int sequence_number, test_t *test) = test_synchro_pss_sss;
+  int (*p_test_synchro_pss_sss)(PHY_VARS_NR_UE *PHY_vars_UE, int position_symbol, int sequence_number) = test_synchro_pss_sss_nr;
 
 #if 0
   int Nid_cell[] = { (3*0+0), (3*71+0), (3*21+2), (3*21+2), (3*55+1), (3*111+2) };
@@ -413,21 +414,19 @@ int main(int argc, char *argv[])
   size_test_position = sizeof(test_position)/sizeof(int);
 
   printf("***********************************\n");
-  printf("    %s Test NR synchronisation \n", test.test_current);
+  printf("    %s Test NR synchroisation \n", test.test_current);
   printf("***********************************\n");
 
   for (unsigned int index = 0; index < (sizeof(Nid_cell)/sizeof(int)); index++) {
 
-    PHY_vars_eNB->frame_parms.Nid_cell = Nid_cell[index];
-
-    Nid2 = GET_NID2(PHY_vars_eNB->frame_parms.Nid_cell);
-    Nid1 = GET_NID1(PHY_vars_eNB->frame_parms.Nid_cell);
+    Nid2 = GET_NID2(Nid_cell[index]);
+    Nid1 = GET_NID1(Nid_cell[index]);
 
     for (int position = 0; position < size_test_position; position++) {
 
       PHY_vars_UE->frame_parms.Nid_cell = (3 * N_ID_1_NUMBER) + N_ID_2_NUMBER; /* set to unvalid value */
 
-      decoded_pbch = (*p_test_synchro_pss_sss)(PHY_vars_UE, test_position[position], Nid2, &test); /* return phase index which gives phase error from an array */
+      decoded_pbch = (*p_test_synchro_pss_sss)(PHY_vars_UE, test_position[position], Nid2); /* return phase index which gives phase error from an array */
 
       test.number_of_tests++;
       printf("\n%s ", test.test_current);
diff --git a/openair1/SIMULATION/TOOLS/sim.h b/openair1/SIMULATION/TOOLS/sim.h
index bde7b9250633858f8e628a0230d66dc7cfe0d197..1cfc096a33b953a2047ae15533e984df8c464a4f 100644
--- a/openair1/SIMULATION/TOOLS/sim.h
+++ b/openair1/SIMULATION/TOOLS/sim.h
@@ -398,7 +398,7 @@ void multipath_tv_channel(channel_desc_t *desc,
 double N_RB2sampling_rate(uint16_t N_RB);
 double N_RB2channel_bandwidth(uint16_t N_RB);
 
-#include "targets/RT/USER/rfsim.h"
+//#include "targets/RT/USER/rfsim.h"
 
 void do_DL_sig(sim_t *sim,
                uint16_t subframe,
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
index 5f88a20b8b936d05806d69966f375b70a60879de..2e73775f29645e68c29587ddc0e12dc742889880 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
@@ -75,7 +75,7 @@ void nr_schedule_css_dlsch_phytest(module_id_t   module_idP,
     pdu_rel15->vrb_to_prb_mapping = 0;
     pdu_rel15->mcs = 12;
     pdu_rel15->tb_scaling = 1;
-    LOG_I(MAC, "[gNB scheduler phytest] DCI type 1 payload: freq_alloc %d, time_alloc %d, vrb to prb %d, mcs %d tb_scaling %d\n",
+    LOG_D(MAC, "[gNB scheduler phytest] DCI type 1 payload: freq_alloc %d, time_alloc %d, vrb to prb %d, mcs %d tb_scaling %d\n",
                 pdu_rel15->frequency_domain_assignment,
                 pdu_rel15->time_domain_assignment,
                 pdu_rel15->vrb_to_prb_mapping,
@@ -86,7 +86,7 @@ void nr_schedule_css_dlsch_phytest(module_id_t   module_idP,
     params_rel15->rnti_type = NFAPI_NR_RNTI_RA;
     params_rel15->dci_format = NFAPI_NR_DL_DCI_FORMAT_1_0;
     //params_rel15->aggregation_level = 1;
-    LOG_I(MAC, "DCI type 1 params: rmsi_pdcch_config %d, rnti %d, rnti_type %d, dci_format %d\n \
+    LOG_D(MAC, "DCI type 1 params: rmsi_pdcch_config %d, rnti %d, rnti_type %d, dci_format %d\n \
                 coreset params: mux_pattern %d, n_rb %d, n_symb %d, rb_offset %d  \n \
                 ss params : nb_ss_sets_per_slot %d, first symb %d, nb_slots %d, sfn_mod2 %d, first slot %d\n",
                 0,
diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c
index a87501ced95ee3401e63235d410420a30fb70e33..ca7206744c9673b22f0f6e4430a7b13a1da99ed7 100644
--- a/openair2/RRC/NR/MESSAGES/asn1_msg.c
+++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c
@@ -267,7 +267,7 @@ uint8_t do_MIB_NR(rrc_gNB_carrier_data_t *carrier,
     default:
     AssertFatal(1==0,"Unknown subCarrierSpacingCommon %d\n",subCarrierSpacingCommon);
   }
-
+mib->message.choice.mib->subCarrierSpacingCommon = 1;
     switch (dmrs_TypeA_Position) {
     case 2:
       mib->message.choice.mib->dmrs_TypeA_Position = NR_MIB__dmrs_TypeA_Position_pos2;
diff --git a/targets/RT/USER/nr-ru.c b/targets/RT/USER/nr-ru.c
index 22a8af279932239b6bb9bbceec4ddaf5c6d02662..1c39906d2b1c278f3230953d5702f8b0cf794574 100644
--- a/targets/RT/USER/nr-ru.c
+++ b/targets/RT/USER/nr-ru.c
@@ -844,10 +844,10 @@ void tx_rf(RU_t *ru) {
     for (i=0; i<ru->nb_tx; i++)
       txp[i] = (void*)&ru->common.txdata[i][(proc->subframe_tx*fp->samples_per_subframe)-sf_extension];
 
-    /*if (proc->subframe_tx == 0){
+    if (proc->subframe_tx == 0){
       write_output("txdataF_frame.m","txdataF_frame",&ru->common.txdataF_BF[i],fp->samples_per_subframe_wCP, 1, 1);
       write_output("txdata_frame.m","txdata_frame",&ru->common.txdata[i],fp->samples_per_subframe, 1, 1);
-    }*/
+    }
     
     VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TST, (proc->timestamp_tx-ru->openair0_cfg.tx_sample_advance)&0xffffffff );
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, 1 );
diff --git a/targets/RT/USER/nr-softmodem.c b/targets/RT/USER/nr-softmodem.c
index a4af82871082023b0e1e357c0de3255b8a9d7775..23c047822ad30460cbd2877dc736826094fb7b4a 100644
--- a/targets/RT/USER/nr-softmodem.c
+++ b/targets/RT/USER/nr-softmodem.c
@@ -94,8 +94,6 @@ unsigned short config_frames[4] = {2,9,11,13};
 // current status is that every UE has a DL scope for a SINGLE eNB (gnb_id=0)
 // at eNB 0, an UL scope for every UE
 
-short nr_mod_table[NR_MOD_TABLE_SIZE_SHORT] = {0,0,23170,23170,-23170,-23170,23170,23170,23170,-23170,-23170,23170,-23170,-23170};
-
 FD_lte_phy_scope_ue  *form_ue[NUMBER_OF_UE_MAX];
 FD_lte_phy_scope_enb *form_enb[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
 FD_stats_form                  *form_stats=NULL,*form_stats_l2=NULL;
diff --git a/targets/RT/USER/nr-ue.c b/targets/RT/USER/nr-ue.c
index ee1b7c20b66d4671a579bd81ff1dc0b4d170c2ea..3453fb71649d1f0319fa576cf2d0a7b15b2bccca 100644
--- a/targets/RT/USER/nr-ue.c
+++ b/targets/RT/USER/nr-ue.c
@@ -492,7 +492,7 @@ static void *UE_thread_synch(void *arg) {
                     //UE->rfdevice.trx_set_gains_func(&openair0,&openair0_cfg[0]);
                     //UE->rfdevice.trx_stop_func(&UE->rfdevice);
                     // sleep(1);
-		            nr_init_frame_parms_ue(&UE->frame_parms);
+		    //nr_init_frame_parms_ue(&UE->frame_parms);
                     /*if (UE->rfdevice.trx_start_func(&UE->rfdevice) != 0 ) {
                         LOG_E(HW,"Could not start the device\n");
                         oai_exit=1;
diff --git a/targets/RT/USER/nr-uesoftmodem.c b/targets/RT/USER/nr-uesoftmodem.c
index d28f6860b78974c4865853dcffd1867add4aac36..e4ffe4a74863fb249eb504ef81cd2b89865a7141 100644
--- a/targets/RT/USER/nr-uesoftmodem.c
+++ b/targets/RT/USER/nr-uesoftmodem.c
@@ -493,7 +493,7 @@ void *l2l1_task(void *arg) {
 }
 #endif
 
-extern int16_t dlsch_demod_shift;
+int16_t dlsch_demod_shift;
 
 static void get_options(void) {
   int CC_id;