1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
7 * Project: CMSIS DSP Library
8 * Title: arm_fir_init_q15.c
10 * Description: Q15 FIR filter initialization function.
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 * Version 1.0.10 2011/7/15
15 * Big Endian support added and Merged M0 and M3/M4 Source code.
17 * Version 1.0.3 2010/11/29
18 * Re-organized the CMSIS folders and updated documentation.
20 * Version 1.0.2 2010/11/11
21 * Documentation updated.
23 * Version 1.0.1 2010/10/05
24 * Production release and review comments incorporated.
26 * Version 1.0.0 2010/09/20
27 * Production release and review comments incorporated.
29 * Version 0.0.5 2010/04/26
30 * incorporated review comments and updated with latest CMSIS layer
32 * Version 0.0.3 2010/03/10
34 * ------------------------------------------------------------------- */
39 * @ingroup groupFilters
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.
58 * <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order:
60 * {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
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
68 * set <code>numTaps=4</code> and use the coefficients:
70 * {0.3, -0.8, 0.3, 0}.
72 * Similarly, to implement a two point filter
76 * set <code>numTaps=4</code> and use the coefficients:
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>.
85 arm_status arm_fir_init_q15(
86 arm_fir_instance_q15 * S,
97 /* Run the below code for Cortex-M4 and Cortex-M3 */
99 /* The Number of filter coefficients in the filter must be even and at least 4 */
100 if((numTaps < 4u) || (numTaps & 0x1u))
102 status = ARM_MATH_ARGUMENT_ERROR;
106 /* Assign filter taps */
107 S->numTaps = numTaps;
109 /* Assign coefficient pointer */
110 S->pCoeffs = pCoeffs;
112 /* Clear the state buffer. The size is always (blockSize + numTaps - 1) */
113 memset(pState, 0, (numTaps + (blockSize - 1u)) * sizeof(q15_t));
115 /* Assign state pointer */
118 status = ARM_MATH_SUCCESS;
125 /* Run the below code for Cortex-M0 */
127 /* Assign filter taps */
128 S->numTaps = numTaps;
130 /* Assign coefficient pointer */
131 S->pCoeffs = pCoeffs;
133 /* Clear the state buffer. The size is always (blockSize + numTaps - 1) */
134 memset(pState, 0, (numTaps + (blockSize - 1u)) * sizeof(q15_t));
136 /* Assign state pointer */
139 status = ARM_MATH_SUCCESS;
143 #endif /* #ifndef ARM_MATH_CM0 */
148 * @} end of FIR group