lte_dl_ue_spec.c 11.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
/*******************************************************************************
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.


    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
   see <http://www.gnu.org/licenses/>.

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr

  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE

 *******************************************************************************/

/*! \file PHY/LTE_REFSIG/lte_dl_ue_spec.c
* \brief Top-level routines for generating UE-specific Reference signals from 36-211, V11.3.0 2013-06
* \author R. Knopp X. Jiang
* \date 2015
* \version 0.1
* \company Eurecom
* \email: knopp@eurecom.fr xiwen.jiang@eurecom.fr
* \note
* \warning
*/

#ifdef USER_MODE
#include <stdio.h>
#include <stdlib.h>
#endif

#include "defs.h"
#include "PHY/defs.h"
#include "log.h"

//extern unsigned int lte_gold_table[3][20][2][14];
//#define DEBUG_DL_CELL_SPEC

int Wbar_NCP[8][4] = {{1,1,1,1},{1,-1,1,-1},{1,1,1,1},{1,-1,1,-1},{1,1,-1,-1},{-1,-1,1,1},{1,-1,-1,1},{-1,1,1,-1}};

int lte_dl_ue_spec(PHY_VARS_eNB *phy_vars_eNB,
                   uint8_t UE_id,
                   mod_sym_t *output,
                   short amp,
                   uint8_t Ns,
		   uint8_t lprime,
                   uint8_t p,
62
                   int SS_flag)
63 64
{

65
 /* mod_sym_t qpsk[4],nqpsk[4];
66
  int16_t k=0,a;
67
  int mprime,ind,ind_dword,ind_qpsk_symb;
68 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 101 102 103 104 105
  unsigned nushift,kprime;
  //  LTE_eNB_DLSCH_t *dlsch = phy_vars_eNB->dlsch_eNB[UE_id][0];

  a = (amp*ONE_OVER_SQRT2_Q15)>>15;
  ((short *)&qpsk[0])[0] = a;
  ((short *)&qpsk[0])[1] = a;
  ((short *)&qpsk[1])[0] = -a;
  ((short *)&qpsk[1])[1] = a;
  ((short *)&qpsk[2])[0] = a;
  ((short *)&qpsk[2])[1] = -a;
  ((short *)&qpsk[3])[0] = -a;
  ((short *)&qpsk[3])[1] = -a;

  ((short *)&nqpsk[0])[0] = -a;
  ((short *)&nqpsk[0])[1] = -a;
  ((short *)&nqpsk[1])[0] = a;
  ((short *)&nqpsk[1])[1] = -a;
  ((short *)&nqpsk[2])[0] = -a;
  ((short *)&nqpsk[2])[1] = a;
  ((short *)&nqpsk[3])[0] = a;
  ((short *)&nqpsk[3])[1] = a;

  if (p==5) {
    if (SS_flag==0) {
      if (phy_vars_eNB->lte_frame_parms.Ncp == NORMAL) {
      // this is 3GPP 36-211 6.10.3.2, NORMAL CP, p=5
      
      nushift =  phy_vars_eNB->lte_frame_parms.Nid_cell%3;

      if(lprime==0){
        kprime=nushift;
      }else{
        kprime=(nushift+2*lprime)%4;
      }

      k = kprime+phy_vars_eNB->lte_frame_parms.first_carrier_offset;
      printf("lte_dl_ue_spec:k=%d\n",k);
 
106 107 108 109
      for (mprime=0;mprime<3*nRB_PDSCH-1;mprime++) {
        ind = 3*lprime*nRB_PDSCH+mprime;
        ind_dword = ind>>4;
        ind_qpsk_symb = ind&0xf;
110

111 112
        output[k] = qpsk[(phy_vars_UE->lte_gold_uespec_port5_table[Ns][ind_dword]>>(2*ind_qpsk_symb))&3];
        //output[k] = 0xffffffff;
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128

        k += 4;
        if (k >= phy_vars_eNB->lte_frame_parms.ofdm_symbol_size) {
          k++;  // skip DC carrier
          k-=phy_vars_eNB->lte_frame_parms.ofdm_symbol_size;
        }

       }
      }
    }
  } else if (p>=7) {
    printf("lte_dl_ue_spec:antenna ports >=7 not supported yet!\n");
  } else {
    LOG_E(PHY,"Illegal p %d UE specific pilots\n",p);
  }

129
  return(0);*/
130 131 132 133
}


int lte_dl_ue_spec_rx(PHY_VARS_UE *phy_vars_ue,
134 135 136 137 138 139
                      mod_sym_t *output,
                      unsigned char Ns,
                      unsigned char p, 
                      int lprime,
                      int SS_flag,
                      uint16_t nRB_PDSCH)
