CMSIS DSP library
Dependents: performance_timer Surfboard_ gps2rtty Capstone ... more
Legacy Warning
This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.
cmsis_dsp/FilteringFunctions/arm_fir_f32.c@5:3762170b6d4d, 2015-11-20 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Nov 20 08:45:18 2015 +0000
- Revision:
- 5:3762170b6d4d
- Parent:
- 3:7a284390b0ce
Synchronized with git revision 2eb940b9a73af188d3004a2575fdfbb05febe62b
Full URL: https://github.com/mbedmicro/mbed/commit/2eb940b9a73af188d3004a2575fdfbb05febe62b/
Added option to build rpc library. closes #1426
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:fdd22bb7aa52 | 1 | /* ---------------------------------------------------------------------- |
mbed_official | 5:3762170b6d4d | 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. |
emilmont | 1:fdd22bb7aa52 | 3 | * |
mbed_official | 5:3762170b6d4d | 4 | * $Date: 19. March 2015 |
mbed_official | 5:3762170b6d4d | 5 | * $Revision: V.1.4.5 |
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 | 5:3762170b6d4d | 134 | #if defined(ARM_MATH_CM7) |
mbed_official | 5:3762170b6d4d | 135 | |
mbed_official | 5:3762170b6d4d | 136 | void arm_fir_f32( |
mbed_official | 5:3762170b6d4d | 137 | const arm_fir_instance_f32 * S, |
mbed_official | 5:3762170b6d4d | 138 | float32_t * pSrc, |
mbed_official | 5:3762170b6d4d | 139 | float32_t * pDst, |
mbed_official | 5:3762170b6d4d | 140 | uint32_t blockSize) |
mbed_official | 5:3762170b6d4d | 141 | { |
mbed_official | 5:3762170b6d4d | 142 | float32_t *pState = S->pState; /* State pointer */ |
mbed_official | 5:3762170b6d4d | 143 | float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
mbed_official | 5:3762170b6d4d | 144 | float32_t *pStateCurnt; /* Points to the current sample of the state */ |
mbed_official | 5:3762170b6d4d | 145 | float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */ |
mbed_official | 5:3762170b6d4d | 146 | float32_t acc0, acc1, acc2, acc3, acc4, acc5, acc6, acc7; /* Accumulators */ |
mbed_official | 5:3762170b6d4d | 147 | float32_t x0, x1, x2, x3, x4, x5, x6, x7, c0; /* Temporary variables to hold state and coefficient values */ |
mbed_official | 5:3762170b6d4d | 148 | uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ |
mbed_official | 5:3762170b6d4d | 149 | uint32_t i, tapCnt, blkCnt; /* Loop counters */ |
mbed_official | 5:3762170b6d4d | 150 | |
mbed_official | 5:3762170b6d4d | 151 | /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ |
mbed_official | 5:3762170b6d4d | 152 | /* pStateCurnt points to the location where the new input data should be written */ |
mbed_official | 5:3762170b6d4d | 153 | pStateCurnt = &(S->pState[(numTaps - 1u)]); |
mbed_official | 5:3762170b6d4d | 154 | |
mbed_official | 5:3762170b6d4d | 155 | /* Apply loop unrolling and compute 8 output values simultaneously. |
mbed_official | 5:3762170b6d4d | 156 | * The variables acc0 ... acc7 hold output values that are being computed: |
mbed_official | 5:3762170b6d4d | 157 | * |
mbed_official | 5:3762170b6d4d | 158 | * 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 | 5:3762170b6d4d | 159 | * 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 | 5:3762170b6d4d | 160 | * 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 | 5:3762170b6d4d | 161 | * 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 | 5:3762170b6d4d | 162 | */ |
mbed_official | 5:3762170b6d4d | 163 | blkCnt = blockSize >> 3; |
mbed_official | 5:3762170b6d4d | 164 | |
mbed_official | 5:3762170b6d4d | 165 | /* First part of the processing with loop unrolling. Compute 8 outputs at a time. |
mbed_official | 5:3762170b6d4d | 166 | ** a second loop below computes the remaining 1 to 7 samples. */ |
mbed_official | 5:3762170b6d4d | 167 | while(blkCnt > 0u) |
mbed_official | 5:3762170b6d4d | 168 | { |
mbed_official | 5:3762170b6d4d | 169 | /* Copy four new input samples into the state buffer */ |
mbed_official | 5:3762170b6d4d | 170 | *pStateCurnt++ = *pSrc++; |
mbed_official | 5:3762170b6d4d | 171 | *pStateCurnt++ = *pSrc++; |
mbed_official | 5:3762170b6d4d | 172 | *pStateCurnt++ = *pSrc++; |
mbed_official | 5:3762170b6d4d | 173 | *pStateCurnt++ = *pSrc++; |
mbed_official | 5:3762170b6d4d | 174 | |
mbed_official | 5:3762170b6d4d | 175 | /* Set all accumulators to zero */ |
mbed_official | 5:3762170b6d4d | 176 | acc0 = 0.0f; |
mbed_official | 5:3762170b6d4d | 177 | acc1 = 0.0f; |
mbed_official | 5:3762170b6d4d | 178 | acc2 = 0.0f; |
mbed_official | 5:3762170b6d4d | 179 | acc3 = 0.0f; |
mbed_official | 5:3762170b6d4d | 180 | acc4 = 0.0f; |
mbed_official | 5:3762170b6d4d | 181 | acc5 = 0.0f; |
mbed_official | 5:3762170b6d4d | 182 | acc6 = 0.0f; |
mbed_official | 5:3762170b6d4d | 183 | acc7 = 0.0f; |
mbed_official | 5:3762170b6d4d | 184 | |
mbed_official | 5:3762170b6d4d | 185 | /* Initialize state pointer */ |
mbed_official | 5:3762170b6d4d | 186 | px = pState; |
mbed_official | 5:3762170b6d4d | 187 | |
mbed_official | 5:3762170b6d4d | 188 | /* Initialize coeff pointer */ |
mbed_official | 5:3762170b6d4d | 189 | pb = (pCoeffs); |
mbed_official | 5:3762170b6d4d | 190 | |
mbed_official | 5:3762170b6d4d | 191 | /* This is separated from the others to avoid |
mbed_official | 5:3762170b6d4d | 192 | * a call to __aeabi_memmove which would be slower |
mbed_official | 5:3762170b6d4d | 193 | */ |
mbed_official | 5:3762170b6d4d | 194 | *pStateCurnt++ = *pSrc++; |
mbed_official | 5:3762170b6d4d | 195 | *pStateCurnt++ = *pSrc++; |
mbed_official | 5:3762170b6d4d | 196 | *pStateCurnt++ = *pSrc++; |
mbed_official | 5:3762170b6d4d | 197 | *pStateCurnt++ = *pSrc++; |
mbed_official | 5:3762170b6d4d | 198 | |
mbed_official | 5:3762170b6d4d | 199 | /* Read the first seven samples from the state buffer: x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2] */ |
mbed_official | 5:3762170b6d4d | 200 | x0 = *px++; |
mbed_official | 5:3762170b6d4d | 201 | x1 = *px++; |
mbed_official | 5:3762170b6d4d | 202 | x2 = *px++; |
mbed_official | 5:3762170b6d4d | 203 | x3 = *px++; |
mbed_official | 5:3762170b6d4d | 204 | x4 = *px++; |
mbed_official | 5:3762170b6d4d | 205 | x5 = *px++; |
mbed_official | 5:3762170b6d4d | 206 | x6 = *px++; |
mbed_official | 5:3762170b6d4d | 207 | |
mbed_official | 5:3762170b6d4d | 208 | /* Loop unrolling. Process 8 taps at a time. */ |
mbed_official | 5:3762170b6d4d | 209 | tapCnt = numTaps >> 3u; |
mbed_official | 5:3762170b6d4d | 210 | |
mbed_official | 5:3762170b6d4d | 211 | /* Loop over the number of taps. Unroll by a factor of 8. |
mbed_official | 5:3762170b6d4d | 212 | ** Repeat until we've computed numTaps-8 coefficients. */ |
mbed_official | 5:3762170b6d4d | 213 | while(tapCnt > 0u) |
mbed_official | 5:3762170b6d4d | 214 | { |
mbed_official | 5:3762170b6d4d | 215 | /* Read the b[numTaps-1] coefficient */ |
mbed_official | 5:3762170b6d4d | 216 | c0 = *(pb++); |
mbed_official | 5:3762170b6d4d | 217 | |
mbed_official | 5:3762170b6d4d | 218 | /* Read x[n-numTaps-3] sample */ |
mbed_official | 5:3762170b6d4d | 219 | x7 = *(px++); |
mbed_official | 5:3762170b6d4d | 220 | |
mbed_official | 5:3762170b6d4d | 221 | /* acc0 += b[numTaps-1] * x[n-numTaps] */ |
mbed_official | 5:3762170b6d4d | 222 | acc0 += x0 * c0; |
mbed_official | 5:3762170b6d4d | 223 | |
mbed_official | 5:3762170b6d4d | 224 | /* acc1 += b[numTaps-1] * x[n-numTaps-1] */ |
mbed_official | 5:3762170b6d4d | 225 | acc1 += x1 * c0; |
mbed_official | 5:3762170b6d4d | 226 | |
mbed_official | 5:3762170b6d4d | 227 | /* acc2 += b[numTaps-1] * x[n-numTaps-2] */ |
mbed_official | 5:3762170b6d4d | 228 | acc2 += x2 * c0; |
mbed_official | 5:3762170b6d4d | 229 | |
mbed_official | 5:3762170b6d4d | 230 | /* acc3 += b[numTaps-1] * x[n-numTaps-3] */ |
mbed_official | 5:3762170b6d4d | 231 | acc3 += x3 * c0; |
mbed_official | 5:3762170b6d4d | 232 | |
mbed_official | 5:3762170b6d4d | 233 | /* acc4 += b[numTaps-1] * x[n-numTaps-4] */ |
mbed_official | 5:3762170b6d4d | 234 | acc4 += x4 * c0; |
mbed_official | 5:3762170b6d4d | 235 | |
mbed_official | 5:3762170b6d4d | 236 | /* acc1 += b[numTaps-1] * x[n-numTaps-5] */ |
mbed_official | 5:3762170b6d4d | 237 | acc5 += x5 * c0; |
mbed_official | 5:3762170b6d4d | 238 | |
mbed_official | 5:3762170b6d4d | 239 | /* acc2 += b[numTaps-1] * x[n-numTaps-6] */ |
mbed_official | 5:3762170b6d4d | 240 | acc6 += x6 * c0; |
mbed_official | 5:3762170b6d4d | 241 | |
mbed_official | 5:3762170b6d4d | 242 | /* acc3 += b[numTaps-1] * x[n-numTaps-7] */ |
mbed_official | 5:3762170b6d4d | 243 | acc7 += x7 * c0; |
mbed_official | 5:3762170b6d4d | 244 | |
mbed_official | 5:3762170b6d4d | 245 | /* Read the b[numTaps-2] coefficient */ |
mbed_official | 5:3762170b6d4d | 246 | c0 = *(pb++); |
mbed_official | 5:3762170b6d4d | 247 | |
mbed_official | 5:3762170b6d4d | 248 | /* Read x[n-numTaps-4] sample */ |
mbed_official | 5:3762170b6d4d | 249 | x0 = *(px++); |
mbed_official | 5:3762170b6d4d | 250 | |
mbed_official | 5:3762170b6d4d | 251 | /* Perform the multiply-accumulate */ |
mbed_official | 5:3762170b6d4d | 252 | acc0 += x1 * c0; |
mbed_official | 5:3762170b6d4d | 253 | acc1 += x2 * c0; |
mbed_official | 5:3762170b6d4d | 254 | acc2 += x3 * c0; |
mbed_official | 5:3762170b6d4d | 255 | acc3 += x4 * c0; |
mbed_official | 5:3762170b6d4d | 256 | acc4 += x5 * c0; |
mbed_official | 5:3762170b6d4d | 257 | acc5 += x6 * c0; |
mbed_official | 5:3762170b6d4d | 258 | acc6 += x7 * c0; |
mbed_official | 5:3762170b6d4d | 259 | acc7 += x0 * c0; |
mbed_official | 5:3762170b6d4d | 260 | |
mbed_official | 5:3762170b6d4d | 261 | /* Read the b[numTaps-3] coefficient */ |
mbed_official | 5:3762170b6d4d | 262 | c0 = *(pb++); |
mbed_official | 5:3762170b6d4d | 263 | |
mbed_official | 5:3762170b6d4d | 264 | /* Read x[n-numTaps-5] sample */ |
mbed_official | 5:3762170b6d4d | 265 | x1 = *(px++); |
mbed_official | 5:3762170b6d4d | 266 | |
mbed_official | 5:3762170b6d4d | 267 | /* Perform the multiply-accumulates */ |
mbed_official | 5:3762170b6d4d | 268 | acc0 += x2 * c0; |
mbed_official | 5:3762170b6d4d | 269 | acc1 += x3 * c0; |
mbed_official | 5:3762170b6d4d | 270 | acc2 += x4 * c0; |
mbed_official | 5:3762170b6d4d | 271 | acc3 += x5 * c0; |
mbed_official | 5:3762170b6d4d | 272 | acc4 += x6 * c0; |
mbed_official | 5:3762170b6d4d | 273 | acc5 += x7 * c0; |
mbed_official | 5:3762170b6d4d | 274 | acc6 += x0 * c0; |
mbed_official | 5:3762170b6d4d | 275 | acc7 += x1 * c0; |
mbed_official | 5:3762170b6d4d | 276 | |
mbed_official | 5:3762170b6d4d | 277 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 5:3762170b6d4d | 278 | c0 = *(pb++); |
mbed_official | 5:3762170b6d4d | 279 | |
mbed_official | 5:3762170b6d4d | 280 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 5:3762170b6d4d | 281 | x2 = *(px++); |
mbed_official | 5:3762170b6d4d | 282 | |
mbed_official | 5:3762170b6d4d | 283 | /* Perform the multiply-accumulates */ |
mbed_official | 5:3762170b6d4d | 284 | acc0 += x3 * c0; |
mbed_official | 5:3762170b6d4d | 285 | acc1 += x4 * c0; |
mbed_official | 5:3762170b6d4d | 286 | acc2 += x5 * c0; |
mbed_official | 5:3762170b6d4d | 287 | acc3 += x6 * c0; |
mbed_official | 5:3762170b6d4d | 288 | acc4 += x7 * c0; |
mbed_official | 5:3762170b6d4d | 289 | acc5 += x0 * c0; |
mbed_official | 5:3762170b6d4d | 290 | acc6 += x1 * c0; |
mbed_official | 5:3762170b6d4d | 291 | acc7 += x2 * c0; |
mbed_official | 5:3762170b6d4d | 292 | |
mbed_official | 5:3762170b6d4d | 293 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 5:3762170b6d4d | 294 | c0 = *(pb++); |
mbed_official | 5:3762170b6d4d | 295 | |
mbed_official | 5:3762170b6d4d | 296 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 5:3762170b6d4d | 297 | x3 = *(px++); |
mbed_official | 5:3762170b6d4d | 298 | /* Perform the multiply-accumulates */ |
mbed_official | 5:3762170b6d4d | 299 | acc0 += x4 * c0; |
mbed_official | 5:3762170b6d4d | 300 | acc1 += x5 * c0; |
mbed_official | 5:3762170b6d4d | 301 | acc2 += x6 * c0; |
mbed_official | 5:3762170b6d4d | 302 | acc3 += x7 * c0; |
mbed_official | 5:3762170b6d4d | 303 | acc4 += x0 * c0; |
mbed_official | 5:3762170b6d4d | 304 | acc5 += x1 * c0; |
mbed_official | 5:3762170b6d4d | 305 | acc6 += x2 * c0; |
mbed_official | 5:3762170b6d4d | 306 | acc7 += x3 * c0; |
mbed_official | 5:3762170b6d4d | 307 | |
mbed_official | 5:3762170b6d4d | 308 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 5:3762170b6d4d | 309 | c0 = *(pb++); |
mbed_official | 5:3762170b6d4d | 310 | |
mbed_official | 5:3762170b6d4d | 311 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 5:3762170b6d4d | 312 | x4 = *(px++); |
mbed_official | 5:3762170b6d4d | 313 | |
mbed_official | 5:3762170b6d4d | 314 | /* Perform the multiply-accumulates */ |
mbed_official | 5:3762170b6d4d | 315 | acc0 += x5 * c0; |
mbed_official | 5:3762170b6d4d | 316 | acc1 += x6 * c0; |
mbed_official | 5:3762170b6d4d | 317 | acc2 += x7 * c0; |
mbed_official | 5:3762170b6d4d | 318 | acc3 += x0 * c0; |
mbed_official | 5:3762170b6d4d | 319 | acc4 += x1 * c0; |
mbed_official | 5:3762170b6d4d | 320 | acc5 += x2 * c0; |
mbed_official | 5:3762170b6d4d | 321 | acc6 += x3 * c0; |
mbed_official | 5:3762170b6d4d | 322 | acc7 += x4 * c0; |
mbed_official | 5:3762170b6d4d | 323 | |
mbed_official | 5:3762170b6d4d | 324 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 5:3762170b6d4d | 325 | c0 = *(pb++); |
mbed_official | 5:3762170b6d4d | 326 | |
mbed_official | 5:3762170b6d4d | 327 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 5:3762170b6d4d | 328 | x5 = *(px++); |
mbed_official | 5:3762170b6d4d | 329 | |
mbed_official | 5:3762170b6d4d | 330 | /* Perform the multiply-accumulates */ |
mbed_official | 5:3762170b6d4d | 331 | acc0 += x6 * c0; |
mbed_official | 5:3762170b6d4d | 332 | acc1 += x7 * c0; |
mbed_official | 5:3762170b6d4d | 333 | acc2 += x0 * c0; |
mbed_official | 5:3762170b6d4d | 334 | acc3 += x1 * c0; |
mbed_official | 5:3762170b6d4d | 335 | acc4 += x2 * c0; |
mbed_official | 5:3762170b6d4d | 336 | acc5 += x3 * c0; |
mbed_official | 5:3762170b6d4d | 337 | acc6 += x4 * c0; |
mbed_official | 5:3762170b6d4d | 338 | acc7 += x5 * c0; |
mbed_official | 5:3762170b6d4d | 339 | |
mbed_official | 5:3762170b6d4d | 340 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 5:3762170b6d4d | 341 | c0 = *(pb++); |
mbed_official | 5:3762170b6d4d | 342 | |
mbed_official | 5:3762170b6d4d | 343 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 5:3762170b6d4d | 344 | x6 = *(px++); |
mbed_official | 5:3762170b6d4d | 345 | |
mbed_official | 5:3762170b6d4d | 346 | /* Perform the multiply-accumulates */ |
mbed_official | 5:3762170b6d4d | 347 | acc0 += x7 * c0; |
mbed_official | 5:3762170b6d4d | 348 | acc1 += x0 * c0; |
mbed_official | 5:3762170b6d4d | 349 | acc2 += x1 * c0; |
mbed_official | 5:3762170b6d4d | 350 | acc3 += x2 * c0; |
mbed_official | 5:3762170b6d4d | 351 | acc4 += x3 * c0; |
mbed_official | 5:3762170b6d4d | 352 | acc5 += x4 * c0; |
mbed_official | 5:3762170b6d4d | 353 | acc6 += x5 * c0; |
mbed_official | 5:3762170b6d4d | 354 | acc7 += x6 * c0; |
mbed_official | 5:3762170b6d4d | 355 | |
mbed_official | 5:3762170b6d4d | 356 | tapCnt--; |
mbed_official | 5:3762170b6d4d | 357 | } |
mbed_official | 5:3762170b6d4d | 358 | |
mbed_official | 5:3762170b6d4d | 359 | /* If the filter length is not a multiple of 8, compute the remaining filter taps */ |
mbed_official | 5:3762170b6d4d | 360 | tapCnt = numTaps % 0x8u; |
mbed_official | 5:3762170b6d4d | 361 | |
mbed_official | 5:3762170b6d4d | 362 | while(tapCnt > 0u) |
mbed_official | 5:3762170b6d4d | 363 | { |
mbed_official | 5:3762170b6d4d | 364 | /* Read coefficients */ |
mbed_official | 5:3762170b6d4d | 365 | c0 = *(pb++); |
mbed_official | 5:3762170b6d4d | 366 | |
mbed_official | 5:3762170b6d4d | 367 | /* Fetch 1 state variable */ |
mbed_official | 5:3762170b6d4d | 368 | x7 = *(px++); |
mbed_official | 5:3762170b6d4d | 369 | |
mbed_official | 5:3762170b6d4d | 370 | /* Perform the multiply-accumulates */ |
mbed_official | 5:3762170b6d4d | 371 | acc0 += x0 * c0; |
mbed_official | 5:3762170b6d4d | 372 | acc1 += x1 * c0; |
mbed_official | 5:3762170b6d4d | 373 | acc2 += x2 * c0; |
mbed_official | 5:3762170b6d4d | 374 | acc3 += x3 * c0; |
mbed_official | 5:3762170b6d4d | 375 | acc4 += x4 * c0; |
mbed_official | 5:3762170b6d4d | 376 | acc5 += x5 * c0; |
mbed_official | 5:3762170b6d4d | 377 | acc6 += x6 * c0; |
mbed_official | 5:3762170b6d4d | 378 | acc7 += x7 * c0; |
mbed_official | 5:3762170b6d4d | 379 | |
mbed_official | 5:3762170b6d4d | 380 | /* Reuse the present sample states for next sample */ |
mbed_official | 5:3762170b6d4d | 381 | x0 = x1; |
mbed_official | 5:3762170b6d4d | 382 | x1 = x2; |
mbed_official | 5:3762170b6d4d | 383 | x2 = x3; |
mbed_official | 5:3762170b6d4d | 384 | x3 = x4; |
mbed_official | 5:3762170b6d4d | 385 | x4 = x5; |
mbed_official | 5:3762170b6d4d | 386 | x5 = x6; |
mbed_official | 5:3762170b6d4d | 387 | x6 = x7; |
mbed_official | 5:3762170b6d4d | 388 | |
mbed_official | 5:3762170b6d4d | 389 | /* Decrement the loop counter */ |
mbed_official | 5:3762170b6d4d | 390 | tapCnt--; |
mbed_official | 5:3762170b6d4d | 391 | } |
mbed_official | 5:3762170b6d4d | 392 | |
mbed_official | 5:3762170b6d4d | 393 | /* Advance the state pointer by 8 to process the next group of 8 samples */ |
mbed_official | 5:3762170b6d4d | 394 | pState = pState + 8; |
mbed_official | 5:3762170b6d4d | 395 | |
mbed_official | 5:3762170b6d4d | 396 | /* The results in the 8 accumulators, store in the destination buffer. */ |
mbed_official | 5:3762170b6d4d | 397 | *pDst++ = acc0; |
mbed_official | 5:3762170b6d4d | 398 | *pDst++ = acc1; |
mbed_official | 5:3762170b6d4d | 399 | *pDst++ = acc2; |
mbed_official | 5:3762170b6d4d | 400 | *pDst++ = acc3; |
mbed_official | 5:3762170b6d4d | 401 | *pDst++ = acc4; |
mbed_official | 5:3762170b6d4d | 402 | *pDst++ = acc5; |
mbed_official | 5:3762170b6d4d | 403 | *pDst++ = acc6; |
mbed_official | 5:3762170b6d4d | 404 | *pDst++ = acc7; |
mbed_official | 5:3762170b6d4d | 405 | |
mbed_official | 5:3762170b6d4d | 406 | blkCnt--; |
mbed_official | 5:3762170b6d4d | 407 | } |
mbed_official | 5:3762170b6d4d | 408 | |
mbed_official | 5:3762170b6d4d | 409 | /* If the blockSize is not a multiple of 8, compute any remaining output samples here. |
mbed_official | 5:3762170b6d4d | 410 | ** No loop unrolling is used. */ |
mbed_official | 5:3762170b6d4d | 411 | blkCnt = blockSize % 0x8u; |
mbed_official | 5:3762170b6d4d | 412 | |
mbed_official | 5:3762170b6d4d | 413 | while(blkCnt > 0u) |
mbed_official | 5:3762170b6d4d | 414 | { |
mbed_official | 5:3762170b6d4d | 415 | /* Copy one sample at a time into state buffer */ |
mbed_official | 5:3762170b6d4d | 416 | *pStateCurnt++ = *pSrc++; |
mbed_official | 5:3762170b6d4d | 417 | |
mbed_official | 5:3762170b6d4d | 418 | /* Set the accumulator to zero */ |
mbed_official | 5:3762170b6d4d | 419 | acc0 = 0.0f; |
mbed_official | 5:3762170b6d4d | 420 | |
mbed_official | 5:3762170b6d4d | 421 | /* Initialize state pointer */ |
mbed_official | 5:3762170b6d4d | 422 | px = pState; |
mbed_official | 5:3762170b6d4d | 423 | |
mbed_official | 5:3762170b6d4d | 424 | /* Initialize Coefficient pointer */ |
mbed_official | 5:3762170b6d4d | 425 | pb = (pCoeffs); |
mbed_official | 5:3762170b6d4d | 426 | |
mbed_official | 5:3762170b6d4d | 427 | i = numTaps; |
mbed_official | 5:3762170b6d4d | 428 | |
mbed_official | 5:3762170b6d4d | 429 | /* Perform the multiply-accumulates */ |
mbed_official | 5:3762170b6d4d | 430 | do |
mbed_official | 5:3762170b6d4d | 431 | { |
mbed_official | 5:3762170b6d4d | 432 | acc0 += *px++ * *pb++; |
mbed_official | 5:3762170b6d4d | 433 | i--; |
mbed_official | 5:3762170b6d4d | 434 | |
mbed_official | 5:3762170b6d4d | 435 | } while(i > 0u); |
mbed_official | 5:3762170b6d4d | 436 | |
mbed_official | 5:3762170b6d4d | 437 | /* The result is store in the destination buffer. */ |
mbed_official | 5:3762170b6d4d | 438 | *pDst++ = acc0; |
mbed_official | 5:3762170b6d4d | 439 | |
mbed_official | 5:3762170b6d4d | 440 | /* Advance state pointer by 1 for the next sample */ |
mbed_official | 5:3762170b6d4d | 441 | pState = pState + 1; |
mbed_official | 5:3762170b6d4d | 442 | |
mbed_official | 5:3762170b6d4d | 443 | blkCnt--; |
mbed_official | 5:3762170b6d4d | 444 | } |
mbed_official | 5:3762170b6d4d | 445 | |
mbed_official | 5:3762170b6d4d | 446 | /* Processing is complete. |
mbed_official | 5:3762170b6d4d | 447 | ** Now copy the last numTaps - 1 samples to the start of the state buffer. |
mbed_official | 5:3762170b6d4d | 448 | ** This prepares the state buffer for the next function call. */ |
mbed_official | 5:3762170b6d4d | 449 | |
mbed_official | 5:3762170b6d4d | 450 | /* Points to the start of the state buffer */ |
mbed_official | 5:3762170b6d4d | 451 | pStateCurnt = S->pState; |
mbed_official | 5:3762170b6d4d | 452 | |
mbed_official | 5:3762170b6d4d | 453 | tapCnt = (numTaps - 1u) >> 2u; |
mbed_official | 5:3762170b6d4d | 454 | |
mbed_official | 5:3762170b6d4d | 455 | /* copy data */ |
mbed_official | 5:3762170b6d4d | 456 | while(tapCnt > 0u) |
mbed_official | 5:3762170b6d4d | 457 | { |
mbed_official | 5:3762170b6d4d | 458 | *pStateCurnt++ = *pState++; |
mbed_official | 5:3762170b6d4d | 459 | *pStateCurnt++ = *pState++; |
mbed_official | 5:3762170b6d4d | 460 | *pStateCurnt++ = *pState++; |
mbed_official | 5:3762170b6d4d | 461 | *pStateCurnt++ = *pState++; |
mbed_official | 5:3762170b6d4d | 462 | |
mbed_official | 5:3762170b6d4d | 463 | /* Decrement the loop counter */ |
mbed_official | 5:3762170b6d4d | 464 | tapCnt--; |
mbed_official | 5:3762170b6d4d | 465 | } |
mbed_official | 5:3762170b6d4d | 466 | |
mbed_official | 5:3762170b6d4d | 467 | /* Calculate remaining number of copies */ |
mbed_official | 5:3762170b6d4d | 468 | tapCnt = (numTaps - 1u) % 0x4u; |
mbed_official | 5:3762170b6d4d | 469 | |
mbed_official | 5:3762170b6d4d | 470 | /* Copy the remaining q31_t data */ |
mbed_official | 5:3762170b6d4d | 471 | while(tapCnt > 0u) |
mbed_official | 5:3762170b6d4d | 472 | { |
mbed_official | 5:3762170b6d4d | 473 | *pStateCurnt++ = *pState++; |
mbed_official | 5:3762170b6d4d | 474 | |
mbed_official | 5:3762170b6d4d | 475 | /* Decrement the loop counter */ |
mbed_official | 5:3762170b6d4d | 476 | tapCnt--; |
mbed_official | 5:3762170b6d4d | 477 | } |
mbed_official | 5:3762170b6d4d | 478 | } |
mbed_official | 5:3762170b6d4d | 479 | |
mbed_official | 5:3762170b6d4d | 480 | #elif defined(ARM_MATH_CM0_FAMILY) |
mbed_official | 5:3762170b6d4d | 481 | |
mbed_official | 5:3762170b6d4d | 482 | void arm_fir_f32( |
mbed_official | 5:3762170b6d4d | 483 | const arm_fir_instance_f32 * S, |
mbed_official | 5:3762170b6d4d | 484 | float32_t * pSrc, |
mbed_official | 5:3762170b6d4d | 485 | float32_t * pDst, |
mbed_official | 5:3762170b6d4d | 486 | uint32_t blockSize) |
mbed_official | 5:3762170b6d4d | 487 | { |
mbed_official | 5:3762170b6d4d | 488 | float32_t *pState = S->pState; /* State pointer */ |
mbed_official | 5:3762170b6d4d | 489 | float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
mbed_official | 5:3762170b6d4d | 490 | float32_t *pStateCurnt; /* Points to the current sample of the state */ |
mbed_official | 5:3762170b6d4d | 491 | float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */ |
mbed_official | 5:3762170b6d4d | 492 | uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ |
mbed_official | 5:3762170b6d4d | 493 | uint32_t i, tapCnt, blkCnt; /* Loop counters */ |
mbed_official | 5:3762170b6d4d | 494 | |
mbed_official | 5:3762170b6d4d | 495 | /* Run the below code for Cortex-M0 */ |
mbed_official | 5:3762170b6d4d | 496 | |
mbed_official | 5:3762170b6d4d | 497 | float32_t acc; |
mbed_official | 5:3762170b6d4d | 498 | |
mbed_official | 5:3762170b6d4d | 499 | /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ |
mbed_official | 5:3762170b6d4d | 500 | /* pStateCurnt points to the location where the new input data should be written */ |
mbed_official | 5:3762170b6d4d | 501 | pStateCurnt = &(S->pState[(numTaps - 1u)]); |
mbed_official | 5:3762170b6d4d | 502 | |
mbed_official | 5:3762170b6d4d | 503 | /* Initialize blkCnt with blockSize */ |
mbed_official | 5:3762170b6d4d | 504 | blkCnt = blockSize; |
mbed_official | 5:3762170b6d4d | 505 | |
mbed_official | 5:3762170b6d4d | 506 | while(blkCnt > 0u) |
mbed_official | 5:3762170b6d4d | 507 | { |
mbed_official | 5:3762170b6d4d | 508 | /* Copy one sample at a time into state buffer */ |
mbed_official | 5:3762170b6d4d | 509 | *pStateCurnt++ = *pSrc++; |
mbed_official | 5:3762170b6d4d | 510 | |
mbed_official | 5:3762170b6d4d | 511 | /* Set the accumulator to zero */ |
mbed_official | 5:3762170b6d4d | 512 | acc = 0.0f; |
mbed_official | 5:3762170b6d4d | 513 | |
mbed_official | 5:3762170b6d4d | 514 | /* Initialize state pointer */ |
mbed_official | 5:3762170b6d4d | 515 | px = pState; |
mbed_official | 5:3762170b6d4d | 516 | |
mbed_official | 5:3762170b6d4d | 517 | /* Initialize Coefficient pointer */ |
mbed_official | 5:3762170b6d4d | 518 | pb = pCoeffs; |
mbed_official | 5:3762170b6d4d | 519 | |
mbed_official | 5:3762170b6d4d | 520 | i = numTaps; |
mbed_official | 5:3762170b6d4d | 521 | |
mbed_official | 5:3762170b6d4d | 522 | /* Perform the multiply-accumulates */ |
mbed_official | 5:3762170b6d4d | 523 | do |
mbed_official | 5:3762170b6d4d | 524 | { |
mbed_official | 5:3762170b6d4d | 525 | /* 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 | 5:3762170b6d4d | 526 | acc += *px++ * *pb++; |
mbed_official | 5:3762170b6d4d | 527 | i--; |
mbed_official | 5:3762170b6d4d | 528 | |
mbed_official | 5:3762170b6d4d | 529 | } while(i > 0u); |
mbed_official | 5:3762170b6d4d | 530 | |
mbed_official | 5:3762170b6d4d | 531 | /* The result is store in the destination buffer. */ |
mbed_official | 5:3762170b6d4d | 532 | *pDst++ = acc; |
mbed_official | 5:3762170b6d4d | 533 | |
mbed_official | 5:3762170b6d4d | 534 | /* Advance state pointer by 1 for the next sample */ |
mbed_official | 5:3762170b6d4d | 535 | pState = pState + 1; |
mbed_official | 5:3762170b6d4d | 536 | |
mbed_official | 5:3762170b6d4d | 537 | blkCnt--; |
mbed_official | 5:3762170b6d4d | 538 | } |
mbed_official | 5:3762170b6d4d | 539 | |
mbed_official | 5:3762170b6d4d | 540 | /* Processing is complete. |
mbed_official | 5:3762170b6d4d | 541 | ** Now copy the last numTaps - 1 samples to the starting of the state buffer. |
mbed_official | 5:3762170b6d4d | 542 | ** This prepares the state buffer for the next function call. */ |
mbed_official | 5:3762170b6d4d | 543 | |
mbed_official | 5:3762170b6d4d | 544 | /* Points to the start of the state buffer */ |
mbed_official | 5:3762170b6d4d | 545 | pStateCurnt = S->pState; |
mbed_official | 5:3762170b6d4d | 546 | |
mbed_official | 5:3762170b6d4d | 547 | /* Copy numTaps number of values */ |
mbed_official | 5:3762170b6d4d | 548 | tapCnt = numTaps - 1u; |
mbed_official | 5:3762170b6d4d | 549 | |
mbed_official | 5:3762170b6d4d | 550 | /* Copy data */ |
mbed_official | 5:3762170b6d4d | 551 | while(tapCnt > 0u) |
mbed_official | 5:3762170b6d4d | 552 | { |
mbed_official | 5:3762170b6d4d | 553 | *pStateCurnt++ = *pState++; |
mbed_official | 5:3762170b6d4d | 554 | |
mbed_official | 5:3762170b6d4d | 555 | /* Decrement the loop counter */ |
mbed_official | 5:3762170b6d4d | 556 | tapCnt--; |
mbed_official | 5:3762170b6d4d | 557 | } |
mbed_official | 5:3762170b6d4d | 558 | |
mbed_official | 5:3762170b6d4d | 559 | } |
mbed_official | 5:3762170b6d4d | 560 | |
mbed_official | 5:3762170b6d4d | 561 | #else |
emilmont | 1:fdd22bb7aa52 | 562 | |
mbed_official | 3:7a284390b0ce | 563 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emilmont | 1:fdd22bb7aa52 | 564 | |
emilmont | 1:fdd22bb7aa52 | 565 | void arm_fir_f32( |
mbed_official | 3:7a284390b0ce | 566 | const arm_fir_instance_f32 * S, |
mbed_official | 3:7a284390b0ce | 567 | float32_t * pSrc, |
mbed_official | 3:7a284390b0ce | 568 | float32_t * pDst, |
mbed_official | 3:7a284390b0ce | 569 | uint32_t blockSize) |
emilmont | 1:fdd22bb7aa52 | 570 | { |
mbed_official | 3:7a284390b0ce | 571 | float32_t *pState = S->pState; /* State pointer */ |
mbed_official | 3:7a284390b0ce | 572 | float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
mbed_official | 3:7a284390b0ce | 573 | float32_t *pStateCurnt; /* Points to the current sample of the state */ |
mbed_official | 3:7a284390b0ce | 574 | float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */ |
mbed_official | 3:7a284390b0ce | 575 | float32_t acc0, acc1, acc2, acc3, acc4, acc5, acc6, acc7; /* Accumulators */ |
mbed_official | 3:7a284390b0ce | 576 | float32_t x0, x1, x2, x3, x4, x5, x6, x7, c0; /* Temporary variables to hold state and coefficient values */ |
mbed_official | 3:7a284390b0ce | 577 | uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ |
mbed_official | 3:7a284390b0ce | 578 | uint32_t i, tapCnt, blkCnt; /* Loop counters */ |
mbed_official | 3:7a284390b0ce | 579 | float32_t p0,p1,p2,p3,p4,p5,p6,p7; /* Temporary product values */ |
mbed_official | 3:7a284390b0ce | 580 | |
mbed_official | 3:7a284390b0ce | 581 | /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ |
mbed_official | 3:7a284390b0ce | 582 | /* pStateCurnt points to the location where the new input data should be written */ |
mbed_official | 3:7a284390b0ce | 583 | pStateCurnt = &(S->pState[(numTaps - 1u)]); |
mbed_official | 3:7a284390b0ce | 584 | |
mbed_official | 3:7a284390b0ce | 585 | /* Apply loop unrolling and compute 8 output values simultaneously. |
mbed_official | 3:7a284390b0ce | 586 | * The variables acc0 ... acc7 hold output values that are being computed: |
mbed_official | 3:7a284390b0ce | 587 | * |
mbed_official | 3:7a284390b0ce | 588 | * 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 | 589 | * 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 | 590 | * 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 | 591 | * 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 | 592 | */ |
mbed_official | 3:7a284390b0ce | 593 | blkCnt = blockSize >> 3; |
mbed_official | 3:7a284390b0ce | 594 | |
mbed_official | 3:7a284390b0ce | 595 | /* First part of the processing with loop unrolling. Compute 8 outputs at a time. |
mbed_official | 3:7a284390b0ce | 596 | ** a second loop below computes the remaining 1 to 7 samples. */ |
mbed_official | 3:7a284390b0ce | 597 | while(blkCnt > 0u) |
mbed_official | 3:7a284390b0ce | 598 | { |
mbed_official | 3:7a284390b0ce | 599 | /* Copy four new input samples into the state buffer */ |
mbed_official | 3:7a284390b0ce | 600 | *pStateCurnt++ = *pSrc++; |
mbed_official | 3:7a284390b0ce | 601 | *pStateCurnt++ = *pSrc++; |
mbed_official | 3:7a284390b0ce | 602 | *pStateCurnt++ = *pSrc++; |
mbed_official | 3:7a284390b0ce | 603 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 604 | |
mbed_official | 3:7a284390b0ce | 605 | /* Set all accumulators to zero */ |
mbed_official | 3:7a284390b0ce | 606 | acc0 = 0.0f; |
mbed_official | 3:7a284390b0ce | 607 | acc1 = 0.0f; |
mbed_official | 3:7a284390b0ce | 608 | acc2 = 0.0f; |
mbed_official | 3:7a284390b0ce | 609 | acc3 = 0.0f; |
mbed_official | 3:7a284390b0ce | 610 | acc4 = 0.0f; |
mbed_official | 3:7a284390b0ce | 611 | acc5 = 0.0f; |
mbed_official | 3:7a284390b0ce | 612 | acc6 = 0.0f; |
mbed_official | 3:7a284390b0ce | 613 | acc7 = 0.0f; |
mbed_official | 3:7a284390b0ce | 614 | |
mbed_official | 3:7a284390b0ce | 615 | /* Initialize state pointer */ |
mbed_official | 3:7a284390b0ce | 616 | px = pState; |
mbed_official | 3:7a284390b0ce | 617 | |
mbed_official | 3:7a284390b0ce | 618 | /* Initialize coeff pointer */ |
mbed_official | 3:7a284390b0ce | 619 | pb = (pCoeffs); |
mbed_official | 3:7a284390b0ce | 620 | |
mbed_official | 3:7a284390b0ce | 621 | /* This is separated from the others to avoid |
mbed_official | 3:7a284390b0ce | 622 | * a call to __aeabi_memmove which would be slower |
mbed_official | 3:7a284390b0ce | 623 | */ |
mbed_official | 3:7a284390b0ce | 624 | *pStateCurnt++ = *pSrc++; |
mbed_official | 3:7a284390b0ce | 625 | *pStateCurnt++ = *pSrc++; |
mbed_official | 3:7a284390b0ce | 626 | *pStateCurnt++ = *pSrc++; |
mbed_official | 3:7a284390b0ce | 627 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 628 | |
mbed_official | 3:7a284390b0ce | 629 | /* Read the first seven samples from the state buffer: x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2] */ |
mbed_official | 3:7a284390b0ce | 630 | x0 = *px++; |
mbed_official | 3:7a284390b0ce | 631 | x1 = *px++; |
mbed_official | 3:7a284390b0ce | 632 | x2 = *px++; |
mbed_official | 3:7a284390b0ce | 633 | x3 = *px++; |
mbed_official | 3:7a284390b0ce | 634 | x4 = *px++; |
mbed_official | 3:7a284390b0ce | 635 | x5 = *px++; |
mbed_official | 3:7a284390b0ce | 636 | x6 = *px++; |
mbed_official | 3:7a284390b0ce | 637 | |
mbed_official | 3:7a284390b0ce | 638 | /* Loop unrolling. Process 8 taps at a time. */ |
mbed_official | 3:7a284390b0ce | 639 | tapCnt = numTaps >> 3u; |
mbed_official | 3:7a284390b0ce | 640 | |
mbed_official | 3:7a284390b0ce | 641 | /* Loop over the number of taps. Unroll by a factor of 8. |
mbed_official | 3:7a284390b0ce | 642 | ** Repeat until we've computed numTaps-8 coefficients. */ |
mbed_official | 3:7a284390b0ce | 643 | while(tapCnt > 0u) |
mbed_official | 3:7a284390b0ce | 644 | { |
mbed_official | 3:7a284390b0ce | 645 | /* Read the b[numTaps-1] coefficient */ |
mbed_official | 3:7a284390b0ce | 646 | c0 = *(pb++); |
mbed_official | 3:7a284390b0ce | 647 | |
mbed_official | 3:7a284390b0ce | 648 | /* Read x[n-numTaps-3] sample */ |
mbed_official | 3:7a284390b0ce | 649 | x7 = *(px++); |
mbed_official | 3:7a284390b0ce | 650 | |
mbed_official | 3:7a284390b0ce | 651 | /* acc0 += b[numTaps-1] * x[n-numTaps] */ |
mbed_official | 3:7a284390b0ce | 652 | p0 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 653 | |
mbed_official | 3:7a284390b0ce | 654 | /* acc1 += b[numTaps-1] * x[n-numTaps-1] */ |
mbed_official | 3:7a284390b0ce | 655 | p1 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 656 | |
mbed_official | 3:7a284390b0ce | 657 | /* acc2 += b[numTaps-1] * x[n-numTaps-2] */ |
mbed_official | 3:7a284390b0ce | 658 | p2 = x2 * c0; |
emilmont | 1:fdd22bb7aa52 | 659 | |
mbed_official | 3:7a284390b0ce | 660 | /* acc3 += b[numTaps-1] * x[n-numTaps-3] */ |
mbed_official | 3:7a284390b0ce | 661 | p3 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 662 | |
mbed_official | 3:7a284390b0ce | 663 | /* acc4 += b[numTaps-1] * x[n-numTaps-4] */ |
mbed_official | 3:7a284390b0ce | 664 | p4 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 665 | |
mbed_official | 3:7a284390b0ce | 666 | /* acc1 += b[numTaps-1] * x[n-numTaps-5] */ |
mbed_official | 3:7a284390b0ce | 667 | p5 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 668 | |
mbed_official | 3:7a284390b0ce | 669 | /* acc2 += b[numTaps-1] * x[n-numTaps-6] */ |
mbed_official | 3:7a284390b0ce | 670 | p6 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 671 | |
mbed_official | 3:7a284390b0ce | 672 | /* acc3 += b[numTaps-1] * x[n-numTaps-7] */ |
mbed_official | 3:7a284390b0ce | 673 | p7 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 674 | |
mbed_official | 3:7a284390b0ce | 675 | /* Read the b[numTaps-2] coefficient */ |
mbed_official | 3:7a284390b0ce | 676 | c0 = *(pb++); |
mbed_official | 3:7a284390b0ce | 677 | |
mbed_official | 3:7a284390b0ce | 678 | /* Read x[n-numTaps-4] sample */ |
mbed_official | 3:7a284390b0ce | 679 | x0 = *(px++); |
mbed_official | 3:7a284390b0ce | 680 | |
mbed_official | 3:7a284390b0ce | 681 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 682 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 683 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 684 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 685 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 686 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 687 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 688 | acc7 += p7; |
mbed_official | 3:7a284390b0ce | 689 | |
mbed_official | 3:7a284390b0ce | 690 | |
mbed_official | 3:7a284390b0ce | 691 | /* Perform the multiply-accumulate */ |
mbed_official | 3:7a284390b0ce | 692 | p0 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 693 | p1 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 694 | p2 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 695 | p3 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 696 | p4 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 697 | p5 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 698 | p6 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 699 | p7 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 700 | |
mbed_official | 3:7a284390b0ce | 701 | /* Read the b[numTaps-3] coefficient */ |
mbed_official | 3:7a284390b0ce | 702 | c0 = *(pb++); |
emilmont | 1:fdd22bb7aa52 | 703 | |
mbed_official | 3:7a284390b0ce | 704 | /* Read x[n-numTaps-5] sample */ |
mbed_official | 3:7a284390b0ce | 705 | x1 = *(px++); |
mbed_official | 3:7a284390b0ce | 706 | |
mbed_official | 3:7a284390b0ce | 707 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 708 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 709 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 710 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 711 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 712 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 713 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 714 | acc7 += p7; |
mbed_official | 3:7a284390b0ce | 715 | |
mbed_official | 3:7a284390b0ce | 716 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 717 | p0 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 718 | p1 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 719 | p2 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 720 | p3 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 721 | p4 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 722 | p5 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 723 | p6 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 724 | p7 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 725 | |
mbed_official | 3:7a284390b0ce | 726 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 3:7a284390b0ce | 727 | c0 = *(pb++); |
emilmont | 1:fdd22bb7aa52 | 728 | |
mbed_official | 3:7a284390b0ce | 729 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 3:7a284390b0ce | 730 | x2 = *(px++); |
mbed_official | 3:7a284390b0ce | 731 | |
mbed_official | 3:7a284390b0ce | 732 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 733 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 734 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 735 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 736 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 737 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 738 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 739 | acc7 += p7; |
emilmont | 1:fdd22bb7aa52 | 740 | |
mbed_official | 3:7a284390b0ce | 741 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 742 | p0 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 743 | p1 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 744 | p2 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 745 | p3 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 746 | p4 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 747 | p5 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 748 | p6 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 749 | p7 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 750 | |
mbed_official | 3:7a284390b0ce | 751 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 3:7a284390b0ce | 752 | c0 = *(pb++); |
emilmont | 1:fdd22bb7aa52 | 753 | |
mbed_official | 3:7a284390b0ce | 754 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 3:7a284390b0ce | 755 | x3 = *(px++); |
mbed_official | 3:7a284390b0ce | 756 | |
mbed_official | 3:7a284390b0ce | 757 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 758 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 759 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 760 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 761 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 762 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 763 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 764 | acc7 += p7; |
emilmont | 1:fdd22bb7aa52 | 765 | |
mbed_official | 3:7a284390b0ce | 766 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 767 | p0 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 768 | p1 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 769 | p2 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 770 | p3 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 771 | p4 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 772 | p5 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 773 | p6 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 774 | p7 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 775 | |
mbed_official | 3:7a284390b0ce | 776 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 3:7a284390b0ce | 777 | c0 = *(pb++); |
mbed_official | 3:7a284390b0ce | 778 | |
mbed_official | 3:7a284390b0ce | 779 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 3:7a284390b0ce | 780 | x4 = *(px++); |
mbed_official | 3:7a284390b0ce | 781 | |
mbed_official | 3:7a284390b0ce | 782 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 783 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 784 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 785 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 786 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 787 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 788 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 789 | acc7 += p7; |
emilmont | 1:fdd22bb7aa52 | 790 | |
mbed_official | 3:7a284390b0ce | 791 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 792 | p0 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 793 | p1 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 794 | p2 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 795 | p3 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 796 | p4 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 797 | p5 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 798 | p6 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 799 | p7 = x4 * c0; |
emilmont | 1:fdd22bb7aa52 | 800 | |
mbed_official | 3:7a284390b0ce | 801 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 3:7a284390b0ce | 802 | c0 = *(pb++); |
mbed_official | 3:7a284390b0ce | 803 | |
mbed_official | 3:7a284390b0ce | 804 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 3:7a284390b0ce | 805 | x5 = *(px++); |
mbed_official | 3:7a284390b0ce | 806 | |
mbed_official | 3:7a284390b0ce | 807 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 808 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 809 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 810 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 811 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 812 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 813 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 814 | acc7 += p7; |
emilmont | 1:fdd22bb7aa52 | 815 | |
mbed_official | 3:7a284390b0ce | 816 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 817 | p0 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 818 | p1 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 819 | p2 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 820 | p3 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 821 | p4 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 822 | p5 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 823 | p6 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 824 | p7 = x5 * c0; |
emilmont | 1:fdd22bb7aa52 | 825 | |
mbed_official | 3:7a284390b0ce | 826 | /* Read the b[numTaps-4] coefficient */ |
mbed_official | 3:7a284390b0ce | 827 | c0 = *(pb++); |
emilmont | 1:fdd22bb7aa52 | 828 | |
mbed_official | 3:7a284390b0ce | 829 | /* Read x[n-numTaps-6] sample */ |
mbed_official | 3:7a284390b0ce | 830 | x6 = *(px++); |
mbed_official | 3:7a284390b0ce | 831 | |
mbed_official | 3:7a284390b0ce | 832 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 833 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 834 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 835 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 836 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 837 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 838 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 839 | acc7 += p7; |
emilmont | 1:fdd22bb7aa52 | 840 | |
mbed_official | 3:7a284390b0ce | 841 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 842 | p0 = x7 * c0; |
mbed_official | 3:7a284390b0ce | 843 | p1 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 844 | p2 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 845 | p3 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 846 | p4 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 847 | p5 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 848 | p6 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 849 | p7 = x6 * c0; |
emilmont | 1:fdd22bb7aa52 | 850 | |
mbed_official | 3:7a284390b0ce | 851 | tapCnt--; |
mbed_official | 3:7a284390b0ce | 852 | |
mbed_official | 3:7a284390b0ce | 853 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 854 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 855 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 856 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 857 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 858 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 859 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 860 | acc7 += p7; |
mbed_official | 3:7a284390b0ce | 861 | } |
mbed_official | 3:7a284390b0ce | 862 | |
mbed_official | 3:7a284390b0ce | 863 | /* If the filter length is not a multiple of 8, compute the remaining filter taps */ |
mbed_official | 3:7a284390b0ce | 864 | tapCnt = numTaps % 0x8u; |
emilmont | 1:fdd22bb7aa52 | 865 | |
mbed_official | 3:7a284390b0ce | 866 | while(tapCnt > 0u) |
mbed_official | 3:7a284390b0ce | 867 | { |
mbed_official | 3:7a284390b0ce | 868 | /* Read coefficients */ |
mbed_official | 3:7a284390b0ce | 869 | c0 = *(pb++); |
mbed_official | 3:7a284390b0ce | 870 | |
mbed_official | 3:7a284390b0ce | 871 | /* Fetch 1 state variable */ |
mbed_official | 3:7a284390b0ce | 872 | x7 = *(px++); |
emilmont | 1:fdd22bb7aa52 | 873 | |
mbed_official | 3:7a284390b0ce | 874 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 875 | p0 = x0 * c0; |
mbed_official | 3:7a284390b0ce | 876 | p1 = x1 * c0; |
mbed_official | 3:7a284390b0ce | 877 | p2 = x2 * c0; |
mbed_official | 3:7a284390b0ce | 878 | p3 = x3 * c0; |
mbed_official | 3:7a284390b0ce | 879 | p4 = x4 * c0; |
mbed_official | 3:7a284390b0ce | 880 | p5 = x5 * c0; |
mbed_official | 3:7a284390b0ce | 881 | p6 = x6 * c0; |
mbed_official | 3:7a284390b0ce | 882 | p7 = x7 * c0; |
emilmont | 1:fdd22bb7aa52 | 883 | |
mbed_official | 3:7a284390b0ce | 884 | /* Reuse the present sample states for next sample */ |
mbed_official | 3:7a284390b0ce | 885 | x0 = x1; |
mbed_official | 3:7a284390b0ce | 886 | x1 = x2; |
mbed_official | 3:7a284390b0ce | 887 | x2 = x3; |
mbed_official | 3:7a284390b0ce | 888 | x3 = x4; |
mbed_official | 3:7a284390b0ce | 889 | x4 = x5; |
mbed_official | 3:7a284390b0ce | 890 | x5 = x6; |
mbed_official | 3:7a284390b0ce | 891 | x6 = x7; |
mbed_official | 3:7a284390b0ce | 892 | |
mbed_official | 3:7a284390b0ce | 893 | acc0 += p0; |
mbed_official | 3:7a284390b0ce | 894 | acc1 += p1; |
mbed_official | 3:7a284390b0ce | 895 | acc2 += p2; |
mbed_official | 3:7a284390b0ce | 896 | acc3 += p3; |
mbed_official | 3:7a284390b0ce | 897 | acc4 += p4; |
mbed_official | 3:7a284390b0ce | 898 | acc5 += p5; |
mbed_official | 3:7a284390b0ce | 899 | acc6 += p6; |
mbed_official | 3:7a284390b0ce | 900 | acc7 += p7; |
mbed_official | 3:7a284390b0ce | 901 | |
mbed_official | 3:7a284390b0ce | 902 | /* Decrement the loop counter */ |
mbed_official | 3:7a284390b0ce | 903 | tapCnt--; |
mbed_official | 3:7a284390b0ce | 904 | } |
mbed_official | 3:7a284390b0ce | 905 | |
mbed_official | 3:7a284390b0ce | 906 | /* Advance the state pointer by 8 to process the next group of 8 samples */ |
mbed_official | 3:7a284390b0ce | 907 | pState = pState + 8; |
emilmont | 1:fdd22bb7aa52 | 908 | |
mbed_official | 3:7a284390b0ce | 909 | /* The results in the 8 accumulators, store in the destination buffer. */ |
mbed_official | 3:7a284390b0ce | 910 | *pDst++ = acc0; |
mbed_official | 3:7a284390b0ce | 911 | *pDst++ = acc1; |
mbed_official | 3:7a284390b0ce | 912 | *pDst++ = acc2; |
mbed_official | 3:7a284390b0ce | 913 | *pDst++ = acc3; |
mbed_official | 3:7a284390b0ce | 914 | *pDst++ = acc4; |
mbed_official | 3:7a284390b0ce | 915 | *pDst++ = acc5; |
mbed_official | 3:7a284390b0ce | 916 | *pDst++ = acc6; |
mbed_official | 3:7a284390b0ce | 917 | *pDst++ = acc7; |
mbed_official | 3:7a284390b0ce | 918 | |
mbed_official | 3:7a284390b0ce | 919 | blkCnt--; |
mbed_official | 3:7a284390b0ce | 920 | } |
emilmont | 1:fdd22bb7aa52 | 921 | |
mbed_official | 3:7a284390b0ce | 922 | /* If the blockSize is not a multiple of 8, compute any remaining output samples here. |
mbed_official | 3:7a284390b0ce | 923 | ** No loop unrolling is used. */ |
mbed_official | 3:7a284390b0ce | 924 | blkCnt = blockSize % 0x8u; |
mbed_official | 3:7a284390b0ce | 925 | |
mbed_official | 3:7a284390b0ce | 926 | while(blkCnt > 0u) |
mbed_official | 3:7a284390b0ce | 927 | { |
mbed_official | 3:7a284390b0ce | 928 | /* Copy one sample at a time into state buffer */ |
mbed_official | 3:7a284390b0ce | 929 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 930 | |
mbed_official | 3:7a284390b0ce | 931 | /* Set the accumulator to zero */ |
mbed_official | 3:7a284390b0ce | 932 | acc0 = 0.0f; |
mbed_official | 3:7a284390b0ce | 933 | |
mbed_official | 3:7a284390b0ce | 934 | /* Initialize state pointer */ |
mbed_official | 3:7a284390b0ce | 935 | px = pState; |
mbed_official | 3:7a284390b0ce | 936 | |
mbed_official | 3:7a284390b0ce | 937 | /* Initialize Coefficient pointer */ |
mbed_official | 3:7a284390b0ce | 938 | pb = (pCoeffs); |
mbed_official | 3:7a284390b0ce | 939 | |
mbed_official | 3:7a284390b0ce | 940 | i = numTaps; |
emilmont | 1:fdd22bb7aa52 | 941 | |
emilmont | 1:fdd22bb7aa52 | 942 | /* Perform the multiply-accumulates */ |
mbed_official | 3:7a284390b0ce | 943 | do |
mbed_official | 3:7a284390b0ce | 944 | { |
mbed_official | 3:7a284390b0ce | 945 | acc0 += *px++ * *pb++; |
mbed_official | 3:7a284390b0ce | 946 | i--; |
emilmont | 1:fdd22bb7aa52 | 947 | |
mbed_official | 3:7a284390b0ce | 948 | } while(i > 0u); |
emilmont | 1:fdd22bb7aa52 | 949 | |
mbed_official | 3:7a284390b0ce | 950 | /* The result is store in the destination buffer. */ |
mbed_official | 3:7a284390b0ce | 951 | *pDst++ = acc0; |
emilmont | 1:fdd22bb7aa52 | 952 | |
mbed_official | 3:7a284390b0ce | 953 | /* Advance state pointer by 1 for the next sample */ |
mbed_official | 3:7a284390b0ce | 954 | pState = pState + 1; |
emilmont | 1:fdd22bb7aa52 | 955 | |
mbed_official | 3:7a284390b0ce | 956 | blkCnt--; |
mbed_official | 3:7a284390b0ce | 957 | } |
emilmont | 1:fdd22bb7aa52 | 958 | |
mbed_official | 3:7a284390b0ce | 959 | /* Processing is complete. |
mbed_official | 3:7a284390b0ce | 960 | ** Now copy the last numTaps - 1 samples to the start of the state buffer. |
mbed_official | 3:7a284390b0ce | 961 | ** This prepares the state buffer for the next function call. */ |
emilmont | 1:fdd22bb7aa52 | 962 | |
mbed_official | 3:7a284390b0ce | 963 | /* Points to the start of the state buffer */ |
mbed_official | 3:7a284390b0ce | 964 | pStateCurnt = S->pState; |
emilmont | 1:fdd22bb7aa52 | 965 | |
mbed_official | 3:7a284390b0ce | 966 | tapCnt = (numTaps - 1u) >> 2u; |
emilmont | 1:fdd22bb7aa52 | 967 | |
mbed_official | 3:7a284390b0ce | 968 | /* copy data */ |
mbed_official | 3:7a284390b0ce | 969 | while(tapCnt > 0u) |
mbed_official | 3:7a284390b0ce | 970 | { |
mbed_official | 3:7a284390b0ce | 971 | *pStateCurnt++ = *pState++; |
mbed_official | 3:7a284390b0ce | 972 | *pStateCurnt++ = *pState++; |
mbed_official | 3:7a284390b0ce | 973 | *pStateCurnt++ = *pState++; |
mbed_official | 3:7a284390b0ce | 974 | *pStateCurnt++ = *pState++; |
emilmont | 1:fdd22bb7aa52 | 975 | |
emilmont | 1:fdd22bb7aa52 | 976 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 977 | tapCnt--; |
mbed_official | 3:7a284390b0ce | 978 | } |
emilmont | 1:fdd22bb7aa52 | 979 | |
mbed_official | 3:7a284390b0ce | 980 | /* Calculate remaining number of copies */ |
mbed_official | 3:7a284390b0ce | 981 | tapCnt = (numTaps - 1u) % 0x4u; |
emilmont | 1:fdd22bb7aa52 | 982 | |
mbed_official | 3:7a284390b0ce | 983 | /* Copy the remaining q31_t data */ |
mbed_official | 3:7a284390b0ce | 984 | while(tapCnt > 0u) |
mbed_official | 3:7a284390b0ce | 985 | { |
mbed_official | 3:7a284390b0ce | 986 | *pStateCurnt++ = *pState++; |
emilmont | 1:fdd22bb7aa52 | 987 | |
mbed_official | 3:7a284390b0ce | 988 | /* Decrement the loop counter */ |
mbed_official | 3:7a284390b0ce | 989 | tapCnt--; |
mbed_official | 3:7a284390b0ce | 990 | } |
emilmont | 1:fdd22bb7aa52 | 991 | } |
emilmont | 1:fdd22bb7aa52 | 992 | |
mbed_official | 5:3762170b6d4d | 993 | #endif |
emilmont | 1:fdd22bb7aa52 | 994 | |
emilmont | 1:fdd22bb7aa52 | 995 | /** |
mbed_official | 3:7a284390b0ce | 996 | * @} end of FIR group |
mbed_official | 3:7a284390b0ce | 997 | */ |