From ec0aea2374414a6bf0b1c24442909ad0e6a1923c Mon Sep 17 00:00:00 2001
From: Parminder Singh <parminder.singh@iis.fraunhofer.de>
Date: Fri, 28 Aug 2020 09:51:58 +0200
Subject: [PATCH] Removed separate LLR calculation for PTRS

- New Data Structure to store PTRS RE's is removed
- LLR's are calculated at the end symbol for whole slot
---
 openair1/PHY/INIT/nr_init.c                   | 12 +---
 .../NR_ESTIMATION/nr_ul_channel_estimation.c  | 11 ++-
 .../PHY/NR_TRANSPORT/nr_ulsch_demodulation.c  | 72 +++++++------------
 openair1/PHY/defs_gNB.h                       | 11 +--
 openair1/SIMULATION/NR_PHY/ulsim.c            |  4 --
 5 files changed, 36 insertions(+), 74 deletions(-)

diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index 604e17ecfcf..c1509d6c657 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -248,10 +248,8 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
     pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates     = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
     pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates_ext = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
     pusch_vars[ULSCH_id]->ptrs_phase_per_slot   = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
-    pusch_vars[ULSCH_id]->ptrs_valid_re_per_slot= (int16_t **)malloc16(Prx*sizeof(int16_t *) );
     pusch_vars[ULSCH_id]->ul_ch_estimates_time  = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
     pusch_vars[ULSCH_id]->rxdataF_comp          = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
-    pusch_vars[ULSCH_id]->rxdataF_ptrs_comp     = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
     pusch_vars[ULSCH_id]->ul_ch_mag0            = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
     pusch_vars[ULSCH_id]->ul_ch_magb0           = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
     pusch_vars[ULSCH_id]->ul_ch_mag             = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
@@ -268,9 +266,7 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
       pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates[i]       = (int32_t *)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size*2*fp->symbols_per_slot ); // max intensity in freq is 1 sc every 2 RBs
       pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates_ext[i]   = (int32_t *)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size*2*fp->symbols_per_slot );
       pusch_vars[ULSCH_id]->ptrs_phase_per_slot[i]   = (int32_t *)malloc16_clear( sizeof(int32_t)*fp->symbols_per_slot); // symbols per slot
-      pusch_vars[ULSCH_id]->ptrs_valid_re_per_slot[i]= (int16_t *)malloc16_clear( sizeof(int16_t)*fp->symbols_per_slot);
       pusch_vars[ULSCH_id]->rxdataF_comp[i]          = (int32_t *)malloc16_clear( sizeof(int32_t)*N_RB_UL*12*fp->symbols_per_slot );
-      pusch_vars[ULSCH_id]->rxdataF_ptrs_comp[i]     = (int32_t *)malloc16_clear( sizeof(int32_t)*N_RB_UL*12*fp->symbols_per_slot );
       pusch_vars[ULSCH_id]->ul_ch_mag0[i]            = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*N_RB_UL*12 );
       pusch_vars[ULSCH_id]->ul_ch_magb0[i]           = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*N_RB_UL*12 );
       pusch_vars[ULSCH_id]->ul_ch_mag[i]             = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*N_RB_UL*12 );
@@ -279,7 +275,8 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
     }
     printf("ULSCH_id %d (before llr alloc) : %p\n",ULSCH_id,gNB->dlsch[0][0]->harq_processes[0]);
     pusch_vars[ULSCH_id]->llr = (int16_t *)malloc16_clear( (8*((3*8*6144)+12))*sizeof(int16_t) ); // [hna] 6144 is LTE and (8*((3*8*6144)+12)) is not clear
