nr_dl_channel_estimation.c 34.1 KB
Newer Older
Hongzhi Wang's avatar
Hongzhi Wang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

Raymond Knopp's avatar
Raymond Knopp committed
22

Hongzhi Wang's avatar
Hongzhi Wang committed
23
#include <string.h>
Hongzhi Wang's avatar
Hongzhi Wang committed
24
#include "SCHED_NR_UE/defs.h"
25
#include "nr_estimation.h"
Raymond Knopp's avatar
Raymond Knopp committed
26
#include "PHY/NR_REFSIG/refsig_defs_ue.h"
Hongzhi Wang's avatar
Hongzhi Wang committed
27
#include "filt16a_32.h"
28

hongzhi wang's avatar
hongzhi wang committed
29
//#define DEBUG_PDSCH
Guy De Souza's avatar
Guy De Souza committed
30
//#define DEBUG_PDCCH
Hongzhi Wang's avatar
Hongzhi Wang committed
31

Raymond Knopp's avatar
Raymond Knopp committed
32

33
int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue,
yilmazt's avatar
yilmazt committed
34 35 36 37 38
                             uint8_t eNB_offset,
                             unsigned char Ns,
                             unsigned char symbol,
                             int dmrss,
                             NR_UE_SSB *current_ssb)
39 40 41 42 43 44 45
{
  int pilot[200] __attribute__((aligned(16)));
  unsigned char aarx;
  unsigned short k;
  unsigned int pilot_cnt;
  int16_t ch[2],*pil,*rxF;
  int symbol_offset;
46

47 48 49 50

  uint8_t nushift;
  uint8_t ssb_index=current_ssb->i_ssb;
  uint8_t n_hf=current_ssb->n_hf;
51
  int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF;
52 53 54 55 56 57

  nushift =  ue->frame_parms.Nid_cell%4;
  ue->frame_parms.nushift = nushift;
  unsigned int  ssb_offset = ue->frame_parms.first_carrier_offset + ue->frame_parms.ssb_start_subcarrier;
  if (ssb_offset>= ue->frame_parms.ofdm_symbol_size) ssb_offset-=ue->frame_parms.ofdm_symbol_size;

58 59 60
  AssertFatal(dmrss >= 0 && dmrss < 3,
	      "symbol %d is illegal for PBCH DM-RS \n",
	      dmrss);
61 62 63 64 65 66 67

  symbol_offset = ue->frame_parms.ofdm_symbol_size*symbol;


  k = nushift;

#ifdef DEBUG_CH
68
  printf("PBCH DMRS Correlation : ThreadId %d, eNB_offset %d , OFDM size %d, Ncp=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns], eNB_offset,ue->frame_parms.ofdm_symbol_size,
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
         ue->frame_parms.Ncp,Ns,k, symbol);
#endif

  // generate pilot
  nr_pbch_dmrs_rx(dmrss,ue->nr_gold_pbch[n_hf][ssb_index], &pilot[0]);

  int re_offset = ssb_offset;
  for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++) {

    pil   = (int16_t *)&pilot[0];
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];

#ifdef DEBUG_CH
    printf("pbch ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL);
    printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset);
    printf("rxF addr %p\n", rxF);
#endif
    //if ((ue->frame_parms.N_RB_DL&1)==0) {

    // Treat first 2 pilots specially (left edge)
    ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
    ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);

    current_ssb->c_re +=ch[0];
    current_ssb->c_im +=ch[1];

#ifdef DEBUG_CH
    printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1]));
    printf("pilot 0 : rxF - > (%d,%d) addr %p  ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]);
#endif

    pil+=2;
101 102
    //re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
    re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 4) : (re_offset+4);
103 104 105 106 107 108 109 110 111 112 113 114 115 116
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];


    ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
    ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);

    current_ssb->c_re +=ch[0];
    current_ssb->c_im +=ch[1];

#ifdef DEBUG_CH
    printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif

    pil+=2;
117 118
    //re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
    re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 4) : (re_offset+4);
119 120 121 122 123 124 125 126 127 128
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];

    current_ssb->c_re +=ch[0];
    current_ssb->c_im +=ch[1];

#ifdef DEBUG_CH
    printf("pilot 2 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif

    pil+=2;
129 130
    //re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
    re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 4) : (re_offset+4);
131 132 133 134 135 136 137 138 139 140
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];

    for (pilot_cnt=3; pilot_cnt<(3*20); pilot_cnt+=3) {

      //	if (pilot_cnt == 30)
      //	  rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k)];

      // in 2nd symbol, skip middle  REs (48 with DMRS,  144 for SSS, and another 48 with DMRS) 
      if (dmrss == 1 && pilot_cnt == 12) {
	pilot_cnt=48;
141 142
	//re_offset = (re_offset+144)&(ue->frame_parms.ofdm_symbol_size-1);
        re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 144) : (re_offset+144);
143 144 145 146 147 148 149 150 151
	rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
      }
      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
      
      current_ssb->c_re +=ch[0];
      current_ssb->c_im +=ch[1];

