tools_defs.h 15 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
 * 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
 */
ghaddab's avatar
ghaddab committed
21

22 23 24 25 26 27 28 29 30
#ifndef __PHY_TOOLS_DEFS__H__
#define __PHY_TOOLS_DEFS__H__

/** @addtogroup _PHY_DSP_TOOLS_


* @{

*/
31

32
#include <stdint.h>
33
#include "PHY/sse_intrin.h"
34 35


36
struct complex {
37 38 39 40
  double x;
  double y;
};

41
struct complexf {
42 43 44 45
  float r;
  float i;
};

46
struct complex16 {
47
  int16_t r;
48
  int16_t i;
49 50
};

51
struct complex32 {
52 53
  int32_t r;
  int32_t i;
54 55
};

56 57
//cmult_sv.h

58
/*!\fn void multadd_real_vector_complex_scalar(int16_t *x,int16_t *alpha,int16_t *y,uint32_t N)
59
This function performs componentwise multiplication and accumulation of a complex scalar and a real vector.
60
@param x Vector input (Q1.15)
61 62 63 64 65 66
@param alpha Scalar input (Q1.15) in the format  |Re0 Im0|
@param y Output (Q1.15) in the format  |Re0  Im0 Re1 Im1|,......,|Re(N-1)  Im(N-1) Re(N-1) Im(N-1)|
@param N Length of x WARNING: N>=8

The function implemented is : \f$\mathbf{y} = y + \alpha\mathbf{x}\f$
*/
67
void multadd_real_vector_complex_scalar(int16_t *x,
68 69 70 71
                                        int16_t *alpha,
                                        int16_t *y,
                                        uint32_t N
                                       );
72

73
/*!\fn void multadd_complex_vector_real_scalar(int16_t *x,int16_t alpha,int16_t *y,uint8_t zero_flag,uint32_t N)
74
This function performs componentwise multiplication and accumulation of a real scalar and a complex vector.
75
@param x Vector input (Q1.15) in the format |Re0 Im0|Re1 Im 1| ...
76 77 78 79 80 81 82
@param alpha Scalar input (Q1.15) in the format  |Re0|
@param y Output (Q1.15) in the format  |Re0  Im0 Re1 Im1|,......,|Re(N-1)  Im(N-1) Re(N-1) Im(N-1)|
@param zero_flag Set output (y) to zero prior to accumulation
@param N Length of x WARNING: N>=8

The function implemented is : \f$\mathbf{y} = y + \alpha\mathbf{x}\f$
*/
83
void multadd_complex_vector_real_scalar(int16_t *x,
84 85 86 87
                                        int16_t alpha,
                                        int16_t *y,
                                        uint8_t zero_flag,
                                        uint32_t N);
88

89 90
int rotate_cpx_vector(int16_t *x,
                      int16_t *alpha,
91
                      int16_t *y,
92 93
                      uint32_t N,
                      uint16_t output_shift);
94 95 96 97




98
/*!\fn void init_fft(uint16_t size,uint8_t logsize,uint16_t *rev)
99 100 101 102 103 104
\brief Initialize the FFT engine for a given size
@param size Size of the FFT
@param logsize log2(size)
@param rev Pointer to bit-reversal permutation array
*/

105 106 107 108 109 110 111 112 113 114
//cmult_vv.c
/*!
  Multiply elementwise the complex conjugate of x1 with x2. 
  @param x1       - input 1    in the format  |Re0 Im0 Re1 Im1|,......,|Re(N-2)  Im(N-2) Re(N-1) Im(N-1)|
              We assume x1 with a dinamic of 15 bit maximum
  @param x2       - input 2    in the format  |Re0 Im0 Re1 Im1|,......,|Re(N-2)  Im(N-2) Re(N-1) Im(N-1)|
              We assume x2 with a dinamic of 14 bit maximum
  @param y        - output     in the format  |Re0 Im0 Re1 Im1|,......,|Re(N-2)  Im(N-2) Re(N-1) Im(N-1)|
  @param N        - the size f the vectors (this function does N cpx mpy. WARNING: N>=4;
  @param output_shift  - shift to be applied to generate output
115
  @param madd - if not zero result is added to output
116 117 118 119 120 121
*/

int mult_cpx_conj_vector(int16_t *x1,
                         int16_t *x2,
                         int16_t *y,
                         uint32_t N,
122 123
                         int output_shift,
			 int madd);
124

