ofdm_mod.c 11.5 KB
Newer Older
1 2 3 4 5
/*
 * 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
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 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
 */

22 23 24 25 26 27 28 29 30 31
/*
* @defgroup _PHY_MODULATION_
* @ingroup _physical_layer_ref_implementation_
* @{
\section _phy_modulation_ OFDM Modulation Blocks
This section deals with basic functions for OFDM Modulation.


*/

32
#include "PHY/defs_eNB.h"
33
#include "PHY/defs_gNB.h"
34
#include "PHY/impl_defs_top.h"
35 36
#include "common/utils/LOG/log.h"
#include "common/utils/LOG/vcd_signal_dumper.h"
37
#include "modulation_common.h"
38
#include "PHY/LTE_TRANSPORT/transport_common_proto.h"
Raymond Knopp's avatar
Raymond Knopp committed
39
//#define DEBUG_OFDM_MOD
40 41


42 43
void normal_prefix_mod(int32_t *txdataF,int32_t *txdata,uint8_t nsymb,LTE_DL_FRAME_PARMS *frame_parms)
{
44 45


46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
  
  PHY_ofdm_mod(txdataF,        // input
	       txdata,         // output
	       frame_parms->ofdm_symbol_size,                
	       1,                 // number of symbols
	       frame_parms->nb_prefix_samples0,               // number of prefix samples
	       CYCLIC_PREFIX);
  PHY_ofdm_mod(txdataF+frame_parms->ofdm_symbol_size,        // input
	       txdata+OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES0,         // output
	       frame_parms->ofdm_symbol_size,                
	       nsymb-1,
	       frame_parms->nb_prefix_samples,               // number of prefix samples
	       CYCLIC_PREFIX);
  

  
62 63
}

Guy De Souza's avatar
Guy De Souza committed
64 65 66 67 68 69 70 71 72
void nr_normal_prefix_mod(int32_t *txdataF,int32_t *txdata,uint8_t nsymb,NR_DL_FRAME_PARMS *frame_parms)
{
  PHY_ofdm_mod(txdataF,        // input
	       txdata,         // output
	       frame_parms->ofdm_symbol_size,                
	       1,                 // number of symbols
	       frame_parms->nb_prefix_samples0,               // number of prefix samples
	       CYCLIC_PREFIX);
  PHY_ofdm_mod(txdataF+frame_parms->ofdm_symbol_size,        // input
Guy De Souza's avatar
Guy De Souza committed
73
	       txdata + frame_parms->ofdm_symbol_size + frame_parms->nb_prefix_samples0,         // output
Guy De Souza's avatar
Guy De Souza committed
74 75 76 77 78 79
	       frame_parms->ofdm_symbol_size,                
	       nsymb - 1,
	       frame_parms->nb_prefix_samples,               // number of prefix samples
	       CYCLIC_PREFIX);  
}

