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
    re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
102 103 104 105 106 107 108 109 110 111 112 113 114 115
    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;
116
    re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
117 118 119 120 121 122 123 124 125 126
    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;
127
    re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
128 129 130 131 132 133 134 135 136 137
    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;
138
	re_offset = (re_offset+144) % ue->frame_parms.ofdm_symbol_size;
139 140 141 142 143 144 145 146 147
	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
148
      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]);
149 150 151
#endif

      pil+=2;
152
      re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
153 154 155 156 157 158 159 160 161 162
      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
163
      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]);
164 165
#endif
      pil+=2;
166
      re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
167 168 169 170 171 172 173 174 175 176
      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
177
      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]);
178 179 180
#endif

      pil+=2;
181
      re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
182 183 184 185 186 187 188 189 190 191 192
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];

    }


    //}

  }
  return(0);
}

Francesco Mani's avatar
Francesco Mani committed
193

Hongzhi Wang's avatar
Hongzhi Wang committed
194
int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue,
yilmazt's avatar
yilmazt committed
195 196 197 198 199 200
                               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
201
{
Raymond Knopp's avatar
Raymond Knopp committed
202
  int pilot[200] __attribute__((aligned(16)));
Hongzhi Wang's avatar
Hongzhi Wang committed
203
  unsigned char aarx,p;
Hongzhi Wang's avatar
Hongzhi Wang committed
204
  unsigned short k;
hongzhi wang's avatar
hongzhi wang committed
205
  unsigned int pilot_cnt;
hongzhi wang's avatar
hongzhi wang committed
206
  int16_t ch[2],*pil,*rxF,*dl_ch,*fl,*fm,*fr;
Hongzhi Wang's avatar
Hongzhi Wang committed
207
  int ch_offset,symbol_offset;
laurent's avatar
laurent committed
208
  //int slot_pbch;
Hongzhi Wang's avatar
Hongzhi Wang committed
209

hongzhi wang's avatar
hongzhi wang committed
210
  //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
211

Francesco Mani's avatar
Francesco Mani committed
212
  uint8_t nushift;
213
  int **dl_ch_estimates  =ue->pbch_vars[eNB_offset]->dl_ch_estimates;
214
  int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF;
Hongzhi Wang's avatar
Hongzhi Wang committed
215

hongzhi wang's avatar
hongzhi wang committed
216
  nushift =  ue->frame_parms.Nid_cell%4;
hongzhi wang's avatar
hongzhi wang committed
217
  ue->frame_parms.nushift = nushift;
Raymond Knopp's avatar
Raymond Knopp committed
218 219 220
  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
221 222 223 224 225
  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;

226 227 228
  AssertFatal(dmrss >= 0 && dmrss < 3,
	      "symbol %d is illegal for PBCH DM-RS \n",
	      dmrss);
Raymond Knopp's avatar
Raymond Knopp committed
229

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

Raymond Knopp's avatar
Raymond Knopp committed
232

Hongzhi Wang's avatar
Hongzhi Wang committed
233 234 235
  k = nushift;

#ifdef DEBUG_CH
Francesco Mani's avatar
Francesco Mani committed
236
  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,
237
         ue->frame_parms.Ncp,Ns,k, symbol);
Hongzhi Wang's avatar
Hongzhi Wang committed
238 239 240 241
#endif

  switch (k) {
  case 0:
Raymond Knopp's avatar
Raymond Knopp committed
242 243 244 245
    fl = filt16a_l0;
    fm = filt16a_m0;
    fr = filt16a_r0;
    break;
Hongzhi Wang's avatar
Hongzhi Wang committed
246 247

  case 1:
Raymond Knopp's avatar
Raymond Knopp committed
248 249 250 251
    fl = filt16a_l1;
    fm = filt16a_m1;
    fr = filt16a_r1;
    break;
Hongzhi Wang's avatar
Hongzhi Wang committed
252 253

  case 2:
Raymond Knopp's avatar
Raymond Knopp committed
254 255 256 257
    fl = filt16a_l2;
    fm = filt16a_m2;
    fr = filt16a_r2;
    break;
Hongzhi Wang's avatar
Hongzhi Wang committed
258 259

  case 3:
Raymond Knopp's avatar
Raymond Knopp committed
260 261 262 263
    fl = filt16a_l3;
    fm = filt16a_m3;
    fr = filt16a_r3;
    break;
Hongzhi Wang's avatar
Hongzhi Wang committed
264 265 266 267 268 269 270 271

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

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

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

Raymond Knopp's avatar
Raymond Knopp committed
277 278 279
    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
280

Hongzhi Wang's avatar
Hongzhi Wang committed
281 282 283 284 285
    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);
