dlsch_demodulation.c 282 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 41 42
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <string.h>
43 44 45 46 47
#include <linux/version.h>
#if RHEL_RELEASE_CODE >= 1796
#include <lapacke/lapacke_utils.h>
#include <lapacke/lapacke.h>
#else
48 49
#include <lapacke_utils.h>
#include <lapacke.h>
50
#endif
51 52
#include <cblas.h>
#include "linear_preprocessing_rec.h"
53

54
#define NOCYGWIN_STATIC
55 56
//#define DEBUG_MMSE

57

58 59 60 61 62
/* 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
63
int16_t interf_unaw_shift = 13;
64

65 66
//#define DEBUG_HARQ

knopp's avatar
knopp committed
67
//#define DEBUG_PHY 1
68
//#define DEBUG_DLSCH_DEMOD 1
69

knopp's avatar
knopp committed
70
//#define DISABLE_LOG_X
71 72

// [MCS][i_mod (0,1,2) = (2,4,6)]
73
unsigned char offset_mumimo_llr_drange_fix=0;
74
//inferference-free case
75
unsigned char interf_unaw_shift_tm4_mcs[29]={5, 3, 4, 3, 3, 2, 1, 1, 2, 0, 1, 1, 1, 1, 0, 0,
76
                                             1, 1, 1, 1, 0, 2, 1, 0, 1, 0, 1, 0, 0} ;
77
unsigned char interf_unaw_shift_tm1_mcs[29]={5, 5, 4, 3, 3, 3, 2, 2, 4, 4, 2, 3, 3, 3, 1, 1,
78
                                             0, 1, 1, 2, 5, 4, 4, 6, 5, 1, 0, 5, 6} ; // mcs 21, 26, 28 seem to be errorneous
79

80 81 82
/*
//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
83 84
{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
85
*/
86 87 88 89 90 91 92 93
 /*
 //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
 */
94
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}};
95

96

97
extern void print_shorts(char *s,int16_t *x);
98

99

100
int rx_pdsch(PHY_VARS_UE *ue,
101 102
             PDSCH_t type,
             unsigned char eNB_id,
103
             unsigned char eNB_id_i, //if this == ue->n_connected_eNB, we assume MU interference
104
             uint32_t frame,
105
             uint8_t subframe,
106 107
             unsigned char symbol,
             unsigned char first_symbol_flag,
108
             RX_type_t rx_type,
109
             unsigned char i_mod,
110 111 112
             unsigned char harq_pid)
{

113 114 115
  LTE_UE_COMMON *common_vars  = &ue->common_vars;
  LTE_UE_PDSCH **pdsch_vars;
  LTE_DL_FRAME_PARMS *frame_parms    = &ue->frame_parms;
116
  PHY_MEASUREMENTS *measurements = &ue->measurements;
117
  LTE_UE_DLSCH_t   **dlsch;
118

Bilel's avatar
Bilel committed
119 120 121
  int avg[4];
  int avg_0[2];
  int avg_1[2];
122
  unsigned short mmse_flag=0;
Elena Lukashova's avatar
Elena Lukashova committed
123

124
#if UE_TIMING_TRACE
125
  uint8_t slot = 0;
126
#endif
127

128
  unsigned char aatx,aarx;
129

130
  unsigned short nb_rb = 0, round;
131
  int avgs = 0, rb;
132
  LTE_DL_UE_HARQ_t *dlsch0_harq,*dlsch1_harq = 0;
Elena Lukashova's avatar
Elena Lukashova committed
133

134
  uint8_t beamforming_mode;
135
  uint32_t *rballoc;
136

137 138
  int32_t **rxdataF_comp_ptr;
  int32_t **dl_ch_mag_ptr;
139 140
  int32_t codeword_TB0 = -1;
  int32_t codeword_TB1 = -1;
141 142


143

144 145
  switch (type) {
  case SI_PDSCH:
146
    pdsch_vars = &ue->pdsch_vars_SI[eNB_id];
147 148
    dlsch = &ue->dlsch_SI[eNB_id];
    dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
149
    beamforming_mode  = 0;
150
    break;
151

152
  case RA_PDSCH:
153
    pdsch_vars = &ue->pdsch_vars_ra[eNB_id];
154 155
    dlsch = &ue->dlsch_ra[eNB_id];
    dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
156
    beamforming_mode  = 0;
157
    break;
158

159
  case PDSCH:
160 161
    pdsch_vars = ue->pdsch_vars[ue->current_thread_id[subframe]];
    dlsch = ue->dlsch[ue->current_thread_id[subframe]][eNB_id];
162
    //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
163 164 165 166 167
    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);

168 169 170 171 172 173
    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];
