dlsch_demodulation.c 236 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 34 35
#include "PHY/extern.h"
#include "defs.h"
#include "extern.h"
36
#include "PHY/sse_intrin.h"
37
#include "T.h"
38 39 40 41

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

45 46
//#define DEBUG_HARQ

47 48 49
//#undef LOG_D
//#define LOG_D LOG_I

50
//#define DEBUG_PHY 1
51
//#define DEBUG_DLSCH_DEMOD 1
52

53
int avg[4];
54 55
int avg_0[2];
int avg_1[2];
56 57

// [MCS][i_mod (0,1,2) = (2,4,6)]
58
unsigned char offset_mumimo_llr_drange_fix=0;
Elena Lukashova's avatar
Elena Lukashova committed
59 60 61
uint8_t interf_unaw_shift0=0;
uint8_t interf_unaw_shift1=0;
uint8_t interf_unaw_shift=0;
62
//inferference-free case
63
unsigned char interf_unaw_shift_tm4_mcs[29]={5, 3, 4, 3, 3, 2, 1, 1, 2, 0, 1, 1, 1, 1, 0, 0,
64
                                             1, 1, 1, 1, 0, 2, 1, 0, 1, 0, 1, 0, 0} ;
65
unsigned char interf_unaw_shift_tm1_mcs[29]={5, 5, 4, 3, 3, 3, 2, 2, 4, 4, 2, 3, 3, 3, 1, 1,
66
                                             0, 1, 1, 2, 5, 4, 4, 6, 5, 1, 0, 5, 6} ; // mcs 21, 26, 28 seem to be errorneous
67

68 69 70
/*
//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
71 72
{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
73
*/
74 75 76 77 78 79 80 81
 /*
 //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
 */
82
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}};
83

84

85
extern void print_shorts(char *s,int16_t *x);
86

87

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

101 102 103
  LTE_UE_COMMON *common_vars  = &ue->common_vars;
  LTE_UE_PDSCH **pdsch_vars;
  LTE_DL_FRAME_PARMS *frame_parms    = &ue->frame_parms;
104
  PHY_MEASUREMENTS *measurements = &ue->measurements;
105
  LTE_UE_DLSCH_t   **dlsch;
106

Elena Lukashova's avatar
Elena Lukashova committed
107

108
  unsigned char aatx,aarx;
109

110
  unsigned short nb_rb = 0, round;
111
  int avgs, rb;
112
  LTE_DL_UE_HARQ_t *dlsch0_harq,*dlsch1_harq = 0;
Elena Lukashova's avatar
Elena Lukashova committed
113

114
  uint8_t beamforming_mode;
115
  uint32_t *rballoc;
116

117 118
  int32_t **rxdataF_comp_ptr;
  int32_t **dl_ch_mag_ptr;
119 120 121 122
  int32_t codeword_TB0;
  int32_t codeword_TB1;


123

124 125
  switch (type) {
  case SI_PDSCH:
126
    pdsch_vars = &ue->pdsch_vars_SI[eNB_id];
127 128
    dlsch = &ue->dlsch_SI[eNB_id];
    dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
129
    beamforming_mode  = 0;
130
    break;
131

132
  case RA_PDSCH:
133
    pdsch_vars = &ue->pdsch_vars_ra[eNB_id];
134 135
    dlsch = &ue->dlsch_ra[eNB_id];
    dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
136
    beamforming_mode  = 0;
137
    break;
138

139
  case PDSCH:
140
    pdsch_vars = &ue->pdsch_vars[subframe&0x1][eNB_id];
141 142 143 144 145 146 147
    dlsch = ue->dlsch[eNB_id];
    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];
148 149 150
#ifdef DEBUG_HARQ
      printf("I am assuming both CW active\n");
#endif
151
    }
152 153 154 155 156 157
     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;
158
    }
159 160 161 162 163 164
     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;
      dlsch0_harq = dlsch[1]->harq_processes[harq_pid];
      dlsch1_harq = NULL;
      codeword_TB0 = -1;
165
    }
166 167 168 169
    else {
      LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: no active DLSCH\n",ue->proc.proc_rxtx[0].frame_rx,subframe);
      return(-1);
    }
