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

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"
Wang Tsu-Han's avatar
Wang Tsu-Han committed
39 40 41 42 43 44 45 46
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <string.h>
#include <lapacke_utils.h>
#include <lapacke.h>
#include <cblas.h>
#include "linear_preprocessing_rec.h"
47

48
#define NOCYGWIN_STATIC
Wang Tsu-Han's avatar
Wang Tsu-Han committed
49 50
//#define DEBUG_MMSE

51

52 53 54 55 56
/* 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
57
int16_t interf_unaw_shift = 13;
58

59 60
//#define DEBUG_HARQ

knopp's avatar
knopp committed
61
//#define DEBUG_PHY 1
62
//#define DEBUG_DLSCH_DEMOD 1
63

knopp's avatar
knopp committed
64
//#define DISABLE_LOG_X
65 66

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

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

90

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

93

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

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

Bilel's avatar
Bilel committed
113 114 115
  int avg[4];
  int avg_0[2];
  int avg_1[2];
Wang Tsu-Han's avatar
Wang Tsu-Han committed
116
  unsigned short mmse_flag=0;
Elena Lukashova's avatar
Elena Lukashova committed
117

118
#if UE_TIMING_TRACE
119
  uint8_t slot = 0;
120
#endif
121

122
  unsigned char aatx,aarx;
123

124
  unsigned short nb_rb = 0, round;
125
  int avgs = 0, rb;
126
  LTE_DL_UE_HARQ_t *dlsch0_harq,*dlsch1_harq = 0;
Elena Lukashova's avatar
Elena Lukashova committed
127

128
  uint8_t beamforming_mode;
129
  uint32_t *rballoc;
130

131 132
  int32_t **rxdataF_comp_ptr;
  int32_t **dl_ch_mag_ptr;
133 134
  int32_t codeword_TB0 = -1;
  int32_t codeword_TB1 = -1;
135 136


137

138 139
  switch (type) {
  case SI_PDSCH:
140
    pdsch_vars = &ue->pdsch_vars_SI[eNB_id];
141 142
    dlsch = &ue->dlsch_SI[eNB_id];
    dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
143
    beamforming_mode  = 0;
144
    break;
145

146
  case RA_PDSCH:
147
    pdsch_vars = &ue->pdsch_vars_ra[eNB_id];
148 149
    dlsch = &ue->dlsch_ra[eNB_id];
    dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
150
    beamforming_mode  = 0;
151
    break;
152

153
  case PDSCH:
154 155
    pdsch_vars = ue->pdsch_vars[ue->current_thread_id[subframe]];
    dlsch = ue->dlsch[ue->current_thread_id[subframe]][eNB_id];
156
    //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
157 158 159 160 161
    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);

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

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

209 210
  DevAssert(dlsch0_harq);
  round = dlsch0_harq->round;
211
  //printf("round = %d\n", round);
212

213
  if (eNB_id > 2) {
jiangx's avatar
jiangx committed
214
    LOG_W(PHY,"dlsch_demodulation.c: Illegal eNB_id %d\n",eNB_id);
215 216
    return(-1);
  }
217

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

223
  if (!dlsch[0]) {
jiangx's avatar
jiangx committed
224
    LOG_W(PHY,"dlsch_demodulation.c: Null dlsch_ue pointer\n");
225 226 227
    return(-1);
  }

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

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

238 239 240 241 242
  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;
243

244

245
  if (dlsch0_harq->mimo_mode>DUALSTREAM_PUSCH_PRECODING) {
246 247 248
    LOG_E(PHY,"This transmission mode is not yet supported!\n");
    return(-1);
  }
249 250


251 252 253 254 255 256 257 258
  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);
    }
  }

259
#if UE_TIMING_TRACE
260 261 262 263
  if(symbol > ue->frame_parms.symbols_per_tti>>1)
  {
      slot = 1;
  }
264 265
#endif

266 267 268
#ifdef DEBUG_HARQ
  printf("Demod  dlsch0_harq->pmi_alloc %d\n",  dlsch0_harq->pmi_alloc);
#endif
269

Xiwen JIANG's avatar
Xiwen JIANG committed
270
  if (frame_parms->nb_antenna_ports_eNB>1 && beamforming_mode==0) {
271
#ifdef DEBUG_DLSCH_MOD
272
    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]);
273
#endif
274

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

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

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

375
  } else if(beamforming_mode>7) {
376
    LOG_W(PHY,"dlsch_demodulation: beamforming mode not supported yet.\n");
377
  }
378

Bilel's avatar
Bilel committed
379
  //printf("nb_rb = %d, eNB_id %d\n",nb_rb,eNB_id);
380
  if (nb_rb==0) {
knopp's avatar
knopp committed
381
    //    LOG_D(PHY,"dlsch_demodulation.c: nb_rb=0\n");
382 383
    return(-1);
  }
384

Elena Lukashova's avatar
Elena Lukashova committed
385

386
#if UE_TIMING_TRACE
387
    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
388 389
#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,
390
            symbol,ue->high_speed_flag,type,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
391 392
#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,
393
            ue->high_speed_flag,type,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0));
394
#endif
395 396
#endif

397

398
#if UE_TIMING_TRACE
399
    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
400
#endif
401
  aatx = frame_parms->nb_antenna_ports_eNB;
Elena Lukashova's avatar
Elena Lukashova committed
402 403
  aarx = frame_parms->nb_antennas_rx;

404
  dlsch_scale_channel(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
405 406 407 408
                      frame_parms,
                      dlsch,
                      symbol,
                      nb_rb);
409

410 411 412 413 414 415
  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
  {
416
    dlsch_scale_channel(pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
417
                        frame_parms,
418
                        dlsch,
419 420
                        symbol,
                        nb_rb);
421
  }
422

423
#if UE_TIMING_TRACE
424
    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
425
#if DISABLE_LOG_X
426
    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));
427
#else
428
    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));
429 430 431 432
#endif
#endif

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

        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)))
     {
Wang Tsu-Han's avatar
Wang Tsu-Han committed
454 455 456 457 458 459 460 461 462
       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);
463

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

491 492
        }
        else if (dlsch0_harq->dl_power_off==1) { //TM6
493

494 495 496 497 498
          dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
                                   frame_parms,
                                   avg,
                                   symbol,
                                   nb_rb);
499

500 501 502 503
          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]);
504

505 506
          pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2) + 1;
          pdsch_vars[eNB_id]->log2_maxh++;
507

508
        }
509
      }
510

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

    //wait until pdcch is decoded
tct-labo4's avatar
tct-labo4 committed
528
    //proc->channel_level = 1;
529
  }
530

tct-labo4's avatar
tct-labo4 committed
531
  /*
532 533 534 535 536
  uint32_t wait = 0;
  while(proc->channel_level == 0)
  {
      usleep(1);
      wait++;
537
  }
tct-labo4's avatar
tct-labo4 committed
538
  */
