V4.0.1 of the ARM CMSIS DSP libraries. Note that arm_bitreversal2.s, arm_cfft_f32.c and arm_rfft_fast_f32.c had to be removed. arm_bitreversal2.s will not assemble with the online tools. So, the fast f32 FFT functions are not yet available. All the other FFT functions are available.
Dependents: MPU9150_Example fir_f32 fir_f32 MPU9150_nucleo_noni2cdev ... more
arm_sin_f32.c
00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 12. March 2014 00005 * $Revision: V1.4.3 00006 * 00007 * Project: CMSIS DSP Library 00008 * Title: arm_sin_f32.c 00009 * 00010 * Description: Fast sine calculation for floating-point values. 00011 * 00012 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 00013 * 00014 * Redistribution and use in source and binary forms, with or without 00015 * modification, are permitted provided that the following conditions 00016 * are met: 00017 * - Redistributions of source code must retain the above copyright 00018 * notice, this list of conditions and the following disclaimer. 00019 * - Redistributions in binary form must reproduce the above copyright 00020 * notice, this list of conditions and the following disclaimer in 00021 * the documentation and/or other materials provided with the 00022 * distribution. 00023 * - Neither the name of ARM LIMITED nor the names of its contributors 00024 * may be used to endorse or promote products derived from this 00025 * software without specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00028 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00029 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00030 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00031 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00032 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00033 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00034 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00035 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00036 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00037 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00038 * POSSIBILITY OF SUCH DAMAGE. 00039 * -------------------------------------------------------------------- */ 00040 00041 #include "arm_math.h" 00042 #include "arm_common_tables.h" 00043 00044 /** 00045 * @ingroup groupFastMath 00046 */ 00047 00048 /** 00049 * @defgroup sin Sine 00050 * 00051 * Computes the trigonometric sine function using a combination of table lookup 00052 * and cubic interpolation. There are separate functions for 00053 * Q15, Q31, and floating-point data types. 00054 * The input to the floating-point version is in radians while the 00055 * fixed-point Q15 and Q31 have a scaled input with the range 00056 * [0 +0.9999] mapping to [0 2*pi). The fixed-point range is chosen so that a 00057 * value of 2*pi wraps around to 0. 00058 * 00059 * The implementation is based on table lookup using 256 values together with cubic interpolation. 00060 * The steps used are: 00061 * -# Calculation of the nearest integer table index 00062 * -# Fetch the four table values a, b, c, and d 00063 * -# Compute the fractional portion (fract) of the table index. 00064 * -# Calculation of wa, wb, wc, wd 00065 * -# The final result equals <code>a*wa + b*wb + c*wc + d*wd</code> 00066 * 00067 * where 00068 * <pre> 00069 * a=Table[index-1]; 00070 * b=Table[index+0]; 00071 * c=Table[index+1]; 00072 * d=Table[index+2]; 00073 * </pre> 00074 * and 00075 * <pre> 00076 * wa=-(1/6)*fract.^3 + (1/2)*fract.^2 - (1/3)*fract; 00077 * wb=(1/2)*fract.^3 - fract.^2 - (1/2)*fract + 1; 00078 * wc=-(1/2)*fract.^3+(1/2)*fract.^2+fract; 00079 * wd=(1/6)*fract.^3 - (1/6)*fract; 00080 * </pre> 00081 */ 00082 00083 /** 00084 * @addtogroup sin 00085 * @{ 00086 */ 00087 00088 /** 00089 * @brief Fast approximation to the trigonometric sine function for floating-point data. 00090 * @param[in] x input value in radians. 00091 * @return sin(x). 00092 */ 00093 00094 float32_t arm_sin_f32( 00095 float32_t x) 00096 { 00097 float32_t sinVal, fract, in; /* Temporary variables for input, output */ 00098 uint16_t index; /* Index variable */ 00099 float32_t a, b; /* Two nearest output values */ 00100 int32_t n; 00101 float32_t findex; 00102 00103 /* input x is in radians */ 00104 /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi */ 00105 in = x * 0.159154943092f; 00106 00107 /* Calculation of floor value of input */ 00108 n = (int32_t) in; 00109 00110 /* Make negative values towards -infinity */ 00111 if(x < 0.0f) 00112 { 00113 n--; 00114 } 00115 00116 /* Map input value to [0 1] */ 00117 in = in - (float32_t) n; 00118 00119 /* Calculation of index of the table */ 00120 findex = (float32_t) FAST_MATH_TABLE_SIZE * in; 00121 index = ((uint16_t)findex) & 0x1ff; 00122 00123 /* fractional value calculation */ 00124 fract = findex - (float32_t) index; 00125 00126 /* Read two nearest values of input value from the sin table */ 00127 a = sinTable_f32[index]; 00128 b = sinTable_f32[index+1]; 00129 00130 /* Linear interpolation process */ 00131 sinVal = (1.0f-fract)*a + fract*b; 00132 00133 /* Return the output value */ 00134 return (sinVal); 00135 } 00136 00137 /** 00138 * @} end of sin group 00139 */
Generated on Tue Jul 12 2022 19:48:45 by 1.7.2