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:
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?

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