174 175 176
#ifdef DEBUG_HARQ
      printf("[DEMOD] I am assuming both TBs are active\n");
#endif
177
    }
178 179 180 181 182 183
     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;
184 185 186
#ifdef DEBUG_HARQ
      printf("[DEMOD] I am assuming only TB0 is active\n");
#endif
187
    }
188 189 190
     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
191 192
      dlsch0_harq  = dlsch[1]->harq_processes[harq_pid];
      dlsch1_harq  = NULL;
193
      codeword_TB0 = -1;
194
#ifdef DEBUG_HARQ
195
      printf("[DEMOD] I am assuming only TB1 is active, it is in cw %d\n", dlsch0_harq->codeword);
196
#endif
197
    }
198 199 200 201
    else {
      LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: no active DLSCH\n",ue->proc.proc_rxtx[0].frame_rx,subframe);
      return(-1);
    }
202
    beamforming_mode  = ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id];
203 204 205
    break;

  default:
Cedric Roux's avatar
Cedric Roux committed
206
    LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: Unknown PDSCH format %d\n",ue->proc.proc_rxtx[0].frame_rx,subframe,type);
207 208 209
    return(-1);
    break;
  }
210 211 212 213
#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
214

215 216
  DevAssert(dlsch0_harq);
  round = dlsch0_harq->round;
217
  //printf("round = %d\n", round);
218

219
  if (eNB_id > 2) {
jiangx's avatar
jiangx committed
220
    LOG_W(PHY,"dlsch_demodulation.c: Illegal eNB_id %d\n",eNB_id);
221 222
    return(-1);
  }
223

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

229
  if (!dlsch[0]) {
jiangx's avatar
jiangx committed
230
    LOG_W(PHY,"dlsch_demodulation.c: Null dlsch_ue pointer\n");
231 232 233
    return(-1);
  }

234 235
  if (!pdsch_vars) {
    LOG_W(PHY,"dlsch_demodulation.c: Null pdsch_vars pointer\n");
236 237
    return(-1);
  }
238

239
  if (!frame_parms) {
240
    LOG_W(PHY,"dlsch_demodulation.c: Null frame_parms\n");
241 242
    return(-1);
  }
243

244 245 246 247 248
  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;
249

250

251
  if (dlsch0_harq->mimo_mode>DUALSTREAM_PUSCH_PRECODING) {
252 253 254
    LOG_E(PHY,"This transmission mode is not yet supported!\n");
    return(-1);
  }
255 256


257 258 259 260 261 262 263 264
  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);
    }
  }

265
#if UE_TIMING_TRACE
266 267 268 269
  if(symbol > ue->frame_parms.symbols_per_tti>>1)
  {
      slot = 1;
  }
270 271
#endif

272 273 274
#ifdef DEBUG_HARQ
  printf("Demod  dlsch0_harq->pmi_alloc %d\n",  dlsch0_harq->pmi_alloc);
#endif
275

Xiwen JIANG's avatar
Xiwen JIANG committed
276
  if (frame_parms->nb_antenna_ports_eNB>1 && beamforming_mode==0) {
277
#ifdef DEBUG_DLSCH_MOD
278
    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]);
279
#endif
280

281
#if UE_TIMING_TRACE
282
    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
283
#endif
284 285
    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],
286 287
                                   pdsch_vars[eNB_id]->rxdataF_ext,
                                   pdsch_vars[eNB_id]->dl_ch_estimates_ext,
288
                                   dlsch0_harq->pmi_alloc,
289
                                   pdsch_vars[eNB_id]->pmi_ext,
290
                                   rballoc,
291 292
                                   symbol,
                                   subframe,
293
                                   ue->high_speed_flag,
294
                                   frame_parms,
295
                                   dlsch0_harq->mimo_mode);
Gabriel's avatar
Gabriel committed
296 297
#ifdef DEBUG_DLSCH_MOD
      printf("dlsch: using pmi %lx, rb_alloc %x, pmi_ext ",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),*rballoc);
298
       for (rb=0;rb<nb_rb;rb++)
299
          printf("%d",pdsch_vars[eNB_id]->pmi_ext[rb]);
