CMSIS DSP library
Dependents: KL25Z_FFT_Demo Hat_Board_v5_1 KL25Z_FFT_Demo_tony KL25Z_FFT_Demo_tony ... more
Fork of mbed-dsp by
cmsis_dsp/FilteringFunctions/arm_fir_f32.c@3:7a284390b0ce, 2013-11-08 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Nov 08 13:45:10 2013 +0000
- Revision:
- 3:7a284390b0ce
- Parent:
- 2:da51fb522205
Synchronized with git revision e69956aba2f68a2a26ac26b051f8d349deaa1ce8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:fdd22bb7aa52 | 1 | /* ---------------------------------------------------------------------- |
mbed_official | 3:7a284390b0ce | 2 | * Copyright (C) 2010-2013 ARM Limited. All rights reserved. |
emilmont | 1:fdd22bb7aa52 | 3 | * |
mbed_official | 3:7a284390b0ce | 4 | * $Date: 17. January 2013 |
mbed_official | 3:7a284390b0ce | 5 | * $Revision: V1.4.1 |
emilmont | 1:fdd22bb7aa52 | 6 | * |
emilmont | 2:da51fb522205 | 7 | * Project: CMSIS DSP Library |
emilmont | 2:da51fb522205 | 8 | * Title: arm_fir_f32.c |
emilmont | 1:fdd22bb7aa52 | 9 | * |
emilmont | 2:da51fb522205 | 10 | * Description: Floating-point FIR filter processing function. |
emilmont | 1:fdd22bb7aa52 | 11 | * |
emilmont | 1:fdd22bb7aa52 | 12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 |
emilmont | 1:fdd22bb7aa52 | 13 | * |
mbed_official | 3:7a284390b0ce | 14 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 3:7a284390b0ce | 15 | * modification, are permitted provided that the following conditions |
mbed_official | 3:7a284390b0ce | 16 | * are met: |
mbed_official | 3:7a284390b0ce | 17 | * - Redistributions of source code must retain the above copyright |
mbed_official | 3:7a284390b0ce | 18 | * notice, this list of conditions and the following disclaimer. |
mbed_official | 3:7a284390b0ce | 19 | * - Redistributions in binary form must reproduce the above copyright |
mbed_official | 3:7a284390b0ce | 20 | * notice, this list of conditions and the following disclaimer in |
mbed_official | 3:7a284390b0ce | 21 | * the documentation and/or other materials provided with the |
mbed_official | 3:7a284390b0ce | 22 | * distribution. |
mbed_official | 3:7a284390b0ce | 23 | * - Neither the name of ARM LIMITED nor the names of its contributors |
mbed_official | 3:7a284390b0ce | 24 | * may be used to endorse or promote products derived from this |
mbed_official | 3:7a284390b0ce | 25 | * software without specific prior written permission. |
mbed_official | 3:7a284390b0ce | 26 | * |
mbed_official | 3:7a284390b0ce | 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
mbed_official | 3:7a284390b0ce | 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
mbed_official | 3:7a284390b0ce | 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
mbed_official | 3:7a284390b0ce | 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
mbed_official | 3:7a284390b0ce | 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
mbed_official | 3:7a284390b0ce | 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
mbed_official | 3:7a284390b0ce | 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
mbed_official | 3:7a284390b0ce | 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 3:7a284390b0ce | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
mbed_official | 3:7a284390b0ce | 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
mbed_official | 3:7a284390b0ce | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
mbed_official | 3:7a284390b0ce | 38 | * POSSIBILITY OF SUCH DAMAGE. |
emilmont | 1:fdd22bb7aa52 | 39 | * -------------------------------------------------------------------- */ |
emilmont | 1:fdd22bb7aa52 | 40 | |
emilmont | 1:fdd22bb7aa52 | 41 | #include "arm_math.h" |
emilmont | 1:fdd22bb7aa52 | 42 | |
emilmont | 1:fdd22bb7aa52 | 43 | /** |
mbed_official | 3:7a284390b0ce | 44 | * @ingroup groupFilters |
mbed_official | 3:7a284390b0ce | 45 | */ |
emilmont | 1:fdd22bb7aa52 | 46 | |
emilmont | 1:fdd22bb7aa52 | 47 | /** |
mbed_official | 3:7a284390b0ce | 48 | * @defgroup FIR Finite Impulse Response (FIR) Filters |
mbed_official | 3:7a284390b0ce | 49 | * |
mbed_official | 3:7a284390b0ce | 50 | * This set of functions implements Finite Impulse Response (FIR) filters |
mbed_official | 3:7a284390b0ce | 51 | * for Q7, Q15, Q31, and floating-point data types. Fast versions of Q15 and Q31 are also provided. |
mbed_official | 3:7a284390b0ce | 52 | * The functions operate on blocks of input and output data and each call to the function processes |
mbed_official | 3:7a284390b0ce | 53 | * <code>blockSize</code> samples through the filter. <code>pSrc</code> and |
mbed_official | 3:7a284390b0ce | 54 | * <code>pDst</code> points to input and output arrays containing <code>blockSize</code> values. |
mbed_official | 3:7a284390b0ce | 55 | * |
mbed_official | 3:7a284390b0ce | 56 | * \par Algorithm: |
mbed_official | 3:7a284390b0ce | 57 | * The FIR filter algorithm is based upon a sequence of multiply-accumulate (MAC) operations. |
mbed_official | 3:7a284390b0ce | 58 | * Each filter coefficient <code>b[n]</code> is multiplied by a state variable which equals a previous input sample <code>x[n]</code>. |
mbed_official | 3:7a284390b0ce | 59 | * <pre> |
mbed_official | 3:7a284390b0ce | 60 | * y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[numTaps-1] * x[n-numTaps+1] |
mbed_official | 3:7a284390b0ce | 61 | * </pre> |
mbed_official | 3:7a284390b0ce | 62 | * \par |
mbed_official | 3:7a284390b0ce | 63 | * \image html FIR.gif "Finite Impulse Response filter" |
mbed_official | 3:7a284390b0ce | 64 | * \par |
mbed_official | 3:7a284390b0ce | 65 | * <code>pCoeffs</code> points to a coefficient array of size <code>numTaps</code>. |
mbed_official | 3:7a284390b0ce | 66 | * Coefficients are stored in time reversed order. |
mbed_official | 3:7a284390b0ce | 67 | * \par |
mbed_official | 3:7a284390b0ce | 68 | * <pre> |
mbed_official | 3:7a284390b0ce | 69 | * {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} |
mbed_official | 3:7a284390b0ce | 70 | * </pre> |
mbed_official | 3:7a284390b0ce | 71 | * \par |
mbed_official | 3:7a284390b0ce | 72 | * <code>pState</code> points to a state array of size <code>numTaps + blockSize - 1</code>. |
mbed_official | 3:7a284390b0ce | 73 | * Samples in the state buffer are stored in the following order. |
mbed_official | 3:7a284390b0ce | 74 | * \par |
mbed_official | 3:7a284390b0ce | 75 | * <pre> |
mbed_official | 3:7a284390b0ce | 76 | * {x[n-numTaps+1], x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2]....x[0], x[1], ..., x[blockSize-1]} |
mbed_official | 3:7a284390b0ce | 77 | * </pre> |
mbed_official | 3:7a284390b0ce | 78 | * \par |
mbed_official | 3:7a284390b0ce | 79 | * Note that the length of the state buffer exceeds the length of the coefficient array by <code>blockSize-1</code>. |
mbed_official | 3:7a284390b0ce | 80 | * The increased state buffer length allows circular addressing, which is traditionally used in the FIR filters, |
mbed_official | 3:7a284390b0ce | 81 | * to be avoided and yields a significant speed improvement. |
mbed_official | 3:7a284390b0ce | 82 | * The state variables are updated after each block of data is processed; the coefficients are untouched. |
mbed_official | 3:7a284390b0ce | 83 | * \par Instance Structure |
mbed_official | 3:7a284390b0ce | 84 | * The coefficients and state variables for a filter are stored together in an instance data structure. |
mbed_official | 3:7a284390b0ce | 85 | * A separate instance structure must be defined for each filter. |
mbed_official | 3:7a284390b0ce | 86 | * Coefficient arrays may be shared among several instances while state variable arrays cannot be shared. |
mbed_official | 3:7a284390b0ce | 87 | * There are separate instance structure declarations for each of the 4 supported data types. |
mbed_official | 3:7a284390b0ce | 88 | * |
mbed_official | 3:7a284390b0ce | 89 | * \par Initialization Functions |
mbed_official | 3:7a284390b0ce | 90 | * There is also an associated initialization function for each data type. |
mbed_official | 3:7a284390b0ce | 91 | * The initialization function performs the following operations: |
mbed_official | 3:7a284390b0ce | 92 | * - Sets the values of the internal structure fields. |
mbed_official | 3:7a284390b0ce | 93 | * - Zeros out the values in the state buffer. |
mbed_official | 3:7a284390b0ce | 94 | * To do this manually without calling the init function, assign the follow subfields of the instance structure: |
mbed_official | 3:7a284390b0ce | 95 | * numTaps, pCoeffs, pState. Also set all of the values in pState to zero. |
mbed_official | 3:7a284390b0ce | 96 | * |
mbed_official | 3:7a284390b0ce | 97 | * \par |
mbed_official | 3:7a284390b0ce | 98 | * Use of the initialization function is optional. |
mbed_official | 3:7a284390b0ce | 99 | * However, if the initialization function is used, then the instance structure cannot be placed into a const data section. |
mbed_official | 3:7a284390b0ce | 100 | * To place an instance structure into a const data section, the instance structure must be manually initialized. |
mbed_official | 3:7a284390b0ce | 101 | * Set the values in the state buffer to zeros before static initialization. |
mbed_official | 3:7a284390b0ce | 102 | * The code below statically initializes each of the 4 different data type filter instance structures |
mbed_official | 3:7a284390b0ce | 103 | * <pre> |
mbed_official | 3:7a284390b0ce | 104 | *arm_fir_instance_f32 S = {numTaps, pState, pCoeffs}; |
mbed_official | 3:7a284390b0ce | 105 | *arm_fir_instance_q31 S = {numTaps, pState, pCoeffs}; |
mbed_official | 3:7a284390b0ce | 106 | *arm_fir_instance_q15 S = {numTaps, pState, pCoeffs}; |
mbed_official | 3:7a284390b0ce | 107 | *arm_fir_instance_q7 S = {numTaps, pState, pCoeffs}; |
mbed_official | 3:7a284390b0ce | 108 | * </pre> |
mbed_official | 3:7a284390b0ce | 109 | * |
mbed_official | 3:7a284390b0ce | 110 | * where <code>numTaps</code> is the number of filter coefficients in the filter; <code>pState</code> is the address of the state buffer; |
mbed_official | 3:7a284390b0ce | 111 | * <code>pCoeffs</code> is the address of the coefficient buffer. |
mbed_official | 3:7a284390b0ce | 112 | * |
mbed_official | 3:7a284390b0ce | 113 | * \par Fixed-Point Behavior |
mbed_official | 3:7a284390b0ce | 114 | * Care must be taken when using the fixed-point versions of the FIR filter functions. |
mbed_official | 3:7a284390b0ce | 115 | * In particular, the overflow and saturation behavior of the accumulator used in each function must be considered. |
mbed_official | 3:7a284390b0ce | 116 | * Refer to the function specific documentation below for usage guidelines. |
mbed_official | 3:7a284390b0ce | 117 | */ |
emilmont | 1:fdd22bb7aa52 | 118 | |
emilmont | 1:fdd22bb7aa52 | 119 | /** |
mbed_official | 3:7a284390b0ce | 120 | * @addtogroup FIR |
mbed_official | 3:7a284390b0ce | 121 | * @{ |
mbed_official | 3:7a284390b0ce | 122 | */ |
emilmont | 1:fdd22bb7aa52 | 123 | |
emilmont | 1:fdd22bb7aa52 | 124 | /** |
mbed_official | 3:7a284390b0ce | 125 | * |
mbed_official | 3:7a284390b0ce | 126 | * @param[in] *S points to an instance of the floating-point FIR filter structure. |
mbed_official | 3:7a284390b0ce | 127 | * @param[in] *pSrc points to the block of input data. |
mbed_official | 3:7a284390b0ce | 128 | * @param[out] *pDst points to the block of output data. |
mbed_official | 3:7a284390b0ce | 129 | * @param[in] blockSize number of samples to process per call. |
mbed_official | 3:7a284390b0ce | 130 | * @return none. |
mbed_official | 3:7a284390b0ce | 131 | * |
mbed_official | 3:7a284390b0ce | 132 | */ |
emilmont | 1:fdd22bb7aa52 | 133 | |
mbed_official | 3:7a284390b0ce | 134 | #ifndef ARM_MATH_CM0_FAMILY |
emilmont | 1:fdd22bb7aa52 | 135 | |
mbed_official | 3:7a284390b0ce | 136 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emilmont | 1:fdd22bb7aa52 | 137 | |
emilmont | 1:fdd22bb7aa52 | 138 | void arm_fir_f32( |
mbed_official | 3:7a284390b0ce | 139 | const arm_fir_instance_f32 * S, |
mbed_official | 3:7a284390b0ce | 140 | float32_t * pSrc, |
mbed_official | 3:7a284390b0ce | 141 | float32_t * pDst, |
mbed_official | 3:7a284390b0ce | 142 | uint32_t blockSize) |
emilmont | 1:fdd22bb7aa52 | 143 | { |
mbed_official | 3:7a284390b0ce | 144 | float32_t *pState = S->pState; /* State pointer */ |
mbed_official | 3:7a284390b0ce | 145 | float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
mbed_official | 3:7a284390b0ce | 146 | float32_t *pStateCurnt; /* Points to the current sample of the state */ |
mbed_official | 3:7a284390b0ce | 147 | float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */ |
mbed_official | 3:7a284390b0ce | 148 | float32_t acc0, acc1, acc2, acc3, acc4, acc5, acc6, acc7; /* Accumulators */ |
mbed_official | 3:7a284390b0ce | 149 | float32_t x0, x1, x2, x3, x4, x5, x6, x7, c0; /* Temporary variables to hold state and coefficient values */ |
mbed_official | 3:7a284390b0ce | 150 | uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ |
mbed_official | 3:7a284390b0ce | 151 | uint32_t i, tapCnt, blkCnt; /* Loop counters */ |
mbed_official | 3:7a284390b0ce | 152 | float32_t p0,p1,p2,p3,p4,p5,p6,p7; /* Temporary product values */ |
mbed_official | 3:7a284390b0ce | 153 | |
mbed_official | 3:7a284390b0ce | 154 | /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ |
mbed_official | 3:7a284390b0ce | 155 | /* pStateCurnt points to the location where the new input data should be written */ |
mbed_official | 3:7a284390b0ce | 156 | pStateCurnt = &(S->pState[(numTaps - 1u)]); |
mbed_official | 3:7a284390b0ce | 157 | |
mbed_official | 3:7a284390b0ce | 158 | /* Apply loop unrolling and compute 8 output values simultaneously. |
mbed_official | 3:7a284390b0ce | 159 | * The variables acc0 ... acc7 hold output values that are being computed: |
mbed_official | 3:7a284390b0ce | 160 | * |
mbed_official | 3:7a284390b0ce | 161 | * acc0 = b[numTaps-1] * x[n-numTaps-1] + b[numTaps-2] * x[n-numTaps-2] + b[numTaps-3] * x[n-numTaps-3] +...+ b[0] * x[0] |
mbed_official | 3:7a284390b0ce | 162 | * acc1 = b[numTaps-1] * x[n-numTaps] + b[numTaps-2] * x[n-numTaps-1] + b[numTaps-3] * x[n-numTaps-2] +...+ b[0] * x[1] |
mbed_official | 3:7a284390b0ce | 163 | * acc2 = b[numTaps-1] * x[n-numTaps+1] + b[numTaps-2] * x[n-numTaps] + b[numTaps-3] * x[n-numTaps-1] +...+ b[0] * x[2] |
mbed_official | 3:7a284390b0ce | 164 | * acc3 = b[numTaps-1] * x[n-numTaps+2] + b[numTaps-2] * x[n-numTaps+1] + b[numTaps-3] * x[n-numTaps] +...+ b[0] * x[3] |
mbed_official | 3:7a284390b0ce | 165 | */ |
mbed_official | 3:7a284390b0ce | 166 | blkCnt = blockSize >> 3; |
mbed_official | 3:7a284390b0ce | 167 | |
mbed_official | 3:7a284390b0ce | 168 | /* First part of the processing with loop unrolling. Compute 8 outputs at a time. |
mbed_official | 3:7a284390b0ce | 169 | ** a second loop below computes the remaining 1 to 7 samples. */ |
mbed_official | 3:7a284390b0ce | 170 | while(blkCnt > 0u) |
mbed_official | 3:7a284390b0ce | 171 | { |
mbed_official | 3:7a284390b0ce | 172 | /* Copy four new input samples into the state buffer */ |
mbed_official | 3:7a284390b0ce | 173 | *pStateCurnt++ = *pSrc++; |
mbed_official | 3:7a284390b0ce | 174 | *pStateCurnt++ = *pSrc++; |
mbed_official | 3:7a284390b0ce | 175 | *pStateCurnt++ = *pSrc++; |
mbed_official | 3:7a284390b0ce | 176 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 177 | |
mbed_official | 3:7a284390b0ce | 178 | /* Set all accumulators to zero */ |
mbed_official | 3:7a284390b0ce | 179 | acc0 = 0.0f; |
mbed_official | 3:7a284390b0ce | 180 | acc1 = 0.0f; |
mbed_official | 3:7a284390b0ce | 181 | acc2 = 0.0f; |
mbed_official | 3:7a284390b0ce | 182 | acc3 = 0.0f; |
mbed_official | 3:7a284390b0ce | 183 | acc4 = 0.0f; |
mbed_official | 3:7a284390b0ce | 184 | acc5 = 0.0f; |
mbed_official | 3:7a284390b0ce | 185 | acc6 = 0.0f; |
mbed_official | 3:7a284390b0ce | 186 | acc7 = 0.0f; |
mbed_official | 3:7a284390b0ce | 187 | |
mbed_official | 3:7a284390b0ce | 188 | /* Initialize state pointer */ |
mbed_official | 3:7a284390b0ce | 189 | px = pState; |
mbed_official | 3:7a284390b0ce | 190 | |
mbed_official | 3:7a284390b0ce | 191 | /* Initialize coeff pointer */ |
mbed_official | 3:7a284390b0ce | 192 | pb = (pCoeffs); |
mbed_official | 3:7a284390b0ce | 193 | |
mbed_official | 3:7a284390b0ce | 194 | /* This is separated from the others to avoid |
mbed_official | 3:7a284390b0ce | 195 | * a call to __aeabi_memmove which would be slower |
mbed_official | 3:7a284390b0ce | 196 | */ |
mbed_official | 3:7a284390b0ce | 197 | *pStateCurnt++ = *pSrc++; |
mbed_official | 3:7a284390b0ce | 198 | *pStateCurnt++ = *pSrc++; |
mbed_official | 3:7a284390b0ce | 199 | *pStateCurnt++ = *pSrc++; |
mbed_official | 3:7a284390b0ce | 200 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 201 | |
mbed_official | 3:7a284390b0ce | 202 | /* Read the first seven samples from the state buffer: x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2] */ |
mbed_official | 3:7a284390b0ce | 203 | x0 = *px++; |
mbed_official | 3:7a284390b0ce | 204 | x1 = *px++; |
mbed_official | 3:7a284390b0ce | 205 | x2 = *px++; |
mbed_official | 3:7a284390b0ce | 206 | x3 = *px++; |
mbed_official | 3:7a284390b0ce | 207 | x4 = *px++; |
mbed_official | 3:7a284390b0ce | 208 | x5 = *px++; |
mbed_official | 3:7a284390b0ce | 209 | x6 = *px++; |
mbed_official | 3:7a284390b0ce | 210 | |
mbed_official | 3:7a284390b0ce | 211 | /* Loop unrolling. Process 8 taps at a time. */ |
mbed_official | 3:7a284390b0ce | 212 | tapCnt = numTaps >> 3u; |
mbed_official | 3:7a284390b0ce | 213 | |
mbed_official | 3:7a284390b0ce | 214 | /* Loop over the number of taps. Unroll by a factor of 8. |
mbed_official | 3:7a284390b0ce | 215 | ** Repeat until we've computed numTaps-8 coefficients. */ |
mbed_official | 3:7a284390b0ce | 216 | while(tapCnt > 0u) |
mbed_official | 3:7a284390b0ce | 217 | { |
mbed_official | 3:7a284390b0ce | 218 | /* Read the b[numTaps-1] coefficient */ |
mbed_official | 3:7a284390b0ce | 219 | c0 = *(pb++); |
mbed_official | 3:7a284390b0ce | 220 | |
mbed_official | 3:7a284390b0ce | 221 | /* Read x[n-numTaps-3] sample */ |
mbed_official | 3:7a284390b0ce | 222 | x7 = *(px++); |
mbed_official | 3:7a284390b0ce | 223 | |
mbed_official | 3:7a284390b0ce | 224 | /* acc0 += b[numTaps-1] * x[n-numTaps] */ |
mbed_official | 3:7a284390b0ce | 225 | p0 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 226 | |
mbed_official | 3:7a284390b0ce | 227 | /* acc1 += b[numTaps-1] * x[n-numTaps-1] */ |
mbed_official | 3:7a284390b0ce | 228 | p1 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 229 | |
mbed_official | 3:7a284390b0ce | 230 | /* acc2 += b[numTaps-1] * x[n-numTaps-2] */ |
mbed_official | 3:7a284390b0ce | 231 | p2 = x2 * c0; |
emilmont | 1:fdd22bb7aa52 | 232 | |
mbed_official | 3:7a284390b0ce | 233 | /* acc3 += b[numTaps-1] * x[n-numTaps-3] */ |
mbed_official | 3:7a284390b0ce | 234 | p3 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 235 | |
mbed_official | 3:7a284390b0ce | 236 | /* acc4 += b[numTaps-1] * x[n-numTaps-4] */ |
mbed_official | 3:7a284390b0ce | 237 | p4 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 238 | |
mbed_official | 3:7a284390b0ce | 239 | /* acc1 += b[numTaps-1] * x[n-numTaps-5] */ |
mbed_official | 3:7a284390b0ce | 240 | p5 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 241 | |
mbed_official | 3:7a284390b0ce | 242 | /* acc2 += b[numTaps-1] * x[n-numTaps-6] */ |
mbed_official | 3:7a284390b0ce | 243 | p6 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 244 | |
mbed_official | 3:7a284390b0ce | 245 | /* acc3 += b[numTaps-1] * x[n-numTaps-7] */ |
mbed_official | 3:7a284390b0ce | 246 | p7 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 247 | |
mbed_official | 3:7a284390b0ce | 248 | /* Read the b[numTaps-2] coefficient */ |
mbed_official | 3:7a284390b0ce | 249 | c0 = *(pb++); |
mbed_official | 3:7a284390b0ce | 250 | |
mbed_official | 3:7a284390b0ce | 251 | /* Read x[n-numTaps-4] sample */ |
mbed_official | 3:7a284390b0ce | 252 | x0 = *(px++); |
mbed_official | 3:7a284390b0ce | 253 | |
mbed_official | 3:7a284390b0ce | 254 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 255 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 256 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 257 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 258 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 259 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 260 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 261 | acc7 += p7; |
mbed_official | 3:7a284390b0ce | 262 | |
mbed_official | 3:7a284390b0ce | 263 | |
mbed_official | 3:7a284390b0ce | 264 | /* Perform the multiply-accumulate */ |
mbed_official | 3:7a284390b0ce | 265 | p0 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 266 | p1 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 267 | p2 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 268 | p3 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 269 | p4 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 270 | p5 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 271 | p6 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 272 | p7 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 273 | |
mbed_official | 3:7a284390b0ce | 274 | /* Read the b[numTaps-3] coefficient */ |
mbed_official | 3:7a284390b0ce | 275 | c0 = *(pb++); |
emilmont | 1:fdd22bb7aa52 | 276 | |
mbed_official | 3:7a284390b0ce | 277 | /* Read x[n-numTaps-5] sample */ |
mbed_official | 3:7a284390b0ce | 278 | x1 = *(px++); |
mbed_official | 3:7a284390b0ce | 279 | |
mbed_official | 3:7a284390b0ce | 280 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 281 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 282 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 283 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 284 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 285 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 286 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 287 | acc7 += p7; |
mbed_official | 3:7a284390b0ce | 288 | |
mbed_official | 3:7a284390b0ce | 289 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 290 | p0 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 291 | p1 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 292 | p2 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 293 | p3 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 294 | p4 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 295 | p5 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 296 | p6 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 297 | p7 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 298 | |
mbed_official | 3:7a284390b0ce | 299 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 3:7a284390b0ce | 300 | c0 = *(pb++); |
emilmont | 1:fdd22bb7aa52 | 301 | |
mbed_official | 3:7a284390b0ce | 302 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 3:7a284390b0ce | 303 | x2 = *(px++); |
mbed_official | 3:7a284390b0ce | 304 | |
mbed_official | 3:7a284390b0ce | 305 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 306 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 307 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 308 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 309 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 310 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 311 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 312 | acc7 += p7; |
emilmont | 1:fdd22bb7aa52 | 313 | |
mbed_official | 3:7a284390b0ce | 314 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 315 | p0 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 316 | p1 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 317 | p2 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 318 | p3 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 319 | p4 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 320 | p5 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 321 | p6 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 322 | p7 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 323 | |
mbed_official | 3:7a284390b0ce | 324 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 3:7a284390b0ce | 325 | c0 = *(pb++); |
emilmont | 1:fdd22bb7aa52 | 326 | |
mbed_official | 3:7a284390b0ce | 327 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 3:7a284390b0ce | 328 | x3 = *(px++); |
mbed_official | 3:7a284390b0ce | 329 | |
mbed_official | 3:7a284390b0ce | 330 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 331 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 332 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 333 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 334 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 335 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 336 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 337 | acc7 += p7; |
emilmont | 1:fdd22bb7aa52 | 338 | |
mbed_official | 3:7a284390b0ce | 339 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 340 | p0 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 341 | p1 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 342 | p2 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 343 | p3 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 344 | p4 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 345 | p5 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 346 | p6 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 347 | p7 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 348 | |
mbed_official | 3:7a284390b0ce | 349 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 3:7a284390b0ce | 350 | c0 = *(pb++); |
mbed_official | 3:7a284390b0ce | 351 | |
mbed_official | 3:7a284390b0ce | 352 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 3:7a284390b0ce | 353 | x4 = *(px++); |
mbed_official | 3:7a284390b0ce | 354 | |
mbed_official | 3:7a284390b0ce | 355 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 356 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 357 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 358 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 359 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 360 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 361 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 362 | acc7 += p7; |
emilmont | 1:fdd22bb7aa52 | 363 | |
mbed_official | 3:7a284390b0ce | 364 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 365 | p0 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 366 | p1 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 367 | p2 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 368 | p3 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 369 | p4 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 370 | p5 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 371 | p6 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 372 | p7 = x4 * c0; |
emilmont | 1:fdd22bb7aa52 | 373 | |
mbed_official | 3:7a284390b0ce | 374 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 3:7a284390b0ce | 375 | c0 = *(pb++); |
mbed_official | 3:7a284390b0ce | 376 | |
mbed_official | 3:7a284390b0ce | 377 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 3:7a284390b0ce | 378 | x5 = *(px++); |
mbed_official | 3:7a284390b0ce | 379 | |
mbed_official | 3:7a284390b0ce | 380 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 381 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 382 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 383 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 384 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 385 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 386 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 387 | acc7 += p7; |
emilmont | 1:fdd22bb7aa52 | 388 | |
mbed_official | 3:7a284390b0ce | 389 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 390 | p0 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 391 | p1 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 392 | p2 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 393 | p3 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 394 | p4 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 395 | p5 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 396 | p6 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 397 | p7 = x5 * c0; |
emilmont | 1:fdd22bb7aa52 | 398 | |
mbed_official | 3:7a284390b0ce | 399 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 3:7a284390b0ce | 400 | c0 = *(pb++); |
emilmont | 1:fdd22bb7aa52 | 401 | |
mbed_official | 3:7a284390b0ce | 402 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 3:7a284390b0ce | 403 | x6 = *(px++); |
mbed_official | 3:7a284390b0ce | 404 | |
mbed_official | 3:7a284390b0ce | 405 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 406 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 407 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 408 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 409 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 410 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 411 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 412 | acc7 += p7; |
emilmont | 1:fdd22bb7aa52 | 413 | |
mbed_official | 3:7a284390b0ce | 414 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 415 | p0 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 416 | p1 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 417 | p2 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 418 | p3 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 419 | p4 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 420 | p5 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 421 | p6 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 422 | p7 = x6 * c0; |
emilmont | 1:fdd22bb7aa52 | 423 | |
mbed_official | 3:7a284390b0ce | 424 | tapCnt--; |
mbed_official | 3:7a284390b0ce | 425 | |
mbed_official | 3:7a284390b0ce | 426 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 427 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 428 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 429 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 430 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 431 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 432 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 433 | acc7 += p7; |
mbed_official | 3:7a284390b0ce | 434 | } |
mbed_official | 3:7a284390b0ce | 435 | |
mbed_official | 3:7a284390b0ce | 436 | /* If the filter length is not a multiple of 8, compute the remaining filter taps */ |
mbed_official | 3:7a284390b0ce | 437 | tapCnt = numTaps % 0x8u; |
emilmont | 1:fdd22bb7aa52 | 438 | |
mbed_official | 3:7a284390b0ce | 439 | while(tapCnt > 0u) |
mbed_official | 3:7a284390b0ce | 440 | { |
mbed_official | 3:7a284390b0ce | 441 | /* Read coefficients */ |
mbed_official | 3:7a284390b0ce | 442 | c0 = *(pb++); |
mbed_official | 3:7a284390b0ce | 443 | |
mbed_official | 3:7a284390b0ce | 444 | /* Fetch 1 state variable */ |
mbed_official | 3:7a284390b0ce | 445 | x7 = *(px++); |
emilmont | 1:fdd22bb7aa52 | 446 | |
mbed_official | 3:7a284390b0ce | 447 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 448 | p0 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 449 | p1 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 450 | p2 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 451 | p3 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 452 | p4 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 453 | p5 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 454 | p6 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 455 | p7 = x7 * c0; |
emilmont | 1:fdd22bb7aa52 | 456 | |
mbed_official | 3:7a284390b0ce | 457 | /* Reuse the present sample states for next sample */ |
mbed_official | 3:7a284390b0ce | 458 | x0 = x1; |
mbed_official | 3:7a284390b0ce | 459 | x1 = x2; |
mbed_official | 3:7a284390b0ce | 460 | x2 = x3; |
mbed_official | 3:7a284390b0ce | 461 | x3 = x4; |
mbed_official | 3:7a284390b0ce | 462 | x4 = x5; |
mbed_official | 3:7a284390b0ce | 463 | x5 = x6; |
mbed_official | 3:7a284390b0ce | 464 | x6 = x7; |
mbed_official | 3:7a284390b0ce | 465 | |
mbed_official | 3:7a284390b0ce | 466 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 467 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 468 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 469 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 470 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 471 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 472 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 473 | acc7 += p7; |
mbed_official | 3:7a284390b0ce | 474 | |
mbed_official | 3:7a284390b0ce | 475 | /* Decrement the loop counter */ |
mbed_official | 3:7a284390b0ce | 476 | tapCnt--; |
mbed_official | 3:7a284390b0ce | 477 | } |
mbed_official | 3:7a284390b0ce | 478 | |
mbed_official | 3:7a284390b0ce | 479 | /* Advance the state pointer by 8 to process the next group of 8 samples */ |
mbed_official | 3:7a284390b0ce | 480 | pState = pState + 8; |
emilmont | 1:fdd22bb7aa52 | 481 | |
mbed_official | 3:7a284390b0ce | 482 | /* The results in the 8 accumulators, store in the destination buffer. */ |
mbed_official | 3:7a284390b0ce | 483 | *pDst++ = acc0; |
mbed_official | 3:7a284390b0ce | 484 | *pDst++ = acc1; |
mbed_official | 3:7a284390b0ce | 485 | *pDst++ = acc2; |
mbed_official | 3:7a284390b0ce | 486 | *pDst++ = acc3; |
mbed_official | 3:7a284390b0ce | 487 | *pDst++ = acc4; |
mbed_official | 3:7a284390b0ce | 488 | *pDst++ = acc5; |
mbed_official | 3:7a284390b0ce | 489 | *pDst++ = acc6; |
mbed_official | 3:7a284390b0ce | 490 | *pDst++ = acc7; |
mbed_official | 3:7a284390b0ce | 491 | |
mbed_official | 3:7a284390b0ce | 492 | blkCnt--; |
mbed_official | 3:7a284390b0ce | 493 | } |
emilmont | 1:fdd22bb7aa52 | 494 | |
mbed_official | 3:7a284390b0ce | 495 | /* If the blockSize is not a multiple of 8, compute any remaining output samples here. |
mbed_official | 3:7a284390b0ce | 496 | ** No loop unrolling is used. */ |
mbed_official | 3:7a284390b0ce | 497 | blkCnt = blockSize % 0x8u; |
mbed_official | 3:7a284390b0ce | 498 | |
mbed_official | 3:7a284390b0ce | 499 | while(blkCnt > 0u) |
mbed_official | 3:7a284390b0ce | 500 | { |
mbed_official | 3:7a284390b0ce | 501 | /* Copy one sample at a time into state buffer */ |
mbed_official | 3:7a284390b0ce | 502 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 503 | |
mbed_official | 3:7a284390b0ce | 504 | /* Set the accumulator to zero */ |
mbed_official | 3:7a284390b0ce | 505 | acc0 = 0.0f; |
mbed_official | 3:7a284390b0ce | 506 | |
mbed_official | 3:7a284390b0ce | 507 | /* Initialize state pointer */ |
mbed_official | 3:7a284390b0ce | 508 | px = pState; |
mbed_official | 3:7a284390b0ce | 509 | |
mbed_official | 3:7a284390b0ce | 510 | /* Initialize Coefficient pointer */ |
mbed_official | 3:7a284390b0ce | 511 | pb = (pCoeffs); |
mbed_official | 3:7a284390b0ce | 512 | |
mbed_official | 3:7a284390b0ce | 513 | i = numTaps; |
emilmont | 1:fdd22bb7aa52 | 514 | |
emilmont | 1:fdd22bb7aa52 | 515 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 516 | do |
mbed_official | 3:7a284390b0ce | 517 | { |
mbed_official | 3:7a284390b0ce | 518 | acc0 += *px++ * *pb++; |
mbed_official | 3:7a284390b0ce | 519 | i--; |
emilmont | 1:fdd22bb7aa52 | 520 | |
mbed_official | 3:7a284390b0ce | 521 | } while(i > 0u); |
emilmont | 1:fdd22bb7aa52 | 522 | |
mbed_official | 3:7a284390b0ce | 523 | /* The result is store in the destination buffer. */ |
mbed_official | 3:7a284390b0ce | 524 | *pDst++ = acc0; |
emilmont | 1:fdd22bb7aa52 | 525 | |
mbed_official | 3:7a284390b0ce | 526 | /* Advance state pointer by 1 for the next sample */ |
mbed_official | 3:7a284390b0ce | 527 | pState = pState + 1; |
emilmont | 1:fdd22bb7aa52 | 528 | |
mbed_official | 3:7a284390b0ce | 529 | blkCnt--; |
mbed_official | 3:7a284390b0ce | 530 | } |
emilmont | 1:fdd22bb7aa52 | 531 | |
mbed_official | 3:7a284390b0ce | 532 | /* Processing is complete. |
mbed_official | 3:7a284390b0ce | 533 | ** Now copy the last numTaps - 1 samples to the start of the state buffer. |
mbed_official | 3:7a284390b0ce | 534 | ** This prepares the state buffer for the next function call. */ |
emilmont | 1:fdd22bb7aa52 | 535 | |
mbed_official | 3:7a284390b0ce | 536 | /* Points to the start of the state buffer */ |
mbed_official | 3:7a284390b0ce | 537 | pStateCurnt = S->pState; |
emilmont | 1:fdd22bb7aa52 | 538 | |
mbed_official | 3:7a284390b0ce | 539 | tapCnt = (numTaps - 1u) >> 2u; |
emilmont | 1:fdd22bb7aa52 | 540 | |
mbed_official | 3:7a284390b0ce | 541 | /* copy data */ |
mbed_official | 3:7a284390b0ce | 542 | while(tapCnt > 0u) |
mbed_official | 3:7a284390b0ce | 543 | { |
mbed_official | 3:7a284390b0ce | 544 | *pStateCurnt++ = *pState++; |
mbed_official | 3:7a284390b0ce | 545 | *pStateCurnt++ = *pState++; |
mbed_official | 3:7a284390b0ce | 546 | *pStateCurnt++ = *pState++; |
mbed_official | 3:7a284390b0ce | 547 | *pStateCurnt++ = *pState++; |
emilmont | 1:fdd22bb7aa52 | 548 | |
emilmont | 1:fdd22bb7aa52 | 549 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 550 | tapCnt--; |
mbed_official | 3:7a284390b0ce | 551 | } |
emilmont | 1:fdd22bb7aa52 | 552 | |
mbed_official | 3:7a284390b0ce | 553 | /* Calculate remaining number of copies */ |
mbed_official | 3:7a284390b0ce | 554 | tapCnt = (numTaps - 1u) % 0x4u; |
emilmont | 1:fdd22bb7aa52 | 555 | |
mbed_official | 3:7a284390b0ce | 556 | /* Copy the remaining q31_t data */ |
mbed_official | 3:7a284390b0ce | 557 | while(tapCnt > 0u) |
mbed_official | 3:7a284390b0ce | 558 | { |
mbed_official | 3:7a284390b0ce | 559 | *pStateCurnt++ = *pState++; |
emilmont | 1:fdd22bb7aa52 | 560 | |
mbed_official | 3:7a284390b0ce | 561 | /* Decrement the loop counter */ |
mbed_official | 3:7a284390b0ce | 562 | tapCnt--; |
mbed_official | 3:7a284390b0ce | 563 | } |
emilmont | 1:fdd22bb7aa52 | 564 | } |
emilmont | 1:fdd22bb7aa52 | 565 | |
emilmont | 1:fdd22bb7aa52 | 566 | #else |
emilmont | 1:fdd22bb7aa52 | 567 | |
emilmont | 1:fdd22bb7aa52 | 568 | void arm_fir_f32( |
mbed_official | 3:7a284390b0ce | 569 | const arm_fir_instance_f32 * S, |
mbed_official | 3:7a284390b0ce | 570 | float32_t * pSrc, |
mbed_official | 3:7a284390b0ce | 571 | float32_t * pDst, |
mbed_official | 3:7a284390b0ce | 572 | uint32_t blockSize) |
emilmont | 1:fdd22bb7aa52 | 573 | { |
mbed_official | 3:7a284390b0ce | 574 | float32_t *pState = S->pState; /* State pointer */ |
mbed_official | 3:7a284390b0ce | 575 | float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
mbed_official | 3:7a284390b0ce | 576 | float32_t *pStateCurnt; /* Points to the current sample of the state */ |
mbed_official | 3:7a284390b0ce | 577 | float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */ |
mbed_official | 3:7a284390b0ce | 578 | uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ |
mbed_official | 3:7a284390b0ce | 579 | uint32_t i, tapCnt, blkCnt; /* Loop counters */ |
emilmont | 1:fdd22bb7aa52 | 580 | |
mbed_official | 3:7a284390b0ce | 581 | /* Run the below code for Cortex-M0 */ |
emilmont | 1:fdd22bb7aa52 | 582 | |
mbed_official | 3:7a284390b0ce | 583 | float32_t acc; |
emilmont | 1:fdd22bb7aa52 | 584 | |
mbed_official | 3:7a284390b0ce | 585 | /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ |
mbed_official | 3:7a284390b0ce | 586 | /* pStateCurnt points to the location where the new input data should be written */ |
mbed_official | 3:7a284390b0ce | 587 | pStateCurnt = &(S->pState[(numTaps - 1u)]); |
emilmont | 1:fdd22bb7aa52 | 588 | |
mbed_official | 3:7a284390b0ce | 589 | /* Initialize blkCnt with blockSize */ |
mbed_official | 3:7a284390b0ce | 590 | blkCnt = blockSize; |
emilmont | 1:fdd22bb7aa52 | 591 | |
mbed_official | 3:7a284390b0ce | 592 | while(blkCnt > 0u) |
mbed_official | 3:7a284390b0ce | 593 | { |
mbed_official | 3:7a284390b0ce | 594 | /* Copy one sample at a time into state buffer */ |
mbed_official | 3:7a284390b0ce | 595 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 596 | |
mbed_official | 3:7a284390b0ce | 597 | /* Set the accumulator to zero */ |
mbed_official | 3:7a284390b0ce | 598 | acc = 0.0f; |
emilmont | 1:fdd22bb7aa52 | 599 | |
mbed_official | 3:7a284390b0ce | 600 | /* Initialize state pointer */ |
mbed_official | 3:7a284390b0ce | 601 | px = pState; |
emilmont | 1:fdd22bb7aa52 | 602 | |
mbed_official | 3:7a284390b0ce | 603 | /* Initialize Coefficient pointer */ |
mbed_official | 3:7a284390b0ce | 604 | pb = pCoeffs; |
emilmont | 1:fdd22bb7aa52 | 605 | |
mbed_official | 3:7a284390b0ce | 606 | i = numTaps; |
emilmont | 1:fdd22bb7aa52 | 607 | |
mbed_official | 3:7a284390b0ce | 608 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 609 | do |
mbed_official | 3:7a284390b0ce | 610 | { |
mbed_official | 3:7a284390b0ce | 611 | /* acc = b[numTaps-1] * x[n-numTaps-1] + b[numTaps-2] * x[n-numTaps-2] + b[numTaps-3] * x[n-numTaps-3] +...+ b[0] * x[0] */ |
mbed_official | 3:7a284390b0ce | 612 | acc += *px++ * *pb++; |
mbed_official | 3:7a284390b0ce | 613 | i--; |
emilmont | 1:fdd22bb7aa52 | 614 | |
mbed_official | 3:7a284390b0ce | 615 | } while(i > 0u); |
emilmont | 1:fdd22bb7aa52 | 616 | |
mbed_official | 3:7a284390b0ce | 617 | /* The result is store in the destination buffer. */ |
mbed_official | 3:7a284390b0ce | 618 | *pDst++ = acc; |
emilmont | 1:fdd22bb7aa52 | 619 | |
mbed_official | 3:7a284390b0ce | 620 | /* Advance state pointer by 1 for the next sample */ |
mbed_official | 3:7a284390b0ce | 621 | pState = pState + 1; |
emilmont | 1:fdd22bb7aa52 | 622 | |
mbed_official | 3:7a284390b0ce | 623 | blkCnt--; |
mbed_official | 3:7a284390b0ce | 624 | } |
emilmont | 1:fdd22bb7aa52 | 625 | |
mbed_official | 3:7a284390b0ce | 626 | /* Processing is complete. |
emilmont | 1:fdd22bb7aa52 | 627 | ** Now copy the last numTaps - 1 samples to the starting of the state buffer. |
emilmont | 1:fdd22bb7aa52 | 628 | ** This prepares the state buffer for the next function call. */ |
emilmont | 1:fdd22bb7aa52 | 629 | |
mbed_official | 3:7a284390b0ce | 630 | /* Points to the start of the state buffer */ |
mbed_official | 3:7a284390b0ce | 631 | pStateCurnt = S->pState; |
emilmont | 1:fdd22bb7aa52 | 632 | |
mbed_official | 3:7a284390b0ce | 633 | /* Copy numTaps number of values */ |
mbed_official | 3:7a284390b0ce | 634 | tapCnt = numTaps - 1u; |
emilmont | 1:fdd22bb7aa52 | 635 | |
mbed_official | 3:7a284390b0ce | 636 | /* Copy data */ |
mbed_official | 3:7a284390b0ce | 637 | while(tapCnt > 0u) |
mbed_official | 3:7a284390b0ce | 638 | { |
mbed_official | 3:7a284390b0ce | 639 | *pStateCurnt++ = *pState++; |
emilmont | 1:fdd22bb7aa52 | 640 | |
mbed_official | 3:7a284390b0ce | 641 | /* Decrement the loop counter */ |
mbed_official | 3:7a284390b0ce | 642 | tapCnt--; |
mbed_official | 3:7a284390b0ce | 643 | } |
emilmont | 1:fdd22bb7aa52 | 644 | |
emilmont | 1:fdd22bb7aa52 | 645 | } |
emilmont | 1:fdd22bb7aa52 | 646 | |
mbed_official | 3:7a284390b0ce | 647 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
emilmont | 1:fdd22bb7aa52 | 648 | |
emilmont | 1:fdd22bb7aa52 | 649 | /** |
mbed_official | 3:7a284390b0ce | 650 | * @} end of FIR group |
mbed_official | 3:7a284390b0ce | 651 | */ |