brazos-trapezoidal
Classes | Macros | Functions
MathLib_Iq.h File Reference
#include "uc.h"
Include dependency graph for MathLib_Iq.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ABC_t
 
struct  DQ_t
 
struct  AlphaBeta_t
 
struct  trig_t
 

Macros

#define BASE_IQ   (15)
 
#define _IQ(x)
 
#define _IQX_TO_IQY(x, qx, qy)
 
#define _IQX(x, qx)   ((x) * ((mc_t)1 << (qx)))
 
#define _FLOAT_TO_IQ(x, base)   (((x) * (1 << (BASE_IQ)))/(base))
 
#define _FLOAT_TO_IQY(x, base_iq, base)   (((float)(x) * ((mc_t)1 << (base_iq)))/(float)(base))
 
#define _IQ_TO_FLOATY(x, y, base)   ((float32_t)(((float32_t)(x)*(float32_t)(base)) / (float32_t)(1 << y)))
 
#define _IQ_TO_FLOAT(x)   ((float32_t)(((float32_t)(x)) / (float32_t)(1 << BASE_IQ)))
 
#define MATHLIB_MIN_VALUE   ((mc_t)1)
 
#define MATHLIB_IQMPY(a, b, a_format, b_format, out_format)
 
#define MATHLIB_MPY(a, b)   MATHLIB_IQMPY(a, b, BASE_IQ, BASE_IQ, BASE_IQ)
 
#define MATHLIB_DIV(x, y)   ((((x) << BASE_IQ) / (y)))
 
#define MATHLIB_ABS(x)   ((x < 0) ? -x : x)
 
#define MATHLIB_SAT(x, lim_inf, lim_sup)
 
#define MATHLIB_MPY_BY_TWO(a)   ((a)<<1)
 
#define MATHLIB_MPY_BY_FOUR(a)   ((a)<<2)
 
#define MATHLIB_MPY_BY_EIGHT(a)   ((a)<<3)
 
#define MATHLIB_DIV_BY_TWO(a)   ((a)>>1)
 
#define MATHLIB_DIV_BY_FOUR(a)   ((a)>>2)
 
#define MATHLIB_DIV_BY_EIGHT(a)   ((a)>>3)
 
#define MATHLIB_SQRT(x)   MathLib_SqrtLUT((x))
 
#define MATHLIB_SINCOS(th, sc)   MathLib_SinCosIQ(th, sc)
 
#define MATHLIB_MOD(x, y)   MathLib_ModIq(x, y)
 
#define MATHLIB_SINCOSMODAB(ab, m, sc)   MathLib_SinCosModAbIq(ab, m, sc)
 
#define ONE_OVER_PI   _IQ(0.31830988618379067153776752674503)
 
#define ONE_OVER_4PI   _IQ(0.07957747154594766788444188168626/2)
 
#define ONE_OVER_TWO   _IQ(0.5)
 
#define ONE_OVER_THREE   _IQ(0.33333)
 
#define ONE_OVER_SQRT3   _IQ(0.57735026918962576450914878050196)
 
#define SQRT3_OVER_TWO   _IQ(0.86602540378443864676372317075294)
 
#define SQRT3   _IQ(0.86602540378443864676372317075294*2)
 

Functions

u_mc_t MathLib_SqrtLUT (uint16_t value)
 Calculates the square root of IQ1.15 number using a Look-up table that needs to have a size of a power of 2. More...
 
void MathLib_SinCosPoly (mc_t theta, trig_t *sinCos)
 Calculates the sine and cosine using a sixth order polynomial approximation, the approximation is just valid for the range -0.5 to 0.5 which represents the range from 0 to pi/2. More...
 
mc_t MathLib_ModIq (mc_t x, mc_t y)
 Modulus function, it calculates hypotenusa in Q1.15. More...
 
void MathLib_SinCosModAbIq (AlphaBeta_t *ab, mc_t mod, trig_t *sinCos)
 Modulus function, it calculates hypotenusa in Q1.15. More...
 
void MathLib_SinCosIQ (mc_t theta, trig_t *sinCos)
 Sin and Cosine calculation of a Q1.15 angle. More...
 

Detailed Description


Author
Horacio Beckert Polli
Copyright 2018.  Theta Power Systems.  All rights reserved - CONFIDENTIAL ---------------------

Definition in file MathLib_Iq.h.

Macro Definition Documentation

◆ _FLOAT_TO_IQ

#define _FLOAT_TO_IQ (   x,
  base 
)    (((x) * (1 << (BASE_IQ)))/(base))

Definition at line 74 of file MathLib_Iq.h.

◆ _FLOAT_TO_IQY

#define _FLOAT_TO_IQY (   x,
  base_iq,
  base 
)    (((float)(x) * ((mc_t)1 << (base_iq)))/(float)(base))

