arm_rfft_f32.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_rfft_f32.c
  4. * Description: RFFT & RIFFT Floating point process function
  5. *
  6. * $Date: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 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. const float32_t * pCoef,
  36. uint16_t twidCoefModifier);
  37. extern void arm_radix4_butterfly_inverse_f32(
  38. float32_t * pSrc,
  39. uint16_t fftLen,
  40. const 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. const uint16_t * pBitRevTab);
  48. void arm_split_rfft_f32(
  49. float32_t * pSrc,
  50. uint32_t fftLen,
  51. const float32_t * pATable,
  52. const 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. const float32_t * pATable,
  59. const 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 in the future.
  72. @param[in] S points to an instance of the floating-point RFFT/RIFFT structure
  73. @param[in] pSrc points to the input buffer
  74. @param[out] pDst points to the output buffer
  75. @return none
  76. */
  77. void arm_rfft_f32(
  78. const arm_rfft_instance_f32 * S,
  79. float32_t * pSrc,
  80. float32_t * pDst)
  81. {
  82. const arm_cfft_radix4_instance_f32 *S_CFFT = S->pCfft;
  83. /* Calculation of Real IFFT of input */
  84. if (S->ifftFlagR == 1U)
  85. {
  86. /* Real IFFT core process */
  87. arm_split_rifft_f32 (pSrc, S->fftLenBy2, S->pTwiddleAReal, S->pTwiddleBReal, pDst, S->twidCoefRModifier);
  88. /* Complex radix-4 IFFT process */
  89. arm_radix4_butterfly_inverse_f32 (pDst, S_CFFT->fftLen, S_CFFT->pTwiddle, S_CFFT->twidCoefModifier, S_CFFT->onebyfftLen);
  90. /* Bit reversal process */
  91. if (S->bitReverseFlagR == 1U)
  92. {
  93. arm_bitreversal_f32 (pDst, S_CFFT->fftLen, S_CFFT->bitRevFactor, S_CFFT->pBitRevTable);
  94. }
  95. }
  96. else
  97. {
  98. /* Calculation of RFFT of input */
  99. /* Complex radix-4 FFT process */
  100. arm_radix4_butterfly_f32 (pSrc, S_CFFT->fftLen, S_CFFT->pTwiddle, S_CFFT->twidCoefModifier);
  101. /* Bit reversal process */
  102. if (S->bitReverseFlagR == 1U)
  103. {
  104. arm_bitreversal_f32 (pSrc, S_CFFT->fftLen, S_CFFT->bitRevFactor, S_CFFT->pBitRevTable);
  105. }
  106. /* Real FFT core process */
  107. arm_split_rfft_f32 (pSrc, S->fftLenBy2, S->pTwiddleAReal, S->pTwiddleBReal, pDst, S->twidCoefRModifier);
  108. }
  109. }
  110. /**
  111. @} end of RealFFT group
  112. */
  113. /**
  114. @brief Core Real FFT process
  115. @param[in] pSrc points to input buffer
  116. @param[in] fftLen length of FFT
  117. @param[in] pATable points to twiddle Coef A buffer
  118. @param[in] pBTable points to twiddle Coef B buffer
  119. @param[out] pDst points to output buffer
  120. @param[in] modifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table
  121. @return none
  122. */
  123. void arm_split_rfft_f32(
  124. float32_t * pSrc,
  125. uint32_t fftLen,
  126. const float32_t * pATable,
  127. const float32_t * pBTable,
  128. float32_t * pDst,
  129. uint32_t modifier)
  130. {
  131. uint32_t i; /* Loop Counter */
  132. float32_t outR, outI; /* Temporary variables for output */
  133. const float32_t *pCoefA, *pCoefB; /* Temporary pointers for twiddle factors */
  134. float32_t CoefA1, CoefA2, CoefB1; /* Temporary variables for twiddle coefficients */
  135. float32_t *pDst1 = &pDst[2], *pDst2 = &pDst[(4U * fftLen) - 1U]; /* temp pointers for output buffer */
  136. float32_t *pSrc1 = &pSrc[2], *pSrc2 = &pSrc[(2U * fftLen) - 1U]; /* temp pointers for input buffer */
  137. /* Init coefficient pointers */
  138. pCoefA = &pATable[modifier * 2];
  139. pCoefB = &pBTable[modifier * 2];
  140. i = fftLen - 1U;
  141. while (i > 0U)
  142. {
  143. /*
  144. outR = ( pSrc[2 * i] * pATable[2 * i]
  145. - pSrc[2 * i + 1] * pATable[2 * i + 1]
  146. + pSrc[2 * n - 2 * i] * pBTable[2 * i]
  147. + pSrc[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
  148. outI = ( pIn[2 * i + 1] * pATable[2 * i]
  149. + pIn[2 * i] * pATable[2 * i + 1]
  150. + pIn[2 * n - 2 * i] * pBTable[2 * i + 1]
  151. - pIn[2 * n - 2 * i + 1] * pBTable[2 * i]);
  152. */
  153. /* read pATable[2 * i] */
  154. CoefA1 = *pCoefA++;
  155. /* pATable[2 * i + 1] */
  156. CoefA2 = *pCoefA;
  157. /* pSrc[2 * i] * pATable[2 * i] */
  158. outR = *pSrc1 * CoefA1;
  159. /* pSrc[2 * i] * CoefA2 */
  160. outI = *pSrc1++ * CoefA2;
  161. /* (pSrc[2 * i + 1] + pSrc[2 * fftLen - 2 * i + 1]) * CoefA2 */
  162. outR -= (*pSrc1 + *pSrc2) * CoefA2;
  163. /* pSrc[2 * i + 1] * CoefA1 */
  164. outI += *pSrc1++ * CoefA1;
  165. CoefB1 = *pCoefB;
  166. /* pSrc[2 * fftLen - 2 * i + 1] * CoefB1 */
  167. outI -= *pSrc2-- * CoefB1;
  168. /* pSrc[2 * fftLen - 2 * i] * CoefA2 */
  169. outI -= *pSrc2 * CoefA2;
  170. /* pSrc[2 * fftLen - 2 * i] * CoefB1 */
  171. outR += *pSrc2-- * CoefB1;
  172. /* write output */
  173. *pDst1++ = outR;
  174. *pDst1++ = outI;
  175. /* write complex conjugate output */
  176. *pDst2-- = -outI;
  177. *pDst2-- = outR;
  178. /* update coefficient pointer */
  179. pCoefB = pCoefB + (modifier * 2U);
  180. pCoefA = pCoefA + ((modifier * 2U) - 1U);
  181. i--;
  182. }
  183. pDst[2U * fftLen] = pSrc[0] - pSrc[1];
  184. pDst[(2U * fftLen) + 1U] = 0.0f;
  185. pDst[0] = pSrc[0] + pSrc[1];
  186. pDst[1] = 0.0f;
  187. }
  188. /**
  189. @brief Core Real IFFT process
  190. @param[in] pSrc points to input buffer
  191. @param[in] fftLen length of FFT
  192. @param[in] pATable points to twiddle Coef A buffer
  193. @param[in] pBTable points to twiddle Coef B buffer
  194. @param[out] pDst points to output buffer
  195. @param[in] modifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table
  196. @return none
  197. */
  198. void arm_split_rifft_f32(
  199. float32_t * pSrc,
  200. uint32_t fftLen,
  201. const float32_t * pATable,
  202. const float32_t * pBTable,
  203. float32_t * pDst,
  204. uint32_t modifier)
  205. {
  206. float32_t outR, outI; /* Temporary variables for output */
  207. const float32_t *pCoefA, *pCoefB; /* Temporary pointers for twiddle factors */
  208. float32_t CoefA1, CoefA2, CoefB1; /* Temporary variables for twiddle coefficients */
  209. float32_t *pSrc1 = &pSrc[0], *pSrc2 = &pSrc[(2U * fftLen) + 1U];
  210. pCoefA = &pATable[0];
  211. pCoefB = &pBTable[0];
  212. while (fftLen > 0U)
  213. {
  214. /*
  215. outR = ( pIn[2 * i] * pATable[2 * i]
  216. + pIn[2 * i + 1] * pATable[2 * i + 1]
  217. + pIn[2 * n - 2 * i] * pBTable[2 * i]
  218. - pIn[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
  219. outI = ( pIn[2 * i + 1] * pATable[2 * i]
  220. - pIn[2 * i] * pATable[2 * i + 1]
  221. - pIn[2 * n - 2 * i] * pBTable[2 * i + 1]
  222. - pIn[2 * n - 2 * i + 1] * pBTable[2 * i]);
  223. */
  224. CoefA1 = *pCoefA++;
  225. CoefA2 = *pCoefA;
  226. /* outR = (pSrc[2 * i] * CoefA1 */
  227. outR = *pSrc1 * CoefA1;
  228. /* - pSrc[2 * i] * CoefA2 */
  229. outI = -(*pSrc1++) * CoefA2;
  230. /* (pSrc[2 * i + 1] + pSrc[2 * fftLen - 2 * i + 1]) * CoefA2 */
  231. outR += (*pSrc1 + *pSrc2) * CoefA2;
  232. /* pSrc[2 * i + 1] * CoefA1 */
  233. outI += (*pSrc1++) * CoefA1;
  234. CoefB1 = *pCoefB;
  235. /* - pSrc[2 * fftLen - 2 * i + 1] * CoefB1 */
  236. outI -= *pSrc2-- * CoefB1;
  237. /* pSrc[2 * fftLen - 2 * i] * CoefB1 */
  238. outR += *pSrc2 * CoefB1;
  239. /* pSrc[2 * fftLen - 2 * i] * CoefA2 */
  240. outI += *pSrc2-- * CoefA2;
  241. /* write output */
  242. *pDst++ = outR;
  243. *pDst++ = outI;
  244. /* update coefficient pointer */
  245. pCoefB = pCoefB + (modifier * 2);
  246. pCoefA = pCoefA + (modifier * 2 - 1);
  247. /* Decrement loop count */
  248. fftLen--;
  249. }
  250. }