dlsch_demodulation.c 242 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 51
/* 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;

52 53
//#define DEBUG_HARQ

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

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

Bilel's avatar
Bilel committed
60

61 62

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

73 74 75
/*
//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
76 77
{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
78
*/
79 80 81 82 83 84 85 86
 /*
 //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
 */
87
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}};
88 89


90
extern void print_shorts(char *s,int16_t *x);
91

92

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

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

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

116
  unsigned char aatx,aarx;
117

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

122
  uint8_t beamforming_mode;
123
  uint32_t *rballoc;
124

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


131

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

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

147
  case PDSCH:
Bilel's avatar
Bilel committed
148
    pdsch_vars = ue->pdsch_vars[subframe&0x1];
149
    dlsch = ue->dlsch[subframe_DL(&ue->frame_parms,subframe)&0x1][eNB_id];
Bilel's avatar
Bilel committed
150 151 152 153 154
    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);

155 156 157 158 159 160
    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];
161
    }
162 163 164 165 166 167
     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;
168
    }
169 170 171
     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
172 173
      dlsch0_harq  = dlsch[1]->harq_processes[harq_pid];
      dlsch1_harq  = NULL;
174
      codeword_TB0 = -1;
175
    }
176 177 178 179
    else {
      LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: no active DLSCH\n",ue->proc.proc_rxtx[0].frame_rx,subframe);
      return(-1);
    }
180
    beamforming_mode  = ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id];
181 182 183
    break;

  default:
Cedric Roux's avatar
Cedric Roux committed
184
    LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: Unknown PDSCH format %d\n",ue->proc.proc_rxtx[0].frame_rx,subframe,type);
185 186 187
    return(-1);
    break;
  }
188 189 190 191
#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
192

193 194
  DevAssert(dlsch0_harq);
  round = dlsch0_harq->round;
195

196
  if (eNB_id > 2) {
jiangx's avatar
jiangx committed
197
    LOG_W(PHY,"dlsch_demodulation.c: Illegal eNB_id %d\n",eNB_id);
198 199
    return(-1);
  }
200

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

206
  if (!dlsch[0]) {
jiangx's avatar
jiangx committed
207
    LOG_W(PHY,"dlsch_demodulation.c: Null dlsch_ue pointer\n");
208 209 210
    return(-1);
  }

211 212
  if (!pdsch_vars) {
    LOG_W(PHY,"dlsch_demodulation.c: Null pdsch_vars pointer\n");
213 214
    return(-1);
  }
215

216
  if (!frame_parms) {
217
    LOG_W(PHY,"dlsch_demodulation.c: Null frame_parms\n");
218 219
    return(-1);
  }
220

221 222 223 224 225
  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;
226

227

228
  if (dlsch0_harq->mimo_mode>DUALSTREAM_PUSCH_PRECODING) {
229 230 231
    LOG_E(PHY,"This transmission mode is not yet supported!\n");
    return(-1);
  }
232 233 234



235 236 237 238 239 240 241 242
  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
243
  if (frame_parms->nb_antenna_ports_eNB>1 && beamforming_mode==0) {
244
#ifdef DEBUG_DLSCH_MOD
245
    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]);
246
#endif
247

248 249
    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],
250 251
                                   pdsch_vars[eNB_id]->rxdataF_ext,
                                   pdsch_vars[eNB_id]->dl_ch_estimates_ext,
252
                                   dlsch0_harq->pmi_alloc,
253
                                   pdsch_vars[eNB_id]->pmi_ext,
254
                                   rballoc,
255 256
                                   symbol,
                                   subframe,
257
                                   ue->high_speed_flag,
258
                                   frame_parms,
259
                                   dlsch0_harq->mimo_mode);
Gabriel's avatar
Gabriel committed
260 261
#ifdef DEBUG_DLSCH_MOD
      printf("dlsch: using pmi %lx, rb_alloc %x, pmi_ext ",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),*rballoc);
