lte_dl_cell_spec.c 8.82 KB
Newer Older
ghaddab's avatar
ghaddab committed
1
/*******************************************************************************
2
    OpenAirInterface
ghaddab's avatar
ghaddab committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16
    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
17 18
    along with OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
ghaddab's avatar
ghaddab committed
19 20 21 22 23
   see <http://www.gnu.org/licenses/>.

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

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
ghaddab's avatar
ghaddab committed
27 28

 *******************************************************************************/
29 30 31 32 33 34 35 36 37 38 39 40 41 42
#ifdef USER_MODE
#include <stdio.h>
#include <stdlib.h>
#endif

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

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



//Calibration
43
int lte_dl_cell_spec_SS(PHY_VARS_eNB *eNB,
44
                        int32_t *output,
45 46 47 48 49
                        short amp,
                        unsigned char Ns,
                        unsigned char l,//nb of sym per slot
                        unsigned char p)  //nb of antennas
{
50 51 52

  unsigned char nu,mprime,mprime_dword,mprime_qpsk_symb,m;
  unsigned short k,a;
53
  int32_t qpsk[4];
54 55 56 57 58 59 60 61 62 63

  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;
Raymond Knopp's avatar
 
Raymond Knopp committed
64

65 66 67 68 69 70 71 72 73 74

  if ((p==0) && (l==0) )
    nu = 0;
  else if ((p==0) && (l>0))
    nu = 3;
  else if ((p==1) && (l==0))
    nu = 3;
  else if ((p==1) && (l>0))
    nu = 0;
  else {
75
    printf("lte_dl_cell_spec: p %d, l %d -> ERROR\n",p,l);
76 77 78
    return(-1);
  }

79
  mprime = 110 - eNB->frame_parms.N_RB_DL;
80

81
  k = (nu + eNB->frame_parms.nushift);
82

83 84 85
  if (k > 6)//b
    k -=6;//b

86
  k+=eNB->frame_parms.first_carrier_offset;
Raymond Knopp's avatar
 
Raymond Knopp committed
87

88
  for (m=0; m<eNB->frame_parms.N_RB_DL<<1; m++) { // loop over pilots in one slot/symbol, 2*N_RB_DL pilots
89 90 91 92

    mprime_dword     = mprime>>4;
    mprime_qpsk_symb = mprime&0xf;

93
    // this is r_mprime from 3GPP 36-211 6.10.1.2
94
    output[k] = qpsk[(eNB->lte_gold_table[Ns][l][mprime_dword]>>(2*mprime_qpsk_symb))&3];
95 96
    //output[k] = (lte_gold_table[eNB_offset][Ns][l][mprime_dword]>>(2*mprime_qpsk_symb))&3;
#ifdef DEBUG_DL_CELL_SPEC
97
    printf("Ns %d, l %d, m %d,mprime_dword %d, mprime_qpsk_symbol %d\n",
98
              Ns,l,m,mprime_dword,mprime_qpsk_symb);
99
    printf("index = %d (k %d)\n",(eNB->lte_gold_table[Ns][l][mprime_dword]>>(2*mprime_qpsk_symb))&3,k);
100
#endif
101 102 103

    mprime++;
#ifdef DEBUG_DL_CELL_SPEC
104

105
    if (m<4)
106 107
      printf("Ns %d, l %d output[%d] = (%d,%d)\n",Ns,l,k,((short *)&output[k])[0],((short *)&output[k])[1]);

108 109
#endif
    k+=6;//b
110

111
    if (k >= eNB->frame_parms.ofdm_symbol_size) {
112
      k++;  // skip DC carrier
113
      k-=eNB->frame_parms.ofdm_symbol_size;
114
    }
115

116 117
    //    printf("** k %d\n",k);
  }
118

119 120 121 122
  return(0);
}


