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
FilteringFunctions/arm_iir_lattice_f32.c@0:3d9c67d97d6f, 2014-07-28 (annotated)
- 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?
User | Revision | Line number | New 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_iir_lattice_f32.c |
emh203 | 0:3d9c67d97d6f | 9 | * |
emh203 | 0:3d9c67d97d6f | 10 | * Description: Floating-point IIR Lattice filter processing function. |
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 IIR_Lattice Infinite Impulse Response (IIR) Lattice Filters |
emh203 | 0:3d9c67d97d6f | 49 | * |
emh203 | 0:3d9c67d97d6f | 50 | * This set of functions implements 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 has feedforward and |
emh203 | 0:3d9c67d97d6f | 53 | * feedback components and the net impulse response is infinite 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 IIRLattice.gif "Infinite Impulse Response Lattice filter" |
emh203 | 0:3d9c67d97d6f | 61 | * <pre> |
emh203 | 0:3d9c67d97d6f | 62 | * fN(n) = x(n) |
emh203 | 0:3d9c67d97d6f | 63 | * fm-1(n) = fm(n) - km * gm-1(n-1) for m = N, N-1, ...1 |
emh203 | 0:3d9c67d97d6f | 64 | * gm(n) = km * fm-1(n) + gm-1(n-1) for m = N, N-1, ...1 |
emh203 | 0:3d9c67d97d6f | 65 | * y(n) = vN * gN(n) + vN-1 * gN-1(n) + ...+ v0 * g0(n) |
emh203 | 0:3d9c67d97d6f | 66 | * </pre> |
emh203 | 0:3d9c67d97d6f | 67 | * \par |
emh203 | 0:3d9c67d97d6f | 68 | * <code>pkCoeffs</code> points to array of reflection coefficients of size <code>numStages</code>. |
emh203 | 0:3d9c67d97d6f | 69 | * Reflection coefficients are stored in time-reversed order. |
emh203 | 0:3d9c67d97d6f | 70 | * \par |
emh203 | 0:3d9c67d97d6f | 71 | * <pre> |
emh203 | 0:3d9c67d97d6f | 72 | * {kN, kN-1, ....k1} |
emh203 | 0:3d9c67d97d6f | 73 | * </pre> |
emh203 | 0:3d9c67d97d6f | 74 | * <code>pvCoeffs</code> points to the array of ladder coefficients of size <code>(numStages+1)</code>. |
emh203 | 0:3d9c67d97d6f | 75 | * Ladder coefficients are stored in time-reversed order. |
emh203 | 0:3d9c67d97d6f | 76 | * \par |
emh203 | 0:3d9c67d97d6f | 77 | * <pre> |
emh203 | 0:3d9c67d97d6f | 78 | * {vN, vN-1, ...v0} |
emh203 | 0:3d9c67d97d6f | 79 | * </pre> |
emh203 | 0:3d9c67d97d6f | 80 | * <code>pState</code> points to a state array of size <code>numStages + blockSize</code>. |
emh203 | 0:3d9c67d97d6f | 81 | * The state variables shown in the figure above (the g values) are stored in the <code>pState</code> array. |
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, pkCoeffs, pvCoeffs, 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_iir_lattice_instance_f32 S = {numStages, pState, pkCoeffs, pvCoeffs}; |
emh203 | 0:3d9c67d97d6f | 104 | *arm_iir_lattice_instance_q31 S = {numStages, pState, pkCoeffs, pvCoeffs}; |
emh203 | 0:3d9c67d97d6f | 105 | *arm_iir_lattice_instance_q15 S = {numStages, pState, pkCoeffs, pvCoeffs}; |
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> points to the state buffer array; |
emh203 | 0:3d9c67d97d6f | 109 | * <code>pkCoeffs</code> points to array of the reflection coefficients; <code>pvCoeffs</code> points to the array of ladder coefficients. |
emh203 | 0:3d9c67d97d6f | 110 | * \par Fixed-Point Behavior |
emh203 | 0:3d9c67d97d6f | 111 | * Care must be taken when using the fixed-point versions of the IIR 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 IIR_Lattice |
emh203 | 0:3d9c67d97d6f | 118 | * @{ |
emh203 | 0:3d9c67d97d6f | 119 | */ |
emh203 | 0:3d9c67d97d6f | 120 | |
emh203 | 0:3d9c67d97d6f | 121 | /** |
emh203 | 0:3d9c67d97d6f | 122 | * @brief Processing function for the floating-point IIR lattice filter. |
emh203 | 0:3d9c67d97d6f | 123 | * @param[in] *S points to an instance of the floating-point IIR lattice structure. |
emh203 | 0:3d9c67d97d6f | 124 | * @param[in] *pSrc points to the block of input data. |
emh203 | 0:3d9c67d97d6f | 125 | * @param[out] *pDst points to the block of output data. |
emh203 | 0:3d9c67d97d6f | 126 | * @param[in] blockSize number of samples to process. |
emh203 | 0:3d9c67d97d6f | 127 | * @return none. |
emh203 | 0:3d9c67d97d6f | 128 | */ |
emh203 | 0:3d9c67d97d6f | 129 | |
emh203 | 0:3d9c67d97d6f | 130 | #ifndef ARM_MATH_CM0_FAMILY |
emh203 | 0:3d9c67d97d6f | 131 | |
emh203 | 0:3d9c67d97d6f | 132 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emh203 | 0:3d9c67d97d6f | 133 | |
emh203 | 0:3d9c67d97d6f | 134 | void arm_iir_lattice_f32( |
emh203 | 0:3d9c67d97d6f | 135 | const arm_iir_lattice_instance_f32 * S, |
emh203 | 0:3d9c67d97d6f | 136 | float32_t * pSrc, |
emh203 | 0:3d9c67d97d6f | 137 | float32_t * pDst, |
emh203 | 0:3d9c67d97d6f | 138 | uint32_t blockSize) |
emh203 | 0:3d9c67d97d6f | 139 | { |
emh203 | 0:3d9c67d97d6f | 140 | float32_t fnext1, gcurr1, gnext; /* Temporary variables for lattice stages */ |
emh203 | 0:3d9c67d97d6f | 141 | float32_t acc; /* Accumlator */ |
emh203 | 0:3d9c67d97d6f | 142 | uint32_t blkCnt, tapCnt; /* temporary variables for counts */ |
emh203 | 0:3d9c67d97d6f | 143 | float32_t *px1, *px2, *pk, *pv; /* temporary pointers for state and coef */ |
emh203 | 0:3d9c67d97d6f | 144 | uint32_t numStages = S->numStages; /* number of stages */ |
emh203 | 0:3d9c67d97d6f | 145 | float32_t *pState; /* State pointer */ |
emh203 | 0:3d9c67d97d6f | 146 | float32_t *pStateCurnt; /* State current pointer */ |
emh203 | 0:3d9c67d97d6f | 147 | float32_t k1, k2; |
emh203 | 0:3d9c67d97d6f | 148 | float32_t v1, v2, v3, v4; |
emh203 | 0:3d9c67d97d6f | 149 | float32_t gcurr2; |
emh203 | 0:3d9c67d97d6f | 150 | float32_t fnext2; |
emh203 | 0:3d9c67d97d6f | 151 | |
emh203 | 0:3d9c67d97d6f | 152 | /* initialise loop count */ |
emh203 | 0:3d9c67d97d6f | 153 | blkCnt = blockSize; |
emh203 | 0:3d9c67d97d6f | 154 | |
emh203 | 0:3d9c67d97d6f | 155 | /* initialise state pointer */ |
emh203 | 0:3d9c67d97d6f | 156 | pState = &S->pState[0]; |
emh203 | 0:3d9c67d97d6f | 157 | |
emh203 | 0:3d9c67d97d6f | 158 | /* Sample processing */ |
emh203 | 0:3d9c67d97d6f | 159 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 160 | { |
emh203 | 0:3d9c67d97d6f | 161 | /* Read Sample from input buffer */ |
emh203 | 0:3d9c67d97d6f | 162 | /* fN(n) = x(n) */ |
emh203 | 0:3d9c67d97d6f | 163 | fnext2 = *pSrc++; |
emh203 | 0:3d9c67d97d6f | 164 | |
emh203 | 0:3d9c67d97d6f | 165 | /* Initialize Ladder coeff pointer */ |
emh203 | 0:3d9c67d97d6f | 166 | pv = &S->pvCoeffs[0]; |
emh203 | 0:3d9c67d97d6f | 167 | /* Initialize Reflection coeff pointer */ |
emh203 | 0:3d9c67d97d6f | 168 | pk = &S->pkCoeffs[0]; |
emh203 | 0:3d9c67d97d6f | 169 | |
emh203 | 0:3d9c67d97d6f | 170 | /* Initialize state read pointer */ |
emh203 | 0:3d9c67d97d6f | 171 | px1 = pState; |
emh203 | 0:3d9c67d97d6f | 172 | /* Initialize state write pointer */ |
emh203 | 0:3d9c67d97d6f | 173 | px2 = pState; |
emh203 | 0:3d9c67d97d6f | 174 | |
emh203 | 0:3d9c67d97d6f | 175 | /* Set accumulator to zero */ |
emh203 | 0:3d9c67d97d6f | 176 | acc = 0.0; |
emh203 | 0:3d9c67d97d6f | 177 | |
emh203 | 0:3d9c67d97d6f | 178 | /* Loop unrolling. Process 4 taps at a time. */ |
emh203 | 0:3d9c67d97d6f | 179 | tapCnt = (numStages) >> 2; |
emh203 | 0:3d9c67d97d6f | 180 | |
emh203 | 0:3d9c67d97d6f | 181 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 182 | { |
emh203 | 0:3d9c67d97d6f | 183 | /* Read gN-1(n-1) from state buffer */ |
emh203 | 0:3d9c67d97d6f | 184 | gcurr1 = *px1; |
emh203 | 0:3d9c67d97d6f | 185 | |
emh203 | 0:3d9c67d97d6f | 186 | /* read reflection coefficient kN */ |
emh203 | 0:3d9c67d97d6f | 187 | k1 = *pk; |
emh203 | 0:3d9c67d97d6f | 188 | |
emh203 | 0:3d9c67d97d6f | 189 | /* fN-1(n) = fN(n) - kN * gN-1(n-1) */ |
emh203 | 0:3d9c67d97d6f | 190 | fnext1 = fnext2 - (k1 * gcurr1); |
emh203 | 0:3d9c67d97d6f | 191 | |
emh203 | 0:3d9c67d97d6f | 192 | /* read ladder coefficient vN */ |
emh203 | 0:3d9c67d97d6f | 193 | v1 = *pv; |
emh203 | 0:3d9c67d97d6f | 194 | |
emh203 | 0:3d9c67d97d6f | 195 | /* read next reflection coefficient kN-1 */ |
emh203 | 0:3d9c67d97d6f | 196 | k2 = *(pk + 1u); |
emh203 | 0:3d9c67d97d6f | 197 | |
emh203 | 0:3d9c67d97d6f | 198 | /* Read gN-2(n-1) from state buffer */ |
emh203 | 0:3d9c67d97d6f | 199 | gcurr2 = *(px1 + 1u); |
emh203 | 0:3d9c67d97d6f | 200 | |
emh203 | 0:3d9c67d97d6f | 201 | /* read next ladder coefficient vN-1 */ |
emh203 | 0:3d9c67d97d6f | 202 | v2 = *(pv + 1u); |
emh203 | 0:3d9c67d97d6f | 203 | |
emh203 | 0:3d9c67d97d6f | 204 | /* fN-2(n) = fN-1(n) - kN-1 * gN-2(n-1) */ |
emh203 | 0:3d9c67d97d6f | 205 | fnext2 = fnext1 - (k2 * gcurr2); |
emh203 | 0:3d9c67d97d6f | 206 | |
emh203 | 0:3d9c67d97d6f | 207 | /* gN(n) = kN * fN-1(n) + gN-1(n-1) */ |
emh203 | 0:3d9c67d97d6f | 208 | gnext = gcurr1 + (k1 * fnext1); |
emh203 | 0:3d9c67d97d6f | 209 | |
emh203 | 0:3d9c67d97d6f | 210 | /* read reflection coefficient kN-2 */ |
emh203 | 0:3d9c67d97d6f | 211 | k1 = *(pk + 2u); |
emh203 | 0:3d9c67d97d6f | 212 | |
emh203 | 0:3d9c67d97d6f | 213 | /* write gN(n) into state for next sample processing */ |
emh203 | 0:3d9c67d97d6f | 214 | *px2++ = gnext; |
emh203 | 0:3d9c67d97d6f | 215 | |
emh203 | 0:3d9c67d97d6f | 216 | /* Read gN-3(n-1) from state buffer */ |
emh203 | 0:3d9c67d97d6f | 217 | gcurr1 = *(px1 + 2u); |
emh203 | 0:3d9c67d97d6f | 218 | |
emh203 | 0:3d9c67d97d6f | 219 | /* y(n) += gN(n) * vN */ |
emh203 | 0:3d9c67d97d6f | 220 | acc += (gnext * v1); |
emh203 | 0:3d9c67d97d6f | 221 | |
emh203 | 0:3d9c67d97d6f | 222 | /* fN-3(n) = fN-2(n) - kN-2 * gN-3(n-1) */ |
emh203 | 0:3d9c67d97d6f | 223 | fnext1 = fnext2 - (k1 * gcurr1); |
emh203 | 0:3d9c67d97d6f | 224 | |
emh203 | 0:3d9c67d97d6f | 225 | /* gN-1(n) = kN-1 * fN-2(n) + gN-2(n-1) */ |
emh203 | 0:3d9c67d97d6f | 226 | gnext = gcurr2 + (k2 * fnext2); |
emh203 | 0:3d9c67d97d6f | 227 | |
emh203 | 0:3d9c67d97d6f | 228 | /* Read gN-4(n-1) from state buffer */ |
emh203 | 0:3d9c67d97d6f | 229 | gcurr2 = *(px1 + 3u); |
emh203 | 0:3d9c67d97d6f | 230 | |
emh203 | 0:3d9c67d97d6f | 231 | /* y(n) += gN-1(n) * vN-1 */ |
emh203 | 0:3d9c67d97d6f | 232 | acc += (gnext * v2); |
emh203 | 0:3d9c67d97d6f | 233 | |
emh203 | 0:3d9c67d97d6f | 234 | /* read reflection coefficient kN-3 */ |
emh203 | 0:3d9c67d97d6f | 235 | k2 = *(pk + 3u); |
emh203 | 0:3d9c67d97d6f | 236 | |
emh203 | 0:3d9c67d97d6f | 237 | /* write gN-1(n) into state for next sample processing */ |
emh203 | 0:3d9c67d97d6f | 238 | *px2++ = gnext; |
emh203 | 0:3d9c67d97d6f | 239 | |
emh203 | 0:3d9c67d97d6f | 240 | /* fN-4(n) = fN-3(n) - kN-3 * gN-4(n-1) */ |
emh203 | 0:3d9c67d97d6f | 241 | fnext2 = fnext1 - (k2 * gcurr2); |
emh203 | 0:3d9c67d97d6f | 242 | |
emh203 | 0:3d9c67d97d6f | 243 | /* gN-2(n) = kN-2 * fN-3(n) + gN-3(n-1) */ |
emh203 | 0:3d9c67d97d6f | 244 | gnext = gcurr1 + (k1 * fnext1); |
emh203 | 0:3d9c67d97d6f | 245 | |
emh203 | 0:3d9c67d97d6f | 246 | /* read ladder coefficient vN-2 */ |
emh203 | 0:3d9c67d97d6f | 247 | v3 = *(pv + 2u); |
emh203 | 0:3d9c67d97d6f | 248 | |
emh203 | 0:3d9c67d97d6f | 249 | /* y(n) += gN-2(n) * vN-2 */ |
emh203 | 0:3d9c67d97d6f | 250 | acc += (gnext * v3); |
emh203 | 0:3d9c67d97d6f | 251 | |
emh203 | 0:3d9c67d97d6f | 252 | /* write gN-2(n) into state for next sample processing */ |
emh203 | 0:3d9c67d97d6f | 253 | *px2++ = gnext; |
emh203 | 0:3d9c67d97d6f | 254 | |
emh203 | 0:3d9c67d97d6f | 255 | /* update pointer */ |
emh203 | 0:3d9c67d97d6f | 256 | pk += 4u; |
emh203 | 0:3d9c67d97d6f | 257 | |
emh203 | 0:3d9c67d97d6f | 258 | /* gN-3(n) = kN-3 * fN-4(n) + gN-4(n-1) */ |
emh203 | 0:3d9c67d97d6f | 259 | gnext = (fnext2 * k2) + gcurr2; |
emh203 | 0:3d9c67d97d6f | 260 | |
emh203 | 0:3d9c67d97d6f | 261 | /* read next ladder coefficient vN-3 */ |
emh203 | 0:3d9c67d97d6f | 262 | v4 = *(pv + 3u); |
emh203 | 0:3d9c67d97d6f | 263 | |
emh203 | 0:3d9c67d97d6f | 264 | /* y(n) += gN-4(n) * vN-4 */ |
emh203 | 0:3d9c67d97d6f | 265 | acc += (gnext * v4); |
emh203 | 0:3d9c67d97d6f | 266 | |
emh203 | 0:3d9c67d97d6f | 267 | /* write gN-3(n) into state for next sample processing */ |
emh203 | 0:3d9c67d97d6f | 268 | *px2++ = gnext; |
emh203 | 0:3d9c67d97d6f | 269 | |
emh203 | 0:3d9c67d97d6f | 270 | /* update pointers */ |
emh203 | 0:3d9c67d97d6f | 271 | px1 += 4u; |
emh203 | 0:3d9c67d97d6f | 272 | pv += 4u; |
emh203 | 0:3d9c67d97d6f | 273 | |
emh203 | 0:3d9c67d97d6f | 274 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 275 | |
emh203 | 0:3d9c67d97d6f | 276 | } |
emh203 | 0:3d9c67d97d6f | 277 | |
emh203 | 0:3d9c67d97d6f | 278 | /* If the filter length is not a multiple of 4, compute the remaining filter taps */ |
emh203 | 0:3d9c67d97d6f | 279 | tapCnt = (numStages) % 0x4u; |
emh203 | 0:3d9c67d97d6f | 280 | |
emh203 | 0:3d9c67d97d6f | 281 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 282 | { |
emh203 | 0:3d9c67d97d6f | 283 | gcurr1 = *px1++; |
emh203 | 0:3d9c67d97d6f | 284 | /* Process sample for last taps */ |
emh203 | 0:3d9c67d97d6f | 285 | fnext1 = fnext2 - ((*pk) * gcurr1); |
emh203 | 0:3d9c67d97d6f | 286 | gnext = (fnext1 * (*pk++)) + gcurr1; |
emh203 | 0:3d9c67d97d6f | 287 | /* Output samples for last taps */ |
emh203 | 0:3d9c67d97d6f | 288 | acc += (gnext * (*pv++)); |
emh203 | 0:3d9c67d97d6f | 289 | *px2++ = gnext; |
emh203 | 0:3d9c67d97d6f | 290 | fnext2 = fnext1; |
emh203 | 0:3d9c67d97d6f | 291 | |
emh203 | 0:3d9c67d97d6f | 292 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 293 | |
emh203 | 0:3d9c67d97d6f | 294 | } |
emh203 | 0:3d9c67d97d6f | 295 | |
emh203 | 0:3d9c67d97d6f | 296 | /* y(n) += g0(n) * v0 */ |
emh203 | 0:3d9c67d97d6f | 297 | acc += (fnext2 * (*pv)); |
emh203 | 0:3d9c67d97d6f | 298 | |
emh203 | 0:3d9c67d97d6f | 299 | *px2++ = fnext2; |
emh203 | 0:3d9c67d97d6f | 300 | |
emh203 | 0:3d9c67d97d6f | 301 | /* write out into pDst */ |
emh203 | 0:3d9c67d97d6f | 302 | *pDst++ = acc; |
emh203 | 0:3d9c67d97d6f | 303 | |
emh203 | 0:3d9c67d97d6f | 304 | /* Advance the state pointer by 4 to process the next group of 4 samples */ |
emh203 | 0:3d9c67d97d6f | 305 | pState = pState + 1u; |
emh203 | 0:3d9c67d97d6f | 306 | |
emh203 | 0:3d9c67d97d6f | 307 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 308 | |
emh203 | 0:3d9c67d97d6f | 309 | } |
emh203 | 0:3d9c67d97d6f | 310 | |
emh203 | 0:3d9c67d97d6f | 311 | /* Processing is complete. Now copy last S->numStages samples to start of the buffer |
emh203 | 0:3d9c67d97d6f | 312 | for the preperation of next frame process */ |
emh203 | 0:3d9c67d97d6f | 313 | |
emh203 | 0:3d9c67d97d6f | 314 | /* Points to the start of the state buffer */ |
emh203 | 0:3d9c67d97d6f | 315 | pStateCurnt = &S->pState[0]; |
emh203 | 0:3d9c67d97d6f | 316 | pState = &S->pState[blockSize]; |
emh203 | 0:3d9c67d97d6f | 317 | |
emh203 | 0:3d9c67d97d6f | 318 | tapCnt = numStages >> 2u; |
emh203 | 0:3d9c67d97d6f | 319 | |
emh203 | 0:3d9c67d97d6f | 320 | /* copy data */ |
emh203 | 0:3d9c67d97d6f | 321 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 322 | { |
emh203 | 0:3d9c67d97d6f | 323 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 324 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 325 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 326 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 327 | |
emh203 | 0:3d9c67d97d6f | 328 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 329 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 330 | |
emh203 | 0:3d9c67d97d6f | 331 | } |
emh203 | 0:3d9c67d97d6f | 332 | |
emh203 | 0:3d9c67d97d6f | 333 | /* Calculate remaining number of copies */ |
emh203 | 0:3d9c67d97d6f | 334 | tapCnt = (numStages) % 0x4u; |
emh203 | 0:3d9c67d97d6f | 335 | |
emh203 | 0:3d9c67d97d6f | 336 | /* Copy the remaining q31_t data */ |
emh203 | 0:3d9c67d97d6f | 337 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 338 | { |
emh203 | 0:3d9c67d97d6f | 339 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 340 | |
emh203 | 0:3d9c67d97d6f | 341 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 342 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 343 | } |
emh203 | 0:3d9c67d97d6f | 344 | } |
emh203 | 0:3d9c67d97d6f | 345 | |
emh203 | 0:3d9c67d97d6f | 346 | #else |
emh203 | 0:3d9c67d97d6f | 347 | |
emh203 | 0:3d9c67d97d6f | 348 | void arm_iir_lattice_f32( |
emh203 | 0:3d9c67d97d6f | 349 | const arm_iir_lattice_instance_f32 * S, |
emh203 | 0:3d9c67d97d6f | 350 | float32_t * pSrc, |
emh203 | 0:3d9c67d97d6f | 351 | float32_t * pDst, |
emh203 | 0:3d9c67d97d6f | 352 | uint32_t blockSize) |
emh203 | 0:3d9c67d97d6f | 353 | { |
emh203 | 0:3d9c67d97d6f | 354 | float32_t fcurr, fnext = 0, gcurr, gnext; /* Temporary variables for lattice stages */ |
emh203 | 0:3d9c67d97d6f | 355 | float32_t acc; /* Accumlator */ |
emh203 | 0:3d9c67d97d6f | 356 | uint32_t blkCnt, tapCnt; /* temporary variables for counts */ |
emh203 | 0:3d9c67d97d6f | 357 | float32_t *px1, *px2, *pk, *pv; /* temporary pointers for state and coef */ |
emh203 | 0:3d9c67d97d6f | 358 | uint32_t numStages = S->numStages; /* number of stages */ |
emh203 | 0:3d9c67d97d6f | 359 | float32_t *pState; /* State pointer */ |
emh203 | 0:3d9c67d97d6f | 360 | float32_t *pStateCurnt; /* State current pointer */ |
emh203 | 0:3d9c67d97d6f | 361 | |
emh203 | 0:3d9c67d97d6f | 362 | |
emh203 | 0:3d9c67d97d6f | 363 | /* Run the below code for Cortex-M0 */ |
emh203 | 0:3d9c67d97d6f | 364 | |
emh203 | 0:3d9c67d97d6f | 365 | blkCnt = blockSize; |
emh203 | 0:3d9c67d97d6f | 366 | |
emh203 | 0:3d9c67d97d6f | 367 | pState = &S->pState[0]; |
emh203 | 0:3d9c67d97d6f | 368 | |
emh203 | 0:3d9c67d97d6f | 369 | /* Sample processing */ |
emh203 | 0:3d9c67d97d6f | 370 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 371 | { |
emh203 | 0:3d9c67d97d6f | 372 | /* Read Sample from input buffer */ |
emh203 | 0:3d9c67d97d6f | 373 | /* fN(n) = x(n) */ |
emh203 | 0:3d9c67d97d6f | 374 | fcurr = *pSrc++; |
emh203 | 0:3d9c67d97d6f | 375 | |
emh203 | 0:3d9c67d97d6f | 376 | /* Initialize state read pointer */ |
emh203 | 0:3d9c67d97d6f | 377 | px1 = pState; |
emh203 | 0:3d9c67d97d6f | 378 | /* Initialize state write pointer */ |
emh203 | 0:3d9c67d97d6f | 379 | px2 = pState; |
emh203 | 0:3d9c67d97d6f | 380 | /* Set accumulator to zero */ |
emh203 | 0:3d9c67d97d6f | 381 | acc = 0.0f; |
emh203 | 0:3d9c67d97d6f | 382 | /* Initialize Ladder coeff pointer */ |
emh203 | 0:3d9c67d97d6f | 383 | pv = &S->pvCoeffs[0]; |
emh203 | 0:3d9c67d97d6f | 384 | /* Initialize Reflection coeff pointer */ |
emh203 | 0:3d9c67d97d6f | 385 | pk = &S->pkCoeffs[0]; |
emh203 | 0:3d9c67d97d6f | 386 | |
emh203 | 0:3d9c67d97d6f | 387 | |
emh203 | 0:3d9c67d97d6f | 388 | /* Process sample for numStages */ |
emh203 | 0:3d9c67d97d6f | 389 | tapCnt = numStages; |
emh203 | 0:3d9c67d97d6f | 390 | |
emh203 | 0:3d9c67d97d6f | 391 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 392 | { |
emh203 | 0:3d9c67d97d6f | 393 | gcurr = *px1++; |
emh203 | 0:3d9c67d97d6f | 394 | /* Process sample for last taps */ |
emh203 | 0:3d9c67d97d6f | 395 | fnext = fcurr - ((*pk) * gcurr); |
emh203 | 0:3d9c67d97d6f | 396 | gnext = (fnext * (*pk++)) + gcurr; |
emh203 | 0:3d9c67d97d6f | 397 | |
emh203 | 0:3d9c67d97d6f | 398 | /* Output samples for last taps */ |
emh203 | 0:3d9c67d97d6f | 399 | acc += (gnext * (*pv++)); |
emh203 | 0:3d9c67d97d6f | 400 | *px2++ = gnext; |
emh203 | 0:3d9c67d97d6f | 401 | fcurr = fnext; |
emh203 | 0:3d9c67d97d6f | 402 | |
emh203 | 0:3d9c67d97d6f | 403 | /* Decrementing loop counter */ |
emh203 | 0:3d9c67d97d6f | 404 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 405 | |
emh203 | 0:3d9c67d97d6f | 406 | } |
emh203 | 0:3d9c67d97d6f | 407 | |
emh203 | 0:3d9c67d97d6f | 408 | /* y(n) += g0(n) * v0 */ |
emh203 | 0:3d9c67d97d6f | 409 | acc += (fnext * (*pv)); |
emh203 | 0:3d9c67d97d6f | 410 | |
emh203 | 0:3d9c67d97d6f | 411 | *px2++ = fnext; |
emh203 | 0:3d9c67d97d6f | 412 | |
emh203 | 0:3d9c67d97d6f | 413 | /* write out into pDst */ |
emh203 | 0:3d9c67d97d6f | 414 | *pDst++ = acc; |
emh203 | 0:3d9c67d97d6f | 415 | |
emh203 | 0:3d9c67d97d6f | 416 | /* Advance the state pointer by 1 to process the next group of samples */ |
emh203 | 0:3d9c67d97d6f | 417 | pState = pState + 1u; |
emh203 | 0:3d9c67d97d6f | 418 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 419 | |
emh203 | 0:3d9c67d97d6f | 420 | } |
emh203 | 0:3d9c67d97d6f | 421 | |
emh203 | 0:3d9c67d97d6f | 422 | /* Processing is complete. Now copy last S->numStages samples to start of the buffer |
emh203 | 0:3d9c67d97d6f | 423 | for the preperation of next frame process */ |
emh203 | 0:3d9c67d97d6f | 424 | |
emh203 | 0:3d9c67d97d6f | 425 | /* Points to the start of the state buffer */ |
emh203 | 0:3d9c67d97d6f | 426 | pStateCurnt = &S->pState[0]; |
emh203 | 0:3d9c67d97d6f | 427 | pState = &S->pState[blockSize]; |
emh203 | 0:3d9c67d97d6f | 428 | |
emh203 | 0:3d9c67d97d6f | 429 | tapCnt = numStages; |
emh203 | 0:3d9c67d97d6f | 430 | |
emh203 | 0:3d9c67d97d6f | 431 | /* Copy the data */ |
emh203 | 0:3d9c67d97d6f | 432 | while(tapCnt > 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 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 438 | } |
emh203 | 0:3d9c67d97d6f | 439 | |
emh203 | 0:3d9c67d97d6f | 440 | } |
emh203 | 0:3d9c67d97d6f | 441 | |
emh203 | 0:3d9c67d97d6f | 442 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
emh203 | 0:3d9c67d97d6f | 443 | |
emh203 | 0:3d9c67d97d6f | 444 | |
emh203 | 0:3d9c67d97d6f | 445 | /** |
emh203 | 0:3d9c67d97d6f | 446 | * @} end of IIR_Lattice group |
emh203 | 0:3d9c67d97d6f | 447 | */ |