dlsch_demodulation.c 247 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * 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.0  (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
 */
21 22 23

/*! \file PHY/LTE_TRANSPORT/dlsch_demodulation.c
 * \brief Top-level routines for demodulating the PDSCH physical channel from 36-211, V8.6 2009-03
24
 * \author R. Knopp, F. Kaltenberger,A. Bhamri, S. Aubert, X. Xiang
25
 * \date 2011
26
 * \version 0.1
27 28 29 30 31
 * \company Eurecom
 * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr,ankit.bhamri@eurecom.fr,sebastien.aubert@eurecom.fr
 * \note
 * \warning
 */
32
//#include "PHY/defs.h"
33
#include "PHY/extern.h"
34
#include "SCHED/defs.h"
35 36
#include "defs.h"
#include "extern.h"
37
#include "PHY/sse_intrin.h"
38
#include "T.h"
39 40 41 42

#ifndef USER_MODE
#define NOCYGWIN_STATIC static
#else
43
#define NOCYGWIN_STATIC
44 45
#endif

46 47 48 49 50
/* dynamic shift for LLR computation for TM3/4
 * set as command line argument, see lte-softmodem.c
 * default value: 0
 */
int16_t dlsch_demod_shift = 0;
Cedric Roux's avatar
Cedric Roux committed
51
int16_t interf_unaw_shift = 13;
52

53 54
//#define DEBUG_HARQ

55 56 57
//#undef LOG_D
//#define LOG_D LOG_I

58
//#define DEBUG_PHY 1
59
//#define DEBUG_DLSCH_DEMOD 1
60

Bilel's avatar
Bilel committed
61

62 63

// [MCS][i_mod (0,1,2) = (2,4,6)]
64
unsigned char offset_mumimo_llr_drange_fix=0;
65
//inferference-free case
66
unsigned char interf_unaw_shift_tm4_mcs[29]={5, 3, 4, 3, 3, 2, 1, 1, 2, 0, 1, 1, 1, 1, 0, 0,
67
                                             1, 1, 1, 1, 0, 2, 1, 0, 1, 0, 1, 0, 0} ;
68
unsigned char interf_unaw_shift_tm1_mcs[29]={5, 5, 4, 3, 3, 3, 2, 2, 4, 4, 2, 3, 3, 3, 1, 1,
69
                                             0, 1, 1, 2, 5, 4, 4, 6, 5, 1, 0, 5, 6} ; // mcs 21, 26, 28 seem to be errorneous
70

71 72 73
/*
//original values from sebastion + same hand tuning
unsigned char offset_mumimo_llr_drange[29][3]={{8,8,8},{7,7,7},{7,7,7},{7,7,7},{6,6,6},{6,6,6},{6,6,6},{5,5,5},{4,4,4},{1,2,4}, // QPSK
74 75
{5,5,4},{5,5,5},{5,5,5},{3,3,3},{2,2,2},{2,2,2},{2,2,2}, // 16-QAM
{2,2,1},{3,3,3},{3,3,3},{3,3,1},{2,2,2},{2,2,2},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}; //64-QAM
76
*/
77 78 79 80 81 82 83 84
 /*
 //first optimization try
 unsigned char offset_mumimo_llr_drange[29][3]={{7, 8, 7},{6, 6, 7},{6, 6, 7},{6, 6, 6},{5, 6, 6},{5, 5, 6},{5, 5, 6},{4, 5, 4},{4, 3, 4},{3, 2, 2},{6, 5, 5},{5, 4, 4},{5, 5, 4},{3, 3, 2},{2, 2, 1},{2, 1, 1},{2, 2, 2},{3, 3, 3},{3, 3, 2},{3, 3, 2},{3, 2, 1},{2, 2, 2},{2, 2, 2},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}};
 */
 //second optimization try
 /*
   unsigned char offset_mumimo_llr_drange[29][3]={{5, 8, 7},{4, 6, 8},{3, 6, 7},{7, 7, 6},{4, 7, 8},{4, 7, 4},{6, 6, 6},{3, 6, 6},{3, 6, 6},{1, 3, 4},{1, 1, 0},{3, 3, 2},{3, 4, 1},{4, 0, 1},{4, 2, 2},{3, 1, 2},{2, 1, 0},{2, 1, 1},{1, 0, 1},{1, 0, 1},{0, 0, 0},{1, 0, 0},{0, 0, 0},{0, 1, 0},{1, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}};  w
 */
85
unsigned char offset_mumimo_llr_drange[29][3]= {{0, 6, 5},{0, 4, 5},{0, 4, 5},{0, 5, 4},{0, 5, 6},{0, 5, 3},{0, 4, 4},{0, 4, 4},{0, 3, 3},{0, 1, 2},{1, 1, 0},{1, 3, 2},{3, 4, 1},{2, 0, 0},{2, 2, 2},{1, 1, 1},{2, 1, 0},{2, 1, 1},{1, 0, 1},{1, 0, 1},{0, 0, 0},{1, 0, 0},{0, 0, 0},{0, 1, 0},{1, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}};
86 87


88
extern void print_shorts(char *s,int16_t *x);
89

90

91
int rx_pdsch(PHY_VARS_UE *ue,
92
             UE_rxtx_proc_t *proc,
93 94
             PDSCH_t type,
             unsigned char eNB_id,
95
             unsigned char eNB_id_i, //if this == ue->n_connected_eNB, we assume MU interference
96
             uint32_t frame,
97
             uint8_t subframe,
98 99
             unsigned char symbol,
             unsigned char first_symbol_flag,
100
             RX_type_t rx_type,
101
             unsigned char i_mod,
102 103 104
             unsigned char harq_pid)
{

105 106 107
  LTE_UE_COMMON *common_vars  = &ue->common_vars;
  LTE_UE_PDSCH **pdsch_vars;
  LTE_DL_FRAME_PARMS *frame_parms    = &ue->frame_parms;
108
  PHY_MEASUREMENTS *measurements = &ue->measurements;
109
  LTE_UE_DLSCH_t   **dlsch;
110

Bilel's avatar
Bilel committed
111 112 113
  int avg[4];
  int avg_0[2];
  int avg_1[2];
Elena Lukashova's avatar
Elena Lukashova committed
114

115 116
  uint8_t slot = 0;

117
  unsigned char aatx,aarx;
118

119
  unsigned short nb_rb = 0, round;
120
  int avgs = 0, rb;
121
  LTE_DL_UE_HARQ_t *dlsch0_harq,*dlsch1_harq = 0;
Elena Lukashova's avatar
Elena Lukashova committed
122

123
  uint8_t beamforming_mode;
124
  uint32_t *rballoc;
125

126 127
  int32_t **rxdataF_comp_ptr;
  int32_t **dl_ch_mag_ptr;
128 129
  int32_t codeword_TB0 = -1;
  int32_t codeword_TB1 = -1;
130 131


132

133 134
  switch (type) {
  case SI_PDSCH:
135
    pdsch_vars = &ue->pdsch_vars_SI[eNB_id];
136 137
    dlsch = &ue->dlsch_SI[eNB_id];
    dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
138
    beamforming_mode  = 0;
139
    break;
140

141
  case RA_PDSCH:
142
    pdsch_vars = &ue->pdsch_vars_ra[eNB_id];
143 144
    dlsch = &ue->dlsch_ra[eNB_id];
    dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
145
    beamforming_mode  = 0;
146
    break;
147

148
  case PDSCH:
149 150
    pdsch_vars = ue->pdsch_vars[subframe%RX_NB_TH];
    dlsch = ue->dlsch[subframe%RX_NB_TH][eNB_id];
151
    //printf("status TB0 = %d, status TB1 = %d \n", dlsch[0]->harq_processes[harq_pid]->status, dlsch[1]->harq_processes[harq_pid]->status);
Bilel's avatar
Bilel committed
152 153 154 155 156
    LOG_D(PHY,"AbsSubframe %d.%d / Sym %d harq_pid %d,  harq status %d.%d \n",
                   frame,subframe,symbol,harq_pid,
                   dlsch[0]->harq_processes[harq_pid]->status,
                   dlsch[1]->harq_processes[harq_pid]->status);

157 158 159 160 161 162
    if ((dlsch[0]->harq_processes[harq_pid]->status == ACTIVE) &&
        (dlsch[1]->harq_processes[harq_pid]->status == ACTIVE)){
      codeword_TB0 = dlsch[0]->harq_processes[harq_pid]->codeword;
      codeword_TB1 = dlsch[1]->harq_processes[harq_pid]->codeword;
      dlsch0_harq = dlsch[codeword_TB0]->harq_processes[harq_pid];
      dlsch1_harq = dlsch[codeword_TB1]->harq_processes[harq_pid];
163 164 165
#ifdef DEBUG_HARQ
      printf("[DEMOD] I am assuming both TBs are active\n");
#endif
166
    }
167 168 169 170 171 172
     else if ((dlsch[0]->harq_processes[harq_pid]->status == ACTIVE) &&
              (dlsch[1]->harq_processes[harq_pid]->status != ACTIVE) ) {
      codeword_TB0 = dlsch[0]->harq_processes[harq_pid]->codeword;
      dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
      dlsch1_harq = NULL;
      codeword_TB1 = -1;
173 174 175
#ifdef DEBUG_HARQ
      printf("[DEMOD] I am assuming only TB0 is active\n");
#endif
176
    }
177 178 179
     else if ((dlsch[0]->harq_processes[harq_pid]->status != ACTIVE) &&
              (dlsch[1]->harq_processes[harq_pid]->status == ACTIVE) ){
      codeword_TB1 = dlsch[1]->harq_processes[harq_pid]->codeword;
Bilel's avatar
Bilel committed
180 181
      dlsch0_harq  = dlsch[1]->harq_processes[harq_pid];
      dlsch1_harq  = NULL;
182
      codeword_TB0 = -1;
183
#ifdef DEBUG_HARQ
184
      printf("[DEMOD] I am assuming only TB1 is active, it is in cw %d\n", dlsch0_harq->codeword);
185
#endif
186
    }
187 188 189 190
    else {
      LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: no active DLSCH\n",ue->proc.proc_rxtx[0].frame_rx,subframe);
      return(-1);
    }
191
    beamforming_mode  = ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id];
192 193 194
    break;

  default:
Cedric Roux's avatar
Cedric Roux committed
195
    LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: Unknown PDSCH format %d\n",ue->proc.proc_rxtx[0].frame_rx,subframe,type);
196 197 198
    return(-1);
    break;
  }
199 200 201 202
#ifdef DEBUG_HARQ
  printf("[DEMOD] MIMO mode = %d\n", dlsch0_harq->mimo_mode);
  printf("[DEMOD] cw for TB0 = %d, cw for TB1 = %d\n", codeword_TB0, codeword_TB1);
#endif
203

204 205
  DevAssert(dlsch0_harq);
  round = dlsch0_harq->round;
206
  //printf("round = %d\n", round);
207

208
  if (eNB_id > 2) {
jiangx's avatar
jiangx committed
209
    LOG_W(PHY,"dlsch_demodulation.c: Illegal eNB_id %d\n",eNB_id);
210 211
    return(-1);
  }
212

213 214
  if (!common_vars) {
    LOG_W(PHY,"dlsch_demodulation.c: Null common_vars\n");
215 216 217
    return(-1);
  }

218
  if (!dlsch[0]) {
jiangx's avatar
jiangx committed
219
    LOG_W(PHY,"dlsch_demodulation.c: Null dlsch_ue pointer\n");
220 221 222
    return(-1);
  }

223 224
  if (!pdsch_vars) {
    LOG_W(PHY,"dlsch_demodulation.c: Null pdsch_vars pointer\n");
225 226
    return(-1);
  }
227

228
  if (!frame_parms) {
229
    LOG_W(PHY,"dlsch_demodulation.c: Null frame_parms\n");
230 231
    return(-1);
  }
232

233 234 235 236 237
  if (((frame_parms->Ncp == NORMAL) && (symbol>=7)) ||
      ((frame_parms->Ncp == EXTENDED) && (symbol>=6)))
    rballoc = dlsch0_harq->rb_alloc_odd;
  else
    rballoc = dlsch0_harq->rb_alloc_even;
238

239

240
  if (dlsch0_harq->mimo_mode>DUALSTREAM_PUSCH_PRECODING) {
241 242 243
    LOG_E(PHY,"This transmission mode is not yet supported!\n");
    return(-1);
  }
244 245


246 247 248 249 250 251 252
  if ((dlsch0_harq->mimo_mode==LARGE_CDD) || ((dlsch0_harq->mimo_mode>=DUALSTREAM_UNIFORM_PRECODING1) && (dlsch0_harq->mimo_mode<=DUALSTREAM_PUSCH_PRECODING)))  {
    DevAssert(dlsch1_harq);
    if (eNB_id!=eNB_id_i) {
      LOG_E(PHY,"TM3/TM4 requires to set eNB_id==eNB_id_i!\n");
      return(-1);
    }
  }
253 254 255 256 257

  if(symbol > ue->frame_parms.symbols_per_tti>>1)
  {
      slot = 1;
  }
258 259 260
#ifdef DEBUG_HARQ
  printf("Demod  dlsch0_harq->pmi_alloc %d\n",  dlsch0_harq->pmi_alloc);
#endif
261

Xiwen JIANG's avatar
Xiwen JIANG committed
262
  if (frame_parms->nb_antenna_ports_eNB>1 && beamforming_mode==0) {
263
#ifdef DEBUG_DLSCH_MOD
264
    LOG_I(PHY,"dlsch: using pmi %x (%p), rb_alloc %x\n",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),dlsch[0],dlsch0_harq->rb_alloc_even[0]);
265
#endif
266

267 268 269
#if UE_TIMING_TRACE
    start_meas(&ue->generic_stat_bis[subframe%RX_NB_TH][slot]);
#endif
270 271
    nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].rxdataF,
                                   common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].dl_ch_estimates[eNB_id],