Gabriel's avatar
Gabriel committed
300 301
       printf("\n");
#endif
302

303
   if (rx_type >= rx_IC_single_stream) {
304
      if (eNB_id_i<ue->n_connected_eNB) // we are in TM5
305 306
      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],
307 308
                                       pdsch_vars[eNB_id_i]->rxdataF_ext,
                                       pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
309
                                       dlsch0_harq->pmi_alloc,
310
                                       pdsch_vars[eNB_id_i]->pmi_ext,
311
                                       rballoc,
312 313
                                       symbol,
                                       subframe,
314
                                       ue->high_speed_flag,
315
                                       frame_parms,
316
                                       dlsch0_harq->mimo_mode);
317
      else
318 319
        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],
320 321
                                       pdsch_vars[eNB_id_i]->rxdataF_ext,
                                       pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
322
                                       dlsch0_harq->pmi_alloc,
323
                                       pdsch_vars[eNB_id_i]->pmi_ext,
324
                                       rballoc,
325 326
                                       symbol,
                                       subframe,
327
                                       ue->high_speed_flag,
328
                                       frame_parms,
329
                                       dlsch0_harq->mimo_mode);
330
    }
331
  } else if (beamforming_mode==0) { //else if nb_antennas_ports_eNB==1 && beamforming_mode == 0
332 333
    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],
334 335
                                     pdsch_vars[eNB_id]->rxdataF_ext,
                                     pdsch_vars[eNB_id]->dl_ch_estimates_ext,
336
                                     dlsch0_harq->pmi_alloc,
337
                                     pdsch_vars[eNB_id]->pmi_ext,
338
                                     rballoc,
339 340
                                     symbol,
                                     subframe,
341
                                     ue->high_speed_flag,
342 343
                                     frame_parms);

Elena Lukashova's avatar
Elena Lukashova committed
344
   if (rx_type==rx_IC_single_stream) {
345
     if (eNB_id_i<ue->n_connected_eNB)
346 347
        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],
348 349
                                         pdsch_vars[eNB_id_i]->rxdataF_ext,
                                         pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
350
                                         dlsch0_harq->pmi_alloc,
351
                                         pdsch_vars[eNB_id_i]->pmi_ext,
352
                                         rballoc,
353 354
                                         symbol,
                                         subframe,
355
                                         ue->high_speed_flag,
356
                                         frame_parms);
357
      else
358 359
        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],
360 361
                                         pdsch_vars[eNB_id_i]->rxdataF_ext,
                                         pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
362
                                         dlsch0_harq->pmi_alloc,
363
                                         pdsch_vars[eNB_id_i]->pmi_ext,
364
                                         rballoc,
365 366
                                         symbol,
                                         subframe,
367
                                         ue->high_speed_flag,
368
                                         frame_parms);
369
    }
370
  } else if (beamforming_mode==7) { //else if beamforming_mode == 7
371
    nb_rb = dlsch_extract_rbs_TM7(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF,
372 373 374
                                  pdsch_vars[eNB_id]->dl_bf_ch_estimates,
                                  pdsch_vars[eNB_id]->rxdataF_ext,
                                  pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
375
                                  rballoc,
376 377
                                  symbol,
                                  subframe,
378
                                  ue->high_speed_flag,
379
                                  frame_parms);
380

381
  } else if(beamforming_mode>7) {
382
    LOG_W(PHY,"dlsch_demodulation: beamforming mode not supported yet.\n");
383
  }
384

Bilel's avatar
Bilel committed
385
  //printf("nb_rb = %d, eNB_id %d\n",nb_rb,eNB_id);
386
  if (nb_rb==0) {
knopp's avatar
knopp committed
387
    //    LOG_D(PHY,"dlsch_demodulation.c: nb_rb=0\n");
388 389
    return(-1);
  }
390

Elena Lukashova's avatar
Elena Lukashova committed
391

392
#if UE_TIMING_TRACE
393
    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
394 395
#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,
396
            symbol,ue->high_speed_flag,type,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
397 398
#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,
399
            ue->high_speed_flag,type,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
400
#endif
401 402
#endif

403

404
#if UE_TIMING_TRACE
405
    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
406
#endif
407
  aatx = frame_parms->nb_antenna_ports_eNB;
Elena Lukashova's avatar
Elena Lukashova committed
408 409
  aarx = frame_parms->nb_antennas_rx;

