CMSIS DSP Library from CMSIS 2.0. See http://www.onarm.com/cmsis/ for full details

Dependents:   K22F_DSP_Matrix_least_square BNO055-ELEC3810 1BNO055 ECE4180Project--Slave2 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_fir_init_q15.c Source File

arm_fir_init_q15.c

00001 /* ----------------------------------------------------------------------  
00002 * Copyright (C) 2010 ARM Limited. All rights reserved.  
00003 *  
00004 * $Date:        29. November 2010  
00005 * $Revision:    V1.0.3  
00006 *  
00007 * Project:      CMSIS DSP Library  
00008 * Title:        arm_fir_init_q15.c  
00009 *  
00010 * Description:  Q15 FIR filter initialization function.  
00011 *  
00012 * Target Processor: Cortex-M4/Cortex-M3
00013 *  
00014 * Version 1.0.3 2010/11/29 
00015 *    Re-organized the CMSIS folders and updated documentation.  
00016 *   
00017 * Version 1.0.2 2010/11/11  
00018 *    Documentation updated.   
00019 *  
00020 * Version 1.0.1 2010/10/05   
00021 *    Production release and review comments incorporated.  
00022 *  
00023 * Version 1.0.0 2010/09/20   
00024 *    Production release and review comments incorporated.  
00025 *  
00026 * Version 0.0.5  2010/04/26   
00027 *    incorporated review comments and updated with latest CMSIS layer  
00028 *  
00029 * Version 0.0.3  2010/03/10   
00030 *    Initial version  
00031 * ------------------------------------------------------------------- */ 
00032  
00033 #include "arm_math.h" 
00034  
00035 /**  
00036  * @ingroup groupFilters  
00037  */ 
00038  
00039 /**  
00040  * @addtogroup FIR  
00041  * @{  
00042  */ 
00043  
00044 /**  
00045  * @param[in,out]  *S points to an instance of the Q15 FIR filter structure.  
00046  * @param[in]      numTaps  Number of filter coefficients in the filter. Must be even and greater than or equal to 4.  
00047  * @param[in]      *pCoeffs points to the filter coefficients buffer.  
00048  * @param[in]      *pState points to the state buffer.  
00049  * @param[in]      blockSize is number of samples processed per call.  
00050  * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if  
00051  * <code>numTaps</code> is not greater than or equal to 4 and even.  
00052  *  
00053  * <b>Description:</b>  
00054  * \par  
00055  * <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order:  
00056  * <pre>  
00057  *    {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}  
00058  * </pre>  
00059  * Note that <code>numTaps</code> must be even and greater than or equal to 4.  
00060  * To implement an odd length filter simply increase <code>numTaps</code> by 1 and set the last coefficient to zero.  
00061  * For example, to implement a filter with <code>numTaps=3</code> and coefficients  
00062  * <pre>  
00063  *     {0.3, -0.8, 0.3}  
00064  * </pre>  
00065  * set <code>numTaps=4</code> and use the coefficients:  
00066  * <pre>  
00067  *     {0.3, -0.8, 0.3, 0}.  
00068  * </pre>  
00069  * Similarly, to implement a two point filter  
00070  * <pre>  
00071  *     {0.3, -0.3}  
00072  * </pre>  
00073  * set <code>numTaps=4</code> and use the coefficients:  
00074  * <pre>  
00075  *     {0.3, -0.3, 0, 0}.  
00076  * </pre>  
00077  * \par  
00078  * <code>pState</code> points to the array of state variables.  
00079  * <code>pState</code> is of length <code>numTaps+blockSize-1</code>, where <code>blockSize</code> is the number of input samples processed by each call to <code>arm_fir_q15()</code>.  
00080  */ 
00081  
00082 arm_status arm_fir_init_q15( 
00083   arm_fir_instance_q15 * S, 
00084   uint16_t numTaps, 
00085   q15_t * pCoeffs, 
00086   q15_t * pState, 
00087   uint32_t blockSize) 
00088 { 
00089   arm_status status; 
00090  
00091   /* The Number of filter coefficients in the filter must be even and at least 4 */ 
00092   if((numTaps < 4u) || (numTaps & 0x1u)) 
00093   { 
00094     status = ARM_MATH_ARGUMENT_ERROR; 
00095   } 
00096   else 
00097   { 
00098     /* Assign filter taps */ 
00099     S->numTaps = numTaps; 
00100  
00101     /* Assign coefficient pointer */ 
00102     S->pCoeffs = pCoeffs; 
00103  
00104     /* Clear the state buffer.  The size is always (blockSize + numTaps - 1) */ 
00105     memset(pState, 0, (numTaps + (blockSize - 1u)) * sizeof(q15_t)); 
00106  
00107     /* Assign state pointer */ 
00108     S->pState = pState; 
00109  
00110     status = ARM_MATH_SUCCESS; 
00111   } 
00112  
00113   return (status); 
00114 } 
00115  
00116 /**  
00117  * @} end of FIR group  
00118  */