srs_modulation.c 11.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * 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
 */
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

/*! \file PHY/LTE_TRANSPORT/srs_modulation.c
* \brief Top-level routines for generating sounding reference signal (SRS) V8.6 2009-03
* \author R. Knopp, F. Kaltenberger
* \date 2011
* \version 0.1
* \company Eurecom
* \email: knopp@eurecom.fr, florian.kaltenberger@eurecom.fr
* \note
* \warning
*/
#include "PHY/defs.h"
#include "extern.h"
#include "UTIL/LOG/log.h"

unsigned short msrsb_6_40[8][4] = {{36,12,4,4},
37 38 39 40 41 42 43 44
  {32,16,8,4},
  {24,4,4,4},
  {20,4,4,4},
  {16,4,4,4},
  {12,4,4,4},
  {8,4,4,4},
  {4,4,4,4}
};
45 46

unsigned short msrsb_41_60[8][4] = {{48,24,12,4},
47 48 49 50 51 52 53 54
  {48,16,8,4},
  {40,20,4,4},
  {36,12,4,4},
  {32,16,8,4},
  {24,4,4,4},
  {20,4,4,4},
  {16,4,4,4}
};
55 56

unsigned short msrsb_61_80[8][4] = {{72,24,12,4},
57 58 59 60 61 62 63 64
  {64,32,16,4},
  {60,20,4,4},
  {48,24,12,4},
  {48,16,8,4},
  {40,20,4,4},
  {36,12,4,4},
  {32,16,8,4}
};
65 66

unsigned short msrsb_81_110[8][4] = {{96,48,24,4},
67 68 69 70 71 72 73 74
  {96,32,16,4},
  {80,40,20,4},
  {72,24,12,4},
  {64,32,16,4},
  {60,20,4,4},
  {48,24,12,4},
  {48,16,8,4}
};
75 76

unsigned short Nb_6_40[8][4] = {{36,12,4,4},
77 78 79 80 81 82 83 84
  {32,16,8,4},
  {24,4,4,4},
  {20,4,4,4},
  {16,4,4,4},
  {12,4,4,4},
  {8,4,4,4},
  {4,4,4,4}
};
85 86

unsigned short Nb_41_60[8][4] = {{48,24,12,4},
87 88 89 90 91 92 93 94
  {48,16,8,4},
  {40,20,4,4},
  {36,12,4,4},
  {32,16,8,4},
  {24,4,4,4},
  {20,4,4,4},
  {16,4,4,4}
};
95 96

unsigned short Nb_61_80[8][4] = {{72,24,12,4},
97 98 99 100 101 102 103 104
  {64,32,16,4},
  {60,20,4,4},
  {48,24,12,4},
  {48,16,8,4},
  {40,20,4,4},
  {36,12,4,4},
  {32,16,8,4}
};
105 106

unsigned short Nb_81_110[8][4] = {{96,48,24,4},
107 108 109 110 111 112 113 114
  {96,32,16,4},
  {80,40,20,4},
  {72,24,12,4},
  {64,32,16,4},
  {60,20,4,4},
  {48,24,12,4},
  {48,16,8,4}
};
115 116 117 118 119 120 121 122

unsigned short transmission_offset_tdd[16] = {2,6,10,18,14,22,26,30,70,74,194,326,586,210};

int compareints (const void * a, const void * b)
{
  return ( *(unsigned short*)a - *(unsigned short*)b );
}

123 124 125 126 127 128
#define DEBUG_SRS
int32_t generate_srs(LTE_DL_FRAME_PARMS *frame_parms,
		     SOUNDINGRS_UL_CONFIG_DEDICATED *soundingrs_ul_config_dedicated,
		     int32_t *txptr,
		     int16_t amp,
		     uint32_t subframe)