80
void PHY_ofdm_mod(int *input,                       /// pointer to complex input
81
                  int *output,                      /// pointer to complex output
82
                  int fftsize,            /// FFT_SIZE
83 84 85 86 87
                  unsigned char nb_symbols,         /// number of OFDM symbols
                  unsigned short nb_prefix_samples,  /// cyclic prefix length
                  Extension_t etype                /// type of extension
                 )
{
88

89 90
  if(nb_symbols == 0) return;

91
  short temp[4096*4] __attribute__((aligned(32)));
92 93 94 95 96 97 98 99
  unsigned short i,j;
  short k;

  volatile int *output_ptr=(int*)0;

  int *temp_ptr=(int*)0;
  void (*idft)(int16_t *,int16_t *, int);

100 101
  switch (fftsize) {
  case 128:
102 103
    idft = idft128;
    break;
104

105
  case 256:
106 107
    idft = idft256;
    break;
108

109
  case 512:
110 111
    idft = idft512;
    break;
112

113
  case 1024:
114 115
    idft = idft1024;
    break;
116

117 118 119 120 121
  case 1536:
    idft = idft1536;
    break;

  case 2048:
122 123
    idft = idft2048;
    break;
124

125 126
  case 3072:
    idft = idft3072;
Raymond Knopp's avatar
Raymond Knopp committed
127
    break;
128 129
  case 4096:
    idft = idft4096;
Raymond Knopp's avatar
Raymond Knopp committed
130
    break;
131 132 133 134 135 136
  default:
    idft = idft512;
    break;
  }

#ifdef DEBUG_OFDM_MOD
137 138
  printf("[PHY] OFDM mod (size %d,prefix %d) Symbols %d, input %p, output %p\n",
      fftsize,nb_prefix_samples,nb_symbols,input,output);
139 140 141
#endif


142 143

  for (i=0; i<nb_symbols; i++) {
144 145

#ifdef DEBUG_OFDM_MOD
146
    printf("[PHY] symbol %d/%d offset %d (%p,%p -> %p)\n",i,nb_symbols,i*fftsize+(i*nb_prefix_samples),input,&input[i*fftsize],&output[(i*fftsize) + ((i)*nb_prefix_samples)]);
147 148
#endif

149 150
#ifndef __AVX2__
    // handle 128-bit alignment for 128-bit SIMD (SSE4,NEON,AltiVEC)
Raymond Knopp's avatar
Raymond Knopp committed
151
    idft((int16_t *)&input[i*fftsize],
152
         (fftsize==128) ? (int16_t *)temp : (int16_t *)&output[(i*fftsize) + ((1+i)*nb_prefix_samples)],
153
         1);
154 155
#else
    // on AVX2 need 256-bit alignment
Raymond Knopp's avatar
Raymond Knopp committed
156
    idft((int16_t *)&input[i*fftsize],
157
         (int16_t *)temp,
158
         1);
159

160
#endif
161

162 163
    // Copy to frame buffer with Cyclic Extension
    // Note:  will have to adjust for synchronization offset!
164

165 166
    switch (etype) {
    case CYCLIC_PREFIX:
167
      output_ptr = &output[(i*fftsize) + ((1+i)*nb_prefix_samples)];
168
      temp_ptr = (int *)temp;
169

170 171 172

      //      msg("Doing cyclic prefix method\n");

173
#ifndef __AVX2__
174
      if (fftsize==128) 
175 176
#endif
      {
177
        /*for (j=0; j<fftsize ; j++) {
178
          output_ptr[j] = temp_ptr[j];
179 180
        }*/
        memcpy((void*)output_ptr,(void*)temp_ptr,fftsize<<2);
181
      }
182

183
      j=fftsize;
184 185 186

      for (k=-1; k>=-nb_prefix_samples; k--) {
        output_ptr[k] = output_ptr[--j];
187
      }
188

189
      break;
190

191
    case CYCLIC_SUFFIX:
192 193


194
      output_ptr = &output[(i*fftsize)+ (i*nb_prefix_samples)];
195

196
      temp_ptr = (int *)temp;
197

198 199
      //      msg("Doing cyclic suffix method\n");

200
      for (j=0; j<fftsize ; j++) {
201
        output_ptr[j] = temp_ptr[2*j];
202
      }
203 204 205


      for (j=0; j<nb_prefix_samples; j++)
206
        output_ptr[fftsize+j] = output_ptr[j];
207

208 209 210 211 212 213 214 215 216
      break;

    case ZEROS:

      break;

    case NONE:

      //      msg("NO EXTENSION!\n");
217
      output_ptr = &output[fftsize];
218 219

      temp_ptr = (int *)temp;
220

221
      for (j=0; j<fftsize ; j++) {
222
        output_ptr[j] = temp_ptr[2*j];
223 224 225 226 227 228 229 230 231 232 233


      }

      break;

    default:
      break;

    }

234 235


236
  }
237

238

239 240
}

Raymond Knopp's avatar
 
Raymond Knopp committed
241

242
void do_OFDM_mod(int32_t **txdataF, int32_t **txdata, uint32_t frame,uint16_t next_slot, LTE_DL_FRAME_PARMS *frame_parms)
243
{
Raymond Knopp's avatar
 
Raymond Knopp committed
244 245 246 247 248

  int aa, slot_offset, slot_offset_F;

  slot_offset_F = (next_slot)*(frame_parms->ofdm_symbol_size)*((frame_parms->Ncp==1) ? 6 : 7);
  slot_offset = (next_slot)*(frame_parms->samples_per_tti>>1);
249

Raymond Knopp's avatar
 
Raymond Knopp committed
250
  for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
251
    if (is_pmch_subframe(frame,next_slot>>1,frame_parms)) {
Raymond Knopp's avatar
 
Raymond Knopp committed
252
      if ((next_slot%2)==0) {
253 254 255
        LOG_D(PHY,"Frame %d, subframe %d: Doing MBSFN modulation (slot_offset %d)\n",frame,next_slot>>1,slot_offset);
        PHY_ofdm_mod(&txdataF[aa][slot_offset_F],        // input
                     &txdata[aa][slot_offset],         // output
256
                     frame_parms->ofdm_symbol_size,                
257 258 259 260 261 262 263
                     12,                 // number of symbols
                     frame_parms->ofdm_symbol_size>>2,               // number of prefix samples
                     CYCLIC_PREFIX);

        if (frame_parms->Ncp == EXTENDED)
          PHY_ofdm_mod(&txdataF[aa][slot_offset_F],        // input
                       &txdata[aa][slot_offset],         // output
264
                       frame_parms->ofdm_symbol_size,                
265 266 267 268 269 270 271 272 273 274
                       2,                 // number of symbols
                       frame_parms->nb_prefix_samples,               // number of prefix samples
                       CYCLIC_PREFIX);
        else {
          LOG_D(PHY,"Frame %d, subframe %d: Doing PDCCH modulation\n",frame,next_slot>>1);
          normal_prefix_mod(&txdataF[aa][slot_offset_F],
                            &txdata[aa][slot_offset],
                            2,
                            frame_parms);
        }
Raymond Knopp's avatar
 
Raymond Knopp committed
275
      }
276
    } else {
Raymond Knopp's avatar
 
Raymond Knopp committed
277
      if (frame_parms->Ncp == EXTENDED)
278 279
        PHY_ofdm_mod(&txdataF[aa][slot_offset_F],        // input
                     &txdata[aa][slot_offset],         // output
280
                     frame_parms->ofdm_symbol_size,                
281 282 283
                     6,                 // number of symbols
                     frame_parms->nb_prefix_samples,               // number of prefix samples
                     CYCLIC_PREFIX);
Raymond Knopp's avatar
 
Raymond Knopp committed
284
      else {
285 286 287 288
        normal_prefix_mod(&txdataF[aa][slot_offset_F],
                          &txdata[aa][slot_offset],
                          7,
                          frame_parms);
Raymond Knopp's avatar
 
Raymond Knopp committed
289
      }
290
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
291
  }
292

Raymond Knopp's avatar
 
Raymond Knopp committed
293 294
}

