arm_cfft_radix8_f32.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cfft_radix8_f32.c
  4. * Description: Radix-8 Decimation in Frequency CFFT & CIFFT Floating point processing 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 helper function used by the FFTs
  31. * -------------------------------------------------------------------- */
  32. /*
  33. * @brief Core function for the floating-point CFFT butterfly process.
  34. * @param[in, out] *pSrc points to the in-place buffer of floating-point data type.
  35. * @param[in] fftLen length of the FFT.
  36. * @param[in] *pCoef points to the twiddle coefficient buffer.
  37. * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
  38. * @return none.
  39. */
  40. void arm_radix8_butterfly_f32(
  41. float32_t * pSrc,
  42. uint16_t fftLen,
  43. const float32_t * pCoef,
  44. uint16_t twidCoefModifier)
  45. {
  46. uint32_t ia1, ia2, ia3, ia4, ia5, ia6, ia7;
  47. uint32_t i1, i2, i3, i4, i5, i6, i7, i8;
  48. uint32_t id;
  49. uint32_t n1, n2, j;
  50. float32_t r1, r2, r3, r4, r5, r6, r7, r8;
  51. float32_t t1, t2;
  52. float32_t s1, s2, s3, s4, s5, s6, s7, s8;
  53. float32_t p1, p2, p3, p4;
  54. float32_t co2, co3, co4, co5, co6, co7, co8;
  55. float32_t si2, si3, si4, si5, si6, si7, si8;
  56. const float32_t C81 = 0.70710678118f;
  57. n2 = fftLen;
  58. do
  59. {
  60. n1 = n2;
  61. n2 = n2 >> 3;
  62. i1 = 0;
  63. do
  64. {
  65. i2 = i1 + n2;
  66. i3 = i2 + n2;
  67. i4 = i3 + n2;
  68. i5 = i4 + n2;
  69. i6 = i5 + n2;
  70. i7 = i6 + n2;
  71. i8 = i7 + n2;
  72. r1 = pSrc[2 * i1] + pSrc[2 * i5];
  73. r5 = pSrc[2 * i1] - pSrc[2 * i5];
  74. r2 = pSrc[2 * i2] + pSrc[2 * i6];
  75. r6 = pSrc[2 * i2] - pSrc[2 * i6];
  76. r3 = pSrc[2 * i3] + pSrc[2 * i7];
  77. r7 = pSrc[2 * i3] - pSrc[2 * i7];
  78. r4 = pSrc[2 * i4] + pSrc[2 * i8];
  79. r8 = pSrc[2 * i4] - pSrc[2 * i8];
  80. t1 = r1 - r3;
  81. r1 = r1 + r3;
  82. r3 = r2 - r4;
  83. r2 = r2 + r4;
  84. pSrc[2 * i1] = r1 + r2;
  85. pSrc[2 * i5] = r1 - r2;
  86. r1 = pSrc[2 * i1 + 1] + pSrc[2 * i5 + 1];
  87. s5 = pSrc[2 * i1 + 1] - pSrc[2 * i5 + 1];
  88. r2 = pSrc[2 * i2 + 1] + pSrc[2 * i6 + 1];
  89. s6 = pSrc[2 * i2 + 1] - pSrc[2 * i6 + 1];
  90. s3 = pSrc[2 * i3 + 1] + pSrc[2 * i7 + 1];
  91. s7 = pSrc[2 * i3 + 1] - pSrc[2 * i7 + 1];
  92. r4 = pSrc[2 * i4 + 1] + pSrc[2 * i8 + 1];
  93. s8 = pSrc[2 * i4 + 1] - pSrc[2 * i8 + 1];
  94. t2 = r1 - s3;
  95. r1 = r1 + s3;
  96. s3 = r2 - r4;
  97. r2 = r2 + r4;
  98. pSrc[2 * i1 + 1] = r1 + r2;
  99. pSrc[2 * i5 + 1] = r1 - r2;
  100. pSrc[2 * i3] = t1 + s3;
  101. pSrc[2 * i7] = t1 - s3;
  102. pSrc[2 * i3 + 1] = t2 - r3;
  103. pSrc[2 * i7 + 1] = t2 + r3;
  104. r1 = (r6 - r8) * C81;
  105. r6 = (r6 + r8) * C81;
  106. r2 = (s6 - s8) * C81;
  107. s6 = (s6 + s8) * C81;
  108. t1 = r5 - r1;
  109. r5 = r5 + r1;
  110. r8 = r7 - r6;
  111. r7 = r7 + r6;
  112. t2 = s5 - r2;
  113. s5 = s5 + r2;
  114. s8 = s7 - s6;
  115. s7 = s7 + s6;
  116. pSrc[2 * i2] = r5 + s7;
  117. pSrc[2 * i8] = r5 - s7;
  118. pSrc[2 * i6] = t1 + s8;
  119. pSrc[2 * i4] = t1 - s8;
  120. pSrc[2 * i2 + 1] = s5 - r7;
  121. pSrc[2 * i8 + 1] = s5 + r7;
  122. pSrc[2 * i6 + 1] = t2 - r8;
  123. pSrc[2 * i4 + 1] = t2 + r8;
  124. i1 += n1;
  125. } while (i1 < fftLen);
  126. if (n2 < 8)
  127. break;
  128. ia1 = 0;
  129. j = 1;
  130. do
  131. {
  132. /* index calculation for the coefficients */
  133. id = ia1 + twidCoefModifier;
  134. ia1 = id;
  135. ia2 = ia1 + id;
  136. ia3 = ia2 + id;
  137. ia4 = ia3 + id;
  138. ia5 = ia4 + id;
  139. ia6 = ia5 + id;
  140. ia7 = ia6 + id;
  141. co2 = pCoef[2 * ia1];
  142. co3 = pCoef[2 * ia2];
  143. co4 = pCoef[2 * ia3];
  144. co5 = pCoef[2 * ia4];
  145. co6 = pCoef[2 * ia5];
  146. co7 = pCoef[2 * ia6];
  147. co8 = pCoef[2 * ia7];
  148. si2 = pCoef[2 * ia1 + 1];
  149. si3 = pCoef[2 * ia2 + 1];
  150. si4 = pCoef[2 * ia3 + 1];
  151. si5 = pCoef[2 * ia4 + 1];
  152. si6 = pCoef[2 * ia5 + 1];
  153. si7 = pCoef[2 * ia6 + 1];
  154. si8 = pCoef[2 * ia7 + 1];
  155. i1 = j;
  156. do
  157. {
  158. /* index calculation for the input */
  159. i2 = i1 + n2;
  160. i3 = i2 + n2;
  161. i4 = i3 + n2;
  162. i5 = i4 + n2;
  163. i6 = i5 + n2;
  164. i7 = i6 + n2;
  165. i8 = i7 + n2;
  166. r1 = pSrc[2 * i1] + pSrc[2 * i5];
  167. r5 = pSrc[2 * i1] - pSrc[2 * i5];
  168. r2 = pSrc[2 * i2] + pSrc[2 * i6];
  169. r6 = pSrc[2 * i2] - pSrc[2 * i6];
  170. r3 = pSrc[2 * i3] + pSrc[2 * i7];
  171. r7 = pSrc[2 * i3] - pSrc[2 * i7];
  172. r4 = pSrc[2 * i4] + pSrc[2 * i8];
  173. r8 = pSrc[2 * i4] - pSrc[2 * i8];
  174. t1 = r1 - r3;
  175. r1 = r1 + r3;
  176. r3 = r2 - r4;
  177. r2 = r2 + r4;
  178. pSrc[2 * i1] = r1 + r2;
  179. r2 = r1 - r2;
  180. s1 = pSrc[2 * i1 + 1] + pSrc[2 * i5 + 1];
  181. s5 = pSrc[2 * i1 + 1] - pSrc[2 * i5 + 1];
  182. s2 = pSrc[2 * i2 + 1] + pSrc[2 * i6 + 1];
  183. s6 = pSrc[2 * i2 + 1] - pSrc[2 * i6 + 1];
  184. s3 = pSrc[2 * i3 + 1] + pSrc[2 * i7 + 1];
  185. s7 = pSrc[2 * i3 + 1] - pSrc[2 * i7 + 1];
  186. s4 = pSrc[2 * i4 + 1] + pSrc[2 * i8 + 1];
  187. s8 = pSrc[2 * i4 + 1] - pSrc[2 * i8 + 1];
  188. t2 = s1 - s3;
  189. s1 = s1 + s3;
  190. s3 = s2 - s4;
  191. s2 = s2 + s4;
  192. r1 = t1 + s3;
  193. t1 = t1 - s3;
  194. pSrc[2 * i1 + 1] = s1 + s2;
  195. s2 = s1 - s2;
  196. s1 = t2 - r3;
  197. t2 = t2 + r3;
  198. p1 = co5 * r2;
  199. p2 = si5 * s2;
  200. p3 = co5 * s2;
  201. p4 = si5 * r2;
  202. pSrc[2 * i5] = p1 + p2;
  203. pSrc[2 * i5 + 1] = p3 - p4;
  204. p1 = co3 * r1;
  205. p2 = si3 * s1;
  206. p3 = co3 * s1;
  207. p4 = si3 * r1;
  208. pSrc[2 * i3] = p1 + p2;
  209. pSrc[2 * i3 + 1] = p3 - p4;
  210. p1 = co7 * t1;
  211. p2 = si7 * t2;
  212. p3 = co7 * t2;
  213. p4 = si7 * t1;
  214. pSrc[2 * i7] = p1 + p2;
  215. pSrc[2 * i7 + 1] = p3 - p4;
  216. r1 = (r6 - r8) * C81;
  217. r6 = (r6 + r8) * C81;
  218. s1 = (s6 - s8) * C81;
  219. s6 = (s6 + s8) * C81;
  220. t1 = r5 - r1;
  221. r5 = r5 + r1;
  222. r8 = r7 - r6;
  223. r7 = r7 + r6;
  224. t2 = s5 - s1;
  225. s5 = s5 + s1;
  226. s8 = s7 - s6;
  227. s7 = s7 + s6;
  228. r1 = r5 + s7;
  229. r5 = r5 - s7;
  230. r6 = t1 + s8;
  231. t1 = t1 - s8;
  232. s1 = s5 - r7;
  233. s5 = s5 + r7;
  234. s6 = t2 - r8;
  235. t2 = t2 + r8;
  236. p1 = co2 * r1;
  237. p2 = si2 * s1;
  238. p3 = co2 * s1;
  239. p4 = si2 * r1;
  240. pSrc[2 * i2] = p1 + p2;
  241. pSrc[2 * i2 + 1] = p3 - p4;
  242. p1 = co8 * r5;
  243. p2 = si8 * s5;
  244. p3 = co8 * s5;
  245. p4 = si8 * r5;
  246. pSrc[2 * i8] = p1 + p2;
  247. pSrc[2 * i8 + 1] = p3 - p4;
  248. p1 = co6 * r6;
  249. p2 = si6 * s6;
  250. p3 = co6 * s6;
  251. p4 = si6 * r6;
  252. pSrc[2 * i6] = p1 + p2;
  253. pSrc[2 * i6 + 1] = p3 - p4;
  254. p1 = co4 * t1;
  255. p2 = si4 * t2;
  256. p3 = co4 * t2;
  257. p4 = si4 * t1;
  258. pSrc[2 * i4] = p1 + p2;
  259. pSrc[2 * i4 + 1] = p3 - p4;
  260. i1 += n1;
  261. } while (i1 < fftLen);
  262. j++;
  263. } while (j < n2);
  264. twidCoefModifier <<= 3;
  265. } while (n2 > 7);
  266. }