]> git.gag.com Git - fw/stlink/blob - exampleF4/CMSIS/DSP_Lib/Source/FilteringFunctions/arm_fir_init_q15.c
Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / FilteringFunctions / arm_fir_init_q15.c
1 /* ----------------------------------------------------------------------   
2 * Copyright (C) 2010 ARM Limited. All rights reserved.   
3 *   
4 * $Date:        15. July 2011  
5 * $Revision:    V1.0.10  
6 *   
7 * Project:          CMSIS DSP Library   
8 * Title:        arm_fir_init_q15.c   
9 *   
10 * Description:  Q15 FIR filter initialization function.   
11 *   
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
13 *  
14 * Version 1.0.10 2011/7/15 
15 *    Big Endian support added and Merged M0 and M3/M4 Source code.  
16 *   
17 * Version 1.0.3 2010/11/29  
18 *    Re-organized the CMSIS folders and updated documentation.   
19 *    
20 * Version 1.0.2 2010/11/11   
21 *    Documentation updated.    
22 *   
23 * Version 1.0.1 2010/10/05    
24 *    Production release and review comments incorporated.   
25 *   
26 * Version 1.0.0 2010/09/20    
27 *    Production release and review comments incorporated.   
28 *   
29 * Version 0.0.5  2010/04/26    
30 *        incorporated review comments and updated with latest CMSIS layer   
31 *   
32 * Version 0.0.3  2010/03/10    
33 *    Initial version   
34 * ------------------------------------------------------------------- */
35
36 #include "arm_math.h"
37
38 /**   
39  * @ingroup groupFilters   
40  */
41
42 /**   
43  * @addtogroup FIR   
44  * @{   
45  */
46
47 /**   
48  * @param[in,out]  *S points to an instance of the Q15 FIR filter structure.   
49  * @param[in]      numTaps  Number of filter coefficients in the filter. Must be even and greater than or equal to 4.   
50  * @param[in]      *pCoeffs points to the filter coefficients buffer.   
51  * @param[in]      *pState points to the state buffer.   
52  * @param[in]      blockSize is number of samples processed per call.   
53  * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if   
54  * <code>numTaps</code> is not greater than or equal to 4 and even.   
55  *   
56  * <b>Description:</b>   
57  * \par   
58  * <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order:   
59  * <pre>   
60  *    {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}   
61  * </pre>   
62  * Note that <code>numTaps</code> must be even and greater than or equal to 4.   
63  * To implement an odd length filter simply increase <code>numTaps</code> by 1 and set the last coefficient to zero.   
64  * For example, to implement a filter with <code>numTaps=3</code> and coefficients   
65  * <pre>   
66  *     {0.3, -0.8, 0.3}   
67  * </pre>   
68  * set <code>numTaps=4</code> and use the coefficients:   
69  * <pre>   
70  *     {0.3, -0.8, 0.3, 0}.   
71  * </pre>   
72  * Similarly, to implement a two point filter   
73  * <pre>   
74  *     {0.3, -0.3}   
75  * </pre>   
76  * set <code>numTaps=4</code> and use the coefficients:   
77  * <pre>   
78  *     {0.3, -0.3, 0, 0}.   
79  * </pre>   
80  * \par   
81  * <code>pState</code> points to the array of state variables.   
82  * <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>.   
83  */
84
85 arm_status arm_fir_init_q15(
86   arm_fir_instance_q15 * S,
87   uint16_t numTaps,
88   q15_t * pCoeffs,
89   q15_t * pState,
90   uint32_t blockSize)
91 {
92   arm_status status;
93
94
95 #ifndef ARM_MATH_CM0
96
97   /* Run the below code for Cortex-M4 and Cortex-M3 */
98
99   /* The Number of filter coefficients in the filter must be even and at least 4 */
100   if((numTaps < 4u) || (numTaps & 0x1u))
101   {
102     status = ARM_MATH_ARGUMENT_ERROR;
103   }
104   else
105   {
106     /* Assign filter taps */
107     S->numTaps = numTaps;
108
109     /* Assign coefficient pointer */
110     S->pCoeffs = pCoeffs;
111
112     /* Clear the state buffer.  The size is always (blockSize + numTaps - 1) */
113     memset(pState, 0, (numTaps + (blockSize - 1u)) * sizeof(q15_t));
114
115     /* Assign state pointer */
116     S->pState = pState;
117
118     status = ARM_MATH_SUCCESS;
119   }
120
121   return (status);
122
123 #else
124
125   /* Run the below code for Cortex-M0 */
126
127   /* Assign filter taps */
128   S->numTaps = numTaps;
129
130   /* Assign coefficient pointer */
131   S->pCoeffs = pCoeffs;
132
133   /* Clear the state buffer.  The size is always (blockSize + numTaps - 1) */
134   memset(pState, 0, (numTaps + (blockSize - 1u)) * sizeof(q15_t));
135
136   /* Assign state pointer */
137   S->pState = pState;
138
139   status = ARM_MATH_SUCCESS;
140
141   return (status);
142
143 #endif /*  #ifndef ARM_MATH_CM0 */
144
145 }
146
147 /**   
148  * @} end of FIR group   
149  */