V4.0.1 of the ARM CMSIS DSP libraries. Note that arm_bitreversal2.s, arm_cfft_f32.c and arm_rfft_fast_f32.c had to be removed. arm_bitreversal2.s will not assemble with the online tools. So, the fast f32 FFT functions are not yet available. All the other FFT functions are available.

Dependents:   MPU9150_Example fir_f32 fir_f32 MPU9150_nucleo_noni2cdev ... more

Committer:
emh203
Date:
Mon Jul 28 15:03:15 2014 +0000
Revision:
0:3d9c67d97d6f
1st working commit.   Had to remove arm_bitreversal2.s     arm_cfft_f32.c and arm_rfft_fast_f32.c.    The .s will not assemble.      For now I removed these functions so we could at least have a library for the other functions.

Who changed what in which revision?

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