129
{
130

131
  uint16_t msrsb=0,Nb=0,nb,b,msrs0=0,k,Msc_RS,Msc_RS_idx,carrier_pos;
132
  uint16_t *Msc_idx_ptr;
133
  int32_t k0;
134
  //uint32_t subframe_offset;
135 136 137 138 139
  uint8_t Bsrs  = soundingrs_ul_config_dedicated->srs_Bandwidth;
  uint8_t Csrs  = frame_parms->soundingrs_ul_config_common.srs_BandwidthConfig;
  uint8_t Ssrs  = frame_parms->soundingrs_ul_config_common.srs_SubframeConfig;
  uint8_t n_RRC = soundingrs_ul_config_dedicated->freqDomainPosition;
  uint8_t kTC   = soundingrs_ul_config_dedicated->transmissionComb;
140

fnabet's avatar
fnabet committed
141 142 143 144 145 146 147 148 149 150
  // u is the PUCCH sequence-group number defined in Section 5.5.1.3
  // ν is the base sequence number defined in Section 5.5.1.4
  uint32_t u=frame_parms->pucch_config_common.grouphop[1+(subframe<<1)];;
  uint32_t v=frame_parms->pusch_config_common.ul_ReferenceSignalsPUSCH.seqhop[1+(subframe<<1)];

  LOG_D(PHY,"SRS root sequence: u %d, v %d\n",u,v);
  LOG_D(PHY,"CommonSrsConfig:    Csrs %d, Ssrs %d, AnSrsSimultan %d \n",Csrs,Ssrs,frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission);
  LOG_D(PHY,"DedicatedSrsConfig: Bsrs %d, bhop %d, nRRC %d, Isrs %d, kTC %d, n_SRS %d\n",Bsrs,soundingrs_ul_config_dedicated->srs_HoppingBandwidth,n_RRC
                                                                                       ,soundingrs_ul_config_dedicated->srs_ConfigIndex,kTC
                                                                                       ,soundingrs_ul_config_dedicated->cyclicShift);
151 152 153 154 155

  if (frame_parms->N_RB_UL < 41) {
    msrs0 = msrsb_6_40[Csrs][0];
    msrsb = msrsb_6_40[Csrs][Bsrs];
    Nb    = Nb_6_40[Csrs][Bsrs];
156
  } else if (frame_parms->N_RB_UL < 61) {
157 158 159
    msrs0 = msrsb_41_60[Csrs][0];
    msrsb = msrsb_41_60[Csrs][Bsrs];
    Nb    = Nb_41_60[Csrs][Bsrs];
160
  } else if (frame_parms->N_RB_UL < 81) {
161 162 163
    msrs0 = msrsb_61_80[Csrs][0];
    msrsb = msrsb_61_80[Csrs][Bsrs];
    Nb    = Nb_61_80[Csrs][Bsrs];
164
  } else if (frame_parms->N_RB_UL <111) {
165 166 167 168 169 170
    msrs0 = msrsb_81_110[Csrs][0];
    msrsb = msrsb_81_110[Csrs][Bsrs];
    Nb    = Nb_81_110[Csrs][Bsrs];
  }

  Msc_RS = msrsb * 6;
fnabet's avatar
fnabet committed
171
  k0 = ( ( (int16_t)(frame_parms->N_RB_UL>>1) - (int16_t)(msrs0>>1) ) * 12 ) + kTC;
172 173
  nb  = (4*n_RRC/msrsb)%Nb;

174
  for (b=0; b<=Bsrs; b++) {
175 176 177 178
    k0 += 2*nb*Msc_RS;
  }

  if (k0<0) {
179
    LOG_E(PHY,"generate_srs: invalid parameter set msrs0=%d, msrsb=%d, Nb=%d => nb=%d, k0=%d\n",msrs0,msrsb,Nb,nb,k0);
180 181 182 183
    return(-1);
  }

#ifdef USER_MODE
184
  Msc_idx_ptr = (uint16_t*) bsearch((uint16_t*) &Msc_RS, (uint16_t*) dftsizes, 33, sizeof(uint16_t), compareints);
185

186 187 188
  if (Msc_idx_ptr)
    Msc_RS_idx = Msc_idx_ptr - dftsizes;
  else {
189
    LOG_E(PHY,"generate_srs: index for Msc_RS=%d not found\n",Msc_RS);
190 191
    return(-1);
  }
192

193
#else //stdlib not availiable in RTAI
194

195 196 197 198 199
  if (Msc_RS==216)
    Msc_RS_idx = 12;
  else if (Msc_RS==144)
    Msc_RS_idx = 9;
  else {
200
    LOG_E(PHY,"generate_srs: index for Msc_RS=%d not implemented\n",Msc_RS);
201 202
    return(-1);
  }
203

204 205 206
#endif

#ifdef DEBUG_SRS
207
  LOG_D(PHY,"generate_srs_tx: Msc_RS = %d, Msc_RS_idx = %d, k0 = %d\n",Msc_RS, Msc_RS_idx,k0);
208 209
#endif

fnabet's avatar
fnabet committed
210 211 212 213
    carrier_pos = (frame_parms->first_carrier_offset + k0);
    if (carrier_pos>frame_parms->ofdm_symbol_size) {
        carrier_pos -= frame_parms->ofdm_symbol_size;
    }
214

215
    for (k=0; k<Msc_RS; k++) {
fnabet's avatar
fnabet committed
216 217 218
      int32_t real = ((int32_t) amp * (int32_t) ul_ref_sigs[u][v][Msc_RS_idx][k<<1])     >> 15;
      int32_t imag = ((int32_t) amp * (int32_t) ul_ref_sigs[u][v][Msc_RS_idx][(k<<1)+1]) >> 15;
      txptr[carrier_pos] = (real&0xFFFF) + ((imag<<16)&0xFFFF0000);
219 220


fnabet's avatar
fnabet committed
221
      carrier_pos = carrier_pos+2;
222

fnabet's avatar
fnabet committed
223 224
      if (carrier_pos >= frame_parms->ofdm_symbol_size)
        carrier_pos=carrier_pos-frame_parms->ofdm_symbol_size;
225
    }
226 227 228 229

  return(0);
}