272 273
                                   pdsch_vars[eNB_id]->rxdataF_ext,
                                   pdsch_vars[eNB_id]->dl_ch_estimates_ext,
274
                                   dlsch0_harq->pmi_alloc,
275
                                   pdsch_vars[eNB_id]->pmi_ext,
276
                                   rballoc,
277 278
                                   symbol,
                                   subframe,
279
                                   ue->high_speed_flag,
280
                                   frame_parms,
281
                                   dlsch0_harq->mimo_mode);
Gabriel's avatar
Gabriel committed
282 283
#ifdef DEBUG_DLSCH_MOD
      printf("dlsch: using pmi %lx, rb_alloc %x, pmi_ext ",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),*rballoc);
284
       for (rb=0;rb<nb_rb;rb++)
285
          printf("%d",pdsch_vars[eNB_id]->pmi_ext[rb]);
Gabriel's avatar
Gabriel committed
286 287
       printf("\n");
#endif
288

289
   if (rx_type >= rx_IC_single_stream) {
290
      if (eNB_id_i<ue->n_connected_eNB) // we are in TM5
291 292
      nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].rxdataF,
                                       common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].dl_ch_estimates[eNB_id_i],
293 294
                                       pdsch_vars[eNB_id_i]->rxdataF_ext,
                                       pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