#ifdef DEBUG_CH
yilmazt's avatar
yilmazt committed
152
      printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
153 154 155
#endif

      pil+=2;
156 157
      //re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
      re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 4) : (re_offset+4);
158 159 160 161 162 163 164 165 166 167
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
        
  
      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);

      current_ssb->c_re +=ch[0];
      current_ssb->c_im +=ch[1];

#ifdef DEBUG_CH
yilmazt's avatar
yilmazt committed
168
      printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
169 170
#endif
      pil+=2;
171 172
      //re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
      re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 4) : (re_offset+4);
173 174 175 176 177 178 179 180 181 182
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
        

      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);

      current_ssb->c_re +=ch[0];
      current_ssb->c_im +=ch[1];

#ifdef DEBUG_CH
yilmazt's avatar
yilmazt committed
183
      printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+2,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
184 185 186
#endif

      pil+=2;
187 188
      //re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
      re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 4) : (re_offset+4);
189 190 191 192 193 194 195 196 197 198 199
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];

    }


    //}

  }
  return(0);
}

Francesco Mani's avatar
Francesco Mani committed
200

Hongzhi Wang's avatar
Hongzhi Wang committed
201
int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
Hongzhi Wang's avatar
Hongzhi Wang committed
202 203 204 205 206 207
			       uint8_t eNB_offset,
			       unsigned char Ns,
			       unsigned char symbol,
			       int dmrss,
			       uint8_t ssb_index,
			       uint8_t n_hf)