-    printf("ULSCH_id %d (after llr alloc) : %p\n",ULSCH_id,gNB->dlsch[0][0]->harq_processes[0]); 
+    printf("ULSCH_id %d (after llr alloc) : %p\n",ULSCH_id,gNB->dlsch[0][0]->harq_processes[0]);
+    pusch_vars[ULSCH_id]->ul_valid_re_per_slot  = (int16_t *)malloc16_clear( sizeof(int16_t)*fp->symbols_per_slot);
   } //ulsch_id
 /*
   for (ulsch_id=0; ulsch_id<NUMBER_OF_UE_MAX; ulsch_id++)
@@ -341,9 +338,7 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
       free_and_zero(pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates[i]);
       free_and_zero(pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates_ext[i]);
       free_and_zero(pusch_vars[ULSCH_id]->ptrs_phase_per_slot[i]);
-      free_and_zero(pusch_vars[ULSCH_id]->ptrs_valid_re_per_slot[i]);
       free_and_zero(pusch_vars[ULSCH_id]->rxdataF_comp[i]);
-      free_and_zero(pusch_vars[ULSCH_id]->rxdataF_ptrs_comp[i]);
       free_and_zero(pusch_vars[ULSCH_id]->ul_ch_mag0[i]);
       free_and_zero(pusch_vars[ULSCH_id]->ul_ch_magb0[i]);
       free_and_zero(pusch_vars[ULSCH_id]->ul_ch_mag[i]);
@@ -359,9 +354,8 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
     free_and_zero(pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates_ext);
     free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates_time);
     free_and_zero(pusch_vars[ULSCH_id]->ptrs_phase_per_slot);
-    free_and_zero(pusch_vars[ULSCH_id]->ptrs_valid_re_per_slot);
+    free_and_zero(pusch_vars[ULSCH_id]->ul_valid_re_per_slot);
     free_and_zero(pusch_vars[ULSCH_id]->rxdataF_comp);
-    free_and_zero(pusch_vars[ULSCH_id]->rxdataF_ptrs_comp);
     free_and_zero(pusch_vars[ULSCH_id]->ul_ch_mag0);
     free_and_zero(pusch_vars[ULSCH_id]->ul_ch_magb0);
     free_and_zero(pusch_vars[ULSCH_id]->ul_ch_mag);
diff --git a/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c b/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c
index 1e2a0e64cd5..aac3119a018 100644
--- a/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c
+++ b/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c
@@ -536,7 +536,6 @@ void nr_pusch_ptrs_processing(PHY_VARS_gNB *gNB,
 {
   NR_DL_FRAME_PARMS *frame_parms = &gNB->frame_parms;
   int16_t *phase_per_symbol;
-  int16_t *no_re_per_symbol;
 
   uint8_t         L_ptrs          = 0;
   uint8_t         right_side_ref  = 0;
@@ -560,8 +559,6 @@ void nr_pusch_ptrs_processing(PHY_VARS_gNB *gNB,
   for (int aarx=0; aarx< frame_parms->nb_antennas_rx; aarx++)
   {
     phase_per_symbol = (int16_t*)gNB->pusch_vars[ulsch_id]->ptrs_phase_per_slot[aarx];
-    no_re_per_symbol = gNB->pusch_vars[ulsch_id]->ptrs_valid_re_per_slot[aarx];
-    no_re_per_symbol[symbol] = nb_re_pusch;
     /* if not PTRS symbol set current ptrs symbol index to zero*/
     gNB->pusch_vars[ulsch_id]->ptrs_symbol_index = 0;
     gNB->pusch_vars[ulsch_id]->ptrs_sc_per_ofdm_symbol = 0;
@@ -581,8 +578,6 @@ void nr_pusch_ptrs_processing(PHY_VARS_gNB *gNB,
                                 gNB->nr_gold_pusch_dmrs[rel15_ul->scid],
                                 &phase_per_symbol[2* symbol],
                                 &gNB->pusch_vars[ulsch_id]->ptrs_sc_per_ofdm_symbol);
