[GITLAB] - UPGRADE TO v12 on Wednesday the 18th of December at 11.30AM

dlsch_demodulation.c 248 KB
Newer Older
1 2 3 4 5
/*
 * 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
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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 33 34 35 36
#include "PHY/defs_UE.h"
#include "PHY/phy_extern_ue.h"
#include "SCHED_UE/sched_UE.h"
#include "transport_ue.h"
#include "transport_proto_ue.h"
37
#include "PHY/sse_intrin.h"
38
#include "T.h"
39

40
#define NOCYGWIN_STATIC
41

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

49 50
//#define DEBUG_HARQ

knopp's avatar
knopp committed
51
//#define DEBUG_PHY 1
52
//#define DEBUG_DLSCH_DEMOD 1
53

knopp's avatar
knopp committed
54
//#define DISABLE_LOG_X
55 56

// [MCS][i_mod (0,1,2) = (2,4,6)]
57
unsigned char offset_mumimo_llr_drange_fix=0;
58
//inferference-free case
59
unsigned char interf_unaw_shift_tm4_mcs[29]={5, 3, 4, 3, 3, 2, 1, 1, 2, 0, 1, 1, 1, 1, 0, 0,
60
                                             1, 1, 1, 1, 0, 2, 1, 0, 1, 0, 1, 0, 0} ;
61
unsigned char interf_unaw_shift_tm1_mcs[29]={5, 5, 4, 3, 3, 3, 2, 2, 4, 4, 2, 3, 3, 3, 1, 1,
62
                                             0, 1, 1, 2, 5, 4, 4, 6, 5, 1, 0, 5, 6} ; // mcs 21, 26, 28 seem to be errorneous
63

64 65 66
/*
//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
67 68
{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
69
*/
70 71 72 73 74 75 76 77
 /*
 //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
 */
78
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}};
79

80

81
extern void print_shorts(char *s,int16_t *x);
82

83

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

97 98 99
  LTE_UE_COMMON *common_vars  = &ue->common_vars;
  LTE_UE_PDSCH **pdsch_vars;
  LTE_DL_FRAME_PARMS *frame_parms    = &ue->frame_parms;
100
  PHY_MEASUREMENTS *measurements = &ue->measurements;
101
  LTE_UE_DLSCH_t   **dlsch;
102

Bilel's avatar
Bilel committed
103 104 105
  int avg[4];
  int avg_0[2];
  int avg_1[2];
Elena Lukashova's avatar
Elena Lukashova committed
106

107
#if UE_TIMING_TRACE
108
  uint8_t slot = 0;
109
#endif
110

111
  unsigned char aatx,aarx;
112

113
  unsigned short nb_rb = 0, round;
114
  int avgs = 0, rb;
115
  LTE_DL_UE_HARQ_t *dlsch0_harq,*dlsch1_harq = 0;
Elena Lukashova's avatar
Elena Lukashova committed
116

117
  uint8_t beamforming_mode;
118
  uint32_t *rballoc;
119

120 121
  int32_t **rxdataF_comp_ptr;
  int32_t **dl_ch_mag_ptr;
122 123
  int32_t codeword_TB0 = -1;
  int32_t codeword_TB1 = -1;
124 125


126

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

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

142
  case PDSCH:
143 144
    pdsch_vars = ue->pdsch_vars[ue->current_thread_id[subframe]];
    dlsch = ue->dlsch[ue->current_thread_id[subframe]][eNB_id];
145
    //printf("status TB0 = %d, status TB1 = %d \n", dlsch[0]->harq_processes[harq_pid]->status, dlsch[1]->harq_processes[harq_pid]->status);
Bilel's avatar
Bilel committed
146 147 148 149 150
    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);

151 152 153 154 155 156
    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];
157 158 159
#ifdef DEBUG_HARQ
      printf("[DEMOD] I am assuming both TBs are active\n");
#endif
160
    }
161 162 163 164 165 166
     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;
167 168 169
#ifdef DEBUG_HARQ
      printf("[DEMOD] I am assuming only TB0 is active\n");
#endif
170
    }
171 172 173
     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
174 175
      dlsch0_harq  = dlsch[1]->harq_processes[harq_pid];
      dlsch1_harq  = NULL;
176
      codeword_TB0 = -1;
177
#ifdef DEBUG_HARQ
178
      printf("[DEMOD] I am assuming only TB1 is active, it is in cw %d\n", dlsch0_harq->codeword);
179
#endif
180
    }
181 182 183 184
    else {
      LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: no active DLSCH\n",ue->proc.proc_rxtx[0].frame_rx,subframe);
      return(-1);
    }
185
    beamforming_mode  = ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id];
