1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_fir_decimate_init_q31.c
4  * Description:  Initialization function for Q31 FIR Decimation filter
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 Q31 FIR decimator.
42   @param[in,out] S          points to an instance of the Q31 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 passed to <code>arm_fir_decimate_q31()</code>.
60                    <code>M</code> is the decimation factor.
61  */
62 
arm_fir_decimate_init_q31(arm_fir_decimate_instance_q31 * S,uint16_t numTaps,uint8_t M,const q31_t * pCoeffs,q31_t * pState,uint32_t blockSize)63 ARM_DSP_ATTRIBUTE arm_status arm_fir_decimate_init_q31(
64         arm_fir_decimate_instance_q31 * S,
65         uint16_t numTaps,
66         uint8_t M,
67   const q31_t * pCoeffs,
68         q31_t * pState,
69         uint32_t blockSize)
70 {
71   arm_status status;
72 
73   /* The size of the input block must be a multiple of the decimation factor */
74   if ((blockSize % M) != 0U)
75   {
76     /* Set status as ARM_MATH_LENGTH_ERROR */
77     status = ARM_MATH_LENGTH_ERROR;
78   }
79   else
80   {
81     /* Assign filter taps */
82     S->numTaps = numTaps;
83 
84     /* Assign coefficient pointer */
85     S->pCoeffs = pCoeffs;
86 
87     /* Clear the state buffer. The size is always (blockSize + numTaps - 1) */
88     memset(pState, 0, (numTaps + (blockSize - 1U)) * sizeof(q31_t));
89 
90     /* Assign state pointer */
91     S->pState = pState;
92 
93     /* Assign Decimation Factor */
94     S->M = M;
95 
96     status = ARM_MATH_SUCCESS;
97   }
98 
99   return (status);
100 
101 }
102 
103 /**
104   @} end of FIR_decimate group
105  */
106