defs.h 15.1 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
#ifndef __PHY_TOOLS_DEFS__H__
#define __PHY_TOOLS_DEFS__H__

/** @addtogroup _PHY_DSP_TOOLS_


* @{

*/
38

39 40
#include <stdint.h>

41
#include "PHY/sse_intrin.h"
42 43 44 45


//defined in rtai_math.h
#ifndef _RTAI_MATH_H
46
struct complex {
47 48 49 50 51
  double x;
  double y;
};
#endif

52
struct complexf {
53 54 55 56
  float r;
  float i;
};

57
struct complex16 {
58
  int16_t r;
59
  int16_t i;
60 61
};

62
struct complex32 {
63 64
  int32_t r;
  int32_t i;
65 66
};

67 68
//cmult_sv.h

69
/*!\fn void multadd_real_vector_complex_scalar(int16_t *x,int16_t *alpha,int16_t *y,uint32_t N)
70
This function performs componentwise multiplication and accumulation of a complex scalar and a real vector.
71
@param x Vector input (Q1.15)
72 73 74 75 76 77
@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$
*/
78
void multadd_real_vector_complex_scalar(int16_t *x,
79 80 81 82
                                        int16_t *alpha,
                                        int16_t *y,
                                        uint32_t N
                                       );
83

84
/*!\fn void multadd_complex_vector_real_scalar(int16_t *x,int16_t alpha,int16_t *y,uint8_t zero_flag,uint32_t N)
85
This function performs componentwise multiplication and accumulation of a real scalar and a complex vector.
86
@param x Vector input (Q1.15) in the format |Re0 Im0|Re1 Im 1| ...
87 88 89 90 91 92 93
@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$
*/
94
void multadd_complex_vector_real_scalar(int16_t *x,
95 96 97 98
                                        int16_t alpha,
                                        int16_t *y,
                                        uint8_t zero_flag,
                                        uint32_t N);
99

100 101
int rotate_cpx_vector(int16_t *x,
                      int16_t *alpha,
102
                      int16_t *y,
103 104
                      uint32_t N,
                      uint16_t output_shift);
105 106 107 108




109
/*!\fn void init_fft(uint16_t size,uint8_t logsize,uint16_t *rev)
110 111 112 113 114 115
\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
*/

116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
//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
*/

int mult_cpx_conj_vector(int16_t *x1,
                         int16_t *x2,
                         int16_t *y,
                         uint32_t N,
                         int output_shift);

// lte_dfts.c
135
void init_fft(uint16_t size,
136 137
              uint8_t logsize,
              uint16_t *rev);
138

139
/*!\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)
140 141 142 143 144 145 146 147 148
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)
*/
149
/*void fft(int16_t *x,
150 151 152 153 154 155 156
         int16_t *y,
         int16_t *twiddle,
         uint16_t *rev,
         uint8_t log2size,
         uint8_t scale,
         uint8_t input_fmt
        );
157
*/
158

159
void idft1536(int16_t *sigF,int16_t *sig,int scale);
160

161
void idft6144(int16_t *sigF,int16_t *sig);
162

163
void idft12288(int16_t *sigF,int16_t *sig);
164

165
void idft18432(int16_t *sigF,int16_t *sig);
166

167
void idft3072(int16_t *sigF,int16_t *sig);
168

169
void idft24576(int16_t *sigF,int16_t *sig);
170

171
void dft1536(int16_t *sigF,int16_t *sig,int scale);
172

173
void dft6144(int16_t *sigF,int16_t *sig);
174

175
void dft12288(int16_t *sigF,int16_t *sig);
176

177
void dft18432(int16_t *sigF,int16_t *sig);
178

179
void dft3072(int16_t *sigF,int16_t *sig);
180

181
void dft24576(int16_t *sigF,int16_t *sig);
182 183


184
/*!\fn int32_t rotate_cpx_vector(int16_t *x,int16_t *alpha,int16_t *y,uint32_t N,uint16_t output_shift)
185
This function performs componentwise multiplication of a vector with a complex scalar.
186
@param x Vector input (Q1.15)  in the format  |Re0  Im0|,......,|Re(N-1) Im(N-1)|
187
@param alpha Scalar input (Q1.15) in the format  |Re0 Im0|
188
@param y Output (Q1.15) in the format  |Re0  Im0|,......,|Re(N-1) Im(N-1)|
189 190 191 192 193
@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$
*/
194
int32_t rotate_cpx_vector(int16_t *x,
195 196 197
                          int16_t *alpha,
                          int16_t *y,
                          uint32_t N,
198
                          uint16_t output_shift);
199 200


201
//cadd_sv.c
202

203
/*!\fn int32_t add_cpx_vector(int16_t *x,int16_t *alpha,int16_t *y,uint32_t N)
204
This function performs componentwise addition of a vector with a complex scalar.
205
@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)|
206
@param alpha Scalar input (Q1.15) in the format  |Re0 Im0|
207
@param y Output (Q1.15) in the format  |Re0  Im0 Re1 Im1|,......,|Re(N-2)  Im(N-2) Re(N-1) Im(N-1)|
208 209 210 211
@param N Length of x WARNING: N>=4

The function implemented is : \f$\mathbf{y} = \alpha + \mathbf{x}\f$
*/
212
int32_t add_cpx_vector(int16_t *x,
213 214 215
                       int16_t *alpha,
                       int16_t *y,
                       uint32_t N);
