CMSIS DSP library

Dependents:   performance_timer Surfboard_ gps2rtty Capstone ... more

Legacy Warning

This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.

Committer:
mbed_official
Date:
Fri Nov 20 08:45:18 2015 +0000
Revision:
5:3762170b6d4d
Parent:
3:7a284390b0ce
Synchronized with git revision 2eb940b9a73af188d3004a2575fdfbb05febe62b

Full URL: https://github.com/mbedmicro/mbed/commit/2eb940b9a73af188d3004a2575fdfbb05febe62b/

Added option to build rpc library. closes #1426

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 5:3762170b6d4d 1 /* ----------------------------------------------------------------------
mbed_official 5:3762170b6d4d 2 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
mbed_official 5:3762170b6d4d 3 *
mbed_official 5:3762170b6d4d 4 * $Date: 21. September 2015
mbed_official 5:3762170b6d4d 5 * $Revision: V.1.4.5 a
mbed_official 5:3762170b6d4d 6 *
mbed_official 5:3762170b6d4d 7 * Project: CMSIS DSP Library
mbed_official 5:3762170b6d4d 8 * Title: arm_sin_f32.c
mbed_official 5:3762170b6d4d 9 *
mbed_official 5:3762170b6d4d 10 * Description: Fast sine calculation for floating-point values.
mbed_official 5:3762170b6d4d 11 *
emilmont 1:fdd22bb7aa52 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
mbed_official 5:3762170b6d4d 13 *
mbed_official 5:3762170b6d4d 14 * Redistribution and use in source and binary forms, with or without
mbed_official 3:7a284390b0ce 15 * modification, are permitted provided that the following conditions
mbed_official 3:7a284390b0ce 16 * are met:
mbed_official 3:7a284390b0ce 17 * - Redistributions of source code must retain the above copyright
mbed_official 3:7a284390b0ce 18 * notice, this list of conditions and the following disclaimer.
mbed_official 3:7a284390b0ce 19 * - Redistributions in binary form must reproduce the above copyright
mbed_official 3:7a284390b0ce 20 * notice, this list of conditions and the following disclaimer in
mbed_official 5:3762170b6d4d 21 * the documentation and/or other materials provided with the
mbed_official 3:7a284390b0ce 22 * distribution.
mbed_official 3:7a284390b0ce 23 * - Neither the name of ARM LIMITED nor the names of its contributors
mbed_official 3:7a284390b0ce 24 * may be used to endorse or promote products derived from this
mbed_official 3:7a284390b0ce 25 * software without specific prior written permission.
mbed_official 3:7a284390b0ce 26 *
mbed_official 3:7a284390b0ce 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
mbed_official 3:7a284390b0ce 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
mbed_official 3:7a284390b0ce 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
mbed_official 5:3762170b6d4d 30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
mbed_official 3:7a284390b0ce 31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
mbed_official 3:7a284390b0ce 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
mbed_official 3:7a284390b0ce 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 3:7a284390b0ce 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 3:7a284390b0ce 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
mbed_official 3:7a284390b0ce 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 3:7a284390b0ce 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 5:3762170b6d4d 38 * POSSIBILITY OF SUCH DAMAGE.
emilmont 1:fdd22bb7aa52 39 * -------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 40
emilmont 1:fdd22bb7aa52 41 #include "arm_math.h"
mbed_official 5:3762170b6d4d 42 #include "arm_common_tables.h"
mbed_official 5:3762170b6d4d 43 #include <math.h>
emilmont 1:fdd22bb7aa52 44
mbed_official 5:3762170b6d4d 45 /**
mbed_official 5:3762170b6d4d 46 * @ingroup groupFastMath
emilmont 1:fdd22bb7aa52 47 */
emilmont 1:fdd22bb7aa52 48
mbed_official 5:3762170b6d4d 49 /**
mbed_official 5:3762170b6d4d 50 * @defgroup sin Sine
mbed_official 5:3762170b6d4d 51 *
mbed_official 5:3762170b6d4d 52 * Computes the trigonometric sine function using a combination of table lookup
mbed_official 5:3762170b6d4d 53 * and linear interpolation. There are separate functions for
mbed_official 5:3762170b6d4d 54 * Q15, Q31, and floating-point data types.
mbed_official 5:3762170b6d4d 55 * The input to the floating-point version is in radians while the
mbed_official 5:3762170b6d4d 56 * fixed-point Q15 and Q31 have a scaled input with the range
mbed_official 5:3762170b6d4d 57 * [0 +0.9999] mapping to [0 2*pi). The fixed-point range is chosen so that a
mbed_official 5:3762170b6d4d 58 * value of 2*pi wraps around to 0.
mbed_official 5:3762170b6d4d 59 *
mbed_official 5:3762170b6d4d 60 * The implementation is based on table lookup using 256 values together with linear interpolation.
mbed_official 5:3762170b6d4d 61 * The steps used are:
mbed_official 5:3762170b6d4d 62 * -# Calculation of the nearest integer table index
mbed_official 5:3762170b6d4d 63 * -# Compute the fractional portion (fract) of the table index.
mbed_official 5:3762170b6d4d 64 * -# The final result equals <code>(1.0f-fract)*a + fract*b;</code>
mbed_official 5:3762170b6d4d 65 *
mbed_official 5:3762170b6d4d 66 * where
mbed_official 5:3762170b6d4d 67 * <pre>
mbed_official 5:3762170b6d4d 68 * b=Table[index+0];
mbed_official 5:3762170b6d4d 69 * c=Table[index+1];
mbed_official 5:3762170b6d4d 70 * </pre>
mbed_official 5:3762170b6d4d 71 */
emilmont 1:fdd22bb7aa52 72
mbed_official 5:3762170b6d4d 73 /**
mbed_official 5:3762170b6d4d 74 * @addtogroup sin
mbed_official 5:3762170b6d4d 75 * @{
mbed_official 5:3762170b6d4d 76 */
emilmont 1:fdd22bb7aa52 77
mbed_official 5:3762170b6d4d 78 /**
mbed_official 5:3762170b6d4d 79 * @brief Fast approximation to the trigonometric sine function for floating-point data.
mbed_official 5:3762170b6d4d 80 * @param[in] x input value in radians.
mbed_official 5:3762170b6d4d 81 * @return sin(x).
emilmont 1:fdd22bb7aa52 82 */
emilmont 1:fdd22bb7aa52 83
emilmont 1:fdd22bb7aa52 84 float32_t arm_sin_f32(
emilmont 1:fdd22bb7aa52 85 float32_t x)
emilmont 1:fdd22bb7aa52 86 {
mbed_official 5:3762170b6d4d 87 float32_t sinVal, fract, in; /* Temporary variables for input, output */
mbed_official 5:3762170b6d4d 88 uint16_t index; /* Index variable */
mbed_official 5:3762170b6d4d 89 float32_t a, b; /* Two nearest output values */
emilmont 1:fdd22bb7aa52 90 int32_t n;
mbed_official 5:3762170b6d4d 91 float32_t findex;
emilmont 1:fdd22bb7aa52 92
emilmont 1:fdd22bb7aa52 93 /* input x is in radians */
emilmont 1:fdd22bb7aa52 94 /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi */
emilmont 1:fdd22bb7aa52 95 in = x * 0.159154943092f;
emilmont 1:fdd22bb7aa52 96
emilmont 1:fdd22bb7aa52 97 /* Calculation of floor value of input */
emilmont 1:fdd22bb7aa52 98 n = (int32_t) in;
emilmont 1:fdd22bb7aa52 99
emilmont 1:fdd22bb7aa52 100 /* Make negative values towards -infinity */
emilmont 1:fdd22bb7aa52 101 if(x < 0.0f)
emilmont 1:fdd22bb7aa52 102 {
mbed_official 5:3762170b6d4d 103 n--;
emilmont 1:fdd22bb7aa52 104 }
emilmont 1:fdd22bb7aa52 105
emilmont 1:fdd22bb7aa52 106 /* Map input value to [0 1] */
emilmont 1:fdd22bb7aa52 107 in = in - (float32_t) n;
emilmont 1:fdd22bb7aa52 108
emilmont 1:fdd22bb7aa52 109 /* Calculation of index of the table */
mbed_official 5:3762170b6d4d 110 findex = (float32_t) FAST_MATH_TABLE_SIZE * in;
mbed_official 5:3762170b6d4d 111 if (findex >= 512.0f) {
mbed_official 5:3762170b6d4d 112 findex -= 512.0f;
emilmont 1:fdd22bb7aa52 113 }
emilmont 1:fdd22bb7aa52 114
mbed_official 5:3762170b6d4d 115 index = ((uint16_t)findex) & 0x1ff;
emilmont 1:fdd22bb7aa52 116
mbed_official 5:3762170b6d4d 117 /* fractional value calculation */
mbed_official 5:3762170b6d4d 118 fract = findex - (float32_t) index;
emilmont 1:fdd22bb7aa52 119
mbed_official 5:3762170b6d4d 120 /* Read two nearest values of input value from the sin table */
mbed_official 5:3762170b6d4d 121 a = sinTable_f32[index];
mbed_official 5:3762170b6d4d 122 b = sinTable_f32[index+1];
emilmont 1:fdd22bb7aa52 123
mbed_official 5:3762170b6d4d 124 /* Linear interpolation process */
mbed_official 5:3762170b6d4d 125 sinVal = (1.0f-fract)*a + fract*b;
emilmont 1:fdd22bb7aa52 126
emilmont 1:fdd22bb7aa52 127 /* Return the output value */
emilmont 1:fdd22bb7aa52 128 return (sinVal);
emilmont 1:fdd22bb7aa52 129 }
emilmont 1:fdd22bb7aa52 130
mbed_official 5:3762170b6d4d 131 /**
mbed_official 5:3762170b6d4d 132 * @} end of sin group
emilmont 1:fdd22bb7aa52 133 */