262
       for (rb=0;rb<nb_rb;rb++)
263
          printf("%d",pdsch_vars[eNB_id]->pmi_ext[rb]);
Gabriel's avatar
Gabriel committed
264 265
       printf("\n");
#endif
266

267
   if (rx_type >= rx_IC_single_stream) {
268
      if (eNB_id_i<ue->n_connected_eNB) // we are in TM5
269
      nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
270
                                       common_vars->common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[eNB_id_i],
271 272
                                       pdsch_vars[eNB_id_i]->rxdataF_ext,
                                       pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
273
                                       dlsch0_harq->pmi_alloc,
274
                                       pdsch_vars[eNB_id_i]->pmi_ext,
275
                                       rballoc,
276 277
                                       symbol,
                                       subframe,
278
                                       ue->high_speed_flag,
279
                                       frame_parms,
280
                                       dlsch0_harq->mimo_mode);
281
      else
282 283
        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],
284 285
                                       pdsch_vars[eNB_id_i]->rxdataF_ext,
                                       pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
286
                                       dlsch0_harq->pmi_alloc,
287
                                       pdsch_vars[eNB_id_i]->pmi_ext,
288
                                       rballoc,
289 290
                                       symbol,
                                       subframe,
291
                                       ue->high_speed_flag,
292
                                       frame_parms,
293
                                       dlsch0_harq->mimo_mode);
294
    }
295
  } else if (beamforming_mode==0) { //else if nb_antennas_ports_eNB==1 && beamforming_mode == 0
296 297
    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],
298 299
                                     pdsch_vars[eNB_id]->rxdataF_ext,
                                     pdsch_vars[eNB_id]->dl_ch_estimates_ext,
300
                                     dlsch0_harq->pmi_alloc,
301
                                     pdsch_vars[eNB_id]->pmi_ext,
302
                                     rballoc,
303 304
                                     symbol,
                                     subframe,
305
                                     ue->high_speed_flag,
306
                                     frame_parms);
307

Elena Lukashova's avatar
Elena Lukashova committed
308
   if (rx_type==rx_IC_single_stream) {
309
     if (eNB_id_i<ue->n_connected_eNB)
310 311
        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],
312
                                         pdsch_vars[eNB_id_i]->rxdataF_ext,
313
                                         pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
314
                                         dlsch0_harq->pmi_alloc,
315
                                         pdsch_vars[eNB_id_i]->pmi_ext,
316
                                         rballoc,
317 318
                                         symbol,
                                         subframe,
319
                                         ue->high_speed_flag,
320
                                         frame_parms);
321
      else
322 323
        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],
324
                                         pdsch_vars[eNB_id_i]->rxdataF_ext,
325
                                         pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
326
                                         dlsch0_harq->pmi_alloc,
327
                                         pdsch_vars[eNB_id_i]->pmi_ext,
328
                                         rballoc,
329 330
                                         symbol,
                                         subframe,
331
                                         ue->high_speed_flag,
332
                                         frame_parms);
333
    }
334
  } else if (beamforming_mode==7) { //else if beamforming_mode == 7
335
    nb_rb = dlsch_extract_rbs_TM7(common_vars->common_vars_rx_data_per_thread[subframe&0x1].rxdataF,
336 337 338
                                  pdsch_vars[eNB_id]->dl_bf_ch_estimates,
                                  pdsch_vars[eNB_id]->rxdataF_ext,
                                  pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
339
                                  rballoc,
340 341
                                  symbol,
                                  subframe,
342
                                  ue->high_speed_flag,
343
                                  frame_parms);
344

345
  } else if(beamforming_mode>7) {
346
    LOG_W(PHY,"dlsch_demodulation: beamforming mode not supported yet.\n");
347
  }
348

Bilel's avatar
Bilel committed
349
  //printf("nb_rb = %d, eNB_id %d\n",nb_rb,eNB_id);