125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
/*!
  Element-wise multiplication and accumulation of two complex vectors x1 and x2.
  @param x1       - input 1    in the format  |Re0 Im0 Re1 Im1|,......,|Re(N-2)  Im(N-2) Re(N-1) Im(N-1)|
              We assume x1 with a dinamic of 15 bit maximum
  @param x2       - input 2    in the format  |Re0 Im0 Re1 Im1|,......,|Re(N-2)  Im(N-2) Re(N-1) Im(N-1)|
              We assume x2 with a dinamic of 14 bit maximum
  @param y        - output     in the format  |Re0 Im0 Re1 Im1|,......,|Re(N-2)  Im(N-2) Re(N-1) Im(N-1)|
  @param zero_flag Set output (y) to zero prior to accumulation
  @param N        - the size f the vectors (this function does N cpx mpy. WARNING: N>=4;
  @param output_shift  - shift to be applied to generate output
*/

int multadd_cpx_vector(int16_t *x1,
                    int16_t *x2,
                    int16_t *y,
                    uint8_t zero_flag,
                    uint32_t N,
		       int output_shift);
143

lukashov's avatar
lukashov committed
144 145 146 147 148 149
int mult_cpx_vector(int16_t *x1,
                    int16_t  *x2,
                    int16_t *y,
                    uint32_t N,
                    int output_shift);

150
// lte_dfts.c
151
void init_fft(uint16_t size,
152 153
              uint8_t logsize,
              uint16_t *rev);
154

155
/*!\fn void fft(int16_t *x,int16_t *y,int16_t *twiddle,uint16_t *rev,uint8_t log2size,uint8_t scale,uint8_t input_fmt)
156 157 158 159 160 161 162 163 164
This function performs optimized fixed-point radix-2 FFT/IFFT.
@param x Input
@param y Output in format: [Re0,Im0,Re0,Im0, Re1,Im1,Re1,Im1, ....., Re(N-1),Im(N-1),Re(N-1),Im(N-1)]
@param twiddle Twiddle factors
@param rev bit-reversed permutation
@param log2size Base-2 logarithm of FFT size
@param scale Total number of shifts (should be log2size/2 for normalized FFT)
@param input_fmt (0 - input is in complex Q1.15 format, 1 - input is in complex redundant Q1.15 format)
*/
165
/*void fft(int16_t *x,
166 167 168 169 170 171 172
         int16_t *y,
         int16_t *twiddle,
         uint16_t *rev,
         uint8_t log2size,
         uint8_t scale,
         uint8_t input_fmt
        );
173
*/
174

175
void idft1536(int16_t *sigF,int16_t *sig,int scale);
176

Raymond Knopp's avatar
Raymond Knopp committed
177
void idft6144(int16_t *sigF,int16_t *sig,int scale);
178

Raymond Knopp's avatar
Raymond Knopp committed
179
void idft12288(int16_t *sigF,int16_t *sig,int scale);
180

Raymond Knopp's avatar
Raymond Knopp committed
181
void idft18432(int16_t *sigF,int16_t *sig,int scale);
182

Raymond Knopp's avatar
Raymond Knopp committed
183
void idft3072(int16_t *sigF,int16_t *sig,int scale);
184

Raymond Knopp's avatar
Raymond Knopp committed
185
void idft24576(int16_t *sigF,int16_t *sig,int scale);
186

187
void dft1536(int16_t *sigF,int16_t *sig,int scale);
188

Raymond Knopp's avatar
Raymond Knopp committed
189
void dft6144(int16_t *sigF,int16_t *sig,int scale);
190

Raymond Knopp's avatar
Raymond Knopp committed
191
void dft12288(int16_t *sigF,int16_t *sig,int scale);
192

Raymond Knopp's avatar
Raymond Knopp committed
193
void dft18432(int16_t *sigF,int16_t *sig,int scale);
194

Raymond Knopp's avatar
Raymond Knopp committed
195
void dft3072(int16_t *sigF,int16_t *sig,int scale);
196

Raymond Knopp's avatar
Raymond Knopp committed
197
void dft24576(int16_t *sigF,int16_t *sig,int scale);
198 199


