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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_cos_f32.c Source File

arm_cos_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_cos_f32.c    
00009 *    
00010 * Description:  Fast cosine 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  * @ingroup groupFastMath    
00045  */
00046 
00047 /**    
00048  * @defgroup cos Cosine    
00049  *    
00050  * Computes the trigonometric cosine function using a combination of table lookup   
00051  * and cubic interpolation.  There are separate functions for   
00052  * Q15, Q31, and floating-point data types.   
00053  * The input to the floating-point version is in radians while the   
00054  * fixed-point Q15 and Q31 have a scaled input with the range   
00055  * [0 +0.9999] mapping to [0 2*pi).  The fixed-point range is chosen so that a
00056  * value of 2*pi wraps around to 0.
00057  *   
00058  * The implementation is based on table lookup using 256 values together with cubic interpolation.   
00059  * The steps used are:   
00060  *  -# Calculation of the nearest integer table index   
00061  *  -# Fetch the four table values a, b, c, and d     
00062  *  -# Compute the fractional portion (fract) of the table index.   
00063  *  -# Calculation of wa, wb, wc, wd    
00064  *  -# The final result equals <code>a*wa + b*wb + c*wc + d*wd</code>   
00065  *   
00066  * where   
00067  * <pre>    
00068  *    a=Table[index-1];    
00069  *    b=Table[index+0];    
00070  *    c=Table[index+1];    
00071  *    d=Table[index+2];    
00072  * </pre>   
00073  * and   
00074  * <pre>    
00075  *    wa=-(1/6)*fract.^3 + (1/2)*fract.^2 - (1/3)*fract;    
00076  *    wb=(1/2)*fract.^3 - fract.^2 - (1/2)*fract + 1;    
00077  *    wc=-(1/2)*fract.^3+(1/2)*fract.^2+fract;    
00078  *    wd=(1/6)*fract.^3 - (1/6)*fract;    
00079  * </pre>    
00080  */
00081 
00082  /**    
00083  * @addtogroup cos    
00084  * @{    
00085  */
00086 
00087 /**   
00088  * @brief  Fast approximation to the trigonometric cosine function for floating-point data.   
00089  * @param[in] x input value in radians.   
00090  * @return cos(x).   
00091  */
00092 
00093 float32_t arm_cos_f32(
00094   float32_t x)
00095 {
00096   float32_t cosVal, fract, in;                   /* Temporary variables for input, output */
00097   uint16_t index;                                /* Index variable */
00098   float32_t a, b;                                /* Two nearest output values */
00099   int32_t n;
00100   float32_t findex;
00101 
00102   /* input x is in radians */
00103   /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi, add 0.25 (pi/2) to read sine table */
00104   in = x * 0.159154943092f + 0.25f;
00105 
00106   /* Calculation of floor value of input */
00107   n = (int32_t) in;
00108 
00109   /* Make negative values towards -infinity */
00110   if(in < 0.0f)
00111   {
00112     n--;
00113   }
00114 
00115   /* Map input value to [0 1] */
00116   in = in - (float32_t) n;
00117 
00118   /* Calculation of index of the table */
00119   findex = (float32_t) FAST_MATH_TABLE_SIZE * in;
00120   index = ((uint16_t)findex) & 0x1ff;
00121 
00122   /* fractional value calculation */
00123   fract = findex - (float32_t) index;
00124 
00125   /* Read two nearest values of input value from the cos table */
00126   a = sinTable_f32[index];
00127   b = sinTable_f32[index+1];
00128 
00129   /* Linear interpolation process */
00130   cosVal = (1.0f-fract)*a + fract*b;
00131 
00132   /* Return the output value */
00133   return (cosVal);
00134 }
00135 
00136 /**    
00137  * @} end of cos group    
00138  */