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.

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?

UserRevisionLine numberNew 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_decimate_fast_q31.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 2:da51fb522205 10 * Description: Fast Q31 FIR Decimator.
emilmont 1:fdd22bb7aa52 11 *
emilmont 1:fdd22bb7aa52 12 * Target Processor: Cortex-M4/Cortex-M3
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 /**
emilmont 1:fdd22bb7aa52 44 * @ingroup groupFilters
emilmont 1:fdd22bb7aa52 45 */
emilmont 1:fdd22bb7aa52 46
emilmont 1:fdd22bb7aa52 47 /**
emilmont 1:fdd22bb7aa52 48 * @addtogroup FIR_decimate
emilmont 1:fdd22bb7aa52 49 * @{
emilmont 1:fdd22bb7aa52 50 */
emilmont 1:fdd22bb7aa52 51
emilmont 1:fdd22bb7aa52 52 /**
emilmont 1:fdd22bb7aa52 53 * @brief Processing function for the Q31 FIR decimator (fast variant) for Cortex-M3 and Cortex-M4.
emilmont 1:fdd22bb7aa52 54 * @param[in] *S points to an instance of the Q31 FIR decimator structure.
emilmont 1:fdd22bb7aa52 55 * @param[in] *pSrc points to the block of input data.
emilmont 1:fdd22bb7aa52 56 * @param[out] *pDst points to the block of output data
emilmont 1:fdd22bb7aa52 57 * @param[in] blockSize number of input samples to process per call.
emilmont 1:fdd22bb7aa52 58 * @return none
emilmont 1:fdd22bb7aa52 59 *
emilmont 1:fdd22bb7aa52 60 * <b>Scaling and Overflow Behavior:</b>
emilmont 1:fdd22bb7aa52 61 *
emilmont 1:fdd22bb7aa52 62 * \par
emilmont 1:fdd22bb7aa52 63 * This function is optimized for speed at the expense of fixed-point precision and overflow protection.
emilmont 1:fdd22bb7aa52 64 * The result of each 1.31 x 1.31 multiplication is truncated to 2.30 format.
emilmont 1:fdd22bb7aa52 65 * These intermediate results are added to a 2.30 accumulator.
emilmont 1:fdd22bb7aa52 66 * Finally, the accumulator is saturated and converted to a 1.31 result.
emilmont 1:fdd22bb7aa52 67 * The fast version has the same overflow behavior as the standard version and provides less precision since it discards the low 32 bits of each multiplication result.
emilmont 1:fdd22bb7aa52 68 * In order to avoid overflows completely the input signal must be scaled down by log2(numTaps) bits (where log2 is read as log to the base 2).
emilmont 1:fdd22bb7aa52 69 *
emilmont 1:fdd22bb7aa52 70 * \par
emilmont 1:fdd22bb7aa52 71 * Refer to the function <code>arm_fir_decimate_q31()</code> for a slower implementation of this function which uses a 64-bit accumulator to provide higher precision.
emilmont 1:fdd22bb7aa52 72 * Both the slow and the fast versions use the same instance structure.
emilmont 1:fdd22bb7aa52 73 * Use the function <code>arm_fir_decimate_init_q31()</code> to initialize the filter structure.
emilmont 1:fdd22bb7aa52 74 */
emilmont 1:fdd22bb7aa52 75
emilmont 1:fdd22bb7aa52 76 void arm_fir_decimate_fast_q31(
emilmont 1:fdd22bb7aa52 77 arm_fir_decimate_instance_q31 * S,
emilmont 1:fdd22bb7aa52 78 q31_t * pSrc,
emilmont 1:fdd22bb7aa52 79 q31_t * pDst,
emilmont 1:fdd22bb7aa52 80 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 81 {
emilmont 1:fdd22bb7aa52 82 q31_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 83 q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 84 q31_t *pStateCurnt; /* Points to the current sample of the state */
emilmont 1:fdd22bb7aa52 85 q31_t x0, c0; /* Temporary variables to hold state and coefficient values */
emilmont 1:fdd22bb7aa52 86 q31_t *px; /* Temporary pointers for state buffer */
emilmont 1:fdd22bb7aa52 87 q31_t *pb; /* Temporary pointers for coefficient buffer */
emilmont 1:fdd22bb7aa52 88 q31_t sum0; /* Accumulator */
emilmont 1:fdd22bb7aa52 89 uint32_t numTaps = S->numTaps; /* Number of taps */
emilmont 1:fdd22bb7aa52 90 uint32_t i, tapCnt, blkCnt, outBlockSize = blockSize / S->M; /* Loop counters */
emilmont 1:fdd22bb7aa52 91 uint32_t blkCntN2;
emilmont 1:fdd22bb7aa52 92 q31_t x1;
emilmont 1:fdd22bb7aa52 93 q31_t acc0, acc1;
emilmont 1:fdd22bb7aa52 94 q31_t *px0, *px1;
emilmont 1:fdd22bb7aa52 95
emilmont 1:fdd22bb7aa52 96 /* S->pState buffer contains previous frame (numTaps - 1) samples */
emilmont 1:fdd22bb7aa52 97 /* pStateCurnt points to the location where the new input data should be written */
emilmont 1:fdd22bb7aa52 98 pStateCurnt = S->pState + (numTaps - 1u);
emilmont 1:fdd22bb7aa52 99
emilmont 1:fdd22bb7aa52 100 /* Total number of output samples to be computed */
emilmont 1:fdd22bb7aa52 101
emilmont 1:fdd22bb7aa52 102 blkCnt = outBlockSize / 2;
emilmont 1:fdd22bb7aa52 103 blkCntN2 = outBlockSize - (2 * blkCnt);
emilmont 1:fdd22bb7aa52 104
emilmont 1:fdd22bb7aa52 105 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 106 {
emilmont 1:fdd22bb7aa52 107 /* Copy decimation factor number of new input samples into the state buffer */
emilmont 1:fdd22bb7aa52 108 i = 2 * S->M;
emilmont 1:fdd22bb7aa52 109
emilmont 1:fdd22bb7aa52 110 do
emilmont 1:fdd22bb7aa52 111 {
emilmont 1:fdd22bb7aa52 112 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 113
emilmont 1:fdd22bb7aa52 114 } while(--i);
emilmont 1:fdd22bb7aa52 115
emilmont 1:fdd22bb7aa52 116 /* Set accumulator to zero */
emilmont 1:fdd22bb7aa52 117 acc0 = 0;
emilmont 1:fdd22bb7aa52 118 acc1 = 0;
emilmont 1:fdd22bb7aa52 119
emilmont 1:fdd22bb7aa52 120 /* Initialize state pointer */
emilmont 1:fdd22bb7aa52 121 px0 = pState;
emilmont 1:fdd22bb7aa52 122 px1 = pState + S->M;
emilmont 1:fdd22bb7aa52 123
emilmont 1:fdd22bb7aa52 124 /* Initialize coeff pointer */
emilmont 1:fdd22bb7aa52 125 pb = pCoeffs;
emilmont 1:fdd22bb7aa52 126
emilmont 1:fdd22bb7aa52 127 /* Loop unrolling. Process 4 taps at a time. */
emilmont 1:fdd22bb7aa52 128 tapCnt = numTaps >> 2;
emilmont 1:fdd22bb7aa52 129
emilmont 1:fdd22bb7aa52 130 /* Loop over the number of taps. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 131 ** Repeat until we've computed numTaps-4 coefficients. */
emilmont 1:fdd22bb7aa52 132 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 133 {
emilmont 1:fdd22bb7aa52 134 /* Read the b[numTaps-1] coefficient */
emilmont 1:fdd22bb7aa52 135 c0 = *(pb);
emilmont 1:fdd22bb7aa52 136
emilmont 1:fdd22bb7aa52 137 /* Read x[n-numTaps-1] for sample 0 sample 1 */
emilmont 1:fdd22bb7aa52 138 x0 = *(px0);
emilmont 1:fdd22bb7aa52 139 x1 = *(px1);
emilmont 1:fdd22bb7aa52 140
emilmont 1:fdd22bb7aa52 141 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 142 acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 143 acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 144
emilmont 1:fdd22bb7aa52 145 /* Read the b[numTaps-2] coefficient */
emilmont 1:fdd22bb7aa52 146 c0 = *(pb + 1u);
emilmont 1:fdd22bb7aa52 147
emilmont 1:fdd22bb7aa52 148 /* Read x[n-numTaps-2] for sample 0 sample 1 */
emilmont 1:fdd22bb7aa52 149 x0 = *(px0 + 1u);
emilmont 1:fdd22bb7aa52 150 x1 = *(px1 + 1u);
emilmont 1:fdd22bb7aa52 151
emilmont 1:fdd22bb7aa52 152 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 153 acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 154 acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 155
emilmont 1:fdd22bb7aa52 156 /* Read the b[numTaps-3] coefficient */
emilmont 1:fdd22bb7aa52 157 c0 = *(pb + 2u);
emilmont 1:fdd22bb7aa52 158
emilmont 1:fdd22bb7aa52 159 /* Read x[n-numTaps-3] for sample 0 sample 1 */
emilmont 1:fdd22bb7aa52 160 x0 = *(px0 + 2u);
emilmont 1:fdd22bb7aa52 161 x1 = *(px1 + 2u);
emilmont 1:fdd22bb7aa52 162 pb += 4u;
emilmont 1:fdd22bb7aa52 163
emilmont 1:fdd22bb7aa52 164 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 165 acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 166 acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 167
emilmont 1:fdd22bb7aa52 168 /* Read the b[numTaps-4] coefficient */
emilmont 1:fdd22bb7aa52 169 c0 = *(pb - 1u);
emilmont 1:fdd22bb7aa52 170
emilmont 1:fdd22bb7aa52 171 /* Read x[n-numTaps-4] for sample 0 sample 1 */
emilmont 1:fdd22bb7aa52 172 x0 = *(px0 + 3u);
emilmont 1:fdd22bb7aa52 173 x1 = *(px1 + 3u);
emilmont 1:fdd22bb7aa52 174
emilmont 1:fdd22bb7aa52 175
emilmont 1:fdd22bb7aa52 176 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 177 acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 178 acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 179
emilmont 1:fdd22bb7aa52 180 /* update state pointers */
emilmont 1:fdd22bb7aa52 181 px0 += 4u;
emilmont 1:fdd22bb7aa52 182 px1 += 4u;
emilmont 1:fdd22bb7aa52 183
emilmont 1:fdd22bb7aa52 184 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 185 tapCnt--;
emilmont 1:fdd22bb7aa52 186 }
emilmont 1:fdd22bb7aa52 187
emilmont 1:fdd22bb7aa52 188 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emilmont 1:fdd22bb7aa52 189 tapCnt = numTaps % 0x4u;
emilmont 1:fdd22bb7aa52 190
emilmont 1:fdd22bb7aa52 191 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 192 {
emilmont 1:fdd22bb7aa52 193 /* Read coefficients */
emilmont 1:fdd22bb7aa52 194 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 195
emilmont 1:fdd22bb7aa52 196 /* Fetch 1 state variable */
emilmont 1:fdd22bb7aa52 197 x0 = *(px0++);
emilmont 1:fdd22bb7aa52 198 x1 = *(px1++);
emilmont 1:fdd22bb7aa52 199
emilmont 1:fdd22bb7aa52 200 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 201 acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 202 acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 203
emilmont 1:fdd22bb7aa52 204 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 205 tapCnt--;
emilmont 1:fdd22bb7aa52 206 }
emilmont 1:fdd22bb7aa52 207
emilmont 1:fdd22bb7aa52 208 /* Advance the state pointer by the decimation factor
emilmont 1:fdd22bb7aa52 209 * to process the next group of decimation factor number samples */
emilmont 1:fdd22bb7aa52 210 pState = pState + S->M * 2;
emilmont 1:fdd22bb7aa52 211
emilmont 1:fdd22bb7aa52 212 /* The result is in the accumulator, store in the destination buffer. */
emilmont 1:fdd22bb7aa52 213 *pDst++ = (q31_t) (acc0 << 1);
emilmont 1:fdd22bb7aa52 214 *pDst++ = (q31_t) (acc1 << 1);
emilmont 1:fdd22bb7aa52 215
emilmont 1:fdd22bb7aa52 216 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 217 blkCnt--;
emilmont 1:fdd22bb7aa52 218 }
emilmont 1:fdd22bb7aa52 219
emilmont 1:fdd22bb7aa52 220 while(blkCntN2 > 0u)
emilmont 1:fdd22bb7aa52 221 {
emilmont 1:fdd22bb7aa52 222 /* Copy decimation factor number of new input samples into the state buffer */
emilmont 1:fdd22bb7aa52 223 i = S->M;
emilmont 1:fdd22bb7aa52 224
emilmont 1:fdd22bb7aa52 225 do
emilmont 1:fdd22bb7aa52 226 {
emilmont 1:fdd22bb7aa52 227 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 228
emilmont 1:fdd22bb7aa52 229 } while(--i);
emilmont 1:fdd22bb7aa52 230
emilmont 1:fdd22bb7aa52 231 /* Set accumulator to zero */
emilmont 1:fdd22bb7aa52 232 sum0 = 0;
emilmont 1:fdd22bb7aa52 233
emilmont 1:fdd22bb7aa52 234 /* Initialize state pointer */
emilmont 1:fdd22bb7aa52 235 px = pState;
emilmont 1:fdd22bb7aa52 236
emilmont 1:fdd22bb7aa52 237 /* Initialize coeff pointer */
emilmont 1:fdd22bb7aa52 238 pb = pCoeffs;
emilmont 1:fdd22bb7aa52 239
emilmont 1:fdd22bb7aa52 240 /* Loop unrolling. Process 4 taps at a time. */
emilmont 1:fdd22bb7aa52 241 tapCnt = numTaps >> 2;
emilmont 1:fdd22bb7aa52 242
emilmont 1:fdd22bb7aa52 243 /* Loop over the number of taps. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 244 ** Repeat until we've computed numTaps-4 coefficients. */
emilmont 1:fdd22bb7aa52 245 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 246 {
emilmont 1:fdd22bb7aa52 247 /* Read the b[numTaps-1] coefficient */
emilmont 1:fdd22bb7aa52 248 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 249
emilmont 1:fdd22bb7aa52 250 /* Read x[n-numTaps-1] sample */
emilmont 1:fdd22bb7aa52 251 x0 = *(px++);
emilmont 1:fdd22bb7aa52 252
emilmont 1:fdd22bb7aa52 253 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 254 sum0 = (q31_t) ((((q63_t) sum0 << 32) + ((q63_t) x0 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 255
emilmont 1:fdd22bb7aa52 256 /* Read the b[numTaps-2] coefficient */
emilmont 1:fdd22bb7aa52 257 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 258
emilmont 1:fdd22bb7aa52 259 /* Read x[n-numTaps-2] sample */
emilmont 1:fdd22bb7aa52 260 x0 = *(px++);
emilmont 1:fdd22bb7aa52 261
emilmont 1:fdd22bb7aa52 262 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 263 sum0 = (q31_t) ((((q63_t) sum0 << 32) + ((q63_t) x0 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 264
emilmont 1:fdd22bb7aa52 265 /* Read the b[numTaps-3] coefficient */
emilmont 1:fdd22bb7aa52 266 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 267
emilmont 1:fdd22bb7aa52 268 /* Read x[n-numTaps-3] sample */
emilmont 1:fdd22bb7aa52 269 x0 = *(px++);
emilmont 1:fdd22bb7aa52 270
emilmont 1:fdd22bb7aa52 271 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 272 sum0 = (q31_t) ((((q63_t) sum0 << 32) + ((q63_t) x0 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 273
emilmont 1:fdd22bb7aa52 274 /* Read the b[numTaps-4] coefficient */
emilmont 1:fdd22bb7aa52 275 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 276
emilmont 1:fdd22bb7aa52 277 /* Read x[n-numTaps-4] sample */
emilmont 1:fdd22bb7aa52 278 x0 = *(px++);
emilmont 1:fdd22bb7aa52 279
emilmont 1:fdd22bb7aa52 280 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 281 sum0 = (q31_t) ((((q63_t) sum0 << 32) + ((q63_t) x0 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 282
emilmont 1:fdd22bb7aa52 283 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 284 tapCnt--;
emilmont 1:fdd22bb7aa52 285 }
emilmont 1:fdd22bb7aa52 286
emilmont 1:fdd22bb7aa52 287 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emilmont 1:fdd22bb7aa52 288 tapCnt = numTaps % 0x4u;
emilmont 1:fdd22bb7aa52 289
emilmont 1:fdd22bb7aa52 290 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 291 {
emilmont 1:fdd22bb7aa52 292 /* Read coefficients */
emilmont 1:fdd22bb7aa52 293 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 294
emilmont 1:fdd22bb7aa52 295 /* Fetch 1 state variable */
emilmont 1:fdd22bb7aa52 296 x0 = *(px++);
emilmont 1:fdd22bb7aa52 297
emilmont 1:fdd22bb7aa52 298 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 299 sum0 = (q31_t) ((((q63_t) sum0 << 32) + ((q63_t) x0 * c0)) >> 32);
emilmont 1:fdd22bb7aa52 300
emilmont 1:fdd22bb7aa52 301 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 302 tapCnt--;
emilmont 1:fdd22bb7aa52 303 }
emilmont 1:fdd22bb7aa52 304
emilmont 1:fdd22bb7aa52 305 /* Advance the state pointer by the decimation factor
emilmont 1:fdd22bb7aa52 306 * to process the next group of decimation factor number samples */
emilmont 1:fdd22bb7aa52 307 pState = pState + S->M;
emilmont 1:fdd22bb7aa52 308
emilmont 1:fdd22bb7aa52 309 /* The result is in the accumulator, store in the destination buffer. */
emilmont 1:fdd22bb7aa52 310 *pDst++ = (q31_t) (sum0 << 1);
emilmont 1:fdd22bb7aa52 311
emilmont 1:fdd22bb7aa52 312 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 313 blkCntN2--;
emilmont 1:fdd22bb7aa52 314 }
emilmont 1:fdd22bb7aa52 315
emilmont 1:fdd22bb7aa52 316 /* Processing is complete.
emilmont 1:fdd22bb7aa52 317 ** Now copy the last numTaps - 1 samples to the satrt of the state buffer.
emilmont 1:fdd22bb7aa52 318 ** This prepares the state buffer for the next function call. */
emilmont 1:fdd22bb7aa52 319
emilmont 1:fdd22bb7aa52 320 /* Points to the start of the state buffer */
emilmont 1:fdd22bb7aa52 321 pStateCurnt = S->pState;
emilmont 1:fdd22bb7aa52 322
emilmont 1:fdd22bb7aa52 323 i = (numTaps - 1u) >> 2u;
emilmont 1:fdd22bb7aa52 324
emilmont 1:fdd22bb7aa52 325 /* copy data */
emilmont 1:fdd22bb7aa52 326 while(i > 0u)
emilmont 1:fdd22bb7aa52 327 {
emilmont 1:fdd22bb7aa52 328 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 329 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 330 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 331 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 332
emilmont 1:fdd22bb7aa52 333 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 334 i--;
emilmont 1:fdd22bb7aa52 335 }
emilmont 1:fdd22bb7aa52 336
emilmont 1:fdd22bb7aa52 337 i = (numTaps - 1u) % 0x04u;
emilmont 1:fdd22bb7aa52 338
emilmont 1:fdd22bb7aa52 339 /* copy data */
emilmont 1:fdd22bb7aa52 340 while(i > 0u)
emilmont 1:fdd22bb7aa52 341 {
emilmont 1:fdd22bb7aa52 342 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 343
emilmont 1:fdd22bb7aa52 344 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 345 i--;
emilmont 1:fdd22bb7aa52 346 }
emilmont 1:fdd22bb7aa52 347 }
emilmont 1:fdd22bb7aa52 348
emilmont 1:fdd22bb7aa52 349 /**
emilmont 1:fdd22bb7aa52 350 * @} end of FIR_decimate group
emilmont 1:fdd22bb7aa52 351 */