410
  dlsch_scale_channel(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
411 412 413 414
                      frame_parms,
                      dlsch,
                      symbol,
                      nb_rb);
415

416 417 418 419 420 421
  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
  {
422
    dlsch_scale_channel(pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
423
                        frame_parms,
424
                        dlsch,
425 426
                        symbol,
                        nb_rb);
427
  }
428

429
#if UE_TIMING_TRACE
430
    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
431
#if DISABLE_LOG_X
432
    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));
433
#else
434
    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));
435 436 437 438
#endif
#endif

#if UE_TIMING_TRACE
439
    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
440
#endif
441
  if (first_symbol_flag==1) {
442 443 444
    if (beamforming_mode==0){
      if (dlsch0_harq->mimo_mode<LARGE_CDD) {
        dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
445 446 447 448
                           frame_parms,
                           avg,
                           symbol,
                           nb_rb);
449 450 451 452 453 454 455 456 457 458 459
        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)))
     {
460 461 462 463 464 465 466 467 468
       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,
                                  mmse_flag,
                                  dlsch0_harq->mimo_mode);
469

Cedric Roux's avatar
Cedric Roux committed
470
      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],
471
              avg_1[0], rx_type, rx_standard, dlsch_demod_shift);
472
        if (rx_type>rx_standard) {
473 474
          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;
475 476
          pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0);
          pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0);
477
         // printf("dlsch_demod_shift  %d\n", dlsch_demod_shift);
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
         }
          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);
496

497 498
        }
        else if (dlsch0_harq->dl_power_off==1) { //TM6
499

500 501 502 503 504
          dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                   frame_parms,
                                   avg,
                                   symbol,
                                   nb_rb);
505

506 507 508 509
          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]);
510

511 512
          pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2) + 1;
          pdsch_vars[eNB_id]->log2_maxh++;
513

514
        }
515
      }
516

517
    }
518
    else if (beamforming_mode==7)
519
       dlsch_channel_level_TM7(pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
520 521 522 523
                              frame_parms,
                              avg,
                              symbol,
                              nb_rb);
Gabriel's avatar
Gabriel committed
524
#ifdef UE_DEBUG_TRACE
Gabriel's avatar
Gabriel committed
525
    LOG_D(PHY,"[DLSCH] AbsSubframe %d.%d log2_maxh = %d [log2_maxh0 %d log2_maxh1 %d] (%d,%d)\n",
Gabriel's avatar
Gabriel committed
526
            frame%1024,subframe, pdsch_vars[eNB_id]->log2_maxh,
Bilel's avatar
Bilel committed
527 528 529
                                                 pdsch_vars[eNB_id]->log2_maxh0,
                                                 pdsch_vars[eNB_id]->log2_maxh1,
                                                 avg[0],avgs);
Gabriel's avatar
Gabriel committed
530
    //LOG_D(PHY,"[DLSCH] mimo_mode = %d\n", dlsch0_harq->mimo_mode);
531
#endif
532 533

    //wait until pdcch is decoded
tct-labo4's avatar
tct-labo4 committed
534
    //proc->channel_level = 1;
535
  }
536

tct-labo4's avatar
tct-labo4 committed
537
  /*
538 539 540 541 542
  uint32_t wait = 0;
  while(proc->channel_level == 0)
  {
      usleep(1);
      wait++;
543
  }
tct-labo4's avatar
tct-labo4 committed
544
  */
545

546 547 548
#if T_TRACER
    if (type == PDSCH)
    {
Cedric Roux's avatar
Cedric Roux committed
549 550
      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]));
551 552
    }
#endif
553

554
#if UE_TIMING_TRACE
555
    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
556
#if DISABLE_LOG_X
557
    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));
558
#else
559
    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));
560 561 562 563 564
#endif
#endif


#if UE_TIMING_TRACE
565
    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
566
#endif
567

568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
  if (rx_type==rx_IC_dual_stream && mmse_flag==1){

    precode_channel_est(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                        frame_parms,
                        pdsch_vars[eNB_id],
                        symbol,
                        nb_rb,
                        dlsch0_harq->mimo_mode);

   mmse_processing_oai(pdsch_vars[eNB_id],
                        frame_parms,
                        measurements,
                        first_symbol_flag,
                        dlsch0_harq->mimo_mode,
                        mmse_flag,
                        0.0,
                        symbol,
                        nb_rb);
  }