295
/*
296
// OFDM modulation for each symbol
297
void do_OFDM_mod_symbol(LTE_eNB_COMMON *eNB_common_vars, RU_COMMON *common, uint16_t next_slot, LTE_DL_FRAME_PARMS *frame_parms,int do_precoding)
298 299
{

300
  int aa, l, slot_offset, slot_offsetF;
301 302 303
  int32_t **txdataF    = eNB_common_vars->txdataF;
  int32_t **txdataF_BF = common->txdataF_BF;
  int32_t **txdata     = common->txdata;
304

305 306
  slot_offset  = (next_slot)*(frame_parms->samples_per_tti>>1);
  slot_offsetF = (next_slot)*(frame_parms->ofdm_symbol_size)*((frame_parms->Ncp==EXTENDED) ? 6 : 7);
307
  //printf("Thread %d starting ... aa %d (%llu)\n",omp_get_thread_num(),aa,rdtsc());
308 309 310 311
  for (l=0; l<frame_parms->symbols_per_tti>>1; l++) {
  
    for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {

312 313
      //printf("do_OFDM_mod_l, slot=%d, l=%d, NUMBER_OF_OFDM_CARRIERS=%d,OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES=%d\n",next_slot, l,NUMBER_OF_OFDM_CARRIERS,OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES);
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_BEAM_PRECODING,1);
314
      if (do_precoding==1) beam_precoding(txdataF,txdataF_BF,frame_parms,eNB_common_vars->beam_weights,next_slot,l,aa);
315 316
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_BEAM_PRECODING,0);

317 318
      //PMCH case not implemented... 

319 320
      if (frame_parms->Ncp == EXTENDED)
        PHY_ofdm_mod((do_precoding == 1)?txdataF_BF[aa]:&txdataF[aa][slot_offsetF+l*frame_parms->ofdm_symbol_size],         // input
321 322 323 324 325 326 327
                     &txdata[aa][slot_offset+l*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES],            // output
                     frame_parms->ofdm_symbol_size,       
                     1,                                   // number of symbols
                     frame_parms->nb_prefix_samples,      // number of prefix samples
                     CYCLIC_PREFIX);
      else {
        if (l==0) {
328
          PHY_ofdm_mod((do_precoding==1)?txdataF_BF[aa]:&txdataF[aa][slot_offsetF+l*frame_parms->ofdm_symbol_size],        // input
329 330 331 332 333 334 335
                       &txdata[aa][slot_offset],           // output
                       frame_parms->ofdm_symbol_size,      
                       1,                                  // number of symbols
                       frame_parms->nb_prefix_samples0,    // number of prefix samples
                       CYCLIC_PREFIX);
           
        } else {
336
	  PHY_ofdm_mod((do_precoding==1)?txdataF_BF[aa]:&txdataF[aa][slot_offsetF+l*frame_parms->ofdm_symbol_size],        // input
337 338 339 340 341
                       &txdata[aa][slot_offset+OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES0+(l-1)*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES],           // output
                       frame_parms->ofdm_symbol_size,      
                       1,                                  // number of symbols
                       frame_parms->nb_prefix_samples,     // number of prefix samples
                       CYCLIC_PREFIX);
342

343 344
          //printf("txdata[%d][%d]=%d\n",aa,slot_offset+OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES0+(l-1)*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,txdata[aa][slot_offset+OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES0+(l-1)*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES]);
 
345 346 347 348 349 350
        }
      }
    }
  }

}
351
*/