170
    beamforming_mode  = ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id];
171 172 173
    break;

  default:
Cedric Roux's avatar
Cedric Roux committed
174
    LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: Unknown PDSCH format %d\n",ue->proc.proc_rxtx[0].frame_rx,subframe,type);
175 176 177
    return(-1);
    break;
  }
178 179 180 181
#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
182

183 184
  DevAssert(dlsch0_harq);
  round = dlsch0_harq->round;
185

186
  if (eNB_id > 2) {
jiangx's avatar
jiangx committed
187
    LOG_W(PHY,"dlsch_demodulation.c: Illegal eNB_id %d\n",eNB_id);
188 189
    return(-1);
  }
190

191 192
  if (!common_vars) {
    LOG_W(PHY,"dlsch_demodulation.c: Null common_vars\n");
193 194 195
    return(-1);
  }

196
  if (!dlsch[0]) {
jiangx's avatar
jiangx committed
197
    LOG_W(PHY,"dlsch_demodulation.c: Null dlsch_ue pointer\n");
198 199 200
    return(-1);
  }

201 202
  if (!pdsch_vars) {
    LOG_W(PHY,"dlsch_demodulation.c: Null pdsch_vars pointer\n");
203 204
    return(-1);
  }
205

206
  if (!frame_parms) {
207
    LOG_W(PHY,"dlsch_demodulation.c: Null frame_parms\n");
208 209
    return(-1);
  }
210

211 212 213 214 215
  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;
216

217

218
  if (dlsch0_harq->mimo_mode>DUALSTREAM_PUSCH_PRECODING) {
219 220 221
    LOG_E(PHY,"This transmission mode is not yet supported!\n");
    return(-1);
  }
222 223 224



225 226 227 228 229 230 231 232
  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);
    }
  }

Xiwen JIANG's avatar
Xiwen JIANG committed
233
  if (frame_parms->nb_antenna_ports_eNB>1 && beamforming_mode==0) {
234
#ifdef DEBUG_DLSCH_MOD
235
    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]);
236
#endif
237

238 239
    nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
                                   common_vars->common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[eNB_id],
240 241
                                   pdsch_vars[eNB_id]->rxdataF_ext,
                                   pdsch_vars[eNB_id]->dl_ch_estimates_ext,
242
                                   dlsch0_harq->pmi_alloc,
243
                                   pdsch_vars[eNB_id]->pmi_ext,
244
                                   rballoc,
245 246
                                   symbol,
                                   subframe,
247
                                   ue->high_speed_flag,
248
                                   frame_parms,
249
                                   dlsch0_harq->mimo_mode);
250
//#ifdef DEBUG_DLSCH_MOD
251 252
    /*   printf("dlsch: using pmi %lx, rb_alloc %x, pmi_ext ",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),*rballoc);
       for (rb=0;rb<nb_rb;rb++)
253
          printf("%d",pdsch_vars[eNB_id]->pmi_ext[rb]);
254
       printf("\n");*/
255
//#endif
256

257
   if (rx_type >= rx_IC_single_stream) {
258
      if (eNB_id_i<ue->n_connected_eNB) // we are in TM5
259
      nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
260
                                       common_vars->common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[eNB_id_i],
261 262
                                       pdsch_vars[eNB_id_i]->rxdataF_ext,
                                       pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
263
                                       dlsch0_harq->pmi_alloc,
264
                                       pdsch_vars[eNB_id_i]->pmi_ext,
265
                                       rballoc,
266 267
                                       symbol,
                                       subframe,
268
                                       ue->high_speed_flag,
269
                                       frame_parms,
270
                                       dlsch0_harq->mimo_mode);
271
      else
272 273
        nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
                                       common_vars->common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[eNB_id],
274 275
                                       pdsch_vars[eNB_id_i]->rxdataF_ext,
                                       pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
276
                                       dlsch0_harq->pmi_alloc,
277
                                       pdsch_vars[eNB_id_i]->pmi_ext,
278
                                       rballoc,
279 280
                                       symbol,
                                       subframe,
281
                                       ue->high_speed_flag,