588 589
// Now channel compensation
  if (dlsch0_harq->mimo_mode<LARGE_CDD) {
590 591 592 593 594 595
    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,
596 597 598
                               frame_parms,
                               symbol,
                               first_symbol_flag,
599
                               dlsch0_harq->Qm,
600
                               nb_rb,
601
                               pdsch_vars[eNB_id]->log2_maxh,
602
                               measurements); // log2_maxh+I0_shift
Mongazon's avatar
Mongazon committed
603 604 605
    if (symbol == 5) {
     LOG_M("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);
    }
606

607
    if ((rx_type==rx_IC_single_stream) &&
608
        (eNB_id_i<ue->n_connected_eNB)) {
609
         dlsch_channel_compensation(pdsch_vars[eNB_id_i]->rxdataF_ext,
610 611 612 613 614
                                 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,
615 616 617 618 619
                                 frame_parms,
                                 symbol,
                                 first_symbol_flag,
                                 i_mod,
                                 nb_rb,
620
                                 pdsch_vars[eNB_id]->log2_maxh,
621
                                 measurements); // log2_maxh+I0_shift
622
      if (symbol == 5) {
Mongazon's avatar
Mongazon committed
623 624
        LOG_M("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);
        LOG_M("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);
625
      }
626

627
      dlsch_dual_stream_correlation(frame_parms,
628 629
                                    symbol,
                                    nb_rb,
630 631
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
632
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
633
                                    pdsch_vars[eNB_id]->log2_maxh);
634
    }
635 636
  } else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
            (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){
637
      dlsch_channel_compensation_TM34(frame_parms,
638
                                     pdsch_vars[eNB_id],
639
                                     measurements,
640 641
                                     eNB_id,
                                     symbol,
642 643
                                     dlsch0_harq->Qm,
                                     dlsch1_harq->Qm,
644
                                     harq_pid,
645
                                     dlsch0_harq->round,
646
                                     dlsch0_harq->mimo_mode,
647
                                     nb_rb,
648
                                     mmse_flag,
649
                                     pdsch_vars[eNB_id]->log2_maxh0,
650
                                     pdsch_vars[eNB_id]->log2_maxh1);
Mongazon's avatar
Mongazon committed
651 652 653 654 655 656
      if (symbol == 5) {
	LOG_M("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
	LOG_M("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
	LOG_M("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
	LOG_M("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
      }
657
      // compute correlation between signal and interference channels (rho12 and rho21)
Mongazon's avatar
Mongazon committed
658
      dlsch_dual_stream_correlation(frame_parms, // this is doing h11'*h12 and h21'*h22
659 660
                                    symbol,
                                    nb_rb,
661 662
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
663 664 665
                                    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] );
666
      //to be optimized (just take complex conjugate)
667
      dlsch_dual_stream_correlation(frame_parms, // this is doing h12'*h11 and h22'*h21
668 669
                                    symbol,
                                    nb_rb,
670 671
                                    &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
672 673
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                    pdsch_vars[eNB_id]->log2_maxh1);
674
    //  printf("rho stream2 =%d\n",&pdsch_vars[eNB_id]->dl_ch_rho2_ext );
675
      //printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh);
Mongazon's avatar
Mongazon committed
676 677 678 679 680 681
      if (symbol == 5) {
	LOG_M("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
	LOG_M("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
	LOG_M("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
	LOG_M("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
      }
682 683 684
    } 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,
685 686 687 688 689
                                      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,
690
                                      frame_parms,
691
                                      measurements,
692 693
                                      eNB_id,
                                      symbol,
694
                                      dlsch0_harq->Qm,
695
                                      nb_rb,
696
                                      pdsch_vars[eNB_id]->log2_maxh,
697
                                      dlsch0_harq->dl_power_off);
698

699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
        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
714
       //  if (rb==0)
715
        //    printf("pmi %d, pmi_i %d\n",pdsch_vars[eNB_id]->pmi_ext[rb],pdsch_vars[eNB_id_i]->pmi_ext[rb]);
716
      }
717 718 719 720 721 722
      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,
723
                                      frame_parms,
724
                                      measurements,
725 726 727 728
                                      eNB_id_i,
                                      symbol,
                                      i_mod,
                                      nb_rb,
729
                                      pdsch_vars[eNB_id]->log2_maxh,
730
                                      dlsch0_harq->dl_power_off);
731
      if (symbol==5) {
Mongazon's avatar
Mongazon committed
732 733
        LOG_M("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);
	LOG_M("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);
734
      }
Mongazon's avatar
Mongazon committed
735

736 737 738
      dlsch_dual_stream_correlation(frame_parms,
                                    symbol,
                                    nb_rb,
739 740
                                    pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                    pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
741
                                    pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
742
                                    pdsch_vars[eNB_id]->log2_maxh);
743
    }  else if (dlsch0_harq->dl_power_off==1)  {
744 745 746 747 748 749
      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,
750
                                      frame_parms,
751
                                      measurements,
752 753
                                      eNB_id,
                                      symbol,
754
                                      dlsch0_harq->Qm,
755
                                      nb_rb,
756
                                      pdsch_vars[eNB_id]->log2_maxh,
757
                                      1);
758

759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
      }


    } 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
778 779
  }

780
#if UE_TIMING_TRACE
781
    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
782
#if DISABLE_LOG_X
783
    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));
784
#else
Thomas Laurent's avatar
Thomas Laurent committed
785
    LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d log2_maxh %d Channel Comp  %5.2f \n",frame,subframe,slot,symbol,pdsch_vars[eNB_id]->log2_maxh,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
786 787
#endif
#endif
788
// MRC
789
#if UE_TIMING_TRACE
790
    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
791
#endif
792 793

   if (frame_parms->nb_antennas_rx > 1) {
794
    if ((dlsch0_harq->mimo_mode == LARGE_CDD) ||
795
        ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
796
         (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){  // TM3 or TM4
Xiwen JIANG's avatar
Xiwen JIANG committed
797
      if (frame_parms->nb_antenna_ports_eNB == 2) {
798
        dlsch_detection_mrc_TM34(frame_parms,
799
                                 pdsch_vars[eNB_id],
800
                                 harq_pid,
801
                                 dlsch0_harq->round,
802 803 804
                                 symbol,
                                 nb_rb,
                                 1);
Mongazon's avatar
Mongazon committed
805 806 807 808
	if (symbol == 5) {
	  LOG_M("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
	  LOG_M("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
        }
809
      }
810
    } else {
811
      dlsch_detection_mrc(frame_parms,
812 813 814
                          pdsch_vars[eNB_id]->rxdataF_comp0,
                          pdsch_vars[eNB_id_i]->rxdataF_comp0,
                          pdsch_vars[eNB_id]->rho,
815
                          pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
816 817 818 819
                          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,
820 821
                          symbol,
                          nb_rb,
822
                          rx_type==rx_IC_single_stream);
823 824 825 826 827
    }
  }
  //  printf("Combining");
  if ((dlsch0_harq->mimo_mode == SISO) ||
      ((dlsch0_harq->mimo_mode >= UNIFORM_PRECODING11) &&
828 829
       (dlsch0_harq->mimo_mode <= PUSCH_PRECODING0)) ||
       (dlsch0_harq->mimo_mode == TM7)) {
830 831
    /*
      dlsch_siso(frame_parms,
832 833
      pdsch_vars[eNB_id]->rxdataF_comp,
      pdsch_vars[eNB_id_i]->rxdataF_comp,
834 835 836 837 838
      symbol,
      nb_rb);
    */
  } else if (dlsch0_harq->mimo_mode == ALAMOUTI) {
    dlsch_alamouti(frame_parms,
839 840 841
                   pdsch_vars[eNB_id]->rxdataF_comp0,
                   pdsch_vars[eNB_id]->dl_ch_mag0,
                   pdsch_vars[eNB_id]->dl_ch_magb0,
842 843
                   symbol,
                   nb_rb);
844
  }
845

846
  //    printf("LLR");
847 848
  if ((dlsch0_harq->mimo_mode == LARGE_CDD) ||
      ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) &&
849
       (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING)))  {
850
    rxdataF_comp_ptr = pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round];
851
    dl_ch_mag_ptr = pdsch_vars[eNB_id]->dl_ch_mag1[harq_pid][round];
852 853
  }
  else {
854 855
    rxdataF_comp_ptr = pdsch_vars[eNB_id_i]->rxdataF_comp0;
    dl_ch_mag_ptr = pdsch_vars[eNB_id_i]->dl_ch_mag0;
856
    //i_mod should have been passed as a parameter
857
  }
858

859
#if UE_TIMING_TRACE
860
    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
861
#if DISABLE_LOG_X
862
    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));
