1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_fir_interpolate_init_q31.c
4 * Description: Q31 FIR interpolator initialization function
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_Interpolate
37 @{
38 */
39
40 /**
41 @brief Initialization function for the Q31 FIR interpolator.
42 @param[in,out] S points to an instance of the Q31 FIR interpolator structure
43 @param[in] L upsample factor
44 @param[in] numTaps number of filter coefficients in the filter
45 @param[in] pCoeffs points to the filter coefficient buffer
46 @param[in] pState points to the state buffer
47 @param[in] blockSize number of input samples to process per call
48 @return execution status
49 - \ref ARM_MATH_SUCCESS : Operation successful
50 - \ref ARM_MATH_ARGUMENT_ERROR : filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</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[numTaps-2], ..., b[1], b[0]}
56 </pre>
57 The length of the filter <code>numTaps</code> must be a multiple of the interpolation factor <code>L</code>.
58 @par
59 <code>pState</code> points to the array of state variables.
60 <code>pState</code> is of length <code>(numTaps/L)+blockSize-1</code> words
61 where <code>blockSize</code> is the number of input samples processed by each call to <code>arm_fir_interpolate_q31()</code>.
62 */
63
arm_fir_interpolate_init_q31(arm_fir_interpolate_instance_q31 * S,uint8_t L,uint16_t numTaps,const q31_t * pCoeffs,q31_t * pState,uint32_t blockSize)64 arm_status arm_fir_interpolate_init_q31(
65 arm_fir_interpolate_instance_q31 * S,
66 uint8_t L,
67 uint16_t numTaps,
68 const q31_t * pCoeffs,
69 q31_t * pState,
70 uint32_t blockSize)
71 {
72 arm_status status;
73
74 /* The filter length must be a multiple of the interpolation factor */
75 if ((numTaps % L) != 0U)
76 {
77 /* Set status as ARM_MATH_LENGTH_ERROR */
78 status = ARM_MATH_LENGTH_ERROR;
79 }
80 else
81 {
82 /* Assign coefficient pointer */
83 S->pCoeffs = pCoeffs;
84
85 /* Assign Interpolation factor */
86 S->L = L;
87
88 /* Assign polyPhaseLength */
89 S->phaseLength = numTaps / L;
90
91 /* Clear state buffer and size of buffer is always phaseLength + blockSize - 1 */
92 memset(pState, 0, (blockSize + ((uint32_t) S->phaseLength - 1U)) * sizeof(q31_t));
93
94 /* Assign state pointer */
95 S->pState = pState;
96
97 status = ARM_MATH_SUCCESS;
98 }
99
100 return (status);
101 }
102
103 /**
104 @} end of FIR_Interpolate group
105 */
106