216 217

int32_t add_cpx_vector32(int16_t *x,
218 219 220
                         int16_t *y,
                         int16_t *z,
                         uint32_t N);
221 222

int32_t add_real_vector64(int16_t *x,
223 224 225
                          int16_t *y,
                          int16_t *z,
                          uint32_t N);
226 227

int32_t sub_real_vector64(int16_t *x,
228 229 230
                          int16_t* y,
                          int16_t *z,
                          uint32_t N);
231 232

int32_t add_real_vector64_scalar(int16_t *x,
233 234 235
                                 long long int a,
                                 int16_t *y,
                                 uint32_t N);
236

237
/*!\fn int32_t add_vector16(int16_t *x,int16_t *y,int16_t *z,uint32_t N)
238
This function performs componentwise addition of two vectors with Q1.15 components.
239 240 241
@param x Vector input (Q1.15)
@param y Scalar input (Q1.15)
@param z Scalar output (Q1.15)
242 243 244 245
@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$
*/
246
int32_t add_vector16(int16_t *x,
247 248 249
                     int16_t *y,
                     int16_t *z,
                     uint32_t N);
250

251
int32_t add_vector16_64(int16_t *x,
252 253 254
                        int16_t *y,
                        int16_t *z,
                        uint32_t N);
255

256
int32_t complex_conjugate(int16_t *x1,
257 258
                          int16_t *y,
                          uint32_t N);
259

260
void bit8_txmux(int32_t length,int32_t offset);
261

262
void bit8_rxdemux(int32_t length,int32_t offset);
263 264

#ifdef USER_MODE
265
/*!\fn int32_t write_output(const char *fname, const char *vname, void *data, int length, int dec, char format);
266 267 268
\brief Write output file from signal data
@param fname output file name
@param vname  output vector name (for MATLAB/OCTAVE)
269
@param data   point to data
270 271 272 273
@param length length of data vector to output
@param dec    decimation level
@param format data format (0 = real 16-bit, 1 = complex 16-bit,2 real 32-bit, 3 complex 32-bit,4 = real 8-bit, 5 = complex 8-bit)
*/
274
int32_t write_output(const char *fname, const char *vname, void *data, int length, int dec, char format);
275 276
#endif

277 278
void Zero_Buffer(void *,uint32_t);
void Zero_Buffer_nommx(void *buf,uint32_t length);
279 280 281

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

282
/*!\fn int32_t signal_energy(int *,uint32_t);
283 284
\brief Computes the signal energy per subcarrier
*/
285
int32_t signal_energy(int32_t *,uint32_t);
286

287 288 289 290 291 292 293
#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

294
/*!\fn int32_t signal_energy_nodc(int32_t *,uint32_t);
295 296
\brief Computes the signal energy per subcarrier, without DC removal
*/
297
int32_t signal_energy_nodc(int32_t *,uint32_t);
298

299
/*!\fn double signal_energy_fp(double **, double **,uint32_t, uint32_t,uint32_t);
300 301
\brief Computes the signal energy per subcarrier
*/
302
double signal_energy_fp(double **s_re, double **s_im, uint32_t nb_antennas, uint32_t length,uint32_t offset);
303

304
/*!\fn double signal_energy_fp2(struct complex *, uint32_t);
305 306
\brief Computes the signal energy per subcarrier
*/
307
double signal_energy_fp2(struct complex *s, uint32_t length);
308 309


310 311 312 313 314
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);
315

316
/*!\fn int32_t phy_phase_compensation_top (uint32_t pilot_type, uint32_t initial_pilot,
317
        uint32_t last_pilot, int32_t ignore_prefix);
318 319 320 321 322 323 324 325 326
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)

*/


327
int8_t dB_fixed(uint32_t x);
328

329
int8_t dB_fixed2(uint32_t x,uint32_t y);
330

331 332
int16_t dB_fixed_times10(uint32_t x);

333
int32_t phy_phase_compensation_top (uint32_t pilot_type, uint32_t initial_pilot,
334
                                    uint32_t last_pilot, int32_t ignore_prefix);
335

336
/*!\fn void phy_phase_compensation (int16_t *ref_sch, int16_t *tgt_sch, int16_t *out_sym, int32_t ignore_prefix, int32_t aa, struct complex16 *perror_out);
337 338 339 340 341 342 343 344
This function is used by the EMOS to compensate the phase rotation of the RF. It has been designed for symbols of type CHSCH or SCH, but cannot be used for the data channels.
@param ref_sch reference symbol
@param tgt_sch target symbol
@param out_sym output of the operation
@param ignore_prefix  set to 1 if cyclic prefix has not been removed (by the hardware)
@param aa antenna index
@param perror_out phase error (output parameter)
*/
345
void phy_phase_compensation (int16_t *ref_sch, int16_t *tgt_sch, int16_t *out_sym, int32_t ignore_prefix, int32_t aa, struct complex16 *perror_out );
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 378 379 380 381 382 383 384
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);
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);
385 386 387 388 389 390 391

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);
392 393
void dft4096(int16_t *x,int16_t *y,int scale);
void dft8192(int16_t *x,int16_t *y,int scale);
394 395 396 397 398 399
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);
400 401
void idft4096(int16_t *x,int16_t *y,int scale);
void idft8192(int16_t *x,int16_t *y,int scale);
402
/** @} */
403 404


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

407
#endif //__PHY_TOOLS_DEFS__H__