tools_defs.h 15.3 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

Guy De Souza's avatar
Guy De Souza committed
35 36
#define CEILIDIV(a,b) ((a+b-1)/b)
#define ROUNDIDIV(a,b) (((a<<1)+b)/(b<<1))
37

38
struct complex {
39 40 41 42
  double x;
  double y;
};

43
struct complexf {
44 45 46 47
  float r;
  float i;
};

48
struct complex16 {
49
  int16_t r;
50
  int16_t i;
51 52
};

53
struct complex32 {
54 55
  int32_t r;
  int32_t i;
56 57
};

58 59
//cmult_sv.h

60
/*!\fn void multadd_real_vector_complex_scalar(int16_t *x,int16_t *alpha,int16_t *y,uint32_t N)
61
This function performs componentwise multiplication and accumulation of a complex scalar and a real vector.
62
@param x Vector input (Q1.15)
63 64 65 66 67 68
@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$
*/
69
void multadd_real_vector_complex_scalar(int16_t *x,
70 71 72 73
                                        int16_t *alpha,
                                        int16_t *y,
                                        uint32_t N
                                       );
74

75
/*!\fn void multadd_complex_vector_real_scalar(int16_t *x,int16_t alpha,int16_t *y,uint8_t zero_flag,uint32_t N)
76
This function performs componentwise multiplication and accumulation of a real scalar and a complex vector.
77
@param x Vector input (Q1.15) in the format |Re0 Im0|Re1 Im 1| ...
78 79 80 81 82 83 84
@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$
*/
85
void multadd_complex_vector_real_scalar(int16_t *x,
86 87 88 89
                                        int16_t alpha,
                                        int16_t *y,
                                        uint8_t zero_flag,
                                        uint32_t N);
90

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




100
/*!\fn void init_fft(uint16_t size,uint8_t logsize,uint16_t *rev)
101 102 103 104 105 106
\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
*/

107 108 109 110 111 112 113 114 115 116
//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
117
  @param madd - if not zero result is added to output
118 119 120 121 122 123
*/

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

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
/*!
  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);
145

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

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

157
/*!\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)
158 159 160 161 162 163 164 165 166
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)
*/
167
/*void fft(int16_t *x,
168 169 170 171 172 173 174
         int16_t *y,
         int16_t *twiddle,
         uint16_t *rev,
         uint8_t log2size,
         uint8_t scale,
         uint8_t input_fmt
        );
175
*/
176

177
void idft1536(int16_t *sigF,int16_t *sig,int scale);
178

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

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

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

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

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

189
void dft1536(int16_t *sigF,int16_t *sig,int scale);
190

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

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

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


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

Raymond Knopp's avatar
Raymond Knopp committed
200
void dft24576(int16_t *sigF,int16_t *sig,int scale);
201 202


203
/*!\fn int32_t rotate_cpx_vector(int16_t *x,int16_t *alpha,int16_t *y,uint32_t N,uint16_t output_shift)
204
This function performs componentwise multiplication of a vector with a complex scalar.
205
@param x Vector input (Q1.15)  in the format  |Re0  Im0|,......,|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|,......,|Re(N-1) Im(N-1)|
208 209 210 211 212
@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$
*/
213
int32_t rotate_cpx_vector(int16_t *x,
214 215 216
                          int16_t *alpha,
                          int16_t *y,
                          uint32_t N,
217
                          uint16_t output_shift);
218 219


220
//cadd_sv.c
221

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

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

lukashov's avatar
lukashov committed
236 237 238 239 240
int32_t sub_cpx_vector16(int16_t *x,
			  int16_t *y,
			  int16_t *z,
			  uint32_t N);

241
int32_t add_cpx_vector32(int16_t *x,
242 243 244
                         int16_t *y,
                         int16_t *z,
                         uint32_t N);
245 246

int32_t add_real_vector64(int16_t *x,
247 248 249
                          int16_t *y,
                          int16_t *z,
                          uint32_t N);
250 251

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

int32_t add_real_vector64_scalar(int16_t *x,
257 258 259
                                 long long int a,
                                 int16_t *y,
                                 uint32_t N);
260

261
/*!\fn int32_t add_vector16(int16_t *x,int16_t *y,int16_t *z,uint32_t N)
262
This function performs componentwise addition of two vectors with Q1.15 components.
263 264 265
@param x Vector input (Q1.15)
@param y Scalar input (Q1.15)
@param z Scalar output (Q1.15)
266 267 268 269
@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$
*/
270
int32_t add_vector16(int16_t *x,
271 272 273
                     int16_t *y,
                     int16_t *z,
                     uint32_t N);
274

275
int32_t add_vector16_64(int16_t *x,
276 277 278
                        int16_t *y,
                        int16_t *z,
                        uint32_t N);
279

280
int32_t complex_conjugate(int16_t *x1,
281 282
                          int16_t *y,
                          uint32_t N);
283

284
void bit8_txmux(int32_t length,int32_t offset);
285

286
void bit8_rxdemux(int32_t length,int32_t offset);
287

288 289
void Zero_Buffer(void *,uint32_t);
void Zero_Buffer_nommx(void *buf,uint32_t length);
290 291 292

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

293
/*!\fn int32_t signal_energy(int *,uint32_t);
294 295
\brief Computes the signal energy per subcarrier
*/
296
int32_t signal_energy(int32_t *,uint32_t);
297

298 299 300 301 302 303 304
#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

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

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

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


321 322 323 324 325
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);
326

327 328 329
/// computes the number of factors 2 in x
unsigned char factor2(unsigned int x);

330
/*!\fn int32_t phy_phase_compensation_top (uint32_t pilot_type, uint32_t initial_pilot,
331
        uint32_t last_pilot, int32_t ignore_prefix);
332 333 334 335 336 337 338 339 340
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)

*/


341
int8_t dB_fixed(uint32_t x);
342

343
int8_t dB_fixed2(uint32_t x,uint32_t y);
344

345 346
int16_t dB_fixed_times10(uint32_t x);

347 348
uint8_t dB_fixed64(uint64_t x);

349
int32_t phy_phase_compensation_top (uint32_t pilot_type, uint32_t initial_pilot,
350
                                    uint32_t last_pilot, int32_t ignore_prefix);
351

352
int32_t dot_product(int16_t *x,
353 354 355
                    int16_t *y,
                    uint32_t N, //must be a multiple of 8
                    uint8_t output_shift);
356

Raymond Knopp's avatar
Raymond Knopp committed
357 358 359 360 361
int64_t dot_product64(int16_t *x,
		      int16_t *y,
		      uint32_t N, //must be a multiple of 8
		      uint8_t output_shift);

362
void dft12(int16_t *x,int16_t *y);
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
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);
388
void dft768(int16_t *x,int16_t *y,uint8_t scale_flag);
389 390 391 392 393 394 395
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);
396 397 398 399 400 401 402

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);
403 404
void dft4096(int16_t *x,int16_t *y,int scale);
void dft8192(int16_t *x,int16_t *y,int scale);
405 406 407 408 409 410
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);
411 412
void idft4096(int16_t *x,int16_t *y,int scale);
void idft8192(int16_t *x,int16_t *y,int scale);
413
/** @} */
414 415


416 417
double interp(double x, double *xs, double *ys, int count);

Guy De Souza's avatar
Guy De Souza committed
418 419
int write_output(const char *fname,const char *vname,void *data,int length,int dec,char format);

420
#endif //__PHY_TOOLS_DEFS__H__