350
  if (nb_rb==0) {
351
    LOG_D(PHY,"dlsch_demodulation.c: nb_rb=0\n");
352 353
    return(-1);
  }
354

Elena Lukashova's avatar
Elena Lukashova committed
355

356
#ifdef DEBUG_PHY
Gabriel's avatar
Gabriel committed
357
  LOG_I(PHY,"[DLSCH] nb_rb %d log2_maxh = %d (%d,%d)\n",nb_rb,pdsch_vars[eNB_id]->log2_maxh,avg[0],avgs);
358
  LOG_D(PHY,"[DLSCH] mimo_mode = %d\n", dlsch0_harq->mimo_mode);
359 360
#endif

361
  aatx = frame_parms->nb_antenna_ports_eNB;
Elena Lukashova's avatar
Elena Lukashova committed
362 363
  aarx = frame_parms->nb_antennas_rx;

364
  dlsch_scale_channel(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
365 366 367 368
                      frame_parms,
                      dlsch,
                      symbol,
                      nb_rb);
369

370 371 372 373 374 375
  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
  {
376
    dlsch_scale_channel(pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
377
                        frame_parms,
378
                        dlsch,
379 380
                        symbol,
                        nb_rb);
381
  }
382

383
  if (first_symbol_flag==1) {
384 385 386
    if (beamforming_mode==0){
      if (dlsch0_harq->mimo_mode<LARGE_CDD) {
        dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
387 388 389 390
                           frame_parms,
                           avg,
                           symbol,
                           nb_rb);
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
        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);

Bilel's avatar
Bilel committed
411 412
      LOG_D(PHY,"Channel Level TM34  avg_0 %d, avg_1 %d, rx_type %d, rx_standard %d, interf_unaw_shift %d \n", avg_0[0],
              avg_1[0], rx_type, rx_standard, interf_unaw_shift);
413
        if (rx_type>rx_standard) {
414 415
          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;
416 417
          pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0);
          pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0);
Bilel's avatar
Bilel committed
418 419
          //printf("TM4 I-A log2_maxh0 = %d\n", pdsch_vars[eNB_id]->log2_maxh0);
          //printf("TM4 I-A log2_maxh1 = %d\n", pdsch_vars[eNB_id]->log2_maxh1);
420 421 422 423 424 425
         }
          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);
Bilel's avatar
Bilel committed
426 427
          //printf("TM4 I-UA log2_maxh0 = %d\n", pdsch_vars[eNB_id]->log2_maxh0);
          //printf("TM4 I-UA log2_maxh1 = %d\n", pdsch_vars[eNB_id]->log2_maxh1);
428 429 430 431 432 433 434 435 436 437 438 439
        }
      }
      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);
440

441 442
        }
        else if (dlsch0_harq->dl_power_off==1) { //TM6
443

444 445 446 447 448
          dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                   frame_parms,
                                   avg,
                                   symbol,
                                   nb_rb);
449

450 451 452 453
          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]);
454

455 456
          pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2) + 1;
          pdsch_vars[eNB_id]->log2_maxh++;
457

458
        }
459
      }
460

461 462 463 464 465 466 467
    }
    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
468 469 470
//#ifdef DEBUG_PHY
    LOG_I(PHY,"[DLSCH] AbsSubframe %d.%d log2_maxh = %d [log2_maxh0 %d log2_maxh1 %d] (%d,%d)\n",
            frame%1024,subframe, pdsch_vars[eNB_id]->log2_maxh,
Bilel's avatar
Bilel committed
471 472 473
                                                 pdsch_vars[eNB_id]->log2_maxh0,
                                                 pdsch_vars[eNB_id]->log2_maxh1,
                                                 avg[0],avgs);
Gabriel's avatar
Gabriel committed
474 475
    LOG_D(PHY,"[DLSCH] mimo_mode = %d\n", dlsch0_harq->mimo_mode);
//#endif
476
  }
477

478 479 480 481 482 483 484
#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
485