Definition at line 75 of file MathLib_Iq.h.

◆ _IQ

#define _IQ (   x)
Value:
( ((x) < 0.0) ? (mc_t)((1<<BASE_IQ) * (x) - 0.5) :\
(mc_t)((1<<BASE_IQ) * (x) + 0.5) )
#define BASE_IQ
Definition: MathLib_Iq.h:64

Definition at line 65 of file MathLib_Iq.h.

◆ _IQ_TO_FLOAT

#define _IQ_TO_FLOAT (   x)    ((float32_t)(((float32_t)(x)) / (float32_t)(1 << BASE_IQ)))

Definition at line 82 of file MathLib_Iq.h.

◆ _IQ_TO_FLOATY

#define _IQ_TO_FLOATY (   x,
  y,
  base 
)    ((float32_t)(((float32_t)(x)*(float32_t)(base)) / (float32_t)(1 << y)))

Definition at line 81 of file MathLib_Iq.h.

◆ _IQX

#define _IQX (   x,
  qx 
)    ((x) * ((mc_t)1 << (qx)))

Definition at line 72 of file MathLib_Iq.h.

◆ _IQX_TO_IQY

#define _IQX_TO_IQY (   x,
  qx,
  qy 
)
Value:
(((qx)>(qy)) ? \
((x) >> ((qx)-(qy))) \
: ((signed long int)(x) << ((qy)-(qx))))

Definition at line 68 of file MathLib_Iq.h.

◆ BASE_IQ

#define BASE_IQ   (15)

Macros and definitions


Defines the base IQ, unless otherwise noted, all the variables use this base

Definition at line 64 of file MathLib_Iq.h.

◆ MATHLIB_ABS

#define MATHLIB_ABS (   x)    ((x < 0) ? -x : x)

Definition at line 97 of file MathLib_Iq.h.

◆ MATHLIB_DIV

#define MATHLIB_DIV (   x,
  y 
)    ((((x) << BASE_IQ) / (y)))

Definition at line 95 of file MathLib_Iq.h.

◆ MATHLIB_DIV_BY_EIGHT

#define MATHLIB_DIV_BY_EIGHT (   a)    ((a)>>3)

Definition at line 112 of file MathLib_Iq.h.

◆ MATHLIB_DIV_BY_FOUR

#define MATHLIB_DIV_BY_FOUR (   a)    ((a)>>2)

Definition at line 111 of file MathLib_Iq.h.

◆ MATHLIB_DIV_BY_TWO

#define MATHLIB_DIV_BY_TWO (   a)    ((a)>>1)

Definition at line 110 of file MathLib_Iq.h.

◆ MATHLIB_IQMPY

#define MATHLIB_IQMPY (   a,
  b,
  a_format,
  b_format,
  out_format 
)
Value:
( (((a_format)+(b_format))>30) ? \
( (mc_t)(((int64_t)(a) * (int64_t)(b)) >> ((a_format)+(b_format)-(out_format))) ) \
: ( (mc_t)(((mc_t)(a) * (mc_t)(b)) >> ((a_format)+(b_format)-(out_format))) ) )

Multiply two variables defined by BASE_IQ, assuming the integer part is never bigger than 1.41pu (1.41^2 would overflow the multiplication in the Q15 format

Definition at line 90 of file MathLib_Iq.h.

◆ MATHLIB_MIN_VALUE

#define MATHLIB_MIN_VALUE   ((mc_t)1)

Definition at line 84 of file MathLib_Iq.h.

◆ MATHLIB_MOD

#define MATHLIB_MOD (   x,
  y 
)    MathLib_ModIq(x, y)

Definition at line 119 of file MathLib_Iq.h.

◆ MATHLIB_MPY

#define MATHLIB_MPY (   a,
  b 
)    MATHLIB_IQMPY(a, b, BASE_IQ, BASE_IQ, BASE_IQ)

Definition at line 93 of file MathLib_Iq.h.

◆ MATHLIB_MPY_BY_EIGHT

#define MATHLIB_MPY_BY_EIGHT (   a)    ((a)<<3)

Definition at line 109 of file MathLib_Iq.h.

◆ MATHLIB_MPY_BY_FOUR

#define MATHLIB_MPY_BY_FOUR (   a)    ((a)<<2)

Definition at line 108 of file MathLib_Iq.h.

◆ MATHLIB_MPY_BY_TWO

#define MATHLIB_MPY_BY_TWO (   a)    ((a)<<1)

Multiply a variable by two, this macro was created to optimize multiplications by multiples of two in fixed point logic

Definition at line 107 of file MathLib_Iq.h.

◆ MATHLIB_SAT

