mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-20 21:01:25 +03:00
[sam] Adding CMSIS 2.10
This commit is contained in:
@ -0,0 +1,254 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
* Copyright (C) 2010 ARM Limited. All rights reserved.
|
||||
*
|
||||
* $Date: 15. July 2011
|
||||
* $Revision: V1.0.10
|
||||
*
|
||||
* Project: CMSIS DSP Library
|
||||
* Title: arm_cos_f32.c
|
||||
*
|
||||
* Description: Fast cosine calculation for floating-point values.
|
||||
*
|
||||
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
|
||||
*
|
||||
* Version 1.0.10 2011/7/15
|
||||
* Big Endian support added and Merged M0 and M3/M4 Source code.
|
||||
*
|
||||
* Version 1.0.3 2010/11/29
|
||||
* Re-organized the CMSIS folders and updated documentation.
|
||||
*
|
||||
* Version 1.0.2 2010/11/11
|
||||
* Documentation updated.
|
||||
*
|
||||
* Version 1.0.1 2010/10/05
|
||||
* Production release and review comments incorporated.
|
||||
*
|
||||
* Version 1.0.0 2010/09/20
|
||||
* Production release and review comments incorporated.
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#include "arm_math.h"
|
||||
/**
|
||||
* @ingroup groupFastMath
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup cos Cosine
|
||||
*
|
||||
* Computes the trigonometric cosine function using a combination of table lookup
|
||||
* and cubic interpolation. There are separate functions for
|
||||
* Q15, Q31, and floating-point data types.
|
||||
* The input to the floating-point version is in radians while the
|
||||
* fixed-point Q15 and Q31 have a scaled input with the range
|
||||
* [0 1) mapping to [0 2*pi).
|
||||
*
|
||||
* The implementation is based on table lookup using 256 values together with cubic interpolation.
|
||||
* The steps used are:
|
||||
* -# Calculation of the nearest integer table index
|
||||
* -# Fetch the four table values a, b, c, and d
|
||||
* -# Compute the fractional portion (fract) of the table index.
|
||||
* -# Calculation of wa, wb, wc, wd
|
||||
* -# The final result equals <code>a*wa + b*wb + c*wc + d*wd</code>
|
||||
*
|
||||
* where
|
||||
* <pre>
|
||||
* a=Table[index-1];
|
||||
* b=Table[index+0];
|
||||
* c=Table[index+1];
|
||||
* d=Table[index+2];
|
||||
* </pre>
|
||||
* and
|
||||
* <pre>
|
||||
* wa=-(1/6)*fract.^3 + (1/2)*fract.^2 - (1/3)*fract;
|
||||
* wb=(1/2)*fract.^3 - fract.^2 - (1/2)*fract + 1;
|
||||
* wc=-(1/2)*fract.^3+(1/2)*fract.^2+fract;
|
||||
* wd=(1/6)*fract.^3 - (1/6)*fract;
|
||||
* </pre>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup cos
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \par
|
||||
* <b>Example code for Generation of Cos Table:</b>
|
||||
* tableSize = 256;
|
||||
* <pre>for(n = -1; n < (tableSize + 1); n++)
|
||||
* {
|
||||
* cosTable[n+1]= cos(2*pi*n/tableSize);
|
||||
* } </pre>
|
||||
* where pi value is 3.14159265358979
|
||||
*/
|
||||
|
||||
static const float32_t cosTable[259] = {
|
||||
0.999698817729949950f, 1.000000000000000000f, 0.999698817729949950f,
|
||||
0.998795449733734130f, 0.997290432453155520f, 0.995184719562530520f,
|
||||
0.992479562759399410f, 0.989176511764526370f,
|
||||
0.985277652740478520f, 0.980785250663757320f, 0.975702106952667240f,
|
||||
0.970031261444091800f, 0.963776051998138430f, 0.956940352916717530f,
|
||||
0.949528157711029050f, 0.941544055938720700f,
|
||||
0.932992815971374510f, 0.923879504203796390f, 0.914209783077239990f,
|
||||
0.903989315032958980f, 0.893224298954010010f, 0.881921291351318360f,
|
||||
0.870086967945098880f, 0.857728600502014160f,
|
||||
0.844853579998016360f, 0.831469595432281490f, 0.817584812641143800f,
|
||||
0.803207516670227050f, 0.788346409797668460f, 0.773010432720184330f,
|
||||
0.757208824157714840f, 0.740951120853424070f,
|
||||
0.724247097969055180f, 0.707106769084930420f, 0.689540565013885500f,
|
||||
0.671558976173400880f, 0.653172850608825680f, 0.634393274784088130f,
|
||||
0.615231573581695560f, 0.595699310302734380f,
|
||||
0.575808167457580570f, 0.555570244789123540f, 0.534997642040252690f,
|
||||
0.514102756977081300f, 0.492898195981979370f, 0.471396744251251220f,
|
||||
0.449611335992813110f, 0.427555084228515630f,
|
||||
0.405241310596466060f, 0.382683426141738890f, 0.359895050525665280f,
|
||||
0.336889863014221190f, 0.313681751489639280f, 0.290284663438797000f,
|
||||
0.266712754964828490f, 0.242980182170867920f,
|
||||
0.219101235270500180f, 0.195090323686599730f, 0.170961886644363400f,
|
||||
0.146730467677116390f, 0.122410677373409270f, 0.098017141222953796f,
|
||||
0.073564566671848297f, 0.049067676067352295f,
|
||||
0.024541229009628296f, 0.000000000000000061f, -0.024541229009628296f,
|
||||
-0.049067676067352295f, -0.073564566671848297f, -0.098017141222953796f,
|
||||
-0.122410677373409270f, -0.146730467677116390f,
|
||||
-0.170961886644363400f, -0.195090323686599730f, -0.219101235270500180f,
|
||||
-0.242980182170867920f, -0.266712754964828490f, -0.290284663438797000f,
|
||||
-0.313681751489639280f, -0.336889863014221190f,
|
||||
-0.359895050525665280f, -0.382683426141738890f, -0.405241310596466060f,
|
||||
-0.427555084228515630f, -0.449611335992813110f, -0.471396744251251220f,
|
||||
-0.492898195981979370f, -0.514102756977081300f,
|
||||
-0.534997642040252690f, -0.555570244789123540f, -0.575808167457580570f,
|
||||
-0.595699310302734380f, -0.615231573581695560f, -0.634393274784088130f,
|
||||
-0.653172850608825680f, -0.671558976173400880f,
|
||||
-0.689540565013885500f, -0.707106769084930420f, -0.724247097969055180f,
|
||||
-0.740951120853424070f, -0.757208824157714840f, -0.773010432720184330f,
|
||||
-0.788346409797668460f, -0.803207516670227050f,
|
||||
-0.817584812641143800f, -0.831469595432281490f, -0.844853579998016360f,
|
||||
-0.857728600502014160f, -0.870086967945098880f, -0.881921291351318360f,
|
||||
-0.893224298954010010f, -0.903989315032958980f,
|
||||
-0.914209783077239990f, -0.923879504203796390f, -0.932992815971374510f,
|
||||
-0.941544055938720700f, -0.949528157711029050f, -0.956940352916717530f,
|
||||
-0.963776051998138430f, -0.970031261444091800f,
|
||||
-0.975702106952667240f, -0.980785250663757320f, -0.985277652740478520f,
|
||||
-0.989176511764526370f, -0.992479562759399410f, -0.995184719562530520f,
|
||||
-0.997290432453155520f, -0.998795449733734130f,
|
||||
-0.999698817729949950f, -1.000000000000000000f, -0.999698817729949950f,
|
||||
-0.998795449733734130f, -0.997290432453155520f, -0.995184719562530520f,
|
||||
-0.992479562759399410f, -0.989176511764526370f,
|
||||
-0.985277652740478520f, -0.980785250663757320f, -0.975702106952667240f,
|
||||
-0.970031261444091800f, -0.963776051998138430f, -0.956940352916717530f,
|
||||
-0.949528157711029050f, -0.941544055938720700f,
|
||||
-0.932992815971374510f, -0.923879504203796390f, -0.914209783077239990f,
|
||||
-0.903989315032958980f, -0.893224298954010010f, -0.881921291351318360f,
|
||||
-0.870086967945098880f, -0.857728600502014160f,
|
||||
-0.844853579998016360f, -0.831469595432281490f, -0.817584812641143800f,
|
||||
-0.803207516670227050f, -0.788346409797668460f, -0.773010432720184330f,
|
||||
-0.757208824157714840f, -0.740951120853424070f,
|
||||
-0.724247097969055180f, -0.707106769084930420f, -0.689540565013885500f,
|
||||
-0.671558976173400880f, -0.653172850608825680f, -0.634393274784088130f,
|
||||
-0.615231573581695560f, -0.595699310302734380f,
|
||||
-0.575808167457580570f, -0.555570244789123540f, -0.534997642040252690f,
|
||||
-0.514102756977081300f, -0.492898195981979370f, -0.471396744251251220f,
|
||||
-0.449611335992813110f, -0.427555084228515630f,
|
||||
-0.405241310596466060f, -0.382683426141738890f, -0.359895050525665280f,
|
||||
-0.336889863014221190f, -0.313681751489639280f, -0.290284663438797000f,
|
||||
-0.266712754964828490f, -0.242980182170867920f,
|
||||
-0.219101235270500180f, -0.195090323686599730f, -0.170961886644363400f,
|
||||
-0.146730467677116390f, -0.122410677373409270f, -0.098017141222953796f,
|
||||
-0.073564566671848297f, -0.049067676067352295f,
|
||||
-0.024541229009628296f, -0.000000000000000184f, 0.024541229009628296f,
|
||||
0.049067676067352295f, 0.073564566671848297f, 0.098017141222953796f,
|
||||
0.122410677373409270f, 0.146730467677116390f,
|
||||
0.170961886644363400f, 0.195090323686599730f, 0.219101235270500180f,
|
||||
0.242980182170867920f, 0.266712754964828490f, 0.290284663438797000f,
|
||||
0.313681751489639280f, 0.336889863014221190f,
|
||||
0.359895050525665280f, 0.382683426141738890f, 0.405241310596466060f,
|
||||
0.427555084228515630f, 0.449611335992813110f, 0.471396744251251220f,
|
||||
0.492898195981979370f, 0.514102756977081300f,
|
||||
0.534997642040252690f, 0.555570244789123540f, 0.575808167457580570f,
|
||||
0.595699310302734380f, 0.615231573581695560f, 0.634393274784088130f,
|
||||
0.653172850608825680f, 0.671558976173400880f,
|
||||
0.689540565013885500f, 0.707106769084930420f, 0.724247097969055180f,
|
||||
0.740951120853424070f, 0.757208824157714840f, 0.773010432720184330f,
|
||||
0.788346409797668460f, 0.803207516670227050f,
|
||||
0.817584812641143800f, 0.831469595432281490f, 0.844853579998016360f,
|
||||
0.857728600502014160f, 0.870086967945098880f, 0.881921291351318360f,
|
||||
0.893224298954010010f, 0.903989315032958980f,
|
||||
0.914209783077239990f, 0.923879504203796390f, 0.932992815971374510f,
|
||||
0.941544055938720700f, 0.949528157711029050f, 0.956940352916717530f,
|
||||
0.963776051998138430f, 0.970031261444091800f,
|
||||
0.975702106952667240f, 0.980785250663757320f, 0.985277652740478520f,
|
||||
0.989176511764526370f, 0.992479562759399410f, 0.995184719562530520f,
|
||||
0.997290432453155520f, 0.998795449733734130f,
|
||||
0.999698817729949950f, 1.000000000000000000f, 0.999698817729949950f
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Fast approximation to the trigonometric cosine function for floating-point data.
|
||||
* @param[in] x input value in radians.
|
||||
* @return cos(x).
|
||||
*/
|
||||
|
||||
float32_t arm_cos_f32(
|
||||
float32_t x)
|
||||
{
|
||||
float32_t cosVal, fract, in;
|
||||
uint32_t index;
|
||||
uint32_t tableSize = (uint32_t) TABLE_SIZE;
|
||||
float32_t wa, wb, wc, wd;
|
||||
float32_t a, b, c, d;
|
||||
float32_t *tablePtr;
|
||||
int32_t n;
|
||||
|
||||
/* input x is in radians */
|
||||
/* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi */
|
||||
in = x * 0.159154943092f;
|
||||
|
||||
/* Calculation of floor value of input */
|
||||
n = (int32_t) in;
|
||||
|
||||
/* Make negative values towards -infinity */
|
||||
if(x < 0.0f)
|
||||
{
|
||||
n = n - 1;
|
||||
}
|
||||
|
||||
/* Map input value to [0 1] */
|
||||
in = in - (float32_t) n;
|
||||
|
||||
/* Calculation of index of the table */
|
||||
index = (uint32_t) (tableSize * in);
|
||||
|
||||
/* fractional value calculation */
|
||||
fract = ((float32_t) tableSize * in) - (float32_t) index;
|
||||
|
||||
/* Initialise table pointer */
|
||||
tablePtr = (float32_t *) & cosTable[index];
|
||||
|
||||
/* Read four nearest values of input value from the cos table */
|
||||
a = *tablePtr++;
|
||||
b = *tablePtr++;
|
||||
c = *tablePtr++;
|
||||
d = *tablePtr++;
|
||||
|
||||
/* Cubic interpolation process */
|
||||
wa = -(((0.166666667f) * fract) * (fract * fract)) +
|
||||
(((0.5f) * (fract * fract)) - ((0.3333333333333f) * fract));
|
||||
wb = ((((0.5f) * fract) * (fract * fract)) - (fract * fract)) +
|
||||
(-((0.5f) * fract) + 1.0f);
|
||||
wc = -(((0.5f) * fract) * (fract * fract)) +
|
||||
(((0.5f) * (fract * fract)) + fract);
|
||||
wd = (((0.166666667f) * fract) * (fract * fract)) -
|
||||
((0.166666667f) * fract);
|
||||
|
||||
/* Calculate cos value */
|
||||
cosVal = ((a * wa) + (b * wb)) + ((c * wc) + (d * wd));
|
||||
|
||||
/* Return the output value */
|
||||
return (cosVal);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @} end of cos group
|
||||
*/
|
@ -0,0 +1,189 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
* Copyright (C) 2010 ARM Limited. All rights reserved.
|
||||
*
|
||||
* $Date: 15. July 2011
|
||||
* $Revision: V1.0.10
|
||||
*
|
||||
* Project: CMSIS DSP Library
|
||||
* Title: arm_cos_q15.c
|
||||
*
|
||||
* Description: Fast cosine calculation for Q15 values.
|
||||
*
|
||||
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
|
||||
*
|
||||
* Version 1.0.10 2011/7/15
|
||||
* Big Endian support added and Merged M0 and M3/M4 Source code.
|
||||
*
|
||||
* Version 1.0.3 2010/11/29
|
||||
* Re-organized the CMSIS folders and updated documentation.
|
||||
*
|
||||
* Version 1.0.2 2010/11/11
|
||||
* Documentation updated.
|
||||
*
|
||||
* Version 1.0.1 2010/10/05
|
||||
* Production release and review comments incorporated.
|
||||
*
|
||||
* Version 1.0.0 2010/09/20
|
||||
* Production release and review comments incorporated.
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#include "arm_math.h"
|
||||
|
||||
/**
|
||||
* @ingroup groupFastMath
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup cos
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \par
|
||||
* Table Values are in Q15(1.15 Fixed point format) and generation is done in three steps
|
||||
* \par
|
||||
* First Generate cos values in floating point:
|
||||
* tableSize = 256;
|
||||
* <pre>for(n = -1; n < (tableSize + 1); n++)
|
||||
* {
|
||||
* cosTable[n+1]= cos(2*pi*n/tableSize);
|
||||
* }</pre>
|
||||
* where pi value is 3.14159265358979
|
||||
* \par
|
||||
* Secondly Convert Floating point to Q15(Fixed point):
|
||||
* (cosTable[i] * pow(2, 15))
|
||||
* \par
|
||||
* Finally Rounding to nearest integer is done
|
||||
* cosTable[i] += (cosTable[i] > 0 ? 0.5 :-0.5);
|
||||
*/
|
||||
|
||||
static const q15_t cosTableQ15[259] = {
|
||||
0x7ff6, 0x7fff, 0x7ff6, 0x7fd9, 0x7fa7, 0x7f62, 0x7f0a, 0x7e9d,
|
||||
0x7e1e, 0x7d8a, 0x7ce4, 0x7c2a, 0x7b5d, 0x7a7d, 0x798a, 0x7885,
|
||||
0x776c, 0x7642, 0x7505, 0x73b6, 0x7255, 0x70e3, 0x6f5f, 0x6dca,
|
||||
0x6c24, 0x6a6e, 0x68a7, 0x66d0, 0x64e9, 0x62f2, 0x60ec, 0x5ed7,
|
||||
0x5cb4, 0x5a82, 0x5843, 0x55f6, 0x539b, 0x5134, 0x4ec0, 0x4c40,
|
||||
0x49b4, 0x471d, 0x447b, 0x41ce, 0x3f17, 0x3c57, 0x398d, 0x36ba,
|
||||
0x33df, 0x30fc, 0x2e11, 0x2b1f, 0x2827, 0x2528, 0x2224, 0x1f1a,
|
||||
0x1c0c, 0x18f9, 0x15e2, 0x12c8, 0xfab, 0xc8c, 0x96b, 0x648,
|
||||
0x324, 0x0, 0xfcdc, 0xf9b8, 0xf695, 0xf374, 0xf055, 0xed38,
|
||||
0xea1e, 0xe707, 0xe3f4, 0xe0e6, 0xdddc, 0xdad8, 0xd7d9, 0xd4e1,
|
||||
0xd1ef, 0xcf04, 0xcc21, 0xc946, 0xc673, 0xc3a9, 0xc0e9, 0xbe32,
|
||||
0xbb85, 0xb8e3, 0xb64c, 0xb3c0, 0xb140, 0xaecc, 0xac65, 0xaa0a,
|
||||
0xa7bd, 0xa57e, 0xa34c, 0xa129, 0x9f14, 0x9d0e, 0x9b17, 0x9930,
|
||||
0x9759, 0x9592, 0x93dc, 0x9236, 0x90a1, 0x8f1d, 0x8dab, 0x8c4a,
|
||||
0x8afb, 0x89be, 0x8894, 0x877b, 0x8676, 0x8583, 0x84a3, 0x83d6,
|
||||
0x831c, 0x8276, 0x81e2, 0x8163, 0x80f6, 0x809e, 0x8059, 0x8027,
|
||||
0x800a, 0x8000, 0x800a, 0x8027, 0x8059, 0x809e, 0x80f6, 0x8163,
|
||||
0x81e2, 0x8276, 0x831c, 0x83d6, 0x84a3, 0x8583, 0x8676, 0x877b,
|
||||
0x8894, 0x89be, 0x8afb, 0x8c4a, 0x8dab, 0x8f1d, 0x90a1, 0x9236,
|
||||
0x93dc, 0x9592, 0x9759, 0x9930, 0x9b17, 0x9d0e, 0x9f14, 0xa129,
|
||||
0xa34c, 0xa57e, 0xa7bd, 0xaa0a, 0xac65, 0xaecc, 0xb140, 0xb3c0,
|
||||
0xb64c, 0xb8e3, 0xbb85, 0xbe32, 0xc0e9, 0xc3a9, 0xc673, 0xc946,
|
||||
0xcc21, 0xcf04, 0xd1ef, 0xd4e1, 0xd7d9, 0xdad8, 0xdddc, 0xe0e6,
|
||||
0xe3f4, 0xe707, 0xea1e, 0xed38, 0xf055, 0xf374, 0xf695, 0xf9b8,
|
||||
0xfcdc, 0x0, 0x324, 0x648, 0x96b, 0xc8c, 0xfab, 0x12c8,
|
||||
0x15e2, 0x18f9, 0x1c0c, 0x1f1a, 0x2224, 0x2528, 0x2827, 0x2b1f,
|
||||
0x2e11, 0x30fc, 0x33df, 0x36ba, 0x398d, 0x3c57, 0x3f17, 0x41ce,
|
||||
0x447b, 0x471d, 0x49b4, 0x4c40, 0x4ec0, 0x5134, 0x539b, 0x55f6,
|
||||
0x5843, 0x5a82, 0x5cb4, 0x5ed7, 0x60ec, 0x62f2, 0x64e9, 0x66d0,
|
||||
0x68a7, 0x6a6e, 0x6c24, 0x6dca, 0x6f5f, 0x70e3, 0x7255, 0x73b6,
|
||||
0x7505, 0x7642, 0x776c, 0x7885, 0x798a, 0x7a7d, 0x7b5d, 0x7c2a,
|
||||
0x7ce4, 0x7d8a, 0x7e1e, 0x7e9d, 0x7f0a, 0x7f62, 0x7fa7, 0x7fd9,
|
||||
0x7ff6, 0x7fff, 0x7ff6
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Fast approximation to the trigonometric cosine function for Q15 data.
|
||||
* @param[in] x Scaled input value in radians.
|
||||
* @return cos(x).
|
||||
*
|
||||
* The Q15 input value is in the range [0 +1) and is mapped to a radian value in the range [0 2*pi).
|
||||
*/
|
||||
|
||||
q15_t arm_cos_q15(
|
||||
q15_t x)
|
||||
{
|
||||
q31_t cosVal; /* Temporary variable for output */
|
||||
q15_t *tablePtr; /* Pointer to table */
|
||||
q15_t in, in2; /* Temporary variables for input */
|
||||
q31_t wa, wb, wc, wd; /* Cubic interpolation coefficients */
|
||||
q15_t a, b, c, d; /* Four nearest output values */
|
||||
q15_t fract, fractCube, fractSquare; /* Variables for fractional value */
|
||||
q15_t oneBy6 = 0x1555; /* Fixed point value of 1/6 */
|
||||
q15_t tableSpacing = TABLE_SPACING_Q15; /* Table spacing */
|
||||
int32_t index; /* Index variable */
|
||||
|
||||
in = x;
|
||||
|
||||
/* Calculate the nearest index */
|
||||
index = (int32_t) in / tableSpacing;
|
||||
|
||||
/* Calculate the nearest value of input */
|
||||
in2 = (q15_t) index *tableSpacing;
|
||||
|
||||
/* Calculation of fractional value */
|
||||
fract = (in - in2) << 8;
|
||||
|
||||
/* fractSquare = fract * fract */
|
||||
fractSquare = (q15_t) ((fract * fract) >> 15);
|
||||
|
||||
/* fractCube = fract * fract * fract */
|
||||
fractCube = (q15_t) ((fractSquare * fract) >> 15);
|
||||
|
||||
/* Initialise table pointer */
|
||||
tablePtr = (q15_t *) & cosTableQ15[index];
|
||||
|
||||
/* Cubic interpolation process */
|
||||
/* Calculation of wa */
|
||||
/* wa = -(oneBy6)*fractCube + (fractSquare >> 1u) - (0x2AAA)*fract; */
|
||||
wa = (q31_t) oneBy6 *fractCube;
|
||||
wa += (q31_t) 0x2AAA *fract;
|
||||
wa = -(wa >> 15);
|
||||
wa += (fractSquare >> 1u);
|
||||
|
||||
/* Read first nearest value of output from the cos table */
|
||||
a = *tablePtr++;
|
||||
|
||||
/* cosVal = a * wa */
|
||||
cosVal = a * wa;
|
||||
|
||||
/* Calculation of wb */
|
||||
wb = (((fractCube >> 1u) - fractSquare) - (fract >> 1u)) + 0x7FFF;
|
||||
|
||||
/* Read second nearest value of output from the cos table */
|
||||
b = *tablePtr++;
|
||||
|
||||
/* cosVal += b*wb */
|
||||
cosVal += b * wb;
|
||||
|
||||
/* Calculation of wc */
|
||||
wc = -(q31_t) fractCube + fractSquare;
|
||||
wc = (wc >> 1u) + fract;
|
||||
|
||||
/* Read third nearest value of output from the cos table */
|
||||
c = *tablePtr++;
|
||||
|
||||
/* cosVal += c*wc */
|
||||
cosVal += c * wc;
|
||||
|
||||
/* Calculation of wd */
|
||||
/* wd = (oneBy6)*fractCube - (oneBy6)*fract; */
|
||||
fractCube = fractCube - fract;
|
||||
wd = ((q15_t) (((q31_t) oneBy6 * fractCube) >> 15));
|
||||
|
||||
/* Read fourth nearest value of output from the cos table */
|
||||
d = *tablePtr++;
|
||||
|
||||
/* cosVal += d*wd; */
|
||||
cosVal += d * wd;
|
||||
|
||||
/* Return the output value in 1.15(q15) format */
|
||||
return ((q15_t) (cosVal >> 15u));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @} end of cos group
|
||||
*/
|
@ -0,0 +1,225 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
* Copyright (C) 2010 ARM Limited. All rights reserved.
|
||||
*
|
||||
* $Date: 15. July 2011
|
||||
* $Revision: V1.0.10
|
||||
*
|
||||
* Project: CMSIS DSP Library
|
||||
* Title: arm_cos_q31.c
|
||||
*
|
||||
* Description: Fast cosine calculation for Q31 values.
|
||||
*
|
||||
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
|
||||
*
|
||||
* Version 1.0.10 2011/7/15
|
||||
* Big Endian support added and Merged M0 and M3/M4 Source code.
|
||||
*
|
||||
* Version 1.0.3 2010/11/29
|
||||
* Re-organized the CMSIS folders and updated documentation.
|
||||
*
|
||||
* Version 1.0.2 2010/11/11
|
||||
* Documentation updated.
|
||||
*
|
||||
* Version 1.0.1 2010/10/05
|
||||
* Production release and review comments incorporated.
|
||||
*
|
||||
* Version 1.0.0 2010/09/20
|
||||
* Production release and review comments incorporated.
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#include "arm_math.h"
|
||||
|
||||
/**
|
||||
* @ingroup groupFastMath
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup cos
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \par
|
||||
* Table Values are in Q31(1.31 Fixed point format) and generation is done in three steps
|
||||
* First Generate cos values in floating point:
|
||||
* tableSize = 256;
|
||||
* <pre>for(n = -1; n < (tableSize + 1); n++)
|
||||
* {
|
||||
* cosTable[n+1]= cos(2*pi*n/tableSize);
|
||||
* } </pre>
|
||||
* where pi value is 3.14159265358979
|
||||
* \par
|
||||
* Secondly Convert Floating point to Q31(Fixed point):
|
||||
* (cosTable[i] * pow(2, 31))
|
||||
* \par
|
||||
* Finally Rounding to nearest integer is done
|
||||
* cosTable[i] += (cosTable[i] > 0 ? 0.5 :-0.5);
|
||||
*/
|
||||
|
||||
|
||||
static const q31_t cosTableQ31[259] = {
|
||||
0x7ff62182, 0x7fffffff, 0x7ff62182, 0x7fd8878e, 0x7fa736b4, 0x7f62368f,
|
||||
0x7f0991c4, 0x7e9d55fc,
|
||||
0x7e1d93ea, 0x7d8a5f40, 0x7ce3ceb2, 0x7c29fbee, 0x7b5d039e, 0x7a7d055b,
|
||||
0x798a23b1, 0x78848414,
|
||||
0x776c4edb, 0x7641af3d, 0x7504d345, 0x73b5ebd1, 0x72552c85, 0x70e2cbc6,
|
||||
0x6f5f02b2, 0x6dca0d14,
|
||||
0x6c242960, 0x6a6d98a4, 0x68a69e81, 0x66cf8120, 0x64e88926, 0x62f201ac,
|
||||
0x60ec3830, 0x5ed77c8a,
|
||||
0x5cb420e0, 0x5a82799a, 0x5842dd54, 0x55f5a4d2, 0x539b2af0, 0x5133cc94,
|
||||
0x4ebfe8a5, 0x4c3fdff4,
|
||||
0x49b41533, 0x471cece7, 0x447acd50, 0x41ce1e65, 0x3f1749b8, 0x3c56ba70,
|
||||
0x398cdd32, 0x36ba2014,
|
||||
0x33def287, 0x30fbc54d, 0x2e110a62, 0x2b1f34eb, 0x2826b928, 0x25280c5e,
|
||||
0x2223a4c5, 0x1f19f97b,
|
||||
0x1c0b826a, 0x18f8b83c, 0x15e21445, 0x12c8106f, 0xfab272b, 0xc8bd35e,
|
||||
0x96a9049, 0x647d97c,
|
||||
0x3242abf, 0x0, 0xfcdbd541, 0xf9b82684, 0xf6956fb7, 0xf3742ca2, 0xf054d8d5,
|
||||
0xed37ef91,
|
||||
0xea1debbb, 0xe70747c4, 0xe3f47d96, 0xe0e60685, 0xdddc5b3b, 0xdad7f3a2,
|
||||
0xd7d946d8, 0xd4e0cb15,
|
||||
0xd1eef59e, 0xcf043ab3, 0xcc210d79, 0xc945dfec, 0xc67322ce, 0xc3a94590,
|
||||
0xc0e8b648, 0xbe31e19b,
|
||||
0xbb8532b0, 0xb8e31319, 0xb64beacd, 0xb3c0200c, 0xb140175b, 0xaecc336c,
|
||||
0xac64d510, 0xaa0a5b2e,
|
||||
0xa7bd22ac, 0xa57d8666, 0xa34bdf20, 0xa1288376, 0x9f13c7d0, 0x9d0dfe54,
|
||||
0x9b1776da, 0x99307ee0,
|
||||
0x9759617f, 0x9592675c, 0x93dbd6a0, 0x9235f2ec, 0x90a0fd4e, 0x8f1d343a,
|
||||
0x8daad37b, 0x8c4a142f,
|
||||
0x8afb2cbb, 0x89be50c3, 0x8893b125, 0x877b7bec, 0x8675dc4f, 0x8582faa5,
|
||||
0x84a2fc62, 0x83d60412,
|
||||
0x831c314e, 0x8275a0c0, 0x81e26c16, 0x8162aa04, 0x80f66e3c, 0x809dc971,
|
||||
0x8058c94c, 0x80277872,
|
||||
0x8009de7e, 0x80000000, 0x8009de7e, 0x80277872, 0x8058c94c, 0x809dc971,
|
||||
0x80f66e3c, 0x8162aa04,
|
||||
0x81e26c16, 0x8275a0c0, 0x831c314e, 0x83d60412, 0x84a2fc62, 0x8582faa5,
|
||||
0x8675dc4f, 0x877b7bec,
|
||||
0x8893b125, 0x89be50c3, 0x8afb2cbb, 0x8c4a142f, 0x8daad37b, 0x8f1d343a,
|
||||
0x90a0fd4e, 0x9235f2ec,
|
||||
0x93dbd6a0, 0x9592675c, 0x9759617f, 0x99307ee0, 0x9b1776da, 0x9d0dfe54,
|
||||
0x9f13c7d0, 0xa1288376,
|
||||
0xa34bdf20, 0xa57d8666, 0xa7bd22ac, 0xaa0a5b2e, 0xac64d510, 0xaecc336c,
|
||||
0xb140175b, 0xb3c0200c,
|
||||
0xb64beacd, 0xb8e31319, 0xbb8532b0, 0xbe31e19b, 0xc0e8b648, 0xc3a94590,
|
||||
0xc67322ce, 0xc945dfec,
|
||||
0xcc210d79, 0xcf043ab3, 0xd1eef59e, 0xd4e0cb15, 0xd7d946d8, 0xdad7f3a2,
|
||||
0xdddc5b3b, 0xe0e60685,
|
||||
0xe3f47d96, 0xe70747c4, 0xea1debbb, 0xed37ef91, 0xf054d8d5, 0xf3742ca2,
|
||||
0xf6956fb7, 0xf9b82684,
|
||||
0xfcdbd541, 0x0, 0x3242abf, 0x647d97c, 0x96a9049, 0xc8bd35e, 0xfab272b,
|
||||
0x12c8106f,
|
||||
0x15e21445, 0x18f8b83c, 0x1c0b826a, 0x1f19f97b, 0x2223a4c5, 0x25280c5e,
|
||||
0x2826b928, 0x2b1f34eb,
|
||||
0x2e110a62, 0x30fbc54d, 0x33def287, 0x36ba2014, 0x398cdd32, 0x3c56ba70,
|
||||
0x3f1749b8, 0x41ce1e65,
|
||||
0x447acd50, 0x471cece7, 0x49b41533, 0x4c3fdff4, 0x4ebfe8a5, 0x5133cc94,
|
||||
0x539b2af0, 0x55f5a4d2,
|
||||
0x5842dd54, 0x5a82799a, 0x5cb420e0, 0x5ed77c8a, 0x60ec3830, 0x62f201ac,
|
||||
0x64e88926, 0x66cf8120,
|
||||
0x68a69e81, 0x6a6d98a4, 0x6c242960, 0x6dca0d14, 0x6f5f02b2, 0x70e2cbc6,
|
||||
0x72552c85, 0x73b5ebd1,
|
||||
0x7504d345, 0x7641af3d, 0x776c4edb, 0x78848414, 0x798a23b1, 0x7a7d055b,
|
||||
0x7b5d039e, 0x7c29fbee,
|
||||
0x7ce3ceb2, 0x7d8a5f40, 0x7e1d93ea, 0x7e9d55fc, 0x7f0991c4, 0x7f62368f,
|
||||
0x7fa736b4, 0x7fd8878e,
|
||||
0x7ff62182, 0x7fffffff, 0x7ff62182
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Fast approximation to the trigonometric cosine function for Q31 data.
|
||||
* @param[in] x Scaled input value in radians.
|
||||
* @return cos(x).
|
||||
*
|
||||
* The Q31 input value is in the range [0 +1) and is mapped to a radian value in the range [0 2*pi).
|
||||
*/
|
||||
|
||||
q31_t arm_cos_q31(
|
||||
q31_t x)
|
||||
{
|
||||
q31_t cosVal, in, in2; /* Temporary variables for input, output */
|
||||
q31_t wa, wb, wc, wd; /* Cubic interpolation coefficients */
|
||||
q31_t a, b, c, d; /* Four nearest output values */
|
||||
q31_t *tablePtr; /* Pointer to table */
|
||||
q31_t fract, fractCube, fractSquare; /* Temporary values for fractional values */
|
||||
q31_t oneBy6 = 0x15555555; /* Fixed point value of 1/6 */
|
||||
q31_t tableSpacing = TABLE_SPACING_Q31; /* Table spacing */
|
||||
q31_t temp; /* Temporary variable for intermediate process */
|
||||
uint32_t index; /* Index variable */
|
||||
|
||||
in = x;
|
||||
|
||||
/* Calculate the nearest index */
|
||||
index = in / tableSpacing;
|
||||
|
||||
/* Calculate the nearest value of input */
|
||||
in2 = ((q31_t) index) * tableSpacing;
|
||||
|
||||
/* Calculation of fractional value */
|
||||
fract = (in - in2) << 8;
|
||||
|
||||
/* fractSquare = fract * fract */
|
||||
fractSquare = ((q31_t) (((q63_t) fract * fract) >> 32));
|
||||
fractSquare = fractSquare << 1;
|
||||
|
||||
/* fractCube = fract * fract * fract */
|
||||
fractCube = ((q31_t) (((q63_t) fractSquare * fract) >> 32));
|
||||
fractCube = fractCube << 1;
|
||||
|
||||
/* Initialise table pointer */
|
||||
tablePtr = (q31_t *) & cosTableQ31[index];
|
||||
|
||||
/* Cubic interpolation process */
|
||||
/* Calculation of wa */
|
||||
/* wa = -(oneBy6)*fractCube + (fractSquare >> 1u) - (0x2AAAAAAA)*fract; */
|
||||
wa = ((q31_t) (((q63_t) oneBy6 * fractCube) >> 32));
|
||||
temp = 0x2AAAAAAA;
|
||||
wa = (q31_t) ((((q63_t) wa << 32) + ((q63_t) temp * fract)) >> 32);
|
||||
wa = -(wa << 1u);
|
||||
wa += (fractSquare >> 1u);
|
||||
|
||||
/* Read first nearest value of output from the cos table */
|
||||
a = *tablePtr++;
|
||||
|
||||
/* cosVal = a*wa */
|
||||
cosVal = ((q31_t) (((q63_t) a * wa) >> 32));
|
||||
|
||||
/* q31(1.31) Fixed point value of 1 */
|
||||
temp = 0x7FFFFFFF;
|
||||
|
||||
/* Calculation of wb */
|
||||
wb = ((fractCube >> 1u) - (fractSquare + (fract >> 1u))) + temp;
|
||||
/* Read second nearest value of output from the cos table */
|
||||
b = *tablePtr++;
|
||||
|
||||
/* cosVal += b*wb */
|
||||
cosVal = (q31_t) ((((q63_t) cosVal << 32) + ((q63_t) b * (wb))) >> 32);
|
||||
|
||||
/* Calculation of wc */
|
||||
wc = -fractCube + fractSquare;
|
||||
wc = (wc >> 1u) + fract;
|
||||
/* Read third nearest values of output value from the cos table */
|
||||
c = *tablePtr++;
|
||||
|
||||
/* cosVal += c*wc */
|
||||
cosVal = (q31_t) ((((q63_t) cosVal << 32) + ((q63_t) c * (wc))) >> 32);
|
||||
|
||||
/* Calculation of wd */
|
||||
/* wd = (oneBy6)*fractCube - (oneBy6)*fract; */
|
||||
fractCube = fractCube - fract;
|
||||
wd = ((q31_t) (((q63_t) oneBy6 * fractCube) >> 32));
|
||||
wd = (wd << 1u);
|
||||
|
||||
/* Read fourth nearest value of output from the cos table */
|
||||
d = *tablePtr++;
|
||||
|
||||
/* cosVal += d*wd; */
|
||||
cosVal = (q31_t) ((((q63_t) cosVal << 32) + ((q63_t) d * (wd))) >> 32);
|
||||
|
||||
/* convert cosVal in 2.30 format to 1.31 format */
|
||||
return (cosVal << 1u);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @} end of cos group
|
||||
*/
|
@ -0,0 +1,257 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
* Copyright (C) 2010 ARM Limited. All rights reserved.
|
||||
*
|
||||
* $Date: 15. July 2011
|
||||
* $Revision: V1.0.10
|
||||
*
|
||||
* Project: CMSIS DSP Library
|
||||
* Title: arm_sin_f32.c
|
||||
*
|
||||
* Description: Fast sine calculation for floating-point values.
|
||||
*
|
||||
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
|
||||
*
|
||||
* Version 1.0.10 2011/7/15
|
||||
* Big Endian support added and Merged M0 and M3/M4 Source code.
|
||||
*
|
||||
* Version 1.0.3 2010/11/29
|
||||
* Re-organized the CMSIS folders and updated documentation.
|
||||
*
|
||||
* Version 1.0.2 2010/11/11
|
||||
* Documentation updated.
|
||||
*
|
||||
* Version 1.0.1 2010/10/05
|
||||
* Production release and review comments incorporated.
|
||||
*
|
||||
* Version 1.0.0 2010/09/20
|
||||
* Production release and review comments incorporated.
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#include "arm_math.h"
|
||||
|
||||
/**
|
||||
* @ingroup groupFastMath
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup sin Sine
|
||||
*
|
||||
* Computes the trigonometric sine function using a combination of table lookup
|
||||
* and cubic interpolation. There are separate functions for
|
||||
* Q15, Q31, and floating-point data types.
|
||||
* The input to the floating-point version is in radians while the
|
||||
* fixed-point Q15 and Q31 have a scaled input with the range
|
||||
* [0 1) mapping to [0 2*pi).
|
||||
*
|
||||
* The implementation is based on table lookup using 256 values together with cubic interpolation.
|
||||
* The steps used are:
|
||||
* -# Calculation of the nearest integer table index
|
||||
* -# Fetch the four table values a, b, c, and d
|
||||
* -# Compute the fractional portion (fract) of the table index.
|
||||
* -# Calculation of wa, wb, wc, wd
|
||||
* -# The final result equals <code>a*wa + b*wb + c*wc + d*wd</code>
|
||||
*
|
||||
* where
|
||||
* <pre>
|
||||
* a=Table[index-1];
|
||||
* b=Table[index+0];
|
||||
* c=Table[index+1];
|
||||
* d=Table[index+2];
|
||||
* </pre>
|
||||
* and
|
||||
* <pre>
|
||||
* wa=-(1/6)*fract.^3 + (1/2)*fract.^2 - (1/3)*fract;
|
||||
* wb=(1/2)*fract.^3 - fract.^2 - (1/2)*fract + 1;
|
||||
* wc=-(1/2)*fract.^3+(1/2)*fract.^2+fract;
|
||||
* wd=(1/6)*fract.^3 - (1/6)*fract;
|
||||
* </pre>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup sin
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \par
|
||||
* Example code for Generation of Floating-point Sin Table:
|
||||
* tableSize = 256;
|
||||
* <pre>for(n = -1; n < (tableSize + 1); n++)
|
||||
* {
|
||||
* sinTable[n+1]=sin(2*pi*n/tableSize);
|
||||
* }</pre>
|
||||
* \par
|
||||
* where pi value is 3.14159265358979
|
||||
*/
|
||||
|
||||
static const float32_t sinTable[259] = {
|
||||
-0.024541229009628296f, 0.000000000000000000f, 0.024541229009628296f,
|
||||
0.049067676067352295f, 0.073564566671848297f, 0.098017141222953796f,
|
||||
0.122410677373409270f, 0.146730467677116390f,
|
||||
0.170961886644363400f, 0.195090323686599730f, 0.219101235270500180f,
|
||||
0.242980182170867920f, 0.266712754964828490f, 0.290284663438797000f,
|
||||
0.313681751489639280f, 0.336889863014221190f,
|
||||
0.359895050525665280f, 0.382683426141738890f, 0.405241310596466060f,
|
||||
0.427555084228515630f, 0.449611335992813110f, 0.471396744251251220f,
|
||||
0.492898195981979370f, 0.514102756977081300f,
|
||||
0.534997642040252690f, 0.555570244789123540f, 0.575808167457580570f,
|
||||
0.595699310302734380f, 0.615231573581695560f, 0.634393274784088130f,
|
||||
0.653172850608825680f, 0.671558976173400880f,
|
||||
0.689540565013885500f, 0.707106769084930420f, 0.724247097969055180f,
|
||||
0.740951120853424070f, 0.757208824157714840f, 0.773010432720184330f,
|
||||
0.788346409797668460f, 0.803207516670227050f,
|
||||
0.817584812641143800f, 0.831469595432281490f, 0.844853579998016360f,
|
||||
0.857728600502014160f, 0.870086967945098880f, 0.881921291351318360f,
|
||||
0.893224298954010010f, 0.903989315032958980f,
|
||||
0.914209783077239990f, 0.923879504203796390f, 0.932992815971374510f,
|
||||
0.941544055938720700f, 0.949528157711029050f, 0.956940352916717530f,
|
||||
0.963776051998138430f, 0.970031261444091800f,
|
||||
0.975702106952667240f, 0.980785250663757320f, 0.985277652740478520f,
|
||||
0.989176511764526370f, 0.992479562759399410f, 0.995184719562530520f,
|
||||
0.997290432453155520f, 0.998795449733734130f,
|
||||
0.999698817729949950f, 1.000000000000000000f, 0.999698817729949950f,
|
||||
0.998795449733734130f, 0.997290432453155520f, 0.995184719562530520f,
|
||||
0.992479562759399410f, 0.989176511764526370f,
|
||||
0.985277652740478520f, 0.980785250663757320f, 0.975702106952667240f,
|
||||
0.970031261444091800f, 0.963776051998138430f, 0.956940352916717530f,
|
||||
0.949528157711029050f, 0.941544055938720700f,
|
||||
0.932992815971374510f, 0.923879504203796390f, 0.914209783077239990f,
|
||||
0.903989315032958980f, 0.893224298954010010f, 0.881921291351318360f,
|
||||
0.870086967945098880f, 0.857728600502014160f,
|
||||
0.844853579998016360f, 0.831469595432281490f, 0.817584812641143800f,
|
||||
0.803207516670227050f, 0.788346409797668460f, 0.773010432720184330f,
|
||||
0.757208824157714840f, 0.740951120853424070f,
|
||||
0.724247097969055180f, 0.707106769084930420f, 0.689540565013885500f,
|
||||
0.671558976173400880f, 0.653172850608825680f, 0.634393274784088130f,
|
||||
0.615231573581695560f, 0.595699310302734380f,
|
||||
0.575808167457580570f, 0.555570244789123540f, 0.534997642040252690f,
|
||||
0.514102756977081300f, 0.492898195981979370f, 0.471396744251251220f,
|
||||
0.449611335992813110f, 0.427555084228515630f,
|
||||
0.405241310596466060f, 0.382683426141738890f, 0.359895050525665280f,
|
||||
0.336889863014221190f, 0.313681751489639280f, 0.290284663438797000f,
|
||||
0.266712754964828490f, 0.242980182170867920f,
|
||||
0.219101235270500180f, 0.195090323686599730f, 0.170961886644363400f,
|
||||
0.146730467677116390f, 0.122410677373409270f, 0.098017141222953796f,
|
||||
0.073564566671848297f, 0.049067676067352295f,
|
||||
0.024541229009628296f, 0.000000000000000122f, -0.024541229009628296f,
|
||||
-0.049067676067352295f, -0.073564566671848297f, -0.098017141222953796f,
|
||||
-0.122410677373409270f, -0.146730467677116390f,
|
||||
-0.170961886644363400f, -0.195090323686599730f, -0.219101235270500180f,
|
||||
-0.242980182170867920f, -0.266712754964828490f, -0.290284663438797000f,
|
||||
-0.313681751489639280f, -0.336889863014221190f,
|
||||
-0.359895050525665280f, -0.382683426141738890f, -0.405241310596466060f,
|
||||
-0.427555084228515630f, -0.449611335992813110f, -0.471396744251251220f,
|
||||
-0.492898195981979370f, -0.514102756977081300f,
|
||||
-0.534997642040252690f, -0.555570244789123540f, -0.575808167457580570f,
|
||||
-0.595699310302734380f, -0.615231573581695560f, -0.634393274784088130f,
|
||||
-0.653172850608825680f, -0.671558976173400880f,
|
||||
-0.689540565013885500f, -0.707106769084930420f, -0.724247097969055180f,
|
||||
-0.740951120853424070f, -0.757208824157714840f, -0.773010432720184330f,
|
||||
-0.788346409797668460f, -0.803207516670227050f,
|
||||
-0.817584812641143800f, -0.831469595432281490f, -0.844853579998016360f,
|
||||
-0.857728600502014160f, -0.870086967945098880f, -0.881921291351318360f,
|
||||
-0.893224298954010010f, -0.903989315032958980f,
|
||||
-0.914209783077239990f, -0.923879504203796390f, -0.932992815971374510f,
|
||||
-0.941544055938720700f, -0.949528157711029050f, -0.956940352916717530f,
|
||||
-0.963776051998138430f, -0.970031261444091800f,
|
||||
-0.975702106952667240f, -0.980785250663757320f, -0.985277652740478520f,
|
||||
-0.989176511764526370f, -0.992479562759399410f, -0.995184719562530520f,
|
||||
-0.997290432453155520f, -0.998795449733734130f,
|
||||
-0.999698817729949950f, -1.000000000000000000f, -0.999698817729949950f,
|
||||
-0.998795449733734130f, -0.997290432453155520f, -0.995184719562530520f,
|
||||
-0.992479562759399410f, -0.989176511764526370f,
|
||||
-0.985277652740478520f, -0.980785250663757320f, -0.975702106952667240f,
|
||||
-0.970031261444091800f, -0.963776051998138430f, -0.956940352916717530f,
|
||||
-0.949528157711029050f, -0.941544055938720700f,
|
||||
-0.932992815971374510f, -0.923879504203796390f, -0.914209783077239990f,
|
||||
-0.903989315032958980f, -0.893224298954010010f, -0.881921291351318360f,
|
||||
-0.870086967945098880f, -0.857728600502014160f,
|
||||
-0.844853579998016360f, -0.831469595432281490f, -0.817584812641143800f,
|
||||
-0.803207516670227050f, -0.788346409797668460f, -0.773010432720184330f,
|
||||
-0.757208824157714840f, -0.740951120853424070f,
|
||||
-0.724247097969055180f, -0.707106769084930420f, -0.689540565013885500f,
|
||||
-0.671558976173400880f, -0.653172850608825680f, -0.634393274784088130f,
|
||||
-0.615231573581695560f, -0.595699310302734380f,
|
||||
-0.575808167457580570f, -0.555570244789123540f, -0.534997642040252690f,
|
||||
-0.514102756977081300f, -0.492898195981979370f, -0.471396744251251220f,
|
||||
-0.449611335992813110f, -0.427555084228515630f,
|
||||
-0.405241310596466060f, -0.382683426141738890f, -0.359895050525665280f,
|
||||
-0.336889863014221190f, -0.313681751489639280f, -0.290284663438797000f,
|
||||
-0.266712754964828490f, -0.242980182170867920f,
|
||||
-0.219101235270500180f, -0.195090323686599730f, -0.170961886644363400f,
|
||||
-0.146730467677116390f, -0.122410677373409270f, -0.098017141222953796f,
|
||||
-0.073564566671848297f, -0.049067676067352295f,
|
||||
-0.024541229009628296f, -0.000000000000000245f, 0.024541229009628296f
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Fast approximation to the trigonometric sine function for floating-point data.
|
||||
* @param[in] x input value in radians.
|
||||
* @return sin(x).
|
||||
*/
|
||||
|
||||
float32_t arm_sin_f32(
|
||||
float32_t x)
|
||||
{
|
||||
float32_t sinVal, fract, in; /* Temporary variables for input, output */
|
||||
uint32_t index; /* Index variable */
|
||||
uint32_t tableSize = (uint32_t) TABLE_SIZE; /* Initialise tablesize */
|
||||
float32_t wa, wb, wc, wd; /* Cubic interpolation coefficients */
|
||||
float32_t a, b, c, d; /* Four nearest output values */
|
||||
float32_t *tablePtr; /* Pointer to table */
|
||||
int32_t n;
|
||||
|
||||
/* input x is in radians */
|
||||
/* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi */
|
||||
in = x * 0.159154943092f;
|
||||
|
||||
/* Calculation of floor value of input */
|
||||
n = (int32_t) in;
|
||||
|
||||
/* Make negative values towards -infinity */
|
||||
if(x < 0.0f)
|
||||
{
|
||||
n = n - 1;
|
||||
}
|
||||
|
||||
/* Map input value to [0 1] */
|
||||
in = in - (float32_t) n;
|
||||
|
||||
/* Calculation of index of the table */
|
||||
index = (uint32_t) (tableSize * in);
|
||||
|
||||
/* fractional value calculation */
|
||||
fract = ((float32_t) tableSize * in) - (float32_t) index;
|
||||
|
||||
/* Initialise table pointer */
|
||||
tablePtr = (float32_t *) & sinTable[index];
|
||||
|
||||
/* Read four nearest values of output value from the sin table */
|
||||
a = *tablePtr++;
|
||||
b = *tablePtr++;
|
||||
c = *tablePtr++;
|
||||
d = *tablePtr++;
|
||||
|
||||
/* Cubic interpolation process */
|
||||
wa = -(((0.166666667f) * (fract * (fract * fract))) +
|
||||
((0.3333333333333f) * fract)) + ((0.5f) * (fract * fract));
|
||||
wb = (((0.5f) * (fract * (fract * fract))) -
|
||||
((fract * fract) + ((0.5f) * fract))) + 1.0f;
|
||||
wc = (-((0.5f) * (fract * (fract * fract))) +
|
||||
((0.5f) * (fract * fract))) + fract;
|
||||
wd = ((0.166666667f) * (fract * (fract * fract))) -
|
||||
((0.166666667f) * fract);
|
||||
|
||||
/* Calculate sin value */
|
||||
sinVal = ((a * wa) + (b * wb)) + ((c * wc) + (d * wd));
|
||||
|
||||
/* Return the output value */
|
||||
return (sinVal);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @} end of sin group
|
||||
*/
|
@ -0,0 +1,192 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
* Copyright (C) 2010 ARM Limited. All rights reserved.
|
||||
*
|
||||
* $Date: 15. July 2011
|
||||
* $Revision: V1.0.10
|
||||
*
|
||||
* Project: CMSIS DSP Library
|
||||
* Title: arm_sin_q15.c
|
||||
*
|
||||
* Description: Fast sine calculation for Q15 values.
|
||||
*
|
||||
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
|
||||
*
|
||||
* Version 1.0.10 2011/7/15
|
||||
* Big Endian support added and Merged M0 and M3/M4 Source code.
|
||||
*
|
||||
* Version 1.0.3 2010/11/29
|
||||
* Re-organized the CMSIS folders and updated documentation.
|
||||
*
|
||||
* Version 1.0.2 2010/11/11
|
||||
* Documentation updated.
|
||||
*
|
||||
* Version 1.0.1 2010/10/05
|
||||
* Production release and review comments incorporated.
|
||||
*
|
||||
* Version 1.0.0 2010/09/20
|
||||
* Production release and review comments incorporated.
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#include "arm_math.h"
|
||||
|
||||
/**
|
||||
* @ingroup groupFastMath
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup sin
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \par
|
||||
* Example code for Generation of Q15 Sin Table:
|
||||
* \par
|
||||
* <pre>tableSize = 256;
|
||||
* for(n = -1; n < (tableSize + 1); n++)
|
||||
* {
|
||||
* sinTable[n+1]=sin(2*pi*n/tableSize);
|
||||
* } </pre>
|
||||
* where pi value is 3.14159265358979
|
||||
* \par
|
||||
* Convert Floating point to Q15(Fixed point):
|
||||
* (sinTable[i] * pow(2, 15))
|
||||
* \par
|
||||
* rounding to nearest integer is done
|
||||
* sinTable[i] += (sinTable[i] > 0 ? 0.5 :-0.5);
|
||||
*/
|
||||
|
||||
|
||||
static const q15_t sinTableQ15[259] = {
|
||||
0xfcdc, 0x0, 0x324, 0x648, 0x96b, 0xc8c, 0xfab, 0x12c8,
|
||||
0x15e2, 0x18f9, 0x1c0c, 0x1f1a, 0x2224, 0x2528, 0x2827, 0x2b1f,
|
||||
0x2e11, 0x30fc, 0x33df, 0x36ba, 0x398d, 0x3c57, 0x3f17, 0x41ce,
|
||||
0x447b, 0x471d, 0x49b4, 0x4c40, 0x4ec0, 0x5134, 0x539b, 0x55f6,
|
||||
0x5843, 0x5a82, 0x5cb4, 0x5ed7, 0x60ec, 0x62f2, 0x64e9, 0x66d0,
|
||||
0x68a7, 0x6a6e, 0x6c24, 0x6dca, 0x6f5f, 0x70e3, 0x7255, 0x73b6,
|
||||
0x7505, 0x7642, 0x776c, 0x7885, 0x798a, 0x7a7d, 0x7b5d, 0x7c2a,
|
||||
0x7ce4, 0x7d8a, 0x7e1e, 0x7e9d, 0x7f0a, 0x7f62, 0x7fa7, 0x7fd9,
|
||||
0x7ff6, 0x7fff, 0x7ff6, 0x7fd9, 0x7fa7, 0x7f62, 0x7f0a, 0x7e9d,
|
||||
0x7e1e, 0x7d8a, 0x7ce4, 0x7c2a, 0x7b5d, 0x7a7d, 0x798a, 0x7885,
|
||||
0x776c, 0x7642, 0x7505, 0x73b6, 0x7255, 0x70e3, 0x6f5f, 0x6dca,
|
||||
0x6c24, 0x6a6e, 0x68a7, 0x66d0, 0x64e9, 0x62f2, 0x60ec, 0x5ed7,
|
||||
0x5cb4, 0x5a82, 0x5843, 0x55f6, 0x539b, 0x5134, 0x4ec0, 0x4c40,
|
||||
0x49b4, 0x471d, 0x447b, 0x41ce, 0x3f17, 0x3c57, 0x398d, 0x36ba,
|
||||
0x33df, 0x30fc, 0x2e11, 0x2b1f, 0x2827, 0x2528, 0x2224, 0x1f1a,
|
||||
0x1c0c, 0x18f9, 0x15e2, 0x12c8, 0xfab, 0xc8c, 0x96b, 0x648,
|
||||
0x324, 0x0, 0xfcdc, 0xf9b8, 0xf695, 0xf374, 0xf055, 0xed38,
|
||||
0xea1e, 0xe707, 0xe3f4, 0xe0e6, 0xdddc, 0xdad8, 0xd7d9, 0xd4e1,
|
||||
0xd1ef, 0xcf04, 0xcc21, 0xc946, 0xc673, 0xc3a9, 0xc0e9, 0xbe32,
|
||||
0xbb85, 0xb8e3, 0xb64c, 0xb3c0, 0xb140, 0xaecc, 0xac65, 0xaa0a,
|
||||
0xa7bd, 0xa57e, 0xa34c, 0xa129, 0x9f14, 0x9d0e, 0x9b17, 0x9930,
|
||||
0x9759, 0x9592, 0x93dc, 0x9236, 0x90a1, 0x8f1d, 0x8dab, 0x8c4a,
|
||||
0x8afb, 0x89be, 0x8894, 0x877b, 0x8676, 0x8583, 0x84a3, 0x83d6,
|
||||
0x831c, 0x8276, 0x81e2, 0x8163, 0x80f6, 0x809e, 0x8059, 0x8027,
|
||||
0x800a, 0x8000, 0x800a, 0x8027, 0x8059, 0x809e, 0x80f6, 0x8163,
|
||||
0x81e2, 0x8276, 0x831c, 0x83d6, 0x84a3, 0x8583, 0x8676, 0x877b,
|
||||
0x8894, 0x89be, 0x8afb, 0x8c4a, 0x8dab, 0x8f1d, 0x90a1, 0x9236,
|
||||
0x93dc, 0x9592, 0x9759, 0x9930, 0x9b17, 0x9d0e, 0x9f14, 0xa129,
|
||||
0xa34c, 0xa57e, 0xa7bd, 0xaa0a, 0xac65, 0xaecc, 0xb140, 0xb3c0,
|
||||
0xb64c, 0xb8e3, 0xbb85, 0xbe32, 0xc0e9, 0xc3a9, 0xc673, 0xc946,
|
||||
0xcc21, 0xcf04, 0xd1ef, 0xd4e1, 0xd7d9, 0xdad8, 0xdddc, 0xe0e6,
|
||||
0xe3f4, 0xe707, 0xea1e, 0xed38, 0xf055, 0xf374, 0xf695, 0xf9b8,
|
||||
0xfcdc, 0x0, 0x324
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Fast approximation to the trigonometric sine function for Q15 data.
|
||||
* @param[in] x Scaled input value in radians.
|
||||
* @return sin(x).
|
||||
*
|
||||
* The Q15 input value is in the range [0 +1) and is mapped to a radian value in the range [0 2*pi).
|
||||
*/
|
||||
|
||||
q15_t arm_sin_q15(
|
||||
q15_t x)
|
||||
{
|
||||
q31_t sinVal; /* Temporary variables output */
|
||||
q15_t *tablePtr; /* Pointer to table */
|
||||
q15_t fract, in, in2; /* Temporary variables for input, output */
|
||||
q31_t wa, wb, wc, wd; /* Cubic interpolation coefficients */
|
||||
q15_t a, b, c, d; /* Four nearest output values */
|
||||
q15_t fractCube, fractSquare; /* Temporary values for fractional value */
|
||||
q15_t oneBy6 = 0x1555; /* Fixed point value of 1/6 */
|
||||
q15_t tableSpacing = TABLE_SPACING_Q15; /* Table spacing */
|
||||
int32_t index; /* Index variable */
|
||||
|
||||
in = x;
|
||||
|
||||
/* Calculate the nearest index */
|
||||
index = (int32_t) in / tableSpacing;
|
||||
|
||||
/* Calculate the nearest value of input */
|
||||
in2 = (q15_t) ((index) * tableSpacing);
|
||||
|
||||
/* Calculation of fractional value */
|
||||
fract = (in - in2) << 8;
|
||||
|
||||
/* fractSquare = fract * fract */
|
||||
fractSquare = (q15_t) ((fract * fract) >> 15);
|
||||
|
||||
/* fractCube = fract * fract * fract */
|
||||
fractCube = (q15_t) ((fractSquare * fract) >> 15);
|
||||
|
||||
/* Initialise table pointer */
|
||||
tablePtr = (q15_t *) & sinTableQ15[index];
|
||||
|
||||
/* Cubic interpolation process */
|
||||
/* Calculation of wa */
|
||||
/* wa = -(oneBy6)*fractCube + (fractSquare >> 1u) - (0x2AAA)*fract; */
|
||||
wa = (q31_t) oneBy6 *fractCube;
|
||||
wa += (q31_t) 0x2AAA *fract;
|
||||
wa = -(wa >> 15);
|
||||
wa += ((q31_t) fractSquare >> 1u);
|
||||
|
||||
/* Read first nearest value of output from the sin table */
|
||||
a = *tablePtr++;
|
||||
|
||||
/* sinVal = a * wa */
|
||||
sinVal = a * wa;
|
||||
|
||||
/* Calculation of wb */
|
||||
wb = (((q31_t) fractCube >> 1u) - (q31_t) fractSquare) -
|
||||
(((q31_t) fract >> 1u) - 0x7FFF);
|
||||
|
||||
/* Read second nearest value of output from the sin table */
|
||||
b = *tablePtr++;
|
||||
|
||||
/* sinVal += b*wb */
|
||||
sinVal += b * wb;
|
||||
|
||||
|
||||
/* Calculation of wc */
|
||||
wc = -(q31_t) fractCube + fractSquare;
|
||||
wc = (wc >> 1u) + fract;
|
||||
|
||||
/* Read third nearest value of output from the sin table */
|
||||
c = *tablePtr++;
|
||||
|
||||
/* sinVal += c*wc */
|
||||
sinVal += c * wc;
|
||||
|
||||
/* Calculation of wd */
|
||||
/* wd = (oneBy6)*fractCube - (oneBy6)*fract; */
|
||||
fractCube = fractCube - fract;
|
||||
wd = ((q15_t) (((q31_t) oneBy6 * fractCube) >> 15));
|
||||
|
||||
/* Read fourth nearest value of output from the sin table */
|
||||
d = *tablePtr++;
|
||||
|
||||
/* sinVal += d*wd; */
|
||||
sinVal += d * wd;
|
||||
|
||||
/* Return the output value in 1.15(q15) format */
|
||||
return ((q15_t) (sinVal >> 15u));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @} end of sin group
|
||||
*/
|
@ -0,0 +1,227 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
* Copyright (C) 2010 ARM Limited. All rights reserved.
|
||||
*
|
||||
* $Date: 15. July 2011
|
||||
* $Revision: V1.0.10
|
||||
*
|
||||
* Project: CMSIS DSP Library
|
||||
* Title: arm_sin_q31.c
|
||||
*
|
||||
* Description: Fast sine calculation for Q31 values.
|
||||
*
|
||||
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
|
||||
*
|
||||
* Version 1.0.10 2011/7/15
|
||||
* Big Endian support added and Merged M0 and M3/M4 Source code.
|
||||
*
|
||||
* Version 1.0.3 2010/11/29
|
||||
* Re-organized the CMSIS folders and updated documentation.
|
||||
*
|
||||
* Version 1.0.2 2010/11/11
|
||||
* Documentation updated.
|
||||
*
|
||||
* Version 1.0.1 2010/10/05
|
||||
* Production release and review comments incorporated.
|
||||
*
|
||||
* Version 1.0.0 2010/09/20
|
||||
* Production release and review comments incorporated.
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#include "arm_math.h"
|
||||
|
||||
/**
|
||||
* @ingroup groupFastMath
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup sin
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \par
|
||||
* Tables generated are in Q31(1.31 Fixed point format)
|
||||
* Generation of sin values in floating point:
|
||||
* <pre>tableSize = 256;
|
||||
* for(n = -1; n < (tableSize + 1); n++)
|
||||
* {
|
||||
* sinTable[n+1]= sin(2*pi*n/tableSize);
|
||||
* } </pre>
|
||||
* where pi value is 3.14159265358979
|
||||
* \par
|
||||
* Convert Floating point to Q31(Fixed point):
|
||||
* (sinTable[i] * pow(2, 31))
|
||||
* \par
|
||||
* rounding to nearest integer is done
|
||||
* sinTable[i] += (sinTable[i] > 0 ? 0.5 :-0.5);
|
||||
*/
|
||||
|
||||
static const q31_t sinTableQ31[259] = {
|
||||
0xfcdbd541, 0x0, 0x3242abf, 0x647d97c, 0x96a9049, 0xc8bd35e, 0xfab272b,
|
||||
0x12c8106f,
|
||||
0x15e21445, 0x18f8b83c, 0x1c0b826a, 0x1f19f97b, 0x2223a4c5, 0x25280c5e,
|
||||
0x2826b928, 0x2b1f34eb,
|
||||
0x2e110a62, 0x30fbc54d, 0x33def287, 0x36ba2014, 0x398cdd32, 0x3c56ba70,
|
||||
0x3f1749b8, 0x41ce1e65,
|
||||
0x447acd50, 0x471cece7, 0x49b41533, 0x4c3fdff4, 0x4ebfe8a5, 0x5133cc94,
|
||||
0x539b2af0, 0x55f5a4d2,
|
||||
0x5842dd54, 0x5a82799a, 0x5cb420e0, 0x5ed77c8a, 0x60ec3830, 0x62f201ac,
|
||||
0x64e88926, 0x66cf8120,
|
||||
0x68a69e81, 0x6a6d98a4, 0x6c242960, 0x6dca0d14, 0x6f5f02b2, 0x70e2cbc6,
|
||||
0x72552c85, 0x73b5ebd1,
|
||||
0x7504d345, 0x7641af3d, 0x776c4edb, 0x78848414, 0x798a23b1, 0x7a7d055b,
|
||||
0x7b5d039e, 0x7c29fbee,
|
||||
0x7ce3ceb2, 0x7d8a5f40, 0x7e1d93ea, 0x7e9d55fc, 0x7f0991c4, 0x7f62368f,
|
||||
0x7fa736b4, 0x7fd8878e,
|
||||
0x7ff62182, 0x7fffffff, 0x7ff62182, 0x7fd8878e, 0x7fa736b4, 0x7f62368f,
|
||||
0x7f0991c4, 0x7e9d55fc,
|
||||
0x7e1d93ea, 0x7d8a5f40, 0x7ce3ceb2, 0x7c29fbee, 0x7b5d039e, 0x7a7d055b,
|
||||
0x798a23b1, 0x78848414,
|
||||
0x776c4edb, 0x7641af3d, 0x7504d345, 0x73b5ebd1, 0x72552c85, 0x70e2cbc6,
|
||||
0x6f5f02b2, 0x6dca0d14,
|
||||
0x6c242960, 0x6a6d98a4, 0x68a69e81, 0x66cf8120, 0x64e88926, 0x62f201ac,
|
||||
0x60ec3830, 0x5ed77c8a,
|
||||
0x5cb420e0, 0x5a82799a, 0x5842dd54, 0x55f5a4d2, 0x539b2af0, 0x5133cc94,
|
||||
0x4ebfe8a5, 0x4c3fdff4,
|
||||
0x49b41533, 0x471cece7, 0x447acd50, 0x41ce1e65, 0x3f1749b8, 0x3c56ba70,
|
||||
0x398cdd32, 0x36ba2014,
|
||||
0x33def287, 0x30fbc54d, 0x2e110a62, 0x2b1f34eb, 0x2826b928, 0x25280c5e,
|
||||
0x2223a4c5, 0x1f19f97b,
|
||||
0x1c0b826a, 0x18f8b83c, 0x15e21445, 0x12c8106f, 0xfab272b, 0xc8bd35e,
|
||||
0x96a9049, 0x647d97c,
|
||||
0x3242abf, 0x0, 0xfcdbd541, 0xf9b82684, 0xf6956fb7, 0xf3742ca2, 0xf054d8d5,
|
||||
0xed37ef91,
|
||||
0xea1debbb, 0xe70747c4, 0xe3f47d96, 0xe0e60685, 0xdddc5b3b, 0xdad7f3a2,
|
||||
0xd7d946d8, 0xd4e0cb15,
|
||||
0xd1eef59e, 0xcf043ab3, 0xcc210d79, 0xc945dfec, 0xc67322ce, 0xc3a94590,
|
||||
0xc0e8b648, 0xbe31e19b,
|
||||
0xbb8532b0, 0xb8e31319, 0xb64beacd, 0xb3c0200c, 0xb140175b, 0xaecc336c,
|
||||
0xac64d510, 0xaa0a5b2e,
|
||||
0xa7bd22ac, 0xa57d8666, 0xa34bdf20, 0xa1288376, 0x9f13c7d0, 0x9d0dfe54,
|
||||
0x9b1776da, 0x99307ee0,
|
||||
0x9759617f, 0x9592675c, 0x93dbd6a0, 0x9235f2ec, 0x90a0fd4e, 0x8f1d343a,
|
||||
0x8daad37b, 0x8c4a142f,
|
||||
0x8afb2cbb, 0x89be50c3, 0x8893b125, 0x877b7bec, 0x8675dc4f, 0x8582faa5,
|
||||
0x84a2fc62, 0x83d60412,
|
||||
0x831c314e, 0x8275a0c0, 0x81e26c16, 0x8162aa04, 0x80f66e3c, 0x809dc971,
|
||||
0x8058c94c, 0x80277872,
|
||||
0x8009de7e, 0x80000000, 0x8009de7e, 0x80277872, 0x8058c94c, 0x809dc971,
|
||||
0x80f66e3c, 0x8162aa04,
|
||||
0x81e26c16, 0x8275a0c0, 0x831c314e, 0x83d60412, 0x84a2fc62, 0x8582faa5,
|
||||
0x8675dc4f, 0x877b7bec,
|
||||
0x8893b125, 0x89be50c3, 0x8afb2cbb, 0x8c4a142f, 0x8daad37b, 0x8f1d343a,
|
||||
0x90a0fd4e, 0x9235f2ec,
|
||||
0x93dbd6a0, 0x9592675c, 0x9759617f, 0x99307ee0, 0x9b1776da, 0x9d0dfe54,
|
||||
0x9f13c7d0, 0xa1288376,
|
||||
0xa34bdf20, 0xa57d8666, 0xa7bd22ac, 0xaa0a5b2e, 0xac64d510, 0xaecc336c,
|
||||
0xb140175b, 0xb3c0200c,
|
||||
0xb64beacd, 0xb8e31319, 0xbb8532b0, 0xbe31e19b, 0xc0e8b648, 0xc3a94590,
|
||||
0xc67322ce, 0xc945dfec,
|
||||
0xcc210d79, 0xcf043ab3, 0xd1eef59e, 0xd4e0cb15, 0xd7d946d8, 0xdad7f3a2,
|
||||
0xdddc5b3b, 0xe0e60685,
|
||||
0xe3f47d96, 0xe70747c4, 0xea1debbb, 0xed37ef91, 0xf054d8d5, 0xf3742ca2,
|
||||
0xf6956fb7, 0xf9b82684,
|
||||
0xfcdbd541, 0x0, 0x3242abf
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Fast approximation to the trigonometric sine function for Q31 data.
|
||||
* @param[in] x Scaled input value in radians.
|
||||
* @return sin(x).
|
||||
*
|
||||
* The Q31 input value is in the range [0 +1) and is mapped to a radian value in the range [0 2*pi).
|
||||
*/
|
||||
|
||||
q31_t arm_sin_q31(
|
||||
q31_t x)
|
||||
{
|
||||
q31_t sinVal, in, in2; /* Temporary variables for input, output */
|
||||
uint32_t index; /* Index variables */
|
||||
q31_t wa, wb, wc, wd; /* Cubic interpolation coefficients */
|
||||
q31_t a, b, c, d; /* Four nearest output values */
|
||||
q31_t *tablePtr; /* Pointer to table */
|
||||
q31_t fract, fractCube, fractSquare; /* Temporary values for fractional values */
|
||||
q31_t oneBy6 = 0x15555555; /* Fixed point value of 1/6 */
|
||||
q31_t tableSpacing = TABLE_SPACING_Q31; /* Table spacing */
|
||||
q31_t temp; /* Temporary variable for intermediate process */
|
||||
|
||||
in = x;
|
||||
|
||||
/* Calculate the nearest index */
|
||||
index = (uint32_t) in / (uint32_t) tableSpacing;
|
||||
|
||||
/* Calculate the nearest value of input */
|
||||
in2 = (q31_t) index *tableSpacing;
|
||||
|
||||
/* Calculation of fractional value */
|
||||
fract = (in - in2) << 8;
|
||||
|
||||
/* fractSquare = fract * fract */
|
||||
fractSquare = ((q31_t) (((q63_t) fract * fract) >> 32));
|
||||
fractSquare = fractSquare << 1;
|
||||
|
||||
/* fractCube = fract * fract * fract */
|
||||
fractCube = ((q31_t) (((q63_t) fractSquare * fract) >> 32));
|
||||
fractCube = fractCube << 1;
|
||||
|
||||
/* Initialise table pointer */
|
||||
tablePtr = (q31_t *) & sinTableQ31[index];
|
||||
|
||||
/* Cubic interpolation process */
|
||||
/* Calculation of wa */
|
||||
/* wa = -(oneBy6)*fractCube + (fractSquare >> 1u) - (0x2AAAAAAA)*fract; */
|
||||
wa = ((q31_t) (((q63_t) oneBy6 * fractCube) >> 32));
|
||||
temp = 0x2AAAAAAA;
|
||||
wa = (q31_t) ((((q63_t) wa << 32) + ((q63_t) temp * fract)) >> 32);
|
||||
wa = -(wa << 1u);
|
||||
wa += (fractSquare >> 1u);
|
||||
|
||||
/* Read first nearest value of output from the sin table */
|
||||
a = *tablePtr++;
|
||||
|
||||
/* sinVal = a*wa */
|
||||
sinVal = ((q31_t) (((q63_t) a * wa) >> 32));
|
||||
|
||||
/* q31(1.31) Fixed point value of 1 */
|
||||
temp = 0x7FFFFFFF;
|
||||
|
||||
/* Calculation of wb */
|
||||
wb = ((fractCube >> 1u) - (fractSquare + (fract >> 1u))) + temp;
|
||||
|
||||
/* Read second nearest value of output from the sin table */
|
||||
b = *tablePtr++;
|
||||
|
||||
/* sinVal += b*wb */
|
||||
sinVal = (q31_t) ((((q63_t) sinVal << 32) + (q63_t) b * (wb)) >> 32);
|
||||
|
||||
/* Calculation of wc */
|
||||
wc = -fractCube + fractSquare;
|
||||
wc = (wc >> 1u) + fract;
|
||||
|
||||
/* Read third nearest value of output from the sin table */
|
||||
c = *tablePtr++;
|
||||
|
||||
/* sinVal += c*wc */
|
||||
sinVal = (q31_t) ((((q63_t) sinVal << 32) + ((q63_t) c * wc)) >> 32);
|
||||
|
||||
/* Calculation of wd */
|
||||
/* wd = (oneBy6) * fractCube - (oneBy6) * fract; */
|
||||
fractCube = fractCube - fract;
|
||||
wd = ((q31_t) (((q63_t) oneBy6 * fractCube) >> 32));
|
||||
wd = (wd << 1u);
|
||||
|
||||
/* Read fourth nearest value of output from the sin table */
|
||||
d = *tablePtr++;
|
||||
|
||||
/* sinVal += d*wd; */
|
||||
sinVal = (q31_t) ((((q63_t) sinVal << 32) + ((q63_t) d * wd)) >> 32);
|
||||
|
||||
/* convert sinVal in 2.30 format to 1.31 format */
|
||||
return (sinVal << 1u);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @} end of sin group
|
||||
*/
|
@ -0,0 +1,178 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
* Copyright (C) 2010 ARM Limited. All rights reserved.
|
||||
*
|
||||
* $Date: 15. July 2011
|
||||
* $Revision: V1.0.10
|
||||
*
|
||||
* Project: CMSIS DSP Library
|
||||
* Title: arm_sqrt_q15.c
|
||||
*
|
||||
* Description: Q15 square root function.
|
||||
*
|
||||
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
|
||||
*
|
||||
* Version 1.0.10 2011/7/15
|
||||
* Big Endian support added and Merged M0 and M3/M4 Source code.
|
||||
*
|
||||
* Version 1.0.3 2010/11/29
|
||||
* Re-organized the CMSIS folders and updated documentation.
|
||||
*
|
||||
* Version 1.0.2 2010/11/11
|
||||
* Documentation updated.
|
||||
*
|
||||
* Version 1.0.1 2010/10/05
|
||||
* Production release and review comments incorporated.
|
||||
*
|
||||
* Version 1.0.0 2010/09/20
|
||||
* Production release and review comments incorporated.
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#include "arm_math.h"
|
||||
#include "arm_common_tables.h"
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup groupFastMath
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup SQRT
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Q15 square root function.
|
||||
* @param[in] in input value. The range of the input value is [0 +1) or 0x0000 to 0x7FFF.
|
||||
* @param[out] *pOut square root of input value.
|
||||
* @return The function returns ARM_MATH_SUCCESS if input value is positive value or ARM_MATH_ARGUMENT_ERROR if
|
||||
* <code>in</code> is negative value and returns zero output for negative values.
|
||||
*/
|
||||
|
||||
arm_status arm_sqrt_q15(
|
||||
q15_t in,
|
||||
q15_t * pOut)
|
||||
{
|
||||
q31_t prevOut;
|
||||
q15_t oneByOut;
|
||||
uint32_t sign_bits;
|
||||
|
||||
#ifndef ARM_MATH_CM0
|
||||
|
||||
/* Run the below code for Cortex-M4 and Cortex-M3 */
|
||||
|
||||
q31_t out;
|
||||
|
||||
if(in > 0)
|
||||
{
|
||||
/* run for ten iterations */
|
||||
|
||||
/* Take initial guess as half of the input and first iteration */
|
||||
out = ((q31_t) in >> 1u) + 0x3FFF;
|
||||
|
||||
/* Calculation of reciprocal of out */
|
||||
/* oneByOut contains reciprocal of out which is in 2.14 format
|
||||
and oneByOut should be upscaled by signBits */
|
||||
sign_bits = arm_recip_q15((q15_t) out, &oneByOut, armRecipTableQ15);
|
||||
|
||||
/* 0.5 * (out) */
|
||||
out = out >> 1u;
|
||||
/* prevOut = 0.5 * out + (in * (oneByOut << signBits))) */
|
||||
prevOut = out + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits);
|
||||
|
||||
/* Third iteration */
|
||||
sign_bits = arm_recip_q15((q15_t) prevOut, &oneByOut, armRecipTableQ15);
|
||||
prevOut = prevOut >> 1u;
|
||||
out = prevOut + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits);
|
||||
|
||||
sign_bits = arm_recip_q15((q15_t) out, &oneByOut, armRecipTableQ15);
|
||||
out = out >> 1u;
|
||||
prevOut = out + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits);
|
||||
|
||||
/* Fifth iteration */
|
||||
sign_bits = arm_recip_q15((q15_t) prevOut, &oneByOut, armRecipTableQ15);
|
||||
prevOut = prevOut >> 1u;
|
||||
out = prevOut + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits);
|
||||
|
||||
sign_bits = arm_recip_q15((q15_t) out, &oneByOut, armRecipTableQ15);
|
||||
out = out >> 1u;
|
||||
prevOut = out + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits);
|
||||
|
||||
/* Seventh iteration */
|
||||
sign_bits = arm_recip_q15((q15_t) prevOut, &oneByOut, armRecipTableQ15);
|
||||
prevOut = prevOut >> 1u;
|
||||
out = prevOut + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits);
|
||||
|
||||
sign_bits = arm_recip_q15((q15_t) out, &oneByOut, armRecipTableQ15);
|
||||
out = out >> 1u;
|
||||
prevOut = out + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits);
|
||||
|
||||
sign_bits = arm_recip_q15((q15_t) prevOut, &oneByOut, armRecipTableQ15);
|
||||
prevOut = prevOut >> 1u;
|
||||
out = prevOut + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits);
|
||||
|
||||
/* tenth iteration */
|
||||
sign_bits = arm_recip_q15((q15_t) out, &oneByOut, armRecipTableQ15);
|
||||
out = out >> 1u;
|
||||
*pOut = out + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits);
|
||||
|
||||
return (ARM_MATH_SUCCESS);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* Run the below code for Cortex-M0 */
|
||||
|
||||
q31_t out, loopVar; /* Temporary variable for output, loop variable */
|
||||
if(in > 0)
|
||||
{
|
||||
/* run for ten iterations */
|
||||
|
||||
/* Take initial guess as half of the input and first iteration */
|
||||
out = ((q31_t) in >> 1u) + 0x3FFF;
|
||||
|
||||
/* Calculation of reciprocal of out */
|
||||
|
||||
/* oneByOut contains reciprocal of out which is in 2.14 format
|
||||
and oneByOut should be upscaled by sign bits */
|
||||
sign_bits = arm_recip_q15((q15_t) out, &oneByOut, armRecipTableQ15);
|
||||
|
||||
/* 0.5 * (out) */
|
||||
out = out >> 1u;
|
||||
/* prevOut = 0.5 * out + (in * oneByOut) << signbits))) */
|
||||
prevOut = out + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits);
|
||||
|
||||
/* loop for third iteration to tenth iteration */
|
||||
|
||||
for (loopVar = 1; loopVar <= 8; loopVar++)
|
||||
{
|
||||
|
||||
sign_bits = arm_recip_q15((q15_t) prevOut, &oneByOut, armRecipTableQ15);
|
||||
/* 0.5 * (prevOut) */
|
||||
prevOut = prevOut >> 1u;
|
||||
/* prevOut = 0.5 * prevOut+ (in * oneByOut) << signbits))) */
|
||||
out =
|
||||
prevOut + (((q15_t) (((q31_t) in * oneByOut) >> 16)) << sign_bits);
|
||||
/* prevOut = out */
|
||||
prevOut = out;
|
||||
|
||||
}
|
||||
/* output is moved to pOut pointer */
|
||||
*pOut = prevOut;
|
||||
|
||||
return (ARM_MATH_SUCCESS);
|
||||
}
|
||||
|
||||
#endif /* #ifndef ARM_MATH_CM0 */
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
*pOut = 0;
|
||||
return (ARM_MATH_ARGUMENT_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @} end of SQRT group
|
||||
*/
|
@ -0,0 +1,199 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
* Copyright (C) 2010 ARM Limited. All rights reserved.
|
||||
*
|
||||
* $Date: 15. July 2011
|
||||
* $Revision: V1.0.10
|
||||
*
|
||||
* Project: CMSIS DSP Library
|
||||
* Title: arm_sqrt_q31.c
|
||||
*
|
||||
* Description: Q31 square root function.
|
||||
*
|
||||
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
|
||||
*
|
||||
* Version 1.0.10 2011/7/15
|
||||
* Big Endian support added and Merged M0 and M3/M4 Source code.
|
||||
*
|
||||
* Version 1.0.2 2010/11/11
|
||||
* Documentation updated.
|
||||
*
|
||||
* Version 1.0.1 2010/10/05
|
||||
* Production release and review comments incorporated.
|
||||
*
|
||||
* Version 1.0.0 2010/09/20
|
||||
* Production release and review comments incorporated.
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#include "arm_math.h"
|
||||
#include "arm_common_tables.h"
|
||||
|
||||
/**
|
||||
* @ingroup groupFastMath
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup SQRT
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Q31 square root function.
|
||||
* @param[in] in input value. The range of the input value is [0 +1) or 0x00000000 to 0x7FFFFFFF.
|
||||
* @param[out] *pOut square root of input value.
|
||||
* @return The function returns ARM_MATH_SUCCESS if input value is positive value or ARM_MATH_ARGUMENT_ERROR if
|
||||
* <code>in</code> is negative value and returns zero output for negative values.
|
||||
*/
|
||||
|
||||
arm_status arm_sqrt_q31(
|
||||
q31_t in,
|
||||
q31_t * pOut)
|
||||
{
|
||||
q63_t prevOut;
|
||||
q31_t oneByOut;
|
||||
uint32_t signBits;
|
||||
|
||||
#ifndef ARM_MATH_CM0
|
||||
|
||||
/* Run the below code for Cortex-M4 and Cortex-M3 */
|
||||
|
||||
q63_t out;
|
||||
|
||||
if(in > 0)
|
||||
{
|
||||
|
||||
/* run for ten iterations */
|
||||
|
||||
/* Take initial guess as half of the input and first iteration */
|
||||
out = (in >> 1) + 0x3FFFFFFF;
|
||||
|
||||
/* Calculation of reciprocal of out */
|
||||
/* oneByOut contains reciprocal of out which is in 2.30 format
|
||||
and oneByOut should be upscaled by signBits */
|
||||
signBits = arm_recip_q31((q31_t) out, &oneByOut, armRecipTableQ31);
|
||||
|
||||
/* 0.5 * (out) */
|
||||
out = out >> 1u;
|
||||
|
||||
/* prevOut = 0.5 * out + (in * (oneByOut << signBits))) */
|
||||
prevOut = out + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
/* Third iteration */
|
||||
signBits = arm_recip_q31((q31_t) prevOut, &oneByOut, armRecipTableQ31);
|
||||
prevOut = prevOut >> 1u;
|
||||
out = prevOut + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
signBits = arm_recip_q31((q31_t) out, &oneByOut, armRecipTableQ31);
|
||||
out = out >> 1u;
|
||||
prevOut = out + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
/* Fifth iteration */
|
||||
signBits = arm_recip_q31((q31_t) prevOut, &oneByOut, armRecipTableQ31);
|
||||
prevOut = prevOut >> 1u;
|
||||
out = prevOut + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
signBits = arm_recip_q31((q31_t) out, &oneByOut, armRecipTableQ31);
|
||||
out = out >> 1u;
|
||||
prevOut = out + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
/* Seventh iteration */
|
||||
signBits = arm_recip_q31((q31_t) prevOut, &oneByOut, armRecipTableQ31);
|
||||
prevOut = prevOut >> 1u;
|
||||
out = prevOut + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
signBits = arm_recip_q31((q31_t) out, &oneByOut, armRecipTableQ31);
|
||||
out = out >> 1u;
|
||||
prevOut = out + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
signBits = arm_recip_q31((q31_t) prevOut, &oneByOut, armRecipTableQ31);
|
||||
prevOut = prevOut >> 1u;
|
||||
out = prevOut + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
signBits = arm_recip_q31((q31_t) out, &oneByOut, armRecipTableQ31);
|
||||
out = out >> 1u;
|
||||
prevOut = out + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
signBits = arm_recip_q31((q31_t) prevOut, &oneByOut, armRecipTableQ31);
|
||||
prevOut = prevOut >> 1u;
|
||||
out = prevOut + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
signBits = arm_recip_q31((q31_t) out, &oneByOut, armRecipTableQ31);
|
||||
out = out >> 1u;
|
||||
prevOut = out + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
signBits = arm_recip_q31((q31_t) prevOut, &oneByOut, armRecipTableQ31);
|
||||
prevOut = prevOut >> 1u;
|
||||
out = prevOut + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
signBits = arm_recip_q31((q31_t) out, &oneByOut, armRecipTableQ31);
|
||||
out = out >> 1u;
|
||||
prevOut = out + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
signBits = arm_recip_q31((q31_t) prevOut, &oneByOut, armRecipTableQ31);
|
||||
prevOut = prevOut >> 1u;
|
||||
out = prevOut + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
/* tenth iteration */
|
||||
signBits = arm_recip_q31((q31_t) out, &oneByOut, armRecipTableQ31);
|
||||
out = out >> 1u;
|
||||
*pOut = out + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
return (ARM_MATH_SUCCESS);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* Run the below code for Cortex-M0 */
|
||||
|
||||
q63_t out, loopVar; /* Temporary variable for output, loop variable */
|
||||
if(in > 0)
|
||||
{
|
||||
|
||||
/* run for ten iterations */
|
||||
|
||||
/* Take initial guess as half of the input and first iteration */
|
||||
out = (in >> 1) + 0x3FFFFFFF;
|
||||
|
||||
/* Calculation of reciprocal of out */
|
||||
/* oneByOut contains reciprocal of out which is in 2.30 format
|
||||
and oneByOut should be upscaled by sign bits */
|
||||
signBits = arm_recip_q31((q31_t) out, &oneByOut, armRecipTableQ31);
|
||||
|
||||
/* 0.5 * (out) */
|
||||
out = out >> 1u;
|
||||
|
||||
/* prevOut = 0.5 * out + (in * (oneByOut) << signbits) */
|
||||
prevOut = out + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
|
||||
|
||||
/* loop for third iteration to tength iteration */
|
||||
|
||||
for (loopVar = 1; loopVar <= 14; loopVar++)
|
||||
{
|
||||
|
||||
signBits = arm_recip_q31((q31_t) prevOut, &oneByOut, armRecipTableQ31);
|
||||
/* 0.5 * (prevOut) */
|
||||
prevOut = prevOut >> 1u;
|
||||
/* out = 0.5 * prevOut + (in * oneByOut) << signbits))) */
|
||||
out = prevOut + (((q31_t) (((q63_t) in * oneByOut) >> 32)) << signBits);
|
||||
/* prevOut = out */
|
||||
prevOut = out;
|
||||
|
||||
}
|
||||
/* output is moved to pOut pointer */
|
||||
*pOut = prevOut;
|
||||
|
||||
return (ARM_MATH_SUCCESS);
|
||||
}
|
||||
|
||||
#endif /* #ifndef ARM_MATH_CM0 */
|
||||
|
||||
else
|
||||
{
|
||||
*pOut = 0;
|
||||
return (ARM_MATH_ARGUMENT_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @} end of SQRT group
|
||||
*/
|
Reference in New Issue
Block a user