arm_rfft_f32.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_rfft_f32.c
  4. * Description: RFFT & RIFFT Floating point process function
  5. *
  6. * $Date: 27. January 2017
  7. * $Revision: V.1.5.1
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #include "arm_math.h"
  29. /* ----------------------------------------------------------------------
  30. * Internal functions prototypes
  31. * -------------------------------------------------------------------- */
  32. extern void arm_radix4_butterfly_f32(
  33. float32_t * pSrc,
  34. uint16_t fftLen,
  35. float32_t * pCoef,
  36. uint16_t twidCoefModifier);
  37. extern void arm_radix4_butterfly_inverse_f32(
  38. float32_t * pSrc,
  39. uint16_t fftLen,
  40. float32_t * pCoef,
  41. uint16_t twidCoefModifier,
  42. float32_t onebyfftLen);
  43. extern void arm_bitreversal_f32(
  44. float32_t * pSrc,
  45. uint16_t fftSize,
  46. uint16_t bitRevFactor,
  47. uint16_t * pBitRevTab);
  48. void arm_split_rfft_f32(
  49. float32_t * pSrc,
  50. uint32_t fftLen,
  51. float32_t * pATable,
  52. float32_t * pBTable,
  53. float32_t * pDst,
  54. uint32_t modifier);
  55. void arm_split_rifft_f32(
  56. float32_t * pSrc,
  57. uint32_t fftLen,
  58. float32_t * pATable,
  59. float32_t * pBTable,
  60. float32_t * pDst,
  61. uint32_t modifier);
  62. /**
  63. * @ingroup groupTransforms
  64. */
  65. /**
  66. * @addtogroup RealFFT
  67. * @{
  68. */
  69. /**
  70. * @brief Processing function for the floating-point RFFT/RIFFT.
  71. * @deprecated Do not use this function. It has been superceded by \ref arm_rfft_fast_f32 and will be removed
  72. * in the future.
  73. * @param[in] *S points to an instance of the floating-point RFFT/RIFFT structure.
  74. * @param[in] *pSrc points to the input buffer.
  75. * @param[out] *pDst points to the output buffer.
  76. * @return none.
  77. */
  78. void arm_rfft_f32(
  79. const arm_rfft_instance_f32 * S,
  80. float32_t * pSrc,
  81. float32_t * pDst)
  82. {
  83. const arm_cfft_radix4_instance_f32 *S_CFFT = S->pCfft;
  84. /* Calculation of Real IFFT of input */
  85. if (S->ifftFlagR == 1U)
  86. {
  87. /* Real IFFT core process */
  88. arm_split_rifft_f32(pSrc, S->fftLenBy2, S->pTwiddleAReal,
  89. S->pTwiddleBReal, pDst, S->twidCoefRModifier);
  90. /* Complex radix-4 IFFT process */
  91. arm_radix4_butterfly_inverse_f32(pDst, S_CFFT->fftLen,
  92. S_CFFT->pTwiddle,
  93. S_CFFT->twidCoefModifier,
  94. S_CFFT->onebyfftLen);
  95. /* Bit reversal process */
  96. if (S->bitReverseFlagR == 1U)
  97. {
  98. arm_bitreversal_f32(pDst, S_CFFT->fftLen,
  99. S_CFFT->bitRevFactor, S_CFFT->pBitRevTable);
  100. }
  101. }
  102. else
  103. {
  104. /* Calculation of RFFT of input */
  105. /* Complex radix-4 FFT process */
  106. arm_radix4_butterfly_f32(pSrc, S_CFFT->fftLen,
  107. S_CFFT->pTwiddle, S_CFFT->twidCoefModifier);
  108. /* Bit reversal process */
  109. if (S->bitReverseFlagR == 1U)
  110. {
  111. arm_bitreversal_f32(pSrc, S_CFFT->fftLen,
  112. S_CFFT->bitRevFactor, S_CFFT->pBitRevTable);
  113. }
  114. /* Real FFT core process */
  115. arm_split_rfft_f32(pSrc, S->fftLenBy2, S->pTwiddleAReal,
  116. S->pTwiddleBReal, pDst, S->twidCoefRModifier);
  117. }
  118. }
  119. /**
  120. * @} end of RealFFT group
  121. */
  122. /**
  123. * @brief Core Real FFT process
  124. * @param[in] *pSrc points to the input buffer.
  125. * @param[in] fftLen length of FFT.
  126. * @param[in] *pATable points to the twiddle Coef A buffer.
  127. * @param[in] *pBTable points to the twiddle Coef B buffer.
  128. * @param[out] *pDst points to the output buffer.
  129. * @param[in] modifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
  130. * @return none.
  131. */
  132. void arm_split_rfft_f32(
  133. float32_t * pSrc,
  134. uint32_t fftLen,
  135. float32_t * pATable,
  136. float32_t * pBTable,
  137. float32_t * pDst,
  138. uint32_t modifier)
  139. {
  140. uint32_t i; /* Loop Counter */
  141. float32_t outR, outI; /* Temporary variables for output */
  142. float32_t *pCoefA, *pCoefB; /* Temporary pointers for twiddle factors */
  143. float32_t CoefA1, CoefA2, CoefB1; /* Temporary variables for twiddle coefficients */
  144. float32_t *pDst1 = &pDst[2], *pDst2 = &pDst[(4U * fftLen) - 1U]; /* temp pointers for output buffer */
  145. float32_t *pSrc1 = &pSrc[2], *pSrc2 = &pSrc[(2U * fftLen) - 1U]; /* temp pointers for input buffer */
  146. /* Init coefficient pointers */
  147. pCoefA = &pATable[modifier * 2U];
  148. pCoefB = &pBTable[modifier * 2U];
  149. i = fftLen - 1U;
  150. while (i > 0U)
  151. {
  152. /*
  153. outR = (pSrc[2 * i] * pATable[2 * i] - pSrc[2 * i + 1] * pATable[2 * i + 1]
  154. + pSrc[2 * n - 2 * i] * pBTable[2 * i] +
  155. pSrc[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
  156. */
  157. /* outI = (pIn[2 * i + 1] * pATable[2 * i] + pIn[2 * i] * pATable[2 * i + 1] +
  158. pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -
  159. pIn[2 * n - 2 * i + 1] * pBTable[2 * i]); */
  160. /* read pATable[2 * i] */
  161. CoefA1 = *pCoefA++;
  162. /* pATable[2 * i + 1] */
  163. CoefA2 = *pCoefA;
  164. /* pSrc[2 * i] * pATable[2 * i] */
  165. outR = *pSrc1 * CoefA1;
  166. /* pSrc[2 * i] * CoefA2 */
  167. outI = *pSrc1++ * CoefA2;
  168. /* (pSrc[2 * i + 1] + pSrc[2 * fftLen - 2 * i + 1]) * CoefA2 */
  169. outR -= (*pSrc1 + *pSrc2) * CoefA2;
  170. /* pSrc[2 * i + 1] * CoefA1 */
  171. outI += *pSrc1++ * CoefA1;
  172. CoefB1 = *pCoefB;
  173. /* pSrc[2 * fftLen - 2 * i + 1] * CoefB1 */
  174. outI -= *pSrc2-- * CoefB1;
  175. /* pSrc[2 * fftLen - 2 * i] * CoefA2 */
  176. outI -= *pSrc2 * CoefA2;
  177. /* pSrc[2 * fftLen - 2 * i] * CoefB1 */
  178. outR += *pSrc2-- * CoefB1;
  179. /* write output */
  180. *pDst1++ = outR;
  181. *pDst1++ = outI;
  182. /* write complex conjugate output */
  183. *pDst2-- = -outI;
  184. *pDst2-- = outR;
  185. /* update coefficient pointer */
  186. pCoefB = pCoefB + (modifier * 2U);
  187. pCoefA = pCoefA + ((modifier * 2U) - 1U);
  188. i--;
  189. }
  190. pDst[2U * fftLen] = pSrc[0] - pSrc[1];
  191. pDst[(2U * fftLen) + 1U] = 0.0f;
  192. pDst[0] = pSrc[0] + pSrc[1];
  193. pDst[1] = 0.0f;
  194. }
  195. /**
  196. * @brief Core Real IFFT process
  197. * @param[in] *pSrc points to the input buffer.
  198. * @param[in] fftLen length of FFT.
  199. * @param[in] *pATable points to the twiddle Coef A buffer.
  200. * @param[in] *pBTable points to the twiddle Coef B buffer.
  201. * @param[out] *pDst points to the output buffer.
  202. * @param[in] modifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
  203. * @return none.
  204. */
  205. void arm_split_rifft_f32(
  206. float32_t * pSrc,
  207. uint32_t fftLen,
  208. float32_t * pATable,
  209. float32_t * pBTable,
  210. float32_t * pDst,
  211. uint32_t modifier)
  212. {
  213. float32_t outR, outI; /* Temporary variables for output */
  214. float32_t *pCoefA, *pCoefB; /* Temporary pointers for twiddle factors */
  215. float32_t CoefA1, CoefA2, CoefB1; /* Temporary variables for twiddle coefficients */
  216. float32_t *pSrc1 = &pSrc[0], *pSrc2 = &pSrc[(2U * fftLen) + 1U];
  217. pCoefA = &pATable[0];
  218. pCoefB = &pBTable[0];
  219. while (fftLen > 0U)
  220. {
  221. /*
  222. outR = (pIn[2 * i] * pATable[2 * i] + pIn[2 * i + 1] * pATable[2 * i + 1] +
  223. pIn[2 * n - 2 * i] * pBTable[2 * i] -
  224. pIn[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
  225. outI = (pIn[2 * i + 1] * pATable[2 * i] - pIn[2 * i] * pATable[2 * i + 1] -
  226. pIn[2 * n - 2 * i] * pBTable[2 * i + 1] -
  227. pIn[2 * n - 2 * i + 1] * pBTable[2 * i]);
  228. */
  229. CoefA1 = *pCoefA++;
  230. CoefA2 = *pCoefA;
  231. /* outR = (pSrc[2 * i] * CoefA1 */
  232. outR = *pSrc1 * CoefA1;
  233. /* - pSrc[2 * i] * CoefA2 */
  234. outI = -(*pSrc1++) * CoefA2;
  235. /* (pSrc[2 * i + 1] + pSrc[2 * fftLen - 2 * i + 1]) * CoefA2 */
  236. outR += (*pSrc1 + *pSrc2) * CoefA2;
  237. /* pSrc[2 * i + 1] * CoefA1 */
  238. outI += (*pSrc1++) * CoefA1;
  239. CoefB1 = *pCoefB;
  240. /* - pSrc[2 * fftLen - 2 * i + 1] * CoefB1 */
  241. outI -= *pSrc2-- * CoefB1;
  242. /* pSrc[2 * fftLen - 2 * i] * CoefB1 */
  243. outR += *pSrc2 * CoefB1;
  244. /* pSrc[2 * fftLen - 2 * i] * CoefA2 */
  245. outI += *pSrc2-- * CoefA2;
  246. /* write output */
  247. *pDst++ = outR;
  248. *pDst++ = outI;
  249. /* update coefficient pointer */
  250. pCoefB = pCoefB + (modifier * 2U);
  251. pCoefA = pCoefA + ((modifier * 2U) - 1U);
  252. /* Decrement loop count */
  253. fftLen--;
  254. }
  255. }