140 141 142
{
  mod_sym_t qpsk[4],nqpsk[4],*qpsk_p,*output_p;
  int16_t a;
143
  int w,mprime,ind,l,ind_dword,ind_qpsk_symb,nPRB;
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
  short pamp;

  // Compute the correct pilot amplitude, sqrt_rho_b = Q3.13
  pamp = ONE_OVER_SQRT2_Q15;

  // This includes complex conjugate for channel estimation
  ((short *)&qpsk[0])[0] = pamp;
  ((short *)&qpsk[0])[1] = -pamp;
  ((short *)&qpsk[1])[0] = -pamp;
  ((short *)&qpsk[1])[1] = -pamp;
  ((short *)&qpsk[2])[0] = pamp;
  ((short *)&qpsk[2])[1] = pamp;
  ((short *)&qpsk[3])[0] = -pamp;
  ((short *)&qpsk[3])[1] = pamp;

  ((short *)&nqpsk[0])[0] = -pamp;
  ((short *)&nqpsk[0])[1] = pamp;
  ((short *)&nqpsk[1])[0] = pamp;
  ((short *)&nqpsk[1])[1] = pamp;
  ((short *)&nqpsk[2])[0] = -pamp;
  ((short *)&nqpsk[2])[1] = -pamp;
  ((short *)&nqpsk[3])[0] = pamp;
  ((short *)&nqpsk[3])[1] = -pamp;

  if (p>=7) {
    if (SS_flag==0) {
      if (phy_vars_ue->lte_frame_parms.Ncp == NORMAL) {
        // this is 3GPP 36-211 6.10.3.2, NORMAL CP, p>=7

        output_p = output;

175
        //for (lprime=0; lprime<2; lprime++) {
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293

          ind = 3*lprime*phy_vars_ue->lte_frame_parms.N_RB_DL;
          l = lprime + ((Ns&1)<<1);

          // loop over pairs of PRBs, this is the periodicity of the W_bar_NCP sequence
          // unroll the computations for the 6 pilots, select qpsk or nqpsk as function of W_bar_NCP
          for (nPRB=0; nPRB<phy_vars_ue->lte_frame_parms.N_RB_DL; nPRB+=2) {

            // First pilot
            w = Wbar_NCP[p-7][l];
            qpsk_p = (w==1) ? qpsk : nqpsk;


            ind_dword     = ind>>4;
            ind_qpsk_symb = ind&0xf;

            *output_p = qpsk_p[(phy_vars_ue->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3];


#ifdef DEBUG_DL_UESPEC
            LOG_D(PHY,"Ns %d, l %d, m %d,ind_dword %d, ind_qpsk_symbol %d\n",
                  Ns,l,m,ind_dword,ind_qpsk_symb);
            LOG_D(PHY,"index = %d\n",(phy_vars_eNB->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3);
#endif

            output_p++;
            ind++;

            w =  Wbar_NCP[p-7][3-l];
            qpsk_p = (w==1) ? qpsk : nqpsk;

            // Second pilot
            ind_dword     = ind>>4;
            ind_qpsk_symb = ind&0xf;

            *output_p = qpsk_p[(phy_vars_ue->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3];

#ifdef DEBUG_DL_UESPEC
            LOG_D(PHY,"Ns %d, l %d, m %d,ind_dword %d, ind_qpsk_symbol %d\n",
                  Ns,l,m,ind_dword,ind_qpsk_symb);
            LOG_D(PHY,"index = %d\n",(phy_vars_ue->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3);
#endif

            output_p++;
            ind++;

            w = Wbar_NCP[p-7][l];
            qpsk_p = (w==1) ? qpsk : nqpsk;
            // Third pilot
            ind_dword     = ind>>4;
            ind_qpsk_symb = ind&0xf;

            *output_p = qpsk_p[(phy_vars_ue->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3];

#ifdef DEBUG_DL_UESPEC
            LOG_D(PHY,"Ns %d, l %d, m %d,ind_dword %d, ind_qpsk_symbol %d\n",
                  Ns,l,m,ind_dword,ind_qpsk_symb);
            LOG_D(PHY,"index = %d\n",(phy_vars_eNB->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3);
#endif

            output_p++;
            ind++;

            // Fourth pilot
            w = Wbar_NCP[p-7][3-l];
            qpsk_p = (w==1) ? qpsk : nqpsk;


            ind_dword     = ind>>4;
            ind_qpsk_symb = ind&0xf;

            *output_p = qpsk_p[(phy_vars_ue->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3];


#ifdef DEBUG_DL_UESPEC
            LOG_D(PHY,"Ns %d, l %d, m %d,ind_dword %d, ind_qpsk_symbol %d\n",
                  Ns,l,m,ind_dword,ind_qpsk_symb);
            LOG_D(PHY,"index = %d\n",(phy_vars_ue->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3);
#endif

            output_p++;
            ind++;

            w =  Wbar_NCP[p-7][l];
            qpsk_p = (w==1) ? qpsk : nqpsk;

            // Fifth pilot
            ind_dword     = ind>>4;
            ind_qpsk_symb = ind&0xf;

            *output_p = qpsk_p[(phy_vars_ue->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3];

#ifdef DEBUG_DL_UESPEC
            LOG_D(PHY,"Ns %d, l %d, m %d,ind_dword %d, ind_qpsk_symbol %d\n",
                  Ns,l,m,ind_dword,ind_qpsk_symb);
            LOG_D(PHY,"index = %d\n",(phy_vars_ue->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3);
#endif

            output_p++;
            ind++;

            w = Wbar_NCP[p-7][3-l];
            qpsk_p = (w==1) ? qpsk : nqpsk;
            // Sixth pilot
            ind_dword     = ind>>4;
            ind_qpsk_symb = ind&0xf;

            *output_p = qpsk_p[(phy_vars_ue->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3];

#ifdef DEBUG_DL_UESPEC
            LOG_D(PHY,"Ns %d, l %d, m %d,ind_dword %d, ind_qpsk_symbol %d\n",
                  Ns,l,m,ind_dword,ind_qpsk_symb);
            LOG_D(PHY,"index = %d\n",(phy_vars_ue->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3);
#endif

            output_p++;
            ind++;
          }
294
       // }
295 296 297 298 299 300
      } else {
        LOG_E(PHY,"Special subframe not supported for UE specific pilots yet\n");
      }
    }
  } else if (p==5) {
    if (SS_flag==0) {
301 302 303 304 305 306 307 308 309 310 311 312 313 314
      output_p = output;

      if (phy_vars_ue->lte_frame_parms.Ncp == NORMAL) {
        //for (lprime=0;lprime<4;lprime++) {
        for (mprime=0;mprime<3*nRB_PDSCH;mprime++) {

          ind = 3*lprime*nRB_PDSCH+mprime;
          ind_dword = ind>>4;
          ind_qpsk_symb = ind&0xf;

          *output_p = qpsk[(phy_vars_ue->lte_gold_uespec_port5_table[Ns][ind_dword]>>(2*ind_qpsk_symb))&3];
          //printf("lprime=%d,ind=%d,Ns=%d,output_p=(%d,%d)\n",lprime,ind,Ns,((short *)&output_p[0])[0],((short *)&output_p[0])[1]);
          *output_p++;
      
315
        }
316
       // }
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
      }
    }
  } else {
    LOG_E(PHY,"Illegal p %d UE specific pilots\n",p);
  }

  return(0);
}



#ifdef LTE_DL_CELL_SPEC_MAIN



//extern int write_output(const char *,const char *,void *,int,int,char);
// flag change eren
extern int write_output(const char *,const char *,void *,int,int,char);
main()
{

  unsigned short Nid_cell=0;
  unsigned int Ncp = 0;
  int output00[1024];
  int output01[1024];
  int output10[1024];
  int output11[1024];

  memset(output00,0,1024*sizeof(int));
  memset(output01,0,1024*sizeof(int));
  memset(output10,0,1024*sizeof(int));
  memset(output11,0,1024*sizeof(int));

  lte_gold(Nid_cell,Ncp);

  lte_dl_ue_spec(output00,
353 354 355 356 357 358 359 360
                 ONE_OVER_SQRT2_Q15,
                 50,
                 Nid_cell,
                 Ncp,
                 0,
                 0,
                 0,
                 0);
361 362

  lte_dl_ue_spec(output10,
363 364 365 366 367 368 369 370
                 ONE_OVER_SQRT2_Q15,
                 50,
                 Nid_cell,
                 Ncp,
                 0,
                 1,
                 0,
                 0);
371 372

  lte_dl_ue_spec(output01,
373 374 375 376 377 378 379 380
                 ONE_OVER_SQRT2_Q15,
                 50,
                 Nid_cell,
                 Ncp,
                 0,
                 0,
                 1,
                 0);
381 382

  lte_dl_ue_spec(output11,
383 384 385 386 387 388 389 390
                 ONE_OVER_SQRT2_Q15,
                 50,
                 Nid_cell,
                 Ncp,
                 0,
                 1,
                 1,
                 0);
391 392 393 394 395 396 397 398 399 400


  write_output("dl_ue_spec00.m","dl_cs00",output00,1024,1,1);
  write_output("dl_ue_spec01.m","dl_cs01",output01,1024,1,1);
  write_output("dl_ue_spec10.m","dl_cs10",output10,1024,1,1);
  write_output("dl_ue_spec11.m","dl_cs11",output11,1024,1,1);
}


#endif