Aded CMSIS5 DSP and NN folder. Needs some work

Committer:
robert_lp
Date:
Thu Apr 12 01:31:58 2018 +0000
Revision:
0:eedb7d567a5d
CMSIS5 Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robert_lp 0:eedb7d567a5d 1 /* ----------------------------------------------------------------------
robert_lp 0:eedb7d567a5d 2 * Project: CMSIS DSP Library
robert_lp 0:eedb7d567a5d 3 * Title: arm_sin_f32.c
robert_lp 0:eedb7d567a5d 4 * Description: Fast sine calculation for floating-point values
robert_lp 0:eedb7d567a5d 5 *
robert_lp 0:eedb7d567a5d 6 * $Date: 27. January 2017
robert_lp 0:eedb7d567a5d 7 * $Revision: V.1.5.1
robert_lp 0:eedb7d567a5d 8 *
robert_lp 0:eedb7d567a5d 9 * Target Processor: Cortex-M cores
robert_lp 0:eedb7d567a5d 10 * -------------------------------------------------------------------- */
robert_lp 0:eedb7d567a5d 11 /*
robert_lp 0:eedb7d567a5d 12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
robert_lp 0:eedb7d567a5d 13 *
robert_lp 0:eedb7d567a5d 14 * SPDX-License-Identifier: Apache-2.0
robert_lp 0:eedb7d567a5d 15 *
robert_lp 0:eedb7d567a5d 16 * Licensed under the Apache License, Version 2.0 (the License); you may
robert_lp 0:eedb7d567a5d 17 * not use this file except in compliance with the License.
robert_lp 0:eedb7d567a5d 18 * You may obtain a copy of the License at
robert_lp 0:eedb7d567a5d 19 *
robert_lp 0:eedb7d567a5d 20 * www.apache.org/licenses/LICENSE-2.0
robert_lp 0:eedb7d567a5d 21 *
robert_lp 0:eedb7d567a5d 22 * Unless required by applicable law or agreed to in writing, software
robert_lp 0:eedb7d567a5d 23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
robert_lp 0:eedb7d567a5d 24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
robert_lp 0:eedb7d567a5d 25 * See the License for the specific language governing permissions and
robert_lp 0:eedb7d567a5d 26 * limitations under the License.
robert_lp 0:eedb7d567a5d 27 */
robert_lp 0:eedb7d567a5d 28
robert_lp 0:eedb7d567a5d 29 #include "arm_math.h"
robert_lp 0:eedb7d567a5d 30 #include "arm_common_tables.h"
robert_lp 0:eedb7d567a5d 31 #include <math.h>
robert_lp 0:eedb7d567a5d 32
robert_lp 0:eedb7d567a5d 33 /**
robert_lp 0:eedb7d567a5d 34 * @ingroup groupFastMath
robert_lp 0:eedb7d567a5d 35 */
robert_lp 0:eedb7d567a5d 36
robert_lp 0:eedb7d567a5d 37 /**
robert_lp 0:eedb7d567a5d 38 * @defgroup sin Sine
robert_lp 0:eedb7d567a5d 39 *
robert_lp 0:eedb7d567a5d 40 * Computes the trigonometric sine function using a combination of table lookup
robert_lp 0:eedb7d567a5d 41 * and linear interpolation. There are separate functions for
robert_lp 0:eedb7d567a5d 42 * Q15, Q31, and floating-point data types.
robert_lp 0:eedb7d567a5d 43 * The input to the floating-point version is in radians and in the range [0 2*pi) while the
robert_lp 0:eedb7d567a5d 44 * fixed-point Q15 and Q31 have a scaled input with the range
robert_lp 0:eedb7d567a5d 45 * [0 +0.9999] mapping to [0 2*pi). The fixed-point range is chosen so that a
robert_lp 0:eedb7d567a5d 46 * value of 2*pi wraps around to 0.
robert_lp 0:eedb7d567a5d 47 *
robert_lp 0:eedb7d567a5d 48 * The implementation is based on table lookup using 256 values together with linear interpolation.
robert_lp 0:eedb7d567a5d 49 * The steps used are:
robert_lp 0:eedb7d567a5d 50 * -# Calculation of the nearest integer table index
robert_lp 0:eedb7d567a5d 51 * -# Compute the fractional portion (fract) of the table index.
robert_lp 0:eedb7d567a5d 52 * -# The final result equals <code>(1.0f-fract)*a + fract*b;</code>
robert_lp 0:eedb7d567a5d 53 *
robert_lp 0:eedb7d567a5d 54 * where
robert_lp 0:eedb7d567a5d 55 * <pre>
robert_lp 0:eedb7d567a5d 56 * b=Table[index+0];
robert_lp 0:eedb7d567a5d 57 * c=Table[index+1];
robert_lp 0:eedb7d567a5d 58 * </pre>
robert_lp 0:eedb7d567a5d 59 */
robert_lp 0:eedb7d567a5d 60
robert_lp 0:eedb7d567a5d 61 /**
robert_lp 0:eedb7d567a5d 62 * @addtogroup sin
robert_lp 0:eedb7d567a5d 63 * @{
robert_lp 0:eedb7d567a5d 64 */
robert_lp 0:eedb7d567a5d 65
robert_lp 0:eedb7d567a5d 66 /**
robert_lp 0:eedb7d567a5d 67 * @brief Fast approximation to the trigonometric sine function for floating-point data.
robert_lp 0:eedb7d567a5d 68 * @param[in] x input value in radians.
robert_lp 0:eedb7d567a5d 69 * @return sin(x).
robert_lp 0:eedb7d567a5d 70 */
robert_lp 0:eedb7d567a5d 71
robert_lp 0:eedb7d567a5d 72 float32_t arm_sin_f32(
robert_lp 0:eedb7d567a5d 73 float32_t x)
robert_lp 0:eedb7d567a5d 74 {
robert_lp 0:eedb7d567a5d 75 float32_t sinVal, fract, in; /* Temporary variables for input, output */
robert_lp 0:eedb7d567a5d 76 uint16_t index; /* Index variable */
robert_lp 0:eedb7d567a5d 77 float32_t a, b; /* Two nearest output values */
robert_lp 0:eedb7d567a5d 78 int32_t n;
robert_lp 0:eedb7d567a5d 79 float32_t findex;
robert_lp 0:eedb7d567a5d 80
robert_lp 0:eedb7d567a5d 81 /* Special case for small negative inputs */
robert_lp 0:eedb7d567a5d 82 if ((x < 0.0f) && (x >= -1.9e-7f)) {
robert_lp 0:eedb7d567a5d 83 return x;
robert_lp 0:eedb7d567a5d 84 }
robert_lp 0:eedb7d567a5d 85
robert_lp 0:eedb7d567a5d 86 /* input x is in radians */
robert_lp 0:eedb7d567a5d 87 /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi */
robert_lp 0:eedb7d567a5d 88 in = x * 0.159154943092f;
robert_lp 0:eedb7d567a5d 89
robert_lp 0:eedb7d567a5d 90 /* Calculation of floor value of input */
robert_lp 0:eedb7d567a5d 91 n = (int32_t) in;
robert_lp 0:eedb7d567a5d 92
robert_lp 0:eedb7d567a5d 93 /* Make negative values towards -infinity */
robert_lp 0:eedb7d567a5d 94 if (x < 0.0f)
robert_lp 0:eedb7d567a5d 95 {
robert_lp 0:eedb7d567a5d 96 n--;
robert_lp 0:eedb7d567a5d 97 }
robert_lp 0:eedb7d567a5d 98
robert_lp 0:eedb7d567a5d 99 /* Map input value to [0 1] */
robert_lp 0:eedb7d567a5d 100 in = in - (float32_t) n;
robert_lp 0:eedb7d567a5d 101
robert_lp 0:eedb7d567a5d 102 /* Calculation of index of the table */
robert_lp 0:eedb7d567a5d 103 findex = (float32_t) FAST_MATH_TABLE_SIZE * in;
robert_lp 0:eedb7d567a5d 104
robert_lp 0:eedb7d567a5d 105 index = ((uint16_t)findex) & 0x1ff;
robert_lp 0:eedb7d567a5d 106
robert_lp 0:eedb7d567a5d 107 /* fractional value calculation */
robert_lp 0:eedb7d567a5d 108 fract = findex - (float32_t) index;
robert_lp 0:eedb7d567a5d 109
robert_lp 0:eedb7d567a5d 110 /* Read two nearest values of input value from the sin table */
robert_lp 0:eedb7d567a5d 111 a = sinTable_f32[index];
robert_lp 0:eedb7d567a5d 112 b = sinTable_f32[index+1];
robert_lp 0:eedb7d567a5d 113
robert_lp 0:eedb7d567a5d 114 /* Linear interpolation process */
robert_lp 0:eedb7d567a5d 115 sinVal = (1.0f-fract)*a + fract*b;
robert_lp 0:eedb7d567a5d 116
robert_lp 0:eedb7d567a5d 117 /* Return the output value */
robert_lp 0:eedb7d567a5d 118 return (sinVal);
robert_lp 0:eedb7d567a5d 119 }
robert_lp 0:eedb7d567a5d 120
robert_lp 0:eedb7d567a5d 121 /**
robert_lp 0:eedb7d567a5d 122 * @} end of sin group
robert_lp 0:eedb7d567a5d 123 */
robert_lp 0:eedb7d567a5d 124