Robert Lopez / CMSIS5
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_fir_decimate_init_q31.c Source File

arm_fir_decimate_init_q31.c

00001 /* ----------------------------------------------------------------------
00002  * Project:      CMSIS DSP Library
00003  * Title:        arm_fir_decimate_init_q31.c
00004  * Description:  Initialization function for Q31 FIR Decimation filter
00005  *
00006  * $Date:        27. January 2017
00007  * $Revision:    V.1.5.1
00008  *
00009  * Target Processor: Cortex-M cores
00010  * -------------------------------------------------------------------- */
00011 /*
00012  * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
00013  *
00014  * SPDX-License-Identifier: Apache-2.0
00015  *
00016  * Licensed under the Apache License, Version 2.0 (the License); you may
00017  * not use this file except in compliance with the License.
00018  * You may obtain a copy of the License at
00019  *
00020  * www.apache.org/licenses/LICENSE-2.0
00021  *
00022  * Unless required by applicable law or agreed to in writing, software
00023  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00024  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00025  * See the License for the specific language governing permissions and
00026  * limitations under the License.
00027  */
00028 
00029 #include "arm_math.h"
00030 
00031 /**
00032  * @ingroup groupFilters
00033  */
00034 
00035 /**
00036  * @addtogroup FIR_decimate
00037  * @{
00038  */
00039 
00040 /**
00041  * @brief  Initialization function for the Q31 FIR decimator.
00042  * @param[in,out] *S points to an instance of the Q31 FIR decimator structure.
00043  * @param[in] numTaps  number of coefficients in the filter.
00044  * @param[in] M  decimation factor.
00045  * @param[in] *pCoeffs points to the filter coefficients.
00046  * @param[in] *pState points to the state buffer.
00047  * @param[in] blockSize number of input samples to process per call.
00048  * @return    The function returns ARM_MATH_SUCCESS if initialization was successful or ARM_MATH_LENGTH_ERROR if
00049  * <code>blockSize</code> is not a multiple of <code>M</code>.
00050  *
00051  * <b>Description:</b>
00052  * \par
00053  * <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order:
00054  * <pre>
00055  *    {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
00056  * </pre>
00057  * \par
00058  * <code>pState</code> points to the array of state variables.
00059  * <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>.
00060  * <code>M</code> is the decimation factor.
00061  */
00062 
00063 arm_status arm_fir_decimate_init_q31(
00064   arm_fir_decimate_instance_q31 * S,
00065   uint16_t numTaps,
00066   uint8_t M,
00067   q31_t * pCoeffs,
00068   q31_t * pState,
00069   uint32_t blockSize)
00070 {
00071   arm_status status;
00072 
00073   /* The size of the input block must be a multiple of the decimation factor */
00074   if ((blockSize % M) != 0U)
00075   {
00076     /* Set status as ARM_MATH_LENGTH_ERROR */
00077     status = ARM_MATH_LENGTH_ERROR;
00078   }
00079   else
00080   {
00081     /* Assign filter taps */
00082     S->numTaps = numTaps;
00083 
00084     /* Assign coefficient pointer */
00085     S->pCoeffs = pCoeffs;
00086 
00087     /* Clear the state buffer.  The size is always (blockSize + numTaps - 1) */
00088     memset(pState, 0, (numTaps + (blockSize - 1)) * sizeof(q31_t));
00089 
00090     /* Assign state pointer */
00091     S->pState = pState;
00092 
00093     /* Assign Decimation factor */
00094     S->M = M;
00095 
00096     status = ARM_MATH_SUCCESS;
00097   }
00098 
00099   return (status);
00100 
00101 }
00102 
00103 /**
00104  * @} end of FIR_decimate group
00105  */
00106