230 231
int generate_srs_tx_emul(PHY_VARS_UE *phy_vars_ue,uint8_t subframe)
{
232 233

  LOG_D(PHY,"[UE] generate_srs_tx_emul for subframe %d\n",subframe);
234
  return(0);
235 236
}

237
#if 0
238
int generate_srs_rx(LTE_DL_FRAME_PARMS *frame_parms,
239 240 241
                    SOUNDINGRS_UL_CONFIG_DEDICATED *soundingrs_ul_config_dedicated,
                    int *txdataF)
{
242

243 244
  uint16_t msrsb=0,Nb=0,nb,b,msrs0=0,k,Msc_RS,Msc_RS_idx,carrier_pos;
  uint16_t *Msc_idx_ptr;
245
  int k0;
246 247 248 249
  uint8_t Bsrs  = soundingrs_ul_config_dedicated->srs_Bandwidth;
  uint8_t Csrs  = frame_parms->soundingrs_ul_config_common.srs_BandwidthConfig;
  uint8_t n_RRC = soundingrs_ul_config_dedicated->freqDomainPosition;
  uint8_t kTC   = soundingrs_ul_config_dedicated->transmissionComb;
250 251 252 253 254

  if (frame_parms->N_RB_UL < 41) {
    msrs0 = msrsb_6_40[Csrs][0];
    msrsb = msrsb_6_40[Csrs][Bsrs];
    Nb    = Nb_6_40[Csrs][Bsrs];
255
  } else if (frame_parms->N_RB_UL < 61) {
256 257 258
    msrs0 = msrsb_41_60[Csrs][0];
    msrsb = msrsb_41_60[Csrs][Bsrs];
    Nb    = Nb_41_60[Csrs][Bsrs];
259
  } else if (frame_parms->N_RB_UL < 81) {
260 261 262
    msrs0 = msrsb_61_80[Csrs][0];
    msrsb = msrsb_61_80[Csrs][Bsrs];
    Nb    = Nb_61_80[Csrs][Bsrs];
263
  } else if (frame_parms->N_RB_UL <111) {
264 265 266 267 268 269 270 271 272
    msrs0 = msrsb_81_110[Csrs][0];
    msrsb = msrsb_81_110[Csrs][Bsrs];
    Nb    = Nb_81_110[Csrs][Bsrs];
  }

  Msc_RS = msrsb * 6;
  k0 = (((frame_parms->N_RB_UL>>1)-(msrs0>>1))*12) + kTC;
  nb  = (4*n_RRC/msrsb)%Nb;

273
  for (b=0; b<=Bsrs; b++) {
274 275 276 277
    k0 += 2*nb*Msc_RS;
  }

  if (k0<0) {
278
    LOG_E(PHY,"Invalid parameter set msrs0=%d, msrsb=%d, Nb=%d => nb=%d, k0=%d\n",msrs0,msrsb,Nb,nb,k0);
279 280 281 282
    return(-1);
  }

#ifdef USER_MODE
283
  Msc_idx_ptr = (uint16_t*) bsearch((uint16_t*) &Msc_RS, (uint16_t*) dftsizes, 33, sizeof(uint16_t), compareints);
284

285 286 287
  if (Msc_idx_ptr)
    Msc_RS_idx = Msc_idx_ptr - dftsizes;
  else {
288
    LOG_E(PHY,"generate_srs: index for Msc_RS=%d not found\n",Msc_RS);
289 290
    return(-1);
  }
291

292
#else //stdlib not availiable in RTAI
293

294 295 296 297 298
  if (Msc_RS==216)
    Msc_RS_idx = 12;
  else if (Msc_RS==144)
    Msc_RS_idx = 9;
  else {
299
    LOG_E(PHY,"generate_srs: index for Msc_RS=%d not implemented\n",Msc_RS);
300 301
    return(-1);
  }
302

303 304 305
#endif

#ifdef DEBUG_SRS
306
  LOG_I(PHY,"generate_srs_rx: Msc_RS = %d, Msc_RS_idx = %d, k0=%d\n",Msc_RS, Msc_RS_idx,k0);
307 308 309 310
#endif

  carrier_pos = (frame_parms->first_carrier_offset + k0) % frame_parms->ofdm_symbol_size;

311
  for (k=0; k<Msc_RS; k++) {
312 313
    ((short*) txdataF)[carrier_pos<<1]   = ul_ref_sigs_rx[0][0][Msc_RS_idx][k<<1];
    ((short*) txdataF)[(carrier_pos<<1)+1] = ul_ref_sigs_rx[0][0][Msc_RS_idx][(k<<1)+1];
314
    carrier_pos+=2;
315 316

    if (carrier_pos >= frame_parms->ofdm_symbol_size)
317 318
      carrier_pos=1;
  }
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 353 354 355
  /*
  for (k=0;k<Msc_RS;k++) {
    if ((ul_ref_sigs[0][0][Msc_RS_idx][k<<1] >= 0) && (ul_ref_sigs[0][0][Msc_RS_idx][(k<<1)+1] >= 0)) {
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)] = ONE_OVER_SQRT2_Q15;
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)+1] = ONE_OVER_SQRT2_Q15;
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)+2] = -ONE_OVER_SQRT2_Q15;
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)+3] = ONE_OVER_SQRT2_Q15;
    }
    else if ((ul_ref_sigs[0][0][Msc_RS_idx][k<<1] >= 0) && (ul_ref_sigs[0][0][Msc_RS_idx][(k<<1)+1] < 0)) {
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)] = ONE_OVER_SQRT2_Q15;
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)+1] = -ONE_OVER_SQRT2_Q15;
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)+2] = ONE_OVER_SQRT2_Q15;
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)+3] = ONE_OVER_SQRT2_Q15;
    }
    else if ((ul_ref_sigs[0][0][Msc_RS_idx][k<<1] < 0) && (ul_ref_sigs[0][0][Msc_RS_idx][(k<<1)+1] >= 0)) {
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)] = -ONE_OVER_SQRT2_Q15;
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)+1] = ONE_OVER_SQRT2_Q15;
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)+2] = -ONE_OVER_SQRT2_Q15;
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)+3] = -ONE_OVER_SQRT2_Q15;
    }
    else if ((ul_ref_sigs[0][0][Msc_RS_idx][k<<1] < 0) && (ul_ref_sigs[0][0][Msc_RS_idx][(k<<1)+1] < 0)) {
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)] = -ONE_OVER_SQRT2_Q15;
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)+1] = -ONE_OVER_SQRT2_Q15;
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)+2] = ONE_OVER_SQRT2_Q15;
      ((short*) txdataF)[4*(symbol_offset + carrier_pos)+3] = -ONE_OVER_SQRT2_Q15;
    }

    carrier_pos+=2;
    if (carrier_pos >= frame_parms->ofdm_symbol_size)
      carrier_pos=0;
  }
  */

  //  write_output("srs_rx.m","srsrx",txdataF,1024,2,1);
  return(0);
}
356
#endif
357 358

#ifdef MAIN
359 360
main()
{
361 362 363 364


}
#endif