200
/*!\fn int32_t rotate_cpx_vector(int16_t *x,int16_t *alpha,int16_t *y,uint32_t N,uint16_t output_shift)
201
This function performs componentwise multiplication of a vector with a complex scalar.
202
@param x Vector input (Q1.15)  in the format  |Re0  Im0|,......,|Re(N-1) Im(N-1)|
203
@param alpha Scalar input (Q1.15) in the format  |Re0 Im0|
204
@param y Output (Q1.15) in the format  |Re0  Im0|,......,|Re(N-1) Im(N-1)|
205 206 207 208 209
@param N Length of x WARNING: N>=4
@param output_shift Number of bits to shift output down to Q1.15 (should be 15 for Q1.15 inputs) WARNING: log2_amp>0 can cause overflow!!

The function implemented is : \f$\mathbf{y} = \alpha\mathbf{x}\f$
*/
210
int32_t rotate_cpx_vector(int16_t *x,
211 212 213
                          int16_t *alpha,
                          int16_t *y,
                          uint32_t N,
214
                          uint16_t output_shift);
215 216


217
//cadd_sv.c
218

219
/*!\fn int32_t add_cpx_vector(int16_t *x,int16_t *alpha,int16_t *y,uint32_t N)
220
This function performs componentwise addition of a vector with a complex scalar.
221
@param x Vector input (Q1.15)  in the format  |Re0  Im0 Re1 Im1|,......,|Re(N-2)  Im(N-2) Re(N-1) Im(N-1)|
222
@param alpha Scalar input (Q1.15) in the format  |Re0 Im0|
223
@param y Output (Q1.15) in the format  |Re0  Im0 Re1 Im1|,......,|Re(N-2)  Im(N-2) Re(N-1) Im(N-1)|
224 225 226 227
@param N Length of x WARNING: N>=4

The function implemented is : \f$\mathbf{y} = \alpha + \mathbf{x}\f$
*/
228
int32_t add_cpx_vector(int16_t *x,
229 230 231
                       int16_t *alpha,
                       int16_t *y,
                       uint32_t N);
232

lukashov's avatar
lukashov committed
233 234 235 236 237
int32_t sub_cpx_vector16(int16_t *x,
			  int16_t *y,
			  int16_t *z,
			  uint32_t N);

238
int32_t add_cpx_vector32(int16_t *x,
239 240 241
                         int16_t *y,
                         int16_t *z,
                         uint32_t N);
242 243

int32_t add_real_vector64(int16_t *x,
244 245 246
                          int16_t *y,
                          int16_t *z,
                          uint32_t N);
247 248

int32_t sub_real_vector64(int16_t *x,
249 250 251
                          int16_t* y,
                          int16_t *z,
                          uint32_t N);
252 253

int32_t add_real_vector64_scalar(int16_t *x,
254 255 256
                                 long long int a,
                                 int16_t *y,
                                 uint32_t N);
257

258
/*!\fn int32_t add_vector16(int16_t *x,int16_t *y,int16_t *z,uint32_t N)
259
This function performs componentwise addition of two vectors with Q1.15 components.
260 261 262
@param x Vector input (Q1.15)
@param y Scalar input (Q1.15)
@param z Scalar output (Q1.15)
263 264 265 266
@param N Length of x WARNING: N must be a multiple of 32

The function implemented is : \f$\mathbf{z} = \mathbf{x} + \mathbf{y}\f$
*/
267
int32_t add_vector16(int16_t *x,
268 269 270
                     int16_t *y,
                     int16_t *z,
                     uint32_t N);
271

272
int32_t add_vector16_64(int16_t *x,
273 274 275
                        int16_t *y,
                        int16_t *z,
                        uint32_t N);
276

277
int32_t complex_conjugate(int16_t *x1,
278 279
                          int16_t *y,
                          uint32_t N);
280

281
void bit8_txmux(int32_t length,int32_t offset);
282

283
void bit8_rxdemux(int32_t length,int32_t offset);
284

285 286
void Zero_Buffer(void *,uint32_t);
void Zero_Buffer_nommx(void *buf,uint32_t length);
287 288 289

void mmxcopy(void *dest,void *src,int size);

290
/*!\fn int32_t signal_energy(int *,uint32_t);
291 292
\brief Computes the signal energy per subcarrier
*/
293
int32_t signal_energy(int32_t *,uint32_t);
294

295 296 297 298 299 300 301
#ifdef LOCALIZATION
/*!\fn int32_t signal_energy(int *,uint32_t);
\brief Computes the signal energy per subcarrier
*/
int32_t subcarrier_energy(int32_t *,uint32_t, int32_t* subcarrier_energy, uint16_t rx_power_correction);
#endif