295
                                       dlsch0_harq->pmi_alloc,
296
                                       pdsch_vars[eNB_id_i]->pmi_ext,
297
                                       rballoc,
298 299
                                       symbol,
                                       subframe,
300
                                       ue->high_speed_flag,
301
                                       frame_parms,
302
                                       dlsch0_harq->mimo_mode);
303
      else
304 305
        nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].rxdataF,
                                       common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].dl_ch_estimates[eNB_id],
306 307
                                       pdsch_vars[eNB_id_i]->rxdataF_ext,
                                       pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
308
                                       dlsch0_harq->pmi_alloc,
309
                                       pdsch_vars[eNB_id_i]->pmi_ext,
310
                                       rballoc,
311 312
                                       symbol,
                                       subframe,
313
                                       ue->high_speed_flag,
314
                                       frame_parms,
315
                                       dlsch0_harq->mimo_mode);
316
    }
317
  } else if (beamforming_mode==0) { //else if nb_antennas_ports_eNB==1 && beamforming_mode == 0
318 319
    nb_rb = dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].rxdataF,
                                     common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].dl_ch_estimates[eNB_id],
320 321
                                     pdsch_vars[eNB_id]->rxdataF_ext,
                                     pdsch_vars[eNB_id]->dl_ch_estimates_ext,
322
                                     dlsch0_harq->pmi_alloc,
323
                                     pdsch_vars[eNB_id]->pmi_ext,
324
                                     rballoc,
325 326
                                     symbol,
                                     subframe,
327
                                     ue->high_speed_flag,
328
                                     frame_parms);
329

Elena Lukashova's avatar
Elena Lukashova committed
330
   if (rx_type==rx_IC_single_stream) {
331
     if (eNB_id_i<ue->n_connected_eNB)
332 333
        nb_rb = dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].rxdataF,
                                         common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].dl_ch_estimates[eNB_id_i],
334
                                         pdsch_vars[eNB_id_i]->rxdataF_ext,
335
                                         pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
336
                                         dlsch0_harq->pmi_alloc,
337
                                         pdsch_vars[eNB_id_i]->pmi_ext,
338
                                         rballoc,
339 340
                                         symbol,
                                         subframe,
341
                                         ue->high_speed_flag,
342
                                         frame_parms);
343
      else
344 345
        nb_rb = dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].rxdataF,
                                         common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].dl_ch_estimates[eNB_id],
346
                                         pdsch_vars[eNB_id_i]->rxdataF_ext,
347
                                         pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
348
                                         dlsch0_harq->pmi_alloc,
349
                                         pdsch_vars[eNB_id_i]->pmi_ext,
350
                                         rballoc,
351 352
                                         symbol,
                                         subframe,
353
                                         ue->high_speed_flag,
354
                                         frame_parms);
355
    }
356
  } else if (beamforming_mode==7) { //else if beamforming_mode == 7
357
    nb_rb = dlsch_extract_rbs_TM7(common_vars->common_vars_rx_data_per_thread[subframe%RX_NB_TH].rxdataF,
358 359 360
                                  pdsch_vars[eNB_id]->dl_bf_ch_estimates,
                                  pdsch_vars[eNB_id]->rxdataF_ext,
                                  pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
361
                                  rballoc,
362 363
                                  symbol,
                                  subframe,
364
                                  ue->high_speed_flag,
365
                                  frame_parms);
366

367
  } else if(beamforming_mode>7) {
368
    LOG_W(PHY,"dlsch_demodulation: beamforming mode not supported yet.\n");
369
  }
370

Bilel's avatar
Bilel committed
371
  //printf("nb_rb = %d, eNB_id %d\n",nb_rb,eNB_id);
372
  if (nb_rb==0) {
373
    LOG_D(PHY,"dlsch_demodulation.c: nb_rb=0\n");
374 375
    return(-1);
  }
