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_sparse_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_sparse_q31.c |
emh203 | 0:3d9c67d97d6f | 9 | * |
emh203 | 0:3d9c67d97d6f | 10 | * Description: Q31 sparse FIR 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 | #include "arm_math.h" |
emh203 | 0:3d9c67d97d6f | 41 | |
emh203 | 0:3d9c67d97d6f | 42 | |
emh203 | 0:3d9c67d97d6f | 43 | /** |
emh203 | 0:3d9c67d97d6f | 44 | * @addtogroup FIR_Sparse |
emh203 | 0:3d9c67d97d6f | 45 | * @{ |
emh203 | 0:3d9c67d97d6f | 46 | */ |
emh203 | 0:3d9c67d97d6f | 47 | |
emh203 | 0:3d9c67d97d6f | 48 | /** |
emh203 | 0:3d9c67d97d6f | 49 | * @brief Processing function for the Q31 sparse FIR filter. |
emh203 | 0:3d9c67d97d6f | 50 | * @param[in] *S points to an instance of the Q31 sparse FIR structure. |
emh203 | 0:3d9c67d97d6f | 51 | * @param[in] *pSrc points to the block of input data. |
emh203 | 0:3d9c67d97d6f | 52 | * @param[out] *pDst points to the block of output data |
emh203 | 0:3d9c67d97d6f | 53 | * @param[in] *pScratchIn points to a temporary buffer of size blockSize. |
emh203 | 0:3d9c67d97d6f | 54 | * @param[in] blockSize number of input samples to process per call. |
emh203 | 0:3d9c67d97d6f | 55 | * @return none. |
emh203 | 0:3d9c67d97d6f | 56 | * |
emh203 | 0:3d9c67d97d6f | 57 | * <b>Scaling and Overflow Behavior:</b> |
emh203 | 0:3d9c67d97d6f | 58 | * \par |
emh203 | 0:3d9c67d97d6f | 59 | * The function is implemented using an internal 32-bit accumulator. |
emh203 | 0:3d9c67d97d6f | 60 | * The 1.31 x 1.31 multiplications are truncated to 2.30 format. |
emh203 | 0:3d9c67d97d6f | 61 | * This leads to loss of precision on the intermediate multiplications and provides only a single guard bit. |
emh203 | 0:3d9c67d97d6f | 62 | * If the accumulator result overflows, it wraps around rather than saturate. |
emh203 | 0:3d9c67d97d6f | 63 | * In order to avoid overflows the input signal or coefficients must be scaled down by log2(numTaps) bits. |
emh203 | 0:3d9c67d97d6f | 64 | */ |
emh203 | 0:3d9c67d97d6f | 65 | |
emh203 | 0:3d9c67d97d6f | 66 | void arm_fir_sparse_q31( |
emh203 | 0:3d9c67d97d6f | 67 | arm_fir_sparse_instance_q31 * S, |
emh203 | 0:3d9c67d97d6f | 68 | q31_t * pSrc, |
emh203 | 0:3d9c67d97d6f | 69 | q31_t * pDst, |
emh203 | 0:3d9c67d97d6f | 70 | q31_t * pScratchIn, |
emh203 | 0:3d9c67d97d6f | 71 | uint32_t blockSize) |
emh203 | 0:3d9c67d97d6f | 72 | { |
emh203 | 0:3d9c67d97d6f | 73 | |
emh203 | 0:3d9c67d97d6f | 74 | q31_t *pState = S->pState; /* State pointer */ |
emh203 | 0:3d9c67d97d6f | 75 | q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 76 | q31_t *px; /* Scratch buffer pointer */ |
emh203 | 0:3d9c67d97d6f | 77 | q31_t *py = pState; /* Temporary pointers for state buffer */ |
emh203 | 0:3d9c67d97d6f | 78 | q31_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */ |
emh203 | 0:3d9c67d97d6f | 79 | q31_t *pOut; /* Destination pointer */ |
emh203 | 0:3d9c67d97d6f | 80 | q63_t out; /* Temporary output variable */ |
emh203 | 0:3d9c67d97d6f | 81 | int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */ |
emh203 | 0:3d9c67d97d6f | 82 | uint32_t delaySize = S->maxDelay + blockSize; /* state length */ |
emh203 | 0:3d9c67d97d6f | 83 | uint16_t numTaps = S->numTaps; /* Filter order */ |
emh203 | 0:3d9c67d97d6f | 84 | int32_t readIndex; /* Read index of the state buffer */ |
emh203 | 0:3d9c67d97d6f | 85 | uint32_t tapCnt, blkCnt; /* loop counters */ |
emh203 | 0:3d9c67d97d6f | 86 | q31_t coeff = *pCoeffs++; /* Read the first coefficient value */ |
emh203 | 0:3d9c67d97d6f | 87 | q31_t in; |
emh203 | 0:3d9c67d97d6f | 88 | |
emh203 | 0:3d9c67d97d6f | 89 | |
emh203 | 0:3d9c67d97d6f | 90 | /* BlockSize of Input samples are copied into the state buffer */ |
emh203 | 0:3d9c67d97d6f | 91 | /* StateIndex points to the starting position to write in the state buffer */ |
emh203 | 0:3d9c67d97d6f | 92 | arm_circularWrite_f32((int32_t *) py, delaySize, &S->stateIndex, 1, |
emh203 | 0:3d9c67d97d6f | 93 | (int32_t *) pSrc, 1, blockSize); |
emh203 | 0:3d9c67d97d6f | 94 | |
emh203 | 0:3d9c67d97d6f | 95 | /* Read Index, from where the state buffer should be read, is calculated. */ |
emh203 | 0:3d9c67d97d6f | 96 | readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++; |
emh203 | 0:3d9c67d97d6f | 97 | |
emh203 | 0:3d9c67d97d6f | 98 | /* Wraparound of readIndex */ |
emh203 | 0:3d9c67d97d6f | 99 | if(readIndex < 0) |
emh203 | 0:3d9c67d97d6f | 100 | { |
emh203 | 0:3d9c67d97d6f | 101 | readIndex += (int32_t) delaySize; |
emh203 | 0:3d9c67d97d6f | 102 | } |
emh203 | 0:3d9c67d97d6f | 103 | |
emh203 | 0:3d9c67d97d6f | 104 | /* Working pointer for state buffer is updated */ |
emh203 | 0:3d9c67d97d6f | 105 | py = pState; |
emh203 | 0:3d9c67d97d6f | 106 | |
emh203 | 0:3d9c67d97d6f | 107 | /* blockSize samples are read from the state buffer */ |
emh203 | 0:3d9c67d97d6f | 108 | arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, |
emh203 | 0:3d9c67d97d6f | 109 | (int32_t *) pb, (int32_t *) pb, blockSize, 1, |
emh203 | 0:3d9c67d97d6f | 110 | blockSize); |
emh203 | 0:3d9c67d97d6f | 111 | |
emh203 | 0:3d9c67d97d6f | 112 | /* Working pointer for the scratch buffer of state values */ |
emh203 | 0:3d9c67d97d6f | 113 | px = pb; |
emh203 | 0:3d9c67d97d6f | 114 | |
emh203 | 0:3d9c67d97d6f | 115 | /* Working pointer for scratch buffer of output values */ |
emh203 | 0:3d9c67d97d6f | 116 | pOut = pDst; |
emh203 | 0:3d9c67d97d6f | 117 | |
emh203 | 0:3d9c67d97d6f | 118 | |
emh203 | 0:3d9c67d97d6f | 119 | #ifndef ARM_MATH_CM0_FAMILY |
emh203 | 0:3d9c67d97d6f | 120 | |
emh203 | 0:3d9c67d97d6f | 121 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emh203 | 0:3d9c67d97d6f | 122 | |
emh203 | 0:3d9c67d97d6f | 123 | /* Loop over the blockSize. Unroll by a factor of 4. |
emh203 | 0:3d9c67d97d6f | 124 | * Compute 4 Multiplications at a time. */ |
emh203 | 0:3d9c67d97d6f | 125 | blkCnt = blockSize >> 2; |
emh203 | 0:3d9c67d97d6f | 126 | |
emh203 | 0:3d9c67d97d6f | 127 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 128 | { |
emh203 | 0:3d9c67d97d6f | 129 | /* Perform Multiplications and store in the destination buffer */ |
emh203 | 0:3d9c67d97d6f | 130 | *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32); |
emh203 | 0:3d9c67d97d6f | 131 | *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32); |
emh203 | 0:3d9c67d97d6f | 132 | *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32); |
emh203 | 0:3d9c67d97d6f | 133 | *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32); |
emh203 | 0:3d9c67d97d6f | 134 | |
emh203 | 0:3d9c67d97d6f | 135 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 136 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 137 | } |
emh203 | 0:3d9c67d97d6f | 138 | |
emh203 | 0:3d9c67d97d6f | 139 | /* If the blockSize is not a multiple of 4, |
emh203 | 0:3d9c67d97d6f | 140 | * compute the remaining samples */ |
emh203 | 0:3d9c67d97d6f | 141 | blkCnt = blockSize % 0x4u; |
emh203 | 0:3d9c67d97d6f | 142 | |
emh203 | 0:3d9c67d97d6f | 143 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 144 | { |
emh203 | 0:3d9c67d97d6f | 145 | /* Perform Multiplications and store in the destination buffer */ |
emh203 | 0:3d9c67d97d6f | 146 | *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32); |
emh203 | 0:3d9c67d97d6f | 147 | |
emh203 | 0:3d9c67d97d6f | 148 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 149 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 150 | } |
emh203 | 0:3d9c67d97d6f | 151 | |
emh203 | 0:3d9c67d97d6f | 152 | /* Load the coefficient value and |
emh203 | 0:3d9c67d97d6f | 153 | * increment the coefficient buffer for the next set of state values */ |
emh203 | 0:3d9c67d97d6f | 154 | coeff = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 155 | |
emh203 | 0:3d9c67d97d6f | 156 | /* Read Index, from where the state buffer should be read, is calculated. */ |
emh203 | 0:3d9c67d97d6f | 157 | readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++; |
emh203 | 0:3d9c67d97d6f | 158 | |
emh203 | 0:3d9c67d97d6f | 159 | /* Wraparound of readIndex */ |
emh203 | 0:3d9c67d97d6f | 160 | if(readIndex < 0) |
emh203 | 0:3d9c67d97d6f | 161 | { |
emh203 | 0:3d9c67d97d6f | 162 | readIndex += (int32_t) delaySize; |
emh203 | 0:3d9c67d97d6f | 163 | } |
emh203 | 0:3d9c67d97d6f | 164 | |
emh203 | 0:3d9c67d97d6f | 165 | /* Loop over the number of taps. */ |
emh203 | 0:3d9c67d97d6f | 166 | tapCnt = (uint32_t) numTaps - 1u; |
emh203 | 0:3d9c67d97d6f | 167 | |
emh203 | 0:3d9c67d97d6f | 168 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 169 | { |
emh203 | 0:3d9c67d97d6f | 170 | /* Working pointer for state buffer is updated */ |
emh203 | 0:3d9c67d97d6f | 171 | py = pState; |
emh203 | 0:3d9c67d97d6f | 172 | |
emh203 | 0:3d9c67d97d6f | 173 | /* blockSize samples are read from the state buffer */ |
emh203 | 0:3d9c67d97d6f | 174 | arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, |
emh203 | 0:3d9c67d97d6f | 175 | (int32_t *) pb, (int32_t *) pb, blockSize, 1, |
emh203 | 0:3d9c67d97d6f | 176 | blockSize); |
emh203 | 0:3d9c67d97d6f | 177 | |
emh203 | 0:3d9c67d97d6f | 178 | /* Working pointer for the scratch buffer of state values */ |
emh203 | 0:3d9c67d97d6f | 179 | px = pb; |
emh203 | 0:3d9c67d97d6f | 180 | |
emh203 | 0:3d9c67d97d6f | 181 | /* Working pointer for scratch buffer of output values */ |
emh203 | 0:3d9c67d97d6f | 182 | pOut = pDst; |
emh203 | 0:3d9c67d97d6f | 183 | |
emh203 | 0:3d9c67d97d6f | 184 | /* Loop over the blockSize. Unroll by a factor of 4. |
emh203 | 0:3d9c67d97d6f | 185 | * Compute 4 MACS at a time. */ |
emh203 | 0:3d9c67d97d6f | 186 | blkCnt = blockSize >> 2; |
emh203 | 0:3d9c67d97d6f | 187 | |
emh203 | 0:3d9c67d97d6f | 188 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 189 | { |
emh203 | 0:3d9c67d97d6f | 190 | out = *pOut; |
emh203 | 0:3d9c67d97d6f | 191 | out += ((q63_t) * px++ * coeff) >> 32; |
emh203 | 0:3d9c67d97d6f | 192 | *pOut++ = (q31_t) (out); |
emh203 | 0:3d9c67d97d6f | 193 | |
emh203 | 0:3d9c67d97d6f | 194 | out = *pOut; |
emh203 | 0:3d9c67d97d6f | 195 | out += ((q63_t) * px++ * coeff) >> 32; |
emh203 | 0:3d9c67d97d6f | 196 | *pOut++ = (q31_t) (out); |
emh203 | 0:3d9c67d97d6f | 197 | |
emh203 | 0:3d9c67d97d6f | 198 | out = *pOut; |
emh203 | 0:3d9c67d97d6f | 199 | out += ((q63_t) * px++ * coeff) >> 32; |
emh203 | 0:3d9c67d97d6f | 200 | *pOut++ = (q31_t) (out); |
emh203 | 0:3d9c67d97d6f | 201 | |
emh203 | 0:3d9c67d97d6f | 202 | out = *pOut; |
emh203 | 0:3d9c67d97d6f | 203 | out += ((q63_t) * px++ * coeff) >> 32; |
emh203 | 0:3d9c67d97d6f | 204 | *pOut++ = (q31_t) (out); |
emh203 | 0:3d9c67d97d6f | 205 | |
emh203 | 0:3d9c67d97d6f | 206 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 207 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 208 | } |
emh203 | 0:3d9c67d97d6f | 209 | |
emh203 | 0:3d9c67d97d6f | 210 | /* If the blockSize is not a multiple of 4, |
emh203 | 0:3d9c67d97d6f | 211 | * compute the remaining samples */ |
emh203 | 0:3d9c67d97d6f | 212 | blkCnt = blockSize % 0x4u; |
emh203 | 0:3d9c67d97d6f | 213 | |
emh203 | 0:3d9c67d97d6f | 214 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 215 | { |
emh203 | 0:3d9c67d97d6f | 216 | /* Perform Multiply-Accumulate */ |
emh203 | 0:3d9c67d97d6f | 217 | out = *pOut; |
emh203 | 0:3d9c67d97d6f | 218 | out += ((q63_t) * px++ * coeff) >> 32; |
emh203 | 0:3d9c67d97d6f | 219 | *pOut++ = (q31_t) (out); |
emh203 | 0:3d9c67d97d6f | 220 | |
emh203 | 0:3d9c67d97d6f | 221 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 222 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 223 | } |
emh203 | 0:3d9c67d97d6f | 224 | |
emh203 | 0:3d9c67d97d6f | 225 | /* Load the coefficient value and |
emh203 | 0:3d9c67d97d6f | 226 | * increment the coefficient buffer for the next set of state values */ |
emh203 | 0:3d9c67d97d6f | 227 | coeff = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 228 | |
emh203 | 0:3d9c67d97d6f | 229 | /* Read Index, from where the state buffer should be read, is calculated. */ |
emh203 | 0:3d9c67d97d6f | 230 | readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++; |
emh203 | 0:3d9c67d97d6f | 231 | |
emh203 | 0:3d9c67d97d6f | 232 | /* Wraparound of readIndex */ |
emh203 | 0:3d9c67d97d6f | 233 | if(readIndex < 0) |
emh203 | 0:3d9c67d97d6f | 234 | { |
emh203 | 0:3d9c67d97d6f | 235 | readIndex += (int32_t) delaySize; |
emh203 | 0:3d9c67d97d6f | 236 | } |
emh203 | 0:3d9c67d97d6f | 237 | |
emh203 | 0:3d9c67d97d6f | 238 | /* Decrement the tap loop counter */ |
emh203 | 0:3d9c67d97d6f | 239 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 240 | } |
emh203 | 0:3d9c67d97d6f | 241 | |
emh203 | 0:3d9c67d97d6f | 242 | /* Working output pointer is updated */ |
emh203 | 0:3d9c67d97d6f | 243 | pOut = pDst; |
emh203 | 0:3d9c67d97d6f | 244 | |
emh203 | 0:3d9c67d97d6f | 245 | /* Output is converted into 1.31 format. */ |
emh203 | 0:3d9c67d97d6f | 246 | /* Loop over the blockSize. Unroll by a factor of 4. |
emh203 | 0:3d9c67d97d6f | 247 | * process 4 output samples at a time. */ |
emh203 | 0:3d9c67d97d6f | 248 | blkCnt = blockSize >> 2; |
emh203 | 0:3d9c67d97d6f | 249 | |
emh203 | 0:3d9c67d97d6f | 250 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 251 | { |
emh203 | 0:3d9c67d97d6f | 252 | in = *pOut << 1; |
emh203 | 0:3d9c67d97d6f | 253 | *pOut++ = in; |
emh203 | 0:3d9c67d97d6f | 254 | in = *pOut << 1; |
emh203 | 0:3d9c67d97d6f | 255 | *pOut++ = in; |
emh203 | 0:3d9c67d97d6f | 256 | in = *pOut << 1; |
emh203 | 0:3d9c67d97d6f | 257 | *pOut++ = in; |
emh203 | 0:3d9c67d97d6f | 258 | in = *pOut << 1; |
emh203 | 0:3d9c67d97d6f | 259 | *pOut++ = in; |
emh203 | 0:3d9c67d97d6f | 260 | |
emh203 | 0:3d9c67d97d6f | 261 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 262 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 263 | } |
emh203 | 0:3d9c67d97d6f | 264 | |
emh203 | 0:3d9c67d97d6f | 265 | /* If the blockSize is not a multiple of 4, |
emh203 | 0:3d9c67d97d6f | 266 | * process the remaining output samples */ |
emh203 | 0:3d9c67d97d6f | 267 | blkCnt = blockSize % 0x4u; |
emh203 | 0:3d9c67d97d6f | 268 | |
emh203 | 0:3d9c67d97d6f | 269 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 270 | { |
emh203 | 0:3d9c67d97d6f | 271 | in = *pOut << 1; |
emh203 | 0:3d9c67d97d6f | 272 | *pOut++ = in; |
emh203 | 0:3d9c67d97d6f | 273 | |
emh203 | 0:3d9c67d97d6f | 274 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 275 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 276 | } |
emh203 | 0:3d9c67d97d6f | 277 | |
emh203 | 0:3d9c67d97d6f | 278 | #else |
emh203 | 0:3d9c67d97d6f | 279 | |
emh203 | 0:3d9c67d97d6f | 280 | /* Run the below code for Cortex-M0 */ |
emh203 | 0:3d9c67d97d6f | 281 | blkCnt = blockSize; |
emh203 | 0:3d9c67d97d6f | 282 | |
emh203 | 0:3d9c67d97d6f | 283 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 284 | { |
emh203 | 0:3d9c67d97d6f | 285 | /* Perform Multiplications and store in the destination buffer */ |
emh203 | 0:3d9c67d97d6f | 286 | *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32); |
emh203 | 0:3d9c67d97d6f | 287 | |
emh203 | 0:3d9c67d97d6f | 288 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 289 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 290 | } |
emh203 | 0:3d9c67d97d6f | 291 | |
emh203 | 0:3d9c67d97d6f | 292 | /* Load the coefficient value and |
emh203 | 0:3d9c67d97d6f | 293 | * increment the coefficient buffer for the next set of state values */ |
emh203 | 0:3d9c67d97d6f | 294 | coeff = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 295 | |
emh203 | 0:3d9c67d97d6f | 296 | /* Read Index, from where the state buffer should be read, is calculated. */ |
emh203 | 0:3d9c67d97d6f | 297 | readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++; |
emh203 | 0:3d9c67d97d6f | 298 | |
emh203 | 0:3d9c67d97d6f | 299 | /* Wraparound of readIndex */ |
emh203 | 0:3d9c67d97d6f | 300 | if(readIndex < 0) |
emh203 | 0:3d9c67d97d6f | 301 | { |
emh203 | 0:3d9c67d97d6f | 302 | readIndex += (int32_t) delaySize; |
emh203 | 0:3d9c67d97d6f | 303 | } |
emh203 | 0:3d9c67d97d6f | 304 | |
emh203 | 0:3d9c67d97d6f | 305 | /* Loop over the number of taps. */ |
emh203 | 0:3d9c67d97d6f | 306 | tapCnt = (uint32_t) numTaps - 1u; |
emh203 | 0:3d9c67d97d6f | 307 | |
emh203 | 0:3d9c67d97d6f | 308 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 309 | { |
emh203 | 0:3d9c67d97d6f | 310 | /* Working pointer for state buffer is updated */ |
emh203 | 0:3d9c67d97d6f | 311 | py = pState; |
emh203 | 0:3d9c67d97d6f | 312 | |
emh203 | 0:3d9c67d97d6f | 313 | /* blockSize samples are read from the state buffer */ |
emh203 | 0:3d9c67d97d6f | 314 | arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, |
emh203 | 0:3d9c67d97d6f | 315 | (int32_t *) pb, (int32_t *) pb, blockSize, 1, |
emh203 | 0:3d9c67d97d6f | 316 | blockSize); |
emh203 | 0:3d9c67d97d6f | 317 | |
emh203 | 0:3d9c67d97d6f | 318 | /* Working pointer for the scratch buffer of state values */ |
emh203 | 0:3d9c67d97d6f | 319 | px = pb; |
emh203 | 0:3d9c67d97d6f | 320 | |
emh203 | 0:3d9c67d97d6f | 321 | /* Working pointer for scratch buffer of output values */ |
emh203 | 0:3d9c67d97d6f | 322 | pOut = pDst; |
emh203 | 0:3d9c67d97d6f | 323 | |
emh203 | 0:3d9c67d97d6f | 324 | blkCnt = blockSize; |
emh203 | 0:3d9c67d97d6f | 325 | |
emh203 | 0:3d9c67d97d6f | 326 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 327 | { |
emh203 | 0:3d9c67d97d6f | 328 | /* Perform Multiply-Accumulate */ |
emh203 | 0:3d9c67d97d6f | 329 | out = *pOut; |
emh203 | 0:3d9c67d97d6f | 330 | out += ((q63_t) * px++ * coeff) >> 32; |
emh203 | 0:3d9c67d97d6f | 331 | *pOut++ = (q31_t) (out); |
emh203 | 0:3d9c67d97d6f | 332 | |
emh203 | 0:3d9c67d97d6f | 333 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 334 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 335 | } |
emh203 | 0:3d9c67d97d6f | 336 | |
emh203 | 0:3d9c67d97d6f | 337 | /* Load the coefficient value and |
emh203 | 0:3d9c67d97d6f | 338 | * increment the coefficient buffer for the next set of state values */ |
emh203 | 0:3d9c67d97d6f | 339 | coeff = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 340 | |
emh203 | 0:3d9c67d97d6f | 341 | /* Read Index, from where the state buffer should be read, is calculated. */ |
emh203 | 0:3d9c67d97d6f | 342 | readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++; |
emh203 | 0:3d9c67d97d6f | 343 | |
emh203 | 0:3d9c67d97d6f | 344 | /* Wraparound of readIndex */ |
emh203 | 0:3d9c67d97d6f | 345 | if(readIndex < 0) |
emh203 | 0:3d9c67d97d6f | 346 | { |
emh203 | 0:3d9c67d97d6f | 347 | readIndex += (int32_t) delaySize; |
emh203 | 0:3d9c67d97d6f | 348 | } |
emh203 | 0:3d9c67d97d6f | 349 | |
emh203 | 0:3d9c67d97d6f | 350 | /* Decrement the tap loop counter */ |
emh203 | 0:3d9c67d97d6f | 351 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 352 | } |
emh203 | 0:3d9c67d97d6f | 353 | |
emh203 | 0:3d9c67d97d6f | 354 | /* Working output pointer is updated */ |
emh203 | 0:3d9c67d97d6f | 355 | pOut = pDst; |
emh203 | 0:3d9c67d97d6f | 356 | |
emh203 | 0:3d9c67d97d6f | 357 | /* Output is converted into 1.31 format. */ |
emh203 | 0:3d9c67d97d6f | 358 | blkCnt = blockSize; |
emh203 | 0:3d9c67d97d6f | 359 | |
emh203 | 0:3d9c67d97d6f | 360 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 361 | { |
emh203 | 0:3d9c67d97d6f | 362 | in = *pOut << 1; |
emh203 | 0:3d9c67d97d6f | 363 | *pOut++ = in; |
emh203 | 0:3d9c67d97d6f | 364 | |
emh203 | 0:3d9c67d97d6f | 365 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 366 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 367 | } |
emh203 | 0:3d9c67d97d6f | 368 | |
emh203 | 0:3d9c67d97d6f | 369 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
emh203 | 0:3d9c67d97d6f | 370 | |
emh203 | 0:3d9c67d97d6f | 371 | } |
emh203 | 0:3d9c67d97d6f | 372 | |
emh203 | 0:3d9c67d97d6f | 373 | /** |
emh203 | 0:3d9c67d97d6f | 374 | * @} end of FIR_Sparse group |
emh203 | 0:3d9c67d97d6f | 375 | */ |