Hongzhi Wang's avatar
Hongzhi Wang committed
208
{
Raymond Knopp's avatar
Raymond Knopp committed
209
  int pilot[200] __attribute__((aligned(16)));
Hongzhi Wang's avatar
Hongzhi Wang committed
210
  unsigned char aarx,p;
Hongzhi Wang's avatar
Hongzhi Wang committed
211
  unsigned short k;
hongzhi wang's avatar
hongzhi wang committed
212
  unsigned int pilot_cnt;
hongzhi wang's avatar
hongzhi wang committed
213
  int16_t ch[2],*pil,*rxF,*dl_ch,*fl,*fm,*fr;
Hongzhi Wang's avatar
Hongzhi Wang committed
214
  int ch_offset,symbol_offset;
Hongzhi Wang's avatar
Hongzhi Wang committed
215 216 217 218
  int slot_pbch;
  fapi_nr_pbch_config_t *pbch_config = &ue->nrUE_config.pbch_config;
  // initialized to 5ms in nr_init_ue for scenarios where UE is not configured (otherwise acquired by cell configuration from gNB or LTE)
  uint8_t ssb_periodicity = 10;// ue->ssb_periodicity;
Hongzhi Wang's avatar
Hongzhi Wang committed
219

hongzhi wang's avatar
hongzhi wang committed
220
  //uint16_t Nid_cell = (eNB_offset == 0) ? ue->frame_parms.Nid_cell : ue->measurements.adj_cell_id[eNB_offset-1];
Hongzhi Wang's avatar
Hongzhi Wang committed
221

Francesco Mani's avatar
Francesco Mani committed
222
  uint8_t nushift;
223
  int **dl_ch_estimates  =ue->pbch_vars[eNB_offset]->dl_ch_estimates;
224
  int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF;
Hongzhi Wang's avatar
Hongzhi Wang committed
225

hongzhi wang's avatar
hongzhi wang committed
226
  nushift =  ue->frame_parms.Nid_cell%4;
hongzhi wang's avatar
hongzhi wang committed
227
  ue->frame_parms.nushift = nushift;
Raymond Knopp's avatar
Raymond Knopp committed
228 229 230
  unsigned int  ssb_offset = ue->frame_parms.first_carrier_offset + ue->frame_parms.ssb_start_subcarrier;
  if (ssb_offset>= ue->frame_parms.ofdm_symbol_size) ssb_offset-=ue->frame_parms.ofdm_symbol_size;

Hongzhi Wang's avatar
Hongzhi Wang committed
231 232 233 234 235
  if (ue->high_speed_flag == 0) // use second channel estimate position for temporary storage
    ch_offset     = ue->frame_parms.ofdm_symbol_size ;
  else
    ch_offset     = ue->frame_parms.ofdm_symbol_size*symbol;

236 237 238
  AssertFatal(dmrss >= 0 && dmrss < 3,
	      "symbol %d is illegal for PBCH DM-RS \n",
	      dmrss);
Raymond Knopp's avatar
Raymond Knopp committed
239

Hongzhi Wang's avatar
Hongzhi Wang committed
240 241
  symbol_offset = ue->frame_parms.ofdm_symbol_size*symbol;

Raymond Knopp's avatar
Raymond Knopp committed
242

Hongzhi Wang's avatar
Hongzhi Wang committed
243 244 245
  k = nushift;

#ifdef DEBUG_CH
Francesco Mani's avatar
Francesco Mani committed
246
  printf("PBCH Channel Estimation : ThreadId %d, eNB_offset %d ch_offset %d, OFDM size %d, Ncp=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns], eNB_offset,ch_offset,ue->frame_parms.ofdm_symbol_size,
247
         ue->frame_parms.Ncp,Ns,k, symbol);
Hongzhi Wang's avatar
Hongzhi Wang committed
248 249 250 251
#endif

  switch (k) {
  case 0:
Raymond Knopp's avatar
Raymond Knopp committed
252 253 254 255
    fl = filt16a_l0;
    fm = filt16a_m0;
    fr = filt16a_r0;
    break;
Hongzhi Wang's avatar
Hongzhi Wang committed
256 257

  case 1:
Raymond Knopp's avatar
Raymond Knopp committed
258 259 260 261
    fl = filt16a_l1;
    fm = filt16a_m1;
    fr = filt16a_r1;
    break;
Hongzhi Wang's avatar
Hongzhi Wang committed
262 263

  case 2:
Raymond Knopp's avatar
Raymond Knopp committed
264 265 266 267
    fl = filt16a_l2;
    fm = filt16a_m2;
    fr = filt16a_r2;
    break;
Hongzhi Wang's avatar
Hongzhi Wang committed
268 269

  case 3:
Raymond Knopp's avatar
Raymond Knopp committed
270 271 272 273
    fl = filt16a_l3;
    fm = filt16a_m3;
    fr = filt16a_r3;
    break;
Hongzhi Wang's avatar
Hongzhi Wang committed
274 275 276 277 278 279 280 281

  default:
    msg("pbch_channel_estimation: k=%d -> ERROR\n",k);
    return(-1);
    break;
  }

  // generate pilot
Raymond Knopp's avatar
Raymond Knopp committed
282
  nr_pbch_dmrs_rx(dmrss,ue->nr_gold_pbch[n_hf][ssb_index], &pilot[0]);
Hongzhi Wang's avatar
Hongzhi Wang committed
283

Raymond Knopp's avatar
Raymond Knopp committed
284
  int re_offset = ssb_offset;
Hongzhi Wang's avatar
Hongzhi Wang committed
285 286
  for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++) {

Raymond Knopp's avatar
Raymond Knopp committed
287 288 289
    pil   = (int16_t *)&pilot[0];
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
    dl_ch = (int16_t *)&dl_ch_estimates[aarx][ch_offset];
Francesco Mani's avatar
Francesco Mani committed
290

Hongzhi Wang's avatar
Hongzhi Wang committed
291 292 293 294 295
    memset(dl_ch,0,4*(ue->frame_parms.ofdm_symbol_size));
    if (ue->high_speed_flag==0) // multiply previous channel estimate by ch_est_alpha
      multadd_complex_vector_real_scalar(dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                         ue->ch_est_alpha,dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                         1,ue->frame_parms.ofdm_symbol_size);
296
#ifdef DEBUG_CH
Raymond Knopp's avatar
Raymond Knopp committed
297
    printf("pbch ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL);
Hongzhi Wang's avatar
Hongzhi Wang committed
298
    printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset);
hongzhi wang's avatar
hongzhi wang committed
299 300
    printf("rxF addr %p\n", rxF);
    printf("dl_ch addr %p\n",dl_ch);
301
#endif
hongzhi wang's avatar
hongzhi wang committed
302
    //if ((ue->frame_parms.N_RB_DL&1)==0) {
Hongzhi Wang's avatar
Hongzhi Wang committed
303

Raymond Knopp's avatar
Raymond Knopp committed
304 305 306
    // Treat first 2 pilots specially (left edge)
    ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
    ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
Francesco Mani's avatar
Francesco Mani committed
307

Raymond Knopp's avatar
Raymond Knopp committed
308 309 310 311 312 313 314 315 316
#ifdef DEBUG_CH
    printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1]));
    printf("pilot 0 : rxF - > (%d,%d) addr %p  ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]);
#endif
    multadd_real_vector_complex_scalar(fl,
				       ch,
				       dl_ch,
				       16);
    pil+=2;
317 318
    //re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
    re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 4) : (re_offset+4);
Raymond Knopp's avatar
Raymond Knopp committed
319 320 321 322 323 324 325
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];

    //for (int i= 0; i<8; i++)
    //printf("dl_ch addr %p %d\n", dl_ch+i, *(dl_ch+i));

    ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
    ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
Francesco Mani's avatar
Francesco Mani committed
326 327


Raymond Knopp's avatar
Raymond Knopp committed
328 329 330 331 332 333 334 335
#ifdef DEBUG_CH
    printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif
    multadd_real_vector_complex_scalar(fm,
				       ch,
				       dl_ch,
				       16);
    pil+=2;
336 337
    //re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
    re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 4) : (re_offset+4);
Raymond Knopp's avatar
Raymond Knopp committed
338 339
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];

340 341 342
    ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
    ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);

Raymond Knopp's avatar
Raymond Knopp committed
343 344 345 346 347 348 349 350 351
#ifdef DEBUG_CH
    printf("pilot 2 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif

    multadd_real_vector_complex_scalar(fr,
				       ch,
				       dl_ch,
				       16);
    pil+=2;
352 353
    //re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
    re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 4) : (re_offset+4);
