1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
7 * Project: CMSIS DSP Library
8 * Title: arm_rfft_q15.c
10 * Description: RFFT & RIFFT Q15 process function
13 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
15 * Version 1.0.10 2011/7/15
16 * Big Endian support added and Merged M0 and M3/M4 Source code.
18 * Version 1.0.3 2010/11/29
19 * Re-organized the CMSIS folders and updated documentation.
21 * Version 1.0.2 2010/11/11
22 * Documentation updated.
24 * Version 1.0.1 2010/10/05
25 * Production release and review comments incorporated.
27 * Version 1.0.0 2010/09/20
28 * Production release and review comments incorporated
30 * Version 0.0.7 2010/06/10
31 * Misra-C changes done
32 * -------------------------------------------------------------------- */
37 /*--------------------------------------------------------------------
38 * Internal functions prototypes
39 --------------------------------------------------------------------*/
41 void arm_split_rfft_q15(
49 void arm_split_rifft_q15(
58 * @addtogroup RFFT_RIFFT
63 * @brief Processing function for the Q15 RFFT/RIFFT.
64 * @param[in] *S points to an instance of the Q15 RFFT/RIFFT structure.
65 * @param[in] *pSrc points to the input buffer.
66 * @param[out] *pDst points to the output buffer.
69 * \par Input an output formats:
71 * Internally input is downscaled by 2 for every stage to avoid saturations inside CFFT/CIFFT process.
72 * Hence the output format is different for different RFFT sizes.
73 * The input and output formats for different RFFT sizes and number of bits to upscale are mentioned in the tables below for RFFT and RIFFT:
75 * \image html RFFTQ15.gif "Input and Output Formats for Q15 RFFT"
77 * \image html RIFFTQ15.gif "Input and Output Formats for Q15 RIFFT"
81 const arm_rfft_instance_q15 * S,
85 const arm_cfft_radix4_instance_q15 *S_CFFT = S->pCfft;
87 /* Calculation of RIFFT of input */
88 if(S->ifftFlagR == 1u)
90 /* Real IFFT core process */
91 arm_split_rifft_q15(pSrc, S->fftLenBy2, S->pTwiddleAReal,
92 S->pTwiddleBReal, pDst, S->twidCoefRModifier);
94 /* Complex readix-4 IFFT process */
95 arm_radix4_butterfly_inverse_q15(pDst, S_CFFT->fftLen,
97 S_CFFT->twidCoefModifier);
99 /* Bit reversal process */
100 if(S->bitReverseFlagR == 1u)
102 arm_bitreversal_q15(pDst, S_CFFT->fftLen,
103 S_CFFT->bitRevFactor, S_CFFT->pBitRevTable);
108 /* Calculation of RFFT of input */
110 /* Complex readix-4 FFT process */
111 arm_radix4_butterfly_q15(pSrc, S_CFFT->fftLen,
112 S_CFFT->pTwiddle, S_CFFT->twidCoefModifier);
114 /* Bit reversal process */
115 if(S->bitReverseFlagR == 1u)
117 arm_bitreversal_q15(pSrc, S_CFFT->fftLen,
118 S_CFFT->bitRevFactor, S_CFFT->pBitRevTable);
121 arm_split_rfft_q15(pSrc, S->fftLenBy2, S->pTwiddleAReal,
122 S->pTwiddleBReal, pDst, S->twidCoefRModifier);
128 * @} end of RFFT_RIFFT group
132 * @brief Core Real FFT process
133 * @param *pSrc points to the input buffer.
134 * @param fftLen length of FFT.
135 * @param *pATable points to the A twiddle Coef buffer.
136 * @param *pBTable points to the B twiddle Coef buffer.
137 * @param *pDst points to the output buffer.
138 * @param modifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
140 * The function implements a Real FFT
143 void arm_split_rfft_q15(
151 uint32_t i; /* Loop Counter */
152 q31_t outR, outI; /* Temporary variables for output */
153 q15_t *pCoefA, *pCoefB; /* Temporary pointers for twiddle factors */
154 q15_t *pSrc1, *pSrc2;
157 pSrc[2u * fftLen] = pSrc[0];
158 pSrc[(2u * fftLen) + 1u] = pSrc[1];
160 pCoefA = &pATable[modifier * 2u];
161 pCoefB = &pBTable[modifier * 2u];
164 pSrc2 = &pSrc[(2u * fftLen) - 2u];
168 /* Run the below code for Cortex-M4 and Cortex-M3 */
175 outR = (pSrc[2 * i] * pATable[2 * i] - pSrc[2 * i + 1] * pATable[2 * i + 1]
176 + pSrc[2 * n - 2 * i] * pBTable[2 * i] +
177 pSrc[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
180 /* outI = (pIn[2 * i + 1] * pATable[2 * i] + pIn[2 * i] * pATable[2 * i + 1] +
181 pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -
182 pIn[2 * n - 2 * i + 1] * pBTable[2 * i]); */
185 #ifndef ARM_MATH_BIG_ENDIAN
187 /* pSrc[2 * i] * pATable[2 * i] - pSrc[2 * i + 1] * pATable[2 * i + 1] */
188 outR = __SMUSD(*__SIMD32(pSrc1), *__SIMD32(pCoefA));
192 /* -(pSrc[2 * i + 1] * pATable[2 * i + 1] - pSrc[2 * i] * pATable[2 * i]) */
193 outR = -(__SMUSD(*__SIMD32(pSrc1), *__SIMD32(pCoefA)));
195 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
197 /* pSrc[2 * n - 2 * i] * pBTable[2 * i] +
198 pSrc[2 * n - 2 * i + 1] * pBTable[2 * i + 1]) */
199 outR = __SMLAD(*__SIMD32(pSrc2), *__SIMD32(pCoefB), outR) >> 15u;
201 /* pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -
202 pIn[2 * n - 2 * i + 1] * pBTable[2 * i] */
204 #ifndef ARM_MATH_BIG_ENDIAN
206 outI = __SMUSDX(*__SIMD32(pSrc2)--, *__SIMD32(pCoefB));
210 outI = __SMUSDX(*__SIMD32(pCoefB), *__SIMD32(pSrc2)--);
212 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
214 /* (pIn[2 * i + 1] * pATable[2 * i] + pIn[2 * i] * pATable[2 * i + 1] */
215 outI = __SMLADX(*__SIMD32(pSrc1)++, *__SIMD32(pCoefA), outI);
218 pDst[2u * i] = (q15_t) outR;
219 pDst[(2u * i) + 1u] = outI >> 15u;
221 /* write complex conjugate output */
222 pDst[(4u * fftLen) - (2u * i)] = (q15_t) outR;
223 pDst[((4u * fftLen) - (2u * i)) + 1u] = -(outI >> 15u);
225 /* update coefficient pointer */
226 pCoefB = pCoefB + (2u * modifier);
227 pCoefA = pCoefA + (2u * modifier);
233 pDst[2u * fftLen] = pSrc[0] - pSrc[1];
234 pDst[(2u * fftLen) + 1u] = 0;
236 pDst[0] = pSrc[0] + pSrc[1];
242 /* Run the below code for Cortex-M0 */
249 outR = (pSrc[2 * i] * pATable[2 * i] - pSrc[2 * i + 1] * pATable[2 * i + 1]
250 + pSrc[2 * n - 2 * i] * pBTable[2 * i] +
251 pSrc[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
254 outR = *pSrc1 * *pCoefA;
255 outR = outR - (*(pSrc1 + 1) * *(pCoefA + 1));
256 outR = outR + (*pSrc2 * *pCoefB);
257 outR = (outR + (*(pSrc2 + 1) * *(pCoefB + 1))) >> 15;
260 /* outI = (pIn[2 * i + 1] * pATable[2 * i] + pIn[2 * i] * pATable[2 * i + 1] +
261 pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -
262 pIn[2 * n - 2 * i + 1] * pBTable[2 * i]);
265 outI = *pSrc2 * *(pCoefB + 1);
266 outI = outI - (*(pSrc2 + 1) * *pCoefB);
267 outI = outI + (*(pSrc1 + 1) * *pCoefA);
268 outI = outI + (*pSrc1 * *(pCoefA + 1));
270 /* update input pointers */
275 pDst[2u * i] = (q15_t) outR;
276 pDst[(2u * i) + 1u] = outI >> 15u;
278 /* write complex conjugate output */
279 pDst[(4u * fftLen) - (2u * i)] = (q15_t) outR;
280 pDst[((4u * fftLen) - (2u * i)) + 1u] = -(outI >> 15u);
282 /* update coefficient pointer */
283 pCoefB = pCoefB + (2u * modifier);
284 pCoefA = pCoefA + (2u * modifier);
290 pDst[2u * fftLen] = pSrc[0] - pSrc[1];
291 pDst[(2u * fftLen) + 1u] = 0;
293 pDst[0] = pSrc[0] + pSrc[1];
296 #endif /* #ifndef ARM_MATH_CM0 */
302 * @brief Core Real IFFT process
303 * @param[in] *pSrc points to the input buffer.
304 * @param[in] fftLen length of FFT.
305 * @param[in] *pATable points to the twiddle Coef A buffer.
306 * @param[in] *pBTable points to the twiddle Coef B buffer.
307 * @param[out] *pDst points to the output buffer.
308 * @param[in] modifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
310 * The function implements a Real IFFT
312 void arm_split_rifft_q15(
320 uint32_t i; /* Loop Counter */
321 q31_t outR, outI; /* Temporary variables for output */
322 q15_t *pCoefA, *pCoefB; /* Temporary pointers for twiddle factors */
323 q15_t *pSrc1, *pSrc2;
324 q15_t *pDst1 = &pDst[0];
326 pCoefA = &pATable[0];
327 pCoefB = &pBTable[0];
330 pSrc2 = &pSrc[2u * fftLen];
334 /* Run the below code for Cortex-M4 and Cortex-M3 */
342 outR = (pIn[2 * i] * pATable[2 * i] + pIn[2 * i + 1] * pATable[2 * i + 1] +
343 pIn[2 * n - 2 * i] * pBTable[2 * i] -
344 pIn[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
346 outI = (pIn[2 * i + 1] * pATable[2 * i] - pIn[2 * i] * pATable[2 * i + 1] -
347 pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -
348 pIn[2 * n - 2 * i + 1] * pBTable[2 * i]);
353 #ifndef ARM_MATH_BIG_ENDIAN
355 /* pIn[2 * n - 2 * i] * pBTable[2 * i] -
356 pIn[2 * n - 2 * i + 1] * pBTable[2 * i + 1]) */
357 outR = __SMUSD(*__SIMD32(pSrc2), *__SIMD32(pCoefB));
361 /* -(-pIn[2 * n - 2 * i] * pBTable[2 * i] +
362 pIn[2 * n - 2 * i + 1] * pBTable[2 * i + 1])) */
363 outR = -(__SMUSD(*__SIMD32(pSrc2), *__SIMD32(pCoefB)));
365 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
367 /* pIn[2 * i] * pATable[2 * i] + pIn[2 * i + 1] * pATable[2 * i + 1] +
368 pIn[2 * n - 2 * i] * pBTable[2 * i] */
369 outR = __SMLAD(*__SIMD32(pSrc1), *__SIMD32(pCoefA), outR) >> 15u;
372 -pIn[2 * n - 2 * i] * pBTable[2 * i + 1] +
373 pIn[2 * n - 2 * i + 1] * pBTable[2 * i] */
374 outI = __SMUADX(*__SIMD32(pSrc2)--, *__SIMD32(pCoefB));
376 /* pIn[2 * i + 1] * pATable[2 * i] - pIn[2 * i] * pATable[2 * i + 1] */
378 #ifndef ARM_MATH_BIG_ENDIAN
380 outI = __SMLSDX(*__SIMD32(pCoefA), *__SIMD32(pSrc1)++, -outI);
384 outI = __SMLSDX(*__SIMD32(pSrc1)++, *__SIMD32(pCoefA), -outI);
386 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
389 #ifndef ARM_MATH_BIG_ENDIAN
391 *__SIMD32(pDst1)++ = __PKHBT(outR, (outI >> 15u), 16);
395 *__SIMD32(pDst1)++ = __PKHBT((outI >> 15u), outR, 16);
397 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
399 /* update coefficient pointer */
400 pCoefB = pCoefB + (2u * modifier);
401 pCoefA = pCoefA + (2u * modifier);
410 /* Run the below code for Cortex-M0 */
418 outR = (pIn[2 * i] * pATable[2 * i] + pIn[2 * i + 1] * pATable[2 * i + 1] +
419 pIn[2 * n - 2 * i] * pBTable[2 * i] -
420 pIn[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
423 outR = *pSrc2 * *pCoefB;
424 outR = outR - (*(pSrc2 + 1) * *(pCoefB + 1));
425 outR = outR + (*pSrc1 * *pCoefA);
426 outR = (outR + (*(pSrc1 + 1) * *(pCoefA + 1))) >> 15;
429 outI = (pIn[2 * i + 1] * pATable[2 * i] - pIn[2 * i] * pATable[2 * i + 1] -
430 pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -
431 pIn[2 * n - 2 * i + 1] * pBTable[2 * i]);
434 outI = *(pSrc1 + 1) * *pCoefA;
435 outI = outI - (*pSrc1 * *(pCoefA + 1));
436 outI = outI - (*pSrc2 * *(pCoefB + 1));
437 outI = outI - (*(pSrc2 + 1) * *(pCoefB));
439 /* update input pointers */
444 *pDst1++ = (q15_t) outR;
445 *pDst1++ = (q15_t) (outI >> 15);
447 /* update coefficient pointer */
448 pCoefB = pCoefB + (2u * modifier);
449 pCoefA = pCoefA + (2u * modifier);
455 #endif /* #ifndef ARM_MATH_CM0 */