376

377 378 379 380 381 382 383 384 385
#if UE_TIMING_TRACE
    stop_meas(&ue->generic_stat_bis[subframe%RX_NB_TH][slot]);
#if DISABLE_LOG_X
    printf("[AbsSFN %d.%d] Slot%d Symbol %d Flag %d type %d: Pilot/Data extraction %5.2f \n",frame,subframe,slot,
            symbol,ue->high_speed_flag,type,symbol,ue->generic_stat_bis[subframe%RX_NB_TH][slot].p_time/(cpuf*1000.0));
#else
    LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d Flag %d type %d: Pilot/Data extraction  %5.2f \n",frame,subframe,slot,symbol,
            ue->high_speed_flag,type,ue->generic_stat_bis[subframe%RX_NB_TH][slot].p_time/(cpuf*1000.0));
#endif
386 387
#endif

388 389 390
#if UE_TIMING_TRACE
    start_meas(&ue->generic_stat_bis[subframe%RX_NB_TH][slot]);
#endif
391
  aatx = frame_parms->nb_antenna_ports_eNB;
Elena Lukashova's avatar
Elena Lukashova committed
392 393
  aarx = frame_parms->nb_antennas_rx;

394
  dlsch_scale_channel(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
395 396 397 398
                      frame_parms,
                      dlsch,
                      symbol,
                      nb_rb);
399

400 401 402 403 404 405
  if ((dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) &&
      (rx_type==rx_IC_single_stream) &&
      (eNB_id_i==ue->n_connected_eNB) &&
      (dlsch0_harq->dl_power_off==0)
     )  // TM5 two-user
  {
406
    dlsch_scale_channel(pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
407
                        frame_parms,
408
                        dlsch,
409 410
                        symbol,
                        nb_rb);
411
  }
412

413 414 415 416 417 418 419 420 421 422 423 424
#if UE_TIMING_TRACE
    stop_meas(&ue->generic_stat_bis[subframe%RX_NB_TH][slot]);
#if DISABLE_LOG_X
    printf("[AbsSFN %d.%d] Slot%d Symbol %d: Channel Scale %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[subframe%RX_NB_TH][slot].p_time/(cpuf*1000.0));
#else
    LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: Channel Scale  %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[subframe%RX_NB_TH][slot].p_time/(cpuf*1000.0));
#endif
#endif

#if UE_TIMING_TRACE
    start_meas(&ue->generic_stat_bis[subframe%RX_NB_TH][slot]);
#endif
425
  if (first_symbol_flag==1) {
426 427 428
    if (beamforming_mode==0){
      if (dlsch0_harq->mimo_mode<LARGE_CDD) {
        dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
429 430 431 432
                           frame_parms,
                           avg,
                           symbol,
                           nb_rb);
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
        avgs = 0;
        for (aatx=0;aatx<frame_parms->nb_antenna_ports_eNB;aatx++)
          for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++)
            avgs = cmax(avgs,avg[(aatx<<1)+aarx]);

        pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2)+1;
     }
     else if ((dlsch0_harq->mimo_mode == LARGE_CDD) ||
           ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
            (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING)))
     {
      dlsch_channel_level_TM34(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                 frame_parms,
                                 pdsch_vars[eNB_id]->pmi_ext,
                                 avg_0,
                                 avg_1,
                                 symbol,
                                 nb_rb,
                                 dlsch0_harq->mimo_mode);

Cedric Roux's avatar
Cedric Roux committed
453
      LOG_D(PHY,"Channel Level TM34  avg_0 %d, avg_1 %d, rx_type %d, rx_standard %d, dlsch_demod_shift %d \n", avg_0[0],
454
              avg_1[0], rx_type, rx_standard, dlsch_demod_shift);
455
        if (rx_type>rx_standard) {
456 457
          avg_0[0] = (log2_approx(avg_0[0])/2) + dlsch_demod_shift;// + 2 ;//+ 4;
          avg_1[0] = (log2_approx(avg_1[0])/2) + dlsch_demod_shift;// + 2 ;//+ 4;
458 459
          pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0);
          pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0);
460
         // printf("dlsch_demod_shift  %d\n", dlsch_demod_shift);
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
         }
          else {
          avg_0[0] = (log2_approx(avg_0[0])/2) - 13 + interf_unaw_shift;
          avg_1[0] = (log2_approx(avg_1[0])/2) - 13 + interf_unaw_shift;
          pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0);
          pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0);
        }
      }
      else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) {// single-layer precoding (TM5, TM6)
        if ((rx_type==rx_IC_single_stream) && (eNB_id_i==ue->n_connected_eNB) && (dlsch0_harq->dl_power_off==0)) {
            dlsch_channel_level_TM56(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                frame_parms,
                                pdsch_vars[eNB_id]->pmi_ext,
                                avg,
                                symbol,
                                nb_rb);
            avg[0] = log2_approx(avg[0]) - 13 + offset_mumimo_llr_drange[dlsch0_harq->mcs][(i_mod>>1)-1];
            pdsch_vars[eNB_id]->log2_maxh = cmax(avg[0],0);
479

480 481
        }
        else if (dlsch0_harq->dl_power_off==1) { //TM6
482

483 484 485 486 487
          dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                   frame_parms,
                                   avg,
                                   symbol,
                                   nb_rb);
488

489 490 491 492
          avgs = 0;
          for (aatx=0;aatx<frame_parms->nb_antenna_ports_eNB;aatx++)
            for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++)
              avgs = cmax(avgs,avg[(aatx<<1)+aarx]);
493

494 495
          pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2) + 1;
          pdsch_vars[eNB_id]->log2_maxh++;
496

497
        }
498
      }
499

500 501 502 503 504 505 506
    }
    else if (beamforming_mode==7)
       dlsch_channel_level_TM7(pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
                              frame_parms,
                              avg,
                              symbol,
                              nb_rb);
Gabriel's avatar
Gabriel committed
507
#ifdef UE_DEBUG_TRACE
Gabriel's avatar
Gabriel committed
508
    LOG_D(PHY,"[DLSCH] AbsSubframe %d.%d log2_maxh = %d [log2_maxh0 %d log2_maxh1 %d] (%d,%d)\n",
Gabriel's avatar
Gabriel committed
509
            frame%1024,subframe, pdsch_vars[eNB_id]->log2_maxh,
Bilel's avatar
Bilel committed
510 511 512
                                                 pdsch_vars[eNB_id]->log2_maxh0,
                                                 pdsch_vars[eNB_id]->log2_maxh1,
                                                 avg[0],avgs);
