1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_fir_decimate_init_q15.c
4 * Description: Initialization function for the Q15 FIR Decimator
5 *
6 * $Date: 23 April 2021
7 * $Revision: V1.9.0
8 *
9 * Target Processor: Cortex-M and Cortex-A cores
10 * -------------------------------------------------------------------- */
11 /*
12 * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
13 *
14 * SPDX-License-Identifier: Apache-2.0
15 *
16 * Licensed under the Apache License, Version 2.0 (the License); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
28
29 #include "dsp/filtering_functions.h"
30
31 /**
32 @ingroup groupFilters
33 */
34
35 /**
36 @addtogroup FIR_decimate
37 @{
38 */
39
40 /**
41 @brief Initialization function for the Q15 FIR decimator.
42 @param[in,out] S points to an instance of the Q15 FIR decimator structure
43 @param[in] numTaps number of coefficients in the filter
44 @param[in] M decimation factor
45 @param[in] pCoeffs points to the filter coefficients
46 @param[in] pState points to the state buffer
47 @param[in] blockSize number of input samples to process
48 @return execution status
49 - \ref ARM_MATH_SUCCESS : Operation successful
50 - \ref ARM_MATH_LENGTH_ERROR : <code>blockSize</code> is not a multiple of <code>M</code>
51
52 @par Details
53 <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order:
54 <pre>
55 {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
56 </pre>
57 @par
58 <code>pState</code> points to the array of state variables.
59 <code>pState</code> is of length <code>numTaps+blockSize-1</code> words where <code>blockSize</code> is the number of input samples
60 to the call <code>arm_fir_decimate_q15()</code>.
61 <code>M</code> is the decimation factor.
62 */
63
arm_fir_decimate_init_q15(arm_fir_decimate_instance_q15 * S,uint16_t numTaps,uint8_t M,const q15_t * pCoeffs,q15_t * pState,uint32_t blockSize)64 ARM_DSP_ATTRIBUTE arm_status arm_fir_decimate_init_q15(
65 arm_fir_decimate_instance_q15 * S,
66 uint16_t numTaps,
67 uint8_t M,
68 const q15_t * pCoeffs,
69 q15_t * pState,
70 uint32_t blockSize)
71 {
72 arm_status status;
73
74 /* The size of the input block must be a multiple of the decimation factor */
75 if ((blockSize % M) != 0U)
76 {
77 /* Set status as ARM_MATH_LENGTH_ERROR */
78 status = ARM_MATH_LENGTH_ERROR;
79 }
80 else
81 {
82 /* Assign filter taps */
83 S->numTaps = numTaps;
84
85 /* Assign coefficient pointer */
86 S->pCoeffs = pCoeffs;
87
88 /* Clear the state buffer. The size is always (blockSize + numTaps - 1) */
89 memset(pState, 0, (numTaps + (blockSize - 1U)) * sizeof(q15_t));
90
91 /* Assign state pointer */
92 S->pState = pState;
93
94 /* Assign Decimation Factor */
95 S->M = M;
96
97 status = ARM_MATH_SUCCESS;
98 }
99
100 return (status);
101
102 }
103
104 /**
105 @} end of FIR_decimate group
106 */
107