CMSIS DSP library
Dependents: performance_timer Surfboard_ gps2rtty Capstone ... more
Legacy Warning
This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.
cmsis_dsp/FilteringFunctions/arm_fir_sparse_f32.c@2:da51fb522205, 2013-05-30 (annotated)
- Committer:
- emilmont
- Date:
- Thu May 30 17:10:11 2013 +0100
- Revision:
- 2:da51fb522205
- Parent:
- 1:fdd22bb7aa52
- Child:
- 3:7a284390b0ce
Keep "cmsis-dsp" module in synch with its source
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:fdd22bb7aa52 | 1 | /* ---------------------------------------------------------------------- |
emilmont | 1:fdd22bb7aa52 | 2 | * Copyright (C) 2010 ARM Limited. All rights reserved. |
emilmont | 1:fdd22bb7aa52 | 3 | * |
emilmont | 1:fdd22bb7aa52 | 4 | * $Date: 15. February 2012 |
emilmont | 2:da51fb522205 | 5 | * $Revision: V1.1.0 |
emilmont | 1:fdd22bb7aa52 | 6 | * |
emilmont | 2:da51fb522205 | 7 | * Project: CMSIS DSP Library |
emilmont | 2:da51fb522205 | 8 | * Title: arm_fir_sparse_f32.c |
emilmont | 1:fdd22bb7aa52 | 9 | * |
emilmont | 2:da51fb522205 | 10 | * Description: Floating-point sparse FIR filter processing function. |
emilmont | 1:fdd22bb7aa52 | 11 | * |
emilmont | 1:fdd22bb7aa52 | 12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 |
emilmont | 1:fdd22bb7aa52 | 13 | * |
emilmont | 1:fdd22bb7aa52 | 14 | * Version 1.1.0 2012/02/15 |
emilmont | 1:fdd22bb7aa52 | 15 | * Updated with more optimizations, bug fixes and minor API changes. |
emilmont | 1:fdd22bb7aa52 | 16 | * |
emilmont | 1:fdd22bb7aa52 | 17 | * Version 1.0.10 2011/7/15 |
emilmont | 1:fdd22bb7aa52 | 18 | * Big Endian support added and Merged M0 and M3/M4 Source code. |
emilmont | 1:fdd22bb7aa52 | 19 | * |
emilmont | 1:fdd22bb7aa52 | 20 | * Version 1.0.3 2010/11/29 |
emilmont | 1:fdd22bb7aa52 | 21 | * Re-organized the CMSIS folders and updated documentation. |
emilmont | 1:fdd22bb7aa52 | 22 | * |
emilmont | 1:fdd22bb7aa52 | 23 | * Version 1.0.2 2010/11/11 |
emilmont | 1:fdd22bb7aa52 | 24 | * Documentation updated. |
emilmont | 1:fdd22bb7aa52 | 25 | * |
emilmont | 1:fdd22bb7aa52 | 26 | * Version 1.0.1 2010/10/05 |
emilmont | 1:fdd22bb7aa52 | 27 | * Production release and review comments incorporated. |
emilmont | 1:fdd22bb7aa52 | 28 | * |
emilmont | 1:fdd22bb7aa52 | 29 | * Version 1.0.0 2010/09/20 |
emilmont | 1:fdd22bb7aa52 | 30 | * Production release and review comments incorporated |
emilmont | 1:fdd22bb7aa52 | 31 | * |
emilmont | 1:fdd22bb7aa52 | 32 | * Version 0.0.7 2010/06/10 |
emilmont | 1:fdd22bb7aa52 | 33 | * Misra-C changes done |
emilmont | 1:fdd22bb7aa52 | 34 | * ------------------------------------------------------------------- */ |
emilmont | 1:fdd22bb7aa52 | 35 | #include "arm_math.h" |
emilmont | 1:fdd22bb7aa52 | 36 | |
emilmont | 1:fdd22bb7aa52 | 37 | /** |
emilmont | 1:fdd22bb7aa52 | 38 | * @ingroup groupFilters |
emilmont | 1:fdd22bb7aa52 | 39 | */ |
emilmont | 1:fdd22bb7aa52 | 40 | |
emilmont | 1:fdd22bb7aa52 | 41 | /** |
emilmont | 1:fdd22bb7aa52 | 42 | * @defgroup FIR_Sparse Finite Impulse Response (FIR) Sparse Filters |
emilmont | 1:fdd22bb7aa52 | 43 | * |
emilmont | 1:fdd22bb7aa52 | 44 | * This group of functions implements sparse FIR filters. |
emilmont | 1:fdd22bb7aa52 | 45 | * Sparse FIR filters are equivalent to standard FIR filters except that most of the coefficients are equal to zero. |
emilmont | 1:fdd22bb7aa52 | 46 | * Sparse filters are used for simulating reflections in communications and audio applications. |
emilmont | 1:fdd22bb7aa52 | 47 | * |
emilmont | 1:fdd22bb7aa52 | 48 | * There are separate functions for Q7, Q15, Q31, and floating-point data types. |
emilmont | 1:fdd22bb7aa52 | 49 | * The functions operate on blocks of input and output data and each call to the function processes |
emilmont | 1:fdd22bb7aa52 | 50 | * <code>blockSize</code> samples through the filter. <code>pSrc</code> and |
emilmont | 1:fdd22bb7aa52 | 51 | * <code>pDst</code> points to input and output arrays respectively containing <code>blockSize</code> values. |
emilmont | 1:fdd22bb7aa52 | 52 | * |
emilmont | 1:fdd22bb7aa52 | 53 | * \par Algorithm: |
emilmont | 1:fdd22bb7aa52 | 54 | * The sparse filter instant structure contains an array of tap indices <code>pTapDelay</code> which specifies the locations of the non-zero coefficients. |
emilmont | 1:fdd22bb7aa52 | 55 | * This is in addition to the coefficient array <code>b</code>. |
emilmont | 1:fdd22bb7aa52 | 56 | * The implementation essentially skips the multiplications by zero and leads to an efficient realization. |
emilmont | 1:fdd22bb7aa52 | 57 | * <pre> |
emilmont | 1:fdd22bb7aa52 | 58 | * y[n] = b[0] * x[n-pTapDelay[0]] + b[1] * x[n-pTapDelay[1]] + b[2] * x[n-pTapDelay[2]] + ...+ b[numTaps-1] * x[n-pTapDelay[numTaps-1]] |
emilmont | 1:fdd22bb7aa52 | 59 | * </pre> |
emilmont | 1:fdd22bb7aa52 | 60 | * \par |
emilmont | 1:fdd22bb7aa52 | 61 | * \image html FIRSparse.gif "Sparse FIR filter. b[n] represents the filter coefficients" |
emilmont | 1:fdd22bb7aa52 | 62 | * \par |
emilmont | 1:fdd22bb7aa52 | 63 | * <code>pCoeffs</code> points to a coefficient array of size <code>numTaps</code>; |
emilmont | 1:fdd22bb7aa52 | 64 | * <code>pTapDelay</code> points to an array of nonzero indices and is also of size <code>numTaps</code>; |
emilmont | 1:fdd22bb7aa52 | 65 | * <code>pState</code> points to a state array of size <code>maxDelay + blockSize</code>, where |
emilmont | 1:fdd22bb7aa52 | 66 | * <code>maxDelay</code> is the largest offset value that is ever used in the <code>pTapDelay</code> array. |
emilmont | 1:fdd22bb7aa52 | 67 | * Some of the processing functions also require temporary working buffers. |
emilmont | 1:fdd22bb7aa52 | 68 | * |
emilmont | 1:fdd22bb7aa52 | 69 | * \par Instance Structure |
emilmont | 1:fdd22bb7aa52 | 70 | * The coefficients and state variables for a filter are stored together in an instance data structure. |
emilmont | 1:fdd22bb7aa52 | 71 | * A separate instance structure must be defined for each filter. |
emilmont | 1:fdd22bb7aa52 | 72 | * Coefficient and offset arrays may be shared among several instances while state variable arrays cannot be shared. |
emilmont | 1:fdd22bb7aa52 | 73 | * There are separate instance structure declarations for each of the 4 supported data types. |
emilmont | 1:fdd22bb7aa52 | 74 | * |
emilmont | 1:fdd22bb7aa52 | 75 | * \par Initialization Functions |
emilmont | 1:fdd22bb7aa52 | 76 | * There is also an associated initialization function for each data type. |
emilmont | 1:fdd22bb7aa52 | 77 | * The initialization function performs the following operations: |
emilmont | 1:fdd22bb7aa52 | 78 | * - Sets the values of the internal structure fields. |
emilmont | 1:fdd22bb7aa52 | 79 | * - Zeros out the values in the state buffer. |
emilmont | 1:fdd22bb7aa52 | 80 | * |
emilmont | 1:fdd22bb7aa52 | 81 | * \par |
emilmont | 1:fdd22bb7aa52 | 82 | * Use of the initialization function is optional. |
emilmont | 1:fdd22bb7aa52 | 83 | * However, if the initialization function is used, then the instance structure cannot be placed into a const data section. |
emilmont | 1:fdd22bb7aa52 | 84 | * To place an instance structure into a const data section, the instance structure must be manually initialized. |
emilmont | 1:fdd22bb7aa52 | 85 | * Set the values in the state buffer to zeros before static initialization. |
emilmont | 1:fdd22bb7aa52 | 86 | * The code below statically initializes each of the 4 different data type filter instance structures |
emilmont | 1:fdd22bb7aa52 | 87 | * <pre> |
emilmont | 1:fdd22bb7aa52 | 88 | *arm_fir_sparse_instance_f32 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay}; |
emilmont | 1:fdd22bb7aa52 | 89 | *arm_fir_sparse_instance_q31 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay}; |
emilmont | 1:fdd22bb7aa52 | 90 | *arm_fir_sparse_instance_q15 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay}; |
emilmont | 1:fdd22bb7aa52 | 91 | *arm_fir_sparse_instance_q7 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay}; |
emilmont | 1:fdd22bb7aa52 | 92 | * </pre> |
emilmont | 1:fdd22bb7aa52 | 93 | * \par |
emilmont | 1:fdd22bb7aa52 | 94 | * |
emilmont | 1:fdd22bb7aa52 | 95 | * \par Fixed-Point Behavior |
emilmont | 1:fdd22bb7aa52 | 96 | * Care must be taken when using the fixed-point versions of the sparse FIR filter functions. |
emilmont | 1:fdd22bb7aa52 | 97 | * In particular, the overflow and saturation behavior of the accumulator used in each function must be considered. |
emilmont | 1:fdd22bb7aa52 | 98 | * Refer to the function specific documentation below for usage guidelines. |
emilmont | 1:fdd22bb7aa52 | 99 | */ |
emilmont | 1:fdd22bb7aa52 | 100 | |
emilmont | 1:fdd22bb7aa52 | 101 | /** |
emilmont | 1:fdd22bb7aa52 | 102 | * @addtogroup FIR_Sparse |
emilmont | 1:fdd22bb7aa52 | 103 | * @{ |
emilmont | 1:fdd22bb7aa52 | 104 | */ |
emilmont | 1:fdd22bb7aa52 | 105 | |
emilmont | 1:fdd22bb7aa52 | 106 | /** |
emilmont | 1:fdd22bb7aa52 | 107 | * @brief Processing function for the floating-point sparse FIR filter. |
emilmont | 1:fdd22bb7aa52 | 108 | * @param[in] *S points to an instance of the floating-point sparse FIR structure. |
emilmont | 1:fdd22bb7aa52 | 109 | * @param[in] *pSrc points to the block of input data. |
emilmont | 1:fdd22bb7aa52 | 110 | * @param[out] *pDst points to the block of output data |
emilmont | 1:fdd22bb7aa52 | 111 | * @param[in] *pScratchIn points to a temporary buffer of size blockSize. |
emilmont | 1:fdd22bb7aa52 | 112 | * @param[in] blockSize number of input samples to process per call. |
emilmont | 1:fdd22bb7aa52 | 113 | * @return none. |
emilmont | 1:fdd22bb7aa52 | 114 | */ |
emilmont | 1:fdd22bb7aa52 | 115 | |
emilmont | 1:fdd22bb7aa52 | 116 | void arm_fir_sparse_f32( |
emilmont | 1:fdd22bb7aa52 | 117 | arm_fir_sparse_instance_f32 * S, |
emilmont | 1:fdd22bb7aa52 | 118 | float32_t * pSrc, |
emilmont | 1:fdd22bb7aa52 | 119 | float32_t * pDst, |
emilmont | 1:fdd22bb7aa52 | 120 | float32_t * pScratchIn, |
emilmont | 1:fdd22bb7aa52 | 121 | uint32_t blockSize) |
emilmont | 1:fdd22bb7aa52 | 122 | { |
emilmont | 1:fdd22bb7aa52 | 123 | |
emilmont | 1:fdd22bb7aa52 | 124 | float32_t *pState = S->pState; /* State pointer */ |
emilmont | 1:fdd22bb7aa52 | 125 | float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
emilmont | 1:fdd22bb7aa52 | 126 | float32_t *px; /* Scratch buffer pointer */ |
emilmont | 1:fdd22bb7aa52 | 127 | float32_t *py = pState; /* Temporary pointers for state buffer */ |
emilmont | 1:fdd22bb7aa52 | 128 | float32_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */ |
emilmont | 1:fdd22bb7aa52 | 129 | float32_t *pOut; /* Destination pointer */ |
emilmont | 1:fdd22bb7aa52 | 130 | int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */ |
emilmont | 1:fdd22bb7aa52 | 131 | uint32_t delaySize = S->maxDelay + blockSize; /* state length */ |
emilmont | 1:fdd22bb7aa52 | 132 | uint16_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ |
emilmont | 1:fdd22bb7aa52 | 133 | int32_t readIndex; /* Read index of the state buffer */ |
emilmont | 1:fdd22bb7aa52 | 134 | uint32_t tapCnt, blkCnt; /* loop counters */ |
emilmont | 1:fdd22bb7aa52 | 135 | float32_t coeff = *pCoeffs++; /* Read the first coefficient value */ |
emilmont | 1:fdd22bb7aa52 | 136 | |
emilmont | 1:fdd22bb7aa52 | 137 | |
emilmont | 1:fdd22bb7aa52 | 138 | |
emilmont | 1:fdd22bb7aa52 | 139 | /* BlockSize of Input samples are copied into the state buffer */ |
emilmont | 1:fdd22bb7aa52 | 140 | /* StateIndex points to the starting position to write in the state buffer */ |
emilmont | 1:fdd22bb7aa52 | 141 | arm_circularWrite_f32((int32_t *) py, delaySize, &S->stateIndex, 1, |
emilmont | 1:fdd22bb7aa52 | 142 | (int32_t *) pSrc, 1, blockSize); |
emilmont | 1:fdd22bb7aa52 | 143 | |
emilmont | 1:fdd22bb7aa52 | 144 | |
emilmont | 1:fdd22bb7aa52 | 145 | /* Read Index, from where the state buffer should be read, is calculated. */ |
emilmont | 1:fdd22bb7aa52 | 146 | readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
emilmont | 1:fdd22bb7aa52 | 147 | |
emilmont | 1:fdd22bb7aa52 | 148 | /* Wraparound of readIndex */ |
emilmont | 1:fdd22bb7aa52 | 149 | if(readIndex < 0) |
emilmont | 1:fdd22bb7aa52 | 150 | { |
emilmont | 1:fdd22bb7aa52 | 151 | readIndex += (int32_t) delaySize; |
emilmont | 1:fdd22bb7aa52 | 152 | } |
emilmont | 1:fdd22bb7aa52 | 153 | |
emilmont | 1:fdd22bb7aa52 | 154 | /* Working pointer for state buffer is updated */ |
emilmont | 1:fdd22bb7aa52 | 155 | py = pState; |
emilmont | 1:fdd22bb7aa52 | 156 | |
emilmont | 1:fdd22bb7aa52 | 157 | /* blockSize samples are read from the state buffer */ |
emilmont | 1:fdd22bb7aa52 | 158 | arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, |
emilmont | 1:fdd22bb7aa52 | 159 | (int32_t *) pb, (int32_t *) pb, blockSize, 1, |
emilmont | 1:fdd22bb7aa52 | 160 | blockSize); |
emilmont | 1:fdd22bb7aa52 | 161 | |
emilmont | 1:fdd22bb7aa52 | 162 | /* Working pointer for the scratch buffer */ |
emilmont | 1:fdd22bb7aa52 | 163 | px = pb; |
emilmont | 1:fdd22bb7aa52 | 164 | |
emilmont | 1:fdd22bb7aa52 | 165 | /* Working pointer for destination buffer */ |
emilmont | 1:fdd22bb7aa52 | 166 | pOut = pDst; |
emilmont | 1:fdd22bb7aa52 | 167 | |
emilmont | 1:fdd22bb7aa52 | 168 | |
emilmont | 1:fdd22bb7aa52 | 169 | #ifndef ARM_MATH_CM0 |
emilmont | 1:fdd22bb7aa52 | 170 | |
emilmont | 1:fdd22bb7aa52 | 171 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emilmont | 1:fdd22bb7aa52 | 172 | |
emilmont | 1:fdd22bb7aa52 | 173 | /* Loop over the blockSize. Unroll by a factor of 4. |
emilmont | 1:fdd22bb7aa52 | 174 | * Compute 4 Multiplications at a time. */ |
emilmont | 1:fdd22bb7aa52 | 175 | blkCnt = blockSize >> 2u; |
emilmont | 1:fdd22bb7aa52 | 176 | |
emilmont | 1:fdd22bb7aa52 | 177 | while(blkCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 178 | { |
emilmont | 1:fdd22bb7aa52 | 179 | /* Perform Multiplications and store in destination buffer */ |
emilmont | 1:fdd22bb7aa52 | 180 | *pOut++ = *px++ * coeff; |
emilmont | 1:fdd22bb7aa52 | 181 | *pOut++ = *px++ * coeff; |
emilmont | 1:fdd22bb7aa52 | 182 | *pOut++ = *px++ * coeff; |
emilmont | 1:fdd22bb7aa52 | 183 | *pOut++ = *px++ * coeff; |
emilmont | 1:fdd22bb7aa52 | 184 | |
emilmont | 1:fdd22bb7aa52 | 185 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 186 | blkCnt--; |
emilmont | 1:fdd22bb7aa52 | 187 | } |
emilmont | 1:fdd22bb7aa52 | 188 | |
emilmont | 1:fdd22bb7aa52 | 189 | /* If the blockSize is not a multiple of 4, |
emilmont | 1:fdd22bb7aa52 | 190 | * compute the remaining samples */ |
emilmont | 1:fdd22bb7aa52 | 191 | blkCnt = blockSize % 0x4u; |
emilmont | 1:fdd22bb7aa52 | 192 | |
emilmont | 1:fdd22bb7aa52 | 193 | while(blkCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 194 | { |
emilmont | 1:fdd22bb7aa52 | 195 | /* Perform Multiplications and store in destination buffer */ |
emilmont | 1:fdd22bb7aa52 | 196 | *pOut++ = *px++ * coeff; |
emilmont | 1:fdd22bb7aa52 | 197 | |
emilmont | 1:fdd22bb7aa52 | 198 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 199 | blkCnt--; |
emilmont | 1:fdd22bb7aa52 | 200 | } |
emilmont | 1:fdd22bb7aa52 | 201 | |
emilmont | 1:fdd22bb7aa52 | 202 | /* Load the coefficient value and |
emilmont | 1:fdd22bb7aa52 | 203 | * increment the coefficient buffer for the next set of state values */ |
emilmont | 1:fdd22bb7aa52 | 204 | coeff = *pCoeffs++; |
emilmont | 1:fdd22bb7aa52 | 205 | |
emilmont | 1:fdd22bb7aa52 | 206 | /* Read Index, from where the state buffer should be read, is calculated. */ |
emilmont | 1:fdd22bb7aa52 | 207 | readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
emilmont | 1:fdd22bb7aa52 | 208 | |
emilmont | 1:fdd22bb7aa52 | 209 | /* Wraparound of readIndex */ |
emilmont | 1:fdd22bb7aa52 | 210 | if(readIndex < 0) |
emilmont | 1:fdd22bb7aa52 | 211 | { |
emilmont | 1:fdd22bb7aa52 | 212 | readIndex += (int32_t) delaySize; |
emilmont | 1:fdd22bb7aa52 | 213 | } |
emilmont | 1:fdd22bb7aa52 | 214 | |
emilmont | 1:fdd22bb7aa52 | 215 | /* Loop over the number of taps. */ |
emilmont | 1:fdd22bb7aa52 | 216 | tapCnt = (uint32_t) numTaps - 1u; |
emilmont | 1:fdd22bb7aa52 | 217 | |
emilmont | 1:fdd22bb7aa52 | 218 | while(tapCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 219 | { |
emilmont | 1:fdd22bb7aa52 | 220 | |
emilmont | 1:fdd22bb7aa52 | 221 | /* Working pointer for state buffer is updated */ |
emilmont | 1:fdd22bb7aa52 | 222 | py = pState; |
emilmont | 1:fdd22bb7aa52 | 223 | |
emilmont | 1:fdd22bb7aa52 | 224 | /* blockSize samples are read from the state buffer */ |
emilmont | 1:fdd22bb7aa52 | 225 | arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, |
emilmont | 1:fdd22bb7aa52 | 226 | (int32_t *) pb, (int32_t *) pb, blockSize, 1, |
emilmont | 1:fdd22bb7aa52 | 227 | blockSize); |
emilmont | 1:fdd22bb7aa52 | 228 | |
emilmont | 1:fdd22bb7aa52 | 229 | /* Working pointer for the scratch buffer */ |
emilmont | 1:fdd22bb7aa52 | 230 | px = pb; |
emilmont | 1:fdd22bb7aa52 | 231 | |
emilmont | 1:fdd22bb7aa52 | 232 | /* Working pointer for destination buffer */ |
emilmont | 1:fdd22bb7aa52 | 233 | pOut = pDst; |
emilmont | 1:fdd22bb7aa52 | 234 | |
emilmont | 1:fdd22bb7aa52 | 235 | /* Loop over the blockSize. Unroll by a factor of 4. |
emilmont | 1:fdd22bb7aa52 | 236 | * Compute 4 MACS at a time. */ |
emilmont | 1:fdd22bb7aa52 | 237 | blkCnt = blockSize >> 2u; |
emilmont | 1:fdd22bb7aa52 | 238 | |
emilmont | 1:fdd22bb7aa52 | 239 | while(blkCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 240 | { |
emilmont | 1:fdd22bb7aa52 | 241 | /* Perform Multiply-Accumulate */ |
emilmont | 1:fdd22bb7aa52 | 242 | *pOut++ += *px++ * coeff; |
emilmont | 1:fdd22bb7aa52 | 243 | *pOut++ += *px++ * coeff; |
emilmont | 1:fdd22bb7aa52 | 244 | *pOut++ += *px++ * coeff; |
emilmont | 1:fdd22bb7aa52 | 245 | *pOut++ += *px++ * coeff; |
emilmont | 1:fdd22bb7aa52 | 246 | |
emilmont | 1:fdd22bb7aa52 | 247 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 248 | blkCnt--; |
emilmont | 1:fdd22bb7aa52 | 249 | } |
emilmont | 1:fdd22bb7aa52 | 250 | |
emilmont | 1:fdd22bb7aa52 | 251 | /* If the blockSize is not a multiple of 4, |
emilmont | 1:fdd22bb7aa52 | 252 | * compute the remaining samples */ |
emilmont | 1:fdd22bb7aa52 | 253 | blkCnt = blockSize % 0x4u; |
emilmont | 1:fdd22bb7aa52 | 254 | |
emilmont | 1:fdd22bb7aa52 | 255 | while(blkCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 256 | { |
emilmont | 1:fdd22bb7aa52 | 257 | /* Perform Multiply-Accumulate */ |
emilmont | 1:fdd22bb7aa52 | 258 | *pOut++ += *px++ * coeff; |
emilmont | 1:fdd22bb7aa52 | 259 | |
emilmont | 1:fdd22bb7aa52 | 260 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 261 | blkCnt--; |
emilmont | 1:fdd22bb7aa52 | 262 | } |
emilmont | 1:fdd22bb7aa52 | 263 | |
emilmont | 1:fdd22bb7aa52 | 264 | /* Load the coefficient value and |
emilmont | 1:fdd22bb7aa52 | 265 | * increment the coefficient buffer for the next set of state values */ |
emilmont | 1:fdd22bb7aa52 | 266 | coeff = *pCoeffs++; |
emilmont | 1:fdd22bb7aa52 | 267 | |
emilmont | 1:fdd22bb7aa52 | 268 | /* Read Index, from where the state buffer should be read, is calculated. */ |
emilmont | 1:fdd22bb7aa52 | 269 | readIndex = ((int32_t) S->stateIndex - |
emilmont | 1:fdd22bb7aa52 | 270 | (int32_t) blockSize) - *pTapDelay++; |
emilmont | 1:fdd22bb7aa52 | 271 | |
emilmont | 1:fdd22bb7aa52 | 272 | /* Wraparound of readIndex */ |
emilmont | 1:fdd22bb7aa52 | 273 | if(readIndex < 0) |
emilmont | 1:fdd22bb7aa52 | 274 | { |
emilmont | 1:fdd22bb7aa52 | 275 | readIndex += (int32_t) delaySize; |
emilmont | 1:fdd22bb7aa52 | 276 | } |
emilmont | 1:fdd22bb7aa52 | 277 | |
emilmont | 1:fdd22bb7aa52 | 278 | /* Decrement the tap loop counter */ |
emilmont | 1:fdd22bb7aa52 | 279 | tapCnt--; |
emilmont | 1:fdd22bb7aa52 | 280 | } |
emilmont | 1:fdd22bb7aa52 | 281 | |
emilmont | 1:fdd22bb7aa52 | 282 | #else |
emilmont | 1:fdd22bb7aa52 | 283 | |
emilmont | 1:fdd22bb7aa52 | 284 | /* Run the below code for Cortex-M0 */ |
emilmont | 1:fdd22bb7aa52 | 285 | |
emilmont | 1:fdd22bb7aa52 | 286 | blkCnt = blockSize; |
emilmont | 1:fdd22bb7aa52 | 287 | |
emilmont | 1:fdd22bb7aa52 | 288 | while(blkCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 289 | { |
emilmont | 1:fdd22bb7aa52 | 290 | /* Perform Multiplications and store in destination buffer */ |
emilmont | 1:fdd22bb7aa52 | 291 | *pOut++ = *px++ * coeff; |
emilmont | 1:fdd22bb7aa52 | 292 | |
emilmont | 1:fdd22bb7aa52 | 293 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 294 | blkCnt--; |
emilmont | 1:fdd22bb7aa52 | 295 | } |
emilmont | 1:fdd22bb7aa52 | 296 | |
emilmont | 1:fdd22bb7aa52 | 297 | /* Load the coefficient value and |
emilmont | 1:fdd22bb7aa52 | 298 | * increment the coefficient buffer for the next set of state values */ |
emilmont | 1:fdd22bb7aa52 | 299 | coeff = *pCoeffs++; |
emilmont | 1:fdd22bb7aa52 | 300 | |
emilmont | 1:fdd22bb7aa52 | 301 | /* Read Index, from where the state buffer should be read, is calculated. */ |
emilmont | 1:fdd22bb7aa52 | 302 | readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
emilmont | 1:fdd22bb7aa52 | 303 | |
emilmont | 1:fdd22bb7aa52 | 304 | /* Wraparound of readIndex */ |
emilmont | 1:fdd22bb7aa52 | 305 | if(readIndex < 0) |
emilmont | 1:fdd22bb7aa52 | 306 | { |
emilmont | 1:fdd22bb7aa52 | 307 | readIndex += (int32_t) delaySize; |
emilmont | 1:fdd22bb7aa52 | 308 | } |
emilmont | 1:fdd22bb7aa52 | 309 | |
emilmont | 1:fdd22bb7aa52 | 310 | /* Loop over the number of taps. */ |
emilmont | 1:fdd22bb7aa52 | 311 | tapCnt = (uint32_t) numTaps - 1u; |
emilmont | 1:fdd22bb7aa52 | 312 | |
emilmont | 1:fdd22bb7aa52 | 313 | while(tapCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 314 | { |
emilmont | 1:fdd22bb7aa52 | 315 | |
emilmont | 1:fdd22bb7aa52 | 316 | /* Working pointer for state buffer is updated */ |
emilmont | 1:fdd22bb7aa52 | 317 | py = pState; |
emilmont | 1:fdd22bb7aa52 | 318 | |
emilmont | 1:fdd22bb7aa52 | 319 | /* blockSize samples are read from the state buffer */ |
emilmont | 1:fdd22bb7aa52 | 320 | arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, |
emilmont | 1:fdd22bb7aa52 | 321 | (int32_t *) pb, (int32_t *) pb, blockSize, 1, |
emilmont | 1:fdd22bb7aa52 | 322 | blockSize); |
emilmont | 1:fdd22bb7aa52 | 323 | |
emilmont | 1:fdd22bb7aa52 | 324 | /* Working pointer for the scratch buffer */ |
emilmont | 1:fdd22bb7aa52 | 325 | px = pb; |
emilmont | 1:fdd22bb7aa52 | 326 | |
emilmont | 1:fdd22bb7aa52 | 327 | /* Working pointer for destination buffer */ |
emilmont | 1:fdd22bb7aa52 | 328 | pOut = pDst; |
emilmont | 1:fdd22bb7aa52 | 329 | |
emilmont | 1:fdd22bb7aa52 | 330 | blkCnt = blockSize; |
emilmont | 1:fdd22bb7aa52 | 331 | |
emilmont | 1:fdd22bb7aa52 | 332 | while(blkCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 333 | { |
emilmont | 1:fdd22bb7aa52 | 334 | /* Perform Multiply-Accumulate */ |
emilmont | 1:fdd22bb7aa52 | 335 | *pOut++ += *px++ * coeff; |
emilmont | 1:fdd22bb7aa52 | 336 | |
emilmont | 1:fdd22bb7aa52 | 337 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 338 | blkCnt--; |
emilmont | 1:fdd22bb7aa52 | 339 | } |
emilmont | 1:fdd22bb7aa52 | 340 | |
emilmont | 1:fdd22bb7aa52 | 341 | /* Load the coefficient value and |
emilmont | 1:fdd22bb7aa52 | 342 | * increment the coefficient buffer for the next set of state values */ |
emilmont | 1:fdd22bb7aa52 | 343 | coeff = *pCoeffs++; |
emilmont | 1:fdd22bb7aa52 | 344 | |
emilmont | 1:fdd22bb7aa52 | 345 | /* Read Index, from where the state buffer should be read, is calculated. */ |
emilmont | 1:fdd22bb7aa52 | 346 | readIndex = |
emilmont | 1:fdd22bb7aa52 | 347 | ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
emilmont | 1:fdd22bb7aa52 | 348 | |
emilmont | 1:fdd22bb7aa52 | 349 | /* Wraparound of readIndex */ |
emilmont | 1:fdd22bb7aa52 | 350 | if(readIndex < 0) |
emilmont | 1:fdd22bb7aa52 | 351 | { |
emilmont | 1:fdd22bb7aa52 | 352 | readIndex += (int32_t) delaySize; |
emilmont | 1:fdd22bb7aa52 | 353 | } |
emilmont | 1:fdd22bb7aa52 | 354 | |
emilmont | 1:fdd22bb7aa52 | 355 | /* Decrement the tap loop counter */ |
emilmont | 1:fdd22bb7aa52 | 356 | tapCnt--; |
emilmont | 1:fdd22bb7aa52 | 357 | } |
emilmont | 1:fdd22bb7aa52 | 358 | |
emilmont | 1:fdd22bb7aa52 | 359 | #endif /* #ifndef ARM_MATH_CM0 */ |
emilmont | 1:fdd22bb7aa52 | 360 | |
emilmont | 1:fdd22bb7aa52 | 361 | } |
emilmont | 1:fdd22bb7aa52 | 362 | |
emilmont | 1:fdd22bb7aa52 | 363 | /** |
emilmont | 1:fdd22bb7aa52 | 364 | * @} end of FIR_Sparse group |
emilmont | 1:fdd22bb7aa52 | 365 | */ |