286
#ifdef DEBUG_CH
Raymond Knopp's avatar
Raymond Knopp committed
287
    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
288
    printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset);
hongzhi wang's avatar
hongzhi wang committed
289 290
    printf("rxF addr %p\n", rxF);
    printf("dl_ch addr %p\n",dl_ch);
291
#endif
hongzhi wang's avatar
hongzhi wang committed
292
    //if ((ue->frame_parms.N_RB_DL&1)==0) {
Hongzhi Wang's avatar
Hongzhi Wang committed
293

Raymond Knopp's avatar
Raymond Knopp committed
294 295 296
    // 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
297

Raymond Knopp's avatar
Raymond Knopp committed
298 299 300 301 302 303 304 305 306
#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;
307
    re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
Raymond Knopp's avatar
Raymond Knopp committed
308 309 310 311 312 313 314
    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
315 316


Raymond Knopp's avatar
Raymond Knopp committed
317 318 319 320 321 322 323 324
#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;
325
    re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
Raymond Knopp's avatar
Raymond Knopp committed
326 327
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];

328 329 330
    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
331 332 333 334 335 336 337 338 339
#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;
340
    re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
Raymond Knopp's avatar
Raymond Knopp committed
341 342 343 344 345 346 347 348 349 350 351
    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;
352
	re_offset = (re_offset+144) % ue->frame_parms.ofdm_symbol_size;
Raymond Knopp's avatar
Raymond Knopp committed
353 354 355
	rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
	dl_ch += 288;
      }
Hongzhi Wang's avatar
Hongzhi Wang committed
356 357
      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
358

359
#ifdef DEBUG_CH
yilmazt's avatar
yilmazt committed
360
      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]);
361
#endif
Hongzhi Wang's avatar
Hongzhi Wang committed
362
      multadd_real_vector_complex_scalar(fl,
Raymond Knopp's avatar
Raymond Knopp committed
363 364 365 366
					 ch,
					 dl_ch,
					 16);

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

Raymond Knopp's avatar
Raymond Knopp committed
370
      pil+=2;
371
      re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
Raymond Knopp's avatar
Raymond Knopp committed
372 373 374
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
        
  
Hongzhi Wang's avatar
Hongzhi Wang committed
375 376
      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
377

Hongzhi Wang's avatar
Hongzhi Wang committed
378
#ifdef DEBUG_CH
yilmazt's avatar
yilmazt committed
379
      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
380 381
#endif
      multadd_real_vector_complex_scalar(fm,
Raymond Knopp's avatar
Raymond Knopp committed
382 383 384
					 ch,
					 dl_ch,
					 16);
Hongzhi Wang's avatar
Hongzhi Wang committed
385
      pil+=2;
386
      re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
Raymond Knopp's avatar
Raymond Knopp committed
387 388
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
        
Hongzhi Wang's avatar
Hongzhi Wang committed
389 390 391 392

      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
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+2,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
hongzhi wang's avatar
hongzhi wang committed
395
#endif
Hongzhi Wang's avatar
Hongzhi Wang committed
396 397

      multadd_real_vector_complex_scalar(fr,
Raymond Knopp's avatar
Raymond Knopp committed
398 399 400
					 ch,
					 dl_ch,
					 16);
Hongzhi Wang's avatar
Hongzhi Wang committed
401
      pil+=2;
402
      re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
Raymond Knopp's avatar
Raymond Knopp committed
403
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)];
hongzhi wang's avatar
hongzhi wang committed
404
      dl_ch+=24;
Hongzhi Wang's avatar
Hongzhi Wang committed
405

Raymond Knopp's avatar
Raymond Knopp committed
406
    }
Hongzhi Wang's avatar
Hongzhi Wang committed
407

frtabu's avatar
frtabu committed
408
    idft_size_idx_t idftsizeidx;