Raymond Knopp's avatar
Raymond Knopp committed
354 355 356 357 358 359 360 361 362 363 364
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
    dl_ch+=24;

    for (pilot_cnt=3; pilot_cnt<(3*20); pilot_cnt+=3) {

      //	if (pilot_cnt == 30)
      //	  rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k)];

      // in 2nd symbol, skip middle  REs (48 with DMRS,  144 for SSS, and another 48 with DMRS) 
      if (dmrss == 1 && pilot_cnt == 12) {
	pilot_cnt=48;
365 366
	//re_offset = (re_offset+144)&(ue->frame_parms.ofdm_symbol_size-1);
        re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 144) : (re_offset+144);
Raymond Knopp's avatar
Raymond Knopp committed
367 368 369
	rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
	dl_ch += 288;
      }
Hongzhi Wang's avatar
Hongzhi Wang committed
370 371
      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
Francesco Mani's avatar
Francesco Mani committed
372

373
#ifdef DEBUG_CH
yilmazt's avatar
yilmazt committed
374
      printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
375
#endif
Hongzhi Wang's avatar
Hongzhi Wang committed
376
      multadd_real_vector_complex_scalar(fl,
Raymond Knopp's avatar
Raymond Knopp committed
377 378 379 380
					 ch,
					 dl_ch,
					 16);

hongzhi wang's avatar
hongzhi wang committed
381
      //for (int i= 0; i<8; i++)
Raymond Knopp's avatar
Raymond Knopp committed
382
      //            printf("pilot_cnt %d dl_ch %d %d\n", pilot_cnt, dl_ch+i, *(dl_ch+i));
Hongzhi Wang's avatar
Hongzhi Wang committed
383

Raymond Knopp's avatar
Raymond Knopp committed
384
      pil+=2;
385 386
      //re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
      re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 4) : (re_offset+4);
Raymond Knopp's avatar
Raymond Knopp committed
387 388 389
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
        
  
Hongzhi Wang's avatar
Hongzhi Wang committed
390 391
      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
Francesco Mani's avatar
Francesco Mani committed
392

Hongzhi Wang's avatar
Hongzhi Wang committed
393
#ifdef DEBUG_CH
yilmazt's avatar
yilmazt committed
394
      printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
Hongzhi Wang's avatar
Hongzhi Wang committed
395 396
#endif
      multadd_real_vector_complex_scalar(fm,
Raymond Knopp's avatar
Raymond Knopp committed
397 398 399
					 ch,
					 dl_ch,
					 16);
Hongzhi Wang's avatar
Hongzhi Wang committed
400
      pil+=2;
401 402
      //re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
      re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 4) : (re_offset+4);
Raymond Knopp's avatar
Raymond Knopp committed
403 404
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
        
Hongzhi Wang's avatar
Hongzhi Wang committed
405 406 407 408

      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);

hongzhi wang's avatar
hongzhi wang committed
409
#ifdef DEBUG_CH
yilmazt's avatar
yilmazt committed
410
      printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+2,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
hongzhi wang's avatar
hongzhi wang committed
411
#endif
Hongzhi Wang's avatar
Hongzhi Wang committed
412 413

      multadd_real_vector_complex_scalar(fr,
Raymond Knopp's avatar
Raymond Knopp committed
414 415 416
					 ch,
					 dl_ch,
					 16);
Hongzhi Wang's avatar
Hongzhi Wang committed
417
      pil+=2;
418 419
      //re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1);
      re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 4) : (re_offset+4);
Raymond Knopp's avatar
Raymond Knopp committed
420
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
hongzhi wang's avatar
hongzhi wang committed
421
      dl_ch+=24;
Hongzhi Wang's avatar
Hongzhi Wang committed
422

Raymond Knopp's avatar
Raymond Knopp committed
423
    }
Hongzhi Wang's avatar
Hongzhi Wang committed
424

Hongzhi Wang's avatar
Hongzhi Wang committed
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
    void (*idft)(int16_t *,int16_t *, int);

    switch (ue->frame_parms.ofdm_symbol_size) {
    case 128:
      idft = idft128;
      break;

    case 256:
      idft = idft256;
      break;

    case 512:
      idft = idft512;
      break;

    case 1024:
      idft = idft1024;
      break;

    case 1536:
      idft = idft1536;
      break;

    case 2048:
      idft = idft2048;
      break;

    case 3072:
      idft = idft3072;
      break;

    case 4096:
      idft = idft4096;
      break;

    default:
      printf("unsupported ofdm symbol size \n");
      assert(0);
    }

Hongzhi Wang's avatar
Hongzhi Wang committed
465
    if( symbol == 3)