Gabriel's avatar
Gabriel committed
513
    //LOG_D(PHY,"[DLSCH] mimo_mode = %d\n", dlsch0_harq->mimo_mode);
514
#endif
515 516 517 518 519 520 521 522 523 524

    //wait until pdcch is decoded
    proc->channel_level = 1;
  }

  uint32_t wait = 0;
  while(proc->channel_level == 0)
  {
      usleep(1);
      wait++;
525
  }
526

527 528 529 530 531 532 533
#if T_TRACER
    if (type == PDSCH)
    {
      T(T_UE_PHY_PDSCH_ENERGY, T_INT(eNB_id),  T_INT(0), T_INT(frame%1024), T_INT(subframe),
                               T_INT(avg[0]), T_INT(avg[1]),    T_INT(avg[2]),             T_INT(avg[3]));
    }
#endif
534

535 536 537 538 539 540 541 542 543 544 545 546 547
#if UE_TIMING_TRACE
    stop_meas(&ue->generic_stat_bis[subframe%RX_NB_TH][slot]);
#if DISABLE_LOG_X
    printf("[AbsSFN %d.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level %5.2f \n",frame,subframe,slot,symbol,first_symbol_flag,ue->generic_stat_bis[subframe%RX_NB_TH][slot].p_time/(cpuf*1000.0));
#else
    LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level  %5.2f \n",frame,subframe,slot,symbol,first_symbol_flag,ue->generic_stat_bis[subframe%RX_NB_TH][slot].p_time/(cpuf*1000.0));
#endif
#endif


#if UE_TIMING_TRACE
    start_meas(&ue->generic_stat_bis[subframe%RX_NB_TH][slot]);
