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_fir_lattice_q31.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_fir_lattice_q31.c |
emh203 | 0:3d9c67d97d6f | 9 | * |
emh203 | 0:3d9c67d97d6f | 10 | * Description: Q31 FIR 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 | * @addtogroup FIR_Lattice |
emh203 | 0:3d9c67d97d6f | 49 | * @{ |
emh203 | 0:3d9c67d97d6f | 50 | */ |
emh203 | 0:3d9c67d97d6f | 51 | |
emh203 | 0:3d9c67d97d6f | 52 | |
emh203 | 0:3d9c67d97d6f | 53 | /** |
emh203 | 0:3d9c67d97d6f | 54 | * @brief Processing function for the Q31 FIR lattice filter. |
emh203 | 0:3d9c67d97d6f | 55 | * @param[in] *S points to an instance of the Q31 FIR lattice structure. |
emh203 | 0:3d9c67d97d6f | 56 | * @param[in] *pSrc points to the block of input data. |
emh203 | 0:3d9c67d97d6f | 57 | * @param[out] *pDst points to the block of output data |
emh203 | 0:3d9c67d97d6f | 58 | * @param[in] blockSize number of samples to process. |
emh203 | 0:3d9c67d97d6f | 59 | * @return none. |
emh203 | 0:3d9c67d97d6f | 60 | * |
emh203 | 0:3d9c67d97d6f | 61 | * @details |
emh203 | 0:3d9c67d97d6f | 62 | * <b>Scaling and Overflow Behavior:</b> |
emh203 | 0:3d9c67d97d6f | 63 | * In order to avoid overflows the input signal must be scaled down by 2*log2(numStages) bits. |
emh203 | 0:3d9c67d97d6f | 64 | */ |
emh203 | 0:3d9c67d97d6f | 65 | |
emh203 | 0:3d9c67d97d6f | 66 | #ifndef ARM_MATH_CM0_FAMILY |
emh203 | 0:3d9c67d97d6f | 67 | |
emh203 | 0:3d9c67d97d6f | 68 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emh203 | 0:3d9c67d97d6f | 69 | |
emh203 | 0:3d9c67d97d6f | 70 | void arm_fir_lattice_q31( |
emh203 | 0:3d9c67d97d6f | 71 | const arm_fir_lattice_instance_q31 * S, |
emh203 | 0:3d9c67d97d6f | 72 | q31_t * pSrc, |
emh203 | 0:3d9c67d97d6f | 73 | q31_t * pDst, |
emh203 | 0:3d9c67d97d6f | 74 | uint32_t blockSize) |
emh203 | 0:3d9c67d97d6f | 75 | { |
emh203 | 0:3d9c67d97d6f | 76 | q31_t *pState; /* State pointer */ |
emh203 | 0:3d9c67d97d6f | 77 | q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 78 | q31_t *px; /* temporary state pointer */ |
emh203 | 0:3d9c67d97d6f | 79 | q31_t *pk; /* temporary coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 80 | q31_t fcurr1, fnext1, gcurr1 = 0, gnext1; /* temporary variables for first sample in loop unrolling */ |
emh203 | 0:3d9c67d97d6f | 81 | q31_t fcurr2, fnext2, gnext2; /* temporary variables for second sample in loop unrolling */ |
emh203 | 0:3d9c67d97d6f | 82 | uint32_t numStages = S->numStages; /* Length of the filter */ |
emh203 | 0:3d9c67d97d6f | 83 | uint32_t blkCnt, stageCnt; /* temporary variables for counts */ |
emh203 | 0:3d9c67d97d6f | 84 | q31_t k; |
emh203 | 0:3d9c67d97d6f | 85 | |
emh203 | 0:3d9c67d97d6f | 86 | pState = &S->pState[0]; |
emh203 | 0:3d9c67d97d6f | 87 | |
emh203 | 0:3d9c67d97d6f | 88 | blkCnt = blockSize >> 1u; |
emh203 | 0:3d9c67d97d6f | 89 | |
emh203 | 0:3d9c67d97d6f | 90 | /* First part of the processing with loop unrolling. Compute 2 outputs at a time. |
emh203 | 0:3d9c67d97d6f | 91 | a second loop below computes the remaining 1 sample. */ |
emh203 | 0:3d9c67d97d6f | 92 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 93 | { |
emh203 | 0:3d9c67d97d6f | 94 | /* f0(n) = x(n) */ |
emh203 | 0:3d9c67d97d6f | 95 | fcurr1 = *pSrc++; |
emh203 | 0:3d9c67d97d6f | 96 | |
emh203 | 0:3d9c67d97d6f | 97 | /* f0(n) = x(n) */ |
emh203 | 0:3d9c67d97d6f | 98 | fcurr2 = *pSrc++; |
emh203 | 0:3d9c67d97d6f | 99 | |
emh203 | 0:3d9c67d97d6f | 100 | /* Initialize coeff pointer */ |
emh203 | 0:3d9c67d97d6f | 101 | pk = (pCoeffs); |
emh203 | 0:3d9c67d97d6f | 102 | |
emh203 | 0:3d9c67d97d6f | 103 | /* Initialize state pointer */ |
emh203 | 0:3d9c67d97d6f | 104 | px = pState; |
emh203 | 0:3d9c67d97d6f | 105 | |
emh203 | 0:3d9c67d97d6f | 106 | /* read g0(n - 1) from state buffer */ |
emh203 | 0:3d9c67d97d6f | 107 | gcurr1 = *px; |
emh203 | 0:3d9c67d97d6f | 108 | |
emh203 | 0:3d9c67d97d6f | 109 | /* Read the reflection coefficient */ |
emh203 | 0:3d9c67d97d6f | 110 | k = *pk++; |
emh203 | 0:3d9c67d97d6f | 111 | |
emh203 | 0:3d9c67d97d6f | 112 | /* for sample 1 processing */ |
emh203 | 0:3d9c67d97d6f | 113 | /* f1(n) = f0(n) + K1 * g0(n-1) */ |
emh203 | 0:3d9c67d97d6f | 114 | fnext1 = (q31_t) (((q63_t) gcurr1 * k) >> 32); |
emh203 | 0:3d9c67d97d6f | 115 | |
emh203 | 0:3d9c67d97d6f | 116 | /* g1(n) = f0(n) * K1 + g0(n-1) */ |
emh203 | 0:3d9c67d97d6f | 117 | gnext1 = (q31_t) (((q63_t) fcurr1 * (k)) >> 32); |
emh203 | 0:3d9c67d97d6f | 118 | fnext1 = fcurr1 + (fnext1 << 1u); |
emh203 | 0:3d9c67d97d6f | 119 | gnext1 = gcurr1 + (gnext1 << 1u); |
emh203 | 0:3d9c67d97d6f | 120 | |
emh203 | 0:3d9c67d97d6f | 121 | /* for sample 1 processing */ |
emh203 | 0:3d9c67d97d6f | 122 | /* f1(n) = f0(n) + K1 * g0(n-1) */ |
emh203 | 0:3d9c67d97d6f | 123 | fnext2 = (q31_t) (((q63_t) fcurr1 * k) >> 32); |
emh203 | 0:3d9c67d97d6f | 124 | |
emh203 | 0:3d9c67d97d6f | 125 | /* g1(n) = f0(n) * K1 + g0(n-1) */ |
emh203 | 0:3d9c67d97d6f | 126 | gnext2 = (q31_t) (((q63_t) fcurr2 * (k)) >> 32); |
emh203 | 0:3d9c67d97d6f | 127 | fnext2 = fcurr2 + (fnext2 << 1u); |
emh203 | 0:3d9c67d97d6f | 128 | gnext2 = fcurr1 + (gnext2 << 1u); |
emh203 | 0:3d9c67d97d6f | 129 | |
emh203 | 0:3d9c67d97d6f | 130 | /* save g1(n) in state buffer */ |
emh203 | 0:3d9c67d97d6f | 131 | *px++ = fcurr2; |
emh203 | 0:3d9c67d97d6f | 132 | |
emh203 | 0:3d9c67d97d6f | 133 | /* f1(n) is saved in fcurr1 |
emh203 | 0:3d9c67d97d6f | 134 | for next stage processing */ |
emh203 | 0:3d9c67d97d6f | 135 | fcurr1 = fnext1; |
emh203 | 0:3d9c67d97d6f | 136 | fcurr2 = fnext2; |
emh203 | 0:3d9c67d97d6f | 137 | |
emh203 | 0:3d9c67d97d6f | 138 | stageCnt = (numStages - 1u); |
emh203 | 0:3d9c67d97d6f | 139 | |
emh203 | 0:3d9c67d97d6f | 140 | /* stage loop */ |
emh203 | 0:3d9c67d97d6f | 141 | while(stageCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 142 | { |
emh203 | 0:3d9c67d97d6f | 143 | |
emh203 | 0:3d9c67d97d6f | 144 | /* Read the reflection coefficient */ |
emh203 | 0:3d9c67d97d6f | 145 | k = *pk++; |
emh203 | 0:3d9c67d97d6f | 146 | |
emh203 | 0:3d9c67d97d6f | 147 | /* read g2(n) from state buffer */ |
emh203 | 0:3d9c67d97d6f | 148 | gcurr1 = *px; |
emh203 | 0:3d9c67d97d6f | 149 | |
emh203 | 0:3d9c67d97d6f | 150 | /* save g1(n) in state buffer */ |
emh203 | 0:3d9c67d97d6f | 151 | *px++ = gnext2; |
emh203 | 0:3d9c67d97d6f | 152 | |
emh203 | 0:3d9c67d97d6f | 153 | /* Sample processing for K2, K3.... */ |
emh203 | 0:3d9c67d97d6f | 154 | /* f2(n) = f1(n) + K2 * g1(n-1) */ |
emh203 | 0:3d9c67d97d6f | 155 | fnext1 = (q31_t) (((q63_t) gcurr1 * k) >> 32); |
emh203 | 0:3d9c67d97d6f | 156 | fnext2 = (q31_t) (((q63_t) gnext1 * k) >> 32); |
emh203 | 0:3d9c67d97d6f | 157 | |
emh203 | 0:3d9c67d97d6f | 158 | fnext1 = fcurr1 + (fnext1 << 1u); |
emh203 | 0:3d9c67d97d6f | 159 | fnext2 = fcurr2 + (fnext2 << 1u); |
emh203 | 0:3d9c67d97d6f | 160 | |
emh203 | 0:3d9c67d97d6f | 161 | /* g2(n) = f1(n) * K2 + g1(n-1) */ |
emh203 | 0:3d9c67d97d6f | 162 | gnext2 = (q31_t) (((q63_t) fcurr2 * (k)) >> 32); |
emh203 | 0:3d9c67d97d6f | 163 | gnext2 = gnext1 + (gnext2 << 1u); |
emh203 | 0:3d9c67d97d6f | 164 | |
emh203 | 0:3d9c67d97d6f | 165 | /* g2(n) = f1(n) * K2 + g1(n-1) */ |
emh203 | 0:3d9c67d97d6f | 166 | gnext1 = (q31_t) (((q63_t) fcurr1 * (k)) >> 32); |
emh203 | 0:3d9c67d97d6f | 167 | gnext1 = gcurr1 + (gnext1 << 1u); |
emh203 | 0:3d9c67d97d6f | 168 | |
emh203 | 0:3d9c67d97d6f | 169 | /* f1(n) is saved in fcurr1 |
emh203 | 0:3d9c67d97d6f | 170 | for next stage processing */ |
emh203 | 0:3d9c67d97d6f | 171 | fcurr1 = fnext1; |
emh203 | 0:3d9c67d97d6f | 172 | fcurr2 = fnext2; |
emh203 | 0:3d9c67d97d6f | 173 | |
emh203 | 0:3d9c67d97d6f | 174 | stageCnt--; |
emh203 | 0:3d9c67d97d6f | 175 | |
emh203 | 0:3d9c67d97d6f | 176 | } |
emh203 | 0:3d9c67d97d6f | 177 | |
emh203 | 0:3d9c67d97d6f | 178 | /* y(n) = fN(n) */ |
emh203 | 0:3d9c67d97d6f | 179 | *pDst++ = fcurr1; |
emh203 | 0:3d9c67d97d6f | 180 | *pDst++ = fcurr2; |
emh203 | 0:3d9c67d97d6f | 181 | |
emh203 | 0:3d9c67d97d6f | 182 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 183 | |
emh203 | 0:3d9c67d97d6f | 184 | } |
emh203 | 0:3d9c67d97d6f | 185 | |
emh203 | 0:3d9c67d97d6f | 186 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. |
emh203 | 0:3d9c67d97d6f | 187 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 188 | blkCnt = blockSize % 0x2u; |
emh203 | 0:3d9c67d97d6f | 189 | |
emh203 | 0:3d9c67d97d6f | 190 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 191 | { |
emh203 | 0:3d9c67d97d6f | 192 | /* f0(n) = x(n) */ |
emh203 | 0:3d9c67d97d6f | 193 | fcurr1 = *pSrc++; |
emh203 | 0:3d9c67d97d6f | 194 | |
emh203 | 0:3d9c67d97d6f | 195 | /* Initialize coeff pointer */ |
emh203 | 0:3d9c67d97d6f | 196 | pk = (pCoeffs); |
emh203 | 0:3d9c67d97d6f | 197 | |
emh203 | 0:3d9c67d97d6f | 198 | /* Initialize state pointer */ |
emh203 | 0:3d9c67d97d6f | 199 | px = pState; |
emh203 | 0:3d9c67d97d6f | 200 | |
emh203 | 0:3d9c67d97d6f | 201 | /* read g0(n - 1) from state buffer */ |
emh203 | 0:3d9c67d97d6f | 202 | gcurr1 = *px; |
emh203 | 0:3d9c67d97d6f | 203 | |
emh203 | 0:3d9c67d97d6f | 204 | /* Read the reflection coefficient */ |
emh203 | 0:3d9c67d97d6f | 205 | k = *pk++; |
emh203 | 0:3d9c67d97d6f | 206 | |
emh203 | 0:3d9c67d97d6f | 207 | /* for sample 1 processing */ |
emh203 | 0:3d9c67d97d6f | 208 | /* f1(n) = f0(n) + K1 * g0(n-1) */ |
emh203 | 0:3d9c67d97d6f | 209 | fnext1 = (q31_t) (((q63_t) gcurr1 * k) >> 32); |
emh203 | 0:3d9c67d97d6f | 210 | fnext1 = fcurr1 + (fnext1 << 1u); |
emh203 | 0:3d9c67d97d6f | 211 | |
emh203 | 0:3d9c67d97d6f | 212 | /* g1(n) = f0(n) * K1 + g0(n-1) */ |
emh203 | 0:3d9c67d97d6f | 213 | gnext1 = (q31_t) (((q63_t) fcurr1 * (k)) >> 32); |
emh203 | 0:3d9c67d97d6f | 214 | gnext1 = gcurr1 + (gnext1 << 1u); |
emh203 | 0:3d9c67d97d6f | 215 | |
emh203 | 0:3d9c67d97d6f | 216 | /* save g1(n) in state buffer */ |
emh203 | 0:3d9c67d97d6f | 217 | *px++ = fcurr1; |
emh203 | 0:3d9c67d97d6f | 218 | |
emh203 | 0:3d9c67d97d6f | 219 | /* f1(n) is saved in fcurr1 |
emh203 | 0:3d9c67d97d6f | 220 | for next stage processing */ |
emh203 | 0:3d9c67d97d6f | 221 | fcurr1 = fnext1; |
emh203 | 0:3d9c67d97d6f | 222 | |
emh203 | 0:3d9c67d97d6f | 223 | stageCnt = (numStages - 1u); |
emh203 | 0:3d9c67d97d6f | 224 | |
emh203 | 0:3d9c67d97d6f | 225 | /* stage loop */ |
emh203 | 0:3d9c67d97d6f | 226 | while(stageCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 227 | { |
emh203 | 0:3d9c67d97d6f | 228 | /* Read the reflection coefficient */ |
emh203 | 0:3d9c67d97d6f | 229 | k = *pk++; |
emh203 | 0:3d9c67d97d6f | 230 | |
emh203 | 0:3d9c67d97d6f | 231 | /* read g2(n) from state buffer */ |
emh203 | 0:3d9c67d97d6f | 232 | gcurr1 = *px; |
emh203 | 0:3d9c67d97d6f | 233 | |
emh203 | 0:3d9c67d97d6f | 234 | /* save g1(n) in state buffer */ |
emh203 | 0:3d9c67d97d6f | 235 | *px++ = gnext1; |
emh203 | 0:3d9c67d97d6f | 236 | |
emh203 | 0:3d9c67d97d6f | 237 | /* Sample processing for K2, K3.... */ |
emh203 | 0:3d9c67d97d6f | 238 | /* f2(n) = f1(n) + K2 * g1(n-1) */ |
emh203 | 0:3d9c67d97d6f | 239 | fnext1 = (q31_t) (((q63_t) gcurr1 * k) >> 32); |
emh203 | 0:3d9c67d97d6f | 240 | fnext1 = fcurr1 + (fnext1 << 1u); |
emh203 | 0:3d9c67d97d6f | 241 | |
emh203 | 0:3d9c67d97d6f | 242 | /* g2(n) = f1(n) * K2 + g1(n-1) */ |
emh203 | 0:3d9c67d97d6f | 243 | gnext1 = (q31_t) (((q63_t) fcurr1 * (k)) >> 32); |
emh203 | 0:3d9c67d97d6f | 244 | gnext1 = gcurr1 + (gnext1 << 1u); |
emh203 | 0:3d9c67d97d6f | 245 | |
emh203 | 0:3d9c67d97d6f | 246 | /* f1(n) is saved in fcurr1 |
emh203 | 0:3d9c67d97d6f | 247 | for next stage processing */ |
emh203 | 0:3d9c67d97d6f | 248 | fcurr1 = fnext1; |
emh203 | 0:3d9c67d97d6f | 249 | |
emh203 | 0:3d9c67d97d6f | 250 | stageCnt--; |
emh203 | 0:3d9c67d97d6f | 251 | |
emh203 | 0:3d9c67d97d6f | 252 | } |
emh203 | 0:3d9c67d97d6f | 253 | |
emh203 | 0:3d9c67d97d6f | 254 | |
emh203 | 0:3d9c67d97d6f | 255 | /* y(n) = fN(n) */ |
emh203 | 0:3d9c67d97d6f | 256 | *pDst++ = fcurr1; |
emh203 | 0:3d9c67d97d6f | 257 | |
emh203 | 0:3d9c67d97d6f | 258 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 259 | |
emh203 | 0:3d9c67d97d6f | 260 | } |
emh203 | 0:3d9c67d97d6f | 261 | |
emh203 | 0:3d9c67d97d6f | 262 | |
emh203 | 0:3d9c67d97d6f | 263 | } |
emh203 | 0:3d9c67d97d6f | 264 | |
emh203 | 0:3d9c67d97d6f | 265 | |
emh203 | 0:3d9c67d97d6f | 266 | #else |
emh203 | 0:3d9c67d97d6f | 267 | |
emh203 | 0:3d9c67d97d6f | 268 | /* Run the below code for Cortex-M0 */ |
emh203 | 0:3d9c67d97d6f | 269 | |
emh203 | 0:3d9c67d97d6f | 270 | void arm_fir_lattice_q31( |
emh203 | 0:3d9c67d97d6f | 271 | const arm_fir_lattice_instance_q31 * S, |
emh203 | 0:3d9c67d97d6f | 272 | q31_t * pSrc, |
emh203 | 0:3d9c67d97d6f | 273 | q31_t * pDst, |
emh203 | 0:3d9c67d97d6f | 274 | uint32_t blockSize) |
emh203 | 0:3d9c67d97d6f | 275 | { |
emh203 | 0:3d9c67d97d6f | 276 | q31_t *pState; /* State pointer */ |
emh203 | 0:3d9c67d97d6f | 277 | q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 278 | q31_t *px; /* temporary state pointer */ |
emh203 | 0:3d9c67d97d6f | 279 | q31_t *pk; /* temporary coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 280 | q31_t fcurr, fnext, gcurr, gnext; /* temporary variables */ |
emh203 | 0:3d9c67d97d6f | 281 | uint32_t numStages = S->numStages; /* Length of the filter */ |
emh203 | 0:3d9c67d97d6f | 282 | uint32_t blkCnt, stageCnt; /* temporary variables for counts */ |
emh203 | 0:3d9c67d97d6f | 283 | |
emh203 | 0:3d9c67d97d6f | 284 | pState = &S->pState[0]; |
emh203 | 0:3d9c67d97d6f | 285 | |
emh203 | 0:3d9c67d97d6f | 286 | blkCnt = blockSize; |
emh203 | 0:3d9c67d97d6f | 287 | |
emh203 | 0:3d9c67d97d6f | 288 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 289 | { |
emh203 | 0:3d9c67d97d6f | 290 | /* f0(n) = x(n) */ |
emh203 | 0:3d9c67d97d6f | 291 | fcurr = *pSrc++; |
emh203 | 0:3d9c67d97d6f | 292 | |
emh203 | 0:3d9c67d97d6f | 293 | /* Initialize coeff pointer */ |
emh203 | 0:3d9c67d97d6f | 294 | pk = (pCoeffs); |
emh203 | 0:3d9c67d97d6f | 295 | |
emh203 | 0:3d9c67d97d6f | 296 | /* Initialize state pointer */ |
emh203 | 0:3d9c67d97d6f | 297 | px = pState; |
emh203 | 0:3d9c67d97d6f | 298 | |
emh203 | 0:3d9c67d97d6f | 299 | /* read g0(n-1) from state buffer */ |
emh203 | 0:3d9c67d97d6f | 300 | gcurr = *px; |
emh203 | 0:3d9c67d97d6f | 301 | |
emh203 | 0:3d9c67d97d6f | 302 | /* for sample 1 processing */ |
emh203 | 0:3d9c67d97d6f | 303 | /* f1(n) = f0(n) + K1 * g0(n-1) */ |
emh203 | 0:3d9c67d97d6f | 304 | fnext = (q31_t) (((q63_t) gcurr * (*pk)) >> 31) + fcurr; |
emh203 | 0:3d9c67d97d6f | 305 | /* g1(n) = f0(n) * K1 + g0(n-1) */ |
emh203 | 0:3d9c67d97d6f | 306 | gnext = (q31_t) (((q63_t) fcurr * (*pk++)) >> 31) + gcurr; |
emh203 | 0:3d9c67d97d6f | 307 | /* save g1(n) in state buffer */ |
emh203 | 0:3d9c67d97d6f | 308 | *px++ = fcurr; |
emh203 | 0:3d9c67d97d6f | 309 | |
emh203 | 0:3d9c67d97d6f | 310 | /* f1(n) is saved in fcurr1 |
emh203 | 0:3d9c67d97d6f | 311 | for next stage processing */ |
emh203 | 0:3d9c67d97d6f | 312 | fcurr = fnext; |
emh203 | 0:3d9c67d97d6f | 313 | |
emh203 | 0:3d9c67d97d6f | 314 | stageCnt = (numStages - 1u); |
emh203 | 0:3d9c67d97d6f | 315 | |
emh203 | 0:3d9c67d97d6f | 316 | /* stage loop */ |
emh203 | 0:3d9c67d97d6f | 317 | while(stageCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 318 | { |
emh203 | 0:3d9c67d97d6f | 319 | /* read g2(n) from state buffer */ |
emh203 | 0:3d9c67d97d6f | 320 | gcurr = *px; |
emh203 | 0:3d9c67d97d6f | 321 | |
emh203 | 0:3d9c67d97d6f | 322 | /* save g1(n) in state buffer */ |
emh203 | 0:3d9c67d97d6f | 323 | *px++ = gnext; |
emh203 | 0:3d9c67d97d6f | 324 | |
emh203 | 0:3d9c67d97d6f | 325 | /* Sample processing for K2, K3.... */ |
emh203 | 0:3d9c67d97d6f | 326 | /* f2(n) = f1(n) + K2 * g1(n-1) */ |
emh203 | 0:3d9c67d97d6f | 327 | fnext = (q31_t) (((q63_t) gcurr * (*pk)) >> 31) + fcurr; |
emh203 | 0:3d9c67d97d6f | 328 | /* g2(n) = f1(n) * K2 + g1(n-1) */ |
emh203 | 0:3d9c67d97d6f | 329 | gnext = (q31_t) (((q63_t) fcurr * (*pk++)) >> 31) + gcurr; |
emh203 | 0:3d9c67d97d6f | 330 | |
emh203 | 0:3d9c67d97d6f | 331 | /* f1(n) is saved in fcurr1 |
emh203 | 0:3d9c67d97d6f | 332 | for next stage processing */ |
emh203 | 0:3d9c67d97d6f | 333 | fcurr = fnext; |
emh203 | 0:3d9c67d97d6f | 334 | |
emh203 | 0:3d9c67d97d6f | 335 | stageCnt--; |
emh203 | 0:3d9c67d97d6f | 336 | |
emh203 | 0:3d9c67d97d6f | 337 | } |
emh203 | 0:3d9c67d97d6f | 338 | |
emh203 | 0:3d9c67d97d6f | 339 | /* y(n) = fN(n) */ |
emh203 | 0:3d9c67d97d6f | 340 | *pDst++ = fcurr; |
emh203 | 0:3d9c67d97d6f | 341 | |
emh203 | 0:3d9c67d97d6f | 342 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 343 | |
emh203 | 0:3d9c67d97d6f | 344 | } |
emh203 | 0:3d9c67d97d6f | 345 | |
emh203 | 0:3d9c67d97d6f | 346 | } |
emh203 | 0:3d9c67d97d6f | 347 | |
emh203 | 0:3d9c67d97d6f | 348 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
emh203 | 0:3d9c67d97d6f | 349 | |
emh203 | 0:3d9c67d97d6f | 350 | |
emh203 | 0:3d9c67d97d6f | 351 | /** |
emh203 | 0:3d9c67d97d6f | 352 | * @} end of FIR_Lattice group |
emh203 | 0:3d9c67d97d6f | 353 | */ |