Hongzhi Wang's avatar
Hongzhi Wang committed
466 467 468 469 470 471
    {
        // do ifft of channel estimate
        for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++)
            for (p=0; p<ue->frame_parms.nb_antenna_ports_eNB; p++) {
                if (ue->pbch_vars[eNB_offset]->dl_ch_estimates[(p<<1)+aarx])
                {
Hongzhi Wang's avatar
Hongzhi Wang committed
472 473
  		LOG_D(PHY,"Channel Impulse Computation Slot %d ThreadId %d Symbol %d ch_offset %d\n", Ns, ue->current_thread_id[Ns], symbol, ch_offset);
  		idft((int16_t*) &ue->pbch_vars[eNB_offset]->dl_ch_estimates[(p<<1)+aarx][ch_offset],
Hongzhi Wang's avatar
Hongzhi Wang committed
474 475 476 477
  		     (int16_t*) ue->pbch_vars[eNB_offset]->dl_ch_estimates_time[(p<<1)+aarx],1);
                }
            }
    }
Hongzhi Wang's avatar
Hongzhi Wang committed
478

hongzhi wang's avatar
hongzhi wang committed
479
    //}
Hongzhi Wang's avatar
Hongzhi Wang committed
480 481 482 483 484

  }
  return(0);
}

485
int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue,
yilmazt's avatar
yilmazt committed
486 487 488 489 490
                                uint8_t eNB_offset,
                                unsigned char Ns,
                                unsigned char symbol,
                                unsigned short coreset_start_subcarrier,
                                unsigned short nb_rb_coreset)
491
{
Raymond Knopp's avatar
Raymond Knopp committed
492
  int pilot[200] __attribute__((aligned(16)));
Hongzhi Wang's avatar
Hongzhi Wang committed
493
  unsigned char aarx;
494 495 496 497 498 499 500 501
  unsigned short k;
  unsigned int pilot_cnt;
  int16_t ch[2],*pil,*rxF,*dl_ch,*fl,*fm,*fr;
  int ch_offset,symbol_offset;

  //uint16_t Nid_cell = (eNB_offset == 0) ? ue->frame_parms.Nid_cell : ue->measurements.adj_cell_id[eNB_offset-1];

  uint8_t nushift;
502
  int **dl_ch_estimates  =ue->pdcch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates;
503
  int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF;
504 505 506 507 508 509 510 511 512 513 514

  nushift = 1;
  ue->frame_parms.nushift = nushift;

  if (ue->high_speed_flag == 0) // use second channel estimate position for temporary storage
    ch_offset     = ue->frame_parms.ofdm_symbol_size ;
  else
    ch_offset     = ue->frame_parms.ofdm_symbol_size*symbol;

  symbol_offset = ue->frame_parms.ofdm_symbol_size*symbol;

515
  k = coreset_start_subcarrier;
516

hongzhi wang's avatar
hongzhi wang committed
517
#ifdef DEBUG_PDCCH
518 519
  printf("PDCCH Channel Estimation : ThreadId %d, eNB_offset %d ch_offset %d, OFDM size %d, Ncp=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns], eNB_offset,ch_offset,ue->frame_parms.ofdm_symbol_size,
         ue->frame_parms.Ncp,Ns,k, symbol);
520 521 522 523 524 525
#endif

  fl = filt16a_l1;
  fm = filt16a_m1;
  fr = filt16a_r1;

526

527
  // generate pilot 
Florian Kaltenberger's avatar
Florian Kaltenberger committed
528
  nr_pdcch_dmrs_rx(ue,eNB_offset,Ns,ue->nr_gold_pdcch[eNB_offset][Ns][symbol], &pilot[0],2000,nb_rb_coreset);
529 530 531 532


  for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++) {

Raymond Knopp's avatar
Raymond Knopp committed
533
    pil   = (int16_t *)&pilot[0];
534
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+nushift)];
Raymond Knopp's avatar
Raymond Knopp committed
535
    dl_ch = (int16_t *)&dl_ch_estimates[aarx][ch_offset];
536 537 538 539 540 541

    memset(dl_ch,0,4*(ue->frame_parms.ofdm_symbol_size));
    if (ue->high_speed_flag==0) // multiply previous channel estimate by ch_est_alpha
      multadd_complex_vector_real_scalar(dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                         ue->ch_est_alpha,dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                         1,ue->frame_parms.ofdm_symbol_size);
hongzhi wang's avatar
hongzhi wang committed
542
#ifdef DEBUG_PDCCH
Raymond Knopp's avatar
Raymond Knopp committed
543
    printf("pdcch ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL);
544 545 546 547
    printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset);
    printf("rxF addr %p\n", rxF);

    printf("dl_ch addr %p\n",dl_ch);
548
#endif
549
    //    if ((ue->frame_parms.N_RB_DL&1)==0) {
550 551 552
      // Treat first 2 pilots specially (left edge)
      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
553
#ifdef DEBUG_PDCCH
554 555 556 557 558 559 560 561 562 563 564 565 566 567
      printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1]));
      printf("pilot 0 : rxF - > (%d,%d) addr %p  ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]);
#endif
      multadd_real_vector_complex_scalar(fl,
                                         ch,
                                         dl_ch,
                                         16);
      pil+=2;
      rxF+=8;
      //for (int i= 0; i<8; i++)
      //printf("dl_ch addr %p %d\n", dl_ch+i, *(dl_ch+i));

      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
568
#ifdef DEBUG_PDCCH
569 570 571 572 573 574 575 576 577 578 579 580
      printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif
      multadd_real_vector_complex_scalar(fm,
                                         ch,
                                         dl_ch,
                                         16);
      pil+=2;
      rxF+=8;

      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);