-      /*  Subtract total PTRS RE's in the symbol from PUSCH RE's */
-      no_re_per_symbol[symbol] = nb_re_pusch - gNB->pusch_vars[ulsch_id]->ptrs_sc_per_ofdm_symbol;
     }
     /* DMRS Symbol channel estimates extraction */
     else if(dmrs_symbol_flag)
@@ -621,9 +616,11 @@ void nr_pusch_ptrs_processing(PHY_VARS_gNB *gNB,
         left_side_ref = right_side_ref;
       } /*loop over dmrs positions */
 
-      //nr_pusch_phase_interpolation(phase_per_symbol,rel15_ul->start_symbol_index,frame_parms->symbols_per_slot );
 #ifdef DEBUG_UL_PTRS
       LOG_M("ptrsEst.m","est",gNB->pusch_vars[ulsch_id]->ptrs_phase_per_slot[aarx],frame_parms->symbols_per_slot,1,1 );
+      LOG_M("rxdataF_bf_ptrs_comp.m","bf_ptrs_cmp",
+            &gNB->pusch_vars[0]->rxdataF_comp[aarx][rel15_ul->start_symbol_index * NR_NB_SC_PER_RB * rel15_ul->rb_size],
+            rel15_ul->nr_of_symbols * NR_NB_SC_PER_RB * rel15_ul->rb_size,1,1);
 #endif
 
       /*------------------------------------------------------------------------------------------------------- */
