1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_fir_interpolate_init_q15.c
4 * Description: Q15 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 Q15 FIR interpolator.
42 @param[in,out] S points to an instance of the Q15 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
53 @par Details
54 <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order:
55 <pre>
56 {b[numTaps-1], b[numTaps-2], b[numTaps-2], ..., b[1], b[0]}
57 </pre>
58 The length of the filter <code>numTaps</code> must be a multiple of the interpolation factor <code>L</code>.
59 @par
60 <code>pState</code> points to the array of state variables.
61 <code>pState</code> is of length <code>(numTaps/L)+blockSize-1</code> words
62 where <code>blockSize</code> is the number of input samples processed by each call to <code>arm_fir_interpolate_q15()</code>.
63 */
64
arm_fir_interpolate_init_q15(arm_fir_interpolate_instance_q15 * S,uint8_t L,uint16_t numTaps,const q15_t * pCoeffs,q15_t * pState,uint32_t blockSize)65 ARM_DSP_ATTRIBUTE arm_status arm_fir_interpolate_init_q15(
66 arm_fir_interpolate_instance_q15 * S,
67 uint8_t L,
68 uint16_t numTaps,
69 const q15_t * pCoeffs,
70 q15_t * pState,
71 uint32_t blockSize)
72 {
73 arm_status status;
74
75 /* The filter length must be a multiple of the interpolation factor */
76 if ((numTaps % L) != 0U)
77 {
78 /* Set status as ARM_MATH_LENGTH_ERROR */
79 status = ARM_MATH_LENGTH_ERROR;
80 }
81 else
82 {
83 /* Assign coefficient pointer */
84 S->pCoeffs = pCoeffs;
85
86 /* Assign Interpolation factor */
87 S->L = L;
88
89 /* Assign polyPhaseLength */
90 S->phaseLength = numTaps / L;
91
92 /* Clear state buffer and size of buffer is always phaseLength + blockSize - 1 */
93 memset(pState, 0, (blockSize + ((uint32_t) S->phaseLength - 1U)) * sizeof(q15_t));
94
95 /* Assign state pointer */
96 S->pState = pState;
97
98 status = ARM_MATH_SUCCESS;
99 }
100
101 return (status);
102 }
103
104 /**
105 @} end of FIR_Interpolate group
106 */
107