hongzhi wang's avatar
hongzhi wang committed
581
#ifdef DEBUG_PDCCH
582 583 584 585 586 587 588
      printf("pilot 2 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif

      multadd_real_vector_complex_scalar(fr,
                                         ch,
                                         dl_ch,
                                         16);
hongzhi wang's avatar
hongzhi wang committed
589
                                         
hongzhi wang's avatar
hongzhi wang committed
590
#ifdef DEBUG_PDCCH       
hongzhi wang's avatar
hongzhi wang committed
591
      for (int m =0; m<12; m++)
Raymond Knopp's avatar
Raymond Knopp committed
592
	printf("data :  dl_ch -> (%d,%d)\n",dl_ch[0+2*m],dl_ch[1+2*m]);
hongzhi wang's avatar
hongzhi wang committed
593
#endif      
594 595 596
      pil+=2;
      rxF+=8;
      dl_ch+=24;
597
      k+=12;
hongzhi wang's avatar
hongzhi wang committed
598 599
      
      
600

601
      for (pilot_cnt=3; pilot_cnt<(3*nb_rb_coreset); pilot_cnt+=3) {
602

603
        if (k >= ue->frame_parms.ofdm_symbol_size){
Raymond Knopp's avatar
Raymond Knopp committed
604 605
	  k-=ue->frame_parms.ofdm_symbol_size;
	  rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+nushift)];}
606 607 608

        ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
        ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
609
#ifdef DEBUG_PDCCH
yilmazt's avatar
yilmazt committed
610
	printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
611 612 613 614 615 616 617 618 619 620 621 622
#endif
        multadd_real_vector_complex_scalar(fl,
                                           ch,
                                           dl_ch,
                                           16);

        //for (int i= 0; i<8; i++)
        //            printf("pilot_cnt %d dl_ch %d %d\n", pilot_cnt, dl_ch+i, *(dl_ch+i));

        pil+=2;
        rxF+=8;

Hongzhi Wang's avatar
Hongzhi Wang committed
623 624
        ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
        ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
625
#ifdef DEBUG_PDCCH
yilmazt's avatar
yilmazt committed
626
	printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
Hongzhi Wang's avatar
Hongzhi Wang committed
627 628 629 630 631 632 633 634 635 636 637
#endif
        multadd_real_vector_complex_scalar(fm,
                                           ch,
                                           dl_ch,
                                           16);
        pil+=2;
        rxF+=8;

        ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
        ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);

hongzhi wang's avatar
hongzhi wang committed
638
#ifdef DEBUG_PDCCH
hongzhi wang's avatar
hongzhi wang committed
639 640
	printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif
Hongzhi Wang's avatar
Hongzhi Wang committed
641 642 643 644 645 646 647

        multadd_real_vector_complex_scalar(fr,
                                           ch,
                                           dl_ch,
                                           16);
        pil+=2;
        rxF+=8;
hongzhi wang's avatar
hongzhi wang committed
648
        dl_ch+=24;
649
        k+=12;
Hongzhi Wang's avatar
Hongzhi Wang committed
650 651 652 653

      }


654
      //}
Hongzhi Wang's avatar
Hongzhi Wang committed
655 656 657 658 659 660

  }

  return(0);
}

661
int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue,
yilmazt's avatar
yilmazt committed
662 663 664 665 666 667
                                uint8_t eNB_offset,
                                unsigned char Ns,
                                unsigned short p,
                                unsigned char symbol,
                                unsigned short bwp_start_subcarrier,
                                unsigned short nb_rb_pdsch)
