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