282
                                       frame_parms,
283
                                       dlsch0_harq->mimo_mode);
284
    }
285
  } else if (beamforming_mode==0) { //else if nb_antennas_ports_eNB==1 && beamforming_mode == 0
286 287
    nb_rb = dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
                                     common_vars->common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[eNB_id],
288 289
                                     pdsch_vars[eNB_id]->rxdataF_ext,
                                     pdsch_vars[eNB_id]->dl_ch_estimates_ext,
290
                                     dlsch0_harq->pmi_alloc,
291
                                     pdsch_vars[eNB_id]->pmi_ext,
292
                                     rballoc,
293 294
                                     symbol,
                                     subframe,
295
                                     ue->high_speed_flag,
296 297
                                     frame_parms);

Elena Lukashova's avatar
Elena Lukashova committed
298
   if (rx_type==rx_IC_single_stream) {
299
     if (eNB_id_i<ue->n_connected_eNB)
300 301
        nb_rb = dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
                                         common_vars->common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[eNB_id_i],
302 303
                                         pdsch_vars[eNB_id_i]->rxdataF_ext,
                                         pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
304
                                         dlsch0_harq->pmi_alloc,
305
                                         pdsch_vars[eNB_id_i]->pmi_ext,
306
                                         rballoc,
307 308
                                         symbol,
                                         subframe,
309
                                         ue->high_speed_flag,
310
                                         frame_parms);
311
      else
312 313
        nb_rb = dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
                                         common_vars->common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[eNB_id],
314 315
                                         pdsch_vars[eNB_id_i]->rxdataF_ext,
                                         pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
316
                                         dlsch0_harq->pmi_alloc,
317
                                         pdsch_vars[eNB_id_i]->pmi_ext,
318
                                         rballoc,
319 320
                                         symbol,
                                         subframe,
321
                                         ue->high_speed_flag,
322
                                         frame_parms);
323
    }
324
  } else if (beamforming_mode==7) { //else if beamforming_mode == 7
325
    nb_rb = dlsch_extract_rbs_TM7(common_vars->common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
326 327 328
                                  pdsch_vars[eNB_id]->dl_bf_ch_estimates,
                                  pdsch_vars[eNB_id]->rxdataF_ext,
                                  pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
329
                                  rballoc,
330 331
                                  symbol,
                                  subframe,
332
                                  ue->high_speed_flag,
333
                                  frame_parms);
334

335
  } else if(beamforming_mode>7) {
336
    LOG_W(PHY,"dlsch_demodulation: beamforming mode not supported yet.\n");
337
  }
338 339

  //  printf("nb_rb = %d, eNB_id %d\n",nb_rb,eNB_id);
340
  if (nb_rb==0) {
341
    LOG_D(PHY,"dlsch_demodulation.c: nb_rb=0\n");
342 343
    return(-1);
  }
344

Elena Lukashova's avatar
Elena Lukashova committed
345

346
#ifdef DEBUG_PHY
347 348
  LOG_D(PHY,"[DLSCH] log2_maxh = %d (%d,%d)\n",pdsch_vars[eNB_id]->log2_maxh,avg[0],avgs);
  LOG_D(PHY,"[DLSCH] mimo_mode = %d\n", dlsch0_harq->mimo_mode);
349 350
#endif

351
  aatx = frame_parms->nb_antenna_ports_eNB;
Elena Lukashova's avatar
Elena Lukashova committed
352 353
  aarx = frame_parms->nb_antennas_rx;

354
  dlsch_scale_channel(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
355 356 357 358
                      frame_parms,
                      dlsch,
                      symbol,
                      nb_rb);
359

360 361
  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
    dlsch_scale_channel(pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
362
                        frame_parms,
363
                        dlsch,
364 365
                        symbol,
                        nb_rb);
366

