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.

Committer:
emilmont
Date:
Wed Nov 28 12:30:09 2012 +0000
Revision:
1:fdd22bb7aa52
Child:
2:da51fb522205
DSP library code

Who changed what in which revision?

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