539

540 541 542
#if T_TRACER
    if (type == PDSCH)
    {
Cedric Roux's avatar
Cedric Roux committed
543 544
      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]));
545 546
    }
#endif
547

548
#if UE_TIMING_TRACE
549
    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
550
#if DISABLE_LOG_X
551
    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));
552
#else
553
    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));
554 555 556 557 558
#endif
#endif


#if UE_TIMING_TRACE
559
    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
560
#endif
Wang Tsu-Han's avatar
Wang Tsu-Han committed
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581

  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);
  }

582 583
// Now channel compensation
  if (dlsch0_harq->mimo_mode<LARGE_CDD) {
584 585 586 587 588 589
    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,
590 591 592
                               frame_parms,
                               symbol,
                               first_symbol_flag,
593
                               dlsch0_harq->Qm,
594
                               nb_rb,
595
                               pdsch_vars[eNB_id]->log2_maxh,
596
                               measurements); // log2_maxh+I0_shift
Wang Tsu-Han's avatar
Wang Tsu-Han committed
597 598 599 600
    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);
    }

601
    if ((rx_type==rx_IC_single_stream) &&
602
        (eNB_id_i<ue->n_connected_eNB)) {
603
         dlsch_channel_compensation(pdsch_vars[eNB_id_i]->rxdataF_ext,
604 605 606 607 608
                                 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,
609 610 611 612 613
                                 frame_parms,
                                 symbol,
                                 first_symbol_flag,
                                 i_mod,
                                 nb_rb,
614
                                 pdsch_vars[eNB_id]->log2_maxh,
615
                                 measurements); // log2_maxh+I0_shift
616
      if (symbol == 5) {
Wang Tsu-Han's avatar
Wang Tsu-Han committed
617 618
        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);
619
      }
620

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

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

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

753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
      }


    } 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
772 773
  }

774
#if UE_TIMING_TRACE
775
    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
776
#if DISABLE_LOG_X
777
    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));
778
#else
779
    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));
780 781
#endif
#endif
782
// MRC
783
#if UE_TIMING_TRACE
784
    start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
785
#endif
786 787

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

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

853
#if UE_TIMING_TRACE
854
    stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
855
#if DISABLE_LOG_X
856
    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));
857
#else
858
    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));
859 860 861 862
#endif
#endif

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


890
        dlsch_qpsk_llr(frame_parms,
891
                       pdsch_vars[eNB_id]->rxdataF_comp0,
892
                       (int16_t*)pllr_symbol_cw0,
893 894 895
                       symbol,
                       first_symbol_flag,
                       nb_rb,
896
                       adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol),
897
                       beamforming_mode);
898 899 900 901 902

    } else if (codeword_TB0 == -1){

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