#define MATHLIB_SAT (   x,
  lim_inf,
  lim_sup 
)
Value:
((lim_sup) >= (lim_inf)) ? \
(((x) >= (lim_sup)) ? (lim_sup) : ( ((x) <= (lim_inf)) ? (lim_inf) : (x) )) : \
(((x) >= (lim_inf)) ? (lim_inf) : ( ((x) <= (lim_sup)) ? (lim_sup) : (x) ))

Definition at line 98 of file MathLib_Iq.h.

◆ MATHLIB_SINCOS

#define MATHLIB_SINCOS (   th,
  sc 
)    MathLib_SinCosIQ(th, sc)

Definition at line 118 of file MathLib_Iq.h.

◆ MATHLIB_SINCOSMODAB

#define MATHLIB_SINCOSMODAB (   ab,
  m,
  sc 
)    MathLib_SinCosModAbIq(ab, m, sc)

Definition at line 120 of file MathLib_Iq.h.

◆ MATHLIB_SQRT

#define MATHLIB_SQRT (   x)    MathLib_SqrtLUT((x))

Macro Methods definitions

Definition at line 117 of file MathLib_Iq.h.

◆ ONE_OVER_4PI

#define ONE_OVER_4PI   _IQ(0.07957747154594766788444188168626/2)

Definition at line 127 of file MathLib_Iq.h.

◆ ONE_OVER_PI

#define ONE_OVER_PI   _IQ(0.31830988618379067153776752674503)

Constants

Definition at line 126 of file MathLib_Iq.h.

◆ ONE_OVER_SQRT3

#define ONE_OVER_SQRT3   _IQ(0.57735026918962576450914878050196)

Definition at line 130 of file MathLib_Iq.h.

◆ ONE_OVER_THREE

#define ONE_OVER_THREE   _IQ(0.33333)

Definition at line 129 of file MathLib_Iq.h.

◆ ONE_OVER_TWO

#define ONE_OVER_TWO   _IQ(0.5)

Definition at line 128 of file MathLib_Iq.h.

◆ SQRT3

#define SQRT3   _IQ(0.86602540378443864676372317075294*2)

Definition at line 132 of file MathLib_Iq.h.

◆ SQRT3_OVER_TWO

#define SQRT3_OVER_TWO   _IQ(0.86602540378443864676372317075294)

Definition at line 131 of file MathLib_Iq.h.

Function Documentation

◆ MathLib_ModIq()

mc_t MathLib_ModIq ( mc_t  x,
mc_t  y 
)

Modulus function, it calculates hypotenusa in Q1.15.

Parameters
yy-axis value to be calculated
xx-axis value to be calculated
Returns
hypotenusa

Definition at line 363 of file MathLib_Iq.c.

Here is the call graph for this function:

◆ MathLib_SinCosIQ()

void MathLib_SinCosIQ ( mc_t  theta,
trig_t *  sinCos 
)

Sin and Cosine calculation of a Q1.15 angle.


Sin table in the range of [0:2*pi]

Parameters
mc_ttheta: the angle

@param trig_t *sinCos: pointer to the struct that will hold the results

Definition at line 301 of file MathLib_Iq.c.

◆ MathLib_SinCosModAbIq()

void MathLib_SinCosModAbIq ( AlphaBeta_t *  ab,
mc_t  mod,
trig_t *  sinCos 
)

Modulus function, it calculates hypotenusa in Q1.15.

Parameters
yy-axis value to be calculated
xx-axis value to be calculated
Returns
hypotenusa

Definition at line 377 of file MathLib_Iq.c.

◆ MathLib_SinCosPoly()

void MathLib_SinCosPoly ( mc_t  theta,
trig_t *  sinCos 
)

Calculates the sine and cosine using a sixth order polynomial approximation, the approximation is just valid for the range -0.5 to 0.5 which represents the range from 0 to pi/2.

Parameters
thetathe angle
sinCospointer to the struct that will hold the results

get the quadrant of the angle

wrap the angle between 0 and pi/2, the range of the polynomial approximation

Rearrange 0 -> -1/2 and pi/2 -> 1/2, that's how the approximation use the angles

Definition at line 253 of file MathLib_Iq.c.

◆ MathLib_SqrtLUT()

u_mc_t MathLib_SqrtLUT ( uint16_t  value)

Calculates the square root of IQ1.15 number using a Look-up table that needs to have a size of a power of 2.


Functions prototypes

Parameters
valuethe number in 1.15 format
Returns
The square root in 1.15 format

The modulus operation is getting how much the input value is far from the table value, this is being used to interpolate, since everything is in the power of two, tmp will be in the IQ 1.(15-SIZE_SQRT_TABLE_2N) format.

Definition at line 216 of file MathLib_Iq.c.

Here is the caller graph for this function: