Aded CMSIS5 DSP and NN folder. Needs some work
Embed:
(wiki syntax)
Show/hide line numbers
arm_sin_f32.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_sin_f32.c 00004 * Description: Fast sine calculation for floating-point values 00005 * 00006 * $Date: 27. January 2017 00007 * $Revision: V.1.5.1 00008 * 00009 * Target Processor: Cortex-M cores 00010 * -------------------------------------------------------------------- */ 00011 /* 00012 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 00013 * 00014 * SPDX-License-Identifier: Apache-2.0 00015 * 00016 * Licensed under the Apache License, Version 2.0 (the License); you may 00017 * not use this file except in compliance with the License. 00018 * You may obtain a copy of the License at 00019 * 00020 * www.apache.org/licenses/LICENSE-2.0 00021 * 00022 * Unless required by applicable law or agreed to in writing, software 00023 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00024 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00025 * See the License for the specific language governing permissions and 00026 * limitations under the License. 00027 */ 00028 00029 #include "arm_math.h" 00030 #include "arm_common_tables.h" 00031 #include <math.h> 00032 00033 /** 00034 * @ingroup groupFastMath 00035 */ 00036 00037 /** 00038 * @defgroup sin Sine 00039 * 00040 * Computes the trigonometric sine function using a combination of table lookup 00041 * and linear interpolation. There are separate functions for 00042 * Q15, Q31, and floating-point data types. 00043 * The input to the floating-point version is in radians and in the range [0 2*pi) while the 00044 * fixed-point Q15 and Q31 have a scaled input with the range 00045 * [0 +0.9999] mapping to [0 2*pi). The fixed-point range is chosen so that a 00046 * value of 2*pi wraps around to 0. 00047 * 00048 * The implementation is based on table lookup using 256 values together with linear interpolation. 00049 * The steps used are: 00050 * -# Calculation of the nearest integer table index 00051 * -# Compute the fractional portion (fract) of the table index. 00052 * -# The final result equals <code>(1.0f-fract)*a + fract*b;</code> 00053 * 00054 * where 00055 * <pre> 00056 * b=Table[index+0]; 00057 * c=Table[index+1]; 00058 * </pre> 00059 */ 00060 00061 /** 00062 * @addtogroup sin 00063 * @{ 00064 */ 00065 00066 /** 00067 * @brief Fast approximation to the trigonometric sine function for floating-point data. 00068 * @param[in] x input value in radians. 00069 * @return sin(x). 00070 */ 00071 00072 float32_t arm_sin_f32( 00073 float32_t x) 00074 { 00075 float32_t sinVal, fract, in; /* Temporary variables for input, output */ 00076 uint16_t index; /* Index variable */ 00077 float32_t a, b; /* Two nearest output values */ 00078 int32_t n; 00079 float32_t findex; 00080 00081 /* Special case for small negative inputs */ 00082 if ((x < 0.0f) && (x >= -1.9e-7f)) { 00083 return x; 00084 } 00085 00086 /* input x is in radians */ 00087 /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi */ 00088 in = x * 0.159154943092f; 00089 00090 /* Calculation of floor value of input */ 00091 n = (int32_t) in; 00092 00093 /* Make negative values towards -infinity */ 00094 if (x < 0.0f) 00095 { 00096 n--; 00097 } 00098 00099 /* Map input value to [0 1] */ 00100 in = in - (float32_t) n; 00101 00102 /* Calculation of index of the table */ 00103 findex = (float32_t) FAST_MATH_TABLE_SIZE * in; 00104 00105 index = ((uint16_t)findex) & 0x1ff; 00106 00107 /* fractional value calculation */ 00108 fract = findex - (float32_t) index; 00109 00110 /* Read two nearest values of input value from the sin table */ 00111 a = sinTable_f32[index]; 00112 b = sinTable_f32[index+1]; 00113 00114 /* Linear interpolation process */ 00115 sinVal = (1.0f-fract)*a + fract*b; 00116 00117 /* Return the output value */ 00118 return (sinVal); 00119 } 00120 00121 /** 00122 * @} end of sin group 00123 */ 00124
Generated on Tue Jul 12 2022 16:47:28 by 1.7.2