367
  if (first_symbol_flag==1) {
368 369 370
    if (beamforming_mode==0){
      if (dlsch0_harq->mimo_mode<LARGE_CDD) {
        dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
371 372 373 374
                           frame_parms,
                           avg,
                           symbol,
                           nb_rb);
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
        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);

        if (rx_type>rx_standard) {
          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);
          //printf("TM4 I-A log2_maxh0 = %d\n", lte_ue_pdsch_vars[eNB_id]->log2_maxh0);
          //printf("TM4 I-A log2_maxh1 = %d\n", lte_ue_pdsch_vars[eNB_id]->log2_maxh1);
         }
          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);
          //printf("TM4 I-UA log2_maxh0 = %d\n", lte_ue_pdsch_vars[eNB_id]->log2_maxh0);
          //printf("TM4 I-UA log2_maxh1 = %d\n", lte_ue_pdsch_vars[eNB_id]->log2_maxh1);
        }
      }
      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);
422

423 424
        }
        else if (dlsch0_harq->dl_power_off==1) { //TM6
425

426 427 428 429 430
          dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                   frame_parms,
                                   avg,
                                   symbol,
                                   nb_rb);
431

432 433 434 435
          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]);
436

437 438
          pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2) + 1;
          pdsch_vars[eNB_id]->log2_maxh++;
439

440
        }
441
      }
442

443 444 445 446 447 448 449
    }
    else if (beamforming_mode==7)
       dlsch_channel_level_TM7(pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
                              frame_parms,
                              avg,
                              symbol,
                              nb_rb);
450
#ifdef DEBUG_PHY
451
    LOG_D(PHY,"[DLSCH] log2_maxh = %d (%d,%d)\n",pdsch_vars[eNB_id]->log2_maxh,avg[0],avgs);
jiangx's avatar
jiangx committed
452
    LOG_D(PHY,"[DLSCH] mimo_mode = %d\n", dlsch0_harq->mimo_mode);
453 454
#endif
  }
455

456 457 458 459 460 461 462
#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
463

464 465
// Now channel compensation
  if (dlsch0_harq->mimo_mode<LARGE_CDD) {
466 467 468 469 470 471
    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,
472 473 474
                               frame_parms,
                               symbol,
                               first_symbol_flag,
475
                               dlsch0_harq->Qm,
476
                               nb_rb,
477
                               pdsch_vars[eNB_id]->log2_maxh,
478
                               measurements); // log2_maxh+I0_shift
479
 /*if (symbol == 5) {
480
     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);
481
 } */
482
    if ((rx_type==rx_IC_single_stream) &&
483
        (eNB_id_i<ue->n_connected_eNB)) {
484
         dlsch_channel_compensation(pdsch_vars[eNB_id_i]->rxdataF_ext,
485 486 487 488 489
                                 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,
490 491 492 493 494
                                 frame_parms,
                                 symbol,
                                 first_symbol_flag,
                                 i_mod,
                                 nb_rb,
495
                                 pdsch_vars[eNB_id]->log2_maxh,
496
                                 measurements); // log2_maxh+I0_shift
497 498
#ifdef DEBUG_PHY
      if (symbol == 5) {
499 500
        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);
        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);
501
      }
502 503
#endif

504
      dlsch_dual_stream_correlation(frame_parms,
505 506
                                    symbol,
                                    nb_rb,
507 508
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
509
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
510
                                    pdsch_vars[eNB_id]->log2_maxh);
511
    }
512 513
  } else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
            (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){
514
      dlsch_channel_compensation_TM34(frame_parms,
515
                                     pdsch_vars[eNB_id],
516
                                     measurements,
517 518
                                     eNB_id,
                                     symbol,
519 520
                                     dlsch0_harq->Qm,
                                     dlsch1_harq->Qm,
521
                                     harq_pid,
522
                                     dlsch0_harq->round,
523
                                     dlsch0_harq->mimo_mode,
524
                                     nb_rb,
525
                                     pdsch_vars[eNB_id]->log2_maxh0,
526
                                     pdsch_vars[eNB_id]->log2_maxh1);
527
  /*   if (symbol == 5) {
528 529 530 531
     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
532
        } */
533
      // compute correlation between signal and interference channels (rho12 and rho21)
534
        dlsch_dual_stream_correlation(frame_parms, // this is doing h11'*h12 and h21'*h22
535 536
                                    symbol,
                                    nb_rb,
537 538
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
539 540 541
                                    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] );
