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_interpolate_f32.c@5:3762170b6d4d, 2015-11-20 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Nov 20 08:45:18 2015 +0000
- Revision:
- 5:3762170b6d4d
- Parent:
- 3:7a284390b0ce
Synchronized with git revision 2eb940b9a73af188d3004a2575fdfbb05febe62b
Full URL: https://github.com/mbedmicro/mbed/commit/2eb940b9a73af188d3004a2575fdfbb05febe62b/
Added option to build rpc library. closes #1426
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:fdd22bb7aa52 | 1 | /* ---------------------------------------------------------------------- |
mbed_official | 5:3762170b6d4d | 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. |
emilmont | 1:fdd22bb7aa52 | 3 | * |
mbed_official | 5:3762170b6d4d | 4 | * $Date: 19. March 2015 |
mbed_official | 5:3762170b6d4d | 5 | * $Revision: V.1.4.5 |
emilmont | 1:fdd22bb7aa52 | 6 | * |
emilmont | 2:da51fb522205 | 7 | * Project: CMSIS DSP Library |
emilmont | 2:da51fb522205 | 8 | * Title: arm_fir_interpolate_f32.c |
emilmont | 1:fdd22bb7aa52 | 9 | * |
emilmont | 2:da51fb522205 | 10 | * Description: FIR interpolation for floating-point sequences. |
emilmont | 1:fdd22bb7aa52 | 11 | * |
emilmont | 1:fdd22bb7aa52 | 12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 |
emilmont | 1:fdd22bb7aa52 | 13 | * |
mbed_official | 3:7a284390b0ce | 14 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 3:7a284390b0ce | 15 | * modification, are permitted provided that the following conditions |
mbed_official | 3:7a284390b0ce | 16 | * are met: |
mbed_official | 3:7a284390b0ce | 17 | * - Redistributions of source code must retain the above copyright |
mbed_official | 3:7a284390b0ce | 18 | * notice, this list of conditions and the following disclaimer. |
mbed_official | 3:7a284390b0ce | 19 | * - Redistributions in binary form must reproduce the above copyright |
mbed_official | 3:7a284390b0ce | 20 | * notice, this list of conditions and the following disclaimer in |
mbed_official | 3:7a284390b0ce | 21 | * the documentation and/or other materials provided with the |
mbed_official | 3:7a284390b0ce | 22 | * distribution. |
mbed_official | 3:7a284390b0ce | 23 | * - Neither the name of ARM LIMITED nor the names of its contributors |
mbed_official | 3:7a284390b0ce | 24 | * may be used to endorse or promote products derived from this |
mbed_official | 3:7a284390b0ce | 25 | * software without specific prior written permission. |
mbed_official | 3:7a284390b0ce | 26 | * |
mbed_official | 3:7a284390b0ce | 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
mbed_official | 3:7a284390b0ce | 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
mbed_official | 3:7a284390b0ce | 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
mbed_official | 3:7a284390b0ce | 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
mbed_official | 3:7a284390b0ce | 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
mbed_official | 3:7a284390b0ce | 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
mbed_official | 3:7a284390b0ce | 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
mbed_official | 3:7a284390b0ce | 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 3:7a284390b0ce | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
mbed_official | 3:7a284390b0ce | 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
mbed_official | 3:7a284390b0ce | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
mbed_official | 3:7a284390b0ce | 38 | * POSSIBILITY OF SUCH DAMAGE. |
emilmont | 1:fdd22bb7aa52 | 39 | * -------------------------------------------------------------------- */ |
emilmont | 1:fdd22bb7aa52 | 40 | |
emilmont | 1:fdd22bb7aa52 | 41 | #include "arm_math.h" |
emilmont | 1:fdd22bb7aa52 | 42 | |
emilmont | 1:fdd22bb7aa52 | 43 | /** |
emilmont | 1:fdd22bb7aa52 | 44 | * @defgroup FIR_Interpolate Finite Impulse Response (FIR) Interpolator |
emilmont | 1:fdd22bb7aa52 | 45 | * |
emilmont | 1:fdd22bb7aa52 | 46 | * These functions combine an upsampler (zero stuffer) and an FIR filter. |
emilmont | 1:fdd22bb7aa52 | 47 | * They are used in multirate systems for increasing the sample rate of a signal without introducing high frequency images. |
emilmont | 1:fdd22bb7aa52 | 48 | * Conceptually, the functions are equivalent to the block diagram below: |
emilmont | 1:fdd22bb7aa52 | 49 | * \image html FIRInterpolator.gif "Components included in the FIR Interpolator functions" |
emilmont | 1:fdd22bb7aa52 | 50 | * After upsampling by a factor of <code>L</code>, the signal should be filtered by a lowpass filter with a normalized |
emilmont | 1:fdd22bb7aa52 | 51 | * cutoff frequency of <code>1/L</code> in order to eliminate high frequency copies of the spectrum. |
emilmont | 1:fdd22bb7aa52 | 52 | * The user of the function is responsible for providing the filter coefficients. |
emilmont | 1:fdd22bb7aa52 | 53 | * |
emilmont | 1:fdd22bb7aa52 | 54 | * The FIR interpolator functions provided in the CMSIS DSP Library combine the upsampler and FIR filter in an efficient manner. |
emilmont | 1:fdd22bb7aa52 | 55 | * The upsampler inserts <code>L-1</code> zeros between each sample. |
emilmont | 1:fdd22bb7aa52 | 56 | * Instead of multiplying by these zero values, the FIR filter is designed to skip them. |
emilmont | 1:fdd22bb7aa52 | 57 | * This leads to an efficient implementation without any wasted effort. |
emilmont | 1:fdd22bb7aa52 | 58 | * The functions operate on blocks of input and output data. |
emilmont | 1:fdd22bb7aa52 | 59 | * <code>pSrc</code> points to an array of <code>blockSize</code> input values and |
emilmont | 1:fdd22bb7aa52 | 60 | * <code>pDst</code> points to an array of <code>blockSize*L</code> output values. |
emilmont | 1:fdd22bb7aa52 | 61 | * |
emilmont | 1:fdd22bb7aa52 | 62 | * The library provides separate functions for Q15, Q31, and floating-point data types. |
emilmont | 1:fdd22bb7aa52 | 63 | * |
emilmont | 1:fdd22bb7aa52 | 64 | * \par Algorithm: |
emilmont | 1:fdd22bb7aa52 | 65 | * The functions use a polyphase filter structure: |
emilmont | 1:fdd22bb7aa52 | 66 | * <pre> |
emilmont | 1:fdd22bb7aa52 | 67 | * y[n] = b[0] * x[n] + b[L] * x[n-1] + ... + b[L*(phaseLength-1)] * x[n-phaseLength+1] |
emilmont | 1:fdd22bb7aa52 | 68 | * y[n+1] = b[1] * x[n] + b[L+1] * x[n-1] + ... + b[L*(phaseLength-1)+1] * x[n-phaseLength+1] |
emilmont | 1:fdd22bb7aa52 | 69 | * ... |
emilmont | 1:fdd22bb7aa52 | 70 | * y[n+(L-1)] = b[L-1] * x[n] + b[2*L-1] * x[n-1] + ....+ b[L*(phaseLength-1)+(L-1)] * x[n-phaseLength+1] |
emilmont | 1:fdd22bb7aa52 | 71 | * </pre> |
emilmont | 1:fdd22bb7aa52 | 72 | * This approach is more efficient than straightforward upsample-then-filter algorithms. |
emilmont | 1:fdd22bb7aa52 | 73 | * With this method the computation is reduced by a factor of <code>1/L</code> when compared to using a standard FIR filter. |
emilmont | 1:fdd22bb7aa52 | 74 | * \par |
emilmont | 1:fdd22bb7aa52 | 75 | * <code>pCoeffs</code> points to a coefficient array of size <code>numTaps</code>. |
emilmont | 1:fdd22bb7aa52 | 76 | * <code>numTaps</code> must be a multiple of the interpolation factor <code>L</code> and this is checked by the |
emilmont | 1:fdd22bb7aa52 | 77 | * initialization functions. |
emilmont | 1:fdd22bb7aa52 | 78 | * Internally, the function divides the FIR filter's impulse response into shorter filters of length |
emilmont | 1:fdd22bb7aa52 | 79 | * <code>phaseLength=numTaps/L</code>. |
emilmont | 1:fdd22bb7aa52 | 80 | * Coefficients are stored in time reversed order. |
emilmont | 1:fdd22bb7aa52 | 81 | * \par |
emilmont | 1:fdd22bb7aa52 | 82 | * <pre> |
emilmont | 1:fdd22bb7aa52 | 83 | * {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} |
emilmont | 1:fdd22bb7aa52 | 84 | * </pre> |
emilmont | 1:fdd22bb7aa52 | 85 | * \par |
emilmont | 1:fdd22bb7aa52 | 86 | * <code>pState</code> points to a state array of size <code>blockSize + phaseLength - 1</code>. |
emilmont | 1:fdd22bb7aa52 | 87 | * Samples in the state buffer are stored in the order: |
emilmont | 1:fdd22bb7aa52 | 88 | * \par |
emilmont | 1:fdd22bb7aa52 | 89 | * <pre> |
emilmont | 1:fdd22bb7aa52 | 90 | * {x[n-phaseLength+1], x[n-phaseLength], x[n-phaseLength-1], x[n-phaseLength-2]....x[0], x[1], ..., x[blockSize-1]} |
emilmont | 1:fdd22bb7aa52 | 91 | * </pre> |
emilmont | 1:fdd22bb7aa52 | 92 | * The state variables are updated after each block of data is processed, the coefficients are untouched. |
emilmont | 1:fdd22bb7aa52 | 93 | * |
emilmont | 1:fdd22bb7aa52 | 94 | * \par Instance Structure |
emilmont | 1:fdd22bb7aa52 | 95 | * The coefficients and state variables for a filter are stored together in an instance data structure. |
emilmont | 1:fdd22bb7aa52 | 96 | * A separate instance structure must be defined for each filter. |
emilmont | 1:fdd22bb7aa52 | 97 | * Coefficient arrays may be shared among several instances while state variable array should be allocated separately. |
emilmont | 1:fdd22bb7aa52 | 98 | * There are separate instance structure declarations for each of the 3 supported data types. |
emilmont | 1:fdd22bb7aa52 | 99 | * |
emilmont | 1:fdd22bb7aa52 | 100 | * \par Initialization Functions |
emilmont | 1:fdd22bb7aa52 | 101 | * There is also an associated initialization function for each data type. |
emilmont | 1:fdd22bb7aa52 | 102 | * The initialization function performs the following operations: |
emilmont | 1:fdd22bb7aa52 | 103 | * - Sets the values of the internal structure fields. |
emilmont | 1:fdd22bb7aa52 | 104 | * - Zeros out the values in the state buffer. |
emilmont | 1:fdd22bb7aa52 | 105 | * - Checks to make sure that the length of the filter is a multiple of the interpolation factor. |
mbed_official | 3:7a284390b0ce | 106 | * To do this manually without calling the init function, assign the follow subfields of the instance structure: |
mbed_official | 3:7a284390b0ce | 107 | * L (interpolation factor), pCoeffs, phaseLength (numTaps / L), pState. Also set all of the values in pState to zero. |
emilmont | 1:fdd22bb7aa52 | 108 | * |
emilmont | 1:fdd22bb7aa52 | 109 | * \par |
emilmont | 1:fdd22bb7aa52 | 110 | * Use of the initialization function is optional. |
emilmont | 1:fdd22bb7aa52 | 111 | * However, if the initialization function is used, then the instance structure cannot be placed into a const data section. |
emilmont | 1:fdd22bb7aa52 | 112 | * To place an instance structure into a const data section, the instance structure must be manually initialized. |
emilmont | 1:fdd22bb7aa52 | 113 | * The code below statically initializes each of the 3 different data type filter instance structures |
emilmont | 1:fdd22bb7aa52 | 114 | * <pre> |
emilmont | 1:fdd22bb7aa52 | 115 | * arm_fir_interpolate_instance_f32 S = {L, phaseLength, pCoeffs, pState}; |
emilmont | 1:fdd22bb7aa52 | 116 | * arm_fir_interpolate_instance_q31 S = {L, phaseLength, pCoeffs, pState}; |
emilmont | 1:fdd22bb7aa52 | 117 | * arm_fir_interpolate_instance_q15 S = {L, phaseLength, pCoeffs, pState}; |
emilmont | 1:fdd22bb7aa52 | 118 | * </pre> |
emilmont | 1:fdd22bb7aa52 | 119 | * where <code>L</code> is the interpolation factor; <code>phaseLength=numTaps/L</code> is the |
emilmont | 1:fdd22bb7aa52 | 120 | * length of each of the shorter FIR filters used internally, |
emilmont | 1:fdd22bb7aa52 | 121 | * <code>pCoeffs</code> is the address of the coefficient buffer; |
emilmont | 1:fdd22bb7aa52 | 122 | * <code>pState</code> is the address of the state buffer. |
emilmont | 1:fdd22bb7aa52 | 123 | * Be sure to set the values in the state buffer to zeros when doing static initialization. |
emilmont | 1:fdd22bb7aa52 | 124 | * |
emilmont | 1:fdd22bb7aa52 | 125 | * \par Fixed-Point Behavior |
emilmont | 1:fdd22bb7aa52 | 126 | * Care must be taken when using the fixed-point versions of the FIR interpolate filter functions. |
emilmont | 1:fdd22bb7aa52 | 127 | * In particular, the overflow and saturation behavior of the accumulator used in each function must be considered. |
emilmont | 1:fdd22bb7aa52 | 128 | * Refer to the function specific documentation below for usage guidelines. |
emilmont | 1:fdd22bb7aa52 | 129 | */ |
emilmont | 1:fdd22bb7aa52 | 130 | |
emilmont | 1:fdd22bb7aa52 | 131 | /** |
emilmont | 1:fdd22bb7aa52 | 132 | * @addtogroup FIR_Interpolate |
emilmont | 1:fdd22bb7aa52 | 133 | * @{ |
emilmont | 1:fdd22bb7aa52 | 134 | */ |
emilmont | 1:fdd22bb7aa52 | 135 | |
emilmont | 1:fdd22bb7aa52 | 136 | /** |
emilmont | 1:fdd22bb7aa52 | 137 | * @brief Processing function for the floating-point FIR interpolator. |
emilmont | 1:fdd22bb7aa52 | 138 | * @param[in] *S points to an instance of the floating-point FIR interpolator structure. |
emilmont | 1:fdd22bb7aa52 | 139 | * @param[in] *pSrc points to the block of input data. |
emilmont | 1:fdd22bb7aa52 | 140 | * @param[out] *pDst points to the block of output data. |
emilmont | 1:fdd22bb7aa52 | 141 | * @param[in] blockSize number of input samples to process per call. |
emilmont | 1:fdd22bb7aa52 | 142 | * @return none. |
emilmont | 1:fdd22bb7aa52 | 143 | */ |
mbed_official | 3:7a284390b0ce | 144 | #ifndef ARM_MATH_CM0_FAMILY |
emilmont | 1:fdd22bb7aa52 | 145 | |
emilmont | 1:fdd22bb7aa52 | 146 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emilmont | 1:fdd22bb7aa52 | 147 | |
emilmont | 1:fdd22bb7aa52 | 148 | void arm_fir_interpolate_f32( |
emilmont | 1:fdd22bb7aa52 | 149 | const arm_fir_interpolate_instance_f32 * S, |
emilmont | 1:fdd22bb7aa52 | 150 | float32_t * pSrc, |
emilmont | 1:fdd22bb7aa52 | 151 | float32_t * pDst, |
emilmont | 1:fdd22bb7aa52 | 152 | uint32_t blockSize) |
emilmont | 1:fdd22bb7aa52 | 153 | { |
emilmont | 1:fdd22bb7aa52 | 154 | float32_t *pState = S->pState; /* State pointer */ |
emilmont | 1:fdd22bb7aa52 | 155 | float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
emilmont | 1:fdd22bb7aa52 | 156 | float32_t *pStateCurnt; /* Points to the current sample of the state */ |
emilmont | 1:fdd22bb7aa52 | 157 | float32_t *ptr1, *ptr2; /* Temporary pointers for state and coefficient buffers */ |
emilmont | 1:fdd22bb7aa52 | 158 | float32_t sum0; /* Accumulators */ |
emilmont | 1:fdd22bb7aa52 | 159 | float32_t x0, c0; /* Temporary variables to hold state and coefficient values */ |
emilmont | 1:fdd22bb7aa52 | 160 | uint32_t i, blkCnt, j; /* Loop counters */ |
emilmont | 1:fdd22bb7aa52 | 161 | uint16_t phaseLen = S->phaseLength, tapCnt; /* Length of each polyphase filter component */ |
emilmont | 1:fdd22bb7aa52 | 162 | float32_t acc0, acc1, acc2, acc3; |
emilmont | 1:fdd22bb7aa52 | 163 | float32_t x1, x2, x3; |
emilmont | 1:fdd22bb7aa52 | 164 | uint32_t blkCntN4; |
emilmont | 1:fdd22bb7aa52 | 165 | float32_t c1, c2, c3; |
emilmont | 1:fdd22bb7aa52 | 166 | |
emilmont | 1:fdd22bb7aa52 | 167 | /* S->pState buffer contains previous frame (phaseLen - 1) samples */ |
emilmont | 1:fdd22bb7aa52 | 168 | /* pStateCurnt points to the location where the new input data should be written */ |
emilmont | 1:fdd22bb7aa52 | 169 | pStateCurnt = S->pState + (phaseLen - 1u); |
emilmont | 1:fdd22bb7aa52 | 170 | |
emilmont | 1:fdd22bb7aa52 | 171 | /* Initialise blkCnt */ |
emilmont | 1:fdd22bb7aa52 | 172 | blkCnt = blockSize / 4; |
emilmont | 1:fdd22bb7aa52 | 173 | blkCntN4 = blockSize - (4 * blkCnt); |
emilmont | 1:fdd22bb7aa52 | 174 | |
emilmont | 1:fdd22bb7aa52 | 175 | /* Samples loop unrolled by 4 */ |
emilmont | 1:fdd22bb7aa52 | 176 | while(blkCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 177 | { |
emilmont | 1:fdd22bb7aa52 | 178 | /* Copy new input sample into the state buffer */ |
emilmont | 1:fdd22bb7aa52 | 179 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 180 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 181 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 182 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 183 | |
emilmont | 1:fdd22bb7aa52 | 184 | /* Address modifier index of coefficient buffer */ |
emilmont | 1:fdd22bb7aa52 | 185 | j = 1u; |
emilmont | 1:fdd22bb7aa52 | 186 | |
emilmont | 1:fdd22bb7aa52 | 187 | /* Loop over the Interpolation factor. */ |
emilmont | 1:fdd22bb7aa52 | 188 | i = (S->L); |
emilmont | 1:fdd22bb7aa52 | 189 | |
emilmont | 1:fdd22bb7aa52 | 190 | while(i > 0u) |
emilmont | 1:fdd22bb7aa52 | 191 | { |
emilmont | 1:fdd22bb7aa52 | 192 | /* Set accumulator to zero */ |
emilmont | 1:fdd22bb7aa52 | 193 | acc0 = 0.0f; |
emilmont | 1:fdd22bb7aa52 | 194 | acc1 = 0.0f; |
emilmont | 1:fdd22bb7aa52 | 195 | acc2 = 0.0f; |
emilmont | 1:fdd22bb7aa52 | 196 | acc3 = 0.0f; |
emilmont | 1:fdd22bb7aa52 | 197 | |
emilmont | 1:fdd22bb7aa52 | 198 | /* Initialize state pointer */ |
emilmont | 1:fdd22bb7aa52 | 199 | ptr1 = pState; |
emilmont | 1:fdd22bb7aa52 | 200 | |
emilmont | 1:fdd22bb7aa52 | 201 | /* Initialize coefficient pointer */ |
emilmont | 1:fdd22bb7aa52 | 202 | ptr2 = pCoeffs + (S->L - j); |
emilmont | 1:fdd22bb7aa52 | 203 | |
emilmont | 1:fdd22bb7aa52 | 204 | /* Loop over the polyPhase length. Unroll by a factor of 4. |
emilmont | 1:fdd22bb7aa52 | 205 | ** Repeat until we've computed numTaps-(4*S->L) coefficients. */ |
emilmont | 1:fdd22bb7aa52 | 206 | tapCnt = phaseLen >> 2u; |
emilmont | 1:fdd22bb7aa52 | 207 | |
emilmont | 1:fdd22bb7aa52 | 208 | x0 = *(ptr1++); |
emilmont | 1:fdd22bb7aa52 | 209 | x1 = *(ptr1++); |
emilmont | 1:fdd22bb7aa52 | 210 | x2 = *(ptr1++); |
emilmont | 1:fdd22bb7aa52 | 211 | |
emilmont | 1:fdd22bb7aa52 | 212 | while(tapCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 213 | { |
emilmont | 1:fdd22bb7aa52 | 214 | |
emilmont | 1:fdd22bb7aa52 | 215 | /* Read the input sample */ |
emilmont | 1:fdd22bb7aa52 | 216 | x3 = *(ptr1++); |
emilmont | 1:fdd22bb7aa52 | 217 | |
emilmont | 1:fdd22bb7aa52 | 218 | /* Read the coefficient */ |
emilmont | 1:fdd22bb7aa52 | 219 | c0 = *(ptr2); |
emilmont | 1:fdd22bb7aa52 | 220 | |
emilmont | 1:fdd22bb7aa52 | 221 | /* Perform the multiply-accumulate */ |
emilmont | 1:fdd22bb7aa52 | 222 | acc0 += x0 * c0; |
emilmont | 1:fdd22bb7aa52 | 223 | acc1 += x1 * c0; |
emilmont | 1:fdd22bb7aa52 | 224 | acc2 += x2 * c0; |
emilmont | 1:fdd22bb7aa52 | 225 | acc3 += x3 * c0; |
emilmont | 1:fdd22bb7aa52 | 226 | |
emilmont | 1:fdd22bb7aa52 | 227 | /* Read the coefficient */ |
emilmont | 1:fdd22bb7aa52 | 228 | c1 = *(ptr2 + S->L); |
emilmont | 1:fdd22bb7aa52 | 229 | |
emilmont | 1:fdd22bb7aa52 | 230 | /* Read the input sample */ |
emilmont | 1:fdd22bb7aa52 | 231 | x0 = *(ptr1++); |
emilmont | 1:fdd22bb7aa52 | 232 | |
emilmont | 1:fdd22bb7aa52 | 233 | /* Perform the multiply-accumulate */ |
emilmont | 1:fdd22bb7aa52 | 234 | acc0 += x1 * c1; |
emilmont | 1:fdd22bb7aa52 | 235 | acc1 += x2 * c1; |
emilmont | 1:fdd22bb7aa52 | 236 | acc2 += x3 * c1; |
emilmont | 1:fdd22bb7aa52 | 237 | acc3 += x0 * c1; |
emilmont | 1:fdd22bb7aa52 | 238 | |
emilmont | 1:fdd22bb7aa52 | 239 | /* Read the coefficient */ |
emilmont | 1:fdd22bb7aa52 | 240 | c2 = *(ptr2 + S->L * 2); |
emilmont | 1:fdd22bb7aa52 | 241 | |
emilmont | 1:fdd22bb7aa52 | 242 | /* Read the input sample */ |
emilmont | 1:fdd22bb7aa52 | 243 | x1 = *(ptr1++); |
emilmont | 1:fdd22bb7aa52 | 244 | |
emilmont | 1:fdd22bb7aa52 | 245 | /* Perform the multiply-accumulate */ |
emilmont | 1:fdd22bb7aa52 | 246 | acc0 += x2 * c2; |
emilmont | 1:fdd22bb7aa52 | 247 | acc1 += x3 * c2; |
emilmont | 1:fdd22bb7aa52 | 248 | acc2 += x0 * c2; |
emilmont | 1:fdd22bb7aa52 | 249 | acc3 += x1 * c2; |
emilmont | 1:fdd22bb7aa52 | 250 | |
emilmont | 1:fdd22bb7aa52 | 251 | /* Read the coefficient */ |
emilmont | 1:fdd22bb7aa52 | 252 | c3 = *(ptr2 + S->L * 3); |
emilmont | 1:fdd22bb7aa52 | 253 | |
emilmont | 1:fdd22bb7aa52 | 254 | /* Read the input sample */ |
emilmont | 1:fdd22bb7aa52 | 255 | x2 = *(ptr1++); |
emilmont | 1:fdd22bb7aa52 | 256 | |
emilmont | 1:fdd22bb7aa52 | 257 | /* Perform the multiply-accumulate */ |
emilmont | 1:fdd22bb7aa52 | 258 | acc0 += x3 * c3; |
emilmont | 1:fdd22bb7aa52 | 259 | acc1 += x0 * c3; |
emilmont | 1:fdd22bb7aa52 | 260 | acc2 += x1 * c3; |
emilmont | 1:fdd22bb7aa52 | 261 | acc3 += x2 * c3; |
emilmont | 1:fdd22bb7aa52 | 262 | |
emilmont | 1:fdd22bb7aa52 | 263 | |
emilmont | 1:fdd22bb7aa52 | 264 | /* Upsampling is done by stuffing L-1 zeros between each sample. |
emilmont | 1:fdd22bb7aa52 | 265 | * So instead of multiplying zeros with coefficients, |
emilmont | 1:fdd22bb7aa52 | 266 | * Increment the coefficient pointer by interpolation factor times. */ |
emilmont | 1:fdd22bb7aa52 | 267 | ptr2 += 4 * S->L; |
emilmont | 1:fdd22bb7aa52 | 268 | |
emilmont | 1:fdd22bb7aa52 | 269 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 270 | tapCnt--; |
emilmont | 1:fdd22bb7aa52 | 271 | } |
emilmont | 1:fdd22bb7aa52 | 272 | |
emilmont | 1:fdd22bb7aa52 | 273 | /* If the polyPhase length is not a multiple of 4, compute the remaining filter taps */ |
emilmont | 1:fdd22bb7aa52 | 274 | tapCnt = phaseLen % 0x4u; |
emilmont | 1:fdd22bb7aa52 | 275 | |
emilmont | 1:fdd22bb7aa52 | 276 | while(tapCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 277 | { |
emilmont | 1:fdd22bb7aa52 | 278 | |
emilmont | 1:fdd22bb7aa52 | 279 | /* Read the input sample */ |
emilmont | 1:fdd22bb7aa52 | 280 | x3 = *(ptr1++); |
emilmont | 1:fdd22bb7aa52 | 281 | |
emilmont | 1:fdd22bb7aa52 | 282 | /* Read the coefficient */ |
emilmont | 1:fdd22bb7aa52 | 283 | c0 = *(ptr2); |
emilmont | 1:fdd22bb7aa52 | 284 | |
emilmont | 1:fdd22bb7aa52 | 285 | /* Perform the multiply-accumulate */ |
emilmont | 1:fdd22bb7aa52 | 286 | acc0 += x0 * c0; |
emilmont | 1:fdd22bb7aa52 | 287 | acc1 += x1 * c0; |
emilmont | 1:fdd22bb7aa52 | 288 | acc2 += x2 * c0; |
emilmont | 1:fdd22bb7aa52 | 289 | acc3 += x3 * c0; |
emilmont | 1:fdd22bb7aa52 | 290 | |
emilmont | 1:fdd22bb7aa52 | 291 | /* Increment the coefficient pointer by interpolation factor times. */ |
emilmont | 1:fdd22bb7aa52 | 292 | ptr2 += S->L; |
emilmont | 1:fdd22bb7aa52 | 293 | |
emilmont | 1:fdd22bb7aa52 | 294 | /* update states for next sample processing */ |
emilmont | 1:fdd22bb7aa52 | 295 | x0 = x1; |
emilmont | 1:fdd22bb7aa52 | 296 | x1 = x2; |
emilmont | 1:fdd22bb7aa52 | 297 | x2 = x3; |
emilmont | 1:fdd22bb7aa52 | 298 | |
emilmont | 1:fdd22bb7aa52 | 299 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 300 | tapCnt--; |
emilmont | 1:fdd22bb7aa52 | 301 | } |
emilmont | 1:fdd22bb7aa52 | 302 | |
emilmont | 1:fdd22bb7aa52 | 303 | /* The result is in the accumulator, store in the destination buffer. */ |
emilmont | 1:fdd22bb7aa52 | 304 | *pDst = acc0; |
emilmont | 1:fdd22bb7aa52 | 305 | *(pDst + S->L) = acc1; |
emilmont | 1:fdd22bb7aa52 | 306 | *(pDst + 2 * S->L) = acc2; |
emilmont | 1:fdd22bb7aa52 | 307 | *(pDst + 3 * S->L) = acc3; |
emilmont | 1:fdd22bb7aa52 | 308 | |
emilmont | 1:fdd22bb7aa52 | 309 | pDst++; |
emilmont | 1:fdd22bb7aa52 | 310 | |
emilmont | 1:fdd22bb7aa52 | 311 | /* Increment the address modifier index of coefficient buffer */ |
emilmont | 1:fdd22bb7aa52 | 312 | j++; |
emilmont | 1:fdd22bb7aa52 | 313 | |
emilmont | 1:fdd22bb7aa52 | 314 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 315 | i--; |
emilmont | 1:fdd22bb7aa52 | 316 | } |
emilmont | 1:fdd22bb7aa52 | 317 | |
emilmont | 1:fdd22bb7aa52 | 318 | /* Advance the state pointer by 1 |
emilmont | 1:fdd22bb7aa52 | 319 | * to process the next group of interpolation factor number samples */ |
emilmont | 1:fdd22bb7aa52 | 320 | pState = pState + 4; |
emilmont | 1:fdd22bb7aa52 | 321 | |
emilmont | 1:fdd22bb7aa52 | 322 | pDst += S->L * 3; |
emilmont | 1:fdd22bb7aa52 | 323 | |
emilmont | 1:fdd22bb7aa52 | 324 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 325 | blkCnt--; |
emilmont | 1:fdd22bb7aa52 | 326 | } |
emilmont | 1:fdd22bb7aa52 | 327 | |
emilmont | 1:fdd22bb7aa52 | 328 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. |
emilmont | 1:fdd22bb7aa52 | 329 | ** No loop unrolling is used. */ |
emilmont | 1:fdd22bb7aa52 | 330 | |
emilmont | 1:fdd22bb7aa52 | 331 | while(blkCntN4 > 0u) |
emilmont | 1:fdd22bb7aa52 | 332 | { |
emilmont | 1:fdd22bb7aa52 | 333 | /* Copy new input sample into the state buffer */ |
emilmont | 1:fdd22bb7aa52 | 334 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 335 | |
emilmont | 1:fdd22bb7aa52 | 336 | /* Address modifier index of coefficient buffer */ |
emilmont | 1:fdd22bb7aa52 | 337 | j = 1u; |
emilmont | 1:fdd22bb7aa52 | 338 | |
emilmont | 1:fdd22bb7aa52 | 339 | /* Loop over the Interpolation factor. */ |
emilmont | 1:fdd22bb7aa52 | 340 | i = S->L; |
emilmont | 1:fdd22bb7aa52 | 341 | while(i > 0u) |
emilmont | 1:fdd22bb7aa52 | 342 | { |
emilmont | 1:fdd22bb7aa52 | 343 | /* Set accumulator to zero */ |
emilmont | 1:fdd22bb7aa52 | 344 | sum0 = 0.0f; |
emilmont | 1:fdd22bb7aa52 | 345 | |
emilmont | 1:fdd22bb7aa52 | 346 | /* Initialize state pointer */ |
emilmont | 1:fdd22bb7aa52 | 347 | ptr1 = pState; |
emilmont | 1:fdd22bb7aa52 | 348 | |
emilmont | 1:fdd22bb7aa52 | 349 | /* Initialize coefficient pointer */ |
emilmont | 1:fdd22bb7aa52 | 350 | ptr2 = pCoeffs + (S->L - j); |
emilmont | 1:fdd22bb7aa52 | 351 | |
emilmont | 1:fdd22bb7aa52 | 352 | /* Loop over the polyPhase length. Unroll by a factor of 4. |
emilmont | 1:fdd22bb7aa52 | 353 | ** Repeat until we've computed numTaps-(4*S->L) coefficients. */ |
emilmont | 1:fdd22bb7aa52 | 354 | tapCnt = phaseLen >> 2u; |
emilmont | 1:fdd22bb7aa52 | 355 | while(tapCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 356 | { |
emilmont | 1:fdd22bb7aa52 | 357 | |
emilmont | 1:fdd22bb7aa52 | 358 | /* Read the coefficient */ |
emilmont | 1:fdd22bb7aa52 | 359 | c0 = *(ptr2); |
emilmont | 1:fdd22bb7aa52 | 360 | |
emilmont | 1:fdd22bb7aa52 | 361 | /* Upsampling is done by stuffing L-1 zeros between each sample. |
emilmont | 1:fdd22bb7aa52 | 362 | * So instead of multiplying zeros with coefficients, |
emilmont | 1:fdd22bb7aa52 | 363 | * Increment the coefficient pointer by interpolation factor times. */ |
emilmont | 1:fdd22bb7aa52 | 364 | ptr2 += S->L; |
emilmont | 1:fdd22bb7aa52 | 365 | |
emilmont | 1:fdd22bb7aa52 | 366 | /* Read the input sample */ |
emilmont | 1:fdd22bb7aa52 | 367 | x0 = *(ptr1++); |
emilmont | 1:fdd22bb7aa52 | 368 | |
emilmont | 1:fdd22bb7aa52 | 369 | /* Perform the multiply-accumulate */ |
emilmont | 1:fdd22bb7aa52 | 370 | sum0 += x0 * c0; |
emilmont | 1:fdd22bb7aa52 | 371 | |
emilmont | 1:fdd22bb7aa52 | 372 | /* Read the coefficient */ |
emilmont | 1:fdd22bb7aa52 | 373 | c0 = *(ptr2); |
emilmont | 1:fdd22bb7aa52 | 374 | |
emilmont | 1:fdd22bb7aa52 | 375 | /* Increment the coefficient pointer by interpolation factor times. */ |
emilmont | 1:fdd22bb7aa52 | 376 | ptr2 += S->L; |
emilmont | 1:fdd22bb7aa52 | 377 | |
emilmont | 1:fdd22bb7aa52 | 378 | /* Read the input sample */ |
emilmont | 1:fdd22bb7aa52 | 379 | x0 = *(ptr1++); |
emilmont | 1:fdd22bb7aa52 | 380 | |
emilmont | 1:fdd22bb7aa52 | 381 | /* Perform the multiply-accumulate */ |
emilmont | 1:fdd22bb7aa52 | 382 | sum0 += x0 * c0; |
emilmont | 1:fdd22bb7aa52 | 383 | |
emilmont | 1:fdd22bb7aa52 | 384 | /* Read the coefficient */ |
emilmont | 1:fdd22bb7aa52 | 385 | c0 = *(ptr2); |
emilmont | 1:fdd22bb7aa52 | 386 | |
emilmont | 1:fdd22bb7aa52 | 387 | /* Increment the coefficient pointer by interpolation factor times. */ |
emilmont | 1:fdd22bb7aa52 | 388 | ptr2 += S->L; |
emilmont | 1:fdd22bb7aa52 | 389 | |
emilmont | 1:fdd22bb7aa52 | 390 | /* Read the input sample */ |
emilmont | 1:fdd22bb7aa52 | 391 | x0 = *(ptr1++); |
emilmont | 1:fdd22bb7aa52 | 392 | |
emilmont | 1:fdd22bb7aa52 | 393 | /* Perform the multiply-accumulate */ |
emilmont | 1:fdd22bb7aa52 | 394 | sum0 += x0 * c0; |
emilmont | 1:fdd22bb7aa52 | 395 | |
emilmont | 1:fdd22bb7aa52 | 396 | /* Read the coefficient */ |
emilmont | 1:fdd22bb7aa52 | 397 | c0 = *(ptr2); |
emilmont | 1:fdd22bb7aa52 | 398 | |
emilmont | 1:fdd22bb7aa52 | 399 | /* Increment the coefficient pointer by interpolation factor times. */ |
emilmont | 1:fdd22bb7aa52 | 400 | ptr2 += S->L; |
emilmont | 1:fdd22bb7aa52 | 401 | |
emilmont | 1:fdd22bb7aa52 | 402 | /* Read the input sample */ |
emilmont | 1:fdd22bb7aa52 | 403 | x0 = *(ptr1++); |
emilmont | 1:fdd22bb7aa52 | 404 | |
emilmont | 1:fdd22bb7aa52 | 405 | /* Perform the multiply-accumulate */ |
emilmont | 1:fdd22bb7aa52 | 406 | sum0 += x0 * c0; |
emilmont | 1:fdd22bb7aa52 | 407 | |
emilmont | 1:fdd22bb7aa52 | 408 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 409 | tapCnt--; |
emilmont | 1:fdd22bb7aa52 | 410 | } |
emilmont | 1:fdd22bb7aa52 | 411 | |
emilmont | 1:fdd22bb7aa52 | 412 | /* If the polyPhase length is not a multiple of 4, compute the remaining filter taps */ |
emilmont | 1:fdd22bb7aa52 | 413 | tapCnt = phaseLen % 0x4u; |
emilmont | 1:fdd22bb7aa52 | 414 | |
emilmont | 1:fdd22bb7aa52 | 415 | while(tapCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 416 | { |
emilmont | 1:fdd22bb7aa52 | 417 | /* Perform the multiply-accumulate */ |
emilmont | 1:fdd22bb7aa52 | 418 | sum0 += *(ptr1++) * (*ptr2); |
emilmont | 1:fdd22bb7aa52 | 419 | |
emilmont | 1:fdd22bb7aa52 | 420 | /* Increment the coefficient pointer by interpolation factor times. */ |
emilmont | 1:fdd22bb7aa52 | 421 | ptr2 += S->L; |
emilmont | 1:fdd22bb7aa52 | 422 | |
emilmont | 1:fdd22bb7aa52 | 423 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 424 | tapCnt--; |
emilmont | 1:fdd22bb7aa52 | 425 | } |
emilmont | 1:fdd22bb7aa52 | 426 | |
emilmont | 1:fdd22bb7aa52 | 427 | /* The result is in the accumulator, store in the destination buffer. */ |
emilmont | 1:fdd22bb7aa52 | 428 | *pDst++ = sum0; |
emilmont | 1:fdd22bb7aa52 | 429 | |
emilmont | 1:fdd22bb7aa52 | 430 | /* Increment the address modifier index of coefficient buffer */ |
emilmont | 1:fdd22bb7aa52 | 431 | j++; |
emilmont | 1:fdd22bb7aa52 | 432 | |
emilmont | 1:fdd22bb7aa52 | 433 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 434 | i--; |
emilmont | 1:fdd22bb7aa52 | 435 | } |
emilmont | 1:fdd22bb7aa52 | 436 | |
emilmont | 1:fdd22bb7aa52 | 437 | /* Advance the state pointer by 1 |
emilmont | 1:fdd22bb7aa52 | 438 | * to process the next group of interpolation factor number samples */ |
emilmont | 1:fdd22bb7aa52 | 439 | pState = pState + 1; |
emilmont | 1:fdd22bb7aa52 | 440 | |
emilmont | 1:fdd22bb7aa52 | 441 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 442 | blkCntN4--; |
emilmont | 1:fdd22bb7aa52 | 443 | } |
emilmont | 1:fdd22bb7aa52 | 444 | |
emilmont | 1:fdd22bb7aa52 | 445 | /* Processing is complete. |
emilmont | 1:fdd22bb7aa52 | 446 | ** Now copy the last phaseLen - 1 samples to the satrt of the state buffer. |
emilmont | 1:fdd22bb7aa52 | 447 | ** This prepares the state buffer for the next function call. */ |
emilmont | 1:fdd22bb7aa52 | 448 | |
emilmont | 1:fdd22bb7aa52 | 449 | /* Points to the start of the state buffer */ |
emilmont | 1:fdd22bb7aa52 | 450 | pStateCurnt = S->pState; |
emilmont | 1:fdd22bb7aa52 | 451 | |
emilmont | 1:fdd22bb7aa52 | 452 | tapCnt = (phaseLen - 1u) >> 2u; |
emilmont | 1:fdd22bb7aa52 | 453 | |
emilmont | 1:fdd22bb7aa52 | 454 | /* copy data */ |
emilmont | 1:fdd22bb7aa52 | 455 | while(tapCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 456 | { |
emilmont | 1:fdd22bb7aa52 | 457 | *pStateCurnt++ = *pState++; |
emilmont | 1:fdd22bb7aa52 | 458 | *pStateCurnt++ = *pState++; |
emilmont | 1:fdd22bb7aa52 | 459 | *pStateCurnt++ = *pState++; |
emilmont | 1:fdd22bb7aa52 | 460 | *pStateCurnt++ = *pState++; |
emilmont | 1:fdd22bb7aa52 | 461 | |
emilmont | 1:fdd22bb7aa52 | 462 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 463 | tapCnt--; |
emilmont | 1:fdd22bb7aa52 | 464 | } |
emilmont | 1:fdd22bb7aa52 | 465 | |
emilmont | 1:fdd22bb7aa52 | 466 | tapCnt = (phaseLen - 1u) % 0x04u; |
emilmont | 1:fdd22bb7aa52 | 467 | |
emilmont | 1:fdd22bb7aa52 | 468 | /* copy data */ |
emilmont | 1:fdd22bb7aa52 | 469 | while(tapCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 470 | { |
emilmont | 1:fdd22bb7aa52 | 471 | *pStateCurnt++ = *pState++; |
emilmont | 1:fdd22bb7aa52 | 472 | |
emilmont | 1:fdd22bb7aa52 | 473 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 474 | tapCnt--; |
emilmont | 1:fdd22bb7aa52 | 475 | } |
emilmont | 1:fdd22bb7aa52 | 476 | } |
emilmont | 1:fdd22bb7aa52 | 477 | |
emilmont | 1:fdd22bb7aa52 | 478 | #else |
emilmont | 1:fdd22bb7aa52 | 479 | |
emilmont | 1:fdd22bb7aa52 | 480 | /* Run the below code for Cortex-M0 */ |
emilmont | 1:fdd22bb7aa52 | 481 | |
emilmont | 1:fdd22bb7aa52 | 482 | void arm_fir_interpolate_f32( |
emilmont | 1:fdd22bb7aa52 | 483 | const arm_fir_interpolate_instance_f32 * S, |
emilmont | 1:fdd22bb7aa52 | 484 | float32_t * pSrc, |
emilmont | 1:fdd22bb7aa52 | 485 | float32_t * pDst, |
emilmont | 1:fdd22bb7aa52 | 486 | uint32_t blockSize) |
emilmont | 1:fdd22bb7aa52 | 487 | { |
emilmont | 1:fdd22bb7aa52 | 488 | float32_t *pState = S->pState; /* State pointer */ |
emilmont | 1:fdd22bb7aa52 | 489 | float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
emilmont | 1:fdd22bb7aa52 | 490 | float32_t *pStateCurnt; /* Points to the current sample of the state */ |
emilmont | 1:fdd22bb7aa52 | 491 | float32_t *ptr1, *ptr2; /* Temporary pointers for state and coefficient buffers */ |
emilmont | 1:fdd22bb7aa52 | 492 | |
emilmont | 1:fdd22bb7aa52 | 493 | |
emilmont | 1:fdd22bb7aa52 | 494 | float32_t sum; /* Accumulator */ |
emilmont | 1:fdd22bb7aa52 | 495 | uint32_t i, blkCnt; /* Loop counters */ |
emilmont | 1:fdd22bb7aa52 | 496 | uint16_t phaseLen = S->phaseLength, tapCnt; /* Length of each polyphase filter component */ |
emilmont | 1:fdd22bb7aa52 | 497 | |
emilmont | 1:fdd22bb7aa52 | 498 | |
emilmont | 1:fdd22bb7aa52 | 499 | /* S->pState buffer contains previous frame (phaseLen - 1) samples */ |
emilmont | 1:fdd22bb7aa52 | 500 | /* pStateCurnt points to the location where the new input data should be written */ |
emilmont | 1:fdd22bb7aa52 | 501 | pStateCurnt = S->pState + (phaseLen - 1u); |
emilmont | 1:fdd22bb7aa52 | 502 | |
emilmont | 1:fdd22bb7aa52 | 503 | /* Total number of intput samples */ |
emilmont | 1:fdd22bb7aa52 | 504 | blkCnt = blockSize; |
emilmont | 1:fdd22bb7aa52 | 505 | |
emilmont | 1:fdd22bb7aa52 | 506 | /* Loop over the blockSize. */ |
emilmont | 1:fdd22bb7aa52 | 507 | while(blkCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 508 | { |
emilmont | 1:fdd22bb7aa52 | 509 | /* Copy new input sample into the state buffer */ |
emilmont | 1:fdd22bb7aa52 | 510 | *pStateCurnt++ = *pSrc++; |
emilmont | 1:fdd22bb7aa52 | 511 | |
emilmont | 1:fdd22bb7aa52 | 512 | /* Loop over the Interpolation factor. */ |
emilmont | 1:fdd22bb7aa52 | 513 | i = S->L; |
emilmont | 1:fdd22bb7aa52 | 514 | |
emilmont | 1:fdd22bb7aa52 | 515 | while(i > 0u) |
emilmont | 1:fdd22bb7aa52 | 516 | { |
emilmont | 1:fdd22bb7aa52 | 517 | /* Set accumulator to zero */ |
emilmont | 1:fdd22bb7aa52 | 518 | sum = 0.0f; |
emilmont | 1:fdd22bb7aa52 | 519 | |
emilmont | 1:fdd22bb7aa52 | 520 | /* Initialize state pointer */ |
emilmont | 1:fdd22bb7aa52 | 521 | ptr1 = pState; |
emilmont | 1:fdd22bb7aa52 | 522 | |
emilmont | 1:fdd22bb7aa52 | 523 | /* Initialize coefficient pointer */ |
emilmont | 1:fdd22bb7aa52 | 524 | ptr2 = pCoeffs + (i - 1u); |
emilmont | 1:fdd22bb7aa52 | 525 | |
emilmont | 1:fdd22bb7aa52 | 526 | /* Loop over the polyPhase length */ |
emilmont | 1:fdd22bb7aa52 | 527 | tapCnt = phaseLen; |
emilmont | 1:fdd22bb7aa52 | 528 | |
emilmont | 1:fdd22bb7aa52 | 529 | while(tapCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 530 | { |
emilmont | 1:fdd22bb7aa52 | 531 | /* Perform the multiply-accumulate */ |
emilmont | 1:fdd22bb7aa52 | 532 | sum += *ptr1++ * *ptr2; |
emilmont | 1:fdd22bb7aa52 | 533 | |
emilmont | 1:fdd22bb7aa52 | 534 | /* Increment the coefficient pointer by interpolation factor times. */ |
emilmont | 1:fdd22bb7aa52 | 535 | ptr2 += S->L; |
emilmont | 1:fdd22bb7aa52 | 536 | |
emilmont | 1:fdd22bb7aa52 | 537 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 538 | tapCnt--; |
emilmont | 1:fdd22bb7aa52 | 539 | } |
emilmont | 1:fdd22bb7aa52 | 540 | |
emilmont | 1:fdd22bb7aa52 | 541 | /* The result is in the accumulator, store in the destination buffer. */ |
emilmont | 1:fdd22bb7aa52 | 542 | *pDst++ = sum; |
emilmont | 1:fdd22bb7aa52 | 543 | |
emilmont | 1:fdd22bb7aa52 | 544 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 545 | i--; |
emilmont | 1:fdd22bb7aa52 | 546 | } |
emilmont | 1:fdd22bb7aa52 | 547 | |
emilmont | 1:fdd22bb7aa52 | 548 | /* Advance the state pointer by 1 |
emilmont | 1:fdd22bb7aa52 | 549 | * to process the next group of interpolation factor number samples */ |
emilmont | 1:fdd22bb7aa52 | 550 | pState = pState + 1; |
emilmont | 1:fdd22bb7aa52 | 551 | |
emilmont | 1:fdd22bb7aa52 | 552 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 553 | blkCnt--; |
emilmont | 1:fdd22bb7aa52 | 554 | } |
emilmont | 1:fdd22bb7aa52 | 555 | |
emilmont | 1:fdd22bb7aa52 | 556 | /* Processing is complete. |
emilmont | 1:fdd22bb7aa52 | 557 | ** Now copy the last phaseLen - 1 samples to the start of the state buffer. |
emilmont | 1:fdd22bb7aa52 | 558 | ** This prepares the state buffer for the next function call. */ |
emilmont | 1:fdd22bb7aa52 | 559 | |
emilmont | 1:fdd22bb7aa52 | 560 | /* Points to the start of the state buffer */ |
emilmont | 1:fdd22bb7aa52 | 561 | pStateCurnt = S->pState; |
emilmont | 1:fdd22bb7aa52 | 562 | |
emilmont | 1:fdd22bb7aa52 | 563 | tapCnt = phaseLen - 1u; |
emilmont | 1:fdd22bb7aa52 | 564 | |
emilmont | 1:fdd22bb7aa52 | 565 | while(tapCnt > 0u) |
emilmont | 1:fdd22bb7aa52 | 566 | { |
emilmont | 1:fdd22bb7aa52 | 567 | *pStateCurnt++ = *pState++; |
emilmont | 1:fdd22bb7aa52 | 568 | |
emilmont | 1:fdd22bb7aa52 | 569 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 570 | tapCnt--; |
emilmont | 1:fdd22bb7aa52 | 571 | } |
emilmont | 1:fdd22bb7aa52 | 572 | |
emilmont | 1:fdd22bb7aa52 | 573 | } |
emilmont | 1:fdd22bb7aa52 | 574 | |
mbed_official | 3:7a284390b0ce | 575 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
emilmont | 1:fdd22bb7aa52 | 576 | |
emilmont | 1:fdd22bb7aa52 | 577 | |
emilmont | 1:fdd22bb7aa52 | 578 | |
emilmont | 1:fdd22bb7aa52 | 579 | /** |
emilmont | 1:fdd22bb7aa52 | 580 | * @} end of FIR_Interpolate group |
emilmont | 1:fdd22bb7aa52 | 581 | */ |