#endif
548 549
// Now channel compensation
  if (dlsch0_harq->mimo_mode<LARGE_CDD) {
550 551 552 553 554 555
    dlsch_channel_compensation(pdsch_vars[eNB_id]->rxdataF_ext,
                               pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                               pdsch_vars[eNB_id]->dl_ch_mag0,
                               pdsch_vars[eNB_id]->dl_ch_magb0,
                               pdsch_vars[eNB_id]->rxdataF_comp0,
                               (aatx>1) ? pdsch_vars[eNB_id]->rho : NULL,
556 557 558
                               frame_parms,
                               symbol,
                               first_symbol_flag,
Elena Lukashova's avatar
Elena Lukashova committed
559
                               dlsch0_harq->Qm,
560
                               nb_rb,
561
                               pdsch_vars[eNB_id]->log2_maxh,
562
                               measurements); // log2_maxh+I0_shift
563
 /*if (symbol == 5) {
564
     write_output("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
565
 } */
566
    if ((rx_type==rx_IC_single_stream) &&
567
        (eNB_id_i<ue->n_connected_eNB)) {
568
         dlsch_channel_compensation(pdsch_vars[eNB_id_i]->rxdataF_ext,
569 570 571 572 573
                                 pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
                                 pdsch_vars[eNB_id_i]->dl_ch_mag0,
                                 pdsch_vars[eNB_id_i]->dl_ch_magb0,
                                 pdsch_vars[eNB_id_i]->rxdataF_comp0,
                                 (aatx>1) ? pdsch_vars[eNB_id_i]->rho : NULL,
574 575 576 577 578
                                 frame_parms,
                                 symbol,
                                 first_symbol_flag,
                                 i_mod,
                                 nb_rb,
579
                                 pdsch_vars[eNB_id]->log2_maxh,
580
                                 measurements); // log2_maxh+I0_shift
581 582
#ifdef DEBUG_PHY
      if (symbol == 5) {
583
        write_output("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
584
        write_output("rxF_comp_i.m","rxF_c_i",&pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
585
      }
586
#endif
587

588
      dlsch_dual_stream_correlation(frame_parms,
589 590
                                    symbol,
                                    nb_rb,
591 592
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
593
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
594
                                    pdsch_vars[eNB_id]->log2_maxh);
595
    }
596 597
  } else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
            (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){
598
      dlsch_channel_compensation_TM34(frame_parms,
599
                                     pdsch_vars[eNB_id],
600
                                     measurements,
601 602 603
                                     eNB_id,
                                     symbol,
                                     dlsch0_harq->Qm,
Elena Lukashova's avatar
Elena Lukashova committed
604
                                     dlsch1_harq->Qm,
605 606 607
                                     harq_pid,
                                     dlsch0_harq->round,
                                     dlsch0_harq->mimo_mode,
608
                                     nb_rb,
609
                                     pdsch_vars[eNB_id]->log2_maxh0,
610
                                     pdsch_vars[eNB_id]->log2_maxh1);
611
  /*   if (symbol == 5) {
612 613 614 615
     write_output("rxF_comp_d00.m","rxF_c_d00",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM
     write_output("rxF_comp_d01.m","rxF_c_d01",&pdsch_vars[eNB_id]->rxdataF_comp0[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
     write_output("rxF_comp_d10.m","rxF_c_d10",&pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
     write_output("rxF_comp_d11.m","rxF_c_d11",&pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM
616
        } */
617
      // compute correlation between signal and interference channels (rho12 and rho21)
618
        dlsch_dual_stream_correlation(frame_parms, // this is doing h11'*h12 and h21'*h22
619 620
                                    symbol,
                                    nb_rb,
621 622
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
623 624 625
                                    pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                                    pdsch_vars[eNB_id]->log2_maxh0);
        //printf("rho stream1 =%d\n", &pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round] );
626
      //to be optimized (just take complex conjugate)
627
      dlsch_dual_stream_correlation(frame_parms, // this is doing h12'*h11 and h22'*h21
628 629
                                    symbol,
                                    nb_rb,
630
                                    &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
631
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
632 633
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                    pdsch_vars[eNB_id]->log2_maxh1);
634
    //  printf("rho stream2 =%d\n",&pdsch_vars[eNB_id]->dl_ch_rho2_ext );
635
      //printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh);
636
  /*     if (symbol == 5) {
637 638 639 640
     write_output("rho0_0.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM
     write_output("rho2_0.m","rho2_0",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
     write_output("rho0_1.m.m","rho0_1",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
     write_output("rho2_1.m","rho2_1",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM
641
        } */
642

643 644 645
    } else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) {// single-layer precoding (TM5, TM6)
        if ((rx_type==rx_IC_single_stream) && (eNB_id_i==ue->n_connected_eNB) && (dlsch0_harq->dl_power_off==0)) {
          dlsch_channel_compensation_TM56(pdsch_vars[eNB_id]->rxdataF_ext,
646 647 648 649 650
                                      pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                      pdsch_vars[eNB_id]->dl_ch_mag0,
                                      pdsch_vars[eNB_id]->dl_ch_magb0,
                                      pdsch_vars[eNB_id]->rxdataF_comp0,
                                      pdsch_vars[eNB_id]->pmi_ext,
651
                                      frame_parms,
652
                                      measurements,
653 654
                                      eNB_id,
                                      symbol,
655
                                      dlsch0_harq->Qm,
656
                                      nb_rb,
657
                                      pdsch_vars[eNB_id]->log2_maxh,
658
                                      dlsch0_harq->dl_power_off);
659

660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
        for (rb=0; rb<nb_rb; rb++) {
          switch(pdsch_vars[eNB_id]->pmi_ext[rb]) {
          case 0:
            pdsch_vars[eNB_id_i]->pmi_ext[rb]=1;
            break;
         case 1:
            pdsch_vars[eNB_id_i]->pmi_ext[rb]=0;
            break;
         case 2:
            pdsch_vars[eNB_id_i]->pmi_ext[rb]=3;
            break;
          case 3:
            pdsch_vars[eNB_id_i]->pmi_ext[rb]=2;
            break;
          }
Elena Lukashova's avatar
Elena Lukashova committed
675
       //  if (rb==0)
676
        //    printf("pmi %d, pmi_i %d\n",pdsch_vars[eNB_id]->pmi_ext[rb],pdsch_vars[eNB_id_i]->pmi_ext[rb]);
677
      }
678 679 680 681 682 683
      dlsch_channel_compensation_TM56(pdsch_vars[eNB_id_i]->rxdataF_ext,
                                      pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
                                      pdsch_vars[eNB_id_i]->dl_ch_mag0,
                                      pdsch_vars[eNB_id_i]->dl_ch_magb0,
                                      pdsch_vars[eNB_id_i]->rxdataF_comp0,
                                      pdsch_vars[eNB_id_i]->pmi_ext,
684
                                      frame_parms,
685
                                      measurements,
686 687 688 689
                                      eNB_id_i,
                                      symbol,
                                      i_mod,
                                      nb_rb,
690
                                      pdsch_vars[eNB_id]->log2_maxh,
691
                                      dlsch0_harq->dl_power_off);
692 693
#ifdef DEBUG_PHY
      if (symbol==5) {
694
        write_output("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
695
       write_output("rxF_comp_i.m","rxF_c_i",&pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
696
      }
697
#endif
698 699 700
      dlsch_dual_stream_correlation(frame_parms,
                                    symbol,
                                    nb_rb,
701 702 703 704
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                    pdsch_vars[eNB_id]->log2_maxh);
705
    }  else if (dlsch0_harq->dl_power_off==1)  {
706 707 708 709 710 711
      dlsch_channel_compensation_TM56(pdsch_vars[eNB_id]->rxdataF_ext,
                                      pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                      pdsch_vars[eNB_id]->dl_ch_mag0,
                                      pdsch_vars[eNB_id]->dl_ch_magb0,
                                      pdsch_vars[eNB_id]->rxdataF_comp0,
                                      pdsch_vars[eNB_id]->pmi_ext,
712
                                      frame_parms,
713
                                      measurements,
714 715
                                      eNB_id,
                                      symbol,
716
                                      dlsch0_harq->Qm,
717
                                      nb_rb,
718
                                      pdsch_vars[eNB_id]->log2_maxh,
719
                                      1);
Elena Lukashova's avatar
Elena Lukashova committed
720

721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
      }


    } else if (dlsch0_harq->mimo_mode==TM7) { //TM7

      dlsch_channel_compensation(pdsch_vars[eNB_id]->rxdataF_ext,
                                 pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
                                 pdsch_vars[eNB_id]->dl_ch_mag0,
                                 pdsch_vars[eNB_id]->dl_ch_magb0,
                                 pdsch_vars[eNB_id]->rxdataF_comp0,
                                 (aatx>1) ? pdsch_vars[eNB_id]->rho : NULL,
                                 frame_parms,
                                 symbol,
                                 first_symbol_flag,
                                 get_Qm(dlsch0_harq->mcs),
                                 nb_rb,
                                 //9,
                                 pdsch_vars[eNB_id]->log2_maxh,
                                 measurements); // log2_maxh+I0_shift
740 741
  }

742 743 744 745 746 747 748 749
#if UE_TIMING_TRACE
    stop_meas(&ue->generic_stat_bis[subframe%RX_NB_TH][slot]);
#if DISABLE_LOG_X
    printf("[AbsSFN %d.%d] Slot%d Symbol %d log2_maxh %d channel_level %d: Channel Comp %5.2f \n",frame,subframe,slot,symbol,pdsch_vars[eNB_id]->log2_maxh,proc->channel_level,ue->generic_stat_bis[subframe%RX_NB_TH][slot].p_time/(cpuf*1000.0));
#else
    LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d log2_maxh %d channel_level %d: Channel Comp  %5.2f \n",frame,subframe,slot,symbol,pdsch_vars[eNB_id]->log2_maxh,proc->channel_level,ue->generic_stat_bis[subframe%RX_NB_TH][slot].p_time/(cpuf*1000.0));
#endif
#endif
750
// MRC
751 752 753
#if UE_TIMING_TRACE
    start_meas(&ue->generic_stat_bis[subframe%RX_NB_TH][slot]);
#endif
754 755

   if (frame_parms->nb_antennas_rx > 1) {
756
    if ((dlsch0_harq->mimo_mode == LARGE_CDD) ||
757
        ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
758
         (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){  // TM3 or TM4
Xiwen JIANG's avatar
Xiwen JIANG committed
759
      if (frame_parms->nb_antenna_ports_eNB == 2) {
760
        dlsch_detection_mrc_TM34(frame_parms,
761
                                 pdsch_vars[eNB_id],
762
                                 harq_pid,
763
                                 dlsch0_harq->round,
764 765 766
                                 symbol,
                                 nb_rb,
                                 1);
767
    /*   if (symbol == 5) {
768 769
     write_output("rho0_mrc.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM
     write_output("rho2_mrc.m","rho2_0",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0
770
        } */
771
      }
772
    } else {
773
      dlsch_detection_mrc(frame_parms,
774 775 776
                          pdsch_vars[eNB_id]->rxdataF_comp0,
                          pdsch_vars[eNB_id_i]->rxdataF_comp0,
                          pdsch_vars[eNB_id]->rho,
777
                          pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
778 779 780 781
                          pdsch_vars[eNB_id]->dl_ch_mag0,
                          pdsch_vars[eNB_id]->dl_ch_magb0,
                          pdsch_vars[eNB_id_i]->dl_ch_mag0,
                          pdsch_vars[eNB_id_i]->dl_ch_magb0,
782 783
                          symbol,
                          nb_rb,
784
                          rx_type==rx_IC_single_stream);
785 786 787 788 789
    }
  }
  //  printf("Combining");
  if ((dlsch0_harq->mimo_mode == SISO) ||
      ((dlsch0_harq->mimo_mode >= UNIFORM_PRECODING11) &&
790 791
       (dlsch0_harq->mimo_mode <= PUSCH_PRECODING0)) ||
       (dlsch0_harq->mimo_mode == TM7)) {
792 793
    /*
      dlsch_siso(frame_parms,
794 795
      pdsch_vars[eNB_id]->rxdataF_comp,
      pdsch_vars[eNB_id_i]->rxdataF_comp,
796 797 798 799 800
      symbol,
      nb_rb);
    */
  } else if (dlsch0_harq->mimo_mode == ALAMOUTI) {
    dlsch_alamouti(frame_parms,
801 802 803
                   pdsch_vars[eNB_id]->rxdataF_comp0,
                   pdsch_vars[eNB_id]->dl_ch_mag0,
                   pdsch_vars[eNB_id]->dl_ch_magb0,
804 805
                   symbol,
                   nb_rb);
806 807
  }

808
  //    printf("LLR");
809 810
  if ((dlsch0_harq->mimo_mode == LARGE_CDD) ||
      ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
811
       (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING)))  {
812
    rxdataF_comp_ptr = pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round];
813
    dl_ch_mag_ptr = pdsch_vars[eNB_id]->dl_ch_mag1[harq_pid][round];
814 815
  }
  else {
816 817
    rxdataF_comp_ptr = pdsch_vars[eNB_id_i]->rxdataF_comp0;
    dl_ch_mag_ptr = pdsch_vars[eNB_id_i]->dl_ch_mag0;
818
    //i_mod should have been passed as a parameter
819
  }
820

821 822 823 824 825 826 827 828 829 830 831 832
#if UE_TIMING_TRACE
    stop_meas(&ue->generic_stat_bis[subframe%RX_NB_TH][slot]);
#if DISABLE_LOG_X
    printf("[AbsSFN %d.%d] Slot%d Symbol %d: Channel Combine %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[subframe%RX_NB_TH][slot].p_time/(cpuf*1000.0));
#else
    LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: Channel Combine  %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[subframe%RX_NB_TH][slot].p_time/(cpuf*1000.0));
#endif
#endif

#if UE_TIMING_TRACE
    start_meas(&ue->generic_stat_bis[subframe%RX_NB_TH][slot]);
#endif
Gabriel's avatar
Gabriel committed
833
  //printf("LLR dlsch0_harq->Qm %d rx_type %d cw0 %d cw1 %d symbol %d \n",dlsch0_harq->Qm,rx_type,codeword_TB0,codeword_TB1,symbol);
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
  // compute LLRs
  // -> // compute @pointer where llrs should filled for this ofdm-symbol
  int8_t  *pllr_symbol_cw0;
  int8_t  *pllr_symbol_cw1;
  uint32_t llr_offset_symbol;
  llr_offset_symbol = pdsch_vars[eNB_id]->llr_offset[symbol];
  pllr_symbol_cw0  = (int8_t*)pdsch_vars[eNB_id]->llr[0];
  pllr_symbol_cw1  = (int8_t*)pdsch_vars[eNB_id]->llr[1];
  pllr_symbol_cw0 += llr_offset_symbol;
  pllr_symbol_cw1 += llr_offset_symbol;

  /*LOG_I(PHY,"compute LLRs [AbsSubframe %d.%d-%d] NbRB %d Qm %d LLRs-Length %d LLR-Offset %d @LLR Buff %x @LLR Buff(symb) %x\n",
             proc->frame_rx, proc->subframe_rx,symbol,
             nb_rb,dlsch0_harq->Qm,
             pdsch_vars[eNB_id]->llr_length[symbol],
             pdsch_vars[eNB_id]->llr_offset[symbol],
             (int16_t*)pdsch_vars[eNB_id]->llr[0],
             pllr_symbol);*/
Gabriel's avatar
Gabriel committed
852

853
  switch (dlsch0_harq->Qm) {
854
  case 2 :
855
    if ((rx_type==rx_standard) || (codeword_TB1 == -1)) {
856
        dlsch_qpsk_llr(frame_parms,
857
                       pdsch_vars[eNB_id]->rxdataF_comp0,
858
                       (int16_t*)pllr_symbol_cw0,
859 860 861
                       symbol,
                       first_symbol_flag,
                       nb_rb,
862
                       adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
863
                       beamforming_mode);
864 865 866 867 868

    } else if (codeword_TB0 == -1){

        dlsch_qpsk_llr(frame_parms,
                       pdsch_vars[eNB_id]->rxdataF_comp0,
fnabet's avatar
fnabet committed
869
                       (int16_t*)pllr_symbol_cw1,
870 871 872 873 874
                       symbol,
                       first_symbol_flag,
                       nb_rb,
                       adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
                       beamforming_mode);
875
    }
876
      else if (rx_type >= rx_IC_single_stream) {
Elena Lukashova's avatar
Elena Lukashova committed
877
        if (dlsch1_harq->Qm == 2) {
878
          dlsch_qpsk_qpsk_llr(frame_parms,
879
                              pdsch_vars[eNB_id]->rxdataF_comp0,
880
                              rxdataF_comp_ptr,
881 882
                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                              pdsch_vars[eNB_id]->llr[0],
883
                              symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
884
                              adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
885
                              pdsch_vars[eNB_id]->llr128);
886 887 888
          if (rx_type==rx_IC_dual_stream) {
            dlsch_qpsk_qpsk_llr(frame_parms,
                                rxdataF_comp_ptr,
889 890 891
                                pdsch_vars[eNB_id]->rxdataF_comp0,
                                pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                pdsch_vars[eNB_id]->llr[1],
892
                                symbol,first_symbol_flag,nb_rb,
893
                                adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol),
894
                                pdsch_vars[eNB_id]->llr128_2ndstream);
895 896
          }
        }
897
        else if (dlsch1_harq->Qm == 4) {
898
          dlsch_qpsk_16qam_llr(frame_parms,
899
                               pdsch_vars[eNB_id]->rxdataF_comp0,
900 901
                               rxdataF_comp_ptr,//i
                               dl_ch_mag_ptr,//i
902 903
                               pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                               pdsch_vars[eNB_id]->llr[0],
904
                               symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
905
                               adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
906
                               pdsch_vars[eNB_id]->llr128);
907 908 909
          if (rx_type==rx_IC_dual_stream) {
            dlsch_16qam_qpsk_llr(frame_parms,
                                 rxdataF_comp_ptr,
910
                                 pdsch_vars[eNB_id]->rxdataF_comp0,//i
911
                                 dl_ch_mag_ptr,
912 913
                                 pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                 pdsch_vars[eNB_id]->llr[1],
914
                                 symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
915
                                 adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol),
916
                                 pdsch_vars[eNB_id]->llr128_2ndstream);
917 918 919 920
          }
        }
        else {
          dlsch_qpsk_64qam_llr(frame_parms,
921
                               pdsch_vars[eNB_id]->rxdataF_comp0,
922 923
                               rxdataF_comp_ptr,//i
                               dl_ch_mag_ptr,//i
924 925
                               pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                               pdsch_vars[eNB_id]->llr[0],
926
                               symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
927
                               adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
928
                               pdsch_vars[eNB_id]->llr128);
929 930 931
          if (rx_type==rx_IC_dual_stream) {
            dlsch_64qam_qpsk_llr(frame_parms,
                                 rxdataF_comp_ptr,
932
                                 pdsch_vars[eNB_id]->rxdataF_comp0,//i
933
                                 dl_ch_mag_ptr,
934 935
                                 pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                 pdsch_vars[eNB_id]->llr[1],
936
                                 symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
937
                                 adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,subframe,symbol),
938
                                 pdsch_vars[eNB_id]->llr128_2ndstream);
939
          }
940
        }
941
      }