542
      //to be optimized (just take complex conjugate)
543
      dlsch_dual_stream_correlation(frame_parms, // this is doing h12'*h11 and h22'*h21
544 545
                                    symbol,
                                    nb_rb,
546 547
                                    &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
548 549
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                    pdsch_vars[eNB_id]->log2_maxh1);
550
    //  printf("rho stream2 =%d\n",&pdsch_vars[eNB_id]->dl_ch_rho2_ext );
551
      //printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh);
552
  /*     if (symbol == 5) {
553 554 555 556
     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
557
        } */
558

559 560 561
    } 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,
562 563 564 565 566
                                      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,
567
                                      frame_parms,
568
                                      measurements,
569 570
                                      eNB_id,
                                      symbol,
571
                                      dlsch0_harq->Qm,
572
                                      nb_rb,
573
                                      pdsch_vars[eNB_id]->log2_maxh,
574
                                      dlsch0_harq->dl_power_off);
575

576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
        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
591
       //  if (rb==0)
592
        //    printf("pmi %d, pmi_i %d\n",pdsch_vars[eNB_id]->pmi_ext[rb],pdsch_vars[eNB_id_i]->pmi_ext[rb]);
593
      }
594 595 596 597 598 599
      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,
600
                                      frame_parms,
601
                                      measurements,
602 603 604 605
                                      eNB_id_i,
                                      symbol,
                                      i_mod,
                                      nb_rb,
606
                                      pdsch_vars[eNB_id]->log2_maxh,
607
                                      dlsch0_harq->dl_power_off);
608 609
#ifdef DEBUG_PHY
      if (symbol==5) {
610
        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);
611
       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);
612
      }
613 614 615 616
#endif
      dlsch_dual_stream_correlation(frame_parms,
                                    symbol,
                                    nb_rb,
617 618
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
619
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
620
                                    pdsch_vars[eNB_id]->log2_maxh);
621
    }  else if (dlsch0_harq->dl_power_off==1)  {
622 623 624 625 626 627
      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,
628
                                      frame_parms,
629
                                      measurements,
630 631
                                      eNB_id,
                                      symbol,
632
                                      dlsch0_harq->Qm,
633
                                      nb_rb,
634
                                      pdsch_vars[eNB_id]->log2_maxh,
635
                                      1);
636

637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
      }


    } 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
656 657
  }

658 659 660 661
// MRC


   if (frame_parms->nb_antennas_rx > 1) {
662
    if ((dlsch0_harq->mimo_mode == LARGE_CDD) ||
663
        ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
664
         (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){  // TM3 or TM4
Xiwen JIANG's avatar
Xiwen JIANG committed
665
      if (frame_parms->nb_antenna_ports_eNB == 2) {
666
        dlsch_detection_mrc_TM34(frame_parms,
667
                                 pdsch_vars[eNB_id],
668
                                 harq_pid,
669
                                 dlsch0_harq->round,
670 671 672
                                 symbol,
                                 nb_rb,
                                 1);
673
    /*   if (symbol == 5) {
674 675
     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
676
        } */
677
      }
678
    } else {
679
      dlsch_detection_mrc(frame_parms,
680 681 682
                          pdsch_vars[eNB_id]->rxdataF_comp0,
                          pdsch_vars[eNB_id_i]->rxdataF_comp0,
                          pdsch_vars[eNB_id]->rho,
683
                          pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
684 685 686 687
                          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,
688 689
                          symbol,
                          nb_rb,
690
                          rx_type==rx_IC_single_stream);
691 692 693 694 695
    }
  }
  //  printf("Combining");
  if ((dlsch0_harq->mimo_mode == SISO) ||
      ((dlsch0_harq->mimo_mode >= UNIFORM_PRECODING11) &&
696 697
       (dlsch0_harq->mimo_mode <= PUSCH_PRECODING0)) ||
       (dlsch0_harq->mimo_mode == TM7)) {
698 699
    /*
      dlsch_siso(frame_parms,
700 701
      pdsch_vars[eNB_id]->rxdataF_comp,
      pdsch_vars[eNB_id_i]->rxdataF_comp,
702 703 704 705 706
      symbol,
      nb_rb);
    */
  } else if (dlsch0_harq->mimo_mode == ALAMOUTI) {
    dlsch_alamouti(frame_parms,
707 708 709
                   pdsch_vars[eNB_id]->rxdataF_comp0,
                   pdsch_vars[eNB_id]->dl_ch_mag0,
                   pdsch_vars[eNB_id]->dl_ch_magb0,
710 711
                   symbol,
                   nb_rb);
712
  }
713

714
  //    printf("LLR");
715 716
  if ((dlsch0_harq->mimo_mode == LARGE_CDD) ||
      ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
717
       (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING)))  {
718
    rxdataF_comp_ptr = pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round];
