Aded CMSIS5 DSP and NN folder. Needs some work
DSP/source/FastMathFunctions/arm_sin_q15.c@0:eedb7d567a5d, 2018-04-12 (annotated)
- Committer:
- robert_lp
- Date:
- Thu Apr 12 01:31:58 2018 +0000
- Revision:
- 0:eedb7d567a5d
CMSIS5 Library
Who changed what in which revision?
User | Revision | Line number | New 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_q15.c |
robert_lp | 0:eedb7d567a5d | 4 | * Description: Fast sine calculation for Q15 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 | |
robert_lp | 0:eedb7d567a5d | 32 | /** |
robert_lp | 0:eedb7d567a5d | 33 | * @ingroup groupFastMath |
robert_lp | 0:eedb7d567a5d | 34 | */ |
robert_lp | 0:eedb7d567a5d | 35 | |
robert_lp | 0:eedb7d567a5d | 36 | /** |
robert_lp | 0:eedb7d567a5d | 37 | * @addtogroup sin |
robert_lp | 0:eedb7d567a5d | 38 | * @{ |
robert_lp | 0:eedb7d567a5d | 39 | */ |
robert_lp | 0:eedb7d567a5d | 40 | |
robert_lp | 0:eedb7d567a5d | 41 | /** |
robert_lp | 0:eedb7d567a5d | 42 | * @brief Fast approximation to the trigonometric sine function for Q15 data. |
robert_lp | 0:eedb7d567a5d | 43 | * @param[in] x Scaled input value in radians. |
robert_lp | 0:eedb7d567a5d | 44 | * @return sin(x). |
robert_lp | 0:eedb7d567a5d | 45 | * |
robert_lp | 0:eedb7d567a5d | 46 | * The Q15 input value is in the range [0 +0.9999] and is mapped to a radian value in the range [0 2*pi). |
robert_lp | 0:eedb7d567a5d | 47 | */ |
robert_lp | 0:eedb7d567a5d | 48 | |
robert_lp | 0:eedb7d567a5d | 49 | q15_t arm_sin_q15( |
robert_lp | 0:eedb7d567a5d | 50 | q15_t x) |
robert_lp | 0:eedb7d567a5d | 51 | { |
robert_lp | 0:eedb7d567a5d | 52 | q15_t sinVal; /* Temporary variables for input, output */ |
robert_lp | 0:eedb7d567a5d | 53 | int32_t index; /* Index variables */ |
robert_lp | 0:eedb7d567a5d | 54 | q15_t a, b; /* Four nearest output values */ |
robert_lp | 0:eedb7d567a5d | 55 | q15_t fract; /* Temporary values for fractional values */ |
robert_lp | 0:eedb7d567a5d | 56 | |
robert_lp | 0:eedb7d567a5d | 57 | /* Calculate the nearest index */ |
robert_lp | 0:eedb7d567a5d | 58 | index = (uint32_t)x >> FAST_MATH_Q15_SHIFT; |
robert_lp | 0:eedb7d567a5d | 59 | |
robert_lp | 0:eedb7d567a5d | 60 | /* Calculation of fractional value */ |
robert_lp | 0:eedb7d567a5d | 61 | fract = (x - (index << FAST_MATH_Q15_SHIFT)) << 9; |
robert_lp | 0:eedb7d567a5d | 62 | |
robert_lp | 0:eedb7d567a5d | 63 | /* Read two nearest values of input value from the sin table */ |
robert_lp | 0:eedb7d567a5d | 64 | a = sinTable_q15[index]; |
robert_lp | 0:eedb7d567a5d | 65 | b = sinTable_q15[index+1]; |
robert_lp | 0:eedb7d567a5d | 66 | |
robert_lp | 0:eedb7d567a5d | 67 | /* Linear interpolation process */ |
robert_lp | 0:eedb7d567a5d | 68 | sinVal = (q31_t)(0x8000-fract)*a >> 16; |
robert_lp | 0:eedb7d567a5d | 69 | sinVal = (q15_t)((((q31_t)sinVal << 16) + ((q31_t)fract*b)) >> 16); |
robert_lp | 0:eedb7d567a5d | 70 | |
robert_lp | 0:eedb7d567a5d | 71 | return sinVal << 1; |
robert_lp | 0:eedb7d567a5d | 72 | } |
robert_lp | 0:eedb7d567a5d | 73 | |
robert_lp | 0:eedb7d567a5d | 74 | /** |
robert_lp | 0:eedb7d567a5d | 75 | * @} end of sin group |
robert_lp | 0:eedb7d567a5d | 76 | */ |
robert_lp | 0:eedb7d567a5d | 77 |