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_f32.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_f32.c |
| emh203 | 0:3d9c67d97d6f | 9 | * |
| emh203 | 0:3d9c67d97d6f | 10 | * Description: Floating-point 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 | * @ingroup groupFilters |
| emh203 | 0:3d9c67d97d6f | 44 | */ |
| emh203 | 0:3d9c67d97d6f | 45 | |
| emh203 | 0:3d9c67d97d6f | 46 | /** |
| emh203 | 0:3d9c67d97d6f | 47 | * @defgroup FIR_Sparse Finite Impulse Response (FIR) Sparse Filters |
| emh203 | 0:3d9c67d97d6f | 48 | * |
| emh203 | 0:3d9c67d97d6f | 49 | * This group of functions implements sparse FIR filters. |
| emh203 | 0:3d9c67d97d6f | 50 | * Sparse FIR filters are equivalent to standard FIR filters except that most of the coefficients are equal to zero. |
| emh203 | 0:3d9c67d97d6f | 51 | * Sparse filters are used for simulating reflections in communications and audio applications. |
| emh203 | 0:3d9c67d97d6f | 52 | * |
| emh203 | 0:3d9c67d97d6f | 53 | * There are separate functions for Q7, Q15, Q31, and floating-point data types. |
| emh203 | 0:3d9c67d97d6f | 54 | * The functions operate on blocks of input and output data and each call to the function processes |
| emh203 | 0:3d9c67d97d6f | 55 | * <code>blockSize</code> samples through the filter. <code>pSrc</code> and |
| emh203 | 0:3d9c67d97d6f | 56 | * <code>pDst</code> points to input and output arrays respectively containing <code>blockSize</code> values. |
| emh203 | 0:3d9c67d97d6f | 57 | * |
| emh203 | 0:3d9c67d97d6f | 58 | * \par Algorithm: |
| emh203 | 0:3d9c67d97d6f | 59 | * The sparse filter instant structure contains an array of tap indices <code>pTapDelay</code> which specifies the locations of the non-zero coefficients. |
| emh203 | 0:3d9c67d97d6f | 60 | * This is in addition to the coefficient array <code>b</code>. |
| emh203 | 0:3d9c67d97d6f | 61 | * The implementation essentially skips the multiplications by zero and leads to an efficient realization. |
| emh203 | 0:3d9c67d97d6f | 62 | * <pre> |
| emh203 | 0:3d9c67d97d6f | 63 | * 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]] |
| emh203 | 0:3d9c67d97d6f | 64 | * </pre> |
| emh203 | 0:3d9c67d97d6f | 65 | * \par |
| emh203 | 0:3d9c67d97d6f | 66 | * \image html FIRSparse.gif "Sparse FIR filter. b[n] represents the filter coefficients" |
| emh203 | 0:3d9c67d97d6f | 67 | * \par |
| emh203 | 0:3d9c67d97d6f | 68 | * <code>pCoeffs</code> points to a coefficient array of size <code>numTaps</code>; |
| emh203 | 0:3d9c67d97d6f | 69 | * <code>pTapDelay</code> points to an array of nonzero indices and is also of size <code>numTaps</code>; |
| emh203 | 0:3d9c67d97d6f | 70 | * <code>pState</code> points to a state array of size <code>maxDelay + blockSize</code>, where |
| emh203 | 0:3d9c67d97d6f | 71 | * <code>maxDelay</code> is the largest offset value that is ever used in the <code>pTapDelay</code> array. |
| emh203 | 0:3d9c67d97d6f | 72 | * Some of the processing functions also require temporary working buffers. |
| emh203 | 0:3d9c67d97d6f | 73 | * |
| emh203 | 0:3d9c67d97d6f | 74 | * \par Instance Structure |
| emh203 | 0:3d9c67d97d6f | 75 | * The coefficients and state variables for a filter are stored together in an instance data structure. |
| emh203 | 0:3d9c67d97d6f | 76 | * A separate instance structure must be defined for each filter. |
| emh203 | 0:3d9c67d97d6f | 77 | * Coefficient and offset arrays may be shared among several instances while state variable arrays cannot be shared. |
| emh203 | 0:3d9c67d97d6f | 78 | * There are separate instance structure declarations for each of the 4 supported data types. |
| emh203 | 0:3d9c67d97d6f | 79 | * |
| emh203 | 0:3d9c67d97d6f | 80 | * \par Initialization Functions |
| emh203 | 0:3d9c67d97d6f | 81 | * There is also an associated initialization function for each data type. |
| emh203 | 0:3d9c67d97d6f | 82 | * The initialization function performs the following operations: |
| emh203 | 0:3d9c67d97d6f | 83 | * - Sets the values of the internal structure fields. |
| emh203 | 0:3d9c67d97d6f | 84 | * - Zeros out the values in the state buffer. |
| emh203 | 0:3d9c67d97d6f | 85 | * To do this manually without calling the init function, assign the follow subfields of the instance structure: |
| emh203 | 0:3d9c67d97d6f | 86 | * numTaps, pCoeffs, pTapDelay, maxDelay, stateIndex, pState. Also set all of the values in pState to zero. |
| emh203 | 0:3d9c67d97d6f | 87 | * |
| emh203 | 0:3d9c67d97d6f | 88 | * \par |
| emh203 | 0:3d9c67d97d6f | 89 | * Use of the initialization function is optional. |
| emh203 | 0:3d9c67d97d6f | 90 | * However, if the initialization function is used, then the instance structure cannot be placed into a const data section. |
| emh203 | 0:3d9c67d97d6f | 91 | * To place an instance structure into a const data section, the instance structure must be manually initialized. |
| emh203 | 0:3d9c67d97d6f | 92 | * Set the values in the state buffer to zeros before static initialization. |
| emh203 | 0:3d9c67d97d6f | 93 | * The code below statically initializes each of the 4 different data type filter instance structures |
| emh203 | 0:3d9c67d97d6f | 94 | * <pre> |
| emh203 | 0:3d9c67d97d6f | 95 | *arm_fir_sparse_instance_f32 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay}; |
| emh203 | 0:3d9c67d97d6f | 96 | *arm_fir_sparse_instance_q31 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay}; |
| emh203 | 0:3d9c67d97d6f | 97 | *arm_fir_sparse_instance_q15 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay}; |
| emh203 | 0:3d9c67d97d6f | 98 | *arm_fir_sparse_instance_q7 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay}; |
| emh203 | 0:3d9c67d97d6f | 99 | * </pre> |
| emh203 | 0:3d9c67d97d6f | 100 | * \par |
| emh203 | 0:3d9c67d97d6f | 101 | * |
| emh203 | 0:3d9c67d97d6f | 102 | * \par Fixed-Point Behavior |
| emh203 | 0:3d9c67d97d6f | 103 | * Care must be taken when using the fixed-point versions of the sparse FIR filter functions. |
| emh203 | 0:3d9c67d97d6f | 104 | * In particular, the overflow and saturation behavior of the accumulator used in each function must be considered. |
| emh203 | 0:3d9c67d97d6f | 105 | * Refer to the function specific documentation below for usage guidelines. |
| emh203 | 0:3d9c67d97d6f | 106 | */ |
| emh203 | 0:3d9c67d97d6f | 107 | |
| emh203 | 0:3d9c67d97d6f | 108 | /** |
| emh203 | 0:3d9c67d97d6f | 109 | * @addtogroup FIR_Sparse |
| emh203 | 0:3d9c67d97d6f | 110 | * @{ |
| emh203 | 0:3d9c67d97d6f | 111 | */ |
| emh203 | 0:3d9c67d97d6f | 112 | |
| emh203 | 0:3d9c67d97d6f | 113 | /** |
| emh203 | 0:3d9c67d97d6f | 114 | * @brief Processing function for the floating-point sparse FIR filter. |
| emh203 | 0:3d9c67d97d6f | 115 | * @param[in] *S points to an instance of the floating-point sparse FIR structure. |
| emh203 | 0:3d9c67d97d6f | 116 | * @param[in] *pSrc points to the block of input data. |
| emh203 | 0:3d9c67d97d6f | 117 | * @param[out] *pDst points to the block of output data |
| emh203 | 0:3d9c67d97d6f | 118 | * @param[in] *pScratchIn points to a temporary buffer of size blockSize. |
| emh203 | 0:3d9c67d97d6f | 119 | * @param[in] blockSize number of input samples to process per call. |
| emh203 | 0:3d9c67d97d6f | 120 | * @return none. |
| emh203 | 0:3d9c67d97d6f | 121 | */ |
| emh203 | 0:3d9c67d97d6f | 122 | |
| emh203 | 0:3d9c67d97d6f | 123 | void arm_fir_sparse_f32( |
| emh203 | 0:3d9c67d97d6f | 124 | arm_fir_sparse_instance_f32 * S, |
| emh203 | 0:3d9c67d97d6f | 125 | float32_t * pSrc, |
| emh203 | 0:3d9c67d97d6f | 126 | float32_t * pDst, |
| emh203 | 0:3d9c67d97d6f | 127 | float32_t * pScratchIn, |
| emh203 | 0:3d9c67d97d6f | 128 | uint32_t blockSize) |
| emh203 | 0:3d9c67d97d6f | 129 | { |
| emh203 | 0:3d9c67d97d6f | 130 | |
| emh203 | 0:3d9c67d97d6f | 131 | float32_t *pState = S->pState; /* State pointer */ |
| emh203 | 0:3d9c67d97d6f | 132 | float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
| emh203 | 0:3d9c67d97d6f | 133 | float32_t *px; /* Scratch buffer pointer */ |
| emh203 | 0:3d9c67d97d6f | 134 | float32_t *py = pState; /* Temporary pointers for state buffer */ |
| emh203 | 0:3d9c67d97d6f | 135 | float32_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */ |
| emh203 | 0:3d9c67d97d6f | 136 | float32_t *pOut; /* Destination pointer */ |
| emh203 | 0:3d9c67d97d6f | 137 | int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */ |
| emh203 | 0:3d9c67d97d6f | 138 | uint32_t delaySize = S->maxDelay + blockSize; /* state length */ |
| emh203 | 0:3d9c67d97d6f | 139 | uint16_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ |
| emh203 | 0:3d9c67d97d6f | 140 | int32_t readIndex; /* Read index of the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 141 | uint32_t tapCnt, blkCnt; /* loop counters */ |
| emh203 | 0:3d9c67d97d6f | 142 | float32_t coeff = *pCoeffs++; /* Read the first coefficient value */ |
| emh203 | 0:3d9c67d97d6f | 143 | |
| emh203 | 0:3d9c67d97d6f | 144 | |
| emh203 | 0:3d9c67d97d6f | 145 | |
| emh203 | 0:3d9c67d97d6f | 146 | /* BlockSize of Input samples are copied into the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 147 | /* StateIndex points to the starting position to write in the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 148 | arm_circularWrite_f32((int32_t *) py, delaySize, &S->stateIndex, 1, |
| emh203 | 0:3d9c67d97d6f | 149 | (int32_t *) pSrc, 1, blockSize); |
| emh203 | 0:3d9c67d97d6f | 150 | |
| emh203 | 0:3d9c67d97d6f | 151 | |
| emh203 | 0:3d9c67d97d6f | 152 | /* Read Index, from where the state buffer should be read, is calculated. */ |
| emh203 | 0:3d9c67d97d6f | 153 | readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
| emh203 | 0:3d9c67d97d6f | 154 | |
| emh203 | 0:3d9c67d97d6f | 155 | /* Wraparound of readIndex */ |
| emh203 | 0:3d9c67d97d6f | 156 | if(readIndex < 0) |
| emh203 | 0:3d9c67d97d6f | 157 | { |
| emh203 | 0:3d9c67d97d6f | 158 | readIndex += (int32_t) delaySize; |
| emh203 | 0:3d9c67d97d6f | 159 | } |
| emh203 | 0:3d9c67d97d6f | 160 | |
| emh203 | 0:3d9c67d97d6f | 161 | /* Working pointer for state buffer is updated */ |
| emh203 | 0:3d9c67d97d6f | 162 | py = pState; |
| emh203 | 0:3d9c67d97d6f | 163 | |
| emh203 | 0:3d9c67d97d6f | 164 | /* blockSize samples are read from the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 165 | arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, |
| emh203 | 0:3d9c67d97d6f | 166 | (int32_t *) pb, (int32_t *) pb, blockSize, 1, |
| emh203 | 0:3d9c67d97d6f | 167 | blockSize); |
| emh203 | 0:3d9c67d97d6f | 168 | |
| emh203 | 0:3d9c67d97d6f | 169 | /* Working pointer for the scratch buffer */ |
| emh203 | 0:3d9c67d97d6f | 170 | px = pb; |
| emh203 | 0:3d9c67d97d6f | 171 | |
| emh203 | 0:3d9c67d97d6f | 172 | /* Working pointer for destination buffer */ |
| emh203 | 0:3d9c67d97d6f | 173 | pOut = pDst; |
| emh203 | 0:3d9c67d97d6f | 174 | |
| emh203 | 0:3d9c67d97d6f | 175 | |
| emh203 | 0:3d9c67d97d6f | 176 | #ifndef ARM_MATH_CM0_FAMILY |
| emh203 | 0:3d9c67d97d6f | 177 | |
| emh203 | 0:3d9c67d97d6f | 178 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
| emh203 | 0:3d9c67d97d6f | 179 | |
| emh203 | 0:3d9c67d97d6f | 180 | /* Loop over the blockSize. Unroll by a factor of 4. |
| emh203 | 0:3d9c67d97d6f | 181 | * Compute 4 Multiplications at a time. */ |
| emh203 | 0:3d9c67d97d6f | 182 | blkCnt = blockSize >> 2u; |
| emh203 | 0:3d9c67d97d6f | 183 | |
| emh203 | 0:3d9c67d97d6f | 184 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 185 | { |
| emh203 | 0:3d9c67d97d6f | 186 | /* Perform Multiplications and store in destination buffer */ |
| emh203 | 0:3d9c67d97d6f | 187 | *pOut++ = *px++ * coeff; |
| emh203 | 0:3d9c67d97d6f | 188 | *pOut++ = *px++ * coeff; |
| emh203 | 0:3d9c67d97d6f | 189 | *pOut++ = *px++ * coeff; |
| emh203 | 0:3d9c67d97d6f | 190 | *pOut++ = *px++ * coeff; |
| emh203 | 0:3d9c67d97d6f | 191 | |
| emh203 | 0:3d9c67d97d6f | 192 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 193 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 194 | } |
| emh203 | 0:3d9c67d97d6f | 195 | |
| emh203 | 0:3d9c67d97d6f | 196 | /* If the blockSize is not a multiple of 4, |
| emh203 | 0:3d9c67d97d6f | 197 | * compute the remaining samples */ |
| emh203 | 0:3d9c67d97d6f | 198 | blkCnt = blockSize % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 199 | |
| emh203 | 0:3d9c67d97d6f | 200 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 201 | { |
| emh203 | 0:3d9c67d97d6f | 202 | /* Perform Multiplications and store in destination buffer */ |
| emh203 | 0:3d9c67d97d6f | 203 | *pOut++ = *px++ * coeff; |
| emh203 | 0:3d9c67d97d6f | 204 | |
| emh203 | 0:3d9c67d97d6f | 205 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 206 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 207 | } |
| emh203 | 0:3d9c67d97d6f | 208 | |
| emh203 | 0:3d9c67d97d6f | 209 | /* Load the coefficient value and |
| emh203 | 0:3d9c67d97d6f | 210 | * increment the coefficient buffer for the next set of state values */ |
| emh203 | 0:3d9c67d97d6f | 211 | coeff = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 212 | |
| emh203 | 0:3d9c67d97d6f | 213 | /* Read Index, from where the state buffer should be read, is calculated. */ |
| emh203 | 0:3d9c67d97d6f | 214 | readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
| emh203 | 0:3d9c67d97d6f | 215 | |
| emh203 | 0:3d9c67d97d6f | 216 | /* Wraparound of readIndex */ |
| emh203 | 0:3d9c67d97d6f | 217 | if(readIndex < 0) |
| emh203 | 0:3d9c67d97d6f | 218 | { |
| emh203 | 0:3d9c67d97d6f | 219 | readIndex += (int32_t) delaySize; |
| emh203 | 0:3d9c67d97d6f | 220 | } |
| emh203 | 0:3d9c67d97d6f | 221 | |
| emh203 | 0:3d9c67d97d6f | 222 | /* Loop over the number of taps. */ |
| emh203 | 0:3d9c67d97d6f | 223 | tapCnt = (uint32_t) numTaps - 1u; |
| emh203 | 0:3d9c67d97d6f | 224 | |
| emh203 | 0:3d9c67d97d6f | 225 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 226 | { |
| emh203 | 0:3d9c67d97d6f | 227 | |
| emh203 | 0:3d9c67d97d6f | 228 | /* Working pointer for state buffer is updated */ |
| emh203 | 0:3d9c67d97d6f | 229 | py = pState; |
| emh203 | 0:3d9c67d97d6f | 230 | |
| emh203 | 0:3d9c67d97d6f | 231 | /* blockSize samples are read from the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 232 | arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, |
| emh203 | 0:3d9c67d97d6f | 233 | (int32_t *) pb, (int32_t *) pb, blockSize, 1, |
| emh203 | 0:3d9c67d97d6f | 234 | blockSize); |
| emh203 | 0:3d9c67d97d6f | 235 | |
| emh203 | 0:3d9c67d97d6f | 236 | /* Working pointer for the scratch buffer */ |
| emh203 | 0:3d9c67d97d6f | 237 | px = pb; |
| emh203 | 0:3d9c67d97d6f | 238 | |
| emh203 | 0:3d9c67d97d6f | 239 | /* Working pointer for destination buffer */ |
| emh203 | 0:3d9c67d97d6f | 240 | pOut = pDst; |
| emh203 | 0:3d9c67d97d6f | 241 | |
| emh203 | 0:3d9c67d97d6f | 242 | /* Loop over the blockSize. Unroll by a factor of 4. |
| emh203 | 0:3d9c67d97d6f | 243 | * Compute 4 MACS at a time. */ |
| emh203 | 0:3d9c67d97d6f | 244 | blkCnt = blockSize >> 2u; |
| emh203 | 0:3d9c67d97d6f | 245 | |
| emh203 | 0:3d9c67d97d6f | 246 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 247 | { |
| emh203 | 0:3d9c67d97d6f | 248 | /* Perform Multiply-Accumulate */ |
| emh203 | 0:3d9c67d97d6f | 249 | *pOut++ += *px++ * coeff; |
| emh203 | 0:3d9c67d97d6f | 250 | *pOut++ += *px++ * coeff; |
| emh203 | 0:3d9c67d97d6f | 251 | *pOut++ += *px++ * coeff; |
| emh203 | 0:3d9c67d97d6f | 252 | *pOut++ += *px++ * coeff; |
| emh203 | 0:3d9c67d97d6f | 253 | |
| emh203 | 0:3d9c67d97d6f | 254 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 255 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 256 | } |
| emh203 | 0:3d9c67d97d6f | 257 | |
| emh203 | 0:3d9c67d97d6f | 258 | /* If the blockSize is not a multiple of 4, |
| emh203 | 0:3d9c67d97d6f | 259 | * compute the remaining samples */ |
| emh203 | 0:3d9c67d97d6f | 260 | blkCnt = blockSize % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 261 | |
| emh203 | 0:3d9c67d97d6f | 262 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 263 | { |
| emh203 | 0:3d9c67d97d6f | 264 | /* Perform Multiply-Accumulate */ |
| emh203 | 0:3d9c67d97d6f | 265 | *pOut++ += *px++ * coeff; |
| emh203 | 0:3d9c67d97d6f | 266 | |
| emh203 | 0:3d9c67d97d6f | 267 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 268 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 269 | } |
| emh203 | 0:3d9c67d97d6f | 270 | |
| emh203 | 0:3d9c67d97d6f | 271 | /* Load the coefficient value and |
| emh203 | 0:3d9c67d97d6f | 272 | * increment the coefficient buffer for the next set of state values */ |
| emh203 | 0:3d9c67d97d6f | 273 | coeff = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 274 | |
| emh203 | 0:3d9c67d97d6f | 275 | /* Read Index, from where the state buffer should be read, is calculated. */ |
| emh203 | 0:3d9c67d97d6f | 276 | readIndex = ((int32_t) S->stateIndex - |
| emh203 | 0:3d9c67d97d6f | 277 | (int32_t) blockSize) - *pTapDelay++; |
| emh203 | 0:3d9c67d97d6f | 278 | |
| emh203 | 0:3d9c67d97d6f | 279 | /* Wraparound of readIndex */ |
| emh203 | 0:3d9c67d97d6f | 280 | if(readIndex < 0) |
| emh203 | 0:3d9c67d97d6f | 281 | { |
| emh203 | 0:3d9c67d97d6f | 282 | readIndex += (int32_t) delaySize; |
| emh203 | 0:3d9c67d97d6f | 283 | } |
| emh203 | 0:3d9c67d97d6f | 284 | |
| emh203 | 0:3d9c67d97d6f | 285 | /* Decrement the tap loop counter */ |
| emh203 | 0:3d9c67d97d6f | 286 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 287 | } |
| emh203 | 0:3d9c67d97d6f | 288 | |
| emh203 | 0:3d9c67d97d6f | 289 | #else |
| emh203 | 0:3d9c67d97d6f | 290 | |
| emh203 | 0:3d9c67d97d6f | 291 | /* Run the below code for Cortex-M0 */ |
| emh203 | 0:3d9c67d97d6f | 292 | |
| emh203 | 0:3d9c67d97d6f | 293 | blkCnt = blockSize; |
| emh203 | 0:3d9c67d97d6f | 294 | |
| emh203 | 0:3d9c67d97d6f | 295 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 296 | { |
| emh203 | 0:3d9c67d97d6f | 297 | /* Perform Multiplications and store in destination buffer */ |
| emh203 | 0:3d9c67d97d6f | 298 | *pOut++ = *px++ * coeff; |
| emh203 | 0:3d9c67d97d6f | 299 | |
| emh203 | 0:3d9c67d97d6f | 300 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 301 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 302 | } |
| emh203 | 0:3d9c67d97d6f | 303 | |
| emh203 | 0:3d9c67d97d6f | 304 | /* Load the coefficient value and |
| emh203 | 0:3d9c67d97d6f | 305 | * increment the coefficient buffer for the next set of state values */ |
| emh203 | 0:3d9c67d97d6f | 306 | coeff = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 307 | |
| emh203 | 0:3d9c67d97d6f | 308 | /* Read Index, from where the state buffer should be read, is calculated. */ |
| emh203 | 0:3d9c67d97d6f | 309 | readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
| emh203 | 0:3d9c67d97d6f | 310 | |
| emh203 | 0:3d9c67d97d6f | 311 | /* Wraparound of readIndex */ |
| emh203 | 0:3d9c67d97d6f | 312 | if(readIndex < 0) |
| emh203 | 0:3d9c67d97d6f | 313 | { |
| emh203 | 0:3d9c67d97d6f | 314 | readIndex += (int32_t) delaySize; |
| emh203 | 0:3d9c67d97d6f | 315 | } |
| emh203 | 0:3d9c67d97d6f | 316 | |
| emh203 | 0:3d9c67d97d6f | 317 | /* Loop over the number of taps. */ |
| emh203 | 0:3d9c67d97d6f | 318 | tapCnt = (uint32_t) numTaps - 1u; |
| emh203 | 0:3d9c67d97d6f | 319 | |
| emh203 | 0:3d9c67d97d6f | 320 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 321 | { |
| emh203 | 0:3d9c67d97d6f | 322 | |
| emh203 | 0:3d9c67d97d6f | 323 | /* Working pointer for state buffer is updated */ |
| emh203 | 0:3d9c67d97d6f | 324 | py = pState; |
| emh203 | 0:3d9c67d97d6f | 325 | |
| emh203 | 0:3d9c67d97d6f | 326 | /* blockSize samples are read from the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 327 | arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, |
| emh203 | 0:3d9c67d97d6f | 328 | (int32_t *) pb, (int32_t *) pb, blockSize, 1, |
| emh203 | 0:3d9c67d97d6f | 329 | blockSize); |
| emh203 | 0:3d9c67d97d6f | 330 | |
| emh203 | 0:3d9c67d97d6f | 331 | /* Working pointer for the scratch buffer */ |
| emh203 | 0:3d9c67d97d6f | 332 | px = pb; |
| emh203 | 0:3d9c67d97d6f | 333 | |
| emh203 | 0:3d9c67d97d6f | 334 | /* Working pointer for destination buffer */ |
| emh203 | 0:3d9c67d97d6f | 335 | pOut = pDst; |
| emh203 | 0:3d9c67d97d6f | 336 | |
| emh203 | 0:3d9c67d97d6f | 337 | blkCnt = blockSize; |
| emh203 | 0:3d9c67d97d6f | 338 | |
| emh203 | 0:3d9c67d97d6f | 339 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 340 | { |
| emh203 | 0:3d9c67d97d6f | 341 | /* Perform Multiply-Accumulate */ |
| emh203 | 0:3d9c67d97d6f | 342 | *pOut++ += *px++ * coeff; |
| emh203 | 0:3d9c67d97d6f | 343 | |
| emh203 | 0:3d9c67d97d6f | 344 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 345 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 346 | } |
| emh203 | 0:3d9c67d97d6f | 347 | |
| emh203 | 0:3d9c67d97d6f | 348 | /* Load the coefficient value and |
| emh203 | 0:3d9c67d97d6f | 349 | * increment the coefficient buffer for the next set of state values */ |
| emh203 | 0:3d9c67d97d6f | 350 | coeff = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 351 | |
| emh203 | 0:3d9c67d97d6f | 352 | /* Read Index, from where the state buffer should be read, is calculated. */ |
| emh203 | 0:3d9c67d97d6f | 353 | readIndex = |
| emh203 | 0:3d9c67d97d6f | 354 | ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; |
| emh203 | 0:3d9c67d97d6f | 355 | |
| emh203 | 0:3d9c67d97d6f | 356 | /* Wraparound of readIndex */ |
| emh203 | 0:3d9c67d97d6f | 357 | if(readIndex < 0) |
| emh203 | 0:3d9c67d97d6f | 358 | { |
| emh203 | 0:3d9c67d97d6f | 359 | readIndex += (int32_t) delaySize; |
| emh203 | 0:3d9c67d97d6f | 360 | } |
| emh203 | 0:3d9c67d97d6f | 361 | |
| emh203 | 0:3d9c67d97d6f | 362 | /* Decrement the tap loop counter */ |
| emh203 | 0:3d9c67d97d6f | 363 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 364 | } |
| emh203 | 0:3d9c67d97d6f | 365 | |
| emh203 | 0:3d9c67d97d6f | 366 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
| emh203 | 0:3d9c67d97d6f | 367 | |
| emh203 | 0:3d9c67d97d6f | 368 | } |
| emh203 | 0:3d9c67d97d6f | 369 | |
| emh203 | 0:3d9c67d97d6f | 370 | /** |
| emh203 | 0:3d9c67d97d6f | 371 | * @} end of FIR_Sparse group |
| emh203 | 0:3d9c67d97d6f | 372 | */ |
Eli Hughes