719
    dl_ch_mag_ptr = pdsch_vars[eNB_id]->dl_ch_mag1[harq_pid][round];
720 721
  }
  else {
722 723
    rxdataF_comp_ptr = pdsch_vars[eNB_id_i]->rxdataF_comp0;
    dl_ch_mag_ptr = pdsch_vars[eNB_id_i]->dl_ch_mag0;
724
    //i_mod should have been passed as a parameter
725 726
  }

727
  switch (dlsch0_harq->Qm) {
728
  case 2 :
729
    if ((rx_type==rx_standard) || (codeword_TB0 == -1) || (codeword_TB1 == -1)) {
730
        dlsch_qpsk_llr(frame_parms,
731 732
                       pdsch_vars[eNB_id]->rxdataF_comp0,
                       pdsch_vars[eNB_id]->llr[0],
733 734 735
                       symbol,
                       first_symbol_flag,
                       nb_rb,
736
                       adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
737
                       pdsch_vars[eNB_id]->llr128,
738
                       beamforming_mode);
739
    }
740
      else if (rx_type >= rx_IC_single_stream) {
Elena Lukashova's avatar
Elena Lukashova committed
741
        if (dlsch1_harq->Qm == 2) {
742
          dlsch_qpsk_qpsk_llr(frame_parms,
743
                              pdsch_vars[eNB_id]->rxdataF_comp0,
744
                              rxdataF_comp_ptr,
745 746
                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                              pdsch_vars[eNB_id]->llr[0],
747
                              symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
748
                              adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
749
                              pdsch_vars[eNB_id]->llr128);
750 751 752
          if (rx_type==rx_IC_dual_stream) {
            dlsch_qpsk_qpsk_llr(frame_parms,
                                rxdataF_comp_ptr,
753 754 755
                                pdsch_vars[eNB_id]->rxdataF_comp0,
                                pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                pdsch_vars[eNB_id]->llr[1],
756
                                symbol,first_symbol_flag,nb_rb,
757
                                adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol),
758
                                pdsch_vars[eNB_id]->llr128_2ndstream);
759 760
          }
        }
761
        else if (dlsch1_harq->Qm == 4) {
762
          dlsch_qpsk_16qam_llr(frame_parms,
763
                               pdsch_vars[eNB_id]->rxdataF_comp0,
764 765
                               rxdataF_comp_ptr,//i
                               dl_ch_mag_ptr,//i
766 767
                               pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                               pdsch_vars[eNB_id]->llr[0],
768
                               symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
769
                               adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
770
                               pdsch_vars[eNB_id]->llr128);
771 772 773
          if (rx_type==rx_IC_dual_stream) {
            dlsch_16qam_qpsk_llr(frame_parms,
                                 rxdataF_comp_ptr,
774
                                 pdsch_vars[eNB_id]->rxdataF_comp0,//i
775
                                 dl_ch_mag_ptr,
776 777
                                 pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                 pdsch_vars[eNB_id]->llr[1],
778
                                 symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
779
                                 adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol),
780
                                 pdsch_vars[eNB_id]->llr128_2ndstream);
781 782 783 784
          }
        }
        else {
          dlsch_qpsk_64qam_llr(frame_parms,
785
                               pdsch_vars[eNB_id]->rxdataF_comp0,
786 787
                               rxdataF_comp_ptr,//i
                               dl_ch_mag_ptr,//i
788 789
                               pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                               pdsch_vars[eNB_id]->llr[0],
790
                               symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
791
                               adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
792
                               pdsch_vars[eNB_id]->llr128);
793 794 795
          if (rx_type==rx_IC_dual_stream) {
            dlsch_64qam_qpsk_llr(frame_parms,
                                 rxdataF_comp_ptr,
796
                                 pdsch_vars[eNB_id]->rxdataF_comp0,//i
797
                                 dl_ch_mag_ptr,
798 799
                                 pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                 pdsch_vars[eNB_id]->llr[1],
800
                                 symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
801
                                 adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,subframe,symbol),
802
                                 pdsch_vars[eNB_id]->llr128_2ndstream);
803
          }
