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 mbed official

Committer:
emilmont
Date:
Thu May 30 17:10:11 2013 +0100
Revision:
2:da51fb522205
Parent:
1:fdd22bb7aa52
Child:
3:7a284390b0ce
Keep "cmsis-dsp" module in synch with its source

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:fdd22bb7aa52 1 /* ----------------------------------------------------------------------
emilmont 1:fdd22bb7aa52 2 * Copyright (C) 2010 ARM Limited. All rights reserved.
emilmont 1:fdd22bb7aa52 3 *
emilmont 1:fdd22bb7aa52 4 * $Date: 15. February 2012
emilmont 2:da51fb522205 5 * $Revision: V1.1.0
emilmont 1:fdd22bb7aa52 6 *
emilmont 2:da51fb522205 7 * Project: CMSIS DSP Library
emilmont 2:da51fb522205 8 * Title: arm_fir_decimate_f32.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 2:da51fb522205 10 * Description: FIR decimation for floating-point sequences.
emilmont 1:fdd22bb7aa52 11 *
emilmont 1:fdd22bb7aa52 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
emilmont 1:fdd22bb7aa52 13 *
emilmont 1:fdd22bb7aa52 14 * Version 1.1.0 2012/02/15
emilmont 1:fdd22bb7aa52 15 * Updated with more optimizations, bug fixes and minor API changes.
emilmont 1:fdd22bb7aa52 16 *
emilmont 1:fdd22bb7aa52 17 * Version 1.0.10 2011/7/15
emilmont 1:fdd22bb7aa52 18 * Big Endian support added and Merged M0 and M3/M4 Source code.
emilmont 1:fdd22bb7aa52 19 *
emilmont 1:fdd22bb7aa52 20 * Version 1.0.3 2010/11/29
emilmont 1:fdd22bb7aa52 21 * Re-organized the CMSIS folders and updated documentation.
emilmont 1:fdd22bb7aa52 22 *
emilmont 1:fdd22bb7aa52 23 * Version 1.0.2 2010/11/11
emilmont 1:fdd22bb7aa52 24 * Documentation updated.
emilmont 1:fdd22bb7aa52 25 *
emilmont 1:fdd22bb7aa52 26 * Version 1.0.1 2010/10/05
emilmont 1:fdd22bb7aa52 27 * Production release and review comments incorporated.
emilmont 1:fdd22bb7aa52 28 *
emilmont 1:fdd22bb7aa52 29 * Version 1.0.0 2010/09/20
emilmont 1:fdd22bb7aa52 30 * Production release and review comments incorporated
emilmont 1:fdd22bb7aa52 31 *
emilmont 1:fdd22bb7aa52 32 * Version 0.0.7 2010/06/10
emilmont 1:fdd22bb7aa52 33 * Misra-C changes done
emilmont 1:fdd22bb7aa52 34 *
emilmont 1:fdd22bb7aa52 35 * -------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 36
emilmont 1:fdd22bb7aa52 37 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 38
emilmont 1:fdd22bb7aa52 39 /**
emilmont 1:fdd22bb7aa52 40 * @ingroup groupFilters
emilmont 1:fdd22bb7aa52 41 */
emilmont 1:fdd22bb7aa52 42
emilmont 1:fdd22bb7aa52 43 /**
emilmont 1:fdd22bb7aa52 44 * @defgroup FIR_decimate Finite Impulse Response (FIR) Decimator
emilmont 1:fdd22bb7aa52 45 *
emilmont 1:fdd22bb7aa52 46 * These functions combine an FIR filter together with a decimator.
emilmont 1:fdd22bb7aa52 47 * They are used in multirate systems for reducing the sample rate of a signal without introducing aliasing distortion.
emilmont 1:fdd22bb7aa52 48 * Conceptually, the functions are equivalent to the block diagram below:
emilmont 1:fdd22bb7aa52 49 * \image html FIRDecimator.gif "Components included in the FIR Decimator functions"
emilmont 1:fdd22bb7aa52 50 * When decimating by a factor of <code>M</code>, the signal should be prefiltered by a lowpass filter with a normalized
emilmont 1:fdd22bb7aa52 51 * cutoff frequency of <code>1/M</code> in order to prevent aliasing distortion.
emilmont 1:fdd22bb7aa52 52 * The user of the function is responsible for providing the filter coefficients.
emilmont 1:fdd22bb7aa52 53 *
emilmont 1:fdd22bb7aa52 54 * The FIR decimator functions provided in the CMSIS DSP Library combine the FIR filter and the decimator in an efficient manner.
emilmont 1:fdd22bb7aa52 55 * Instead of calculating all of the FIR filter outputs and discarding <code>M-1</code> out of every <code>M</code>, only the
emilmont 1:fdd22bb7aa52 56 * samples output by the decimator are computed.
emilmont 1:fdd22bb7aa52 57 * The functions operate on blocks of input and output data.
emilmont 1:fdd22bb7aa52 58 * <code>pSrc</code> points to an array of <code>blockSize</code> input values and
emilmont 1:fdd22bb7aa52 59 * <code>pDst</code> points to an array of <code>blockSize/M</code> output values.
emilmont 1:fdd22bb7aa52 60 * In order to have an integer number of output samples <code>blockSize</code>
emilmont 1:fdd22bb7aa52 61 * must always be a multiple of the decimation factor <code>M</code>.
emilmont 1:fdd22bb7aa52 62 *
emilmont 1:fdd22bb7aa52 63 * The library provides separate functions for Q15, Q31 and floating-point data types.
emilmont 1:fdd22bb7aa52 64 *
emilmont 1:fdd22bb7aa52 65 * \par Algorithm:
emilmont 1:fdd22bb7aa52 66 * The FIR portion of the algorithm uses the standard form filter:
emilmont 1:fdd22bb7aa52 67 * <pre>
emilmont 1:fdd22bb7aa52 68 * y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[numTaps-1] * x[n-numTaps+1]
emilmont 1:fdd22bb7aa52 69 * </pre>
emilmont 1:fdd22bb7aa52 70 * where, <code>b[n]</code> are the filter coefficients.
emilmont 1:fdd22bb7aa52 71 * \par
emilmont 1:fdd22bb7aa52 72 * The <code>pCoeffs</code> points to a coefficient array of size <code>numTaps</code>.
emilmont 1:fdd22bb7aa52 73 * Coefficients are stored in time reversed order.
emilmont 1:fdd22bb7aa52 74 * \par
emilmont 1:fdd22bb7aa52 75 * <pre>
emilmont 1:fdd22bb7aa52 76 * {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
emilmont 1:fdd22bb7aa52 77 * </pre>
emilmont 1:fdd22bb7aa52 78 * \par
emilmont 1:fdd22bb7aa52 79 * <code>pState</code> points to a state array of size <code>numTaps + blockSize - 1</code>.
emilmont 1:fdd22bb7aa52 80 * Samples in the state buffer are stored in the order:
emilmont 1:fdd22bb7aa52 81 * \par
emilmont 1:fdd22bb7aa52 82 * <pre>
emilmont 1:fdd22bb7aa52 83 * {x[n-numTaps+1], x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2]....x[0], x[1], ..., x[blockSize-1]}
emilmont 1:fdd22bb7aa52 84 * </pre>
emilmont 1:fdd22bb7aa52 85 * The state variables are updated after each block of data is processed, the coefficients are untouched.
emilmont 1:fdd22bb7aa52 86 *
emilmont 1:fdd22bb7aa52 87 * \par Instance Structure
emilmont 1:fdd22bb7aa52 88 * The coefficients and state variables for a filter are stored together in an instance data structure.
emilmont 1:fdd22bb7aa52 89 * A separate instance structure must be defined for each filter.
emilmont 1:fdd22bb7aa52 90 * Coefficient arrays may be shared among several instances while state variable array should be allocated separately.
emilmont 1:fdd22bb7aa52 91 * There are separate instance structure declarations for each of the 3 supported data types.
emilmont 1:fdd22bb7aa52 92 *
emilmont 1:fdd22bb7aa52 93 * \par Initialization Functions
emilmont 1:fdd22bb7aa52 94 * There is also an associated initialization function for each data type.
emilmont 1:fdd22bb7aa52 95 * The initialization function performs the following operations:
emilmont 1:fdd22bb7aa52 96 * - Sets the values of the internal structure fields.
emilmont 1:fdd22bb7aa52 97 * - Zeros out the values in the state buffer.
emilmont 1:fdd22bb7aa52 98 * - Checks to make sure that the size of the input is a multiple of the decimation factor.
emilmont 1:fdd22bb7aa52 99 *
emilmont 1:fdd22bb7aa52 100 * \par
emilmont 1:fdd22bb7aa52 101 * Use of the initialization function is optional.
emilmont 1:fdd22bb7aa52 102 * However, if the initialization function is used, then the instance structure cannot be placed into a const data section.
emilmont 1:fdd22bb7aa52 103 * To place an instance structure into a const data section, the instance structure must be manually initialized.
emilmont 1:fdd22bb7aa52 104 * The code below statically initializes each of the 3 different data type filter instance structures
emilmont 1:fdd22bb7aa52 105 * <pre>
emilmont 1:fdd22bb7aa52 106 *arm_fir_decimate_instance_f32 S = {M, numTaps, pCoeffs, pState};
emilmont 1:fdd22bb7aa52 107 *arm_fir_decimate_instance_q31 S = {M, numTaps, pCoeffs, pState};
emilmont 1:fdd22bb7aa52 108 *arm_fir_decimate_instance_q15 S = {M, numTaps, pCoeffs, pState};
emilmont 1:fdd22bb7aa52 109 * </pre>
emilmont 1:fdd22bb7aa52 110 * where <code>M</code> is the decimation factor; <code>numTaps</code> is the number of filter coefficients in the filter;
emilmont 1:fdd22bb7aa52 111 * <code>pCoeffs</code> is the address of the coefficient buffer;
emilmont 1:fdd22bb7aa52 112 * <code>pState</code> is the address of the state buffer.
emilmont 1:fdd22bb7aa52 113 * Be sure to set the values in the state buffer to zeros when doing static initialization.
emilmont 1:fdd22bb7aa52 114 *
emilmont 1:fdd22bb7aa52 115 * \par Fixed-Point Behavior
emilmont 1:fdd22bb7aa52 116 * Care must be taken when using the fixed-point versions of the FIR decimate filter functions.
emilmont 1:fdd22bb7aa52 117 * In particular, the overflow and saturation behavior of the accumulator used in each function must be considered.
emilmont 1:fdd22bb7aa52 118 * Refer to the function specific documentation below for usage guidelines.
emilmont 1:fdd22bb7aa52 119 */
emilmont 1:fdd22bb7aa52 120
emilmont 1:fdd22bb7aa52 121 /**
emilmont 1:fdd22bb7aa52 122 * @addtogroup FIR_decimate
emilmont 1:fdd22bb7aa52 123 * @{
emilmont 1:fdd22bb7aa52 124 */
emilmont 1:fdd22bb7aa52 125
emilmont 1:fdd22bb7aa52 126 /**
emilmont 1:fdd22bb7aa52 127 * @brief Processing function for the floating-point FIR decimator.
emilmont 1:fdd22bb7aa52 128 * @param[in] *S points to an instance of the floating-point FIR decimator structure.
emilmont 1:fdd22bb7aa52 129 * @param[in] *pSrc points to the block of input data.
emilmont 1:fdd22bb7aa52 130 * @param[out] *pDst points to the block of output data.
emilmont 1:fdd22bb7aa52 131 * @param[in] blockSize number of input samples to process per call.
emilmont 1:fdd22bb7aa52 132 * @return none.
emilmont 1:fdd22bb7aa52 133 */
emilmont 1:fdd22bb7aa52 134
emilmont 1:fdd22bb7aa52 135 void arm_fir_decimate_f32(
emilmont 1:fdd22bb7aa52 136 const arm_fir_decimate_instance_f32 * S,
emilmont 1:fdd22bb7aa52 137 float32_t * pSrc,
emilmont 1:fdd22bb7aa52 138 float32_t * pDst,
emilmont 1:fdd22bb7aa52 139 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 140 {
emilmont 1:fdd22bb7aa52 141 float32_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 142 float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 143 float32_t *pStateCurnt; /* Points to the current sample of the state */
emilmont 1:fdd22bb7aa52 144 float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */
emilmont 1:fdd22bb7aa52 145 float32_t sum0; /* Accumulator */
emilmont 1:fdd22bb7aa52 146 float32_t x0, c0; /* Temporary variables to hold state and coefficient values */
emilmont 1:fdd22bb7aa52 147 uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */
emilmont 1:fdd22bb7aa52 148 uint32_t i, tapCnt, blkCnt, outBlockSize = blockSize / S->M; /* Loop counters */
emilmont 1:fdd22bb7aa52 149
emilmont 1:fdd22bb7aa52 150 #ifndef ARM_MATH_CM0
emilmont 1:fdd22bb7aa52 151
emilmont 1:fdd22bb7aa52 152 uint32_t blkCntN4;
emilmont 1:fdd22bb7aa52 153 float32_t *px0, *px1, *px2, *px3;
emilmont 1:fdd22bb7aa52 154 float32_t acc0, acc1, acc2, acc3;
emilmont 1:fdd22bb7aa52 155 float32_t x1, x2, x3;
emilmont 1:fdd22bb7aa52 156
emilmont 1:fdd22bb7aa52 157 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 158
emilmont 1:fdd22bb7aa52 159 /* S->pState buffer contains previous frame (numTaps - 1) samples */
emilmont 1:fdd22bb7aa52 160 /* pStateCurnt points to the location where the new input data should be written */
emilmont 1:fdd22bb7aa52 161 pStateCurnt = S->pState + (numTaps - 1u);
emilmont 1:fdd22bb7aa52 162
emilmont 1:fdd22bb7aa52 163 /* Total number of output samples to be computed */
emilmont 1:fdd22bb7aa52 164 blkCnt = outBlockSize / 4;
emilmont 1:fdd22bb7aa52 165 blkCntN4 = outBlockSize - (4 * blkCnt);
emilmont 1:fdd22bb7aa52 166
emilmont 1:fdd22bb7aa52 167 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 168 {
emilmont 1:fdd22bb7aa52 169 /* Copy 4 * decimation factor number of new input samples into the state buffer */
emilmont 1:fdd22bb7aa52 170 i = 4 * S->M;
emilmont 1:fdd22bb7aa52 171
emilmont 1:fdd22bb7aa52 172 do
emilmont 1:fdd22bb7aa52 173 {
emilmont 1:fdd22bb7aa52 174 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 175
emilmont 1:fdd22bb7aa52 176 } while(--i);
emilmont 1:fdd22bb7aa52 177
emilmont 1:fdd22bb7aa52 178 /* Set accumulators to zero */
emilmont 1:fdd22bb7aa52 179 acc0 = 0.0f;
emilmont 1:fdd22bb7aa52 180 acc1 = 0.0f;
emilmont 1:fdd22bb7aa52 181 acc2 = 0.0f;
emilmont 1:fdd22bb7aa52 182 acc3 = 0.0f;
emilmont 1:fdd22bb7aa52 183
emilmont 1:fdd22bb7aa52 184 /* Initialize state pointer for all the samples */
emilmont 1:fdd22bb7aa52 185 px0 = pState;
emilmont 1:fdd22bb7aa52 186 px1 = pState + S->M;
emilmont 1:fdd22bb7aa52 187 px2 = pState + 2 * S->M;
emilmont 1:fdd22bb7aa52 188 px3 = pState + 3 * S->M;
emilmont 1:fdd22bb7aa52 189
emilmont 1:fdd22bb7aa52 190 /* Initialize coeff pointer */
emilmont 1:fdd22bb7aa52 191 pb = pCoeffs;
emilmont 1:fdd22bb7aa52 192
emilmont 1:fdd22bb7aa52 193 /* Loop unrolling. Process 4 taps at a time. */
emilmont 1:fdd22bb7aa52 194 tapCnt = numTaps >> 2;
emilmont 1:fdd22bb7aa52 195
emilmont 1:fdd22bb7aa52 196 /* Loop over the number of taps. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 197 ** Repeat until we've computed numTaps-4 coefficients. */
emilmont 1:fdd22bb7aa52 198
emilmont 1:fdd22bb7aa52 199 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 200 {
emilmont 1:fdd22bb7aa52 201 /* Read the b[numTaps-1] coefficient */
emilmont 1:fdd22bb7aa52 202 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 203
emilmont 1:fdd22bb7aa52 204 /* Read x[n-numTaps-1] sample for acc0 */
emilmont 1:fdd22bb7aa52 205 x0 = *(px0++);
emilmont 1:fdd22bb7aa52 206 /* Read x[n-numTaps-1] sample for acc1 */
emilmont 1:fdd22bb7aa52 207 x1 = *(px1++);
emilmont 1:fdd22bb7aa52 208 /* Read x[n-numTaps-1] sample for acc2 */
emilmont 1:fdd22bb7aa52 209 x2 = *(px2++);
emilmont 1:fdd22bb7aa52 210 /* Read x[n-numTaps-1] sample for acc3 */
emilmont 1:fdd22bb7aa52 211 x3 = *(px3++);
emilmont 1:fdd22bb7aa52 212
emilmont 1:fdd22bb7aa52 213 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 214 acc0 += x0 * c0;
emilmont 1:fdd22bb7aa52 215 acc1 += x1 * c0;
emilmont 1:fdd22bb7aa52 216 acc2 += x2 * c0;
emilmont 1:fdd22bb7aa52 217 acc3 += x3 * c0;
emilmont 1:fdd22bb7aa52 218
emilmont 1:fdd22bb7aa52 219 /* Read the b[numTaps-2] coefficient */
emilmont 1:fdd22bb7aa52 220 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 221
emilmont 1:fdd22bb7aa52 222 /* Read x[n-numTaps-2] sample for acc0, acc1, acc2, acc3 */
emilmont 1:fdd22bb7aa52 223 x0 = *(px0++);
emilmont 1:fdd22bb7aa52 224 x1 = *(px1++);
emilmont 1:fdd22bb7aa52 225 x2 = *(px2++);
emilmont 1:fdd22bb7aa52 226 x3 = *(px3++);
emilmont 1:fdd22bb7aa52 227
emilmont 1:fdd22bb7aa52 228 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 229 acc0 += x0 * c0;
emilmont 1:fdd22bb7aa52 230 acc1 += x1 * c0;
emilmont 1:fdd22bb7aa52 231 acc2 += x2 * c0;
emilmont 1:fdd22bb7aa52 232 acc3 += x3 * c0;
emilmont 1:fdd22bb7aa52 233
emilmont 1:fdd22bb7aa52 234 /* Read the b[numTaps-3] coefficient */
emilmont 1:fdd22bb7aa52 235 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 236
emilmont 1:fdd22bb7aa52 237 /* Read x[n-numTaps-3] sample acc0, acc1, acc2, acc3 */
emilmont 1:fdd22bb7aa52 238 x0 = *(px0++);
emilmont 1:fdd22bb7aa52 239 x1 = *(px1++);
emilmont 1:fdd22bb7aa52 240 x2 = *(px2++);
emilmont 1:fdd22bb7aa52 241 x3 = *(px3++);
emilmont 1:fdd22bb7aa52 242
emilmont 1:fdd22bb7aa52 243 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 244 acc0 += x0 * c0;
emilmont 1:fdd22bb7aa52 245 acc1 += x1 * c0;
emilmont 1:fdd22bb7aa52 246 acc2 += x2 * c0;
emilmont 1:fdd22bb7aa52 247 acc3 += x3 * c0;
emilmont 1:fdd22bb7aa52 248
emilmont 1:fdd22bb7aa52 249 /* Read the b[numTaps-4] coefficient */
emilmont 1:fdd22bb7aa52 250 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 251
emilmont 1:fdd22bb7aa52 252 /* Read x[n-numTaps-4] sample acc0, acc1, acc2, acc3 */
emilmont 1:fdd22bb7aa52 253 x0 = *(px0++);
emilmont 1:fdd22bb7aa52 254 x1 = *(px1++);
emilmont 1:fdd22bb7aa52 255 x2 = *(px2++);
emilmont 1:fdd22bb7aa52 256 x3 = *(px3++);
emilmont 1:fdd22bb7aa52 257
emilmont 1:fdd22bb7aa52 258 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 259 acc0 += x0 * c0;
emilmont 1:fdd22bb7aa52 260 acc1 += x1 * c0;
emilmont 1:fdd22bb7aa52 261 acc2 += x2 * c0;
emilmont 1:fdd22bb7aa52 262 acc3 += x3 * c0;
emilmont 1:fdd22bb7aa52 263
emilmont 1:fdd22bb7aa52 264 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 265 tapCnt--;
emilmont 1:fdd22bb7aa52 266 }
emilmont 1:fdd22bb7aa52 267
emilmont 1:fdd22bb7aa52 268 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emilmont 1:fdd22bb7aa52 269 tapCnt = numTaps % 0x4u;
emilmont 1:fdd22bb7aa52 270
emilmont 1:fdd22bb7aa52 271 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 272 {
emilmont 1:fdd22bb7aa52 273 /* Read coefficients */
emilmont 1:fdd22bb7aa52 274 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 275
emilmont 1:fdd22bb7aa52 276 /* Fetch state variables for acc0, acc1, acc2, acc3 */
emilmont 1:fdd22bb7aa52 277 x0 = *(px0++);
emilmont 1:fdd22bb7aa52 278 x1 = *(px1++);
emilmont 1:fdd22bb7aa52 279 x2 = *(px2++);
emilmont 1:fdd22bb7aa52 280 x3 = *(px3++);
emilmont 1:fdd22bb7aa52 281
emilmont 1:fdd22bb7aa52 282 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 283 acc0 += x0 * c0;
emilmont 1:fdd22bb7aa52 284 acc1 += x1 * c0;
emilmont 1:fdd22bb7aa52 285 acc2 += x2 * c0;
emilmont 1:fdd22bb7aa52 286 acc3 += x3 * c0;
emilmont 1:fdd22bb7aa52 287
emilmont 1:fdd22bb7aa52 288 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 289 tapCnt--;
emilmont 1:fdd22bb7aa52 290 }
emilmont 1:fdd22bb7aa52 291
emilmont 1:fdd22bb7aa52 292 /* Advance the state pointer by the decimation factor
emilmont 1:fdd22bb7aa52 293 * to process the next group of decimation factor number samples */
emilmont 1:fdd22bb7aa52 294 pState = pState + 4 * S->M;
emilmont 1:fdd22bb7aa52 295
emilmont 1:fdd22bb7aa52 296 /* The result is in the accumulator, store in the destination buffer. */
emilmont 1:fdd22bb7aa52 297 *pDst++ = acc0;
emilmont 1:fdd22bb7aa52 298 *pDst++ = acc1;
emilmont 1:fdd22bb7aa52 299 *pDst++ = acc2;
emilmont 1:fdd22bb7aa52 300 *pDst++ = acc3;
emilmont 1:fdd22bb7aa52 301
emilmont 1:fdd22bb7aa52 302 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 303 blkCnt--;
emilmont 1:fdd22bb7aa52 304 }
emilmont 1:fdd22bb7aa52 305
emilmont 1:fdd22bb7aa52 306 while(blkCntN4 > 0u)
emilmont 1:fdd22bb7aa52 307 {
emilmont 1:fdd22bb7aa52 308 /* Copy decimation factor number of new input samples into the state buffer */
emilmont 1:fdd22bb7aa52 309 i = S->M;
emilmont 1:fdd22bb7aa52 310
emilmont 1:fdd22bb7aa52 311 do
emilmont 1:fdd22bb7aa52 312 {
emilmont 1:fdd22bb7aa52 313 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 314
emilmont 1:fdd22bb7aa52 315 } while(--i);
emilmont 1:fdd22bb7aa52 316
emilmont 1:fdd22bb7aa52 317 /* Set accumulator to zero */
emilmont 1:fdd22bb7aa52 318 sum0 = 0.0f;
emilmont 1:fdd22bb7aa52 319
emilmont 1:fdd22bb7aa52 320 /* Initialize state pointer */
emilmont 1:fdd22bb7aa52 321 px = pState;
emilmont 1:fdd22bb7aa52 322
emilmont 1:fdd22bb7aa52 323 /* Initialize coeff pointer */
emilmont 1:fdd22bb7aa52 324 pb = pCoeffs;
emilmont 1:fdd22bb7aa52 325
emilmont 1:fdd22bb7aa52 326 /* Loop unrolling. Process 4 taps at a time. */
emilmont 1:fdd22bb7aa52 327 tapCnt = numTaps >> 2;
emilmont 1:fdd22bb7aa52 328
emilmont 1:fdd22bb7aa52 329 /* Loop over the number of taps. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 330 ** Repeat until we've computed numTaps-4 coefficients. */
emilmont 1:fdd22bb7aa52 331 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 332 {
emilmont 1:fdd22bb7aa52 333 /* Read the b[numTaps-1] coefficient */
emilmont 1:fdd22bb7aa52 334 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 335
emilmont 1:fdd22bb7aa52 336 /* Read x[n-numTaps-1] sample */
emilmont 1:fdd22bb7aa52 337 x0 = *(px++);
emilmont 1:fdd22bb7aa52 338
emilmont 1:fdd22bb7aa52 339 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 340 sum0 += x0 * c0;
emilmont 1:fdd22bb7aa52 341
emilmont 1:fdd22bb7aa52 342 /* Read the b[numTaps-2] coefficient */
emilmont 1:fdd22bb7aa52 343 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 344
emilmont 1:fdd22bb7aa52 345 /* Read x[n-numTaps-2] sample */
emilmont 1:fdd22bb7aa52 346 x0 = *(px++);
emilmont 1:fdd22bb7aa52 347
emilmont 1:fdd22bb7aa52 348 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 349 sum0 += x0 * c0;
emilmont 1:fdd22bb7aa52 350
emilmont 1:fdd22bb7aa52 351 /* Read the b[numTaps-3] coefficient */
emilmont 1:fdd22bb7aa52 352 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 353
emilmont 1:fdd22bb7aa52 354 /* Read x[n-numTaps-3] sample */
emilmont 1:fdd22bb7aa52 355 x0 = *(px++);
emilmont 1:fdd22bb7aa52 356
emilmont 1:fdd22bb7aa52 357 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 358 sum0 += x0 * c0;
emilmont 1:fdd22bb7aa52 359
emilmont 1:fdd22bb7aa52 360 /* Read the b[numTaps-4] coefficient */
emilmont 1:fdd22bb7aa52 361 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 362
emilmont 1:fdd22bb7aa52 363 /* Read x[n-numTaps-4] sample */
emilmont 1:fdd22bb7aa52 364 x0 = *(px++);
emilmont 1:fdd22bb7aa52 365
emilmont 1:fdd22bb7aa52 366 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 367 sum0 += x0 * c0;
emilmont 1:fdd22bb7aa52 368
emilmont 1:fdd22bb7aa52 369 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 370 tapCnt--;
emilmont 1:fdd22bb7aa52 371 }
emilmont 1:fdd22bb7aa52 372
emilmont 1:fdd22bb7aa52 373 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emilmont 1:fdd22bb7aa52 374 tapCnt = numTaps % 0x4u;
emilmont 1:fdd22bb7aa52 375
emilmont 1:fdd22bb7aa52 376 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 377 {
emilmont 1:fdd22bb7aa52 378 /* Read coefficients */
emilmont 1:fdd22bb7aa52 379 c0 = *(pb++);
emilmont 1:fdd22bb7aa52 380
emilmont 1:fdd22bb7aa52 381 /* Fetch 1 state variable */
emilmont 1:fdd22bb7aa52 382 x0 = *(px++);
emilmont 1:fdd22bb7aa52 383
emilmont 1:fdd22bb7aa52 384 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 385 sum0 += x0 * c0;
emilmont 1:fdd22bb7aa52 386
emilmont 1:fdd22bb7aa52 387 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 388 tapCnt--;
emilmont 1:fdd22bb7aa52 389 }
emilmont 1:fdd22bb7aa52 390
emilmont 1:fdd22bb7aa52 391 /* Advance the state pointer by the decimation factor
emilmont 1:fdd22bb7aa52 392 * to process the next group of decimation factor number samples */
emilmont 1:fdd22bb7aa52 393 pState = pState + S->M;
emilmont 1:fdd22bb7aa52 394
emilmont 1:fdd22bb7aa52 395 /* The result is in the accumulator, store in the destination buffer. */
emilmont 1:fdd22bb7aa52 396 *pDst++ = sum0;
emilmont 1:fdd22bb7aa52 397
emilmont 1:fdd22bb7aa52 398 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 399 blkCntN4--;
emilmont 1:fdd22bb7aa52 400 }
emilmont 1:fdd22bb7aa52 401
emilmont 1:fdd22bb7aa52 402 /* Processing is complete.
emilmont 1:fdd22bb7aa52 403 ** Now copy the last numTaps - 1 samples to the satrt of the state buffer.
emilmont 1:fdd22bb7aa52 404 ** This prepares the state buffer for the next function call. */
emilmont 1:fdd22bb7aa52 405
emilmont 1:fdd22bb7aa52 406 /* Points to the start of the state buffer */
emilmont 1:fdd22bb7aa52 407 pStateCurnt = S->pState;
emilmont 1:fdd22bb7aa52 408
emilmont 1:fdd22bb7aa52 409 i = (numTaps - 1u) >> 2;
emilmont 1:fdd22bb7aa52 410
emilmont 1:fdd22bb7aa52 411 /* copy data */
emilmont 1:fdd22bb7aa52 412 while(i > 0u)
emilmont 1:fdd22bb7aa52 413 {
emilmont 1:fdd22bb7aa52 414 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 415 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 416 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 417 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 418
emilmont 1:fdd22bb7aa52 419 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 420 i--;
emilmont 1:fdd22bb7aa52 421 }
emilmont 1:fdd22bb7aa52 422
emilmont 1:fdd22bb7aa52 423 i = (numTaps - 1u) % 0x04u;
emilmont 1:fdd22bb7aa52 424
emilmont 1:fdd22bb7aa52 425 /* copy data */
emilmont 1:fdd22bb7aa52 426 while(i > 0u)
emilmont 1:fdd22bb7aa52 427 {
emilmont 1:fdd22bb7aa52 428 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 429
emilmont 1:fdd22bb7aa52 430 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 431 i--;
emilmont 1:fdd22bb7aa52 432 }
emilmont 1:fdd22bb7aa52 433
emilmont 1:fdd22bb7aa52 434 #else
emilmont 1:fdd22bb7aa52 435
emilmont 1:fdd22bb7aa52 436 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 437
emilmont 1:fdd22bb7aa52 438 /* S->pState buffer contains previous frame (numTaps - 1) samples */
emilmont 1:fdd22bb7aa52 439 /* pStateCurnt points to the location where the new input data should be written */
emilmont 1:fdd22bb7aa52 440 pStateCurnt = S->pState + (numTaps - 1u);
emilmont 1:fdd22bb7aa52 441
emilmont 1:fdd22bb7aa52 442 /* Total number of output samples to be computed */
emilmont 1:fdd22bb7aa52 443 blkCnt = outBlockSize;
emilmont 1:fdd22bb7aa52 444
emilmont 1:fdd22bb7aa52 445 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 446 {
emilmont 1:fdd22bb7aa52 447 /* Copy decimation factor number of new input samples into the state buffer */
emilmont 1:fdd22bb7aa52 448 i = S->M;
emilmont 1:fdd22bb7aa52 449
emilmont 1:fdd22bb7aa52 450 do
emilmont 1:fdd22bb7aa52 451 {
emilmont 1:fdd22bb7aa52 452 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 453
emilmont 1:fdd22bb7aa52 454 } while(--i);
emilmont 1:fdd22bb7aa52 455
emilmont 1:fdd22bb7aa52 456 /* Set accumulator to zero */
emilmont 1:fdd22bb7aa52 457 sum0 = 0.0f;
emilmont 1:fdd22bb7aa52 458
emilmont 1:fdd22bb7aa52 459 /* Initialize state pointer */
emilmont 1:fdd22bb7aa52 460 px = pState;
emilmont 1:fdd22bb7aa52 461
emilmont 1:fdd22bb7aa52 462 /* Initialize coeff pointer */
emilmont 1:fdd22bb7aa52 463 pb = pCoeffs;
emilmont 1:fdd22bb7aa52 464
emilmont 1:fdd22bb7aa52 465 tapCnt = numTaps;
emilmont 1:fdd22bb7aa52 466
emilmont 1:fdd22bb7aa52 467 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 468 {
emilmont 1:fdd22bb7aa52 469 /* Read coefficients */
emilmont 1:fdd22bb7aa52 470 c0 = *pb++;
emilmont 1:fdd22bb7aa52 471
emilmont 1:fdd22bb7aa52 472 /* Fetch 1 state variable */
emilmont 1:fdd22bb7aa52 473 x0 = *px++;
emilmont 1:fdd22bb7aa52 474
emilmont 1:fdd22bb7aa52 475 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 476 sum0 += x0 * c0;
emilmont 1:fdd22bb7aa52 477
emilmont 1:fdd22bb7aa52 478 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 479 tapCnt--;
emilmont 1:fdd22bb7aa52 480 }
emilmont 1:fdd22bb7aa52 481
emilmont 1:fdd22bb7aa52 482 /* Advance the state pointer by the decimation factor
emilmont 1:fdd22bb7aa52 483 * to process the next group of decimation factor number samples */
emilmont 1:fdd22bb7aa52 484 pState = pState + S->M;
emilmont 1:fdd22bb7aa52 485
emilmont 1:fdd22bb7aa52 486 /* The result is in the accumulator, store in the destination buffer. */
emilmont 1:fdd22bb7aa52 487 *pDst++ = sum0;
emilmont 1:fdd22bb7aa52 488
emilmont 1:fdd22bb7aa52 489 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 490 blkCnt--;
emilmont 1:fdd22bb7aa52 491 }
emilmont 1:fdd22bb7aa52 492
emilmont 1:fdd22bb7aa52 493 /* Processing is complete.
emilmont 1:fdd22bb7aa52 494 ** Now copy the last numTaps - 1 samples to the start of the state buffer.
emilmont 1:fdd22bb7aa52 495 ** This prepares the state buffer for the next function call. */
emilmont 1:fdd22bb7aa52 496
emilmont 1:fdd22bb7aa52 497 /* Points to the start of the state buffer */
emilmont 1:fdd22bb7aa52 498 pStateCurnt = S->pState;
emilmont 1:fdd22bb7aa52 499
emilmont 1:fdd22bb7aa52 500 /* Copy numTaps number of values */
emilmont 1:fdd22bb7aa52 501 i = (numTaps - 1u);
emilmont 1:fdd22bb7aa52 502
emilmont 1:fdd22bb7aa52 503 /* copy data */
emilmont 1:fdd22bb7aa52 504 while(i > 0u)
emilmont 1:fdd22bb7aa52 505 {
emilmont 1:fdd22bb7aa52 506 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 507
emilmont 1:fdd22bb7aa52 508 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 509 i--;
emilmont 1:fdd22bb7aa52 510 }
emilmont 1:fdd22bb7aa52 511
emilmont 1:fdd22bb7aa52 512 #endif /* #ifndef ARM_MATH_CM0 */
emilmont 1:fdd22bb7aa52 513
emilmont 1:fdd22bb7aa52 514 }
emilmont 1:fdd22bb7aa52 515
emilmont 1:fdd22bb7aa52 516 /**
emilmont 1:fdd22bb7aa52 517 * @} end of FIR_decimate group
emilmont 1:fdd22bb7aa52 518 */