942 943
    break;
  case 4 :
944
    if ((rx_type==rx_standard ) || (codeword_TB1 == -1)) {
945
      dlsch_16qam_llr(frame_parms,
946 947 948
                      pdsch_vars[eNB_id]->rxdataF_comp0,
                      pdsch_vars[eNB_id]->llr[0],
                      pdsch_vars[eNB_id]->dl_ch_mag0,
949
                      symbol,first_symbol_flag,nb_rb,
950
                      adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
951 952
                      pdsch_vars[eNB_id]->llr128,
                      beamforming_mode);
953 954 955 956 957 958 959 960 961
    } else if (codeword_TB0 == -1){
      dlsch_16qam_llr(frame_parms,
                      pdsch_vars[eNB_id]->rxdataF_comp0,
                      pdsch_vars[eNB_id]->llr[1],
                      pdsch_vars[eNB_id]->dl_ch_mag0,
                      symbol,first_symbol_flag,nb_rb,
                      adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
                      pdsch_vars[eNB_id]->llr128_2ndstream,
                      beamforming_mode);
962
    }
963
    else if (rx_type >= rx_IC_single_stream) {
Elena Lukashova's avatar
Elena Lukashova committed
964
      if (dlsch1_harq->Qm == 2) {
965
        dlsch_16qam_qpsk_llr(frame_parms,
966
                             pdsch_vars[eNB_id]->rxdataF_comp0,
967
                             rxdataF_comp_ptr,//i
968 969 970
                             pdsch_vars[eNB_id]->dl_ch_mag0,
                             pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                             pdsch_vars[eNB_id]->llr[0],
971
                             symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
972
                             adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
973
                             pdsch_vars[eNB_id]->llr128);
974 975 976
        if (rx_type==rx_IC_dual_stream) {
          dlsch_qpsk_16qam_llr(frame_parms,
                               rxdataF_comp_ptr,
977 978 979 980
                               pdsch_vars[eNB_id]->rxdataF_comp0,//i
                               pdsch_vars[eNB_id]->dl_ch_mag0,//i
                               pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                               pdsch_vars[eNB_id]->llr[1],
981
                               symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
982
                               adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol),
983
                               pdsch_vars[eNB_id]->llr128_2ndstream);
984
        }
985
      }