804
        }
805
      }
806 807
    break;
  case 4 :
808
    if ((rx_type==rx_standard ) || (codeword_TB0 == -1) || (codeword_TB1 == -1)) {
809
      dlsch_16qam_llr(frame_parms,
810 811 812
                      pdsch_vars[eNB_id]->rxdataF_comp0,
                      pdsch_vars[eNB_id]->llr[0],
                      pdsch_vars[eNB_id]->dl_ch_mag0,
813
                      symbol,first_symbol_flag,nb_rb,
814
                      adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
815 816
                      pdsch_vars[eNB_id]->llr128,
                      beamforming_mode);
817
    }
818
    else if (rx_type >= rx_IC_single_stream) {
819
      if (dlsch1_harq->Qm == 2) {
820
        dlsch_16qam_qpsk_llr(frame_parms,
821
                             pdsch_vars[eNB_id]->rxdataF_comp0,
822
                             rxdataF_comp_ptr,//i
823 824
                             pdsch_vars[eNB_id]->dl_ch_mag0,
                             pdsch_vars[eNB_id]->dl_ch_rho2_ext,
825
                             pdsch_vars[eNB_id]->llr[0],
826
                             symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
827
                             adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
828
                             pdsch_vars[eNB_id]->llr128);
829 830 831
        if (rx_type==rx_IC_dual_stream) {
          dlsch_qpsk_16qam_llr(frame_parms,
                               rxdataF_comp_ptr,
832 833 834 835
                               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],
836
                               symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
837
                               adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol),
838
                               pdsch_vars[eNB_id]->llr128_2ndstream);
839
        }
840
      }
Elena Lukashova's avatar
Elena Lukashova committed
841
      else if (dlsch1_harq->Qm == 4) {
842
        dlsch_16qam_16qam_llr(frame_parms,
843
                              pdsch_vars[eNB_id]->rxdataF_comp0,
844
                              rxdataF_comp_ptr,//i
845
                              pdsch_vars[eNB_id]->dl_ch_mag0,
846
                              dl_ch_mag_ptr,//i
847 848
                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                              pdsch_vars[eNB_id]->llr[0],
849 850
                              symbol,first_symbol_flag,nb_rb,
                              adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
851
                              pdsch_vars[eNB_id]->llr128);
852 853 854
        if (rx_type==rx_IC_dual_stream) {
          dlsch_16qam_16qam_llr(frame_parms,
                                rxdataF_comp_ptr,
855
                                pdsch_vars[eNB_id]->rxdataF_comp0,//i
856
                                dl_ch_mag_ptr,
857 858 859
                                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],
860 861
                                symbol,first_symbol_flag,nb_rb,
                                adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol),
862
                                pdsch_vars[eNB_id]->llr128_2ndstream);
863
        }
