defs.h 14.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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
 */

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 33
#include <stdint.h>

34
#include "PHY/sse_intrin.h"
35 36 37 38


//defined in rtai_math.h
#ifndef _RTAI_MATH_H
39
struct complex {
40 41 42 43 44
  double x;
  double y;
};
#endif

45
struct complexf {
46 47 48 49
  float r;
  float i;
};

50
struct complex16 {
51
  int16_t r;
52
  int16_t i;
53 54
};

55
struct complex32 {
56 57
  int32_t r;
  int32_t i;
58 59
};

60 61
//cmult_sv.h

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

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

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




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

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

int mult_cpx_conj_vector(int16_t *x1,
                         int16_t *x2,
                         int16_t *y,
                         uint32_t N,
126 127
                         int output_shift,
			 int madd);
128 129

// lte_dfts.c
130
void init_fft(uint16_t size,
131 132
              uint8_t logsize,
              uint16_t *rev);
133

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

154
void idft1536(int16_t *sigF,int16_t *sig,int scale);
155

156
void idft6144(int16_t *sigF,int16_t *sig);
157

158
void idft12288(int16_t *sigF,int16_t *sig);
159

160
void idft18432(int16_t *sigF,int16_t *sig);
161

162
void idft3072(int16_t *sigF,int16_t *sig);
163

164
void idft24576(int16_t *sigF,int16_t *sig);
165

166
void dft1536(int16_t *sigF,int16_t *sig,int scale);
167

168
void dft6144(int16_t *sigF,int16_t *sig);
169

170
void dft12288(int16_t *sigF,int16_t *sig);
171

172
void dft18432(int16_t *sigF,int16_t *sig);
173

174
void dft3072(int16_t *sigF,int16_t *sig);
175

176
void dft24576(int16_t *sigF,int16_t *sig);
177 178


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


196
//cadd_sv.c
197

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

The function implemented is : \f$\mathbf{y} = \alpha + \mathbf{x}\f$
*/
207
int32_t add_cpx_vector(int16_t *x,
208 209 210
                       int16_t *alpha,
                       int16_t *y,
                       uint32_t N);
211 212

int32_t add_cpx_vector32(int16_t *x,
213 214 215
                         int16_t *y,
                         int16_t *z,
                         uint32_t N);
216 217

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

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

int32_t add_real_vector64_scalar(int16_t *x,
228 229 230
                                 long long int a,
                                 int16_t *y,
                                 uint32_t N);
231

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

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

251
int32_t complex_conjugate(int16_t *x1,
252 253
                          int16_t *y,
                          uint32_t N);
254

255
void bit8_txmux(int32_t length,int32_t offset);
256

257
void bit8_rxdemux(int32_t length,int32_t offset);
258 259

#ifdef USER_MODE
260
/*!\fn int32_t write_output(const char *fname, const char *vname, void *data, int length, int dec, char format);
261 262 263
\brief Write output file from signal data
@param fname output file name
@param vname  output vector name (for MATLAB/OCTAVE)
264
@param data   point to data
265 266 267 268
@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)
*/
269
int32_t write_output(const char *fname, const char *vname, void *data, int length, int dec, char format);
270 271
#endif

272 273
void Zero_Buffer(void *,uint32_t);
void Zero_Buffer_nommx(void *buf,uint32_t length);
274 275 276

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

277
/*!\fn int32_t signal_energy(int *,uint32_t);
278 279
\brief Computes the signal energy per subcarrier
*/
280
int32_t signal_energy(int32_t *,uint32_t);
281

282 283 284 285 286 287 288
#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

289
/*!\fn int32_t signal_energy_nodc(int32_t *,uint32_t);
290 291
\brief Computes the signal energy per subcarrier, without DC removal
*/
292
int32_t signal_energy_nodc(int32_t *,uint32_t);
293

knopp's avatar
knopp committed
294
/*!\fn double signal_energy_fp(double *s_re[2], double *s_im[2],uint32_t, uint32_t,uint32_t);
295 296
\brief Computes the signal energy per subcarrier
*/
knopp's avatar
knopp committed
297
double signal_energy_fp(double *s_re[2], double *s_im[2], uint32_t nb_antennas, uint32_t length,uint32_t offset);
298

299
/*!\fn double signal_energy_fp2(struct complex *, uint32_t);
300 301
\brief Computes the signal energy per subcarrier
*/
302
double signal_energy_fp2(struct complex *s, uint32_t length);
303 304


305 306 307 308 309
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);
310

311
/*!\fn int32_t phy_phase_compensation_top (uint32_t pilot_type, uint32_t initial_pilot,
312
        uint32_t last_pilot, int32_t ignore_prefix);
313 314 315 316 317 318 319 320 321
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)

*/


322
int8_t dB_fixed(uint32_t x);
323

324
int8_t dB_fixed2(uint32_t x,uint32_t y);
325

326 327
int16_t dB_fixed_times10(uint32_t x);

328
int32_t phy_phase_compensation_top (uint32_t pilot_type, uint32_t initial_pilot,
329
                                    uint32_t last_pilot, int32_t ignore_prefix);
330

331
/*!\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);
332 333 334 335 336 337 338 339
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)
*/
340
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 );
341

342
int32_t dot_product(int16_t *x,
343 344 345
                    int16_t *y,
                    uint32_t N, //must be a multiple of 8
                    uint8_t output_shift);
346 347

void dft12(int16_t *x,int16_t *y);
348 349 350 351 352 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
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);
380 381 382 383 384 385 386

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);
387 388
void dft4096(int16_t *x,int16_t *y,int scale);
void dft8192(int16_t *x,int16_t *y,int scale);
389 390 391 392 393 394
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);
395 396
void idft4096(int16_t *x,int16_t *y,int scale);
void idft8192(int16_t *x,int16_t *y,int scale);
397
/** @} */
398 399


400 401
double interp(double x, double *xs, double *ys, int count);

402
#endif //__PHY_TOOLS_DEFS__H__