Fork of mbed-dsp. CMSIS-DSP library of supporting NEON
Dependents: mbed-os-example-cmsis_dsp_neon
Fork of mbed-dsp by
Information
Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.
CMSIS-DSP of supporting NEON
What is this ?
A library for CMSIS-DSP of supporting NEON.
We supported the NEON to CMSIS-DSP Ver1.4.3(CMSIS V4.1) that ARM supplied, has achieved the processing speed improvement.
If you use the mbed-dsp library, you can use to replace this library.
CMSIS-DSP of supporting NEON is provied as a library.
Library Creation environment
CMSIS-DSP library of supporting NEON was created by the following environment.
- Compiler
ARMCC Version 5.03 - Compile option switch[C Compiler]
-DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -O3 -Otime --cpu=Cortex-A9 --littleend --arm --apcs=/interwork --no_unaligned_access --fpu=vfpv3_fp16 --fpmode=fast --apcs=/hardfp --vectorize --asm
- Compile option switch[Assembler]
--cpreproc --cpu=Cortex-A9 --littleend --arm --apcs=/interwork --no_unaligned_access --fpu=vfpv3_fp16 --fpmode=fast --apcs=/hardfp
Effects of NEON support
In the data which passes to each function, large size will be expected more effective than small size.
Also if the data is a multiple of 16, effect will be expected in every function in the CMSIS-DSP.
NEON対応CMSIS-DSP
概要
NEON対応したCMSIS-DSPのライブラリです。
ARM社提供のCMSIS-DSP Ver1.4.3(CMSIS V4.1)をターゲットにNEON対応を行ない、処理速度向上を実現しております。
mbed-dspライブラリを使用している場合は、本ライブラリに置き換えて使用することができます。
NEON対応したCMSIS-DSPはライブラリで提供します。
ライブラリ作成環境
NEON対応CMSIS-DSPライブラリは、以下の環境で作成しています。
- コンパイラ
ARMCC Version 5.03 - コンパイルオプションスイッチ[C Compiler]
-DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -O3 -Otime --cpu=Cortex-A9 --littleend --arm --apcs=/interwork --no_unaligned_access --fpu=vfpv3_fp16 --fpmode=fast --apcs=/hardfp --vectorize --asm
- コンパイルオプションスイッチ[Assembler]
--cpreproc --cpu=Cortex-A9 --littleend --arm --apcs=/interwork --no_unaligned_access --fpu=vfpv3_fp16 --fpmode=fast --apcs=/hardfp
NEON対応による効果について
CMSIS-DSP内の各関数へ渡すデータは、小さいサイズよりも大きいサイズの方が効果が見込めます。
また、16の倍数のデータであれば、CMSIS-DSP内のどの関数でも効果が見込めます。
cmsis_dsp/FastMathFunctions/arm_sin_f32.c@1:fdd22bb7aa52, 2012-11-28 (annotated)
- Committer:
- emilmont
- Date:
- Wed Nov 28 12:30:09 2012 +0000
- Revision:
- 1:fdd22bb7aa52
- Child:
- 2:da51fb522205
DSP library code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:fdd22bb7aa52 | 1 | /* ---------------------------------------------------------------------- |
emilmont | 1:fdd22bb7aa52 | 2 | * Copyright (C) 2010 ARM Limited. All rights reserved. |
emilmont | 1:fdd22bb7aa52 | 3 | * |
emilmont | 1:fdd22bb7aa52 | 4 | * $Date: 15. February 2012 |
emilmont | 1:fdd22bb7aa52 | 5 | * $Revision: V1.1.0 |
emilmont | 1:fdd22bb7aa52 | 6 | * |
emilmont | 1:fdd22bb7aa52 | 7 | * Project: CMSIS DSP Library |
emilmont | 1:fdd22bb7aa52 | 8 | * Title: arm_sin_f32.c |
emilmont | 1:fdd22bb7aa52 | 9 | * |
emilmont | 1:fdd22bb7aa52 | 10 | * Description: Fast sine calculation for floating-point values. |
emilmont | 1:fdd22bb7aa52 | 11 | * |
emilmont | 1:fdd22bb7aa52 | 12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 |
emilmont | 1:fdd22bb7aa52 | 13 | * |
emilmont | 1:fdd22bb7aa52 | 14 | * Version 1.1.0 2012/02/15 |
emilmont | 1:fdd22bb7aa52 | 15 | * Updated with more optimizations, bug fixes and minor API changes. |
emilmont | 1:fdd22bb7aa52 | 16 | * |
emilmont | 1:fdd22bb7aa52 | 17 | * Version 1.0.10 2011/7/15 |
emilmont | 1:fdd22bb7aa52 | 18 | * Big Endian support added and Merged M0 and M3/M4 Source code. |
emilmont | 1:fdd22bb7aa52 | 19 | * |
emilmont | 1:fdd22bb7aa52 | 20 | * Version 1.0.3 2010/11/29 |
emilmont | 1:fdd22bb7aa52 | 21 | * Re-organized the CMSIS folders and updated documentation. |
emilmont | 1:fdd22bb7aa52 | 22 | * |
emilmont | 1:fdd22bb7aa52 | 23 | * Version 1.0.2 2010/11/11 |
emilmont | 1:fdd22bb7aa52 | 24 | * Documentation updated. |
emilmont | 1:fdd22bb7aa52 | 25 | * |
emilmont | 1:fdd22bb7aa52 | 26 | * Version 1.0.1 2010/10/05 |
emilmont | 1:fdd22bb7aa52 | 27 | * Production release and review comments incorporated. |
emilmont | 1:fdd22bb7aa52 | 28 | * |
emilmont | 1:fdd22bb7aa52 | 29 | * Version 1.0.0 2010/09/20 |
emilmont | 1:fdd22bb7aa52 | 30 | * Production release and review comments incorporated. |
emilmont | 1:fdd22bb7aa52 | 31 | * -------------------------------------------------------------------- */ |
emilmont | 1:fdd22bb7aa52 | 32 | |
emilmont | 1:fdd22bb7aa52 | 33 | #include "arm_math.h" |
emilmont | 1:fdd22bb7aa52 | 34 | |
emilmont | 1:fdd22bb7aa52 | 35 | /** |
emilmont | 1:fdd22bb7aa52 | 36 | * @ingroup groupFastMath |
emilmont | 1:fdd22bb7aa52 | 37 | */ |
emilmont | 1:fdd22bb7aa52 | 38 | |
emilmont | 1:fdd22bb7aa52 | 39 | /** |
emilmont | 1:fdd22bb7aa52 | 40 | * @defgroup sin Sine |
emilmont | 1:fdd22bb7aa52 | 41 | * |
emilmont | 1:fdd22bb7aa52 | 42 | * Computes the trigonometric sine function using a combination of table lookup |
emilmont | 1:fdd22bb7aa52 | 43 | * and cubic interpolation. There are separate functions for |
emilmont | 1:fdd22bb7aa52 | 44 | * Q15, Q31, and floating-point data types. |
emilmont | 1:fdd22bb7aa52 | 45 | * The input to the floating-point version is in radians while the |
emilmont | 1:fdd22bb7aa52 | 46 | * fixed-point Q15 and Q31 have a scaled input with the range |
emilmont | 1:fdd22bb7aa52 | 47 | * [0 +0.9999] mapping to [0 2*pi), Where range excludes 2*pi. |
emilmont | 1:fdd22bb7aa52 | 48 | * |
emilmont | 1:fdd22bb7aa52 | 49 | * The implementation is based on table lookup using 256 values together with cubic interpolation. |
emilmont | 1:fdd22bb7aa52 | 50 | * The steps used are: |
emilmont | 1:fdd22bb7aa52 | 51 | * -# Calculation of the nearest integer table index |
emilmont | 1:fdd22bb7aa52 | 52 | * -# Fetch the four table values a, b, c, and d |
emilmont | 1:fdd22bb7aa52 | 53 | * -# Compute the fractional portion (fract) of the table index. |
emilmont | 1:fdd22bb7aa52 | 54 | * -# Calculation of wa, wb, wc, wd |
emilmont | 1:fdd22bb7aa52 | 55 | * -# The final result equals <code>a*wa + b*wb + c*wc + d*wd</code> |
emilmont | 1:fdd22bb7aa52 | 56 | * |
emilmont | 1:fdd22bb7aa52 | 57 | * where |
emilmont | 1:fdd22bb7aa52 | 58 | * <pre> |
emilmont | 1:fdd22bb7aa52 | 59 | * a=Table[index-1]; |
emilmont | 1:fdd22bb7aa52 | 60 | * b=Table[index+0]; |
emilmont | 1:fdd22bb7aa52 | 61 | * c=Table[index+1]; |
emilmont | 1:fdd22bb7aa52 | 62 | * d=Table[index+2]; |
emilmont | 1:fdd22bb7aa52 | 63 | * </pre> |
emilmont | 1:fdd22bb7aa52 | 64 | * and |
emilmont | 1:fdd22bb7aa52 | 65 | * <pre> |
emilmont | 1:fdd22bb7aa52 | 66 | * wa=-(1/6)*fract.^3 + (1/2)*fract.^2 - (1/3)*fract; |
emilmont | 1:fdd22bb7aa52 | 67 | * wb=(1/2)*fract.^3 - fract.^2 - (1/2)*fract + 1; |
emilmont | 1:fdd22bb7aa52 | 68 | * wc=-(1/2)*fract.^3+(1/2)*fract.^2+fract; |
emilmont | 1:fdd22bb7aa52 | 69 | * wd=(1/6)*fract.^3 - (1/6)*fract; |
emilmont | 1:fdd22bb7aa52 | 70 | * </pre> |
emilmont | 1:fdd22bb7aa52 | 71 | */ |
emilmont | 1:fdd22bb7aa52 | 72 | |
emilmont | 1:fdd22bb7aa52 | 73 | /** |
emilmont | 1:fdd22bb7aa52 | 74 | * @addtogroup sin |
emilmont | 1:fdd22bb7aa52 | 75 | * @{ |
emilmont | 1:fdd22bb7aa52 | 76 | */ |
emilmont | 1:fdd22bb7aa52 | 77 | |
emilmont | 1:fdd22bb7aa52 | 78 | |
emilmont | 1:fdd22bb7aa52 | 79 | /** |
emilmont | 1:fdd22bb7aa52 | 80 | * \par |
emilmont | 1:fdd22bb7aa52 | 81 | * Example code for Generation of Floating-point Sin Table: |
emilmont | 1:fdd22bb7aa52 | 82 | * tableSize = 256; |
emilmont | 1:fdd22bb7aa52 | 83 | * <pre>for(n = -1; n < (tableSize + 1); n++) |
emilmont | 1:fdd22bb7aa52 | 84 | * { |
emilmont | 1:fdd22bb7aa52 | 85 | * sinTable[n+1]=sin(2*pi*n/tableSize); |
emilmont | 1:fdd22bb7aa52 | 86 | * }</pre> |
emilmont | 1:fdd22bb7aa52 | 87 | * \par |
emilmont | 1:fdd22bb7aa52 | 88 | * where pi value is 3.14159265358979 |
emilmont | 1:fdd22bb7aa52 | 89 | */ |
emilmont | 1:fdd22bb7aa52 | 90 | |
emilmont | 1:fdd22bb7aa52 | 91 | static const float32_t sinTable[259] = { |
emilmont | 1:fdd22bb7aa52 | 92 | -0.024541229009628296f, 0.000000000000000000f, 0.024541229009628296f, |
emilmont | 1:fdd22bb7aa52 | 93 | 0.049067676067352295f, 0.073564566671848297f, 0.098017141222953796f, |
emilmont | 1:fdd22bb7aa52 | 94 | 0.122410677373409270f, 0.146730467677116390f, |
emilmont | 1:fdd22bb7aa52 | 95 | 0.170961886644363400f, 0.195090323686599730f, 0.219101235270500180f, |
emilmont | 1:fdd22bb7aa52 | 96 | 0.242980182170867920f, 0.266712754964828490f, 0.290284663438797000f, |
emilmont | 1:fdd22bb7aa52 | 97 | 0.313681751489639280f, 0.336889863014221190f, |
emilmont | 1:fdd22bb7aa52 | 98 | 0.359895050525665280f, 0.382683426141738890f, 0.405241310596466060f, |
emilmont | 1:fdd22bb7aa52 | 99 | 0.427555084228515630f, 0.449611335992813110f, 0.471396744251251220f, |
emilmont | 1:fdd22bb7aa52 | 100 | 0.492898195981979370f, 0.514102756977081300f, |
emilmont | 1:fdd22bb7aa52 | 101 | 0.534997642040252690f, 0.555570244789123540f, 0.575808167457580570f, |
emilmont | 1:fdd22bb7aa52 | 102 | 0.595699310302734380f, 0.615231573581695560f, 0.634393274784088130f, |
emilmont | 1:fdd22bb7aa52 | 103 | 0.653172850608825680f, 0.671558976173400880f, |
emilmont | 1:fdd22bb7aa52 | 104 | 0.689540565013885500f, 0.707106769084930420f, 0.724247097969055180f, |
emilmont | 1:fdd22bb7aa52 | 105 | 0.740951120853424070f, 0.757208824157714840f, 0.773010432720184330f, |
emilmont | 1:fdd22bb7aa52 | 106 | 0.788346409797668460f, 0.803207516670227050f, |
emilmont | 1:fdd22bb7aa52 | 107 | 0.817584812641143800f, 0.831469595432281490f, 0.844853579998016360f, |
emilmont | 1:fdd22bb7aa52 | 108 | 0.857728600502014160f, 0.870086967945098880f, 0.881921291351318360f, |
emilmont | 1:fdd22bb7aa52 | 109 | 0.893224298954010010f, 0.903989315032958980f, |
emilmont | 1:fdd22bb7aa52 | 110 | 0.914209783077239990f, 0.923879504203796390f, 0.932992815971374510f, |
emilmont | 1:fdd22bb7aa52 | 111 | 0.941544055938720700f, 0.949528157711029050f, 0.956940352916717530f, |
emilmont | 1:fdd22bb7aa52 | 112 | 0.963776051998138430f, 0.970031261444091800f, |
emilmont | 1:fdd22bb7aa52 | 113 | 0.975702106952667240f, 0.980785250663757320f, 0.985277652740478520f, |
emilmont | 1:fdd22bb7aa52 | 114 | 0.989176511764526370f, 0.992479562759399410f, 0.995184719562530520f, |
emilmont | 1:fdd22bb7aa52 | 115 | 0.997290432453155520f, 0.998795449733734130f, |
emilmont | 1:fdd22bb7aa52 | 116 | 0.999698817729949950f, 1.000000000000000000f, 0.999698817729949950f, |
emilmont | 1:fdd22bb7aa52 | 117 | 0.998795449733734130f, 0.997290432453155520f, 0.995184719562530520f, |
emilmont | 1:fdd22bb7aa52 | 118 | 0.992479562759399410f, 0.989176511764526370f, |
emilmont | 1:fdd22bb7aa52 | 119 | 0.985277652740478520f, 0.980785250663757320f, 0.975702106952667240f, |
emilmont | 1:fdd22bb7aa52 | 120 | 0.970031261444091800f, 0.963776051998138430f, 0.956940352916717530f, |
emilmont | 1:fdd22bb7aa52 | 121 | 0.949528157711029050f, 0.941544055938720700f, |
emilmont | 1:fdd22bb7aa52 | 122 | 0.932992815971374510f, 0.923879504203796390f, 0.914209783077239990f, |
emilmont | 1:fdd22bb7aa52 | 123 | 0.903989315032958980f, 0.893224298954010010f, 0.881921291351318360f, |
emilmont | 1:fdd22bb7aa52 | 124 | 0.870086967945098880f, 0.857728600502014160f, |
emilmont | 1:fdd22bb7aa52 | 125 | 0.844853579998016360f, 0.831469595432281490f, 0.817584812641143800f, |
emilmont | 1:fdd22bb7aa52 | 126 | 0.803207516670227050f, 0.788346409797668460f, 0.773010432720184330f, |
emilmont | 1:fdd22bb7aa52 | 127 | 0.757208824157714840f, 0.740951120853424070f, |
emilmont | 1:fdd22bb7aa52 | 128 | 0.724247097969055180f, 0.707106769084930420f, 0.689540565013885500f, |
emilmont | 1:fdd22bb7aa52 | 129 | 0.671558976173400880f, 0.653172850608825680f, 0.634393274784088130f, |
emilmont | 1:fdd22bb7aa52 | 130 | 0.615231573581695560f, 0.595699310302734380f, |
emilmont | 1:fdd22bb7aa52 | 131 | 0.575808167457580570f, 0.555570244789123540f, 0.534997642040252690f, |
emilmont | 1:fdd22bb7aa52 | 132 | 0.514102756977081300f, 0.492898195981979370f, 0.471396744251251220f, |
emilmont | 1:fdd22bb7aa52 | 133 | 0.449611335992813110f, 0.427555084228515630f, |
emilmont | 1:fdd22bb7aa52 | 134 | 0.405241310596466060f, 0.382683426141738890f, 0.359895050525665280f, |
emilmont | 1:fdd22bb7aa52 | 135 | 0.336889863014221190f, 0.313681751489639280f, 0.290284663438797000f, |
emilmont | 1:fdd22bb7aa52 | 136 | 0.266712754964828490f, 0.242980182170867920f, |
emilmont | 1:fdd22bb7aa52 | 137 | 0.219101235270500180f, 0.195090323686599730f, 0.170961886644363400f, |
emilmont | 1:fdd22bb7aa52 | 138 | 0.146730467677116390f, 0.122410677373409270f, 0.098017141222953796f, |
emilmont | 1:fdd22bb7aa52 | 139 | 0.073564566671848297f, 0.049067676067352295f, |
emilmont | 1:fdd22bb7aa52 | 140 | 0.024541229009628296f, 0.000000000000000122f, -0.024541229009628296f, |
emilmont | 1:fdd22bb7aa52 | 141 | -0.049067676067352295f, -0.073564566671848297f, -0.098017141222953796f, |
emilmont | 1:fdd22bb7aa52 | 142 | -0.122410677373409270f, -0.146730467677116390f, |
emilmont | 1:fdd22bb7aa52 | 143 | -0.170961886644363400f, -0.195090323686599730f, -0.219101235270500180f, |
emilmont | 1:fdd22bb7aa52 | 144 | -0.242980182170867920f, -0.266712754964828490f, -0.290284663438797000f, |
emilmont | 1:fdd22bb7aa52 | 145 | -0.313681751489639280f, -0.336889863014221190f, |
emilmont | 1:fdd22bb7aa52 | 146 | -0.359895050525665280f, -0.382683426141738890f, -0.405241310596466060f, |
emilmont | 1:fdd22bb7aa52 | 147 | -0.427555084228515630f, -0.449611335992813110f, -0.471396744251251220f, |
emilmont | 1:fdd22bb7aa52 | 148 | -0.492898195981979370f, -0.514102756977081300f, |
emilmont | 1:fdd22bb7aa52 | 149 | -0.534997642040252690f, -0.555570244789123540f, -0.575808167457580570f, |
emilmont | 1:fdd22bb7aa52 | 150 | -0.595699310302734380f, -0.615231573581695560f, -0.634393274784088130f, |
emilmont | 1:fdd22bb7aa52 | 151 | -0.653172850608825680f, -0.671558976173400880f, |
emilmont | 1:fdd22bb7aa52 | 152 | -0.689540565013885500f, -0.707106769084930420f, -0.724247097969055180f, |
emilmont | 1:fdd22bb7aa52 | 153 | -0.740951120853424070f, -0.757208824157714840f, -0.773010432720184330f, |
emilmont | 1:fdd22bb7aa52 | 154 | -0.788346409797668460f, -0.803207516670227050f, |
emilmont | 1:fdd22bb7aa52 | 155 | -0.817584812641143800f, -0.831469595432281490f, -0.844853579998016360f, |
emilmont | 1:fdd22bb7aa52 | 156 | -0.857728600502014160f, -0.870086967945098880f, -0.881921291351318360f, |
emilmont | 1:fdd22bb7aa52 | 157 | -0.893224298954010010f, -0.903989315032958980f, |
emilmont | 1:fdd22bb7aa52 | 158 | -0.914209783077239990f, -0.923879504203796390f, -0.932992815971374510f, |
emilmont | 1:fdd22bb7aa52 | 159 | -0.941544055938720700f, -0.949528157711029050f, -0.956940352916717530f, |
emilmont | 1:fdd22bb7aa52 | 160 | -0.963776051998138430f, -0.970031261444091800f, |
emilmont | 1:fdd22bb7aa52 | 161 | -0.975702106952667240f, -0.980785250663757320f, -0.985277652740478520f, |
emilmont | 1:fdd22bb7aa52 | 162 | -0.989176511764526370f, -0.992479562759399410f, -0.995184719562530520f, |
emilmont | 1:fdd22bb7aa52 | 163 | -0.997290432453155520f, -0.998795449733734130f, |
emilmont | 1:fdd22bb7aa52 | 164 | -0.999698817729949950f, -1.000000000000000000f, -0.999698817729949950f, |
emilmont | 1:fdd22bb7aa52 | 165 | -0.998795449733734130f, -0.997290432453155520f, -0.995184719562530520f, |
emilmont | 1:fdd22bb7aa52 | 166 | -0.992479562759399410f, -0.989176511764526370f, |
emilmont | 1:fdd22bb7aa52 | 167 | -0.985277652740478520f, -0.980785250663757320f, -0.975702106952667240f, |
emilmont | 1:fdd22bb7aa52 | 168 | -0.970031261444091800f, -0.963776051998138430f, -0.956940352916717530f, |
emilmont | 1:fdd22bb7aa52 | 169 | -0.949528157711029050f, -0.941544055938720700f, |
emilmont | 1:fdd22bb7aa52 | 170 | -0.932992815971374510f, -0.923879504203796390f, -0.914209783077239990f, |
emilmont | 1:fdd22bb7aa52 | 171 | -0.903989315032958980f, -0.893224298954010010f, -0.881921291351318360f, |
emilmont | 1:fdd22bb7aa52 | 172 | -0.870086967945098880f, -0.857728600502014160f, |
emilmont | 1:fdd22bb7aa52 | 173 | -0.844853579998016360f, -0.831469595432281490f, -0.817584812641143800f, |
emilmont | 1:fdd22bb7aa52 | 174 | -0.803207516670227050f, -0.788346409797668460f, -0.773010432720184330f, |
emilmont | 1:fdd22bb7aa52 | 175 | -0.757208824157714840f, -0.740951120853424070f, |
emilmont | 1:fdd22bb7aa52 | 176 | -0.724247097969055180f, -0.707106769084930420f, -0.689540565013885500f, |
emilmont | 1:fdd22bb7aa52 | 177 | -0.671558976173400880f, -0.653172850608825680f, -0.634393274784088130f, |
emilmont | 1:fdd22bb7aa52 | 178 | -0.615231573581695560f, -0.595699310302734380f, |
emilmont | 1:fdd22bb7aa52 | 179 | -0.575808167457580570f, -0.555570244789123540f, -0.534997642040252690f, |
emilmont | 1:fdd22bb7aa52 | 180 | -0.514102756977081300f, -0.492898195981979370f, -0.471396744251251220f, |
emilmont | 1:fdd22bb7aa52 | 181 | -0.449611335992813110f, -0.427555084228515630f, |
emilmont | 1:fdd22bb7aa52 | 182 | -0.405241310596466060f, -0.382683426141738890f, -0.359895050525665280f, |
emilmont | 1:fdd22bb7aa52 | 183 | -0.336889863014221190f, -0.313681751489639280f, -0.290284663438797000f, |
emilmont | 1:fdd22bb7aa52 | 184 | -0.266712754964828490f, -0.242980182170867920f, |
emilmont | 1:fdd22bb7aa52 | 185 | -0.219101235270500180f, -0.195090323686599730f, -0.170961886644363400f, |
emilmont | 1:fdd22bb7aa52 | 186 | -0.146730467677116390f, -0.122410677373409270f, -0.098017141222953796f, |
emilmont | 1:fdd22bb7aa52 | 187 | -0.073564566671848297f, -0.049067676067352295f, |
emilmont | 1:fdd22bb7aa52 | 188 | -0.024541229009628296f, -0.000000000000000245f, 0.024541229009628296f |
emilmont | 1:fdd22bb7aa52 | 189 | }; |
emilmont | 1:fdd22bb7aa52 | 190 | |
emilmont | 1:fdd22bb7aa52 | 191 | |
emilmont | 1:fdd22bb7aa52 | 192 | /** |
emilmont | 1:fdd22bb7aa52 | 193 | * @brief Fast approximation to the trigonometric sine function for floating-point data. |
emilmont | 1:fdd22bb7aa52 | 194 | * @param[in] x input value in radians. |
emilmont | 1:fdd22bb7aa52 | 195 | * @return sin(x). |
emilmont | 1:fdd22bb7aa52 | 196 | */ |
emilmont | 1:fdd22bb7aa52 | 197 | |
emilmont | 1:fdd22bb7aa52 | 198 | float32_t arm_sin_f32( |
emilmont | 1:fdd22bb7aa52 | 199 | float32_t x) |
emilmont | 1:fdd22bb7aa52 | 200 | { |
emilmont | 1:fdd22bb7aa52 | 201 | float32_t sinVal, fract, in; /* Temporary variables for input, output */ |
emilmont | 1:fdd22bb7aa52 | 202 | int32_t index; /* Index variable */ |
emilmont | 1:fdd22bb7aa52 | 203 | uint32_t tableSize = (uint32_t) TABLE_SIZE; /* Initialise tablesize */ |
emilmont | 1:fdd22bb7aa52 | 204 | float32_t wa, wb, wc, wd; /* Cubic interpolation coefficients */ |
emilmont | 1:fdd22bb7aa52 | 205 | float32_t a, b, c, d; /* Four nearest output values */ |
emilmont | 1:fdd22bb7aa52 | 206 | float32_t *tablePtr; /* Pointer to table */ |
emilmont | 1:fdd22bb7aa52 | 207 | int32_t n; |
emilmont | 1:fdd22bb7aa52 | 208 | float32_t fractsq, fractby2, fractby6, fractby3, fractsqby2; |
emilmont | 1:fdd22bb7aa52 | 209 | float32_t oneminusfractby2; |
emilmont | 1:fdd22bb7aa52 | 210 | float32_t frby2xfrsq, frby6xfrsq; |
emilmont | 1:fdd22bb7aa52 | 211 | |
emilmont | 1:fdd22bb7aa52 | 212 | /* input x is in radians */ |
emilmont | 1:fdd22bb7aa52 | 213 | /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi */ |
emilmont | 1:fdd22bb7aa52 | 214 | in = x * 0.159154943092f; |
emilmont | 1:fdd22bb7aa52 | 215 | |
emilmont | 1:fdd22bb7aa52 | 216 | /* Calculation of floor value of input */ |
emilmont | 1:fdd22bb7aa52 | 217 | n = (int32_t) in; |
emilmont | 1:fdd22bb7aa52 | 218 | |
emilmont | 1:fdd22bb7aa52 | 219 | /* Make negative values towards -infinity */ |
emilmont | 1:fdd22bb7aa52 | 220 | if(x < 0.0f) |
emilmont | 1:fdd22bb7aa52 | 221 | { |
emilmont | 1:fdd22bb7aa52 | 222 | n = n - 1; |
emilmont | 1:fdd22bb7aa52 | 223 | } |
emilmont | 1:fdd22bb7aa52 | 224 | |
emilmont | 1:fdd22bb7aa52 | 225 | /* Map input value to [0 1] */ |
emilmont | 1:fdd22bb7aa52 | 226 | in = in - (float32_t) n; |
emilmont | 1:fdd22bb7aa52 | 227 | |
emilmont | 1:fdd22bb7aa52 | 228 | /* Calculation of index of the table */ |
emilmont | 1:fdd22bb7aa52 | 229 | index = (uint32_t) (tableSize * in); |
emilmont | 1:fdd22bb7aa52 | 230 | |
emilmont | 1:fdd22bb7aa52 | 231 | /* fractional value calculation */ |
emilmont | 1:fdd22bb7aa52 | 232 | fract = ((float32_t) tableSize * in) - (float32_t) index; |
emilmont | 1:fdd22bb7aa52 | 233 | |
emilmont | 1:fdd22bb7aa52 | 234 | /* Checking min and max index of table */ |
emilmont | 1:fdd22bb7aa52 | 235 | if(index < 0) |
emilmont | 1:fdd22bb7aa52 | 236 | { |
emilmont | 1:fdd22bb7aa52 | 237 | index = 0; |
emilmont | 1:fdd22bb7aa52 | 238 | } |
emilmont | 1:fdd22bb7aa52 | 239 | else if(index > 256) |
emilmont | 1:fdd22bb7aa52 | 240 | { |
emilmont | 1:fdd22bb7aa52 | 241 | index = 256; |
emilmont | 1:fdd22bb7aa52 | 242 | } |
emilmont | 1:fdd22bb7aa52 | 243 | |
emilmont | 1:fdd22bb7aa52 | 244 | /* Initialise table pointer */ |
emilmont | 1:fdd22bb7aa52 | 245 | tablePtr = (float32_t *) & sinTable[index]; |
emilmont | 1:fdd22bb7aa52 | 246 | |
emilmont | 1:fdd22bb7aa52 | 247 | /* Read four nearest values of input value from the sin table */ |
emilmont | 1:fdd22bb7aa52 | 248 | a = tablePtr[0]; |
emilmont | 1:fdd22bb7aa52 | 249 | b = tablePtr[1]; |
emilmont | 1:fdd22bb7aa52 | 250 | c = tablePtr[2]; |
emilmont | 1:fdd22bb7aa52 | 251 | d = tablePtr[3]; |
emilmont | 1:fdd22bb7aa52 | 252 | |
emilmont | 1:fdd22bb7aa52 | 253 | /* Cubic interpolation process */ |
emilmont | 1:fdd22bb7aa52 | 254 | fractsq = fract * fract; |
emilmont | 1:fdd22bb7aa52 | 255 | fractby2 = fract * 0.5f; |
emilmont | 1:fdd22bb7aa52 | 256 | fractby6 = fract * 0.166666667f; |
emilmont | 1:fdd22bb7aa52 | 257 | fractby3 = fract * 0.3333333333333f; |
emilmont | 1:fdd22bb7aa52 | 258 | fractsqby2 = fractsq * 0.5f; |
emilmont | 1:fdd22bb7aa52 | 259 | frby2xfrsq = (fractby2) * fractsq; |
emilmont | 1:fdd22bb7aa52 | 260 | frby6xfrsq = (fractby6) * fractsq; |
emilmont | 1:fdd22bb7aa52 | 261 | oneminusfractby2 = 1.0f - fractby2; |
emilmont | 1:fdd22bb7aa52 | 262 | wb = fractsqby2 - fractby3; |
emilmont | 1:fdd22bb7aa52 | 263 | wc = (fractsqby2 + fract); |
emilmont | 1:fdd22bb7aa52 | 264 | wa = wb - frby6xfrsq; |
emilmont | 1:fdd22bb7aa52 | 265 | wb = frby2xfrsq - fractsq; |
emilmont | 1:fdd22bb7aa52 | 266 | sinVal = wa * a; |
emilmont | 1:fdd22bb7aa52 | 267 | wc = wc - frby2xfrsq; |
emilmont | 1:fdd22bb7aa52 | 268 | wd = (frby6xfrsq) - fractby6; |
emilmont | 1:fdd22bb7aa52 | 269 | wb = wb + oneminusfractby2; |
emilmont | 1:fdd22bb7aa52 | 270 | |
emilmont | 1:fdd22bb7aa52 | 271 | /* Calculate sin value */ |
emilmont | 1:fdd22bb7aa52 | 272 | sinVal = (sinVal + (b * wb)) + ((c * wc) + (d * wd)); |
emilmont | 1:fdd22bb7aa52 | 273 | |
emilmont | 1:fdd22bb7aa52 | 274 | /* Return the output value */ |
emilmont | 1:fdd22bb7aa52 | 275 | return (sinVal); |
emilmont | 1:fdd22bb7aa52 | 276 | |
emilmont | 1:fdd22bb7aa52 | 277 | } |
emilmont | 1:fdd22bb7aa52 | 278 | |
emilmont | 1:fdd22bb7aa52 | 279 | /** |
emilmont | 1:fdd22bb7aa52 | 280 | * @} end of sin group |
emilmont | 1:fdd22bb7aa52 | 281 | */ |