@@ -636,7 +633,7 @@ void nr_pusch_ptrs_processing(PHY_VARS_gNB *gNB,
 #endif
         rotate_cpx_vector((int16_t*)&gNB->pusch_vars[ulsch_id]->rxdataF_comp[aarx][(i * rel15_ul->rb_size * NR_NB_SC_PER_RB)],
                           &phase_per_symbol[2* i],
-                          (int16_t*)&gNB->pusch_vars[ulsch_id]->rxdataF_ptrs_comp[aarx][(i * rel15_ul->rb_size * NR_NB_SC_PER_RB)],
+                          (int16_t*)&gNB->pusch_vars[ulsch_id]->rxdataF_comp[aarx][(i * rel15_ul->rb_size * NR_NB_SC_PER_RB)],
                           (rel15_ul->rb_size * NR_NB_SC_PER_RB),
                           15);
       }// symbol loop
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
index dd31ee3471b..90526075352 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
@@ -1035,6 +1035,8 @@ int nr_rx_pusch(PHY_VARS_gNB *gNB,
 
   if (nb_re_pusch > 0) {
 
+    gNB->pusch_vars[ulsch_id]->ul_valid_re_per_slot[symbol] = nb_re_pusch;
+
     start_meas(&gNB->ulsch_rbs_extraction_stats);
     nr_ulsch_extract_rbs_single(gNB->common_vars.rxdataF,
                                 gNB->pusch_vars[ulsch_id],
@@ -1124,53 +1126,31 @@ int nr_rx_pusch(PHY_VARS_gNB *gNB,
                                symbol,
                                nb_re_pusch);
       stop_meas(&gNB->ulsch_ptrs_processing_stats);
-      /*---------------------------------------------------------------------------------------------------- */
-      /*  Calculate LLR based upon new compensated data after all PTRS symbols are processed                 */
-      /*-----------------------------------------------------------------------------------------------------*/
-      if(symbol == (rel15_ul->start_symbol_index + rel15_ul->nr_of_symbols -1))
-      {
-        for (int aarx=0; aarx< frame_parms->nb_antennas_rx; aarx++)
-        {
-          for(uint8_t i =rel15_ul->start_symbol_index; i< (rel15_ul->start_symbol_index + rel15_ul->nr_of_symbols);i++)
-          {
-            start_meas(&gNB->ulsch_llr_stats);
-            nr_ulsch_compute_llr(&gNB->pusch_vars[ulsch_id]->rxdataF_ptrs_comp[aarx][i * (rel15_ul->rb_size * NR_NB_SC_PER_RB)],
-                                 gNB->pusch_vars[ulsch_id]->ul_ch_mag0,
-                                 gNB->pusch_vars[ulsch_id]->ul_ch_magb0,
-                                 &gNB->pusch_vars[ulsch_id]->llr[gNB->pusch_vars[ulsch_id]->rxdataF_ext_offset * rel15_ul->qam_mod_order],
-                                 rel15_ul->rb_size,
-                                 gNB->pusch_vars[ulsch_id]->ptrs_valid_re_per_slot[aarx][i],
-                                 i,
-                                 rel15_ul->qam_mod_order);
-            stop_meas(&gNB->ulsch_llr_stats);
-            gNB->pusch_vars[ulsch_id]->rxdataF_ext_offset = gNB->pusch_vars[ulsch_id]->rxdataF_ext_offset +  gNB->pusch_vars[ulsch_id]->ptrs_valid_re_per_slot[aarx][i];
-          }// symbol loop
-          /* For scope library rxdataF_comp is used so in PTRS case we point it to correct data pointer */
-          gNB->pusch_vars[ulsch_id]->rxdataF_comp[aarx] = gNB->pusch_vars[ulsch_id]->rxdataF_ptrs_comp[aarx];
-        }// antenna loop
-      }// last symbol check
-    }// PTRS processing
-    else // if no ptrs is enabled
-    {
-    //----------------------------------------------------------
-    //-------------------- LLRs computation --------------------
-    //----------------------------------------------------------
 
-    start_meas(&gNB->ulsch_llr_stats);
-    AssertFatal(gNB->pusch_vars[ulsch_id]->rxdataF_ext_offset * rel15_ul->qam_mod_order+nb_re_pusch*rel15_ul->qam_mod_order < (8*((3*8*6144)+12)) , "Mysterious llr buffer size check");
-    nr_ulsch_compute_llr(&gNB->pusch_vars[ulsch_id]->rxdataF_comp[0][symbol * rel15_ul->rb_size * NR_NB_SC_PER_RB],
-                         gNB->pusch_vars[ulsch_id]->ul_ch_mag0,
-                         gNB->pusch_vars[ulsch_id]->ul_ch_magb0,
-                         &gNB->pusch_vars[ulsch_id]->llr[gNB->pusch_vars[ulsch_id]->rxdataF_ext_offset * rel15_ul->qam_mod_order],
-                         rel15_ul->rb_size,
-                         nb_re_pusch,
-                         symbol,
-                         rel15_ul->qam_mod_order);
-    stop_meas(&gNB->ulsch_llr_stats);
-
-    gNB->pusch_vars[ulsch_id]->rxdataF_ext_offset = gNB->pusch_vars[ulsch_id]->rxdataF_ext_offset +  nb_re_pusch;
-    }/* End for PTRS Condition */
+      /*  Subtract total PTRS RE's in the symbol from PUSCH RE's */
+      gNB->pusch_vars[ulsch_id]->ul_valid_re_per_slot[symbol] -= gNB->pusch_vars[ulsch_id]->ptrs_sc_per_ofdm_symbol;
+    }
+
+    /*---------------------------------------------------------------------------------------------------- */
+    /*--------------------  LLRs computation  -------------------------------------------------------------*/
+    /*-----------------------------------------------------------------------------------------------------*/
+    if(symbol == (rel15_ul->start_symbol_index + rel15_ul->nr_of_symbols -1))
+    {
+      for(uint8_t i =rel15_ul->start_symbol_index; i< (rel15_ul->start_symbol_index + rel15_ul->nr_of_symbols);i++)
+        {
+          start_meas(&gNB->ulsch_llr_stats);
+          nr_ulsch_compute_llr(&gNB->pusch_vars[ulsch_id]->rxdataF_comp[0][i * (rel15_ul->rb_size * NR_NB_SC_PER_RB)],
+                               gNB->pusch_vars[ulsch_id]->ul_ch_mag0,
+                               gNB->pusch_vars[ulsch_id]->ul_ch_magb0,
+                               &gNB->pusch_vars[ulsch_id]->llr[gNB->pusch_vars[ulsch_id]->rxdataF_ext_offset * rel15_ul->qam_mod_order],
+                               rel15_ul->rb_size,
+                               gNB->pusch_vars[ulsch_id]->ul_valid_re_per_slot[i],
+                               i,
+                               rel15_ul->qam_mod_order);
+          stop_meas(&gNB->ulsch_llr_stats);
+          gNB->pusch_vars[ulsch_id]->rxdataF_ext_offset = gNB->pusch_vars[ulsch_id]->rxdataF_ext_offset +  gNB->pusch_vars[ulsch_id]->ul_valid_re_per_slot[i];
+        }// symbol loop
+    }// last symbol check
   }
   return (0);