Hongzhi Wang's avatar
Hongzhi Wang committed
409 410 411

    switch (ue->frame_parms.ofdm_symbol_size) {
    case 128:
frtabu's avatar
frtabu committed
412
      idftsizeidx = IDFT_128;
Hongzhi Wang's avatar
Hongzhi Wang committed
413 414 415
      break;

    case 256:
frtabu's avatar
frtabu committed
416
      idftsizeidx = IDFT_256;
Hongzhi Wang's avatar
Hongzhi Wang committed
417 418 419
      break;

    case 512:
frtabu's avatar
frtabu committed
420
      idftsizeidx = IDFT_512;
Hongzhi Wang's avatar
Hongzhi Wang committed
421 422 423
      break;

    case 1024:
frtabu's avatar
frtabu committed
424
      idftsizeidx = IDFT_1024;
Hongzhi Wang's avatar
Hongzhi Wang committed
425 426 427
      break;

    case 1536:
frtabu's avatar
frtabu committed
428
      idftsizeidx = IDFT_1536;
Hongzhi Wang's avatar
Hongzhi Wang committed
429 430 431
      break;

    case 2048:
frtabu's avatar
frtabu committed
432
      idftsizeidx = IDFT_2048;
Hongzhi Wang's avatar
Hongzhi Wang committed
433 434 435
      break;

    case 3072:
frtabu's avatar
frtabu committed
436
      idftsizeidx = IDFT_3072;
Hongzhi Wang's avatar
Hongzhi Wang committed
437 438 439
      break;

    case 4096:
frtabu's avatar
frtabu committed
440
      idftsizeidx = IDFT_4096;
Hongzhi Wang's avatar
Hongzhi Wang committed
441 442 443 444 445 446 447
      break;

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

Hongzhi Wang's avatar
Hongzhi Wang committed
448
    if( symbol == 3)
Hongzhi Wang's avatar
Hongzhi Wang committed
449 450 451
    {
        // do ifft of channel estimate
        for (aarx=0; aarx<ue->frame_parms.nb_antennas_rx; aarx++)
452
            for (p=0; p<ue->frame_parms.nb_antenna_ports_gNB; p++) {
Hongzhi Wang's avatar
Hongzhi Wang committed
453 454
                if (ue->pbch_vars[eNB_offset]->dl_ch_estimates[(p<<1)+aarx])
                {
Hongzhi Wang's avatar
Hongzhi Wang committed
455
  		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);
frtabu's avatar
frtabu committed
456 457
  		idft(idftsizeidx,
  			 (int16_t*) &ue->pbch_vars[eNB_offset]->dl_ch_estimates[(p<<1)+aarx][ch_offset],
Hongzhi Wang's avatar
Hongzhi Wang committed
458 459 460 461
  		     (int16_t*) ue->pbch_vars[eNB_offset]->dl_ch_estimates_time[(p<<1)+aarx],1);
                }
            }
    }
Hongzhi Wang's avatar
Hongzhi Wang committed
462

hongzhi wang's avatar
hongzhi wang committed
463
    //}
Hongzhi Wang's avatar
Hongzhi Wang committed
464 465 466 467 468

  }
  return(0);
}

469
int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue,
yilmazt's avatar
yilmazt committed
470 471 472 473 474
                                uint8_t eNB_offset,
                                unsigned char Ns,
                                unsigned char symbol,
                                unsigned short coreset_start_subcarrier,
                                unsigned short nb_rb_coreset)
475
{
476

Hongzhi Wang's avatar
Hongzhi Wang committed
477
  unsigned char aarx;
478 479 480 481 482 483 484
  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];

485
  int **dl_ch_estimates  =ue->pdcch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates;
486
  int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF;
487 488 489 490 491 492 493 494 495


  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;

496
  k = coreset_start_subcarrier;
497

hongzhi wang's avatar
hongzhi wang committed
498
#ifdef DEBUG_PDCCH
499 500
  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);
501 502 503 504 505 506
#endif

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

507

508 509
  // generate pilot
  int pilot[nb_rb_coreset * 3] __attribute__((aligned(16))); 
Florian Kaltenberger's avatar
Florian Kaltenberger committed
510
  nr_pdcch_dmrs_rx(ue,eNB_offset,Ns,ue->nr_gold_pdcch[eNB_offset][Ns][symbol], &pilot[0],2000,nb_rb_coreset);
511 512 513 514


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

Raymond Knopp's avatar
Raymond Knopp committed
515
    pil   = (int16_t *)&pilot[0];
516
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+1)];
Raymond Knopp's avatar
Raymond Knopp committed
517
    dl_ch = (int16_t *)&dl_ch_estimates[aarx][ch_offset];
518 519 520 521 522 523

    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
524
#ifdef DEBUG_PDCCH
Raymond Knopp's avatar
Raymond Knopp committed
525
    printf("pdcch ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL);
526 527 528 529
    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);
530
#endif
531
    //    if ((ue->frame_parms.N_RB_DL&1)==0) {
532 533 534
      // 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