863
#else
864
    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));
865 866 867 868
#endif
#endif

#if UE_TIMING_TRACE
869
    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
870
#endif
Gabriel's avatar
Gabriel committed
871
  //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);
872 873 874 875 876 877 878 879 880 881
  // 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
882
  /*
883
  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",
884
             frame, subframe,symbol,
885 886 887 888
             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],
889
             pllr_symbol_cw0);
knopp's avatar
knopp committed
890
  */
891
  switch (dlsch0_harq->Qm) {
892
  case 2 :
893
    if ((rx_type==rx_standard) || (codeword_TB1 == -1)) {
894 895


896
        dlsch_qpsk_llr(frame_parms,
897
                       pdsch_vars[eNB_id]->rxdataF_comp0,
898
                       (int16_t*)pllr_symbol_cw0,
899 900 901
                       symbol,
                       first_symbol_flag,
                       nb_rb,
902
                       adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
903
                       beamforming_mode);
904 905 906 907 908

    } else if (codeword_TB0 == -1){

        dlsch_qpsk_llr(frame_parms,
                       pdsch_vars[eNB_id]->rxdataF_comp0,
fnabet's avatar
fnabet committed
909
                       (int16_t*)pllr_symbol_cw1,
910 911 912
                       symbol,
                       first_symbol_flag,
                       nb_rb,
913
                       adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
914
                       beamforming_mode);
915
    }
916
      else if (rx_type >= rx_IC_single_stream) {
Elena Lukashova's avatar
Elena Lukashova committed
917
        if (dlsch1_harq->Qm == 2) {
918
          dlsch_qpsk_qpsk_llr(frame_parms,
919
                              pdsch_vars[eNB_id]->rxdataF_comp0,
920
                              rxdataF_comp_ptr,
921 922
                              pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                              pdsch_vars[eNB_id]->llr[0],
923
                              symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
924
                              adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
925
                              pdsch_vars[eNB_id]->llr128);
926 927 928
          if (rx_type==rx_IC_dual_stream) {
            dlsch_qpsk_qpsk_llr(frame_parms,
                                rxdataF_comp_ptr,
929 930 931
                                pdsch_vars[eNB_id]->rxdataF_comp0,
                                pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                pdsch_vars[eNB_id]->llr[1],
932
                                symbol,first_symbol_flag,nb_rb,
933
                                adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol),
934
                                pdsch_vars[eNB_id]->llr128_2ndstream);
935 936
          }
        }
937
        else if (dlsch1_harq->Qm == 4) {
938
          dlsch_qpsk_16qam_llr(frame_parms,
939
                               pdsch_vars[eNB_id]->rxdataF_comp0,
940 941
                               rxdataF_comp_ptr,//i
                               dl_ch_mag_ptr,//i
942 943
                               pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                               pdsch_vars[eNB_id]->llr[0],
944
                               symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
945
                               adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
946
                               pdsch_vars[eNB_id]->llr128);
947 948 949
          if (rx_type==rx_IC_dual_stream) {
            dlsch_16qam_qpsk_llr(frame_parms,
                                 rxdataF_comp_ptr,
950
                                 pdsch_vars[eNB_id]->rxdataF_comp0,//i
951
                                 dl_ch_mag_ptr,
952 953
                                 pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                 pdsch_vars[eNB_id]->llr[1],
954
                                 symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
955
                                 adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol),
956
                                 pdsch_vars[eNB_id]->llr128_2ndstream);
957 958 959 960
          }
        }
        else {
          dlsch_qpsk_64qam_llr(frame_parms,
961
                               pdsch_vars[eNB_id]->rxdataF_comp0,
962 963
                               rxdataF_comp_ptr,//i
                               dl_ch_mag_ptr,//i
964 965
                               pdsch_vars[eNB_id]->dl_ch_rho2_ext,
                               pdsch_vars[eNB_id]->llr[0],
966
                               symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
967
                               adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
968
                               pdsch_vars[eNB_id]->llr128);
969 970 971
          if (rx_type==rx_IC_dual_stream) {
            dlsch_64qam_qpsk_llr(frame_parms,
                                 rxdataF_comp_ptr,
972
                                 pdsch_vars[eNB_id]->rxdataF_comp0,//i
973
                                 dl_ch_mag_ptr,
974 975
                                 pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
                                 pdsch_vars[eNB_id]->llr[1],
976
                                 symbol,first_symbol_flag,nb_rb,
Elena Lukashova's avatar