864 865
      }
      else {
866
        dlsch_16qam_64qam_llr(frame_parms,
867
                              pdsch_vars[eNB_id]->rxdataF_comp0,
868
                              rxdataF_comp_ptr,//i
869
                              pdsch_vars[eNB_id]->dl_ch_mag0,
870
                              dl_ch_mag_ptr,//i
871 872
                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                              pdsch_vars[eNB_id]->llr[0],
873 874
                              symbol,first_symbol_flag,nb_rb,
                              adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
875
                              pdsch_vars[eNB_id]->llr128);
876 877 878
        if (rx_type==rx_IC_dual_stream) {
          dlsch_64qam_16qam_llr(frame_parms,
                                rxdataF_comp_ptr,
879
                                pdsch_vars[eNB_id]->rxdataF_comp0,
880
                                dl_ch_mag_ptr,
881 882 883
                                pdsch_vars[eNB_id]->dl_ch_mag0,
                                pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                pdsch_vars[eNB_id]->llr[1],
884 885
                                symbol,first_symbol_flag,nb_rb,
                                adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,subframe,symbol),
886
                                pdsch_vars[eNB_id]->llr128_2ndstream);
887
        }
888 889 890 891
      }
    }
    break;
  case 6 :
892
    if ((rx_type==rx_standard) || (codeword_TB0 == -1) || (codeword_TB1 == -1))  {
893
      dlsch_64qam_llr(frame_parms,
894 895 896 897
                      pdsch_vars[eNB_id]->rxdataF_comp0,
                      pdsch_vars[eNB_id]->llr[0],
                      pdsch_vars[eNB_id]->dl_ch_mag0,
                      pdsch_vars[eNB_id]->dl_ch_magb0,
898
                      symbol,first_symbol_flag,nb_rb,
899
                      adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
900 901
                      pdsch_vars[eNB_id]->llr128,
                      beamforming_mode);
902
    }
903
    else if (rx_type >= rx_IC_single_stream) {
904
      if (dlsch1_harq->Qm == 2) {
905
        dlsch_64qam_qpsk_llr(frame_parms,
906
                             pdsch_vars[eNB_id]->rxdataF_comp0,
907
                             rxdataF_comp_ptr,//i
908 909
                             pdsch_vars[eNB_id]->dl_ch_mag0,
                             pdsch_vars[eNB_id]->dl_ch_rho2_ext,
910
                             pdsch_vars[eNB_id]->llr[0],
911
                             symbol,first_symbol_flag,nb_rb,
912
                             adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
913
                             pdsch_vars[eNB_id]->llr128);
914 915 916
        if (rx_type==rx_IC_dual_stream) {
          dlsch_qpsk_64qam_llr(frame_parms,
                               rxdataF_comp_ptr,
917 918 919 920
                               pdsch_vars[eNB_id]->rxdataF_comp0,//i
                               pdsch_vars[eNB_id]->dl_ch_mag0,
                               pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                               pdsch_vars[eNB_id]->llr[1],
921 922
                               symbol,first_symbol_flag,nb_rb,
                               adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol),
923
                               pdsch_vars[eNB_id]->llr128_2ndstream);
924
        }
925
      }
Elena Lukashova's avatar
Elena Lukashova committed
926
      else if (dlsch1_harq->Qm == 4) {
927
        dlsch_64qam_16qam_llr(frame_parms,
928
                              pdsch_vars[eNB_id]->rxdataF_comp0,
929
                              rxdataF_comp_ptr,//i
930
                              pdsch_vars[eNB_id]->dl_ch_mag0,
931
                              dl_ch_mag_ptr,//i
932 933
                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                              pdsch_vars[eNB_id]->llr[0],
934 935
                              symbol,first_symbol_flag,nb_rb,
                              adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol),
936
                              pdsch_vars[eNB_id]->llr128);
937 938 939
        if (rx_type==rx_IC_dual_stream) {
          dlsch_16qam_64qam_llr(frame_parms,
                                rxdataF_comp_ptr,
940
                                pdsch_vars[eNB_id]->rxdataF_comp0,//i
941
                                dl_ch_mag_ptr,
942 943 944
                                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],
945 946
                                symbol,first_symbol_flag,nb_rb,
                                adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol),
947
                                pdsch_vars[eNB_id]->llr128_2ndstream);
948
        }
949
      }
950
      else {
951
        dlsch_64qam_64qam_llr(frame_parms,
952
                              pdsch_vars[eNB_id]->rxdataF_comp0,
953
                              rxdataF_comp_ptr,//i
954
                              pdsch_vars[eNB_id]->dl_ch_mag0,
955
                              dl_ch_mag_ptr,//i
956 957