arm_cfft_f64.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cfft_f64.c
  4. * Description: Combined Radix Decimation in Frequency CFFT Double Precision Floating point processing function
  5. *
  6. * $Date: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 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 "dsp/transform_functions.h"
  29. #include "arm_common_tables.h"
  30. extern void arm_radix4_butterfly_f64(
  31. float64_t * pSrc,
  32. uint16_t fftLen,
  33. const float64_t * pCoef,
  34. uint16_t twidCoefModifier);
  35. extern void arm_bitreversal_64(
  36. uint64_t * pSrc,
  37. const uint16_t bitRevLen,
  38. const uint16_t * pBitRevTable);
  39. /* ----------------------------------------------------------------------
  40. * Internal helper function used by the FFTs
  41. * ---------------------------------------------------------------------- */
  42. /*
  43. * @brief Core function for the Double Precision floating-point CFFT butterfly process.
  44. * @param[in, out] *pSrc points to the in-place buffer of F64 data type.
  45. * @param[in] fftLen length of the FFT.
  46. * @param[in] *pCoef points to the twiddle coefficient buffer.
  47. * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
  48. */
  49. void arm_radix4_butterfly_f64(
  50. float64_t * pSrc,
  51. uint16_t fftLen,
  52. const float64_t * pCoef,
  53. uint16_t twidCoefModifier)
  54. {
  55. float64_t co1, co2, co3, si1, si2, si3;
  56. uint32_t ia1, ia2, ia3;
  57. uint32_t i0, i1, i2, i3;
  58. uint32_t n1, n2, j, k;
  59. float64_t t1, t2, r1, r2, s1, s2;
  60. /* Initializations for the fft calculation */
  61. n2 = fftLen;
  62. n1 = n2;
  63. for (k = fftLen; k > 1U; k >>= 2U)
  64. {
  65. /* Initializations for the fft calculation */
  66. n1 = n2;
  67. n2 >>= 2U;
  68. ia1 = 0U;
  69. /* FFT Calculation */
  70. j = 0;
  71. do
  72. {
  73. /* index calculation for the coefficients */
  74. ia2 = ia1 + ia1;
  75. ia3 = ia2 + ia1;
  76. co1 = pCoef[ia1 * 2U];
  77. si1 = pCoef[(ia1 * 2U) + 1U];
  78. co2 = pCoef[ia2 * 2U];
  79. si2 = pCoef[(ia2 * 2U) + 1U];
  80. co3 = pCoef[ia3 * 2U];
  81. si3 = pCoef[(ia3 * 2U) + 1U];
  82. /* Twiddle coefficients index modifier */
  83. ia1 = ia1 + twidCoefModifier;
  84. i0 = j;
  85. do
  86. {
  87. /* index calculation for the input as, */
  88. /* pSrc[i0 + 0], pSrc[i0 + fftLen/4], pSrc[i0 + fftLen/2], pSrc[i0 + 3fftLen/4] */
  89. i1 = i0 + n2;
  90. i2 = i1 + n2;
  91. i3 = i2 + n2;
  92. /* xa + xc */
  93. r1 = pSrc[(2U * i0)] + pSrc[(2U * i2)];
  94. /* xa - xc */
  95. r2 = pSrc[(2U * i0)] - pSrc[(2U * i2)];
  96. /* ya + yc */
  97. s1 = pSrc[(2U * i0) + 1U] + pSrc[(2U * i2) + 1U];
  98. /* ya - yc */
  99. s2 = pSrc[(2U * i0) + 1U] - pSrc[(2U * i2) + 1U];
  100. /* xb + xd */
  101. t1 = pSrc[2U * i1] + pSrc[2U * i3];
  102. /* xa' = xa + xb + xc + xd */
  103. pSrc[2U * i0] = r1 + t1;
  104. /* xa + xc -(xb + xd) */
  105. r1 = r1 - t1;
  106. /* yb + yd */
  107. t2 = pSrc[(2U * i1) + 1U] + pSrc[(2U * i3) + 1U];
  108. /* ya' = ya + yb + yc + yd */
  109. pSrc[(2U * i0) + 1U] = s1 + t2;
  110. /* (ya + yc) - (yb + yd) */
  111. s1 = s1 - t2;
  112. /* (yb - yd) */
  113. t1 = pSrc[(2U * i1) + 1U] - pSrc[(2U * i3) + 1U];
  114. /* (xb - xd) */
  115. t2 = pSrc[2U * i1] - pSrc[2U * i3];
  116. /* xc' = (xa-xb+xc-xd)co2 + (ya-yb+yc-yd)(si2) */
  117. pSrc[2U * i1] = (r1 * co2) + (s1 * si2);
  118. /* yc' = (ya-yb+yc-yd)co2 - (xa-xb+xc-xd)(si2) */
  119. pSrc[(2U * i1) + 1U] = (s1 * co2) - (r1 * si2);
  120. /* (xa - xc) + (yb - yd) */
  121. r1 = r2 + t1;
  122. /* (xa - xc) - (yb - yd) */
  123. r2 = r2 - t1;
  124. /* (ya - yc) - (xb - xd) */
  125. s1 = s2 - t2;
  126. /* (ya - yc) + (xb - xd) */
  127. s2 = s2 + t2;
  128. /* xb' = (xa+yb-xc-yd)co1 + (ya-xb-yc+xd)(si1) */
  129. pSrc[2U * i2] = (r1 * co1) + (s1 * si1);
  130. /* yb' = (ya-xb-yc+xd)co1 - (xa+yb-xc-yd)(si1) */
  131. pSrc[(2U * i2) + 1U] = (s1 * co1) - (r1 * si1);
  132. /* xd' = (xa-yb-xc+yd)co3 + (ya+xb-yc-xd)(si3) */
  133. pSrc[2U * i3] = (r2 * co3) + (s2 * si3);
  134. /* yd' = (ya+xb-yc-xd)co3 - (xa-yb-xc+yd)(si3) */
  135. pSrc[(2U * i3) + 1U] = (s2 * co3) - (r2 * si3);
  136. i0 += n1;
  137. } while ( i0 < fftLen);
  138. j++;
  139. } while (j <= (n2 - 1U));
  140. twidCoefModifier <<= 2U;
  141. }
  142. }
  143. /*
  144. * @brief Core function for the Double Precision floating-point CFFT butterfly process.
  145. * @param[in, out] *pSrc points to the in-place buffer of F64 data type.
  146. * @param[in] fftLen length of the FFT.
  147. * @param[in] *pCoef points to the twiddle coefficient buffer.
  148. * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
  149. */
  150. void arm_cfft_radix4by2_f64(
  151. float64_t * pSrc,
  152. uint32_t fftLen,
  153. const float64_t * pCoef)
  154. {
  155. uint32_t i, l;
  156. uint32_t n2, ia;
  157. float64_t xt, yt, cosVal, sinVal;
  158. float64_t p0, p1,p2,p3,a0,a1;
  159. n2 = fftLen >> 1;
  160. ia = 0;
  161. for (i = 0; i < n2; i++)
  162. {
  163. cosVal = pCoef[2*ia];
  164. sinVal = pCoef[2*ia + 1];
  165. ia++;
  166. l = i + n2;
  167. /* Butterfly implementation */
  168. a0 = pSrc[2 * i] + pSrc[2 * l];
  169. xt = pSrc[2 * i] - pSrc[2 * l];
  170. yt = pSrc[2 * i + 1] - pSrc[2 * l + 1];
  171. a1 = pSrc[2 * l + 1] + pSrc[2 * i + 1];
  172. p0 = xt * cosVal;
  173. p1 = yt * sinVal;
  174. p2 = yt * cosVal;
  175. p3 = xt * sinVal;
  176. pSrc[2 * i] = a0;
  177. pSrc[2 * i + 1] = a1;
  178. pSrc[2 * l] = p0 + p1;
  179. pSrc[2 * l + 1] = p2 - p3;
  180. }
  181. // first col
  182. arm_radix4_butterfly_f64( pSrc, n2, (float64_t*)pCoef, 2U);
  183. // second col
  184. arm_radix4_butterfly_f64( pSrc + fftLen, n2, (float64_t*)pCoef, 2U);
  185. }
  186. /**
  187. @addtogroup ComplexFFTF64
  188. @{
  189. */
  190. /**
  191. @brief Processing function for the Double Precision floating-point complex FFT.
  192. @param[in] S points to an instance of the Double Precision floating-point CFFT structure
  193. @param[in,out] p1 points to the complex data buffer of size <code>2*fftLen</code>. Processing occurs in-place
  194. @param[in] ifftFlag flag that selects transform direction
  195. - value = 0: forward transform
  196. - value = 1: inverse transform
  197. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  198. - value = 0: disables bit reversal of output
  199. - value = 1: enables bit reversal of output
  200. */
  201. void arm_cfft_f64(
  202. const arm_cfft_instance_f64 * S,
  203. float64_t * p1,
  204. uint8_t ifftFlag,
  205. uint8_t bitReverseFlag)
  206. {
  207. uint32_t L = S->fftLen, l;
  208. float64_t invL, * pSrc;
  209. if (ifftFlag == 1U)
  210. {
  211. /* Conjugate input data */
  212. pSrc = p1 + 1;
  213. for(l=0; l<L; l++)
  214. {
  215. *pSrc = -*pSrc;
  216. pSrc += 2;
  217. }
  218. }
  219. switch (L)
  220. {
  221. case 16:
  222. case 64:
  223. case 256:
  224. case 1024:
  225. case 4096:
  226. arm_radix4_butterfly_f64 (p1, L, (float64_t*)S->pTwiddle, 1U);
  227. break;
  228. case 32:
  229. case 128:
  230. case 512:
  231. case 2048:
  232. arm_cfft_radix4by2_f64 ( p1, L, (float64_t*)S->pTwiddle);
  233. break;
  234. }
  235. if ( bitReverseFlag )
  236. arm_bitreversal_64((uint64_t*)p1, S->bitRevLength,S->pBitRevTable);
  237. if (ifftFlag == 1U)
  238. {
  239. invL = 1.0 / (float64_t)L;
  240. /* Conjugate and scale output data */
  241. pSrc = p1;
  242. for(l=0; l<L; l++)
  243. {
  244. *pSrc++ *= invL ;
  245. *pSrc = -(*pSrc) * invL;
  246. pSrc++;
  247. }
  248. }
  249. }
  250. /**
  251. @} end of ComplexFFTF64 group
  252. */