668
{
669
  int pilot[1320] __attribute__((aligned(16)));
670 671 672
  unsigned char aarx;
  unsigned short k;
  unsigned int pilot_cnt;
673
  int16_t ch[2],*pil,*rxF,*dl_ch,*fl,*fm,*fr,*fml,*fmr,*fmm;
674 675 676 677 678
  int ch_offset,symbol_offset;

  //uint16_t Nid_cell = (eNB_offset == 0) ? ue->frame_parms.Nid_cell : ue->measurements.adj_cell_id[eNB_offset-1];

  uint8_t nushift;
679
  int **dl_ch_estimates  =ue->pdsch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates;
680
  int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF;
681 682 683 684 685 686 687 688 689 690 691 692

  nushift = (p>>1)&1;
  ue->frame_parms.nushift = nushift;

  if (ue->high_speed_flag == 0) // use second channel estimate position for temporary storage
    ch_offset     = ue->frame_parms.ofdm_symbol_size ;
  else
    ch_offset     = ue->frame_parms.ofdm_symbol_size*symbol;

  symbol_offset = ue->frame_parms.ofdm_symbol_size*symbol;

  k = bwp_start_subcarrier;
hongzhi wang's avatar
hongzhi wang committed
693
  int re_offset = k;
694 695

#ifdef DEBUG_CH
696 697
  printf("PDSCH Channel Estimation : ThreadId %d, eNB_offset %d ch_offset %d, symbol_offset %d OFDM size %d, Ncp=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns], eNB_offset,ch_offset,symbol_offset,ue->frame_parms.ofdm_symbol_size,
         ue->frame_parms.Ncp,Ns,k, symbol);
698 699 700 701 702 703 704
#endif

  switch (nushift) {
   case 0:
         fl = filt8_l0;
         fm = filt8_m0;
         fr = filt8_r0;
hongzhi wang's avatar
hongzhi wang committed
705
         fmm = filt8_mm0;
706 707 708 709 710 711 712 713
         fml = filt8_m0;
         fmr = filt8_mr0;
         break;

   case 1:
         fl = filt8_l1;
         fm = filt8_m1;
         fr = filt8_r1;
hongzhi wang's avatar
hongzhi wang committed
714
         fmm = filt8_mm1;
715 716 717 718 719 720 721 722 723 724 725 726
         fml = filt8_ml1;
         fmr = filt8_m1;
         break;

   default:
     msg("pdsch_channel_estimation: nushift=%d -> ERROR\n",nushift);
     return(-1);
     break;
   }


  // generate pilot
727 728 729
  uint16_t rb_offset = (bwp_start_subcarrier - ue->frame_parms.first_carrier_offset) / 12;
  int config_type = 0; // needs to be updated from higher layer
  nr_pdsch_dmrs_rx(ue,Ns,ue->nr_gold_pdsch[eNB_offset][Ns][0], &pilot[0],1000,0,nb_rb_pdsch+rb_offset);
730 731 732

  for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++) {

733
    pil   = (int16_t *)&pilot[rb_offset*((config_type==0) ? 6:4)];
734
    k     = k&(ue->frame_parms.ofdm_symbol_size-1);
735
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+nushift)];
Raymond Knopp's avatar
Raymond Knopp committed
736
    dl_ch = (int16_t *)&dl_ch_estimates[aarx][ch_offset];
737 738 739 740 741 742

    memset(dl_ch,0,4*(ue->frame_parms.ofdm_symbol_size));
    if (ue->high_speed_flag==0) // multiply previous channel estimate by ch_est_alpha
      multadd_complex_vector_real_scalar(dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                         ue->ch_est_alpha,dl_ch-(ue->frame_parms.ofdm_symbol_size<<1),
                                         1,ue->frame_parms.ofdm_symbol_size);
hongzhi wang's avatar
hongzhi wang committed
743
#ifdef DEBUG_PDSCH
Raymond Knopp's avatar
Raymond Knopp committed
744
    printf("ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL);
745
    printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset);
hongzhi wang's avatar
hongzhi wang committed
746
    printf("rxF addr %p p %d\n", rxF,p);
hongzhi wang's avatar
hongzhi wang committed
747
    printf("dl_ch addr %p nushift %d\n",dl_ch,nushift);
748
#endif
hongzhi wang's avatar
hongzhi wang committed
749
    //if ((ue->frame_parms.N_RB_DL&1)==0) {
750 751 752 753

      // Treat first 2 pilots specially (left edge)
      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
754
#ifdef DEBUG_PDSCH
755 756
      printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1]));
      printf("pilot 0 : rxF - > (%d,%d) addr %p  ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]);
hongzhi wang's avatar
hongzhi wang committed
757
      printf("data 0 : rxF - > (%d,%d) addr %p  ch -> (%d,%d), pil -> (%d,%d) \n",rxF[2],rxF[3],&rxF[2],ch[0],ch[1],pil[0],pil[1]);
758 759 760 761 762 763
#endif
      multadd_real_vector_complex_scalar(fl,
                                         ch,
                                         dl_ch,
                                         8);
      pil+=2;
764 765
      re_offset = (re_offset+2)&(ue->frame_parms.ofdm_symbol_size-1);
      //re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 2) : (re_offset+2);
hongzhi wang's avatar
hongzhi wang committed
766
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+re_offset)];
767 768 769 770 771
      //for (int i= 0; i<8; i++)
      //printf("dl_ch addr %p %d\n", dl_ch+i, *(dl_ch+i));

      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
772
#ifdef DEBUG_PDSCH
773 774 775 776 777 778 779
      printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
#endif
      multadd_real_vector_complex_scalar(fml,
                                         ch,
                                         dl_ch,
                                         8);
      pil+=2;
780 781
      re_offset = (re_offset+2)&(ue->frame_parms.ofdm_symbol_size-1);
      //re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 2) : (re_offset+2);
hongzhi wang's avatar
hongzhi wang committed
782
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+re_offset)];
783
      //printf("dl_ch addr %p\n",dl_ch);
hongzhi wang's avatar
hongzhi wang committed
784 785 786
      
      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