535
#ifdef DEBUG_PDCCH
536 537 538 539 540 541 542 543 544 545 546 547 548 549
      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
550
#ifdef DEBUG_PDCCH
551 552 553 554 555 556 557 558 559 560 561 562
      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
563
#ifdef DEBUG_PDCCH
564 565 566 567 568 569 570
      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
571
                                         
hongzhi wang's avatar
hongzhi wang committed
572
#ifdef DEBUG_PDCCH       
hongzhi wang's avatar
hongzhi wang committed
573
      for (int m =0; m<12; m++)
Raymond Knopp's avatar
Raymond Knopp committed
574
	printf("data :  dl_ch -> (%d,%d)\n",dl_ch[0+2*m],dl_ch[1+2*m]);
hongzhi wang's avatar
hongzhi wang committed
575
#endif      
576 577 578
      pil+=2;
      rxF+=8;
      dl_ch+=24;
579
      k+=12;
hongzhi wang's avatar
hongzhi wang committed
580 581
      
      
582

583
      for (pilot_cnt=3; pilot_cnt<(3*nb_rb_coreset); pilot_cnt+=3) {
584

585
        if (k >= ue->frame_parms.ofdm_symbol_size){
Raymond Knopp's avatar
Raymond Knopp committed
586
	  k-=ue->frame_parms.ofdm_symbol_size;
587
	  rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+1)];}
588 589 590

        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
591
#ifdef DEBUG_PDCCH
yilmazt's avatar
yilmazt committed
592
	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]);
593 594 595 596 597 598 599 600 601 602 603 604
#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
605 606
        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
607
#ifdef DEBUG_PDCCH
yilmazt's avatar
yilmazt committed
608
	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
609 610 611 612 613 614 615 616 617 618 619
#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
620
#ifdef DEBUG_PDCCH
621
	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
622
#endif
Hongzhi Wang's avatar
Hongzhi Wang committed
623 624 625 626 627 628 629

        multadd_real_vector_complex_scalar(fr,
                                           ch,
                                           dl_ch,
                                           16);
        pil+=2;
        rxF+=8;
hongzhi wang's avatar
hongzhi wang committed
630
        dl_ch+=24;
631
        k+=12;
Hongzhi Wang's avatar
Hongzhi Wang committed
632 633 634 635

      }


636
      //}
Hongzhi Wang's avatar
Hongzhi Wang committed
637 638 639 640 641 642

  }

  return(0);
}

643
int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue,
yilmazt's avatar
yilmazt committed
644 645 646 647 648 649
                                uint8_t eNB_offset,
                                unsigned char Ns,
                                unsigned short p,
                                unsigned char symbol,
                                unsigned short bwp_start_subcarrier,
                                unsigned short nb_rb_pdsch)
650
{
651
  int pilot[3280] __attribute__((aligned(16)));
652 653 654
  unsigned char aarx;
  unsigned short k;
  unsigned int pilot_cnt;
655 656
  int16_t ch[2],*pil,*rxF,*dl_ch;
  int16_t *fl,*fm,*fr,*fml,*fmr,*fmm,*fdcl,*fdcr,*fdclh,*fdcrh;
657 658 659 660 661
  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;
662
  int **dl_ch_estimates  =ue->pdsch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates;
663
  int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF;
664 665 666 667

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

668
  if (ue->high_speed_flag == 0)
669 670 671 672 673 674 675
    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
676
  int re_offset = k;
677 678

#ifdef DEBUG_CH
679 680
  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);
681 682 683 684 685 686 687
#endif

  switch (nushift) {
   case 0:
         fl = filt8_l0;
         fm = filt8_m0;
         fr = filt8_r0;
hongzhi wang's avatar
hongzhi wang committed
688
         fmm = filt8_mm0;
689 690
         fml = filt8_m0;
         fmr = filt8_mr0;
691 692 693 694
         fdcl = filt8_dcl0;
         fdcr = filt8_dcr0;
         fdclh = filt8_dcl0_h;
         fdcrh = filt8_dcr0_h;
695 696 697 698 699 700
         break;

   case 1:
         fl = filt8_l1;
         fm = filt8_m1;
         fr = filt8_r1;
hongzhi wang's avatar
hongzhi wang committed
701
         fmm = filt8_mm1;
702 703
         fml = filt8_ml1;
         fmr = filt8_m1;
704 705 706 707
         fdcl = filt8_dcl1;
         fdcr = filt8_dcr1;
         fdclh = filt8_dcl1_h;
         fdcrh = filt8_dcr1_h;
708 709 710 711 712 713 714 715 716 717
         break;

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


  // generate pilot
718 719
  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
720
  nr_pdsch_dmrs_rx(ue,Ns,ue->nr_gold_pdsch[eNB_offset][Ns][symbol], &pilot[0],1000,0,nb_rb_pdsch+rb_offset);
721 722 723

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

724
    pil   = (int16_t *)&pilot[rb_offset*((config_type==0) ? 6:4)];
725
    k     = k % ue->frame_parms.ofdm_symbol_size;
726
    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+nushift)];
