V4.0.1 of the ARM CMSIS DSP libraries. Note that arm_bitreversal2.s, arm_cfft_f32.c and arm_rfft_fast_f32.c had to be removed. arm_bitreversal2.s will not assemble with the online tools. So, the fast f32 FFT functions are not yet available. All the other FFT functions are available.
Dependents: MPU9150_Example fir_f32 fir_f32 MPU9150_nucleo_noni2cdev ... more
FilteringFunctions/arm_fir_interpolate_q15.c@0:3d9c67d97d6f, 2014-07-28 (annotated)
- Committer:
- emh203
- Date:
- Mon Jul 28 15:03:15 2014 +0000
- Revision:
- 0:3d9c67d97d6f
1st working commit. Had to remove arm_bitreversal2.s arm_cfft_f32.c and arm_rfft_fast_f32.c. The .s will not assemble. For now I removed these functions so we could at least have a library for the other functions.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| emh203 | 0:3d9c67d97d6f | 1 | /*----------------------------------------------------------------------------- |
| emh203 | 0:3d9c67d97d6f | 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. |
| emh203 | 0:3d9c67d97d6f | 3 | * |
| emh203 | 0:3d9c67d97d6f | 4 | * $Date: 12. March 2014 |
| emh203 | 0:3d9c67d97d6f | 5 | * $Revision: V1.4.3 |
| emh203 | 0:3d9c67d97d6f | 6 | * |
| emh203 | 0:3d9c67d97d6f | 7 | * Project: CMSIS DSP Library |
| emh203 | 0:3d9c67d97d6f | 8 | * Title: arm_fir_interpolate_q15.c |
| emh203 | 0:3d9c67d97d6f | 9 | * |
| emh203 | 0:3d9c67d97d6f | 10 | * Description: Q15 FIR interpolation. |
| emh203 | 0:3d9c67d97d6f | 11 | * |
| emh203 | 0:3d9c67d97d6f | 12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 |
| emh203 | 0:3d9c67d97d6f | 13 | * |
| emh203 | 0:3d9c67d97d6f | 14 | * Redistribution and use in source and binary forms, with or without |
| emh203 | 0:3d9c67d97d6f | 15 | * modification, are permitted provided that the following conditions |
| emh203 | 0:3d9c67d97d6f | 16 | * are met: |
| emh203 | 0:3d9c67d97d6f | 17 | * - Redistributions of source code must retain the above copyright |
| emh203 | 0:3d9c67d97d6f | 18 | * notice, this list of conditions and the following disclaimer. |
| emh203 | 0:3d9c67d97d6f | 19 | * - Redistributions in binary form must reproduce the above copyright |
| emh203 | 0:3d9c67d97d6f | 20 | * notice, this list of conditions and the following disclaimer in |
| emh203 | 0:3d9c67d97d6f | 21 | * the documentation and/or other materials provided with the |
| emh203 | 0:3d9c67d97d6f | 22 | * distribution. |
| emh203 | 0:3d9c67d97d6f | 23 | * - Neither the name of ARM LIMITED nor the names of its contributors |
| emh203 | 0:3d9c67d97d6f | 24 | * may be used to endorse or promote products derived from this |
| emh203 | 0:3d9c67d97d6f | 25 | * software without specific prior written permission. |
| emh203 | 0:3d9c67d97d6f | 26 | * |
| emh203 | 0:3d9c67d97d6f | 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| emh203 | 0:3d9c67d97d6f | 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| emh203 | 0:3d9c67d97d6f | 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| emh203 | 0:3d9c67d97d6f | 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| emh203 | 0:3d9c67d97d6f | 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| emh203 | 0:3d9c67d97d6f | 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| emh203 | 0:3d9c67d97d6f | 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| emh203 | 0:3d9c67d97d6f | 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| emh203 | 0:3d9c67d97d6f | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| emh203 | 0:3d9c67d97d6f | 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| emh203 | 0:3d9c67d97d6f | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| emh203 | 0:3d9c67d97d6f | 38 | * POSSIBILITY OF SUCH DAMAGE. |
| emh203 | 0:3d9c67d97d6f | 39 | * ---------------------------------------------------------------------------*/ |
| emh203 | 0:3d9c67d97d6f | 40 | |
| emh203 | 0:3d9c67d97d6f | 41 | #include "arm_math.h" |
| emh203 | 0:3d9c67d97d6f | 42 | |
| emh203 | 0:3d9c67d97d6f | 43 | /** |
| emh203 | 0:3d9c67d97d6f | 44 | * @ingroup groupFilters |
| emh203 | 0:3d9c67d97d6f | 45 | */ |
| emh203 | 0:3d9c67d97d6f | 46 | |
| emh203 | 0:3d9c67d97d6f | 47 | /** |
| emh203 | 0:3d9c67d97d6f | 48 | * @addtogroup FIR_Interpolate |
| emh203 | 0:3d9c67d97d6f | 49 | * @{ |
| emh203 | 0:3d9c67d97d6f | 50 | */ |
| emh203 | 0:3d9c67d97d6f | 51 | |
| emh203 | 0:3d9c67d97d6f | 52 | /** |
| emh203 | 0:3d9c67d97d6f | 53 | * @brief Processing function for the Q15 FIR interpolator. |
| emh203 | 0:3d9c67d97d6f | 54 | * @param[in] *S points to an instance of the Q15 FIR interpolator structure. |
| emh203 | 0:3d9c67d97d6f | 55 | * @param[in] *pSrc points to the block of input data. |
| emh203 | 0:3d9c67d97d6f | 56 | * @param[out] *pDst points to the block of output data. |
| emh203 | 0:3d9c67d97d6f | 57 | * @param[in] blockSize number of input samples to process per call. |
| emh203 | 0:3d9c67d97d6f | 58 | * @return none. |
| emh203 | 0:3d9c67d97d6f | 59 | * |
| emh203 | 0:3d9c67d97d6f | 60 | * <b>Scaling and Overflow Behavior:</b> |
| emh203 | 0:3d9c67d97d6f | 61 | * \par |
| emh203 | 0:3d9c67d97d6f | 62 | * The function is implemented using a 64-bit internal accumulator. |
| emh203 | 0:3d9c67d97d6f | 63 | * Both coefficients and state variables are represented in 1.15 format and multiplications yield a 2.30 result. |
| emh203 | 0:3d9c67d97d6f | 64 | * The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. |
| emh203 | 0:3d9c67d97d6f | 65 | * There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. |
| emh203 | 0:3d9c67d97d6f | 66 | * After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits. |
| emh203 | 0:3d9c67d97d6f | 67 | * Lastly, the accumulator is saturated to yield a result in 1.15 format. |
| emh203 | 0:3d9c67d97d6f | 68 | */ |
| emh203 | 0:3d9c67d97d6f | 69 | |
| emh203 | 0:3d9c67d97d6f | 70 | #ifndef ARM_MATH_CM0_FAMILY |
| emh203 | 0:3d9c67d97d6f | 71 | |
| emh203 | 0:3d9c67d97d6f | 72 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
| emh203 | 0:3d9c67d97d6f | 73 | |
| emh203 | 0:3d9c67d97d6f | 74 | void arm_fir_interpolate_q15( |
| emh203 | 0:3d9c67d97d6f | 75 | const arm_fir_interpolate_instance_q15 * S, |
| emh203 | 0:3d9c67d97d6f | 76 | q15_t * pSrc, |
| emh203 | 0:3d9c67d97d6f | 77 | q15_t * pDst, |
| emh203 | 0:3d9c67d97d6f | 78 | uint32_t blockSize) |
| emh203 | 0:3d9c67d97d6f | 79 | { |
| emh203 | 0:3d9c67d97d6f | 80 | q15_t *pState = S->pState; /* State pointer */ |
| emh203 | 0:3d9c67d97d6f | 81 | q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
| emh203 | 0:3d9c67d97d6f | 82 | q15_t *pStateCurnt; /* Points to the current sample of the state */ |
| emh203 | 0:3d9c67d97d6f | 83 | q15_t *ptr1, *ptr2; /* Temporary pointers for state and coefficient buffers */ |
| emh203 | 0:3d9c67d97d6f | 84 | q63_t sum0; /* Accumulators */ |
| emh203 | 0:3d9c67d97d6f | 85 | q15_t x0, c0; /* Temporary variables to hold state and coefficient values */ |
| emh203 | 0:3d9c67d97d6f | 86 | uint32_t i, blkCnt, j, tapCnt; /* Loop counters */ |
| emh203 | 0:3d9c67d97d6f | 87 | uint16_t phaseLen = S->phaseLength; /* Length of each polyphase filter component */ |
| emh203 | 0:3d9c67d97d6f | 88 | uint32_t blkCntN2; |
| emh203 | 0:3d9c67d97d6f | 89 | q63_t acc0, acc1; |
| emh203 | 0:3d9c67d97d6f | 90 | q15_t x1; |
| emh203 | 0:3d9c67d97d6f | 91 | |
| emh203 | 0:3d9c67d97d6f | 92 | /* S->pState buffer contains previous frame (phaseLen - 1) samples */ |
| emh203 | 0:3d9c67d97d6f | 93 | /* pStateCurnt points to the location where the new input data should be written */ |
| emh203 | 0:3d9c67d97d6f | 94 | pStateCurnt = S->pState + ((q31_t) phaseLen - 1); |
| emh203 | 0:3d9c67d97d6f | 95 | |
| emh203 | 0:3d9c67d97d6f | 96 | /* Initialise blkCnt */ |
| emh203 | 0:3d9c67d97d6f | 97 | blkCnt = blockSize / 2; |
| emh203 | 0:3d9c67d97d6f | 98 | blkCntN2 = blockSize - (2 * blkCnt); |
| emh203 | 0:3d9c67d97d6f | 99 | |
| emh203 | 0:3d9c67d97d6f | 100 | /* Samples loop unrolled by 2 */ |
| emh203 | 0:3d9c67d97d6f | 101 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 102 | { |
| emh203 | 0:3d9c67d97d6f | 103 | /* Copy new input sample into the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 104 | *pStateCurnt++ = *pSrc++; |
| emh203 | 0:3d9c67d97d6f | 105 | *pStateCurnt++ = *pSrc++; |
| emh203 | 0:3d9c67d97d6f | 106 | |
| emh203 | 0:3d9c67d97d6f | 107 | /* Address modifier index of coefficient buffer */ |
| emh203 | 0:3d9c67d97d6f | 108 | j = 1u; |
| emh203 | 0:3d9c67d97d6f | 109 | |
| emh203 | 0:3d9c67d97d6f | 110 | /* Loop over the Interpolation factor. */ |
| emh203 | 0:3d9c67d97d6f | 111 | i = (S->L); |
| emh203 | 0:3d9c67d97d6f | 112 | |
| emh203 | 0:3d9c67d97d6f | 113 | while(i > 0u) |
| emh203 | 0:3d9c67d97d6f | 114 | { |
| emh203 | 0:3d9c67d97d6f | 115 | /* Set accumulator to zero */ |
| emh203 | 0:3d9c67d97d6f | 116 | acc0 = 0; |
| emh203 | 0:3d9c67d97d6f | 117 | acc1 = 0; |
| emh203 | 0:3d9c67d97d6f | 118 | |
| emh203 | 0:3d9c67d97d6f | 119 | /* Initialize state pointer */ |
| emh203 | 0:3d9c67d97d6f | 120 | ptr1 = pState; |
| emh203 | 0:3d9c67d97d6f | 121 | |
| emh203 | 0:3d9c67d97d6f | 122 | /* Initialize coefficient pointer */ |
| emh203 | 0:3d9c67d97d6f | 123 | ptr2 = pCoeffs + (S->L - j); |
| emh203 | 0:3d9c67d97d6f | 124 | |
| emh203 | 0:3d9c67d97d6f | 125 | /* Loop over the polyPhase length. Unroll by a factor of 4. |
| emh203 | 0:3d9c67d97d6f | 126 | ** Repeat until we've computed numTaps-(4*S->L) coefficients. */ |
| emh203 | 0:3d9c67d97d6f | 127 | tapCnt = phaseLen >> 2u; |
| emh203 | 0:3d9c67d97d6f | 128 | |
| emh203 | 0:3d9c67d97d6f | 129 | x0 = *(ptr1++); |
| emh203 | 0:3d9c67d97d6f | 130 | |
| emh203 | 0:3d9c67d97d6f | 131 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 132 | { |
| emh203 | 0:3d9c67d97d6f | 133 | |
| emh203 | 0:3d9c67d97d6f | 134 | /* Read the input sample */ |
| emh203 | 0:3d9c67d97d6f | 135 | x1 = *(ptr1++); |
| emh203 | 0:3d9c67d97d6f | 136 | |
| emh203 | 0:3d9c67d97d6f | 137 | /* Read the coefficient */ |
| emh203 | 0:3d9c67d97d6f | 138 | c0 = *(ptr2); |
| emh203 | 0:3d9c67d97d6f | 139 | |
| emh203 | 0:3d9c67d97d6f | 140 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 141 | acc0 += (q63_t) x0 *c0; |
| emh203 | 0:3d9c67d97d6f | 142 | acc1 += (q63_t) x1 *c0; |
| emh203 | 0:3d9c67d97d6f | 143 | |
| emh203 | 0:3d9c67d97d6f | 144 | |
| emh203 | 0:3d9c67d97d6f | 145 | /* Read the coefficient */ |
| emh203 | 0:3d9c67d97d6f | 146 | c0 = *(ptr2 + S->L); |
| emh203 | 0:3d9c67d97d6f | 147 | |
| emh203 | 0:3d9c67d97d6f | 148 | /* Read the input sample */ |
| emh203 | 0:3d9c67d97d6f | 149 | x0 = *(ptr1++); |
| emh203 | 0:3d9c67d97d6f | 150 | |
| emh203 | 0:3d9c67d97d6f | 151 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 152 | acc0 += (q63_t) x1 *c0; |
| emh203 | 0:3d9c67d97d6f | 153 | acc1 += (q63_t) x0 *c0; |
| emh203 | 0:3d9c67d97d6f | 154 | |
| emh203 | 0:3d9c67d97d6f | 155 | |
| emh203 | 0:3d9c67d97d6f | 156 | /* Read the coefficient */ |
| emh203 | 0:3d9c67d97d6f | 157 | c0 = *(ptr2 + S->L * 2); |
| emh203 | 0:3d9c67d97d6f | 158 | |
| emh203 | 0:3d9c67d97d6f | 159 | /* Read the input sample */ |
| emh203 | 0:3d9c67d97d6f | 160 | x1 = *(ptr1++); |
| emh203 | 0:3d9c67d97d6f | 161 | |
| emh203 | 0:3d9c67d97d6f | 162 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 163 | acc0 += (q63_t) x0 *c0; |
| emh203 | 0:3d9c67d97d6f | 164 | acc1 += (q63_t) x1 *c0; |
| emh203 | 0:3d9c67d97d6f | 165 | |
| emh203 | 0:3d9c67d97d6f | 166 | /* Read the coefficient */ |
| emh203 | 0:3d9c67d97d6f | 167 | c0 = *(ptr2 + S->L * 3); |
| emh203 | 0:3d9c67d97d6f | 168 | |
| emh203 | 0:3d9c67d97d6f | 169 | /* Read the input sample */ |
| emh203 | 0:3d9c67d97d6f | 170 | x0 = *(ptr1++); |
| emh203 | 0:3d9c67d97d6f | 171 | |
| emh203 | 0:3d9c67d97d6f | 172 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 173 | acc0 += (q63_t) x1 *c0; |
| emh203 | 0:3d9c67d97d6f | 174 | acc1 += (q63_t) x0 *c0; |
| emh203 | 0:3d9c67d97d6f | 175 | |
| emh203 | 0:3d9c67d97d6f | 176 | |
| emh203 | 0:3d9c67d97d6f | 177 | /* Upsampling is done by stuffing L-1 zeros between each sample. |
| emh203 | 0:3d9c67d97d6f | 178 | * So instead of multiplying zeros with coefficients, |
| emh203 | 0:3d9c67d97d6f | 179 | * Increment the coefficient pointer by interpolation factor times. */ |
| emh203 | 0:3d9c67d97d6f | 180 | ptr2 += 4 * S->L; |
| emh203 | 0:3d9c67d97d6f | 181 | |
| emh203 | 0:3d9c67d97d6f | 182 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 183 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 184 | } |
| emh203 | 0:3d9c67d97d6f | 185 | |
| emh203 | 0:3d9c67d97d6f | 186 | /* If the polyPhase length is not a multiple of 4, compute the remaining filter taps */ |
| emh203 | 0:3d9c67d97d6f | 187 | tapCnt = phaseLen % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 188 | |
| emh203 | 0:3d9c67d97d6f | 189 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 190 | { |
| emh203 | 0:3d9c67d97d6f | 191 | |
| emh203 | 0:3d9c67d97d6f | 192 | /* Read the input sample */ |
| emh203 | 0:3d9c67d97d6f | 193 | x1 = *(ptr1++); |
| emh203 | 0:3d9c67d97d6f | 194 | |
| emh203 | 0:3d9c67d97d6f | 195 | /* Read the coefficient */ |
| emh203 | 0:3d9c67d97d6f | 196 | c0 = *(ptr2); |
| emh203 | 0:3d9c67d97d6f | 197 | |
| emh203 | 0:3d9c67d97d6f | 198 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 199 | acc0 += (q63_t) x0 *c0; |
| emh203 | 0:3d9c67d97d6f | 200 | acc1 += (q63_t) x1 *c0; |
| emh203 | 0:3d9c67d97d6f | 201 | |
| emh203 | 0:3d9c67d97d6f | 202 | /* Increment the coefficient pointer by interpolation factor times. */ |
| emh203 | 0:3d9c67d97d6f | 203 | ptr2 += S->L; |
| emh203 | 0:3d9c67d97d6f | 204 | |
| emh203 | 0:3d9c67d97d6f | 205 | /* update states for next sample processing */ |
| emh203 | 0:3d9c67d97d6f | 206 | x0 = x1; |
| emh203 | 0:3d9c67d97d6f | 207 | |
| emh203 | 0:3d9c67d97d6f | 208 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 209 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 210 | } |
| emh203 | 0:3d9c67d97d6f | 211 | |
| emh203 | 0:3d9c67d97d6f | 212 | /* The result is in the accumulator, store in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 213 | *pDst = (q15_t) (__SSAT((acc0 >> 15), 16)); |
| emh203 | 0:3d9c67d97d6f | 214 | *(pDst + S->L) = (q15_t) (__SSAT((acc1 >> 15), 16)); |
| emh203 | 0:3d9c67d97d6f | 215 | |
| emh203 | 0:3d9c67d97d6f | 216 | pDst++; |
| emh203 | 0:3d9c67d97d6f | 217 | |
| emh203 | 0:3d9c67d97d6f | 218 | /* Increment the address modifier index of coefficient buffer */ |
| emh203 | 0:3d9c67d97d6f | 219 | j++; |
| emh203 | 0:3d9c67d97d6f | 220 | |
| emh203 | 0:3d9c67d97d6f | 221 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 222 | i--; |
| emh203 | 0:3d9c67d97d6f | 223 | } |
| emh203 | 0:3d9c67d97d6f | 224 | |
| emh203 | 0:3d9c67d97d6f | 225 | /* Advance the state pointer by 1 |
| emh203 | 0:3d9c67d97d6f | 226 | * to process the next group of interpolation factor number samples */ |
| emh203 | 0:3d9c67d97d6f | 227 | pState = pState + 2; |
| emh203 | 0:3d9c67d97d6f | 228 | |
| emh203 | 0:3d9c67d97d6f | 229 | pDst += S->L; |
| emh203 | 0:3d9c67d97d6f | 230 | |
| emh203 | 0:3d9c67d97d6f | 231 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 232 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 233 | } |
| emh203 | 0:3d9c67d97d6f | 234 | |
| emh203 | 0:3d9c67d97d6f | 235 | /* If the blockSize is not a multiple of 2, compute any remaining output samples here. |
| emh203 | 0:3d9c67d97d6f | 236 | ** No loop unrolling is used. */ |
| emh203 | 0:3d9c67d97d6f | 237 | blkCnt = blkCntN2; |
| emh203 | 0:3d9c67d97d6f | 238 | |
| emh203 | 0:3d9c67d97d6f | 239 | /* Loop over the blockSize. */ |
| emh203 | 0:3d9c67d97d6f | 240 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 241 | { |
| emh203 | 0:3d9c67d97d6f | 242 | /* Copy new input sample into the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 243 | *pStateCurnt++ = *pSrc++; |
| emh203 | 0:3d9c67d97d6f | 244 | |
| emh203 | 0:3d9c67d97d6f | 245 | /* Address modifier index of coefficient buffer */ |
| emh203 | 0:3d9c67d97d6f | 246 | j = 1u; |
| emh203 | 0:3d9c67d97d6f | 247 | |
| emh203 | 0:3d9c67d97d6f | 248 | /* Loop over the Interpolation factor. */ |
| emh203 | 0:3d9c67d97d6f | 249 | i = S->L; |
| emh203 | 0:3d9c67d97d6f | 250 | while(i > 0u) |
| emh203 | 0:3d9c67d97d6f | 251 | { |
| emh203 | 0:3d9c67d97d6f | 252 | /* Set accumulator to zero */ |
| emh203 | 0:3d9c67d97d6f | 253 | sum0 = 0; |
| emh203 | 0:3d9c67d97d6f | 254 | |
| emh203 | 0:3d9c67d97d6f | 255 | /* Initialize state pointer */ |
| emh203 | 0:3d9c67d97d6f | 256 | ptr1 = pState; |
| emh203 | 0:3d9c67d97d6f | 257 | |
| emh203 | 0:3d9c67d97d6f | 258 | /* Initialize coefficient pointer */ |
| emh203 | 0:3d9c67d97d6f | 259 | ptr2 = pCoeffs + (S->L - j); |
| emh203 | 0:3d9c67d97d6f | 260 | |
| emh203 | 0:3d9c67d97d6f | 261 | /* Loop over the polyPhase length. Unroll by a factor of 4. |
| emh203 | 0:3d9c67d97d6f | 262 | ** Repeat until we've computed numTaps-(4*S->L) coefficients. */ |
| emh203 | 0:3d9c67d97d6f | 263 | tapCnt = phaseLen >> 2; |
| emh203 | 0:3d9c67d97d6f | 264 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 265 | { |
| emh203 | 0:3d9c67d97d6f | 266 | |
| emh203 | 0:3d9c67d97d6f | 267 | /* Read the coefficient */ |
| emh203 | 0:3d9c67d97d6f | 268 | c0 = *(ptr2); |
| emh203 | 0:3d9c67d97d6f | 269 | |
| emh203 | 0:3d9c67d97d6f | 270 | /* Upsampling is done by stuffing L-1 zeros between each sample. |
| emh203 | 0:3d9c67d97d6f | 271 | * So instead of multiplying zeros with coefficients, |
| emh203 | 0:3d9c67d97d6f | 272 | * Increment the coefficient pointer by interpolation factor times. */ |
| emh203 | 0:3d9c67d97d6f | 273 | ptr2 += S->L; |
| emh203 | 0:3d9c67d97d6f | 274 | |
| emh203 | 0:3d9c67d97d6f | 275 | /* Read the input sample */ |
| emh203 | 0:3d9c67d97d6f | 276 | x0 = *(ptr1++); |
| emh203 | 0:3d9c67d97d6f | 277 | |
| emh203 | 0:3d9c67d97d6f | 278 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 279 | sum0 += (q63_t) x0 *c0; |
| emh203 | 0:3d9c67d97d6f | 280 | |
| emh203 | 0:3d9c67d97d6f | 281 | /* Read the coefficient */ |
| emh203 | 0:3d9c67d97d6f | 282 | c0 = *(ptr2); |
| emh203 | 0:3d9c67d97d6f | 283 | |
| emh203 | 0:3d9c67d97d6f | 284 | /* Increment the coefficient pointer by interpolation factor times. */ |
| emh203 | 0:3d9c67d97d6f | 285 | ptr2 += S->L; |
| emh203 | 0:3d9c67d97d6f | 286 | |
| emh203 | 0:3d9c67d97d6f | 287 | /* Read the input sample */ |
| emh203 | 0:3d9c67d97d6f | 288 | x0 = *(ptr1++); |
| emh203 | 0:3d9c67d97d6f | 289 | |
| emh203 | 0:3d9c67d97d6f | 290 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 291 | sum0 += (q63_t) x0 *c0; |
| emh203 | 0:3d9c67d97d6f | 292 | |
| emh203 | 0:3d9c67d97d6f | 293 | /* Read the coefficient */ |
| emh203 | 0:3d9c67d97d6f | 294 | c0 = *(ptr2); |
| emh203 | 0:3d9c67d97d6f | 295 | |
| emh203 | 0:3d9c67d97d6f | 296 | /* Increment the coefficient pointer by interpolation factor times. */ |
| emh203 | 0:3d9c67d97d6f | 297 | ptr2 += S->L; |
| emh203 | 0:3d9c67d97d6f | 298 | |
| emh203 | 0:3d9c67d97d6f | 299 | /* Read the input sample */ |
| emh203 | 0:3d9c67d97d6f | 300 | x0 = *(ptr1++); |
| emh203 | 0:3d9c67d97d6f | 301 | |
| emh203 | 0:3d9c67d97d6f | 302 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 303 | sum0 += (q63_t) x0 *c0; |
| emh203 | 0:3d9c67d97d6f | 304 | |
| emh203 | 0:3d9c67d97d6f | 305 | /* Read the coefficient */ |
| emh203 | 0:3d9c67d97d6f | 306 | c0 = *(ptr2); |
| emh203 | 0:3d9c67d97d6f | 307 | |
| emh203 | 0:3d9c67d97d6f | 308 | /* Increment the coefficient pointer by interpolation factor times. */ |
| emh203 | 0:3d9c67d97d6f | 309 | ptr2 += S->L; |
| emh203 | 0:3d9c67d97d6f | 310 | |
| emh203 | 0:3d9c67d97d6f | 311 | /* Read the input sample */ |
| emh203 | 0:3d9c67d97d6f | 312 | x0 = *(ptr1++); |
| emh203 | 0:3d9c67d97d6f | 313 | |
| emh203 | 0:3d9c67d97d6f | 314 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 315 | sum0 += (q63_t) x0 *c0; |
| emh203 | 0:3d9c67d97d6f | 316 | |
| emh203 | 0:3d9c67d97d6f | 317 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 318 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 319 | } |
| emh203 | 0:3d9c67d97d6f | 320 | |
| emh203 | 0:3d9c67d97d6f | 321 | /* If the polyPhase length is not a multiple of 4, compute the remaining filter taps */ |
| emh203 | 0:3d9c67d97d6f | 322 | tapCnt = phaseLen & 0x3u; |
| emh203 | 0:3d9c67d97d6f | 323 | |
| emh203 | 0:3d9c67d97d6f | 324 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 325 | { |
| emh203 | 0:3d9c67d97d6f | 326 | /* Read the coefficient */ |
| emh203 | 0:3d9c67d97d6f | 327 | c0 = *(ptr2); |
| emh203 | 0:3d9c67d97d6f | 328 | |
| emh203 | 0:3d9c67d97d6f | 329 | /* Increment the coefficient pointer by interpolation factor times. */ |
| emh203 | 0:3d9c67d97d6f | 330 | ptr2 += S->L; |
| emh203 | 0:3d9c67d97d6f | 331 | |
| emh203 | 0:3d9c67d97d6f | 332 | /* Read the input sample */ |
| emh203 | 0:3d9c67d97d6f | 333 | x0 = *(ptr1++); |
| emh203 | 0:3d9c67d97d6f | 334 | |
| emh203 | 0:3d9c67d97d6f | 335 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 336 | sum0 += (q63_t) x0 *c0; |
| emh203 | 0:3d9c67d97d6f | 337 | |
| emh203 | 0:3d9c67d97d6f | 338 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 339 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 340 | } |
| emh203 | 0:3d9c67d97d6f | 341 | |
| emh203 | 0:3d9c67d97d6f | 342 | /* The result is in the accumulator, store in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 343 | *pDst++ = (q15_t) (__SSAT((sum0 >> 15), 16)); |
| emh203 | 0:3d9c67d97d6f | 344 | |
| emh203 | 0:3d9c67d97d6f | 345 | j++; |
| emh203 | 0:3d9c67d97d6f | 346 | |
| emh203 | 0:3d9c67d97d6f | 347 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 348 | i--; |
| emh203 | 0:3d9c67d97d6f | 349 | } |
| emh203 | 0:3d9c67d97d6f | 350 | |
| emh203 | 0:3d9c67d97d6f | 351 | /* Advance the state pointer by 1 |
| emh203 | 0:3d9c67d97d6f | 352 | * to process the next group of interpolation factor number samples */ |
| emh203 | 0:3d9c67d97d6f | 353 | pState = pState + 1; |
| emh203 | 0:3d9c67d97d6f | 354 | |
| emh203 | 0:3d9c67d97d6f | 355 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 356 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 357 | } |
| emh203 | 0:3d9c67d97d6f | 358 | |
| emh203 | 0:3d9c67d97d6f | 359 | |
| emh203 | 0:3d9c67d97d6f | 360 | /* Processing is complete. |
| emh203 | 0:3d9c67d97d6f | 361 | ** Now copy the last phaseLen - 1 samples to the satrt of the state buffer. |
| emh203 | 0:3d9c67d97d6f | 362 | ** This prepares the state buffer for the next function call. */ |
| emh203 | 0:3d9c67d97d6f | 363 | |
| emh203 | 0:3d9c67d97d6f | 364 | /* Points to the start of the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 365 | pStateCurnt = S->pState; |
| emh203 | 0:3d9c67d97d6f | 366 | |
| emh203 | 0:3d9c67d97d6f | 367 | i = ((uint32_t) phaseLen - 1u) >> 2u; |
| emh203 | 0:3d9c67d97d6f | 368 | |
| emh203 | 0:3d9c67d97d6f | 369 | /* copy data */ |
| emh203 | 0:3d9c67d97d6f | 370 | while(i > 0u) |
| emh203 | 0:3d9c67d97d6f | 371 | { |
| emh203 | 0:3d9c67d97d6f | 372 | #ifndef UNALIGNED_SUPPORT_DISABLE |
| emh203 | 0:3d9c67d97d6f | 373 | |
| emh203 | 0:3d9c67d97d6f | 374 | *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++; |
| emh203 | 0:3d9c67d97d6f | 375 | *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++; |
| emh203 | 0:3d9c67d97d6f | 376 | |
| emh203 | 0:3d9c67d97d6f | 377 | #else |
| emh203 | 0:3d9c67d97d6f | 378 | |
| emh203 | 0:3d9c67d97d6f | 379 | *pStateCurnt++ = *pState++; |
| emh203 | 0:3d9c67d97d6f | 380 | *pStateCurnt++ = *pState++; |
| emh203 | 0:3d9c67d97d6f | 381 | *pStateCurnt++ = *pState++; |
| emh203 | 0:3d9c67d97d6f | 382 | *pStateCurnt++ = *pState++; |
| emh203 | 0:3d9c67d97d6f | 383 | |
| emh203 | 0:3d9c67d97d6f | 384 | #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */ |
| emh203 | 0:3d9c67d97d6f | 385 | |
| emh203 | 0:3d9c67d97d6f | 386 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 387 | i--; |
| emh203 | 0:3d9c67d97d6f | 388 | } |
| emh203 | 0:3d9c67d97d6f | 389 | |
| emh203 | 0:3d9c67d97d6f | 390 | i = ((uint32_t) phaseLen - 1u) % 0x04u; |
| emh203 | 0:3d9c67d97d6f | 391 | |
| emh203 | 0:3d9c67d97d6f | 392 | while(i > 0u) |
| emh203 | 0:3d9c67d97d6f | 393 | { |
| emh203 | 0:3d9c67d97d6f | 394 | *pStateCurnt++ = *pState++; |
| emh203 | 0:3d9c67d97d6f | 395 | |
| emh203 | 0:3d9c67d97d6f | 396 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 397 | i--; |
| emh203 | 0:3d9c67d97d6f | 398 | } |
| emh203 | 0:3d9c67d97d6f | 399 | } |
| emh203 | 0:3d9c67d97d6f | 400 | |
| emh203 | 0:3d9c67d97d6f | 401 | #else |
| emh203 | 0:3d9c67d97d6f | 402 | |
| emh203 | 0:3d9c67d97d6f | 403 | /* Run the below code for Cortex-M0 */ |
| emh203 | 0:3d9c67d97d6f | 404 | |
| emh203 | 0:3d9c67d97d6f | 405 | void arm_fir_interpolate_q15( |
| emh203 | 0:3d9c67d97d6f | 406 | const arm_fir_interpolate_instance_q15 * S, |
| emh203 | 0:3d9c67d97d6f | 407 | q15_t * pSrc, |
| emh203 | 0:3d9c67d97d6f | 408 | q15_t * pDst, |
| emh203 | 0:3d9c67d97d6f | 409 | uint32_t blockSize) |
| emh203 | 0:3d9c67d97d6f | 410 | { |
| emh203 | 0:3d9c67d97d6f | 411 | q15_t *pState = S->pState; /* State pointer */ |
| emh203 | 0:3d9c67d97d6f | 412 | q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
| emh203 | 0:3d9c67d97d6f | 413 | q15_t *pStateCurnt; /* Points to the current sample of the state */ |
| emh203 | 0:3d9c67d97d6f | 414 | q15_t *ptr1, *ptr2; /* Temporary pointers for state and coefficient buffers */ |
| emh203 | 0:3d9c67d97d6f | 415 | q63_t sum; /* Accumulator */ |
| emh203 | 0:3d9c67d97d6f | 416 | q15_t x0, c0; /* Temporary variables to hold state and coefficient values */ |
| emh203 | 0:3d9c67d97d6f | 417 | uint32_t i, blkCnt, tapCnt; /* Loop counters */ |
| emh203 | 0:3d9c67d97d6f | 418 | uint16_t phaseLen = S->phaseLength; /* Length of each polyphase filter component */ |
| emh203 | 0:3d9c67d97d6f | 419 | |
| emh203 | 0:3d9c67d97d6f | 420 | |
| emh203 | 0:3d9c67d97d6f | 421 | /* S->pState buffer contains previous frame (phaseLen - 1) samples */ |
| emh203 | 0:3d9c67d97d6f | 422 | /* pStateCurnt points to the location where the new input data should be written */ |
| emh203 | 0:3d9c67d97d6f | 423 | pStateCurnt = S->pState + (phaseLen - 1u); |
| emh203 | 0:3d9c67d97d6f | 424 | |
| emh203 | 0:3d9c67d97d6f | 425 | /* Total number of intput samples */ |
| emh203 | 0:3d9c67d97d6f | 426 | blkCnt = blockSize; |
| emh203 | 0:3d9c67d97d6f | 427 | |
| emh203 | 0:3d9c67d97d6f | 428 | /* Loop over the blockSize. */ |
| emh203 | 0:3d9c67d97d6f | 429 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 430 | { |
| emh203 | 0:3d9c67d97d6f | 431 | /* Copy new input sample into the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 432 | *pStateCurnt++ = *pSrc++; |
| emh203 | 0:3d9c67d97d6f | 433 | |
| emh203 | 0:3d9c67d97d6f | 434 | /* Loop over the Interpolation factor. */ |
| emh203 | 0:3d9c67d97d6f | 435 | i = S->L; |
| emh203 | 0:3d9c67d97d6f | 436 | |
| emh203 | 0:3d9c67d97d6f | 437 | while(i > 0u) |
| emh203 | 0:3d9c67d97d6f | 438 | { |
| emh203 | 0:3d9c67d97d6f | 439 | /* Set accumulator to zero */ |
| emh203 | 0:3d9c67d97d6f | 440 | sum = 0; |
| emh203 | 0:3d9c67d97d6f | 441 | |
| emh203 | 0:3d9c67d97d6f | 442 | /* Initialize state pointer */ |
| emh203 | 0:3d9c67d97d6f | 443 | ptr1 = pState; |
| emh203 | 0:3d9c67d97d6f | 444 | |
| emh203 | 0:3d9c67d97d6f | 445 | /* Initialize coefficient pointer */ |
| emh203 | 0:3d9c67d97d6f | 446 | ptr2 = pCoeffs + (i - 1u); |
| emh203 | 0:3d9c67d97d6f | 447 | |
| emh203 | 0:3d9c67d97d6f | 448 | /* Loop over the polyPhase length */ |
| emh203 | 0:3d9c67d97d6f | 449 | tapCnt = (uint32_t) phaseLen; |
| emh203 | 0:3d9c67d97d6f | 450 | |
| emh203 | 0:3d9c67d97d6f | 451 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 452 | { |
| emh203 | 0:3d9c67d97d6f | 453 | /* Read the coefficient */ |
| emh203 | 0:3d9c67d97d6f | 454 | c0 = *ptr2; |
| emh203 | 0:3d9c67d97d6f | 455 | |
| emh203 | 0:3d9c67d97d6f | 456 | /* Increment the coefficient pointer by interpolation factor times. */ |
| emh203 | 0:3d9c67d97d6f | 457 | ptr2 += S->L; |
| emh203 | 0:3d9c67d97d6f | 458 | |
| emh203 | 0:3d9c67d97d6f | 459 | /* Read the input sample */ |
| emh203 | 0:3d9c67d97d6f | 460 | x0 = *ptr1++; |
| emh203 | 0:3d9c67d97d6f | 461 | |
| emh203 | 0:3d9c67d97d6f | 462 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 463 | sum += ((q31_t) x0 * c0); |
| emh203 | 0:3d9c67d97d6f | 464 | |
| emh203 | 0:3d9c67d97d6f | 465 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 466 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 467 | } |
| emh203 | 0:3d9c67d97d6f | 468 | |
| emh203 | 0:3d9c67d97d6f | 469 | /* Store the result after converting to 1.15 format in the destination buffer */ |
| emh203 | 0:3d9c67d97d6f | 470 | *pDst++ = (q15_t) (__SSAT((sum >> 15), 16)); |
| emh203 | 0:3d9c67d97d6f | 471 | |
| emh203 | 0:3d9c67d97d6f | 472 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 473 | i--; |
| emh203 | 0:3d9c67d97d6f | 474 | } |
| emh203 | 0:3d9c67d97d6f | 475 | |
| emh203 | 0:3d9c67d97d6f | 476 | /* Advance the state pointer by 1 |
| emh203 | 0:3d9c67d97d6f | 477 | * to process the next group of interpolation factor number samples */ |
| emh203 | 0:3d9c67d97d6f | 478 | pState = pState + 1; |
| emh203 | 0:3d9c67d97d6f | 479 | |
| emh203 | 0:3d9c67d97d6f | 480 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 481 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 482 | } |
| emh203 | 0:3d9c67d97d6f | 483 | |
| emh203 | 0:3d9c67d97d6f | 484 | /* Processing is complete. |
| emh203 | 0:3d9c67d97d6f | 485 | ** Now copy the last phaseLen - 1 samples to the start of the state buffer. |
| emh203 | 0:3d9c67d97d6f | 486 | ** This prepares the state buffer for the next function call. */ |
| emh203 | 0:3d9c67d97d6f | 487 | |
| emh203 | 0:3d9c67d97d6f | 488 | /* Points to the start of the state buffer */ |
| emh203 | 0:3d9c67d97d6f | 489 | pStateCurnt = S->pState; |
| emh203 | 0:3d9c67d97d6f | 490 | |
| emh203 | 0:3d9c67d97d6f | 491 | i = (uint32_t) phaseLen - 1u; |
| emh203 | 0:3d9c67d97d6f | 492 | |
| emh203 | 0:3d9c67d97d6f | 493 | while(i > 0u) |
| emh203 | 0:3d9c67d97d6f | 494 | { |
| emh203 | 0:3d9c67d97d6f | 495 | *pStateCurnt++ = *pState++; |
| emh203 | 0:3d9c67d97d6f | 496 | |
| emh203 | 0:3d9c67d97d6f | 497 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 498 | i--; |
| emh203 | 0:3d9c67d97d6f | 499 | } |
| emh203 | 0:3d9c67d97d6f | 500 | |
| emh203 | 0:3d9c67d97d6f | 501 | } |
| emh203 | 0:3d9c67d97d6f | 502 | |
| emh203 | 0:3d9c67d97d6f | 503 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
| emh203 | 0:3d9c67d97d6f | 504 | |
| emh203 | 0:3d9c67d97d6f | 505 | |
| emh203 | 0:3d9c67d97d6f | 506 | /** |
| emh203 | 0:3d9c67d97d6f | 507 | * @} end of FIR_Interpolate group |
| emh203 | 0:3d9c67d97d6f | 508 | */ |
Eli Hughes