From 49f86b0aa933eed092aae9d032c400d8cdb9f9e4 Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Wed, 18 Oct 2017 11:37:26 +0200
Subject: [PATCH] added LUT for finer-grain ULSCH power measurement
 compensation based on TBS. Still seems too high, to be checked some more.

---
 openair1/PHY/INIT/lte_init.c                  |  2 ++
 openair1/PHY/LTE_TRANSPORT/proto.h            |  2 ++
 .../PHY/LTE_TRANSPORT/ulsch_demodulation.c    | 27 ++++++++++++++-----
 targets/RT/USER/lte-enb.c                     |  1 -
 4 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/openair1/PHY/INIT/lte_init.c b/openair1/PHY/INIT/lte_init.c
index 9c9ab1a29b..4f11f79352 100644
--- a/openair1/PHY/INIT/lte_init.c
+++ b/openair1/PHY/INIT/lte_init.c
@@ -1857,6 +1857,8 @@ int phy_init_lte_eNB(PHY_VARS_eNB *eNB,
 
   generate_ul_ref_sigs_rx();
   
+  init_ulsch_power_LUT();
+
   // SRS
   for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
     srs_vars[UE_id].srs = (int32_t*)malloc16_clear(2*fp->ofdm_symbol_size*sizeof(int32_t));
diff --git a/openair1/PHY/LTE_TRANSPORT/proto.h b/openair1/PHY/LTE_TRANSPORT/proto.h
index 441cd5539a..3ee8df87e3 100644
--- a/openair1/PHY/LTE_TRANSPORT/proto.h
+++ b/openair1/PHY/LTE_TRANSPORT/proto.h
@@ -2109,6 +2109,8 @@ int32_t rx_pucch_emul(PHY_VARS_eNB *phy_vars_eNB,
                       uint8_t *payload);
 
 
+void init_ulsch_power_LUT(void);
+
 /*!
   \brief Check for PRACH TXop in subframe
   @param frame_parms Pointer to LTE_DL_FRAME_PARMS
diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c b/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c
index 43c14bde1c..8e97a9af2e 100644
--- a/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c
+++ b/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c
@@ -1102,7 +1102,15 @@ void ulsch_channel_level(int32_t **drs_ch_estimates_ext,
 #endif
 }
 
+int ulsch_power_LUT[750];
 
+void init_ulsch_power_LUT() {
+  
+  int i;
+
+  for (i=0;i<750;i++) ulsch_power_LUT[i] = (int)ceil((pow(2.0,(double)i/100) - 1.0));
+
+}
 
 void rx_ulsch(PHY_VARS_eNB *eNB,
 	      eNB_rxtx_proc_t *proc,
@@ -1166,19 +1174,26 @@ void rx_ulsch(PHY_VARS_eNB *eNB,
 
   int correction_factor = 1;
   int deltaMCS=1; 
-  int MPR_times_Ks;
+  int MPR_times_100Ks;
 
   if (deltaMCS==1) {
-// Note we're using TBS instead of sumKr, since didn't run segmentation yet!
-    MPR_times_Ks = 5*ulsch[UE_id]->harq_processes[harq_pid]->TBS/(ulsch[UE_id]->harq_processes[harq_pid]->nb_rb*12*4*ulsch[UE_id]->harq_processes[harq_pid]->Nsymb_pusch);
-    if (MPR_times_Ks > 0) correction_factor = (1<<MPR_times_Ks) - 1;
+    // Note we're using TBS instead of sumKr, since didn't run segmentation yet!
+
+    MPR_times_100Ks = 500*ulsch[UE_id]->harq_processes[harq_pid]->TBS/(ulsch[UE_id]->harq_processes[harq_pid]->nb_rb*12*4*ulsch[UE_id]->harq_processes[harq_pid]->Nsymb_pusch);
+
+    AssertFatal(MPR_times_100Ks < 750 && MPR_times_100Ks >= 0,"Impossible value for MPR_times_100Ks %d (TBS %d,Nre %d)\n",
+		MPR_times_100Ks,ulsch[UE_id]->harq_processes[harq_pid]->TBS,
+		(ulsch[UE_id]->harq_processes[harq_pid]->nb_rb*12*4*ulsch[UE_id]->harq_processes[harq_pid]->Nsymb_pusch));
+
+    if (MPR_times_100Ks > 0) correction_factor = ulsch_power_LUT[MPR_times_100Ks];
+			       
   }
   for (i=0; i<frame_parms->nb_antennas_rx; i++) {
     
     pusch_vars->ulsch_power[i] = signal_energy_nodc(pusch_vars->drs_ch_estimates[i],
 						    ulsch[UE_id]->harq_processes[harq_pid]->nb_rb*12)/correction_factor;
-//printf("%4.4d.%d power harq_pid %d rb %2.2d TBS %2.2d (MPR_times_Ks %d correction %d)  power %d dBtimes10\n", proc->frame_rx, proc->subframe_rx, harq_pid, ulsch[UE_id]->harq_processes[harq_pid]->nb_rb, ulsch[UE_id]->harq_processes[harq_pid]->TBS,MPR_times_Ks,correction_factor,dB_fixed_times10(pusch_vars->ulsch_power[i])); 
-    
+    /*    printf("%4.4d.%d power harq_pid %d rb %2.2d TBS %2.2d (MPR_times_Ks %d correction %d)  power %d dBtimes10\n", proc->frame_rx, proc->subframe_rx, harq_pid, ulsch[UE_id]->harq_processes[harq_pid]->nb_rb, ulsch[UE_id]->harq_processes[harq_pid]->TBS,MPR_times_100Ks,correction_factor,dB_fixed_times10(pusch_vars->ulsch_power[i])); 
+     */
   }
 
 
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index 8e476e06b7..c7cc203da6 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -577,7 +577,6 @@ static void* eNB_thread_prach_br( void* param ) {
 #endif
 
 
-extern void init_fep_thread(PHY_VARS_eNB *, pthread_attr_t *);
 extern void init_td_thread(PHY_VARS_eNB *, pthread_attr_t *);
 extern void init_te_thread(PHY_VARS_eNB *, pthread_attr_t *);
 
-- 
GitLab