Elena Lukashova's avatar
Elena Lukashova committed
986
      else if (dlsch1_harq->Qm == 4) {
987
        dlsch_16qam_16qam_llr(frame_parms,
988
                              pdsch_vars[eNB_id]->rxdataF_comp0,
989
                              rxdataF_comp_ptr,//i
990
                              pdsch_vars[eNB_id]->dl_ch_mag0,
991
                              dl_ch_mag_ptr,//i
992 993
                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                              pdsch_vars[eNB_id]->llr[0],
994 995
                              symbol,first_symbol_flag,nb_rb,
                              adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
996
                              pdsch_vars[eNB_id]->llr128);
997 998 999
        if (rx_type==rx_IC_dual_stream) {
          dlsch_16qam_16qam_llr(frame_parms,
                                rxdataF_comp_ptr,
1000
                                pdsch_vars[eNB_id]->rxdataF_comp0,//i
1001
                                dl_ch_mag_ptr,
1002 1003 1004
                                pdsch_vars[eNB_id]->dl_ch_mag0,//i
                                pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                pdsch_vars[eNB_id]->llr[1],
1005 1006
                                symbol,first_symbol_flag,nb_rb,
                                adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol),
1007
                                pdsch_vars[eNB_id]->llr128_2ndstream);
1008
        }
1009 1010
      }
      else {
1011
        dlsch_16qam_64qam_llr(frame_parms,
1012
                              pdsch_vars[eNB_id]->rxdataF_comp0,
1013
                              rxdataF_comp_ptr,//i
1014
                              pdsch_vars[eNB_id]->dl_ch_mag0,
1015
                              dl_ch_mag_ptr,//i
1016 1017
                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                              pdsch_vars[eNB_id]->llr[0],