302
/*!\fn int32_t signal_energy_nodc(int32_t *,uint32_t);
303 304
\brief Computes the signal energy per subcarrier, without DC removal
*/
305
int32_t signal_energy_nodc(int32_t *,uint32_t);
306

307
/*!\fn double signal_energy_fp(double *s_re[2], double *s_im[2],uint32_t, uint32_t,uint32_t);
308 309
\brief Computes the signal energy per subcarrier
*/
310
double signal_energy_fp(double *s_re[2], double *s_im[2], uint32_t nb_antennas, uint32_t length,uint32_t offset);
311

312
/*!\fn double signal_energy_fp2(struct complex *, uint32_t);
313 314
\brief Computes the signal energy per subcarrier
*/
315
double signal_energy_fp2(struct complex *s, uint32_t length);
316 317


318 319 320 321 322
int32_t iSqrt(int32_t value);
uint8_t log2_approx(uint32_t);
uint8_t log2_approx64(unsigned long long int x);
int16_t invSqrt(int16_t x);
uint32_t angle(struct complex16 perrror);
323

324 325 326
/// computes the number of factors 2 in x
unsigned char factor2(unsigned int x);

327
/*!\fn int32_t phy_phase_compensation_top (uint32_t pilot_type, uint32_t initial_pilot,
328
        uint32_t last_pilot, int32_t ignore_prefix);
329 330 331 332 333 334 335 336 337
Compensate the phase rotation of the RF. WARNING: This function is currently unused. It has not been tested!
@param pilot_type indicates whether it is a CHBCH (=0) or a SCH (=1) pilot
@param initial_pilot index of the first pilot (which serves as reference)
@param last_pilot index of the last pilot in the range of pilots to correct the phase
@param ignore_prefix set to 1 if cyclic prefix has not been removed (by the hardware)

*/


338
int8_t dB_fixed(uint32_t x);
339

340
int8_t dB_fixed2(uint32_t x,uint32_t y);
341

342 343
int16_t dB_fixed_times10(uint32_t x);

344
int32_t phy_phase_compensation_top (uint32_t pilot_type, uint32_t initial_pilot,
345
                                    uint32_t last_pilot, int32_t ignore_prefix);
346

347
int32_t dot_product(int16_t *x,
348 349 350
                    int16_t *y,
                    uint32_t N, //must be a multiple of 8
                    uint8_t output_shift);
351 352

void dft12(int16_t *x,int16_t *y);
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
void dft24(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft36(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft48(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft60(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft72(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft96(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft108(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft120(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft144(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft180(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft192(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft216(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft240(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft288(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft300(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft324(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft360(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft384(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft432(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft480(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft540(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft576(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft600(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft648(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft720(int16_t *x,int16_t *y,uint8_t scale_flag);
378
void dft768(int16_t *x,int16_t *y,uint8_t scale_flag);
379 380 381 382 383 384 385
void dft864(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft900(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft960(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft972(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft1080(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft1152(int16_t *x,int16_t *y,uint8_t scale_flag);
void dft1200(int16_t *x,int16_t *y,uint8_t scale_flag);
386 387 388 389 390 391 392

void dft64(int16_t *x,int16_t *y,int scale);
void dft128(int16_t *x,int16_t *y,int scale);
void dft256(int16_t *x,int16_t *y,int scale);
void dft512(int16_t *x,int16_t *y,int scale);
void dft1024(int16_t *x,int16_t *y,int scale);
void dft2048(int16_t *x,int16_t *y,int scale);
393 394
void dft4096(int16_t *x,int16_t *y,int scale);
void dft8192(int16_t *x,int16_t *y,int scale);
395 396 397 398 399 400
void idft64(int16_t *x,int16_t *y,int scale);
void idft128(int16_t *x,int16_t *y,int scale);
void idft256(int16_t *x,int16_t *y,int scale);
void idft512(int16_t *x,int16_t *y,int scale);
void idft1024(int16_t *x,int16_t *y,int scale);
void idft2048(int16_t *x,int16_t *y,int scale);
401 402
void idft4096(int16_t *x,int16_t *y,int scale);
void idft8192(int16_t *x,int16_t *y,int scale);
403
/** @} */
404 405


406 407
double interp(double x, double *xs, double *ys, int count);

408
#endif //__PHY_TOOLS_DEFS__H__