486 487
// Now channel compensation
  if (dlsch0_harq->mimo_mode<LARGE_CDD) {
488 489 490 491 492 493
    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,
494 495 496
                               frame_parms,
                               symbol,
                               first_symbol_flag,
Elena Lukashova's avatar
Elena Lukashova committed
497
                               dlsch0_harq->Qm,
498
                               nb_rb,
499
                               pdsch_vars[eNB_id]->log2_maxh,
500
                               measurements); // log2_maxh+I0_shift
501
 /*if (symbol == 5) {
502
     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);
503
 } */
504
    if ((rx_type==rx_IC_single_stream) &&
505
        (eNB_id_i<ue->n_connected_eNB)) {
506
         dlsch_channel_compensation(pdsch_vars[eNB_id_i]->rxdataF_ext,
507 508 509 510 511
                                 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,
512 513 514 515 516
                                 frame_parms,
                                 symbol,
                                 first_symbol_flag,
                                 i_mod,
                                 nb_rb,
517
                                 pdsch_vars[eNB_id]->log2_maxh,
518
                                 measurements); // log2_maxh+I0_shift
519 520
#ifdef DEBUG_PHY
      if (symbol == 5) {
521
        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);
522
        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);
523
      }
524
#endif
525

526
      dlsch_dual_stream_correlation(frame_parms,
527 528
                                    symbol,
                                    nb_rb,
529 530
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
531
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
532
                                    pdsch_vars[eNB_id]->log2_maxh);
533
    }
534 535
  } else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
            (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){
536
      dlsch_channel_compensation_TM34(frame_parms,
537
                                     pdsch_vars[eNB_id],
538
                                     measurements,
539 540 541
                                     eNB_id,
                                     symbol,
                                     dlsch0_harq->Qm,
Elena Lukashova's avatar
Elena Lukashova committed
542
                                     dlsch1_harq->Qm,
543 544 545
                                     harq_pid,
                                     dlsch0_harq->round,
                                     dlsch0_harq->mimo_mode,
546
                                     nb_rb,
547
                                     pdsch_vars[eNB_id]->log2_maxh0,
548
                                     pdsch_vars[eNB_id]->log2_maxh1);
549
  /*   if (symbol == 5) {
550 551 552 553
     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
554
        } */
555
      // compute correlation between signal and interference channels (rho12 and rho21)
556
        dlsch_dual_stream_correlation(frame_parms, // this is doing h11'*h12 and h21'*h22
557 558
                                    symbol,
                                    nb_rb,
559 560
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
561 562 563
                                    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] );
564
      //to be optimized (just take complex conjugate)
565
      dlsch_dual_stream_correlation(frame_parms, // this is doing h12'*h11 and h22'*h21
566 567
                                    symbol,
                                    nb_rb,
568
                                    &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
569
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
570 571
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                    pdsch_vars[eNB_id]->log2_maxh1);
572
    //  printf("rho stream2 =%d\n",&pdsch_vars[eNB_id]->dl_ch_rho2_ext );
573
      //printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh);
574
  /*     if (symbol == 5) {
575 576 577 578
     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
579
        } */
580

581 582 583
    } 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,
584 585 586 587 588
                                      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,
589
                                      frame_parms,
590
                                      measurements,
591 592
                                      eNB_id,
                                      symbol,
593
                                      dlsch0_harq->Qm,
594
                                      nb_rb,
595
                                      pdsch_vars[eNB_id]->log2_maxh,
596
                                      dlsch0_harq->dl_power_off);
597

598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
        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
613
       //  if (rb==0)
614
        //    printf("pmi %d, pmi_i %d\n",pdsch_vars[eNB_id]->pmi_ext[rb],pdsch_vars[eNB_id_i]->pmi_ext[rb]);
615
      }
616 617 618 619 620 621
      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,
622
                                      frame_parms,
623
                                      measurements,
624 625 626 627
                                      eNB_id_i,
                                      symbol,
                                      i_mod,
                                      nb_rb,
