brazos-trapezoidal
Macros | Functions | Variables
MathLib_Iq.c File Reference
#include "MathLib.h"
Include dependency graph for MathLib_Iq.c:

Go to the source code of this file.

Macros

#define SIZE_SQRT_TABLE_2N   7
 
#define SIN_TABLE_SIZE   512
 
#define COS_TABLE_OFFSET   128
 
#define SIN_POL_A0   _IQ(0.70710781187)
 
#define SIN_POL_A2   _IQ(-0.872348075361)
 
#define SIN_POL_A4   _IQ(0.179251759526)
 
#define SIN_POL_A6   _IQ(-0.0142718282624)
 
#define SIN_POL_B1   _IQ(-1.11067032264)
 
#define SIN_POL_B3   _IQ(0.4561589075945)
 
#define SIN_POL_B5   _IQ(-0.0539104694791)
 
#define ATAN_POL_A7   _IQ(-1.57588)
 
#define ATAN_POL_A5   _IQ(1.48697)
 
#define ATAN_POL_A3   _IQ(-0.817719)
 
#define ATAN_POL_A1   _IQ(0.63611725)
 
#define ATAN_POL_A0   _IQ(0.25)
 

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...
 
void MathLib_SinCosIQ (mc_t theta, trig_t *sinCos)
 Sin and Cosine calculation of a Q1.15 angle. 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...
 
mc_t MathLib_AtanPoly (mc_t a)
 Calculates the atangent from a IQ number. More...
 
mc_t MathLib_Atan2Poly (mc_t y, mc_t x)
 Atan2 function, it calculates the atan based on the x and y values. More...
 

Variables

const uint16_t SquareRootLUT []
 

Detailed Description


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

Definition in file MathLib_Iq.c.

Macro Definition Documentation

◆ ATAN_POL_A0

#define ATAN_POL_A0   _IQ(0.25)

Definition at line 44 of file MathLib_Iq.c.

◆ ATAN_POL_A1

#define ATAN_POL_A1   _IQ(0.63611725)

Definition at line 43 of file MathLib_Iq.c.

◆ ATAN_POL_A3

#define ATAN_POL_A3   _IQ(-0.817719)

Definition at line 42 of file MathLib_Iq.c.

◆ ATAN_POL_A5

#define ATAN_POL_A5   _IQ(1.48697)

Definition at line 41 of file MathLib_Iq.c.

◆ ATAN_POL_A7

#define ATAN_POL_A7   _IQ(-1.57588)

Polynomial solution for the atan

Definition at line 40 of file MathLib_Iq.c.

◆ COS_TABLE_OFFSET

#define COS_TABLE_OFFSET   128

defines the size of the Sin Look-up table in 2^n logic, since 2^8 = 256, the table has 256 entries

Definition at line 28 of file MathLib_Iq.c.

◆ SIN_POL_A0

#define SIN_POL_A0   _IQ(0.70710781187)

Polynomial solution for the sine and cosine

Definition at line 32 of file MathLib_Iq.c.

◆ SIN_POL_A2

#define SIN_POL_A2   _IQ(-0.872348075361)

Definition at line 33 of file MathLib_Iq.c.

◆ SIN_POL_A4

#define SIN_POL_A4   _IQ(0.179251759526)

Definition at line 34 of file MathLib_Iq.c.

◆ SIN_POL_A6

#define SIN_POL_A6   _IQ(-0.0142718282624)

Definition at line 35 of file MathLib_Iq.c.

◆ SIN_POL_B1

#define SIN_POL_B1   _IQ(-1.11067032264)

Definition at line 36 of file MathLib_Iq.c.

◆ SIN_POL_B3

#define SIN_POL_B3   _IQ(0.4561589075945)

Definition at line 37 of file MathLib_Iq.c.

◆ SIN_POL_B5

#define SIN_POL_B5   _IQ(-0.0539104694791)

Definition at line 38 of file MathLib_Iq.c.

◆ SIN_TABLE_SIZE

#define SIN_TABLE_SIZE   512

Definition at line 25 of file MathLib_Iq.c.

◆ SIZE_SQRT_TABLE_2N

#define SIZE_SQRT_TABLE_2N   7

defines the size of the square root Look-up table in 2^n logic, since 2^7 = 128, the table has 128 entries

Definition at line 24 of file MathLib_Iq.c.

Function Documentation

◆ MathLib_Atan2Poly()

mc_t MathLib_Atan2Poly ( mc_t  y,
mc_t  x 
)

Atan2 function, it calculates the atan based on the x and y values.

Parameters
yy-axis value to be calculated
xx-axis value to be calculated
Returns
the angle

Definition at line 453 of file MathLib_Iq.c.

◆ MathLib_AtanPoly()

mc_t MathLib_AtanPoly ( mc_t  a)

Calculates the atangent from a IQ number.

Parameters
athe IQ value to be calculated, it needs to be between -0.5 and 0.5
Returns
The angle

Definition at line 430 of file MathLib_Iq.c.

◆ 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.

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:

Variable Documentation

◆ SquareRootLUT

const uint16_t SquareRootLUT[]
Initial value:
= { 0, 2896, 4096, 5016, 5792, 6476, 7094, 7663, 8192, 8689,
9159, 9606, 10033, 10442, 10837, 11217, 11585, 11941, 12288, 12624, 12952, 13272,
13584, 13890, 14189, 14481, 14768, 15049, 15325, 15597, 15863, 16125, 16384, 16638,
16888, 17134, 17377, 17617, 17854, 18087, 18317, 18545, 18770, 18992, 19211, 19428,
19643, 19855, 20066, 20274, 20479, 20683, 20885, 21085, 21283, 21479, 21673, 21866,
22057, 22246, 22434, 22620, 22805, 22988, 23170, 23350, 23529, 23707, 23883, 24058,
24232, 24404, 24575, 24745, 24914, 25082, 25249, 25414, 25579, 25742, 25905, 26066,
26226, 26386, 26544, 26702, 26858, 27014, 27169, 27323, 27476, 27628, 27780, 27930,
28080, 28229, 28377, 28524, 28671, 28817, 28962, 29107, 29250, 29393, 29536, 29677,
29818, 29959, 30098, 30237, 30376, 30514, 30651, 30787, 30923, 31059, 31193, 31327,
31461, 31594, 31727, 31858, 31990, 32121, 32251, 32381, 32510, 32639, 32767 }

Definition at line 65 of file MathLib_Iq.c.