186 187 188
    break;

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

198 199
  DevAssert(dlsch0_harq);
  round = dlsch0_harq->round;
200
  //printf("round = %d\n", round);
201

202
  if (eNB_id > 2) {
jiangx's avatar
jiangx committed
203
    LOG_W(PHY,"dlsch_demodulation.c: Illegal eNB_id %d\n",eNB_id);
204 205
    return(-1);
  }
206

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

212
  if (!dlsch[0]) {
jiangx's avatar
jiangx committed
213
    LOG_W(PHY,"dlsch_demodulation.c: Null dlsch_ue pointer\n");
214 215 216
    return(-1);
  }

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

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

227 228 229 230 231
  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;
232

233

234
  if (dlsch0_harq->mimo_mode>DUALSTREAM_PUSCH_PRECODING) {
235 236 237
    LOG_E(PHY,"This transmission mode is not yet supported!\n");
    return(-1);
  }
238 239


240 241 242 243 244 245 246 247
  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);
    }
  }

248
#if UE_TIMING_TRACE
249 250 251 252
  if(symbol > ue->frame_parms.symbols_per_tti>>1)
  {
      slot = 1;
  }
253 254
#endif

255 256 257
#ifdef DEBUG_HARQ
  printf("Demod  dlsch0_harq->pmi_alloc %d\n",  dlsch0_harq->pmi_alloc);
#endif
258

Xiwen JIANG's avatar
Xiwen JIANG committed
259
  if (frame_parms->nb_antenna_ports_eNB>1 && beamforming_mode==0) {
260
#ifdef DEBUG_DLSCH_MOD
261
    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]);
262
#endif
263

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

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

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

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

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

Elena Lukashova's avatar
Elena Lukashova committed
374

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

386

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

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

399 400 401 402 403 404
  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
  {
405
    dlsch_scale_channel(pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
406
                        frame_parms,
407
                        dlsch,
408 409
                        symbol,
                        nb_rb);
410
  }
411

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

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

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

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

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

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

488 489 490 491
          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]);
492

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

496
        }
497
      }
498

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

    //wait until pdcch is decoded
tct-labo4's avatar
tct-labo4 committed
516
    //proc->channel_level = 1;
517
  }
518

tct-labo4's avatar
tct-labo4 committed
519
  /*
520 521 522 523 524
  uint32_t wait = 0;
  while(proc->channel_level == 0)
  {
      usleep(1);
      wait++;
525
  }
tct-labo4's avatar
tct-labo4 committed
526
  */
527

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

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


#if UE_TIMING_TRACE
547
    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
548
#endif
549 550
// Now channel compensation
  if (dlsch0_harq->mimo_mode<LARGE_CDD) {
551 552 553 554 555 556
    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,
557 558 559
                               frame_parms,
                               symbol,
                               first_symbol_flag,
560
                               dlsch0_harq->Qm,
561
                               nb_rb,
562
                               pdsch_vars[eNB_id]->log2_maxh,
563
                               measurements); // log2_maxh+I0_shift
564
 /*if (symbol == 5) {
565
     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);
566
 } */
567
    if ((rx_type==rx_IC_single_stream) &&
568
        (eNB_id_i<ue->n_connected_eNB)) {
569
         dlsch_channel_compensation(pdsch_vars[eNB_id_i]->rxdataF_ext,
570 571 572 573 574
                                 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,
575 576 577 578 579
                                 frame_parms,
                                 symbol,
                                 first_symbol_flag,
                                 i_mod,
                                 nb_rb,
580
                                 pdsch_vars[eNB_id]->log2_maxh,
581
                                 measurements); // log2_maxh+I0_shift
582 583
#ifdef DEBUG_PHY
      if (symbol == 5) {
584 585
        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);
586
      }
587 588
#endif

589
      dlsch_dual_stream_correlation(frame_parms,
590 591
                                    symbol,
                                    nb_rb,
592 593
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
594
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
595
                                    pdsch_vars[eNB_id]->log2_maxh);
596
    }
597 598
  } else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
            (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){
599
      dlsch_channel_compensation_TM34(frame_parms,
600
                                     pdsch_vars[eNB_id],
601
                                     measurements,
602 603
                                     eNB_id,
                                     symbol,
604 605
                                     dlsch0_harq->Qm,
                                     dlsch1_harq->Qm,
606
                                     harq_pid,
607
                                     dlsch0_harq->round,
608
                                     dlsch0_harq->mimo_mode,
609
                                     nb_rb,
610
                                     pdsch_vars[eNB_id]->log2_maxh0,
611
                                     pdsch_vars[eNB_id]->log2_maxh1);
612
  /*   if (symbol == 5) {
613 614 615 616
     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
617
        } */
618
      // compute correlation between signal and interference channels (rho12 and rho21)
619
        dlsch_dual_stream_correlation(frame_parms, // this is doing h11'*h12 and h21'*h22
620 621
                                    symbol,
                                    nb_rb,
622 623
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
624 625 626
                                    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] );
627
      //to be optimized (just take complex conjugate)
628
      dlsch_dual_stream_correlation(frame_parms, // this is doing h12'*h11 and h22'*h21
629 630
                                    symbol,
                                    nb_rb,
631 632
                                    &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
633 634
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                    pdsch_vars[eNB_id]->log2_maxh1);
635
    //  printf("rho stream2 =%d\n",&pdsch_vars[eNB_id]->dl_ch_rho2_ext );
636
      //printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh);
637
  /*     if (symbol == 5) {
638 639 640 641
     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
642
        } */
643

644 645 646
    } 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,
647 648 649 650 651
                                      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,
652
                                      frame_parms,
653
                                      measurements,
654 655
                                      eNB_id,
                                      symbol,
656
                                      dlsch0_harq->Qm,
657
                                      nb_rb,
658
                                      pdsch_vars[eNB_id]->log2_maxh,
659
                                      dlsch0_harq->dl_power_off);
660

661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
        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
676
       //  if (rb==0)
677
        //    printf("pmi %d, pmi_i %d\n",pdsch_vars[eNB_id]->pmi_ext[rb],pdsch_vars[eNB_id_i]->pmi_ext[rb]);
678
      }
679 680 681 682 683 684
      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,
685
                                      frame_parms,
686
                                      measurements,
687 688 689 690
                                      eNB_id_i,
                                      symbol,
                                      i_mod,
                                      nb_rb,
691
                                      pdsch_vars[eNB_id]->log2_maxh,
692
                                      dlsch0_harq->dl_power_off);
693 694
#ifdef DEBUG_PHY
      if (symbol==5) {
695
        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);
696
       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);
697
      }
698 699 700 701
#endif
      dlsch_dual_stream_correlation(frame_parms,
                                    symbol,
                                    nb_rb,
702 703
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
704
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
705
                                    pdsch_vars[eNB_id]->log2_maxh);
706
    }  else if (dlsch0_harq->dl_power_off==1)  {
707 708 709 710 711 712
      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,
713
                                      frame_parms,
714
                                      measurements,
715 716
                                      eNB_id,
                                      symbol,
717
                                      dlsch0_harq->Qm,
718
                                      nb_rb,
719
                                      pdsch_vars[eNB_id]->log2_maxh,
720
                                      1);
721

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


    } 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
741 742
  }

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

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

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

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

#if UE_TIMING_TRACE
832
    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
833
#endif
Gabriel's avatar
Gabriel committed
834
  //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);
835 836 837 838 839 840 841 842 843 844
  // compute LLRs
  // -> // compute @pointer where llrs should filled for this ofdm-symbol
  int8_t  *pllr_symbol_cw0;
  int8_t  *pllr_symbol_cw1;
  uint32_t llr_offset_symbol;
  llr_offset_symbol = pdsch_vars[eNB_id]->llr_offset[symbol];
  pllr_symbol_cw0  = (int8_t*)pdsch_vars[eNB_id]->llr[0];
  pllr_symbol_cw1  = (int8_t*)pdsch_vars[eNB_id]->llr[1];
  pllr_symbol_cw0 += llr_offset_symbol;
  pllr_symbol_cw1 += llr_offset_symbol;
knopp's avatar
knopp committed
845
  /*
846
  LOG_I(PHY,"compute LLRs [AbsSubframe %d.%d-%d] NbRB %d Qm %d LLRs-Length %d LLR-Offset %d @LLR Buff %p @LLR Buff(symb) %p\n",
847
             frame, subframe,symbol,
848 849 850 851
             nb_rb,dlsch0_harq->Qm,
             pdsch_vars[eNB_id]->llr_length[symbol],
             pdsch_vars[eNB_id]->llr_offset[symbol],
             (int16_t*)pdsch_vars[eNB_id]->llr[0],
852
             pllr_symbol_cw0);
knopp's avatar
knopp committed
853
  */
854
  switch (dlsch0_harq->Qm) {
855
  case 2 :
856
    if ((rx_type==rx_standard) || (codeword_TB1 == -1)) {
857 858


859
        dlsch_qpsk_llr(frame_parms,
860
                       pdsch_vars[eNB_id]->rxdataF_comp0,
861
                       (int16_t*)pllr_symbol_cw0,
862 863 864
                       symbol,
                       first_symbol_flag,
                       nb_rb,
865
                       adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
866
                       beamforming_mode);
867 868 869 870 871

    } else if (codeword_TB0 == -1){

        dlsch_qpsk_llr(frame_parms,
                       pdsch_vars[eNB_id]->rxdataF_comp0,
fnabet's avatar
fnabet committed
872
                       (int16_t*)pllr_symbol_cw1,
873 874 875
                       symbol,
                       first_symbol_flag,
                       nb_rb,
876
                       adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
877
                       beamforming_mode);
878
    }
879
      else if (rx_type >= rx_IC_single_stream) {
Elena Lukashova's avatar
Elena Lukashova committed
880
        if (dlsch1_harq->Qm == 2) {
881
          dlsch_qpsk_qpsk_llr(frame_parms,
882
                              pdsch_vars[eNB_id]->rxdataF_comp0,
883
                              rxdataF_comp_ptr,
884 885
                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                              pdsch_vars[eNB_id]->llr[0],
886
                              symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
887
                              adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
888
                              pdsch_vars[eNB_id]->llr128);
889 890 891
          if (rx_type==rx_IC_dual_stream) {
            dlsch_qpsk_qpsk_llr(frame_parms,
                                rxdataF_comp_ptr,
892 893 894
                                pdsch_vars[eNB_id]->rxdataF_comp0,
                                pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                pdsch_vars[eNB_id]->llr[1],
895
                                symbol,first_symbol_flag,nb_rb,
896
                                adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol),
897
                                pdsch_vars[eNB_id]->llr128_2ndstream);
898 899
          }
        }
900
        else if (dlsch1_harq->Qm == 4) {
901
          dlsch_qpsk_16qam_llr(frame_parms,
902
                               pdsch_vars[eNB_id]->rxdataF_comp0,
903 904
                               rxdataF_comp_ptr,//i
                               dl_ch_mag_ptr,//i
905 906
                               pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                               pdsch_vars[eNB_id]->llr[0],
907
                               symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
908
                               adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
909
                               pdsch_vars[eNB_id]->llr128);
910 911 912
          if (rx_type==rx_IC_dual_stream) {
            dlsch_16qam_qpsk_llr(frame_parms,
                                 rxdataF_comp_ptr,
913
                                 pdsch_vars[eNB_id]->rxdataF_comp0,//i
914
                                 dl_ch_mag_ptr,
915 916
                                 pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                 pdsch_vars[eNB_id]->llr[1],
917
                                 symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
918
                                 adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol),
919
                                 pdsch_vars[eNB_id]->llr128_2ndstream);
920 921 922 923
          }
        }
        else {
          dlsch_qpsk_64qam_llr(frame_parms,
924
                               pdsch_vars[eNB_id]->rxdataF_comp0,
925 926
                               rxdataF_comp_ptr,//i
                               dl_ch_mag_ptr,//i
927 928
                               pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                               pdsch_vars[eNB_id]->llr[0],
929
                               symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
930
                               adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
931
                               pdsch_vars[eNB_id]->llr128);
932 933 934
          if (rx_type==rx_IC_dual_stream) {
            dlsch_64qam_qpsk_llr(frame_parms,
                                 rxdataF_comp_ptr,
935
                                 pdsch_vars[eNB_id]->rxdataF_comp0,//i
936
                                 dl_ch_mag_ptr,
937 938
                                 pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                 pdsch_vars[eNB_id]->llr[1],
939
                                 symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
940
                                 adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,subframe,symbol),
941
                                 pdsch_vars[eNB_id]->llr128_2ndstream);
942
          }
943
        }
944
      }
945 946
    break;
  case 4 :
947
    if ((rx_type==rx_standard ) || (codeword_TB1 == -1)) {
948
      dlsch_16qam_llr(frame_parms,
949 950 951
                      pdsch_vars[eNB_id]->rxdataF_comp0,
                      pdsch_vars[eNB_id]->llr[0],
                      pdsch_vars[eNB_id]->dl_ch_mag0,
952
                      symbol,first_symbol_flag,nb_rb,
953
                      adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
954 955
                      pdsch_vars[eNB_id]->llr128,
                      beamforming_mode);
956 957 958 959 960 961 962 963 964
    } else if (codeword_TB0 == -1){
      dlsch_16qam_llr(frame_parms,
                      pdsch_vars[eNB_id]->rxdataF_comp0,
                      pdsch_vars[eNB_id]->llr[1],
                      pdsch_vars[eNB_id]->dl_ch_mag0,
                      symbol,first_symbol_flag,nb_rb,
                      adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol),
                      pdsch_vars[eNB_id]->llr128_2ndstream,
                      beamforming_mode);