Raymond Knopp's avatar
Raymond Knopp committed
727
    dl_ch = (int16_t *)&dl_ch_estimates[aarx][ch_offset];
728 729 730 731 732 733

    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
734
#ifdef DEBUG_PDSCH
Raymond Knopp's avatar
Raymond Knopp committed
735
    printf("ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL);
736
    printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset);
hongzhi wang's avatar
hongzhi wang committed
737
    printf("rxF addr %p p %d\n", rxF,p);
hongzhi wang's avatar
hongzhi wang committed
738
    printf("dl_ch addr %p nushift %d\n",dl_ch,nushift);
739
#endif
hongzhi wang's avatar
hongzhi wang committed
740
    //if ((ue->frame_parms.N_RB_DL&1)==0) {
741 742 743 744

      // 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
745
#ifdef DEBUG_PDSCH
746 747
      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
748
      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]);
749 750 751 752 753 754
#endif
      multadd_real_vector_complex_scalar(fl,
                                         ch,
                                         dl_ch,
                                         8);
      pil+=2;
755
      re_offset = (re_offset+2) % ue->frame_parms.ofdm_symbol_size;
hongzhi wang's avatar
hongzhi wang committed
756
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+re_offset)];
757 758 759 760 761
      //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
762
#ifdef DEBUG_PDSCH
763 764 765 766 767 768 769
      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;
770
      re_offset = (re_offset+2) % ue->frame_parms.ofdm_symbol_size;
hongzhi wang's avatar
hongzhi wang committed
771
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+re_offset)];
772
      //printf("dl_ch addr %p\n",dl_ch);
hongzhi wang's avatar
hongzhi wang committed
773 774 775
      
      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
776
#ifdef DEBUG_PDSCH
hongzhi wang's avatar
hongzhi wang committed
777
      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
778
#endif
hongzhi wang's avatar
hongzhi wang committed
779 780 781 782
      multadd_real_vector_complex_scalar(fmm,
                                         ch,
                                         dl_ch,
                                         8);
hongzhi wang's avatar
hongzhi wang committed
783 784 785 786
                                         
      //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
787
      pil+=2;
788
      re_offset = (re_offset+2) % ue->frame_parms.ofdm_symbol_size;
hongzhi wang's avatar
hongzhi wang committed
789
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+re_offset)];
hongzhi wang's avatar
hongzhi wang committed
790
      dl_ch+=8;
791

hongzhi wang's avatar
hongzhi wang committed
792
      for (pilot_cnt=3; pilot_cnt<(6*nb_rb_pdsch-3); pilot_cnt+=2) {
hongzhi wang's avatar
hongzhi wang committed
793 794
    	//if ((pilot_cnt%6)==0)
    		//dl_ch+=4;
hongzhi wang's avatar
hongzhi wang committed
795
		//printf("re_offset %d\n",re_offset);
796 797 798

        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
799
#ifdef DEBUG_PDSCH
yilmazt's avatar
yilmazt committed
800
	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]);
801 802 803 804 805 806 807
#endif
        multadd_real_vector_complex_scalar(fm,
                                           ch,
                                           dl_ch,
                                           8);

        pil+=2;
808
        re_offset = (re_offset+2) % ue->frame_parms.ofdm_symbol_size;
hongzhi wang's avatar
hongzhi wang committed
809
        rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+re_offset)];
hongzhi wang's avatar
hongzhi wang committed
810
      
811 812
        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
813
#ifdef DEBUG_PDSCH
yilmazt's avatar
yilmazt committed
814
	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]);
815
#endif
hongzhi wang's avatar
hongzhi wang committed
816
        multadd_real_vector_complex_scalar(fmm,
817 818 819 820
                                           ch,
                                           dl_ch,
                                           8);
        pil+=2;
821
        re_offset = (re_offset+2) % ue->frame_parms.ofdm_symbol_size;
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
        dl_ch+=8;
824 825

      }
