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_decimate_fast_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_decimate_fast_q31.c |
emh203 | 0:3d9c67d97d6f | 9 | * |
emh203 | 0:3d9c67d97d6f | 10 | * Description: Fast Q31 FIR Decimator. |
emh203 | 0:3d9c67d97d6f | 11 | * |
emh203 | 0:3d9c67d97d6f | 12 | * Target Processor: Cortex-M4/Cortex-M3 |
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_decimate |
emh203 | 0:3d9c67d97d6f | 49 | * @{ |
emh203 | 0:3d9c67d97d6f | 50 | */ |
emh203 | 0:3d9c67d97d6f | 51 | |
emh203 | 0:3d9c67d97d6f | 52 | /** |
emh203 | 0:3d9c67d97d6f | 53 | * @brief Processing function for the Q31 FIR decimator (fast variant) for Cortex-M3 and Cortex-M4. |
emh203 | 0:3d9c67d97d6f | 54 | * @param[in] *S points to an instance of the Q31 FIR decimator structure. |
emh203 | 0:3d9c67d97d6f | 55 | * @param[in] *pSrc points to the block of input data. |
emh203 | 0:3d9c67d97d6f | 56 | * @param[out] *pDst points to the block of output data |
emh203 | 0:3d9c67d97d6f | 57 | * @param[in] blockSize number of input samples to process per call. |
emh203 | 0:3d9c67d97d6f | 58 | * @return none |
emh203 | 0:3d9c67d97d6f | 59 | * |
emh203 | 0:3d9c67d97d6f | 60 | * <b>Scaling and Overflow Behavior:</b> |
emh203 | 0:3d9c67d97d6f | 61 | * |
emh203 | 0:3d9c67d97d6f | 62 | * \par |
emh203 | 0:3d9c67d97d6f | 63 | * This function is optimized for speed at the expense of fixed-point precision and overflow protection. |
emh203 | 0:3d9c67d97d6f | 64 | * The result of each 1.31 x 1.31 multiplication is truncated to 2.30 format. |
emh203 | 0:3d9c67d97d6f | 65 | * These intermediate results are added to a 2.30 accumulator. |
emh203 | 0:3d9c67d97d6f | 66 | * Finally, the accumulator is saturated and converted to a 1.31 result. |
emh203 | 0:3d9c67d97d6f | 67 | * The fast version has the same overflow behavior as the standard version and provides less precision since it discards the low 32 bits of each multiplication result. |
emh203 | 0:3d9c67d97d6f | 68 | * In order to avoid overflows completely the input signal must be scaled down by log2(numTaps) bits (where log2 is read as log to the base 2). |
emh203 | 0:3d9c67d97d6f | 69 | * |
emh203 | 0:3d9c67d97d6f | 70 | * \par |
emh203 | 0:3d9c67d97d6f | 71 | * Refer to the function <code>arm_fir_decimate_q31()</code> for a slower implementation of this function which uses a 64-bit accumulator to provide higher precision. |
emh203 | 0:3d9c67d97d6f | 72 | * Both the slow and the fast versions use the same instance structure. |
emh203 | 0:3d9c67d97d6f | 73 | * Use the function <code>arm_fir_decimate_init_q31()</code> to initialize the filter structure. |
emh203 | 0:3d9c67d97d6f | 74 | */ |
emh203 | 0:3d9c67d97d6f | 75 | |
emh203 | 0:3d9c67d97d6f | 76 | void arm_fir_decimate_fast_q31( |
emh203 | 0:3d9c67d97d6f | 77 | arm_fir_decimate_instance_q31 * S, |
emh203 | 0:3d9c67d97d6f | 78 | q31_t * pSrc, |
emh203 | 0:3d9c67d97d6f | 79 | q31_t * pDst, |
emh203 | 0:3d9c67d97d6f | 80 | uint32_t blockSize) |
emh203 | 0:3d9c67d97d6f | 81 | { |
emh203 | 0:3d9c67d97d6f | 82 | q31_t *pState = S->pState; /* State pointer */ |
emh203 | 0:3d9c67d97d6f | 83 | q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 84 | q31_t *pStateCurnt; /* Points to the current sample of the state */ |
emh203 | 0:3d9c67d97d6f | 85 | q31_t x0, c0; /* Temporary variables to hold state and coefficient values */ |
emh203 | 0:3d9c67d97d6f | 86 | q31_t *px; /* Temporary pointers for state buffer */ |
emh203 | 0:3d9c67d97d6f | 87 | q31_t *pb; /* Temporary pointers for coefficient buffer */ |
emh203 | 0:3d9c67d97d6f | 88 | q31_t sum0; /* Accumulator */ |
emh203 | 0:3d9c67d97d6f | 89 | uint32_t numTaps = S->numTaps; /* Number of taps */ |
emh203 | 0:3d9c67d97d6f | 90 | uint32_t i, tapCnt, blkCnt, outBlockSize = blockSize / S->M; /* Loop counters */ |
emh203 | 0:3d9c67d97d6f | 91 | uint32_t blkCntN2; |
emh203 | 0:3d9c67d97d6f | 92 | q31_t x1; |
emh203 | 0:3d9c67d97d6f | 93 | q31_t acc0, acc1; |
emh203 | 0:3d9c67d97d6f | 94 | q31_t *px0, *px1; |
emh203 | 0:3d9c67d97d6f | 95 | |
emh203 | 0:3d9c67d97d6f | 96 | /* S->pState buffer contains previous frame (numTaps - 1) samples */ |
emh203 | 0:3d9c67d97d6f | 97 | /* pStateCurnt points to the location where the new input data should be written */ |
emh203 | 0:3d9c67d97d6f | 98 | pStateCurnt = S->pState + (numTaps - 1u); |
emh203 | 0:3d9c67d97d6f | 99 | |
emh203 | 0:3d9c67d97d6f | 100 | /* Total number of output samples to be computed */ |
emh203 | 0:3d9c67d97d6f | 101 | |
emh203 | 0:3d9c67d97d6f | 102 | blkCnt = outBlockSize / 2; |
emh203 | 0:3d9c67d97d6f | 103 | blkCntN2 = outBlockSize - (2 * blkCnt); |
emh203 | 0:3d9c67d97d6f | 104 | |
emh203 | 0:3d9c67d97d6f | 105 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 106 | { |
emh203 | 0:3d9c67d97d6f | 107 | /* Copy decimation factor number of new input samples into the state buffer */ |
emh203 | 0:3d9c67d97d6f | 108 | i = 2 * S->M; |
emh203 | 0:3d9c67d97d6f | 109 | |
emh203 | 0:3d9c67d97d6f | 110 | do |
emh203 | 0:3d9c67d97d6f | 111 | { |
emh203 | 0:3d9c67d97d6f | 112 | *pStateCurnt++ = *pSrc++; |
emh203 | 0:3d9c67d97d6f | 113 | |
emh203 | 0:3d9c67d97d6f | 114 | } while(--i); |
emh203 | 0:3d9c67d97d6f | 115 | |
emh203 | 0:3d9c67d97d6f | 116 | /* Set accumulator to zero */ |
emh203 | 0:3d9c67d97d6f | 117 | acc0 = 0; |
emh203 | 0:3d9c67d97d6f | 118 | acc1 = 0; |
emh203 | 0:3d9c67d97d6f | 119 | |
emh203 | 0:3d9c67d97d6f | 120 | /* Initialize state pointer */ |
emh203 | 0:3d9c67d97d6f | 121 | px0 = pState; |
emh203 | 0:3d9c67d97d6f | 122 | px1 = pState + S->M; |
emh203 | 0:3d9c67d97d6f | 123 | |
emh203 | 0:3d9c67d97d6f | 124 | /* Initialize coeff pointer */ |
emh203 | 0:3d9c67d97d6f | 125 | pb = pCoeffs; |
emh203 | 0:3d9c67d97d6f | 126 | |
emh203 | 0:3d9c67d97d6f | 127 | /* Loop unrolling. Process 4 taps at a time. */ |
emh203 | 0:3d9c67d97d6f | 128 | tapCnt = numTaps >> 2; |
emh203 | 0:3d9c67d97d6f | 129 | |
emh203 | 0:3d9c67d97d6f | 130 | /* Loop over the number of taps. Unroll by a factor of 4. |
emh203 | 0:3d9c67d97d6f | 131 | ** Repeat until we've computed numTaps-4 coefficients. */ |
emh203 | 0:3d9c67d97d6f | 132 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 133 | { |
emh203 | 0:3d9c67d97d6f | 134 | /* Read the b[numTaps-1] coefficient */ |
emh203 | 0:3d9c67d97d6f | 135 | c0 = *(pb); |
emh203 | 0:3d9c67d97d6f | 136 | |
emh203 | 0:3d9c67d97d6f | 137 | /* Read x[n-numTaps-1] for sample 0 sample 1 */ |
emh203 | 0:3d9c67d97d6f | 138 | x0 = *(px0); |
emh203 | 0:3d9c67d97d6f | 139 | x1 = *(px1); |
emh203 | 0:3d9c67d97d6f | 140 | |
emh203 | 0:3d9c67d97d6f | 141 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 142 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 143 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 144 | |
emh203 | 0:3d9c67d97d6f | 145 | /* Read the b[numTaps-2] coefficient */ |
emh203 | 0:3d9c67d97d6f | 146 | c0 = *(pb + 1u); |
emh203 | 0:3d9c67d97d6f | 147 | |
emh203 | 0:3d9c67d97d6f | 148 | /* Read x[n-numTaps-2] for sample 0 sample 1 */ |
emh203 | 0:3d9c67d97d6f | 149 | x0 = *(px0 + 1u); |
emh203 | 0:3d9c67d97d6f | 150 | x1 = *(px1 + 1u); |
emh203 | 0:3d9c67d97d6f | 151 | |
emh203 | 0:3d9c67d97d6f | 152 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 153 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 154 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 155 | |
emh203 | 0:3d9c67d97d6f | 156 | /* Read the b[numTaps-3] coefficient */ |
emh203 | 0:3d9c67d97d6f | 157 | c0 = *(pb + 2u); |
emh203 | 0:3d9c67d97d6f | 158 | |
emh203 | 0:3d9c67d97d6f | 159 | /* Read x[n-numTaps-3] for sample 0 sample 1 */ |
emh203 | 0:3d9c67d97d6f | 160 | x0 = *(px0 + 2u); |
emh203 | 0:3d9c67d97d6f | 161 | x1 = *(px1 + 2u); |
emh203 | 0:3d9c67d97d6f | 162 | pb += 4u; |
emh203 | 0:3d9c67d97d6f | 163 | |
emh203 | 0:3d9c67d97d6f | 164 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 165 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 166 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 167 | |
emh203 | 0:3d9c67d97d6f | 168 | /* Read the b[numTaps-4] coefficient */ |
emh203 | 0:3d9c67d97d6f | 169 | c0 = *(pb - 1u); |
emh203 | 0:3d9c67d97d6f | 170 | |
emh203 | 0:3d9c67d97d6f | 171 | /* Read x[n-numTaps-4] for sample 0 sample 1 */ |
emh203 | 0:3d9c67d97d6f | 172 | x0 = *(px0 + 3u); |
emh203 | 0:3d9c67d97d6f | 173 | x1 = *(px1 + 3u); |
emh203 | 0:3d9c67d97d6f | 174 | |
emh203 | 0:3d9c67d97d6f | 175 | |
emh203 | 0:3d9c67d97d6f | 176 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 177 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 178 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 179 | |
emh203 | 0:3d9c67d97d6f | 180 | /* update state pointers */ |
emh203 | 0:3d9c67d97d6f | 181 | px0 += 4u; |
emh203 | 0:3d9c67d97d6f | 182 | px1 += 4u; |
emh203 | 0:3d9c67d97d6f | 183 | |
emh203 | 0:3d9c67d97d6f | 184 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 185 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 186 | } |
emh203 | 0:3d9c67d97d6f | 187 | |
emh203 | 0:3d9c67d97d6f | 188 | /* If the filter length is not a multiple of 4, compute the remaining filter taps */ |
emh203 | 0:3d9c67d97d6f | 189 | tapCnt = numTaps % 0x4u; |
emh203 | 0:3d9c67d97d6f | 190 | |
emh203 | 0:3d9c67d97d6f | 191 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 192 | { |
emh203 | 0:3d9c67d97d6f | 193 | /* Read coefficients */ |
emh203 | 0:3d9c67d97d6f | 194 | c0 = *(pb++); |
emh203 | 0:3d9c67d97d6f | 195 | |
emh203 | 0:3d9c67d97d6f | 196 | /* Fetch 1 state variable */ |
emh203 | 0:3d9c67d97d6f | 197 | x0 = *(px0++); |
emh203 | 0:3d9c67d97d6f | 198 | x1 = *(px1++); |
emh203 | 0:3d9c67d97d6f | 199 | |
emh203 | 0:3d9c67d97d6f | 200 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 201 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 202 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 203 | |
emh203 | 0:3d9c67d97d6f | 204 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 205 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 206 | } |
emh203 | 0:3d9c67d97d6f | 207 | |
emh203 | 0:3d9c67d97d6f | 208 | /* Advance the state pointer by the decimation factor |
emh203 | 0:3d9c67d97d6f | 209 | * to process the next group of decimation factor number samples */ |
emh203 | 0:3d9c67d97d6f | 210 | pState = pState + S->M * 2; |
emh203 | 0:3d9c67d97d6f | 211 | |
emh203 | 0:3d9c67d97d6f | 212 | /* The result is in the accumulator, store in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 213 | *pDst++ = (q31_t) (acc0 << 1); |
emh203 | 0:3d9c67d97d6f | 214 | *pDst++ = (q31_t) (acc1 << 1); |
emh203 | 0:3d9c67d97d6f | 215 | |
emh203 | 0:3d9c67d97d6f | 216 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 217 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 218 | } |
emh203 | 0:3d9c67d97d6f | 219 | |
emh203 | 0:3d9c67d97d6f | 220 | while(blkCntN2 > 0u) |
emh203 | 0:3d9c67d97d6f | 221 | { |
emh203 | 0:3d9c67d97d6f | 222 | /* Copy decimation factor number of new input samples into the state buffer */ |
emh203 | 0:3d9c67d97d6f | 223 | i = S->M; |
emh203 | 0:3d9c67d97d6f | 224 | |
emh203 | 0:3d9c67d97d6f | 225 | do |
emh203 | 0:3d9c67d97d6f | 226 | { |
emh203 | 0:3d9c67d97d6f | 227 | *pStateCurnt++ = *pSrc++; |
emh203 | 0:3d9c67d97d6f | 228 | |
emh203 | 0:3d9c67d97d6f | 229 | } while(--i); |
emh203 | 0:3d9c67d97d6f | 230 | |
emh203 | 0:3d9c67d97d6f | 231 | /* Set accumulator to zero */ |
emh203 | 0:3d9c67d97d6f | 232 | sum0 = 0; |
emh203 | 0:3d9c67d97d6f | 233 | |
emh203 | 0:3d9c67d97d6f | 234 | /* Initialize state pointer */ |
emh203 | 0:3d9c67d97d6f | 235 | px = pState; |
emh203 | 0:3d9c67d97d6f | 236 | |
emh203 | 0:3d9c67d97d6f | 237 | /* Initialize coeff pointer */ |
emh203 | 0:3d9c67d97d6f | 238 | pb = pCoeffs; |
emh203 | 0:3d9c67d97d6f | 239 | |
emh203 | 0:3d9c67d97d6f | 240 | /* Loop unrolling. Process 4 taps at a time. */ |
emh203 | 0:3d9c67d97d6f | 241 | tapCnt = numTaps >> 2; |
emh203 | 0:3d9c67d97d6f | 242 | |
emh203 | 0:3d9c67d97d6f | 243 | /* Loop over the number of taps. Unroll by a factor of 4. |
emh203 | 0:3d9c67d97d6f | 244 | ** Repeat until we've computed numTaps-4 coefficients. */ |
emh203 | 0:3d9c67d97d6f | 245 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 246 | { |
emh203 | 0:3d9c67d97d6f | 247 | /* Read the b[numTaps-1] coefficient */ |
emh203 | 0:3d9c67d97d6f | 248 | c0 = *(pb++); |
emh203 | 0:3d9c67d97d6f | 249 | |
emh203 | 0:3d9c67d97d6f | 250 | /* Read x[n-numTaps-1] sample */ |
emh203 | 0:3d9c67d97d6f | 251 | x0 = *(px++); |
emh203 | 0:3d9c67d97d6f | 252 | |
emh203 | 0:3d9c67d97d6f | 253 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 254 | sum0 = (q31_t) ((((q63_t) sum0 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 255 | |
emh203 | 0:3d9c67d97d6f | 256 | /* Read the b[numTaps-2] coefficient */ |
emh203 | 0:3d9c67d97d6f | 257 | c0 = *(pb++); |
emh203 | 0:3d9c67d97d6f | 258 | |
emh203 | 0:3d9c67d97d6f | 259 | /* Read x[n-numTaps-2] sample */ |
emh203 | 0:3d9c67d97d6f | 260 | x0 = *(px++); |
emh203 | 0:3d9c67d97d6f | 261 | |
emh203 | 0:3d9c67d97d6f | 262 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 263 | sum0 = (q31_t) ((((q63_t) sum0 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 264 | |
emh203 | 0:3d9c67d97d6f | 265 | /* Read the b[numTaps-3] coefficient */ |
emh203 | 0:3d9c67d97d6f | 266 | c0 = *(pb++); |
emh203 | 0:3d9c67d97d6f | 267 | |
emh203 | 0:3d9c67d97d6f | 268 | /* Read x[n-numTaps-3] sample */ |
emh203 | 0:3d9c67d97d6f | 269 | x0 = *(px++); |
emh203 | 0:3d9c67d97d6f | 270 | |
emh203 | 0:3d9c67d97d6f | 271 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 272 | sum0 = (q31_t) ((((q63_t) sum0 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 273 | |
emh203 | 0:3d9c67d97d6f | 274 | /* Read the b[numTaps-4] coefficient */ |
emh203 | 0:3d9c67d97d6f | 275 | c0 = *(pb++); |
emh203 | 0:3d9c67d97d6f | 276 | |
emh203 | 0:3d9c67d97d6f | 277 | /* Read x[n-numTaps-4] sample */ |
emh203 | 0:3d9c67d97d6f | 278 | x0 = *(px++); |
emh203 | 0:3d9c67d97d6f | 279 | |
emh203 | 0:3d9c67d97d6f | 280 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 281 | sum0 = (q31_t) ((((q63_t) sum0 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 282 | |
emh203 | 0:3d9c67d97d6f | 283 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 284 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 285 | } |
emh203 | 0:3d9c67d97d6f | 286 | |
emh203 | 0:3d9c67d97d6f | 287 | /* If the filter length is not a multiple of 4, compute the remaining filter taps */ |
emh203 | 0:3d9c67d97d6f | 288 | tapCnt = numTaps % 0x4u; |
emh203 | 0:3d9c67d97d6f | 289 | |
emh203 | 0:3d9c67d97d6f | 290 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 291 | { |
emh203 | 0:3d9c67d97d6f | 292 | /* Read coefficients */ |
emh203 | 0:3d9c67d97d6f | 293 | c0 = *(pb++); |
emh203 | 0:3d9c67d97d6f | 294 | |
emh203 | 0:3d9c67d97d6f | 295 | /* Fetch 1 state variable */ |
emh203 | 0:3d9c67d97d6f | 296 | x0 = *(px++); |
emh203 | 0:3d9c67d97d6f | 297 | |
emh203 | 0:3d9c67d97d6f | 298 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 299 | sum0 = (q31_t) ((((q63_t) sum0 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 300 | |
emh203 | 0:3d9c67d97d6f | 301 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 302 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 303 | } |
emh203 | 0:3d9c67d97d6f | 304 | |
emh203 | 0:3d9c67d97d6f | 305 | /* Advance the state pointer by the decimation factor |
emh203 | 0:3d9c67d97d6f | 306 | * to process the next group of decimation factor number samples */ |
emh203 | 0:3d9c67d97d6f | 307 | pState = pState + S->M; |
emh203 | 0:3d9c67d97d6f | 308 | |
emh203 | 0:3d9c67d97d6f | 309 | /* The result is in the accumulator, store in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 310 | *pDst++ = (q31_t) (sum0 << 1); |
emh203 | 0:3d9c67d97d6f | 311 | |
emh203 | 0:3d9c67d97d6f | 312 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 313 | blkCntN2--; |
emh203 | 0:3d9c67d97d6f | 314 | } |
emh203 | 0:3d9c67d97d6f | 315 | |
emh203 | 0:3d9c67d97d6f | 316 | /* Processing is complete. |
emh203 | 0:3d9c67d97d6f | 317 | ** Now copy the last numTaps - 1 samples to the satrt of the state buffer. |
emh203 | 0:3d9c67d97d6f | 318 | ** This prepares the state buffer for the next function call. */ |
emh203 | 0:3d9c67d97d6f | 319 | |
emh203 | 0:3d9c67d97d6f | 320 | /* Points to the start of the state buffer */ |
emh203 | 0:3d9c67d97d6f | 321 | pStateCurnt = S->pState; |
emh203 | 0:3d9c67d97d6f | 322 | |
emh203 | 0:3d9c67d97d6f | 323 | i = (numTaps - 1u) >> 2u; |
emh203 | 0:3d9c67d97d6f | 324 | |
emh203 | 0:3d9c67d97d6f | 325 | /* copy data */ |
emh203 | 0:3d9c67d97d6f | 326 | while(i > 0u) |
emh203 | 0:3d9c67d97d6f | 327 | { |
emh203 | 0:3d9c67d97d6f | 328 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 329 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 330 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 331 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 332 | |
emh203 | 0:3d9c67d97d6f | 333 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 334 | i--; |
emh203 | 0:3d9c67d97d6f | 335 | } |
emh203 | 0:3d9c67d97d6f | 336 | |
emh203 | 0:3d9c67d97d6f | 337 | i = (numTaps - 1u) % 0x04u; |
emh203 | 0:3d9c67d97d6f | 338 | |
emh203 | 0:3d9c67d97d6f | 339 | /* copy data */ |
emh203 | 0:3d9c67d97d6f | 340 | while(i > 0u) |
emh203 | 0:3d9c67d97d6f | 341 | { |
emh203 | 0:3d9c67d97d6f | 342 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 343 | |
emh203 | 0:3d9c67d97d6f | 344 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 345 | i--; |
emh203 | 0:3d9c67d97d6f | 346 | } |
emh203 | 0:3d9c67d97d6f | 347 | } |
emh203 | 0:3d9c67d97d6f | 348 | |
emh203 | 0:3d9c67d97d6f | 349 | /** |
emh203 | 0:3d9c67d97d6f | 350 | * @} end of FIR_decimate group |
emh203 | 0:3d9c67d97d6f | 351 | */ |