-
 }
diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h
index 04c832fc3a1..fd2305f4591 100644
--- a/openair1/PHY/defs_gNB.h
+++ b/openair1/PHY/defs_gNB.h
@@ -403,10 +403,6 @@ typedef struct {
   /// - first index: rx antenna id [0..nb_antennas_rx[
   /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
   int32_t **rxdataF_comp;
-  /// \brief Holds the PTRS compensated signal.
-  /// - first index: rx antenna id [0..nb_antennas_rx[
-  /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
-  int32_t **rxdataF_ptrs_comp;
   /// \brief Magnitude of the UL channel estimates. Used for 2nd-bit level thresholds in LLR computation
   /// - first index: rx antenna id [0..nb_antennas_rx[
   /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
@@ -454,10 +450,9 @@ typedef struct {
   /// - first index: ? [0..7] Number of Antenna
   /// - second index: ? [0...14] smybol per slot
   int32_t **ptrs_phase_per_slot;
-  /// \brief Total RE count after PTRS RE's are extracted from respective symbol.
-  /// - first index: ? [0..7] Number of Antenna
-  /// - second index: ? [0...14] smybol per slot
-  int16_t **ptrs_valid_re_per_slot;
+  /// \brief Total RE count after DMRS/PTRS RE's are extracted from respective symbol.
+  /// - first index: ? [0...14] smybol per slot
+  int16_t *ul_valid_re_per_slot;
   /// flag to verify if channel level computation is done
   uint8_t cl_done;
 } NR_gNB_PUSCH;
diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c
index 999eb179ae6..e27b87f2daf 100644
--- a/openair1/SIMULATION/NR_PHY/ulsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulsim.c
@@ -830,10 +830,6 @@ int main(int argc, char **argv)
 		&gNB->pusch_vars[0]->ul_ch_estimates_ext[0][(start_symbol+1)*NR_NB_SC_PER_RB * pusch_pdu->rb_size],(nb_symb_sch-1)*NR_NB_SC_PER_RB * pusch_pdu->rb_size,1,1);
 	  LOG_M("rxsigF0_comp.m","rxsF0_comp",
 		&gNB->pusch_vars[0]->rxdataF_comp[0][(start_symbol+1)*NR_NB_SC_PER_RB * pusch_pdu->rb_size],(nb_symb_sch-1)*NR_NB_SC_PER_RB * pusch_pdu->rb_size,1,1);
-#ifdef DEBUG_UL_PTRS
-          LOG_M("rxdataF_ptrs_comp.m","ptrs_comp",
-                &gNB->pusch_vars[0]->rxdataF_ptrs_comp[0][(start_symbol+1)*NR_NB_SC_PER_RB * pusch_pdu->rb_size],(nb_symb_sch-1)*NR_NB_SC_PER_RB * pusch_pdu->rb_size,1,1);
-#endif
 	}
         start_meas(&gNB->phy_proc_rx);
         ////////////////////////////////////////////////////////////
-- 
GitLab