787
#ifdef DEBUG_PDSCH
hongzhi wang's avatar
hongzhi wang committed
788
      printf("pilot 2 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
hongzhi wang's avatar
hongzhi wang committed
789
#endif
hongzhi wang's avatar
hongzhi wang committed
790 791 792 793
      multadd_real_vector_complex_scalar(fmm,
                                         ch,
                                         dl_ch,
                                         8);
hongzhi wang's avatar
hongzhi wang committed
794 795 796 797
                                         
      //for (int i= 0; i<16; i++)
      //printf("dl_ch addr %p %d\n", dl_ch+i, *(dl_ch+i));
      
hongzhi wang's avatar
hongzhi wang committed
798
      pil+=2;
799 800
      re_offset = (re_offset+2)&(ue->frame_parms.ofdm_symbol_size-1);
      //re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 2) : (re_offset+2);
hongzhi wang's avatar
hongzhi wang committed
801
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+re_offset)];
hongzhi wang's avatar
hongzhi wang committed
802
      dl_ch+=8;
803

hongzhi wang's avatar
hongzhi wang committed
804
      for (pilot_cnt=3; pilot_cnt<(6*nb_rb_pdsch-3); pilot_cnt+=2) {
hongzhi wang's avatar
hongzhi wang committed
805 806
    	//if ((pilot_cnt%6)==0)
    		//dl_ch+=4;
hongzhi wang's avatar
hongzhi wang committed
807
		//printf("re_offset %d\n",re_offset);
808 809 810

        ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
        ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
811
#ifdef DEBUG_PDSCH
yilmazt's avatar
yilmazt committed
812
	printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
813 814 815 816 817 818 819
#endif
        multadd_real_vector_complex_scalar(fm,
                                           ch,
                                           dl_ch,
                                           8);

        pil+=2;
820 821
        re_offset = (re_offset+2)&(ue->frame_parms.ofdm_symbol_size-1);
        //re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 2) : (re_offset+2);
hongzhi wang's avatar
hongzhi wang committed
822
        rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+re_offset)];
hongzhi wang's avatar
hongzhi wang committed
823
      
824 825
        ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
        ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
826
#ifdef DEBUG_PDSCH
yilmazt's avatar
yilmazt committed
827
	printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
828
#endif
hongzhi wang's avatar
hongzhi wang committed
829
        multadd_real_vector_complex_scalar(fmm,
830 831 832 833
                                           ch,
                                           dl_ch,
                                           8);
        pil+=2;
834 835
        re_offset = (re_offset+2)&(ue->frame_parms.ofdm_symbol_size-1);
        //re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 2) : (re_offset+2);
hongzhi wang's avatar
hongzhi wang committed
836
        rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+re_offset)];
hongzhi wang's avatar
hongzhi wang committed
837
        dl_ch+=8;
838 839

      }
hongzhi wang's avatar
hongzhi wang committed
840
      
841
      // Treat first 2 pilots specially (right edge)
842
	  ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
hongzhi wang's avatar
hongzhi wang committed
843
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
844
#ifdef DEBUG_PDSCH
yilmazt's avatar
yilmazt committed
845
	printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
hongzhi wang's avatar
hongzhi wang committed
846 847
#endif
      multadd_real_vector_complex_scalar(fm,
hongzhi wang's avatar
hongzhi wang committed
848 849 850
                                         ch,
                                         dl_ch,
                                         8);
hongzhi wang's avatar
hongzhi wang committed
851 852 853 854
                                         
      //for (int i= 0; i<8; i++)
      //printf("dl_ch addr %p %d\n", dl_ch+i, *(dl_ch+i));

hongzhi wang's avatar
hongzhi wang committed
855
      pil+=2;
856 857
      re_offset = (re_offset+2)&(ue->frame_parms.ofdm_symbol_size-1);
      //re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 2) : (re_offset+2);
hongzhi wang's avatar
hongzhi wang committed
858
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+re_offset)];
hongzhi wang's avatar
hongzhi wang committed
859
             
860 861
      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
862
#ifdef DEBUG_PDSCH
863
      printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1]));
yilmazt's avatar
yilmazt committed
864
      printf("pilot %u: rxF - > (%d,%d) addr %p  ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]);
865 866 867 868 869
#endif
      multadd_real_vector_complex_scalar(fmr,
                                         ch,
                                         dl_ch,
                                         8);
hongzhi wang's avatar
hongzhi wang committed
870
                                         
871
      pil+=2;
872 873
      re_offset = (re_offset+2)&(ue->frame_parms.ofdm_symbol_size-1);
      //re_offset = (re_offset >= ue->frame_parms.ofdm_symbol_size) ? (re_offset - ue->frame_parms.ofdm_symbol_size + 2) : (re_offset+2);
hongzhi wang's avatar
hongzhi wang committed
874
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+re_offset)];
hongzhi wang's avatar
hongzhi wang committed
875 876
      dl_ch+=8;
      
877 878
      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
879
#ifdef DEBUG_PDSCH
yilmazt's avatar
yilmazt committed
880
      printf("pilot %u: rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+2,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
881 882 883 884 885
#endif
      multadd_real_vector_complex_scalar(fr,
                                         ch,
                                         dl_ch,
                                         8);
hongzhi wang's avatar
hongzhi wang committed
886
    //}
887

888 889 890 891 892
  }

  return(0);
}