628
                                      pdsch_vars[eNB_id]->log2_maxh,
629
                                      dlsch0_harq->dl_power_off);
630 631
#ifdef DEBUG_PHY
      if (symbol==5) {
632
        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);
633
       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);
634
      }
635
#endif
636 637 638
      dlsch_dual_stream_correlation(frame_parms,
                                    symbol,
                                    nb_rb,
639 640 641 642
                                    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);
643
    }  else if (dlsch0_harq->dl_power_off==1)  {
644 645 646 647 648 649
      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,
650
                                      frame_parms,
651
                                      measurements,
652 653
                                      eNB_id,
                                      symbol,
654
                                      dlsch0_harq->Qm,
655
                                      nb_rb,
656
                                      pdsch_vars[eNB_id]->log2_maxh,
657
                                      1);
Elena Lukashova's avatar
Elena Lukashova committed
658

659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
      }


    } 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
678 679
  }

680 681 682 683
// MRC


   if (frame_parms->nb_antennas_rx > 1) {
684
    if ((dlsch0_harq->mimo_mode == LARGE_CDD) ||
685
        ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
686
         (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){  // TM3 or TM4
Xiwen JIANG's avatar
Xiwen JIANG committed
687
      if (frame_parms->nb_antenna_ports_eNB == 2) {
688
        dlsch_detection_mrc_TM34(frame_parms,
689
                                 pdsch_vars[eNB_id],
690
                                 harq_pid,
691
                                 dlsch0_harq->round,
692 693 694
                                 symbol,
                                 nb_rb,
                                 1);
695
    /*   if (symbol == 5) {
696 697
     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
698
        } */
699
      }
700
    } else {
701
      dlsch_detection_mrc(frame_parms,
702 703 704
                          pdsch_vars[eNB_id]->rxdataF_comp0,
                          pdsch_vars[eNB_id_i]->rxdataF_comp0,
                          pdsch_vars[eNB_id]->rho,
705
                          pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
706 707 708 709
                          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,
710 711
                          symbol,
                          nb_rb,
712
                          rx_type==rx_IC_single_stream);
713 714 715 716 717
    }
  }
  //  printf("Combining");
  if ((dlsch0_harq->mimo_mode == SISO) ||
      ((dlsch0_harq->mimo_mode >= UNIFORM_PRECODING11) &&
718 719
       (dlsch0_harq->mimo_mode <= PUSCH_PRECODING0)) ||
       (dlsch0_harq->mimo_mode == TM7)) {
720 721
    /*
      dlsch_siso(frame_parms,
722 723
      pdsch_vars[eNB_id]->rxdataF_comp,
      pdsch_vars[eNB_id_i]->rxdataF_comp,
724 725 726 727 728
      symbol,
      nb_rb);
    */
  } else if (dlsch0_harq->mimo_mode == ALAMOUTI) {
    dlsch_alamouti(frame_parms,
729 730 731
                   pdsch_vars[eNB_id]->rxdataF_comp0,
                   pdsch_vars[eNB_id]->dl_ch_mag0,
                   pdsch_vars[eNB_id]->dl_ch_magb0,
732 733
                   symbol,
                   nb_rb);
734 735
  }

736
  //    printf("LLR");
737 738
  if ((dlsch0_harq->mimo_mode == LARGE_CDD) ||
      ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
739
       (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING)))  {
740
    rxdataF_comp_ptr = pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round];
741
    dl_ch_mag_ptr = pdsch_vars[eNB_id]->dl_ch_mag1[harq_pid][round];
742 743
  }
  else {
744 745
    rxdataF_comp_ptr = pdsch_vars[eNB_id_i]->rxdataF_comp0;
    dl_ch_mag_ptr = pdsch_vars[eNB_id_i]->dl_ch_mag0;
746
    //i_mod should have been passed as a parameter
747
  }
748

Gabriel's avatar
Gabriel committed
749 750
  //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);

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