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_lattice_f32.c
emh203 0:3d9c67d97d6f 9 *
emh203 0:3d9c67d97d6f 10 * Description: Processing function for the floating-point FIR Lattice filter.
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_Lattice Finite Impulse Response (FIR) Lattice Filters
emh203 0:3d9c67d97d6f 49 *
emh203 0:3d9c67d97d6f 50 * This set of functions implements Finite Impulse Response (FIR) lattice filters
emh203 0:3d9c67d97d6f 51 * for Q15, Q31 and floating-point data types. Lattice filters are used in a
emh203 0:3d9c67d97d6f 52 * variety of adaptive filter applications. The filter structure is feedforward and
emh203 0:3d9c67d97d6f 53 * the net impulse response is finite length.
emh203 0:3d9c67d97d6f 54 * The functions operate on blocks
emh203 0:3d9c67d97d6f 55 * of input and output data and each call to the function processes
emh203 0:3d9c67d97d6f 56 * <code>blockSize</code> samples through the filter. <code>pSrc</code> and
emh203 0:3d9c67d97d6f 57 * <code>pDst</code> point to input and output arrays containing <code>blockSize</code> values.
emh203 0:3d9c67d97d6f 58 *
emh203 0:3d9c67d97d6f 59 * \par Algorithm:
emh203 0:3d9c67d97d6f 60 * \image html FIRLattice.gif "Finite Impulse Response Lattice filter"
emh203 0:3d9c67d97d6f 61 * The following difference equation is implemented:
emh203 0:3d9c67d97d6f 62 * <pre>
emh203 0:3d9c67d97d6f 63 * f0[n] = g0[n] = x[n]
emh203 0:3d9c67d97d6f 64 * fm[n] = fm-1[n] + km * gm-1[n-1] for m = 1, 2, ...M
emh203 0:3d9c67d97d6f 65 * gm[n] = km * fm-1[n] + gm-1[n-1] for m = 1, 2, ...M
emh203 0:3d9c67d97d6f 66 * y[n] = fM[n]
emh203 0:3d9c67d97d6f 67 * </pre>
emh203 0:3d9c67d97d6f 68 * \par
emh203 0:3d9c67d97d6f 69 * <code>pCoeffs</code> points to tha array of reflection coefficients of size <code>numStages</code>.
emh203 0:3d9c67d97d6f 70 * Reflection Coefficients are stored in the following order.
emh203 0:3d9c67d97d6f 71 * \par
emh203 0:3d9c67d97d6f 72 * <pre>
emh203 0:3d9c67d97d6f 73 * {k1, k2, ..., kM}
emh203 0:3d9c67d97d6f 74 * </pre>
emh203 0:3d9c67d97d6f 75 * where M is number of stages
emh203 0:3d9c67d97d6f 76 * \par
emh203 0:3d9c67d97d6f 77 * <code>pState</code> points to a state array of size <code>numStages</code>.
emh203 0:3d9c67d97d6f 78 * The state variables (g values) hold previous inputs and are stored in the following order.
emh203 0:3d9c67d97d6f 79 * <pre>
emh203 0:3d9c67d97d6f 80 * {g0[n], g1[n], g2[n] ...gM-1[n]}
emh203 0:3d9c67d97d6f 81 * </pre>
emh203 0:3d9c67d97d6f 82 * The state variables are updated after each block of data is processed; the coefficients are untouched.
emh203 0:3d9c67d97d6f 83 * \par Instance Structure
emh203 0:3d9c67d97d6f 84 * The coefficients and state variables for a filter are stored together in an instance data structure.
emh203 0:3d9c67d97d6f 85 * A separate instance structure must be defined for each filter.
emh203 0:3d9c67d97d6f 86 * Coefficient arrays may be shared among several instances while state variable arrays cannot be shared.
emh203 0:3d9c67d97d6f 87 * There are separate instance structure declarations for each of the 3 supported data types.
emh203 0:3d9c67d97d6f 88 *
emh203 0:3d9c67d97d6f 89 * \par Initialization Functions
emh203 0:3d9c67d97d6f 90 * There is also an associated initialization function for each data type.
emh203 0:3d9c67d97d6f 91 * The initialization function performs the following operations:
emh203 0:3d9c67d97d6f 92 * - Sets the values of the internal structure fields.
emh203 0:3d9c67d97d6f 93 * - Zeros out the values in the state buffer.
emh203 0:3d9c67d97d6f 94 * To do this manually without calling the init function, assign the follow subfields of the instance structure:
emh203 0:3d9c67d97d6f 95 * numStages, pCoeffs, pState. Also set all of the values in pState to zero.
emh203 0:3d9c67d97d6f 96 *
emh203 0:3d9c67d97d6f 97 * \par
emh203 0:3d9c67d97d6f 98 * Use of the initialization function is optional.
emh203 0:3d9c67d97d6f 99 * However, if the initialization function is used, then the instance structure cannot be placed into a const data section.
emh203 0:3d9c67d97d6f 100 * To place an instance structure into a const data section, the instance structure must be manually initialized.
emh203 0:3d9c67d97d6f 101 * Set the values in the state buffer to zeros and then manually initialize the instance structure as follows:
emh203 0:3d9c67d97d6f 102 * <pre>
emh203 0:3d9c67d97d6f 103 *arm_fir_lattice_instance_f32 S = {numStages, pState, pCoeffs};
emh203 0:3d9c67d97d6f 104 *arm_fir_lattice_instance_q31 S = {numStages, pState, pCoeffs};
emh203 0:3d9c67d97d6f 105 *arm_fir_lattice_instance_q15 S = {numStages, pState, pCoeffs};
emh203 0:3d9c67d97d6f 106 * </pre>
emh203 0:3d9c67d97d6f 107 * \par
emh203 0:3d9c67d97d6f 108 * where <code>numStages</code> is the number of stages in the filter; <code>pState</code> is the address of the state buffer;
emh203 0:3d9c67d97d6f 109 * <code>pCoeffs</code> is the address of the coefficient buffer.
emh203 0:3d9c67d97d6f 110 * \par Fixed-Point Behavior
emh203 0:3d9c67d97d6f 111 * Care must be taken when using the fixed-point versions of the FIR Lattice filter functions.
emh203 0:3d9c67d97d6f 112 * In particular, the overflow and saturation behavior of the accumulator used in each function must be considered.
emh203 0:3d9c67d97d6f 113 * Refer to the function specific documentation below for usage guidelines.
emh203 0:3d9c67d97d6f 114 */
emh203 0:3d9c67d97d6f 115
emh203 0:3d9c67d97d6f 116 /**
emh203 0:3d9c67d97d6f 117 * @addtogroup FIR_Lattice
emh203 0:3d9c67d97d6f 118 * @{
emh203 0:3d9c67d97d6f 119 */
emh203 0:3d9c67d97d6f 120
emh203 0:3d9c67d97d6f 121
emh203 0:3d9c67d97d6f 122 /**
emh203 0:3d9c67d97d6f 123 * @brief Processing function for the floating-point FIR lattice filter.
emh203 0:3d9c67d97d6f 124 * @param[in] *S points to an instance of the floating-point FIR lattice structure.
emh203 0:3d9c67d97d6f 125 * @param[in] *pSrc points to the block of input data.
emh203 0:3d9c67d97d6f 126 * @param[out] *pDst points to the block of output data
emh203 0:3d9c67d97d6f 127 * @param[in] blockSize number of samples to process.
emh203 0:3d9c67d97d6f 128 * @return none.
emh203 0:3d9c67d97d6f 129 */
emh203 0:3d9c67d97d6f 130
emh203 0:3d9c67d97d6f 131 void arm_fir_lattice_f32(
emh203 0:3d9c67d97d6f 132 const arm_fir_lattice_instance_f32 * S,
emh203 0:3d9c67d97d6f 133 float32_t * pSrc,
emh203 0:3d9c67d97d6f 134 float32_t * pDst,
emh203 0:3d9c67d97d6f 135 uint32_t blockSize)
emh203 0:3d9c67d97d6f 136 {
emh203 0:3d9c67d97d6f 137 float32_t *pState; /* State pointer */
emh203 0:3d9c67d97d6f 138 float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emh203 0:3d9c67d97d6f 139 float32_t *px; /* temporary state pointer */
emh203 0:3d9c67d97d6f 140 float32_t *pk; /* temporary coefficient pointer */
emh203 0:3d9c67d97d6f 141
emh203 0:3d9c67d97d6f 142
emh203 0:3d9c67d97d6f 143 #ifndef ARM_MATH_CM0_FAMILY
emh203 0:3d9c67d97d6f 144
emh203 0:3d9c67d97d6f 145 /* Run the below code for Cortex-M4 and Cortex-M3 */
emh203 0:3d9c67d97d6f 146
emh203 0:3d9c67d97d6f 147 float32_t fcurr1, fnext1, gcurr1, gnext1; /* temporary variables for first sample in loop unrolling */
emh203 0:3d9c67d97d6f 148 float32_t fcurr2, fnext2, gnext2; /* temporary variables for second sample in loop unrolling */
emh203 0:3d9c67d97d6f 149 float32_t fcurr3, fnext3, gnext3; /* temporary variables for third sample in loop unrolling */
emh203 0:3d9c67d97d6f 150 float32_t fcurr4, fnext4, gnext4; /* temporary variables for fourth sample in loop unrolling */
emh203 0:3d9c67d97d6f 151 uint32_t numStages = S->numStages; /* Number of stages in the filter */
emh203 0:3d9c67d97d6f 152 uint32_t blkCnt, stageCnt; /* temporary variables for counts */
emh203 0:3d9c67d97d6f 153
emh203 0:3d9c67d97d6f 154 gcurr1 = 0.0f;
emh203 0:3d9c67d97d6f 155 pState = &S->pState[0];
emh203 0:3d9c67d97d6f 156
emh203 0:3d9c67d97d6f 157 blkCnt = blockSize >> 2;
emh203 0:3d9c67d97d6f 158
emh203 0:3d9c67d97d6f 159 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
emh203 0:3d9c67d97d6f 160 a second loop below computes the remaining 1 to 3 samples. */
emh203 0:3d9c67d97d6f 161 while(blkCnt > 0u)
emh203 0:3d9c67d97d6f 162 {
emh203 0:3d9c67d97d6f 163
emh203 0:3d9c67d97d6f 164 /* Read two samples from input buffer */
emh203 0:3d9c67d97d6f 165 /* f0(n) = x(n) */
emh203 0:3d9c67d97d6f 166 fcurr1 = *pSrc++;
emh203 0:3d9c67d97d6f 167 fcurr2 = *pSrc++;
emh203 0:3d9c67d97d6f 168
emh203 0:3d9c67d97d6f 169 /* Initialize coeff pointer */
emh203 0:3d9c67d97d6f 170 pk = (pCoeffs);
emh203 0:3d9c67d97d6f 171
emh203 0:3d9c67d97d6f 172 /* Initialize state pointer */
emh203 0:3d9c67d97d6f 173 px = pState;
emh203 0:3d9c67d97d6f 174
emh203 0:3d9c67d97d6f 175 /* Read g0(n-1) from state */
emh203 0:3d9c67d97d6f 176 gcurr1 = *px;
emh203 0:3d9c67d97d6f 177
emh203 0:3d9c67d97d6f 178 /* Process first sample for first tap */
emh203 0:3d9c67d97d6f 179 /* f1(n) = f0(n) + K1 * g0(n-1) */
emh203 0:3d9c67d97d6f 180 fnext1 = fcurr1 + ((*pk) * gcurr1);
emh203 0:3d9c67d97d6f 181 /* g1(n) = f0(n) * K1 + g0(n-1) */
emh203 0:3d9c67d97d6f 182 gnext1 = (fcurr1 * (*pk)) + gcurr1;
emh203 0:3d9c67d97d6f 183
emh203 0:3d9c67d97d6f 184 /* Process second sample for first tap */
emh203 0:3d9c67d97d6f 185 /* for sample 2 processing */
emh203 0:3d9c67d97d6f 186 fnext2 = fcurr2 + ((*pk) * fcurr1);
emh203 0:3d9c67d97d6f 187 gnext2 = (fcurr2 * (*pk)) + fcurr1;
emh203 0:3d9c67d97d6f 188
emh203 0:3d9c67d97d6f 189 /* Read next two samples from input buffer */
emh203 0:3d9c67d97d6f 190 /* f0(n+2) = x(n+2) */
emh203 0:3d9c67d97d6f 191 fcurr3 = *pSrc++;
emh203 0:3d9c67d97d6f 192 fcurr4 = *pSrc++;
emh203 0:3d9c67d97d6f 193
emh203 0:3d9c67d97d6f 194 /* Copy only last input samples into the state buffer
emh203 0:3d9c67d97d6f 195 which will be used for next four samples processing */
emh203 0:3d9c67d97d6f 196 *px++ = fcurr4;
emh203 0:3d9c67d97d6f 197
emh203 0:3d9c67d97d6f 198 /* Process third sample for first tap */
emh203 0:3d9c67d97d6f 199 fnext3 = fcurr3 + ((*pk) * fcurr2);
emh203 0:3d9c67d97d6f 200 gnext3 = (fcurr3 * (*pk)) + fcurr2;
emh203 0:3d9c67d97d6f 201
emh203 0:3d9c67d97d6f 202 /* Process fourth sample for first tap */
emh203 0:3d9c67d97d6f 203 fnext4 = fcurr4 + ((*pk) * fcurr3);
emh203 0:3d9c67d97d6f 204 gnext4 = (fcurr4 * (*pk++)) + fcurr3;
emh203 0:3d9c67d97d6f 205
emh203 0:3d9c67d97d6f 206 /* Update of f values for next coefficient set processing */
emh203 0:3d9c67d97d6f 207 fcurr1 = fnext1;
emh203 0:3d9c67d97d6f 208 fcurr2 = fnext2;
emh203 0:3d9c67d97d6f 209 fcurr3 = fnext3;
emh203 0:3d9c67d97d6f 210 fcurr4 = fnext4;
emh203 0:3d9c67d97d6f 211
emh203 0:3d9c67d97d6f 212 /* Loop unrolling. Process 4 taps at a time . */
emh203 0:3d9c67d97d6f 213 stageCnt = (numStages - 1u) >> 2u;
emh203 0:3d9c67d97d6f 214
emh203 0:3d9c67d97d6f 215 /* Loop over the number of taps. Unroll by a factor of 4.
emh203 0:3d9c67d97d6f 216 ** Repeat until we've computed numStages-3 coefficients. */
emh203 0:3d9c67d97d6f 217
emh203 0:3d9c67d97d6f 218 /* Process 2nd, 3rd, 4th and 5th taps ... here */
emh203 0:3d9c67d97d6f 219 while(stageCnt > 0u)
emh203 0:3d9c67d97d6f 220 {
emh203 0:3d9c67d97d6f 221 /* Read g1(n-1), g3(n-1) .... from state */
emh203 0:3d9c67d97d6f 222 gcurr1 = *px;
emh203 0:3d9c67d97d6f 223
emh203 0:3d9c67d97d6f 224 /* save g1(n) in state buffer */
emh203 0:3d9c67d97d6f 225 *px++ = gnext4;
emh203 0:3d9c67d97d6f 226
emh203 0:3d9c67d97d6f 227 /* Process first sample for 2nd, 6th .. tap */
emh203 0:3d9c67d97d6f 228 /* Sample processing for K2, K6.... */
emh203 0:3d9c67d97d6f 229 /* f2(n) = f1(n) + K2 * g1(n-1) */
emh203 0:3d9c67d97d6f 230 fnext1 = fcurr1 + ((*pk) * gcurr1);
emh203 0:3d9c67d97d6f 231 /* Process second sample for 2nd, 6th .. tap */
emh203 0:3d9c67d97d6f 232 /* for sample 2 processing */
emh203 0:3d9c67d97d6f 233 fnext2 = fcurr2 + ((*pk) * gnext1);
emh203 0:3d9c67d97d6f 234 /* Process third sample for 2nd, 6th .. tap */
emh203 0:3d9c67d97d6f 235 fnext3 = fcurr3 + ((*pk) * gnext2);
emh203 0:3d9c67d97d6f 236 /* Process fourth sample for 2nd, 6th .. tap */
emh203 0:3d9c67d97d6f 237 fnext4 = fcurr4 + ((*pk) * gnext3);
emh203 0:3d9c67d97d6f 238
emh203 0:3d9c67d97d6f 239 /* g2(n) = f1(n) * K2 + g1(n-1) */
emh203 0:3d9c67d97d6f 240 /* Calculation of state values for next stage */
emh203 0:3d9c67d97d6f 241 gnext4 = (fcurr4 * (*pk)) + gnext3;
emh203 0:3d9c67d97d6f 242 gnext3 = (fcurr3 * (*pk)) + gnext2;
emh203 0:3d9c67d97d6f 243 gnext2 = (fcurr2 * (*pk)) + gnext1;
emh203 0:3d9c67d97d6f 244 gnext1 = (fcurr1 * (*pk++)) + gcurr1;
emh203 0:3d9c67d97d6f 245
emh203 0:3d9c67d97d6f 246
emh203 0:3d9c67d97d6f 247 /* Read g2(n-1), g4(n-1) .... from state */
emh203 0:3d9c67d97d6f 248 gcurr1 = *px;
emh203 0:3d9c67d97d6f 249
emh203 0:3d9c67d97d6f 250 /* save g2(n) in state buffer */
emh203 0:3d9c67d97d6f 251 *px++ = gnext4;
emh203 0:3d9c67d97d6f 252
emh203 0:3d9c67d97d6f 253 /* Sample processing for K3, K7.... */
emh203 0:3d9c67d97d6f 254 /* Process first sample for 3rd, 7th .. tap */
emh203 0:3d9c67d97d6f 255 /* f3(n) = f2(n) + K3 * g2(n-1) */
emh203 0:3d9c67d97d6f 256 fcurr1 = fnext1 + ((*pk) * gcurr1);
emh203 0:3d9c67d97d6f 257 /* Process second sample for 3rd, 7th .. tap */
emh203 0:3d9c67d97d6f 258 fcurr2 = fnext2 + ((*pk) * gnext1);
emh203 0:3d9c67d97d6f 259 /* Process third sample for 3rd, 7th .. tap */
emh203 0:3d9c67d97d6f 260 fcurr3 = fnext3 + ((*pk) * gnext2);
emh203 0:3d9c67d97d6f 261 /* Process fourth sample for 3rd, 7th .. tap */
emh203 0:3d9c67d97d6f 262 fcurr4 = fnext4 + ((*pk) * gnext3);
emh203 0:3d9c67d97d6f 263
emh203 0:3d9c67d97d6f 264 /* Calculation of state values for next stage */
emh203 0:3d9c67d97d6f 265 /* g3(n) = f2(n) * K3 + g2(n-1) */
emh203 0:3d9c67d97d6f 266 gnext4 = (fnext4 * (*pk)) + gnext3;
emh203 0:3d9c67d97d6f 267 gnext3 = (fnext3 * (*pk)) + gnext2;
emh203 0:3d9c67d97d6f 268 gnext2 = (fnext2 * (*pk)) + gnext1;
emh203 0:3d9c67d97d6f 269 gnext1 = (fnext1 * (*pk++)) + gcurr1;
emh203 0:3d9c67d97d6f 270
emh203 0:3d9c67d97d6f 271
emh203 0:3d9c67d97d6f 272 /* Read g1(n-1), g3(n-1) .... from state */
emh203 0:3d9c67d97d6f 273 gcurr1 = *px;
emh203 0:3d9c67d97d6f 274
emh203 0:3d9c67d97d6f 275 /* save g3(n) in state buffer */
emh203 0:3d9c67d97d6f 276 *px++ = gnext4;
emh203 0:3d9c67d97d6f 277
emh203 0:3d9c67d97d6f 278 /* Sample processing for K4, K8.... */
emh203 0:3d9c67d97d6f 279 /* Process first sample for 4th, 8th .. tap */
emh203 0:3d9c67d97d6f 280 /* f4(n) = f3(n) + K4 * g3(n-1) */
emh203 0:3d9c67d97d6f 281 fnext1 = fcurr1 + ((*pk) * gcurr1);
emh203 0:3d9c67d97d6f 282 /* Process second sample for 4th, 8th .. tap */
emh203 0:3d9c67d97d6f 283 /* for sample 2 processing */
emh203 0:3d9c67d97d6f 284 fnext2 = fcurr2 + ((*pk) * gnext1);
emh203 0:3d9c67d97d6f 285 /* Process third sample for 4th, 8th .. tap */
emh203 0:3d9c67d97d6f 286 fnext3 = fcurr3 + ((*pk) * gnext2);
emh203 0:3d9c67d97d6f 287 /* Process fourth sample for 4th, 8th .. tap */
emh203 0:3d9c67d97d6f 288 fnext4 = fcurr4 + ((*pk) * gnext3);
emh203 0:3d9c67d97d6f 289
emh203 0:3d9c67d97d6f 290 /* g4(n) = f3(n) * K4 + g3(n-1) */
emh203 0:3d9c67d97d6f 291 /* Calculation of state values for next stage */
emh203 0:3d9c67d97d6f 292 gnext4 = (fcurr4 * (*pk)) + gnext3;
emh203 0:3d9c67d97d6f 293 gnext3 = (fcurr3 * (*pk)) + gnext2;
emh203 0:3d9c67d97d6f 294 gnext2 = (fcurr2 * (*pk)) + gnext1;
emh203 0:3d9c67d97d6f 295 gnext1 = (fcurr1 * (*pk++)) + gcurr1;
emh203 0:3d9c67d97d6f 296
emh203 0:3d9c67d97d6f 297 /* Read g2(n-1), g4(n-1) .... from state */
emh203 0:3d9c67d97d6f 298 gcurr1 = *px;
emh203 0:3d9c67d97d6f 299
emh203 0:3d9c67d97d6f 300 /* save g4(n) in state buffer */
emh203 0:3d9c67d97d6f 301 *px++ = gnext4;
emh203 0:3d9c67d97d6f 302
emh203 0:3d9c67d97d6f 303 /* Sample processing for K5, K9.... */
emh203 0:3d9c67d97d6f 304 /* Process first sample for 5th, 9th .. tap */
emh203 0:3d9c67d97d6f 305 /* f5(n) = f4(n) + K5 * g4(n-1) */
emh203 0:3d9c67d97d6f 306 fcurr1 = fnext1 + ((*pk) * gcurr1);
emh203 0:3d9c67d97d6f 307 /* Process second sample for 5th, 9th .. tap */
emh203 0:3d9c67d97d6f 308 fcurr2 = fnext2 + ((*pk) * gnext1);
emh203 0:3d9c67d97d6f 309 /* Process third sample for 5th, 9th .. tap */
emh203 0:3d9c67d97d6f 310 fcurr3 = fnext3 + ((*pk) * gnext2);
emh203 0:3d9c67d97d6f 311 /* Process fourth sample for 5th, 9th .. tap */
emh203 0:3d9c67d97d6f 312 fcurr4 = fnext4 + ((*pk) * gnext3);
emh203 0:3d9c67d97d6f 313
emh203 0:3d9c67d97d6f 314 /* Calculation of state values for next stage */
emh203 0:3d9c67d97d6f 315 /* g5(n) = f4(n) * K5 + g4(n-1) */
emh203 0:3d9c67d97d6f 316 gnext4 = (fnext4 * (*pk)) + gnext3;
emh203 0:3d9c67d97d6f 317 gnext3 = (fnext3 * (*pk)) + gnext2;
emh203 0:3d9c67d97d6f 318 gnext2 = (fnext2 * (*pk)) + gnext1;
emh203 0:3d9c67d97d6f 319 gnext1 = (fnext1 * (*pk++)) + gcurr1;
emh203 0:3d9c67d97d6f 320
emh203 0:3d9c67d97d6f 321 stageCnt--;
emh203 0:3d9c67d97d6f 322 }
emh203 0:3d9c67d97d6f 323
emh203 0:3d9c67d97d6f 324 /* If the (filter length -1) is not a multiple of 4, compute the remaining filter taps */
emh203 0:3d9c67d97d6f 325 stageCnt = (numStages - 1u) % 0x4u;
emh203 0:3d9c67d97d6f 326
emh203 0:3d9c67d97d6f 327 while(stageCnt > 0u)
emh203 0:3d9c67d97d6f 328 {
emh203 0:3d9c67d97d6f 329 gcurr1 = *px;
emh203 0:3d9c67d97d6f 330
emh203 0:3d9c67d97d6f 331 /* save g value in state buffer */
emh203 0:3d9c67d97d6f 332 *px++ = gnext4;
emh203 0:3d9c67d97d6f 333
emh203 0:3d9c67d97d6f 334 /* Process four samples for last three taps here */
emh203 0:3d9c67d97d6f 335 fnext1 = fcurr1 + ((*pk) * gcurr1);
emh203 0:3d9c67d97d6f 336 fnext2 = fcurr2 + ((*pk) * gnext1);
emh203 0:3d9c67d97d6f 337 fnext3 = fcurr3 + ((*pk) * gnext2);
emh203 0:3d9c67d97d6f 338 fnext4 = fcurr4 + ((*pk) * gnext3);
emh203 0:3d9c67d97d6f 339
emh203 0:3d9c67d97d6f 340 /* g1(n) = f0(n) * K1 + g0(n-1) */
emh203 0:3d9c67d97d6f 341 gnext4 = (fcurr4 * (*pk)) + gnext3;
emh203 0:3d9c67d97d6f 342 gnext3 = (fcurr3 * (*pk)) + gnext2;
emh203 0:3d9c67d97d6f 343 gnext2 = (fcurr2 * (*pk)) + gnext1;
emh203 0:3d9c67d97d6f 344 gnext1 = (fcurr1 * (*pk++)) + gcurr1;
emh203 0:3d9c67d97d6f 345
emh203 0:3d9c67d97d6f 346 /* Update of f values for next coefficient set processing */
emh203 0:3d9c67d97d6f 347 fcurr1 = fnext1;
emh203 0:3d9c67d97d6f 348 fcurr2 = fnext2;
emh203 0:3d9c67d97d6f 349 fcurr3 = fnext3;
emh203 0:3d9c67d97d6f 350 fcurr4 = fnext4;
emh203 0:3d9c67d97d6f 351
emh203 0:3d9c67d97d6f 352 stageCnt--;
emh203 0:3d9c67d97d6f 353
emh203 0:3d9c67d97d6f 354 }
emh203 0:3d9c67d97d6f 355
emh203 0:3d9c67d97d6f 356 /* The results in the 4 accumulators, store in the destination buffer. */
emh203 0:3d9c67d97d6f 357 /* y(n) = fN(n) */
emh203 0:3d9c67d97d6f 358 *pDst++ = fcurr1;
emh203 0:3d9c67d97d6f 359 *pDst++ = fcurr2;
emh203 0:3d9c67d97d6f 360 *pDst++ = fcurr3;
emh203 0:3d9c67d97d6f 361 *pDst++ = fcurr4;
emh203 0:3d9c67d97d6f 362
emh203 0:3d9c67d97d6f 363 blkCnt--;
emh203 0:3d9c67d97d6f 364 }
emh203 0:3d9c67d97d6f 365
emh203 0:3d9c67d97d6f 366 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
emh203 0:3d9c67d97d6f 367 ** No loop unrolling is used. */
emh203 0:3d9c67d97d6f 368 blkCnt = blockSize % 0x4u;
emh203 0:3d9c67d97d6f 369
emh203 0:3d9c67d97d6f 370 while(blkCnt > 0u)
emh203 0:3d9c67d97d6f 371 {
emh203 0:3d9c67d97d6f 372 /* f0(n) = x(n) */
emh203 0:3d9c67d97d6f 373 fcurr1 = *pSrc++;
emh203 0:3d9c67d97d6f 374
emh203 0:3d9c67d97d6f 375 /* Initialize coeff pointer */
emh203 0:3d9c67d97d6f 376 pk = (pCoeffs);
emh203 0:3d9c67d97d6f 377
emh203 0:3d9c67d97d6f 378 /* Initialize state pointer */
emh203 0:3d9c67d97d6f 379 px = pState;
emh203 0:3d9c67d97d6f 380
emh203 0:3d9c67d97d6f 381 /* read g2(n) from state buffer */
emh203 0:3d9c67d97d6f 382 gcurr1 = *px;
emh203 0:3d9c67d97d6f 383
emh203 0:3d9c67d97d6f 384 /* for sample 1 processing */
emh203 0:3d9c67d97d6f 385 /* f1(n) = f0(n) + K1 * g0(n-1) */
emh203 0:3d9c67d97d6f 386 fnext1 = fcurr1 + ((*pk) * gcurr1);
emh203 0:3d9c67d97d6f 387 /* g1(n) = f0(n) * K1 + g0(n-1) */
emh203 0:3d9c67d97d6f 388 gnext1 = (fcurr1 * (*pk++)) + gcurr1;
emh203 0:3d9c67d97d6f 389
emh203 0:3d9c67d97d6f 390 /* save g1(n) in state buffer */
emh203 0:3d9c67d97d6f 391 *px++ = fcurr1;
emh203 0:3d9c67d97d6f 392
emh203 0:3d9c67d97d6f 393 /* f1(n) is saved in fcurr1
emh203 0:3d9c67d97d6f 394 for next stage processing */
emh203 0:3d9c67d97d6f 395 fcurr1 = fnext1;
emh203 0:3d9c67d97d6f 396
emh203 0:3d9c67d97d6f 397 stageCnt = (numStages - 1u);
emh203 0:3d9c67d97d6f 398
emh203 0:3d9c67d97d6f 399 /* stage loop */
emh203 0:3d9c67d97d6f 400 while(stageCnt > 0u)
emh203 0:3d9c67d97d6f 401 {
emh203 0:3d9c67d97d6f 402 /* read g2(n) from state buffer */
emh203 0:3d9c67d97d6f 403 gcurr1 = *px;
emh203 0:3d9c67d97d6f 404
emh203 0:3d9c67d97d6f 405 /* save g1(n) in state buffer */
emh203 0:3d9c67d97d6f 406 *px++ = gnext1;
emh203 0:3d9c67d97d6f 407
emh203 0:3d9c67d97d6f 408 /* Sample processing for K2, K3.... */
emh203 0:3d9c67d97d6f 409 /* f2(n) = f1(n) + K2 * g1(n-1) */
emh203 0:3d9c67d97d6f 410 fnext1 = fcurr1 + ((*pk) * gcurr1);
emh203 0:3d9c67d97d6f 411 /* g2(n) = f1(n) * K2 + g1(n-1) */
emh203 0:3d9c67d97d6f 412 gnext1 = (fcurr1 * (*pk++)) + gcurr1;
emh203 0:3d9c67d97d6f 413
emh203 0:3d9c67d97d6f 414 /* f1(n) is saved in fcurr1
emh203 0:3d9c67d97d6f 415 for next stage processing */
emh203 0:3d9c67d97d6f 416 fcurr1 = fnext1;
emh203 0:3d9c67d97d6f 417
emh203 0:3d9c67d97d6f 418 stageCnt--;
emh203 0:3d9c67d97d6f 419
emh203 0:3d9c67d97d6f 420 }
emh203 0:3d9c67d97d6f 421
emh203 0:3d9c67d97d6f 422 /* y(n) = fN(n) */
emh203 0:3d9c67d97d6f 423 *pDst++ = fcurr1;
emh203 0:3d9c67d97d6f 424
emh203 0:3d9c67d97d6f 425 blkCnt--;
emh203 0:3d9c67d97d6f 426
emh203 0:3d9c67d97d6f 427 }
emh203 0:3d9c67d97d6f 428
emh203 0:3d9c67d97d6f 429 #else
emh203 0:3d9c67d97d6f 430
emh203 0:3d9c67d97d6f 431 /* Run the below code for Cortex-M0 */
emh203 0:3d9c67d97d6f 432
emh203 0:3d9c67d97d6f 433 float32_t fcurr, fnext, gcurr, gnext; /* temporary variables */
emh203 0:3d9c67d97d6f 434 uint32_t numStages = S->numStages; /* Length of the filter */
emh203 0:3d9c67d97d6f 435 uint32_t blkCnt, stageCnt; /* temporary variables for counts */
emh203 0:3d9c67d97d6f 436
emh203 0:3d9c67d97d6f 437 pState = &S->pState[0];
emh203 0:3d9c67d97d6f 438
emh203 0:3d9c67d97d6f 439 blkCnt = blockSize;
emh203 0:3d9c67d97d6f 440
emh203 0:3d9c67d97d6f 441 while(blkCnt > 0u)
emh203 0:3d9c67d97d6f 442 {
emh203 0:3d9c67d97d6f 443 /* f0(n) = x(n) */
emh203 0:3d9c67d97d6f 444 fcurr = *pSrc++;
emh203 0:3d9c67d97d6f 445
emh203 0:3d9c67d97d6f 446 /* Initialize coeff pointer */
emh203 0:3d9c67d97d6f 447 pk = pCoeffs;
emh203 0:3d9c67d97d6f 448
emh203 0:3d9c67d97d6f 449 /* Initialize state pointer */
emh203 0:3d9c67d97d6f 450 px = pState;
emh203 0:3d9c67d97d6f 451
emh203 0:3d9c67d97d6f 452 /* read g0(n-1) from state buffer */
emh203 0:3d9c67d97d6f 453 gcurr = *px;
emh203 0:3d9c67d97d6f 454
emh203 0:3d9c67d97d6f 455 /* for sample 1 processing */
emh203 0:3d9c67d97d6f 456 /* f1(n) = f0(n) + K1 * g0(n-1) */
emh203 0:3d9c67d97d6f 457 fnext = fcurr + ((*pk) * gcurr);
emh203 0:3d9c67d97d6f 458 /* g1(n) = f0(n) * K1 + g0(n-1) */
emh203 0:3d9c67d97d6f 459 gnext = (fcurr * (*pk++)) + gcurr;
emh203 0:3d9c67d97d6f 460
emh203 0:3d9c67d97d6f 461 /* save f0(n) in state buffer */
emh203 0:3d9c67d97d6f 462 *px++ = fcurr;
emh203 0:3d9c67d97d6f 463
emh203 0:3d9c67d97d6f 464 /* f1(n) is saved in fcurr
emh203 0:3d9c67d97d6f 465 for next stage processing */
emh203 0:3d9c67d97d6f 466 fcurr = fnext;
emh203 0:3d9c67d97d6f 467
emh203 0:3d9c67d97d6f 468 stageCnt = (numStages - 1u);
emh203 0:3d9c67d97d6f 469
emh203 0:3d9c67d97d6f 470 /* stage loop */
emh203 0:3d9c67d97d6f 471 while(stageCnt > 0u)
emh203 0:3d9c67d97d6f 472 {
emh203 0:3d9c67d97d6f 473 /* read g2(n) from state buffer */
emh203 0:3d9c67d97d6f 474 gcurr = *px;
emh203 0:3d9c67d97d6f 475
emh203 0:3d9c67d97d6f 476 /* save g1(n) in state buffer */
emh203 0:3d9c67d97d6f 477 *px++ = gnext;
emh203 0:3d9c67d97d6f 478
emh203 0:3d9c67d97d6f 479 /* Sample processing for K2, K3.... */
emh203 0:3d9c67d97d6f 480 /* f2(n) = f1(n) + K2 * g1(n-1) */
emh203 0:3d9c67d97d6f 481 fnext = fcurr + ((*pk) * gcurr);
emh203 0:3d9c67d97d6f 482 /* g2(n) = f1(n) * K2 + g1(n-1) */
emh203 0:3d9c67d97d6f 483 gnext = (fcurr * (*pk++)) + gcurr;
emh203 0:3d9c67d97d6f 484
emh203 0:3d9c67d97d6f 485 /* f1(n) is saved in fcurr1
emh203 0:3d9c67d97d6f 486 for next stage processing */
emh203 0:3d9c67d97d6f 487 fcurr = fnext;
emh203 0:3d9c67d97d6f 488
emh203 0:3d9c67d97d6f 489 stageCnt--;
emh203 0:3d9c67d97d6f 490
emh203 0:3d9c67d97d6f 491 }
emh203 0:3d9c67d97d6f 492
emh203 0:3d9c67d97d6f 493 /* y(n) = fN(n) */
emh203 0:3d9c67d97d6f 494 *pDst++ = fcurr;
emh203 0:3d9c67d97d6f 495
emh203 0:3d9c67d97d6f 496 blkCnt--;
emh203 0:3d9c67d97d6f 497
emh203 0:3d9c67d97d6f 498 }
emh203 0:3d9c67d97d6f 499
emh203 0:3d9c67d97d6f 500 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emh203 0:3d9c67d97d6f 501
emh203 0:3d9c67d97d6f 502 }
emh203 0:3d9c67d97d6f 503
emh203 0:3d9c67d97d6f 504 /**
emh203 0:3d9c67d97d6f 505 * @} end of FIR_Lattice group
emh203 0:3d9c67d97d6f 506 */