Robert Lopez / CMSIS5
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_fir_init_q15.c Source File

arm_fir_init_q15.c

00001 /* ----------------------------------------------------------------------
00002  * Project:      CMSIS DSP Library
00003  * Title:        arm_fir_init_q15.c
00004  * Description:  Q15 FIR filter initialization function
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
00037  * @{
00038  */
00039 
00040 /**
00041  * @param[in,out]  *S points to an instance of the Q15 FIR filter structure.
00042  * @param[in]      numTaps  Number of filter coefficients in the filter. Must be even and greater than or equal to 4.
00043  * @param[in]      *pCoeffs points to the filter coefficients buffer.
00044  * @param[in]      *pState points to the state buffer.
00045  * @param[in]      blockSize is number of samples processed per call.
00046  * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if
00047  * <code>numTaps</code> is not greater than or equal to 4 and even.
00048  *
00049  * <b>Description:</b>
00050  * \par
00051  * <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order:
00052  * <pre>
00053  *    {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
00054  * </pre>
00055  * Note that <code>numTaps</code> must be even and greater than or equal to 4.
00056  * To implement an odd length filter simply increase <code>numTaps</code> by 1 and set the last coefficient to zero.
00057  * For example, to implement a filter with <code>numTaps=3</code> and coefficients
00058  * <pre>
00059  *     {0.3, -0.8, 0.3}
00060  * </pre>
00061  * set <code>numTaps=4</code> and use the coefficients:
00062  * <pre>
00063  *     {0.3, -0.8, 0.3, 0}.
00064  * </pre>
00065  * Similarly, to implement a two point filter
00066  * <pre>
00067  *     {0.3, -0.3}
00068  * </pre>
00069  * set <code>numTaps=4</code> and use the coefficients:
00070  * <pre>
00071  *     {0.3, -0.3, 0, 0}.
00072  * </pre>
00073  * \par
00074  * <code>pState</code> points to the array of state variables.
00075  * <code>pState</code> is of length <code>numTaps+blockSize</code>, when running on Cortex-M4 and Cortex-M3  and is of length <code>numTaps+blockSize-1</code>, when running on Cortex-M0 where <code>blockSize</code> is the number of input samples processed by each call to <code>arm_fir_q15()</code>.
00076  */
00077 
00078 arm_status arm_fir_init_q15(
00079   arm_fir_instance_q15 * S,
00080   uint16_t numTaps,
00081   q15_t * pCoeffs,
00082   q15_t * pState,
00083   uint32_t blockSize)
00084 {
00085   arm_status status;
00086 
00087 
00088 #if defined (ARM_MATH_DSP)
00089 
00090   /* Run the below code for Cortex-M4 and Cortex-M3 */
00091 
00092   /* The Number of filter coefficients in the filter must be even and at least 4 */
00093   if (numTaps & 0x1U)
00094   {
00095     status = ARM_MATH_ARGUMENT_ERROR;
00096   }
00097   else
00098   {
00099     /* Assign filter taps */
00100     S->numTaps = numTaps;
00101 
00102     /* Assign coefficient pointer */
00103     S->pCoeffs = pCoeffs;
00104 
00105     /* Clear the state buffer.  The size is always (blockSize + numTaps ) */
00106     memset(pState, 0, (numTaps + (blockSize)) * sizeof(q15_t));
00107 
00108     /* Assign state pointer */
00109     S->pState = pState;
00110 
00111     status = ARM_MATH_SUCCESS;
00112   }
00113 
00114   return (status);
00115 
00116 #else
00117 
00118   /* Run the below code for Cortex-M0 */
00119 
00120   /* Assign filter taps */
00121   S->numTaps = numTaps;
00122 
00123   /* Assign coefficient pointer */
00124   S->pCoeffs = pCoeffs;
00125 
00126   /* Clear the state buffer.  The size is always (blockSize + numTaps - 1) */
00127   memset(pState, 0, (numTaps + (blockSize - 1U)) * sizeof(q15_t));
00128 
00129   /* Assign state pointer */
00130   S->pState = pState;
00131 
00132   status = ARM_MATH_SUCCESS;
00133 
00134   return (status);
00135 
00136 #endif /*  #if defined (ARM_MATH_DSP) */
00137 
00138 }
00139 
00140 /**
00141  * @} end of FIR group
00142  */
00143