123
int lte_dl_cell_spec(PHY_VARS_eNB *eNB,
124
                     int32_t *output,
125 126 127 128 129
                     short amp,
                     unsigned char Ns,
                     unsigned char l,
                     unsigned char p)
{
130 131 132

  unsigned char nu,mprime,mprime_dword,mprime_qpsk_symb,m;
  unsigned short k,a;
133
  int32_t qpsk[4];
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

  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;

  if ((p==0) && (l==0) )
    nu = 0;
  else if ((p==0) && (l>0))
    nu = 3;
  else if ((p==1) && (l==0))
    nu = 3;
  else if ((p==1) && (l>0))
    nu = 0;
  else {
154
    printf("lte_dl_cell_spec: p %d, l %d -> ERROR\n",p,l);
155 156 157
    return(-1);
  }

158
  mprime = 110 - eNB->frame_parms.N_RB_DL;
159

160
  k = (nu + eNB->frame_parms.nushift);
161

162 163 164
  if (k > 5)
    k -=6;

165
  k+=eNB->frame_parms.first_carrier_offset;
Raymond Knopp's avatar
 
Raymond Knopp committed
166

167 168 169 170
  DevAssert( Ns < 20 );
  DevAssert( l < 2 );
  DevAssert( mprime>>4 < 14 );

171
  for (m=0; m<eNB->frame_parms.N_RB_DL<<1; m++) {
172 173 174 175

    mprime_dword     = mprime>>4;
    mprime_qpsk_symb = mprime&0xf;

176
    // this is r_mprime from 3GPP 36-211 6.10.1.2
177
    output[k] = qpsk[(eNB->lte_gold_table[Ns][l][mprime_dword]>>(2*mprime_qpsk_symb))&3];
178 179
    //output[k] = (lte_gold_table[eNB_offset][Ns][l][mprime_dword]>>(2*mprime_qpsk_symb))&3;
#ifdef DEBUG_DL_CELL_SPEC
180
    printf("Ns %d, l %d, m %d,mprime_dword %d, mprime_qpsk_symbol %d\n",
181
        Ns,l,m,mprime_dword,mprime_qpsk_symb);
182
    printf("index = %d (k %d)\n",(eNB->lte_gold_table[Ns][l][mprime_dword]>>(2*mprime_qpsk_symb))&3,k);
183
#endif
184 185 186

    mprime++;
#ifdef DEBUG_DL_CELL_SPEC
187

188
    if (m<4)
189 190
      printf("Ns %d, l %d output[%d] = (%d,%d)\n",Ns,l,k,((short *)&output[k])[0],((short *)&output[k])[1]);

191 192
#endif
    k+=6;
193

194
    if (k >= eNB->frame_parms.ofdm_symbol_size) {
195
      k++;  // skip DC carrier
196
      k-=eNB->frame_parms.ofdm_symbol_size;
197
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
198

199 200
    //    printf("** k %d\n",k);
  }
201

202 203 204
  return(0);
}

205
int lte_dl_cell_spec_rx(PHY_VARS_UE *ue,
206 207 208 209 210 211 212
                        uint8_t eNB_offset,
                        int *output,
                        unsigned char Ns,
                        unsigned char l,
                        unsigned char p)
{

213 214 215 216 217

  unsigned char mprime,mprime_dword,mprime_qpsk_symb,m;
  unsigned short k=0;
  unsigned int qpsk[4];
  short pamp;
218

219 220 221 222 223 224 225 226 227 228 229 230 231 232
  // 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;

233
  mprime = 110 - ue->frame_parms.N_RB_DL;
234

235
  for (m=0; m<ue->frame_parms.N_RB_DL<<1; m++) {
236 237 238 239

    mprime_dword     = mprime>>4;
    mprime_qpsk_symb = mprime&0xf;

240
    // this is r_mprime from 3GPP 36-211 6.10.1.2
241
    output[k] = qpsk[(ue->lte_gold_table[eNB_offset][Ns][l][mprime_dword]>>(2*mprime_qpsk_symb))&3];
242 243
#ifdef DEBUG_DL_CELL_SPEC
    printf("Ns %d, l %d, m %d,mprime_dword %d, mprime_qpsk_symbol %d\n",
244
           Ns,l,m,mprime_dword,mprime_qpsk_symb);
245
    printf("index = %d (k %d)\n",(ue->lte_gold_table[eNB_offset][Ns][l][mprime_dword]>>(2*mprime_qpsk_symb))&3,k);
246
#endif
247 248 249

    mprime++;
#ifdef DEBUG_DL_CELL_SPEC
250

251
    if (m<4)
252 253
      printf("Ns %d l %d output[%d] = (%d,%d)\n",Ns,l,k,((short *)&output[k])[0],((short *)&output[k])[1]);

254 255 256 257
#endif
    k++;
    //    printf("** k %d\n",k);
  }
258

259 260 261 262 263 264 265 266 267 268 269
  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);
270 271
main()
{
272 273 274 275 276 277 278 279 280

  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));
281
  memset(output01,0,1024*sizeof(int));
282 283 284 285 286 287
  memset(output10,0,1024*sizeof(int));
  memset(output11,0,1024*sizeof(int));

  lte_gold(Nid_cell,Ncp);

  lte_dl_cell_spec(output00,
288 289 290 291 292 293 294 295 296
                   ONE_OVER_SQRT2_Q15,
                   50,
                   Nid_cell,
                   Ncp,
                   0,
                   0,
                   0,
                   0);

297
  lte_dl_cell_spec(output10,
298 299 300 301 302 303 304 305
                   ONE_OVER_SQRT2_Q15,
                   50,
                   Nid_cell,
                   Ncp,
                   0,
                   1,
                   0,
                   0);
306 307

  lte_dl_cell_spec(output01,
308 309 310 311 312 313 314 315
                   ONE_OVER_SQRT2_Q15,
                   50,
                   Nid_cell,
                   Ncp,
                   0,
                   0,
                   1,
                   0);
316 317

  lte_dl_cell_spec(output11,
318 319 320 321 322 323 324 325 326
                   ONE_OVER_SQRT2_Q15,
                   50,
                   Nid_cell,
                   Ncp,
                   0,
                   1,
                   1,
                   0);

327 328 329

  write_output("dl_cell_spec00.m","dl_cs00",output00,1024,1,1);
  write_output("dl_cell_spec01.m","dl_cs01",output01,1024,1,1);
330
  write_output("dl_cell_spec10.m","dl_cs10",output10,1024,1,1);
331
  write_output("dl_cell_spec11.m","dl_cs11",output11,1024,1,1);
332 333
}

334
#endif