arm_rfft_f32.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. Source buffer is modified by this function.
  72. @deprecated Do not use this function. It has been superceded by \ref arm_rfft_fast_f32 and will be removed 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, S->pTwiddleBReal, pDst, S->twidCoefRModifier);
  89. /* Complex radix-4 IFFT process */
  90. arm_radix4_butterfly_inverse_f32 (pDst, S_CFFT->fftLen, S_CFFT->pTwiddle, S_CFFT->twidCoefModifier, S_CFFT->onebyfftLen);
  91. /* Bit reversal process */
  92. if (S->bitReverseFlagR == 1U)
  93. {
  94. arm_bitreversal_f32 (pDst, S_CFFT->fftLen, S_CFFT->bitRevFactor, S_CFFT->pBitRevTable);
  95. }
  96. }
  97. else
  98. {
  99. /* Calculation of RFFT of input */
  100. /* Complex radix-4 FFT process */
  101. arm_radix4_butterfly_f32 (pSrc, S_CFFT->fftLen, S_CFFT->pTwiddle, S_CFFT->twidCoefModifier);
  102. /* Bit reversal process */
  103. if (S->bitReverseFlagR == 1U)
  104. {
  105. arm_bitreversal_f32 (pSrc, S_CFFT->fftLen, S_CFFT->bitRevFactor, S_CFFT->pBitRevTable);
  106. }
  107. /* Real FFT core process */
  108. arm_split_rfft_f32 (pSrc, S->fftLenBy2, S->pTwiddleAReal, S->pTwiddleBReal, pDst, S->twidCoefRModifier);
  109. }
  110. }
  111. /**
  112. @} end of RealFFT group
  113. */
  114. /**
  115. @brief Core Real FFT process
  116. @param[in] pSrc points to input buffer
  117. @param[in] fftLen length of FFT
  118. @param[in] pATable points to twiddle Coef A buffer
  119. @param[in] pBTable points to twiddle Coef B buffer
  120. @param[out] pDst points to output buffer
  121. @param[in] modifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table
  122. @return none
  123. */
  124. void arm_split_rfft_f32(
  125. float32_t * pSrc,
  126. uint32_t fftLen,
  127. const float32_t * pATable,
  128. const float32_t * pBTable,
  129. float32_t * pDst,
  130. uint32_t modifier)
  131. {
  132. uint32_t i; /* Loop Counter */
  133. float32_t outR, outI; /* Temporary variables for output */
  134. const float32_t *pCoefA, *pCoefB; /* Temporary pointers for twiddle factors */
  135. float32_t CoefA1, CoefA2, CoefB1; /* Temporary variables for twiddle coefficients */
  136. float32_t *pDst1 = &pDst[2], *pDst2 = &pDst[(4U * fftLen) - 1U]; /* temp pointers for output buffer */
  137. float32_t *pSrc1 = &pSrc[2], *pSrc2 = &pSrc[(2U * fftLen) - 1U]; /* temp pointers for input buffer */
  138. /* Init coefficient pointers */
  139. pCoefA = &pATable[modifier * 2];
  140. pCoefB = &pBTable[modifier * 2];
  141. i = fftLen - 1U;
  142. while (i > 0U)
  143. {
  144. /*
  145. outR = ( pSrc[2 * i] * pATable[2 * i]
  146. - pSrc[2 * i + 1] * pATable[2 * i + 1]
  147. + pSrc[2 * n - 2 * i] * pBTable[2 * i]
  148. + pSrc[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
  149. outI = ( pIn[2 * i + 1] * pATable[2 * i]
  150. + pIn[2 * i] * pATable[2 * i + 1]
  151. + pIn[2 * n - 2 * i] * pBTable[2 * i + 1]
  152. - pIn[2 * n - 2 * i + 1] * pBTable[2 * i]);
  153. */
  154. /* read pATable[2 * i] */
  155. CoefA1 = *pCoefA++;
  156. /* pATable[2 * i + 1] */
  157. CoefA2 = *pCoefA;
  158. /* pSrc[2 * i] * pATable[2 * i] */
  159. outR = *pSrc1 * CoefA1;
  160. /* pSrc[2 * i] * CoefA2 */
  161. outI = *pSrc1++ * CoefA2;
  162. /* (pSrc[2 * i + 1] + pSrc[2 * fftLen - 2 * i + 1]) * CoefA2 */
  163. outR -= (*pSrc1 + *pSrc2) * CoefA2;
  164. /* pSrc[2 * i + 1] * CoefA1 */
  165. outI += *pSrc1++ * CoefA1;
  166. CoefB1 = *pCoefB;
  167. /* pSrc[2 * fftLen - 2 * i + 1] * CoefB1 */
  168. outI -= *pSrc2-- * CoefB1;
  169. /* pSrc[2 * fftLen - 2 * i] * CoefA2 */
  170. outI -= *pSrc2 * CoefA2;
  171. /* pSrc[2 * fftLen - 2 * i] * CoefB1 */
  172. outR += *pSrc2-- * CoefB1;
  173. /* write output */
  174. *pDst1++ = outR;
  175. *pDst1++ = outI;
  176. /* write complex conjugate output */
  177. *pDst2-- = -outI;
  178. *pDst2-- = outR;
  179. /* update coefficient pointer */
  180. pCoefB = pCoefB + (modifier * 2U);
  181. pCoefA = pCoefA + ((modifier * 2U) - 1U);
  182. i--;
  183. }
  184. pDst[2U * fftLen] = pSrc[0] - pSrc[1];
  185. pDst[(2U * fftLen) + 1U] = 0.0f;
  186. pDst[0] = pSrc[0] + pSrc[1];
  187. pDst[1] = 0.0f;
  188. }
  189. /**
  190. @brief Core Real IFFT process
  191. @param[in] pSrc points to input buffer
  192. @param[in] fftLen length of FFT
  193. @param[in] pATable points to twiddle Coef A buffer
  194. @param[in] pBTable points to twiddle Coef B buffer
  195. @param[out] pDst points to output buffer
  196. @param[in] modifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table
  197. @return none
  198. */
  199. void arm_split_rifft_f32(
  200. float32_t * pSrc,
  201. uint32_t fftLen,
  202. const float32_t * pATable,
  203. const float32_t * pBTable,
  204. float32_t * pDst,
  205. uint32_t modifier)
  206. {
  207. float32_t outR, outI; /* Temporary variables for output */
  208. const float32_t *pCoefA, *pCoefB; /* Temporary pointers for twiddle factors */
  209. float32_t CoefA1, CoefA2, CoefB1; /* Temporary variables for twiddle coefficients */
  210. float32_t *pSrc1 = &pSrc[0], *pSrc2 = &pSrc[(2U * fftLen) + 1U];
  211. pCoefA = &pATable[0];
  212. pCoefB = &pBTable[0];
  213. while (fftLen > 0U)
  214. {
  215. /*
  216. outR = ( pIn[2 * i] * pATable[2 * i]
  217. + pIn[2 * i + 1] * pATable[2 * i + 1]
  218. + pIn[2 * n - 2 * i] * pBTable[2 * i]
  219. - pIn[2 * n - 2 * i + 1] * pBTable[2 * i + 1]);
  220. outI = ( pIn[2 * i + 1] * pATable[2 * i]
  221. - pIn[2 * i] * pATable[2 * i + 1]
  222. - pIn[2 * n - 2 * i] * pBTable[2 * i + 1]
  223. - pIn[2 * n - 2 * i + 1] * pBTable[2 * i]);
  224. */
  225. CoefA1 = *pCoefA++;
  226. CoefA2 = *pCoefA;
  227. /* outR = (pSrc[2 * i] * CoefA1 */
  228. outR = *pSrc1 * CoefA1;
  229. /* - pSrc[2 * i] * CoefA2 */
  230. outI = -(*pSrc1++) * CoefA2;
  231. /* (pSrc[2 * i + 1] + pSrc[2 * fftLen - 2 * i + 1]) * CoefA2 */
  232. outR += (*pSrc1 + *pSrc2) * CoefA2;
  233. /* pSrc[2 * i + 1] * CoefA1 */
  234. outI += (*pSrc1++) * CoefA1;
  235. CoefB1 = *pCoefB;
  236. /* - pSrc[2 * fftLen - 2 * i + 1] * CoefB1 */
  237. outI -= *pSrc2-- * CoefB1;
  238. /* pSrc[2 * fftLen - 2 * i] * CoefB1 */
  239. outR += *pSrc2 * CoefB1;
  240. /* pSrc[2 * fftLen - 2 * i] * CoefA2 */
  241. outI += *pSrc2-- * CoefA2;
  242. /* write output */
  243. *pDst++ = outR;
  244. *pDst++ = outI;
  245. /* update coefficient pointer */
  246. pCoefB = pCoefB + (modifier * 2);
  247. pCoefA = pCoefA + (modifier * 2 - 1);
  248. /* Decrement loop count */
  249. fftLen--;
  250. }
  251. }