hongzhi wang's avatar
hongzhi wang committed
826
      
827
      // Treat first 2 pilots specially (right edge)
828
      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
hongzhi wang's avatar
hongzhi wang committed
829
      ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
hongzhi wang's avatar
hongzhi wang committed
830
#ifdef DEBUG_PDSCH
yilmazt's avatar
yilmazt committed
831
	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
832 833
#endif
      multadd_real_vector_complex_scalar(fm,
hongzhi wang's avatar
hongzhi wang committed
834 835 836
                                         ch,
                                         dl_ch,
                                         8);
hongzhi wang's avatar
hongzhi wang committed
837 838 839 840
                                         
      //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
841
      pil+=2;
842
      re_offset = (re_offset+2) % ue->frame_parms.ofdm_symbol_size;
hongzhi wang's avatar
hongzhi wang committed
843
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+re_offset)];
hongzhi wang's avatar
hongzhi wang committed
844
             
845 846
      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
847
#ifdef DEBUG_PDSCH
848
      printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1]));
yilmazt's avatar
yilmazt committed
849
      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]);
850 851 852 853 854
#endif
      multadd_real_vector_complex_scalar(fmr,
                                         ch,
                                         dl_ch,
                                         8);
hongzhi wang's avatar
hongzhi wang committed
855
                                         
856
      pil+=2;
857
      re_offset = (re_offset+2) % ue->frame_parms.ofdm_symbol_size;
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
      dl_ch+=8;
      
861 862
      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
863
#ifdef DEBUG_PDSCH
yilmazt's avatar
yilmazt committed
864
      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]);
865 866 867 868 869
#endif
      multadd_real_vector_complex_scalar(fr,
                                         ch,
                                         dl_ch,
                                         8);
hongzhi wang's avatar
hongzhi wang committed
870
    //}
871 872
    
    // check if PRB crosses DC and improve estimates around DC
Sakthivel Velumani's avatar
Sakthivel Velumani committed
873
    if ((bwp_start_subcarrier < ue->frame_parms.ofdm_symbol_size) && (bwp_start_subcarrier+nb_rb_pdsch*12 >= ue->frame_parms.ofdm_symbol_size)) {
874 875 876 877 878
      dl_ch = (int16_t *)&dl_ch_estimates[aarx][ch_offset];
      uint16_t idxDC = 2*(ue->frame_parms.ofdm_symbol_size - bwp_start_subcarrier);
      uint16_t idxPil = idxDC/2;
      re_offset = k;
      pil = (int16_t *)&pilot[rb_offset*((config_type==0) ? 6:4)];
879 880 881
      pil += (idxPil-2);
      dl_ch += (idxDC-4);
      dl_ch = memset(dl_ch, 0, sizeof(int16_t)*10);
882
      re_offset = (re_offset+idxDC/2-2) % ue->frame_parms.ofdm_symbol_size;
883 884 885
      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+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);
886
      
887 888
      // for proper allignment of SIMD vectors
      if((ue->frame_parms.N_RB_DL&1)==0) {
889
        
890
        multadd_real_vector_complex_scalar(fdcl,
891 892 893 894 895
                                           ch,
                                           dl_ch-4,
                                           8);
        
        pil += 4;
896
        re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
897 898 899 900
        rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+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);
        
901
        multadd_real_vector_complex_scalar(fdcr,
902 903 904 905 906
                                           ch,
                                           dl_ch-4,
                                           8);
      } else {

907
        multadd_real_vector_complex_scalar(fdclh,
908 909 910 911 912
                                           ch,
                                           dl_ch,
                                           8);
        
        pil += 4;
913
        re_offset = (re_offset+4) % ue->frame_parms.ofdm_symbol_size;
914 915 916 917
        rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+nushift+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);
        
918
        multadd_real_vector_complex_scalar(fdcrh,
919 920 921
                                           ch,
                                           dl_ch,
                                           8);
922
      }
923 924 925

    }

926
#ifdef DEBUG_PDSCH
927
    dl_ch = (int16_t *)&dl_ch_estimates[aarx][ch_offset];
928
    for(uint16_t idxP=0; idxP<ceil((float)nb_rb_pdsch*12/8); idxP++) {
929 930 931
      for(uint8_t idxI=0; idxI<16; idxI+=2) {
        printf("%d\t%d\t",dl_ch[idxP*16+idxI],dl_ch[idxP*16+idxI+1]);
      }
932
      printf("%d\n",idxP);
933
    }
934
#endif    
935 936 937 938 939
  }

  return(0);
}