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_q15.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 1:fdd22bb7aa52 10 * Description: Q15 FIR interpolation.
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 * @ingroup groupFilters
emilmont 1:fdd22bb7aa52 40 */
emilmont 1:fdd22bb7aa52 41
emilmont 1:fdd22bb7aa52 42 /**
emilmont 1:fdd22bb7aa52 43 * @addtogroup FIR_Interpolate
emilmont 1:fdd22bb7aa52 44 * @{
emilmont 1:fdd22bb7aa52 45 */
emilmont 1:fdd22bb7aa52 46
emilmont 1:fdd22bb7aa52 47 /**
emilmont 1:fdd22bb7aa52 48 * @brief Processing function for the Q15 FIR interpolator.
emilmont 1:fdd22bb7aa52 49 * @param[in] *S points to an instance of the Q15 FIR interpolator structure.
emilmont 1:fdd22bb7aa52 50 * @param[in] *pSrc points to the block of input data.
emilmont 1:fdd22bb7aa52 51 * @param[out] *pDst points to the block of output data.
emilmont 1:fdd22bb7aa52 52 * @param[in] blockSize number of input samples to process per call.
emilmont 1:fdd22bb7aa52 53 * @return none.
emilmont 1:fdd22bb7aa52 54 *
emilmont 1:fdd22bb7aa52 55 * <b>Scaling and Overflow Behavior:</b>
emilmont 1:fdd22bb7aa52 56 * \par
emilmont 1:fdd22bb7aa52 57 * The function is implemented using a 64-bit internal accumulator.
emilmont 1:fdd22bb7aa52 58 * Both coefficients and state variables are represented in 1.15 format and multiplications yield a 2.30 result.
emilmont 1:fdd22bb7aa52 59 * The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format.
emilmont 1:fdd22bb7aa52 60 * There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved.
emilmont 1:fdd22bb7aa52 61 * After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits.
emilmont 1:fdd22bb7aa52 62 * Lastly, the accumulator is saturated to yield a result in 1.15 format.
emilmont 1:fdd22bb7aa52 63 */
emilmont 1:fdd22bb7aa52 64
emilmont 1:fdd22bb7aa52 65 #ifndef ARM_MATH_CM0
emilmont 1:fdd22bb7aa52 66
emilmont 1:fdd22bb7aa52 67 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 68
emilmont 1:fdd22bb7aa52 69 void arm_fir_interpolate_q15(
emilmont 1:fdd22bb7aa52 70 const arm_fir_interpolate_instance_q15 * S,
emilmont 1:fdd22bb7aa52 71 q15_t * pSrc,
emilmont 1:fdd22bb7aa52 72 q15_t * pDst,
emilmont 1:fdd22bb7aa52 73 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 74 {
emilmont 1:fdd22bb7aa52 75 q15_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 76 q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 77 q15_t *pStateCurnt; /* Points to the current sample of the state */
emilmont 1:fdd22bb7aa52 78 q15_t *ptr1, *ptr2; /* Temporary pointers for state and coefficient buffers */
emilmont 1:fdd22bb7aa52 79 q63_t sum0; /* Accumulators */
emilmont 1:fdd22bb7aa52 80 q15_t x0, c0; /* Temporary variables to hold state and coefficient values */
emilmont 1:fdd22bb7aa52 81 uint32_t i, blkCnt, j, tapCnt; /* Loop counters */
emilmont 1:fdd22bb7aa52 82 uint16_t phaseLen = S->phaseLength; /* Length of each polyphase filter component */
emilmont 1:fdd22bb7aa52 83 uint32_t blkCntN2;
emilmont 1:fdd22bb7aa52 84 q63_t acc0, acc1;
emilmont 1:fdd22bb7aa52 85 q15_t x1;
emilmont 1:fdd22bb7aa52 86
emilmont 1:fdd22bb7aa52 87 /* S->pState buffer contains previous frame (phaseLen - 1) samples */
emilmont 1:fdd22bb7aa52 88 /* pStateCurnt points to the location where the new input data should be written */
emilmont 1:fdd22bb7aa52 89 pStateCurnt = S->pState + ((q31_t) phaseLen - 1);
emilmont 1:fdd22bb7aa52 90
emilmont 1:fdd22bb7aa52 91 /* Initialise blkCnt */
emilmont 1:fdd22bb7aa52 92 blkCnt = blockSize / 2;
emilmont 1:fdd22bb7aa52 93 blkCntN2 = blockSize - (2 * blkCnt);
emilmont 1:fdd22bb7aa52 94
emilmont 1:fdd22bb7aa52 95 /* Samples loop unrolled by 2 */
emilmont 1:fdd22bb7aa52 96 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 97 {
emilmont 1:fdd22bb7aa52 98 /* Copy new input sample into the state buffer */
emilmont 1:fdd22bb7aa52 99 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 100 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 101
emilmont 1:fdd22bb7aa52 102 /* Address modifier index of coefficient buffer */
emilmont 1:fdd22bb7aa52 103 j = 1u;
emilmont 1:fdd22bb7aa52 104
emilmont 1:fdd22bb7aa52 105 /* Loop over the Interpolation factor. */
emilmont 1:fdd22bb7aa52 106 i = (S->L);
emilmont 1:fdd22bb7aa52 107
emilmont 1:fdd22bb7aa52 108 while(i > 0u)
emilmont 1:fdd22bb7aa52 109 {
emilmont 1:fdd22bb7aa52 110 /* Set accumulator to zero */
emilmont 1:fdd22bb7aa52 111 acc0 = 0;
emilmont 1:fdd22bb7aa52 112 acc1 = 0;
emilmont 1:fdd22bb7aa52 113
emilmont 1:fdd22bb7aa52 114 /* Initialize state pointer */
emilmont 1:fdd22bb7aa52 115 ptr1 = pState;
emilmont 1:fdd22bb7aa52 116
emilmont 1:fdd22bb7aa52 117 /* Initialize coefficient pointer */
emilmont 1:fdd22bb7aa52 118 ptr2 = pCoeffs + (S->L - j);
emilmont 1:fdd22bb7aa52 119
emilmont 1:fdd22bb7aa52 120 /* Loop over the polyPhase length. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 121 ** Repeat until we've computed numTaps-(4*S->L) coefficients. */
emilmont 1:fdd22bb7aa52 122 tapCnt = phaseLen >> 2u;
emilmont 1:fdd22bb7aa52 123
emilmont 1:fdd22bb7aa52 124 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 125
emilmont 1:fdd22bb7aa52 126 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 127 {
emilmont 1:fdd22bb7aa52 128
emilmont 1:fdd22bb7aa52 129 /* Read the input sample */
emilmont 1:fdd22bb7aa52 130 x1 = *(ptr1++);
emilmont 1:fdd22bb7aa52 131
emilmont 1:fdd22bb7aa52 132 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 133 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 134
emilmont 1:fdd22bb7aa52 135 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 136 acc0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 137 acc1 += (q63_t) x1 *c0;
emilmont 1:fdd22bb7aa52 138
emilmont 1:fdd22bb7aa52 139
emilmont 1:fdd22bb7aa52 140 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 141 c0 = *(ptr2 + S->L);
emilmont 1:fdd22bb7aa52 142
emilmont 1:fdd22bb7aa52 143 /* Read the input sample */
emilmont 1:fdd22bb7aa52 144 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 145
emilmont 1:fdd22bb7aa52 146 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 147 acc0 += (q63_t) x1 *c0;
emilmont 1:fdd22bb7aa52 148 acc1 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 149
emilmont 1:fdd22bb7aa52 150
emilmont 1:fdd22bb7aa52 151 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 152 c0 = *(ptr2 + S->L * 2);
emilmont 1:fdd22bb7aa52 153
emilmont 1:fdd22bb7aa52 154 /* Read the input sample */
emilmont 1:fdd22bb7aa52 155 x1 = *(ptr1++);
emilmont 1:fdd22bb7aa52 156
emilmont 1:fdd22bb7aa52 157 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 158 acc0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 159 acc1 += (q63_t) x1 *c0;
emilmont 1:fdd22bb7aa52 160
emilmont 1:fdd22bb7aa52 161 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 162 c0 = *(ptr2 + S->L * 3);
emilmont 1:fdd22bb7aa52 163
emilmont 1:fdd22bb7aa52 164 /* Read the input sample */
emilmont 1:fdd22bb7aa52 165 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 166
emilmont 1:fdd22bb7aa52 167 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 168 acc0 += (q63_t) x1 *c0;
emilmont 1:fdd22bb7aa52 169 acc1 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 170
emilmont 1:fdd22bb7aa52 171
emilmont 1:fdd22bb7aa52 172 /* Upsampling is done by stuffing L-1 zeros between each sample.
emilmont 1:fdd22bb7aa52 173 * So instead of multiplying zeros with coefficients,
emilmont 1:fdd22bb7aa52 174 * Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 175 ptr2 += 4 * S->L;
emilmont 1:fdd22bb7aa52 176
emilmont 1:fdd22bb7aa52 177 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 178 tapCnt--;
emilmont 1:fdd22bb7aa52 179 }
emilmont 1:fdd22bb7aa52 180
emilmont 1:fdd22bb7aa52 181 /* If the polyPhase length is not a multiple of 4, compute the remaining filter taps */
emilmont 1:fdd22bb7aa52 182 tapCnt = phaseLen % 0x4u;
emilmont 1:fdd22bb7aa52 183
emilmont 1:fdd22bb7aa52 184 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 185 {
emilmont 1:fdd22bb7aa52 186
emilmont 1:fdd22bb7aa52 187 /* Read the input sample */
emilmont 1:fdd22bb7aa52 188 x1 = *(ptr1++);
emilmont 1:fdd22bb7aa52 189
emilmont 1:fdd22bb7aa52 190 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 191 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 192
emilmont 1:fdd22bb7aa52 193 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 194 acc0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 195 acc1 += (q63_t) x1 *c0;
emilmont 1:fdd22bb7aa52 196
emilmont 1:fdd22bb7aa52 197 /* Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 198 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 199
emilmont 1:fdd22bb7aa52 200 /* update states for next sample processing */
emilmont 1:fdd22bb7aa52 201 x0 = x1;
emilmont 1:fdd22bb7aa52 202
emilmont 1:fdd22bb7aa52 203 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 204 tapCnt--;
emilmont 1:fdd22bb7aa52 205 }
emilmont 1:fdd22bb7aa52 206
emilmont 1:fdd22bb7aa52 207 /* The result is in the accumulator, store in the destination buffer. */
emilmont 1:fdd22bb7aa52 208 *pDst = (q15_t) (__SSAT((acc0 >> 15), 16));
emilmont 1:fdd22bb7aa52 209 *(pDst + S->L) = (q15_t) (__SSAT((acc1 >> 15), 16));
emilmont 1:fdd22bb7aa52 210
emilmont 1:fdd22bb7aa52 211 pDst++;
emilmont 1:fdd22bb7aa52 212
emilmont 1:fdd22bb7aa52 213 /* Increment the address modifier index of coefficient buffer */
emilmont 1:fdd22bb7aa52 214 j++;
emilmont 1:fdd22bb7aa52 215
emilmont 1:fdd22bb7aa52 216 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 217 i--;
emilmont 1:fdd22bb7aa52 218 }
emilmont 1:fdd22bb7aa52 219
emilmont 1:fdd22bb7aa52 220 /* Advance the state pointer by 1
emilmont 1:fdd22bb7aa52 221 * to process the next group of interpolation factor number samples */
emilmont 1:fdd22bb7aa52 222 pState = pState + 2;
emilmont 1:fdd22bb7aa52 223
emilmont 1:fdd22bb7aa52 224 pDst += S->L;
emilmont 1:fdd22bb7aa52 225
emilmont 1:fdd22bb7aa52 226 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 227 blkCnt--;
emilmont 1:fdd22bb7aa52 228 }
emilmont 1:fdd22bb7aa52 229
emilmont 1:fdd22bb7aa52 230 /* If the blockSize is not a multiple of 2, compute any remaining output samples here.
emilmont 1:fdd22bb7aa52 231 ** No loop unrolling is used. */
emilmont 1:fdd22bb7aa52 232 blkCnt = blkCntN2;
emilmont 1:fdd22bb7aa52 233
emilmont 1:fdd22bb7aa52 234 /* Loop over the blockSize. */
emilmont 1:fdd22bb7aa52 235 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 236 {
emilmont 1:fdd22bb7aa52 237 /* Copy new input sample into the state buffer */
emilmont 1:fdd22bb7aa52 238 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 239
emilmont 1:fdd22bb7aa52 240 /* Address modifier index of coefficient buffer */
emilmont 1:fdd22bb7aa52 241 j = 1u;
emilmont 1:fdd22bb7aa52 242
emilmont 1:fdd22bb7aa52 243 /* Loop over the Interpolation factor. */
emilmont 1:fdd22bb7aa52 244 i = S->L;
emilmont 1:fdd22bb7aa52 245 while(i > 0u)
emilmont 1:fdd22bb7aa52 246 {
emilmont 1:fdd22bb7aa52 247 /* Set accumulator to zero */
emilmont 1:fdd22bb7aa52 248 sum0 = 0;
emilmont 1:fdd22bb7aa52 249
emilmont 1:fdd22bb7aa52 250 /* Initialize state pointer */
emilmont 1:fdd22bb7aa52 251 ptr1 = pState;
emilmont 1:fdd22bb7aa52 252
emilmont 1:fdd22bb7aa52 253 /* Initialize coefficient pointer */
emilmont 1:fdd22bb7aa52 254 ptr2 = pCoeffs + (S->L - j);
emilmont 1:fdd22bb7aa52 255
emilmont 1:fdd22bb7aa52 256 /* Loop over the polyPhase length. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 257 ** Repeat until we've computed numTaps-(4*S->L) coefficients. */
emilmont 1:fdd22bb7aa52 258 tapCnt = phaseLen >> 2;
emilmont 1:fdd22bb7aa52 259 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 260 {
emilmont 1:fdd22bb7aa52 261
emilmont 1:fdd22bb7aa52 262 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 263 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 264
emilmont 1:fdd22bb7aa52 265 /* Upsampling is done by stuffing L-1 zeros between each sample.
emilmont 1:fdd22bb7aa52 266 * So instead of multiplying zeros with coefficients,
emilmont 1:fdd22bb7aa52 267 * Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 268 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 269
emilmont 1:fdd22bb7aa52 270 /* Read the input sample */
emilmont 1:fdd22bb7aa52 271 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 272
emilmont 1:fdd22bb7aa52 273 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 274 sum0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 275
emilmont 1:fdd22bb7aa52 276 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 277 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 278
emilmont 1:fdd22bb7aa52 279 /* Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 280 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 281
emilmont 1:fdd22bb7aa52 282 /* Read the input sample */
emilmont 1:fdd22bb7aa52 283 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 284
emilmont 1:fdd22bb7aa52 285 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 286 sum0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 287
emilmont 1:fdd22bb7aa52 288 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 289 c0 = *(ptr2);
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 /* Read the input sample */
emilmont 1:fdd22bb7aa52 295 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 296
emilmont 1:fdd22bb7aa52 297 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 298 sum0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 299
emilmont 1:fdd22bb7aa52 300 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 301 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 302
emilmont 1:fdd22bb7aa52 303 /* Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 304 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 305
emilmont 1:fdd22bb7aa52 306 /* Read the input sample */
emilmont 1:fdd22bb7aa52 307 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 308
emilmont 1:fdd22bb7aa52 309 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 310 sum0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 311
emilmont 1:fdd22bb7aa52 312 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 313 tapCnt--;
emilmont 1:fdd22bb7aa52 314 }
emilmont 1:fdd22bb7aa52 315
emilmont 1:fdd22bb7aa52 316 /* If the polyPhase length is not a multiple of 4, compute the remaining filter taps */
emilmont 1:fdd22bb7aa52 317 tapCnt = phaseLen & 0x3u;
emilmont 1:fdd22bb7aa52 318
emilmont 1:fdd22bb7aa52 319 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 320 {
emilmont 1:fdd22bb7aa52 321 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 322 c0 = *(ptr2);
emilmont 1:fdd22bb7aa52 323
emilmont 1:fdd22bb7aa52 324 /* Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 325 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 326
emilmont 1:fdd22bb7aa52 327 /* Read the input sample */
emilmont 1:fdd22bb7aa52 328 x0 = *(ptr1++);
emilmont 1:fdd22bb7aa52 329
emilmont 1:fdd22bb7aa52 330 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 331 sum0 += (q63_t) x0 *c0;
emilmont 1:fdd22bb7aa52 332
emilmont 1:fdd22bb7aa52 333 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 334 tapCnt--;
emilmont 1:fdd22bb7aa52 335 }
emilmont 1:fdd22bb7aa52 336
emilmont 1:fdd22bb7aa52 337 /* The result is in the accumulator, store in the destination buffer. */
emilmont 1:fdd22bb7aa52 338 *pDst++ = (q15_t) (__SSAT((sum0 >> 15), 16));
emilmont 1:fdd22bb7aa52 339
emilmont 1:fdd22bb7aa52 340 j++;
emilmont 1:fdd22bb7aa52 341
emilmont 1:fdd22bb7aa52 342 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 343 i--;
emilmont 1:fdd22bb7aa52 344 }
emilmont 1:fdd22bb7aa52 345
emilmont 1:fdd22bb7aa52 346 /* Advance the state pointer by 1
emilmont 1:fdd22bb7aa52 347 * to process the next group of interpolation factor number samples */
emilmont 1:fdd22bb7aa52 348 pState = pState + 1;
emilmont 1:fdd22bb7aa52 349
emilmont 1:fdd22bb7aa52 350 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 351 blkCnt--;
emilmont 1:fdd22bb7aa52 352 }
emilmont 1:fdd22bb7aa52 353
emilmont 1:fdd22bb7aa52 354
emilmont 1:fdd22bb7aa52 355 /* Processing is complete.
emilmont 1:fdd22bb7aa52 356 ** Now copy the last phaseLen - 1 samples to the satrt of the state buffer.
emilmont 1:fdd22bb7aa52 357 ** This prepares the state buffer for the next function call. */
emilmont 1:fdd22bb7aa52 358
emilmont 1:fdd22bb7aa52 359 /* Points to the start of the state buffer */
emilmont 1:fdd22bb7aa52 360 pStateCurnt = S->pState;
emilmont 1:fdd22bb7aa52 361
emilmont 1:fdd22bb7aa52 362 i = ((uint32_t) phaseLen - 1u) >> 2u;
emilmont 1:fdd22bb7aa52 363
emilmont 1:fdd22bb7aa52 364 /* copy data */
emilmont 1:fdd22bb7aa52 365 while(i > 0u)
emilmont 1:fdd22bb7aa52 366 {
emilmont 1:fdd22bb7aa52 367 #ifndef UNALIGNED_SUPPORT_DISABLE
emilmont 1:fdd22bb7aa52 368
emilmont 1:fdd22bb7aa52 369 *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++;
emilmont 1:fdd22bb7aa52 370 *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++;
emilmont 1:fdd22bb7aa52 371
emilmont 1:fdd22bb7aa52 372 #else
emilmont 1:fdd22bb7aa52 373
emilmont 1:fdd22bb7aa52 374 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 375 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 376 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 377 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 378
emilmont 1:fdd22bb7aa52 379 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
emilmont 1:fdd22bb7aa52 380
emilmont 1:fdd22bb7aa52 381 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 382 i--;
emilmont 1:fdd22bb7aa52 383 }
emilmont 1:fdd22bb7aa52 384
emilmont 1:fdd22bb7aa52 385 i = ((uint32_t) phaseLen - 1u) % 0x04u;
emilmont 1:fdd22bb7aa52 386
emilmont 1:fdd22bb7aa52 387 while(i > 0u)
emilmont 1:fdd22bb7aa52 388 {
emilmont 1:fdd22bb7aa52 389 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 390
emilmont 1:fdd22bb7aa52 391 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 392 i--;
emilmont 1:fdd22bb7aa52 393 }
emilmont 1:fdd22bb7aa52 394 }
emilmont 1:fdd22bb7aa52 395
emilmont 1:fdd22bb7aa52 396 #else
emilmont 1:fdd22bb7aa52 397
emilmont 1:fdd22bb7aa52 398 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 399
emilmont 1:fdd22bb7aa52 400 void arm_fir_interpolate_q15(
emilmont 1:fdd22bb7aa52 401 const arm_fir_interpolate_instance_q15 * S,
emilmont 1:fdd22bb7aa52 402 q15_t * pSrc,
emilmont 1:fdd22bb7aa52 403 q15_t * pDst,
emilmont 1:fdd22bb7aa52 404 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 405 {
emilmont 1:fdd22bb7aa52 406 q15_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 407 q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 408 q15_t *pStateCurnt; /* Points to the current sample of the state */
emilmont 1:fdd22bb7aa52 409 q15_t *ptr1, *ptr2; /* Temporary pointers for state and coefficient buffers */
emilmont 1:fdd22bb7aa52 410 q63_t sum; /* Accumulator */
emilmont 1:fdd22bb7aa52 411 q15_t x0, c0; /* Temporary variables to hold state and coefficient values */
emilmont 1:fdd22bb7aa52 412 uint32_t i, blkCnt, tapCnt; /* Loop counters */
emilmont 1:fdd22bb7aa52 413 uint16_t phaseLen = S->phaseLength; /* Length of each polyphase filter component */
emilmont 1:fdd22bb7aa52 414
emilmont 1:fdd22bb7aa52 415
emilmont 1:fdd22bb7aa52 416 /* S->pState buffer contains previous frame (phaseLen - 1) samples */
emilmont 1:fdd22bb7aa52 417 /* pStateCurnt points to the location where the new input data should be written */
emilmont 1:fdd22bb7aa52 418 pStateCurnt = S->pState + (phaseLen - 1u);
emilmont 1:fdd22bb7aa52 419
emilmont 1:fdd22bb7aa52 420 /* Total number of intput samples */
emilmont 1:fdd22bb7aa52 421 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 422
emilmont 1:fdd22bb7aa52 423 /* Loop over the blockSize. */
emilmont 1:fdd22bb7aa52 424 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 425 {
emilmont 1:fdd22bb7aa52 426 /* Copy new input sample into the state buffer */
emilmont 1:fdd22bb7aa52 427 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 428
emilmont 1:fdd22bb7aa52 429 /* Loop over the Interpolation factor. */
emilmont 1:fdd22bb7aa52 430 i = S->L;
emilmont 1:fdd22bb7aa52 431
emilmont 1:fdd22bb7aa52 432 while(i > 0u)
emilmont 1:fdd22bb7aa52 433 {
emilmont 1:fdd22bb7aa52 434 /* Set accumulator to zero */
emilmont 1:fdd22bb7aa52 435 sum = 0;
emilmont 1:fdd22bb7aa52 436
emilmont 1:fdd22bb7aa52 437 /* Initialize state pointer */
emilmont 1:fdd22bb7aa52 438 ptr1 = pState;
emilmont 1:fdd22bb7aa52 439
emilmont 1:fdd22bb7aa52 440 /* Initialize coefficient pointer */
emilmont 1:fdd22bb7aa52 441 ptr2 = pCoeffs + (i - 1u);
emilmont 1:fdd22bb7aa52 442
emilmont 1:fdd22bb7aa52 443 /* Loop over the polyPhase length */
emilmont 1:fdd22bb7aa52 444 tapCnt = (uint32_t) phaseLen;
emilmont 1:fdd22bb7aa52 445
emilmont 1:fdd22bb7aa52 446 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 447 {
emilmont 1:fdd22bb7aa52 448 /* Read the coefficient */
emilmont 1:fdd22bb7aa52 449 c0 = *ptr2;
emilmont 1:fdd22bb7aa52 450
emilmont 1:fdd22bb7aa52 451 /* Increment the coefficient pointer by interpolation factor times. */
emilmont 1:fdd22bb7aa52 452 ptr2 += S->L;
emilmont 1:fdd22bb7aa52 453
emilmont 1:fdd22bb7aa52 454 /* Read the input sample */
emilmont 1:fdd22bb7aa52 455 x0 = *ptr1++;
emilmont 1:fdd22bb7aa52 456
emilmont 1:fdd22bb7aa52 457 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 458 sum += ((q31_t) x0 * c0);
emilmont 1:fdd22bb7aa52 459
emilmont 1:fdd22bb7aa52 460 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 461 tapCnt--;
emilmont 1:fdd22bb7aa52 462 }
emilmont 1:fdd22bb7aa52 463
emilmont 1:fdd22bb7aa52 464 /* Store the result after converting to 1.15 format in the destination buffer */
emilmont 1:fdd22bb7aa52 465 *pDst++ = (q15_t) (__SSAT((sum >> 15), 16));
emilmont 1:fdd22bb7aa52 466
emilmont 1:fdd22bb7aa52 467 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 468 i--;
emilmont 1:fdd22bb7aa52 469 }
emilmont 1:fdd22bb7aa52 470
emilmont 1:fdd22bb7aa52 471 /* Advance the state pointer by 1
emilmont 1:fdd22bb7aa52 472 * to process the next group of interpolation factor number samples */
emilmont 1:fdd22bb7aa52 473 pState = pState + 1;
emilmont 1:fdd22bb7aa52 474
emilmont 1:fdd22bb7aa52 475 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 476 blkCnt--;
emilmont 1:fdd22bb7aa52 477 }
emilmont 1:fdd22bb7aa52 478
emilmont 1:fdd22bb7aa52 479 /* Processing is complete.
emilmont 1:fdd22bb7aa52 480 ** Now copy the last phaseLen - 1 samples to the start of the state buffer.
emilmont 1:fdd22bb7aa52 481 ** This prepares the state buffer for the next function call. */
emilmont 1:fdd22bb7aa52 482
emilmont 1:fdd22bb7aa52 483 /* Points to the start of the state buffer */
emilmont 1:fdd22bb7aa52 484 pStateCurnt = S->pState;
emilmont 1:fdd22bb7aa52 485
emilmont 1:fdd22bb7aa52 486 i = (uint32_t) phaseLen - 1u;
emilmont 1:fdd22bb7aa52 487
emilmont 1:fdd22bb7aa52 488 while(i > 0u)
emilmont 1:fdd22bb7aa52 489 {
emilmont 1:fdd22bb7aa52 490 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 491
emilmont 1:fdd22bb7aa52 492 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 493 i--;
emilmont 1:fdd22bb7aa52 494 }
emilmont 1:fdd22bb7aa52 495
emilmont 1:fdd22bb7aa52 496 }
emilmont 1:fdd22bb7aa52 497
emilmont 1:fdd22bb7aa52 498 #endif /* #ifndef ARM_MATH_CM0 */
emilmont 1:fdd22bb7aa52 499
emilmont 1:fdd22bb7aa52 500
emilmont 1:fdd22bb7aa52 501 /**
emilmont 1:fdd22bb7aa52 502 * @} end of FIR_Interpolate group
emilmont 1:fdd22bb7aa52 503 */