arm_cfft_radix4_q31.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cfft_radix4_q31.c
  4. * Description: This file has function definition of Radix-4 FFT & IFFT function and
  5. * In-place bit reversal using bit reversal table
  6. *
  7. * $Date: 27. January 2017
  8. * $Revision: V.1.5.1
  9. *
  10. * Target Processor: Cortex-M cores
  11. * -------------------------------------------------------------------- */
  12. /*
  13. * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
  14. *
  15. * SPDX-License-Identifier: Apache-2.0
  16. *
  17. * Licensed under the Apache License, Version 2.0 (the License); you may
  18. * not use this file except in compliance with the License.
  19. * You may obtain a copy of the License at
  20. *
  21. * www.apache.org/licenses/LICENSE-2.0
  22. *
  23. * Unless required by applicable law or agreed to in writing, software
  24. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  25. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  26. * See the License for the specific language governing permissions and
  27. * limitations under the License.
  28. */
  29. #include "arm_math.h"
  30. void arm_radix4_butterfly_inverse_q31(
  31. q31_t * pSrc,
  32. uint32_t fftLen,
  33. q31_t * pCoef,
  34. uint32_t twidCoefModifier);
  35. void arm_radix4_butterfly_q31(
  36. q31_t * pSrc,
  37. uint32_t fftLen,
  38. q31_t * pCoef,
  39. uint32_t twidCoefModifier);
  40. void arm_bitreversal_q31(
  41. q31_t * pSrc,
  42. uint32_t fftLen,
  43. uint16_t bitRevFactor,
  44. uint16_t * pBitRevTab);
  45. /**
  46. * @ingroup groupTransforms
  47. */
  48. /**
  49. * @addtogroup ComplexFFT
  50. * @{
  51. */
  52. /**
  53. * @details
  54. * @brief Processing function for the Q31 CFFT/CIFFT.
  55. * @deprecated Do not use this function. It has been superseded by \ref arm_cfft_q31 and will be removed
  56. * @param[in] *S points to an instance of the Q31 CFFT/CIFFT structure.
  57. * @param[in, out] *pSrc points to the complex data buffer of size <code>2*fftLen</code>. Processing occurs in-place.
  58. * @return none.
  59. *
  60. * \par Input and output formats:
  61. * \par
  62. * Internally input is downscaled by 2 for every stage to avoid saturations inside CFFT/CIFFT process.
  63. * Hence the output format is different for different FFT sizes.
  64. * The input and output formats for different FFT sizes and number of bits to upscale are mentioned in the tables below for CFFT and CIFFT:
  65. * \par
  66. * \image html CFFTQ31.gif "Input and Output Formats for Q31 CFFT"
  67. * \image html CIFFTQ31.gif "Input and Output Formats for Q31 CIFFT"
  68. *
  69. */
  70. void arm_cfft_radix4_q31(
  71. const arm_cfft_radix4_instance_q31 * S,
  72. q31_t * pSrc)
  73. {
  74. if (S->ifftFlag == 1U)
  75. {
  76. /* Complex IFFT radix-4 */
  77. arm_radix4_butterfly_inverse_q31(pSrc, S->fftLen, S->pTwiddle, S->twidCoefModifier);
  78. }
  79. else
  80. {
  81. /* Complex FFT radix-4 */
  82. arm_radix4_butterfly_q31(pSrc, S->fftLen, S->pTwiddle, S->twidCoefModifier);
  83. }
  84. if (S->bitReverseFlag == 1U)
  85. {
  86. /* Bit Reversal */
  87. arm_bitreversal_q31(pSrc, S->fftLen, S->bitRevFactor, S->pBitRevTable);
  88. }
  89. }
  90. /**
  91. * @} end of ComplexFFT group
  92. */
  93. /*
  94. * Radix-4 FFT algorithm used is :
  95. *
  96. * Input real and imaginary data:
  97. * x(n) = xa + j * ya
  98. * x(n+N/4 ) = xb + j * yb
  99. * x(n+N/2 ) = xc + j * yc
  100. * x(n+3N 4) = xd + j * yd
  101. *
  102. *
  103. * Output real and imaginary data:
  104. * x(4r) = xa'+ j * ya'
  105. * x(4r+1) = xb'+ j * yb'
  106. * x(4r+2) = xc'+ j * yc'
  107. * x(4r+3) = xd'+ j * yd'
  108. *
  109. *
  110. * Twiddle factors for radix-4 FFT:
  111. * Wn = co1 + j * (- si1)
  112. * W2n = co2 + j * (- si2)
  113. * W3n = co3 + j * (- si3)
  114. *
  115. * Butterfly implementation:
  116. * xa' = xa + xb + xc + xd
  117. * ya' = ya + yb + yc + yd
  118. * xb' = (xa+yb-xc-yd)* co1 + (ya-xb-yc+xd)* (si1)
  119. * yb' = (ya-xb-yc+xd)* co1 - (xa+yb-xc-yd)* (si1)
  120. * xc' = (xa-xb+xc-xd)* co2 + (ya-yb+yc-yd)* (si2)
  121. * yc' = (ya-yb+yc-yd)* co2 - (xa-xb+xc-xd)* (si2)
  122. * xd' = (xa-yb-xc+yd)* co3 + (ya+xb-yc-xd)* (si3)
  123. * yd' = (ya+xb-yc-xd)* co3 - (xa-yb-xc+yd)* (si3)
  124. *
  125. */
  126. /**
  127. * @brief Core function for the Q31 CFFT butterfly process.
  128. * @param[in, out] *pSrc points to the in-place buffer of Q31 data type.
  129. * @param[in] fftLen length of the FFT.
  130. * @param[in] *pCoef points to twiddle coefficient buffer.
  131. * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
  132. * @return none.
  133. */
  134. void arm_radix4_butterfly_q31(
  135. q31_t * pSrc,
  136. uint32_t fftLen,
  137. q31_t * pCoef,
  138. uint32_t twidCoefModifier)
  139. {
  140. #if defined(ARM_MATH_CM7)
  141. uint32_t n1, n2, ia1, ia2, ia3, i0, i1, i2, i3, j, k;
  142. q31_t t1, t2, r1, r2, s1, s2, co1, co2, co3, si1, si2, si3;
  143. q31_t xa, xb, xc, xd;
  144. q31_t ya, yb, yc, yd;
  145. q31_t xa_out, xb_out, xc_out, xd_out;
  146. q31_t ya_out, yb_out, yc_out, yd_out;
  147. q31_t *ptr1;
  148. q63_t xaya, xbyb, xcyc, xdyd;
  149. /* Total process is divided into three stages */
  150. /* process first stage, middle stages, & last stage */
  151. /* start of first stage process */
  152. /* Initializations for the first stage */
  153. n2 = fftLen;
  154. n1 = n2;
  155. /* n2 = fftLen/4 */
  156. n2 >>= 2U;
  157. i0 = 0U;
  158. ia1 = 0U;
  159. j = n2;
  160. /* Calculation of first stage */
  161. do
  162. {
  163. /* index calculation for the input as, */
  164. /* pSrc[i0 + 0], pSrc[i0 + fftLen/4], pSrc[i0 + fftLen/2U], pSrc[i0 + 3fftLen/4] */
  165. i1 = i0 + n2;
  166. i2 = i1 + n2;
  167. i3 = i2 + n2;
  168. /* input is in 1.31(q31) format and provide 4 guard bits for the input */
  169. /* Butterfly implementation */
  170. /* xa + xc */
  171. r1 = (pSrc[(2U * i0)] >> 4U) + (pSrc[(2U * i2)] >> 4U);
  172. /* xa - xc */
  173. r2 = (pSrc[2U * i0] >> 4U) - (pSrc[2U * i2] >> 4U);
  174. /* xb + xd */
  175. t1 = (pSrc[2U * i1] >> 4U) + (pSrc[2U * i3] >> 4U);
  176. /* ya + yc */
  177. s1 = (pSrc[(2U * i0) + 1U] >> 4U) + (pSrc[(2U * i2) + 1U] >> 4U);
  178. /* ya - yc */
  179. s2 = (pSrc[(2U * i0) + 1U] >> 4U) - (pSrc[(2U * i2) + 1U] >> 4U);
  180. /* xa' = xa + xb + xc + xd */
  181. pSrc[2U * i0] = (r1 + t1);
  182. /* (xa + xc) - (xb + xd) */
  183. r1 = r1 - t1;
  184. /* yb + yd */
  185. t2 = (pSrc[(2U * i1) + 1U] >> 4U) + (pSrc[(2U * i3) + 1U] >> 4U);
  186. /* ya' = ya + yb + yc + yd */
  187. pSrc[(2U * i0) + 1U] = (s1 + t2);
  188. /* (ya + yc) - (yb + yd) */
  189. s1 = s1 - t2;
  190. /* yb - yd */
  191. t1 = (pSrc[(2U * i1) + 1U] >> 4U) - (pSrc[(2U * i3) + 1U] >> 4U);
  192. /* xb - xd */
  193. t2 = (pSrc[2U * i1] >> 4U) - (pSrc[2U * i3] >> 4U);
  194. /* index calculation for the coefficients */
  195. ia2 = 2U * ia1;
  196. co2 = pCoef[ia2 * 2U];
  197. si2 = pCoef[(ia2 * 2U) + 1U];
  198. /* xc' = (xa-xb+xc-xd)co2 + (ya-yb+yc-yd)(si2) */
  199. pSrc[2U * i1] = (((int32_t) (((q63_t) r1 * co2) >> 32)) +
  200. ((int32_t) (((q63_t) s1 * si2) >> 32))) << 1U;
  201. /* yc' = (ya-yb+yc-yd)co2 - (xa-xb+xc-xd)(si2) */
  202. pSrc[(2U * i1) + 1U] = (((int32_t) (((q63_t) s1 * co2) >> 32)) -
  203. ((int32_t) (((q63_t) r1 * si2) >> 32))) << 1U;
  204. /* (xa - xc) + (yb - yd) */
  205. r1 = r2 + t1;
  206. /* (xa - xc) - (yb - yd) */
  207. r2 = r2 - t1;
  208. /* (ya - yc) - (xb - xd) */
  209. s1 = s2 - t2;
  210. /* (ya - yc) + (xb - xd) */
  211. s2 = s2 + t2;
  212. co1 = pCoef[ia1 * 2U];
  213. si1 = pCoef[(ia1 * 2U) + 1U];
  214. /* xb' = (xa+yb-xc-yd)co1 + (ya-xb-yc+xd)(si1) */
  215. pSrc[2U * i2] = (((int32_t) (((q63_t) r1 * co1) >> 32)) +
  216. ((int32_t) (((q63_t) s1 * si1) >> 32))) << 1U;
  217. /* yb' = (ya-xb-yc+xd)co1 - (xa+yb-xc-yd)(si1) */
  218. pSrc[(2U * i2) + 1U] = (((int32_t) (((q63_t) s1 * co1) >> 32)) -
  219. ((int32_t) (((q63_t) r1 * si1) >> 32))) << 1U;
  220. /* index calculation for the coefficients */
  221. ia3 = 3U * ia1;
  222. co3 = pCoef[ia3 * 2U];
  223. si3 = pCoef[(ia3 * 2U) + 1U];
  224. /* xd' = (xa-yb-xc+yd)co3 + (ya+xb-yc-xd)(si3) */
  225. pSrc[2U * i3] = (((int32_t) (((q63_t) r2 * co3) >> 32)) +
  226. ((int32_t) (((q63_t) s2 * si3) >> 32))) << 1U;
  227. /* yd' = (ya+xb-yc-xd)co3 - (xa-yb-xc+yd)(si3) */
  228. pSrc[(2U * i3) + 1U] = (((int32_t) (((q63_t) s2 * co3) >> 32)) -
  229. ((int32_t) (((q63_t) r2 * si3) >> 32))) << 1U;
  230. /* Twiddle coefficients index modifier */
  231. ia1 = ia1 + twidCoefModifier;
  232. /* Updating input index */
  233. i0 = i0 + 1U;
  234. } while (--j);
  235. /* end of first stage process */
  236. /* data is in 5.27(q27) format */
  237. /* start of Middle stages process */
  238. /* each stage in middle stages provides two down scaling of the input */
  239. twidCoefModifier <<= 2U;
  240. for (k = fftLen / 4U; k > 4U; k >>= 2U)
  241. {
  242. /* Initializations for the first stage */
  243. n1 = n2;
  244. n2 >>= 2U;
  245. ia1 = 0U;
  246. /* Calculation of first stage */
  247. for (j = 0U; j <= (n2 - 1U); j++)
  248. {
  249. /* index calculation for the coefficients */
  250. ia2 = ia1 + ia1;
  251. ia3 = ia2 + ia1;
  252. co1 = pCoef[ia1 * 2U];
  253. si1 = pCoef[(ia1 * 2U) + 1U];
  254. co2 = pCoef[ia2 * 2U];
  255. si2 = pCoef[(ia2 * 2U) + 1U];
  256. co3 = pCoef[ia3 * 2U];
  257. si3 = pCoef[(ia3 * 2U) + 1U];
  258. /* Twiddle coefficients index modifier */
  259. ia1 = ia1 + twidCoefModifier;
  260. for (i0 = j; i0 < fftLen; i0 += n1)
  261. {
  262. /* index calculation for the input as, */
  263. /* pSrc[i0 + 0], pSrc[i0 + fftLen/4], pSrc[i0 + fftLen/2U], pSrc[i0 + 3fftLen/4] */
  264. i1 = i0 + n2;
  265. i2 = i1 + n2;
  266. i3 = i2 + n2;
  267. /* Butterfly implementation */
  268. /* xa + xc */
  269. r1 = pSrc[2U * i0] + pSrc[2U * i2];
  270. /* xa - xc */
  271. r2 = pSrc[2U * i0] - pSrc[2U * i2];
  272. /* ya + yc */
  273. s1 = pSrc[(2U * i0) + 1U] + pSrc[(2U * i2) + 1U];
  274. /* ya - yc */
  275. s2 = pSrc[(2U * i0) + 1U] - pSrc[(2U * i2) + 1U];
  276. /* xb + xd */
  277. t1 = pSrc[2U * i1] + pSrc[2U * i3];
  278. /* xa' = xa + xb + xc + xd */
  279. pSrc[2U * i0] = (r1 + t1) >> 2U;
  280. /* xa + xc -(xb + xd) */
  281. r1 = r1 - t1;
  282. /* yb + yd */
  283. t2 = pSrc[(2U * i1) + 1U] + pSrc[(2U * i3) + 1U];
  284. /* ya' = ya + yb + yc + yd */
  285. pSrc[(2U * i0) + 1U] = (s1 + t2) >> 2U;
  286. /* (ya + yc) - (yb + yd) */
  287. s1 = s1 - t2;
  288. /* (yb - yd) */
  289. t1 = pSrc[(2U * i1) + 1U] - pSrc[(2U * i3) + 1U];
  290. /* (xb - xd) */
  291. t2 = pSrc[2U * i1] - pSrc[2U * i3];
  292. /* xc' = (xa-xb+xc-xd)co2 + (ya-yb+yc-yd)(si2) */
  293. pSrc[2U * i1] = (((int32_t) (((q63_t) r1 * co2) >> 32)) +
  294. ((int32_t) (((q63_t) s1 * si2) >> 32))) >> 1U;
  295. /* yc' = (ya-yb+yc-yd)co2 - (xa-xb+xc-xd)(si2) */
  296. pSrc[(2U * i1) + 1U] = (((int32_t) (((q63_t) s1 * co2) >> 32)) -
  297. ((int32_t) (((q63_t) r1 * si2) >> 32))) >> 1U;
  298. /* (xa - xc) + (yb - yd) */
  299. r1 = r2 + t1;
  300. /* (xa - xc) - (yb - yd) */
  301. r2 = r2 - t1;
  302. /* (ya - yc) - (xb - xd) */
  303. s1 = s2 - t2;
  304. /* (ya - yc) + (xb - xd) */
  305. s2 = s2 + t2;
  306. /* xb' = (xa+yb-xc-yd)co1 + (ya-xb-yc+xd)(si1) */
  307. pSrc[2U * i2] = (((int32_t) (((q63_t) r1 * co1) >> 32)) +
  308. ((int32_t) (((q63_t) s1 * si1) >> 32))) >> 1U;
  309. /* yb' = (ya-xb-yc+xd)co1 - (xa+yb-xc-yd)(si1) */
  310. pSrc[(2U * i2) + 1U] = (((int32_t) (((q63_t) s1 * co1) >> 32)) -
  311. ((int32_t) (((q63_t) r1 * si1) >> 32))) >> 1U;
  312. /* xd' = (xa-yb-xc+yd)co3 + (ya+xb-yc-xd)(si3) */
  313. pSrc[2U * i3] = (((int32_t) (((q63_t) r2 * co3) >> 32)) +
  314. ((int32_t) (((q63_t) s2 * si3) >> 32))) >> 1U;
  315. /* yd' = (ya+xb-yc-xd)co3 - (xa-yb-xc+yd)(si3) */
  316. pSrc[(2U * i3) + 1U] = (((int32_t) (((q63_t) s2 * co3) >> 32)) -
  317. ((int32_t) (((q63_t) r2 * si3) >> 32))) >> 1U;
  318. }
  319. }
  320. twidCoefModifier <<= 2U;
  321. }
  322. #else
  323. uint32_t n1, n2, ia1, ia2, ia3, i0, j, k;
  324. q31_t t1, t2, r1, r2, s1, s2, co1, co2, co3, si1, si2, si3;
  325. q31_t xa, xb, xc, xd;
  326. q31_t ya, yb, yc, yd;
  327. q31_t xa_out, xb_out, xc_out, xd_out;
  328. q31_t ya_out, yb_out, yc_out, yd_out;
  329. q31_t *ptr1;
  330. q31_t *pSi0;
  331. q31_t *pSi1;
  332. q31_t *pSi2;
  333. q31_t *pSi3;
  334. q63_t xaya, xbyb, xcyc, xdyd;
  335. /* Total process is divided into three stages */
  336. /* process first stage, middle stages, & last stage */
  337. /* start of first stage process */
  338. /* Initializations for the first stage */
  339. n2 = fftLen;
  340. n1 = n2;
  341. /* n2 = fftLen/4 */
  342. n2 >>= 2U;
  343. ia1 = 0U;
  344. j = n2;
  345. pSi0 = pSrc;
  346. pSi1 = pSi0 + 2 * n2;
  347. pSi2 = pSi1 + 2 * n2;
  348. pSi3 = pSi2 + 2 * n2;
  349. /* Calculation of first stage */
  350. do
  351. {
  352. /* input is in 1.31(q31) format and provide 4 guard bits for the input */
  353. /* Butterfly implementation */
  354. /* xa + xc */
  355. r1 = (pSi0[0] >> 4U) + (pSi2[0] >> 4U);
  356. /* xa - xc */
  357. r2 = (pSi0[0] >> 4U) - (pSi2[0] >> 4U);
  358. /* xb + xd */
  359. t1 = (pSi1[0] >> 4U) + (pSi3[0] >> 4U);
  360. /* ya + yc */
  361. s1 = (pSi0[1] >> 4U) + (pSi2[1] >> 4U);
  362. /* ya - yc */
  363. s2 = (pSi0[1] >> 4U) - (pSi2[1] >> 4U);
  364. /* xa' = xa + xb + xc + xd */
  365. *pSi0++ = (r1 + t1);
  366. /* (xa + xc) - (xb + xd) */
  367. r1 = r1 - t1;
  368. /* yb + yd */
  369. t2 = (pSi1[1] >> 4U) + (pSi3[1] >> 4U);
  370. /* ya' = ya + yb + yc + yd */
  371. *pSi0++ = (s1 + t2);
  372. /* (ya + yc) - (yb + yd) */
  373. s1 = s1 - t2;
  374. /* yb - yd */
  375. t1 = (pSi1[1] >> 4U) - (pSi3[1] >> 4U);
  376. /* xb - xd */
  377. t2 = (pSi1[0] >> 4U) - (pSi3[0] >> 4U);
  378. /* index calculation for the coefficients */
  379. ia2 = 2U * ia1;
  380. co2 = pCoef[ia2 * 2U];
  381. si2 = pCoef[(ia2 * 2U) + 1U];
  382. /* xc' = (xa-xb+xc-xd)co2 + (ya-yb+yc-yd)(si2) */
  383. *pSi1++ = (((int32_t) (((q63_t) r1 * co2) >> 32)) +
  384. ((int32_t) (((q63_t) s1 * si2) >> 32))) << 1U;
  385. /* yc' = (ya-yb+yc-yd)co2 - (xa-xb+xc-xd)(si2) */
  386. *pSi1++ = (((int32_t) (((q63_t) s1 * co2) >> 32)) -
  387. ((int32_t) (((q63_t) r1 * si2) >> 32))) << 1U;
  388. /* (xa - xc) + (yb - yd) */
  389. r1 = r2 + t1;
  390. /* (xa - xc) - (yb - yd) */
  391. r2 = r2 - t1;
  392. /* (ya - yc) - (xb - xd) */
  393. s1 = s2 - t2;
  394. /* (ya - yc) + (xb - xd) */
  395. s2 = s2 + t2;
  396. co1 = pCoef[ia1 * 2U];
  397. si1 = pCoef[(ia1 * 2U) + 1U];
  398. /* xb' = (xa+yb-xc-yd)co1 + (ya-xb-yc+xd)(si1) */
  399. *pSi2++ = (((int32_t) (((q63_t) r1 * co1) >> 32)) +
  400. ((int32_t) (((q63_t) s1 * si1) >> 32))) << 1U;
  401. /* yb' = (ya-xb-yc+xd)co1 - (xa+yb-xc-yd)(si1) */
  402. *pSi2++ = (((int32_t) (((q63_t) s1 * co1) >> 32)) -
  403. ((int32_t) (((q63_t) r1 * si1) >> 32))) << 1U;
  404. /* index calculation for the coefficients */
  405. ia3 = 3U * ia1;
  406. co3 = pCoef[ia3 * 2U];
  407. si3 = pCoef[(ia3 * 2U) + 1U];
  408. /* xd' = (xa-yb-xc+yd)co3 + (ya+xb-yc-xd)(si3) */
  409. *pSi3++ = (((int32_t) (((q63_t) r2 * co3) >> 32)) +
  410. ((int32_t) (((q63_t) s2 * si3) >> 32))) << 1U;
  411. /* yd' = (ya+xb-yc-xd)co3 - (xa-yb-xc+yd)(si3) */
  412. *pSi3++ = (((int32_t) (((q63_t) s2 * co3) >> 32)) -
  413. ((int32_t) (((q63_t) r2 * si3) >> 32))) << 1U;
  414. /* Twiddle coefficients index modifier */
  415. ia1 = ia1 + twidCoefModifier;
  416. } while (--j);
  417. /* end of first stage process */
  418. /* data is in 5.27(q27) format */
  419. /* start of Middle stages process */
  420. /* each stage in middle stages provides two down scaling of the input */
  421. twidCoefModifier <<= 2U;
  422. for (k = fftLen / 4U; k > 4U; k >>= 2U)
  423. {
  424. /* Initializations for the first stage */
  425. n1 = n2;
  426. n2 >>= 2U;
  427. ia1 = 0U;
  428. /* Calculation of first stage */
  429. for (j = 0U; j <= (n2 - 1U); j++)
  430. {
  431. /* index calculation for the coefficients */
  432. ia2 = ia1 + ia1;
  433. ia3 = ia2 + ia1;
  434. co1 = pCoef[ia1 * 2U];
  435. si1 = pCoef[(ia1 * 2U) + 1U];
  436. co2 = pCoef[ia2 * 2U];
  437. si2 = pCoef[(ia2 * 2U) + 1U];
  438. co3 = pCoef[ia3 * 2U];
  439. si3 = pCoef[(ia3 * 2U) + 1U];
  440. /* Twiddle coefficients index modifier */
  441. ia1 = ia1 + twidCoefModifier;
  442. pSi0 = pSrc + 2 * j;
  443. pSi1 = pSi0 + 2 * n2;
  444. pSi2 = pSi1 + 2 * n2;
  445. pSi3 = pSi2 + 2 * n2;
  446. for (i0 = j; i0 < fftLen; i0 += n1)
  447. {
  448. /* Butterfly implementation */
  449. /* xa + xc */
  450. r1 = pSi0[0] + pSi2[0];
  451. /* xa - xc */
  452. r2 = pSi0[0] - pSi2[0];
  453. /* ya + yc */
  454. s1 = pSi0[1] + pSi2[1];
  455. /* ya - yc */
  456. s2 = pSi0[1] - pSi2[1];
  457. /* xb + xd */
  458. t1 = pSi1[0] + pSi3[0];
  459. /* xa' = xa + xb + xc + xd */
  460. pSi0[0] = (r1 + t1) >> 2U;
  461. /* xa + xc -(xb + xd) */
  462. r1 = r1 - t1;
  463. /* yb + yd */
  464. t2 = pSi1[1] + pSi3[1];
  465. /* ya' = ya + yb + yc + yd */
  466. pSi0[1] = (s1 + t2) >> 2U;
  467. pSi0 += 2 * n1;
  468. /* (ya + yc) - (yb + yd) */
  469. s1 = s1 - t2;
  470. /* (yb - yd) */
  471. t1 = pSi1[1] - pSi3[1];
  472. /* (xb - xd) */
  473. t2 = pSi1[0] - pSi3[0];
  474. /* xc' = (xa-xb+xc-xd)co2 + (ya-yb+yc-yd)(si2) */
  475. pSi1[0] = (((int32_t) (((q63_t) r1 * co2) >> 32)) +
  476. ((int32_t) (((q63_t) s1 * si2) >> 32))) >> 1U;
  477. /* yc' = (ya-yb+yc-yd)co2 - (xa-xb+xc-xd)(si2) */
  478. pSi1[1] = (((int32_t) (((q63_t) s1 * co2) >> 32)) -
  479. ((int32_t) (((q63_t) r1 * si2) >> 32))) >> 1U;
  480. pSi1 += 2 * n1;
  481. /* (xa - xc) + (yb - yd) */
  482. r1 = r2 + t1;
  483. /* (xa - xc) - (yb - yd) */
  484. r2 = r2 - t1;
  485. /* (ya - yc) - (xb - xd) */
  486. s1 = s2 - t2;
  487. /* (ya - yc) + (xb - xd) */
  488. s2 = s2 + t2;
  489. /* xb' = (xa+yb-xc-yd)co1 + (ya-xb-yc+xd)(si1) */
  490. pSi2[0] = (((int32_t) (((q63_t) r1 * co1) >> 32)) +
  491. ((int32_t) (((q63_t) s1 * si1) >> 32))) >> 1U;
  492. /* yb' = (ya-xb-yc+xd)co1 - (xa+yb-xc-yd)(si1) */
  493. pSi2[1] = (((int32_t) (((q63_t) s1 * co1) >> 32)) -
  494. ((int32_t) (((q63_t) r1 * si1) >> 32))) >> 1U;
  495. pSi2 += 2 * n1;
  496. /* xd' = (xa-yb-xc+yd)co3 + (ya+xb-yc-xd)(si3) */
  497. pSi3[0] = (((int32_t) (((q63_t) r2 * co3) >> 32)) +
  498. ((int32_t) (((q63_t) s2 * si3) >> 32))) >> 1U;
  499. /* yd' = (ya+xb-yc-xd)co3 - (xa-yb-xc+yd)(si3) */
  500. pSi3[1] = (((int32_t) (((q63_t) s2 * co3) >> 32)) -
  501. ((int32_t) (((q63_t) r2 * si3) >> 32))) >> 1U;
  502. pSi3 += 2 * n1;
  503. }
  504. }
  505. twidCoefModifier <<= 2U;
  506. }
  507. #endif
  508. /* End of Middle stages process */
  509. /* data is in 11.21(q21) format for the 1024 point as there are 3 middle stages */
  510. /* data is in 9.23(q23) format for the 256 point as there are 2 middle stages */
  511. /* data is in 7.25(q25) format for the 64 point as there are 1 middle stage */
  512. /* data is in 5.27(q27) format for the 16 point as there are no middle stages */
  513. /* start of Last stage process */
  514. /* Initializations for the last stage */
  515. j = fftLen >> 2;
  516. ptr1 = &pSrc[0];
  517. /* Calculations of last stage */
  518. do
  519. {
  520. #ifndef ARM_MATH_BIG_ENDIAN
  521. /* Read xa (real), ya(imag) input */
  522. xaya = *__SIMD64(ptr1)++;
  523. xa = (q31_t) xaya;
  524. ya = (q31_t) (xaya >> 32);
  525. /* Read xb (real), yb(imag) input */
  526. xbyb = *__SIMD64(ptr1)++;
  527. xb = (q31_t) xbyb;
  528. yb = (q31_t) (xbyb >> 32);
  529. /* Read xc (real), yc(imag) input */
  530. xcyc = *__SIMD64(ptr1)++;
  531. xc = (q31_t) xcyc;
  532. yc = (q31_t) (xcyc >> 32);
  533. /* Read xc (real), yc(imag) input */
  534. xdyd = *__SIMD64(ptr1)++;
  535. xd = (q31_t) xdyd;
  536. yd = (q31_t) (xdyd >> 32);
  537. #else
  538. /* Read xa (real), ya(imag) input */
  539. xaya = *__SIMD64(ptr1)++;
  540. ya = (q31_t) xaya;
  541. xa = (q31_t) (xaya >> 32);
  542. /* Read xb (real), yb(imag) input */
  543. xbyb = *__SIMD64(ptr1)++;
  544. yb = (q31_t) xbyb;
  545. xb = (q31_t) (xbyb >> 32);
  546. /* Read xc (real), yc(imag) input */
  547. xcyc = *__SIMD64(ptr1)++;
  548. yc = (q31_t) xcyc;
  549. xc = (q31_t) (xcyc >> 32);
  550. /* Read xc (real), yc(imag) input */
  551. xdyd = *__SIMD64(ptr1)++;
  552. yd = (q31_t) xdyd;
  553. xd = (q31_t) (xdyd >> 32);
  554. #endif
  555. /* xa' = xa + xb + xc + xd */
  556. xa_out = xa + xb + xc + xd;
  557. /* ya' = ya + yb + yc + yd */
  558. ya_out = ya + yb + yc + yd;
  559. /* pointer updation for writing */
  560. ptr1 = ptr1 - 8U;
  561. /* writing xa' and ya' */
  562. *ptr1++ = xa_out;
  563. *ptr1++ = ya_out;
  564. xc_out = (xa - xb + xc - xd);
  565. yc_out = (ya - yb + yc - yd);
  566. /* writing xc' and yc' */
  567. *ptr1++ = xc_out;
  568. *ptr1++ = yc_out;
  569. xb_out = (xa + yb - xc - yd);
  570. yb_out = (ya - xb - yc + xd);
  571. /* writing xb' and yb' */
  572. *ptr1++ = xb_out;
  573. *ptr1++ = yb_out;
  574. xd_out = (xa - yb - xc + yd);
  575. yd_out = (ya + xb - yc - xd);
  576. /* writing xd' and yd' */
  577. *ptr1++ = xd_out;
  578. *ptr1++ = yd_out;
  579. } while (--j);
  580. /* output is in 11.21(q21) format for the 1024 point */
  581. /* output is in 9.23(q23) format for the 256 point */
  582. /* output is in 7.25(q25) format for the 64 point */
  583. /* output is in 5.27(q27) format for the 16 point */
  584. /* End of last stage process */
  585. }
  586. /**
  587. * @brief Core function for the Q31 CIFFT butterfly process.
  588. * @param[in, out] *pSrc points to the in-place buffer of Q31 data type.
  589. * @param[in] fftLen length of the FFT.
  590. * @param[in] *pCoef points to twiddle coefficient buffer.
  591. * @param[in] twidCoefModifier twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table.
  592. * @return none.
  593. */
  594. /*
  595. * Radix-4 IFFT algorithm used is :
  596. *
  597. * CIFFT uses same twiddle coefficients as CFFT Function
  598. * x[k] = x[n] + (j)k * x[n + fftLen/4] + (-1)k * x[n+fftLen/2] + (-j)k * x[n+3*fftLen/4]
  599. *
  600. *
  601. * IFFT is implemented with following changes in equations from FFT
  602. *
  603. * Input real and imaginary data:
  604. * x(n) = xa + j * ya
  605. * x(n+N/4 ) = xb + j * yb
  606. * x(n+N/2 ) = xc + j * yc
  607. * x(n+3N 4) = xd + j * yd
  608. *
  609. *
  610. * Output real and imaginary data:
  611. * x(4r) = xa'+ j * ya'
  612. * x(4r+1) = xb'+ j * yb'
  613. * x(4r+2) = xc'+ j * yc'
  614. * x(4r+3) = xd'+ j * yd'
  615. *
  616. *
  617. * Twiddle factors for radix-4 IFFT:
  618. * Wn = co1 + j * (si1)
  619. * W2n = co2 + j * (si2)
  620. * W3n = co3 + j * (si3)
  621. * The real and imaginary output values for the radix-4 butterfly are
  622. * xa' = xa + xb + xc + xd
  623. * ya' = ya + yb + yc + yd
  624. * xb' = (xa-yb-xc+yd)* co1 - (ya+xb-yc-xd)* (si1)
  625. * yb' = (ya+xb-yc-xd)* co1 + (xa-yb-xc+yd)* (si1)
  626. * xc' = (xa-xb+xc-xd)* co2 - (ya-yb+yc-yd)* (si2)
  627. * yc' = (ya-yb+yc-yd)* co2 + (xa-xb+xc-xd)* (si2)
  628. * xd' = (xa+yb-xc-yd)* co3 - (ya-xb-yc+xd)* (si3)
  629. * yd' = (ya-xb-yc+xd)* co3 + (xa+yb-xc-yd)* (si3)
  630. *
  631. */
  632. void arm_radix4_butterfly_inverse_q31(
  633. q31_t * pSrc,
  634. uint32_t fftLen,
  635. q31_t * pCoef,
  636. uint32_t twidCoefModifier)
  637. {
  638. #if defined(ARM_MATH_CM7)
  639. uint32_t n1, n2, ia1, ia2, ia3, i0, i1, i2, i3, j, k;
  640. q31_t t1, t2, r1, r2, s1, s2, co1, co2, co3, si1, si2, si3;
  641. q31_t xa, xb, xc, xd;
  642. q31_t ya, yb, yc, yd;
  643. q31_t xa_out, xb_out, xc_out, xd_out;
  644. q31_t ya_out, yb_out, yc_out, yd_out;
  645. q31_t *ptr1;
  646. q63_t xaya, xbyb, xcyc, xdyd;
  647. /* input is be 1.31(q31) format for all FFT sizes */
  648. /* Total process is divided into three stages */
  649. /* process first stage, middle stages, & last stage */
  650. /* Start of first stage process */
  651. /* Initializations for the first stage */
  652. n2 = fftLen;
  653. n1 = n2;
  654. /* n2 = fftLen/4 */
  655. n2 >>= 2U;
  656. i0 = 0U;
  657. ia1 = 0U;
  658. j = n2;
  659. do
  660. {
  661. /* input is in 1.31(q31) format and provide 4 guard bits for the input */
  662. /* index calculation for the input as, */
  663. /* pSrc[i0 + 0], pSrc[i0 + fftLen/4], pSrc[i0 + fftLen/2U], pSrc[i0 + 3fftLen/4] */
  664. i1 = i0 + n2;
  665. i2 = i1 + n2;
  666. i3 = i2 + n2;
  667. /* Butterfly implementation */
  668. /* xa + xc */
  669. r1 = (pSrc[2U * i0] >> 4U) + (pSrc[2U * i2] >> 4U);
  670. /* xa - xc */
  671. r2 = (pSrc[2U * i0] >> 4U) - (pSrc[2U * i2] >> 4U);
  672. /* xb + xd */
  673. t1 = (pSrc[2U * i1] >> 4U) + (pSrc[2U * i3] >> 4U);
  674. /* ya + yc */
  675. s1 = (pSrc[(2U * i0) + 1U] >> 4U) + (pSrc[(2U * i2) + 1U] >> 4U);
  676. /* ya - yc */
  677. s2 = (pSrc[(2U * i0) + 1U] >> 4U) - (pSrc[(2U * i2) + 1U] >> 4U);
  678. /* xa' = xa + xb + xc + xd */
  679. pSrc[2U * i0] = (r1 + t1);
  680. /* (xa + xc) - (xb + xd) */
  681. r1 = r1 - t1;
  682. /* yb + yd */
  683. t2 = (pSrc[(2U * i1) + 1U] >> 4U) + (pSrc[(2U * i3) + 1U] >> 4U);
  684. /* ya' = ya + yb + yc + yd */
  685. pSrc[(2U * i0) + 1U] = (s1 + t2);
  686. /* (ya + yc) - (yb + yd) */
  687. s1 = s1 - t2;
  688. /* yb - yd */
  689. t1 = (pSrc[(2U * i1) + 1U] >> 4U) - (pSrc[(2U * i3) + 1U] >> 4U);
  690. /* xb - xd */
  691. t2 = (pSrc[2U * i1] >> 4U) - (pSrc[2U * i3] >> 4U);
  692. /* index calculation for the coefficients */
  693. ia2 = 2U * ia1;
  694. co2 = pCoef[ia2 * 2U];
  695. si2 = pCoef[(ia2 * 2U) + 1U];
  696. /* xc' = (xa-xb+xc-xd)co2 - (ya-yb+yc-yd)(si2) */
  697. pSrc[2U * i1] = (((int32_t) (((q63_t) r1 * co2) >> 32)) -
  698. ((int32_t) (((q63_t) s1 * si2) >> 32))) << 1U;
  699. /* yc' = (ya-yb+yc-yd)co2 + (xa-xb+xc-xd)(si2) */
  700. pSrc[2U * i1 + 1U] = (((int32_t) (((q63_t) s1 * co2) >> 32)) +
  701. ((int32_t) (((q63_t) r1 * si2) >> 32))) << 1U;
  702. /* (xa - xc) - (yb - yd) */
  703. r1 = r2 - t1;
  704. /* (xa - xc) + (yb - yd) */
  705. r2 = r2 + t1;
  706. /* (ya - yc) + (xb - xd) */
  707. s1 = s2 + t2;
  708. /* (ya - yc) - (xb - xd) */
  709. s2 = s2 - t2;
  710. co1 = pCoef[ia1 * 2U];
  711. si1 = pCoef[(ia1 * 2U) + 1U];
  712. /* xb' = (xa+yb-xc-yd)co1 - (ya-xb-yc+xd)(si1) */
  713. pSrc[2U * i2] = (((int32_t) (((q63_t) r1 * co1) >> 32)) -
  714. ((int32_t) (((q63_t) s1 * si1) >> 32))) << 1U;
  715. /* yb' = (ya-xb-yc+xd)co1 + (xa+yb-xc-yd)(si1) */
  716. pSrc[(2U * i2) + 1U] = (((int32_t) (((q63_t) s1 * co1) >> 32)) +
  717. ((int32_t) (((q63_t) r1 * si1) >> 32))) << 1U;
  718. /* index calculation for the coefficients */
  719. ia3 = 3U * ia1;
  720. co3 = pCoef[ia3 * 2U];
  721. si3 = pCoef[(ia3 * 2U) + 1U];
  722. /* xd' = (xa-yb-xc+yd)co3 - (ya+xb-yc-xd)(si3) */
  723. pSrc[2U * i3] = (((int32_t) (((q63_t) r2 * co3) >> 32)) -
  724. ((int32_t) (((q63_t) s2 * si3) >> 32))) << 1U;
  725. /* yd' = (ya+xb-yc-xd)co3 + (xa-yb-xc+yd)(si3) */
  726. pSrc[(2U * i3) + 1U] = (((int32_t) (((q63_t) s2 * co3) >> 32)) +
  727. ((int32_t) (((q63_t) r2 * si3) >> 32))) << 1U;
  728. /* Twiddle coefficients index modifier */
  729. ia1 = ia1 + twidCoefModifier;
  730. /* Updating input index */
  731. i0 = i0 + 1U;
  732. } while (--j);
  733. /* data is in 5.27(q27) format */
  734. /* each stage provides two down scaling of the input */
  735. /* Start of Middle stages process */
  736. twidCoefModifier <<= 2U;
  737. /* Calculation of second stage to excluding last stage */
  738. for (k = fftLen / 4U; k > 4U; k >>= 2U)
  739. {
  740. /* Initializations for the first stage */
  741. n1 = n2;
  742. n2 >>= 2U;
  743. ia1 = 0U;
  744. for (j = 0; j <= (n2 - 1U); j++)
  745. {
  746. /* index calculation for the coefficients */
  747. ia2 = ia1 + ia1;
  748. ia3 = ia2 + ia1;
  749. co1 = pCoef[ia1 * 2U];
  750. si1 = pCoef[(ia1 * 2U) + 1U];
  751. co2 = pCoef[ia2 * 2U];
  752. si2 = pCoef[(ia2 * 2U) + 1U];
  753. co3 = pCoef[ia3 * 2U];
  754. si3 = pCoef[(ia3 * 2U) + 1U];
  755. /* Twiddle coefficients index modifier */
  756. ia1 = ia1 + twidCoefModifier;
  757. for (i0 = j; i0 < fftLen; i0 += n1)
  758. {
  759. /* index calculation for the input as, */
  760. /* pSrc[i0 + 0], pSrc[i0 + fftLen/4], pSrc[i0 + fftLen/2U], pSrc[i0 + 3fftLen/4] */
  761. i1 = i0 + n2;
  762. i2 = i1 + n2;
  763. i3 = i2 + n2;
  764. /* Butterfly implementation */
  765. /* xa + xc */
  766. r1 = pSrc[2U * i0] + pSrc[2U * i2];
  767. /* xa - xc */
  768. r2 = pSrc[2U * i0] - pSrc[2U * i2];
  769. /* ya + yc */
  770. s1 = pSrc[(2U * i0) + 1U] + pSrc[(2U * i2) + 1U];
  771. /* ya - yc */
  772. s2 = pSrc[(2U * i0) + 1U] - pSrc[(2U * i2) + 1U];
  773. /* xb + xd */
  774. t1 = pSrc[2U * i1] + pSrc[2U * i3];
  775. /* xa' = xa + xb + xc + xd */
  776. pSrc[2U * i0] = (r1 + t1) >> 2U;
  777. /* xa + xc -(xb + xd) */
  778. r1 = r1 - t1;
  779. /* yb + yd */
  780. t2 = pSrc[(2U * i1) + 1U] + pSrc[(2U * i3) + 1U];
  781. /* ya' = ya + yb + yc + yd */
  782. pSrc[(2U * i0) + 1U] = (s1 + t2) >> 2U;
  783. /* (ya + yc) - (yb + yd) */
  784. s1 = s1 - t2;
  785. /* (yb - yd) */
  786. t1 = pSrc[(2U * i1) + 1U] - pSrc[(2U * i3) + 1U];
  787. /* (xb - xd) */
  788. t2 = pSrc[2U * i1] - pSrc[2U * i3];
  789. /* xc' = (xa-xb+xc-xd)co2 - (ya-yb+yc-yd)(si2) */
  790. pSrc[2U * i1] = (((int32_t) (((q63_t) r1 * co2) >> 32U)) -
  791. ((int32_t) (((q63_t) s1 * si2) >> 32U))) >> 1U;
  792. /* yc' = (ya-yb+yc-yd)co2 + (xa-xb+xc-xd)(si2) */
  793. pSrc[(2U * i1) + 1U] =
  794. (((int32_t) (((q63_t) s1 * co2) >> 32U)) +
  795. ((int32_t) (((q63_t) r1 * si2) >> 32U))) >> 1U;
  796. /* (xa - xc) - (yb - yd) */
  797. r1 = r2 - t1;
  798. /* (xa - xc) + (yb - yd) */
  799. r2 = r2 + t1;
  800. /* (ya - yc) + (xb - xd) */
  801. s1 = s2 + t2;
  802. /* (ya - yc) - (xb - xd) */
  803. s2 = s2 - t2;
  804. /* xb' = (xa+yb-xc-yd)co1 - (ya-xb-yc+xd)(si1) */
  805. pSrc[2U * i2] = (((int32_t) (((q63_t) r1 * co1) >> 32)) -
  806. ((int32_t) (((q63_t) s1 * si1) >> 32))) >> 1U;
  807. /* yb' = (ya-xb-yc+xd)co1 + (xa+yb-xc-yd)(si1) */
  808. pSrc[(2U * i2) + 1U] = (((int32_t) (((q63_t) s1 * co1) >> 32)) +
  809. ((int32_t) (((q63_t) r1 * si1) >> 32))) >> 1U;
  810. /* xd' = (xa-yb-xc+yd)co3 - (ya+xb-yc-xd)(si3) */
  811. pSrc[(2U * i3)] = (((int32_t) (((q63_t) r2 * co3) >> 32)) -
  812. ((int32_t) (((q63_t) s2 * si3) >> 32))) >> 1U;
  813. /* yd' = (ya+xb-yc-xd)co3 + (xa-yb-xc+yd)(si3) */
  814. pSrc[(2U * i3) + 1U] = (((int32_t) (((q63_t) s2 * co3) >> 32)) +
  815. ((int32_t) (((q63_t) r2 * si3) >> 32))) >> 1U;
  816. }
  817. }
  818. twidCoefModifier <<= 2U;
  819. }
  820. #else
  821. uint32_t n1, n2, ia1, ia2, ia3, i0, j, k;
  822. q31_t t1, t2, r1, r2, s1, s2, co1, co2, co3, si1, si2, si3;
  823. q31_t xa, xb, xc, xd;
  824. q31_t ya, yb, yc, yd;
  825. q31_t xa_out, xb_out, xc_out, xd_out;
  826. q31_t ya_out, yb_out, yc_out, yd_out;
  827. q31_t *ptr1;
  828. q31_t *pSi0;
  829. q31_t *pSi1;
  830. q31_t *pSi2;
  831. q31_t *pSi3;
  832. q63_t xaya, xbyb, xcyc, xdyd;
  833. /* input is be 1.31(q31) format for all FFT sizes */
  834. /* Total process is divided into three stages */
  835. /* process first stage, middle stages, & last stage */
  836. /* Start of first stage process */
  837. /* Initializations for the first stage */
  838. n2 = fftLen;
  839. n1 = n2;
  840. /* n2 = fftLen/4 */
  841. n2 >>= 2U;
  842. ia1 = 0U;
  843. j = n2;
  844. pSi0 = pSrc;
  845. pSi1 = pSi0 + 2 * n2;
  846. pSi2 = pSi1 + 2 * n2;
  847. pSi3 = pSi2 + 2 * n2;
  848. do
  849. {
  850. /* Butterfly implementation */
  851. /* xa + xc */
  852. r1 = (pSi0[0] >> 4U) + (pSi2[0] >> 4U);
  853. /* xa - xc */
  854. r2 = (pSi0[0] >> 4U) - (pSi2[0] >> 4U);
  855. /* xb + xd */
  856. t1 = (pSi1[0] >> 4U) + (pSi3[0] >> 4U);
  857. /* ya + yc */
  858. s1 = (pSi0[1] >> 4U) + (pSi2[1] >> 4U);
  859. /* ya - yc */
  860. s2 = (pSi0[1] >> 4U) - (pSi2[1] >> 4U);
  861. /* xa' = xa + xb + xc + xd */
  862. *pSi0++ = (r1 + t1);
  863. /* (xa + xc) - (xb + xd) */
  864. r1 = r1 - t1;
  865. /* yb + yd */
  866. t2 = (pSi1[1] >> 4U) + (pSi3[1] >> 4U);
  867. /* ya' = ya + yb + yc + yd */
  868. *pSi0++ = (s1 + t2);
  869. /* (ya + yc) - (yb + yd) */
  870. s1 = s1 - t2;
  871. /* yb - yd */
  872. t1 = (pSi1[1] >> 4U) - (pSi3[1] >> 4U);
  873. /* xb - xd */
  874. t2 = (pSi1[0] >> 4U) - (pSi3[0] >> 4U);
  875. /* index calculation for the coefficients */
  876. ia2 = 2U * ia1;
  877. co2 = pCoef[ia2 * 2U];
  878. si2 = pCoef[(ia2 * 2U) + 1U];
  879. /* xc' = (xa-xb+xc-xd)co2 - (ya-yb+yc-yd)(si2) */
  880. *pSi1++ = (((int32_t) (((q63_t) r1 * co2) >> 32)) -
  881. ((int32_t) (((q63_t) s1 * si2) >> 32))) << 1U;
  882. /* yc' = (ya-yb+yc-yd)co2 + (xa-xb+xc-xd)(si2) */
  883. *pSi1++ = (((int32_t) (((q63_t) s1 * co2) >> 32)) +
  884. ((int32_t) (((q63_t) r1 * si2) >> 32))) << 1U;
  885. /* (xa - xc) - (yb - yd) */
  886. r1 = r2 - t1;
  887. /* (xa - xc) + (yb - yd) */
  888. r2 = r2 + t1;
  889. /* (ya - yc) + (xb - xd) */
  890. s1 = s2 + t2;
  891. /* (ya - yc) - (xb - xd) */
  892. s2 = s2 - t2;
  893. co1 = pCoef[ia1 * 2U];
  894. si1 = pCoef[(ia1 * 2U) + 1U];
  895. /* xb' = (xa+yb-xc-yd)co1 - (ya-xb-yc+xd)(si1) */
  896. *pSi2++ = (((int32_t) (((q63_t) r1 * co1) >> 32)) -
  897. ((int32_t) (((q63_t) s1 * si1) >> 32))) << 1U;
  898. /* yb' = (ya-xb-yc+xd)co1 + (xa+yb-xc-yd)(si1) */
  899. *pSi2++ = (((int32_t) (((q63_t) s1 * co1) >> 32)) +
  900. ((int32_t) (((q63_t) r1 * si1) >> 32))) << 1U;
  901. /* index calculation for the coefficients */
  902. ia3 = 3U * ia1;
  903. co3 = pCoef[ia3 * 2U];
  904. si3 = pCoef[(ia3 * 2U) + 1U];
  905. /* xd' = (xa-yb-xc+yd)co3 - (ya+xb-yc-xd)(si3) */
  906. *pSi3++ = (((int32_t) (((q63_t) r2 * co3) >> 32)) -
  907. ((int32_t) (((q63_t) s2 * si3) >> 32))) << 1U;
  908. /* yd' = (ya+xb-yc-xd)co3 + (xa-yb-xc+yd)(si3) */
  909. *pSi3++ = (((int32_t) (((q63_t) s2 * co3) >> 32)) +
  910. ((int32_t) (((q63_t) r2 * si3) >> 32))) << 1U;
  911. /* Twiddle coefficients index modifier */
  912. ia1 = ia1 + twidCoefModifier;
  913. } while (--j);
  914. /* data is in 5.27(q27) format */
  915. /* each stage provides two down scaling of the input */
  916. /* Start of Middle stages process */
  917. twidCoefModifier <<= 2U;
  918. /* Calculation of second stage to excluding last stage */
  919. for (k = fftLen / 4U; k > 4U; k >>= 2U)
  920. {
  921. /* Initializations for the first stage */
  922. n1 = n2;
  923. n2 >>= 2U;
  924. ia1 = 0U;
  925. for (j = 0; j <= (n2 - 1U); j++)
  926. {
  927. /* index calculation for the coefficients */
  928. ia2 = ia1 + ia1;
  929. ia3 = ia2 + ia1;
  930. co1 = pCoef[ia1 * 2U];
  931. si1 = pCoef[(ia1 * 2U) + 1U];
  932. co2 = pCoef[ia2 * 2U];
  933. si2 = pCoef[(ia2 * 2U) + 1U];
  934. co3 = pCoef[ia3 * 2U];
  935. si3 = pCoef[(ia3 * 2U) + 1U];
  936. /* Twiddle coefficients index modifier */
  937. ia1 = ia1 + twidCoefModifier;
  938. pSi0 = pSrc + 2 * j;
  939. pSi1 = pSi0 + 2 * n2;
  940. pSi2 = pSi1 + 2 * n2;
  941. pSi3 = pSi2 + 2 * n2;
  942. for (i0 = j; i0 < fftLen; i0 += n1)
  943. {
  944. /* Butterfly implementation */
  945. /* xa + xc */
  946. r1 = pSi0[0] + pSi2[0];
  947. /* xa - xc */
  948. r2 = pSi0[0] - pSi2[0];
  949. /* ya + yc */
  950. s1 = pSi0[1] + pSi2[1];
  951. /* ya - yc */
  952. s2 = pSi0[1] - pSi2[1];
  953. /* xb + xd */
  954. t1 = pSi1[0] + pSi3[0];
  955. /* xa' = xa + xb + xc + xd */
  956. pSi0[0] = (r1 + t1) >> 2U;
  957. /* xa + xc -(xb + xd) */
  958. r1 = r1 - t1;
  959. /* yb + yd */
  960. t2 = pSi1[1] + pSi3[1];
  961. /* ya' = ya + yb + yc + yd */
  962. pSi0[1] = (s1 + t2) >> 2U;
  963. pSi0 += 2 * n1;
  964. /* (ya + yc) - (yb + yd) */
  965. s1 = s1 - t2;
  966. /* (yb - yd) */
  967. t1 = pSi1[1] - pSi3[1];
  968. /* (xb - xd) */
  969. t2 = pSi1[0] - pSi3[0];
  970. /* xc' = (xa-xb+xc-xd)co2 - (ya-yb+yc-yd)(si2) */
  971. pSi1[0] = (((int32_t) (((q63_t) r1 * co2) >> 32U)) -
  972. ((int32_t) (((q63_t) s1 * si2) >> 32U))) >> 1U;
  973. /* yc' = (ya-yb+yc-yd)co2 + (xa-xb+xc-xd)(si2) */
  974. pSi1[1] =
  975. (((int32_t) (((q63_t) s1 * co2) >> 32U)) +
  976. ((int32_t) (((q63_t) r1 * si2) >> 32U))) >> 1U;
  977. pSi1 += 2 * n1;
  978. /* (xa - xc) - (yb - yd) */
  979. r1 = r2 - t1;
  980. /* (xa - xc) + (yb - yd) */
  981. r2 = r2 + t1;
  982. /* (ya - yc) + (xb - xd) */
  983. s1 = s2 + t2;
  984. /* (ya - yc) - (xb - xd) */
  985. s2 = s2 - t2;
  986. /* xb' = (xa+yb-xc-yd)co1 - (ya-xb-yc+xd)(si1) */
  987. pSi2[0] = (((int32_t) (((q63_t) r1 * co1) >> 32)) -
  988. ((int32_t) (((q63_t) s1 * si1) >> 32))) >> 1U;
  989. /* yb' = (ya-xb-yc+xd)co1 + (xa+yb-xc-yd)(si1) */
  990. pSi2[1] = (((int32_t) (((q63_t) s1 * co1) >> 32)) +
  991. ((int32_t) (((q63_t) r1 * si1) >> 32))) >> 1U;
  992. pSi2 += 2 * n1;
  993. /* xd' = (xa-yb-xc+yd)co3 - (ya+xb-yc-xd)(si3) */
  994. pSi3[0] = (((int32_t) (((q63_t) r2 * co3) >> 32)) -
  995. ((int32_t) (((q63_t) s2 * si3) >> 32))) >> 1U;
  996. /* yd' = (ya+xb-yc-xd)co3 + (xa-yb-xc+yd)(si3) */
  997. pSi3[1] = (((int32_t) (((q63_t) s2 * co3) >> 32)) +
  998. ((int32_t) (((q63_t) r2 * si3) >> 32))) >> 1U;
  999. pSi3 += 2 * n1;
  1000. }
  1001. }
  1002. twidCoefModifier <<= 2U;
  1003. }
  1004. #endif
  1005. /* End of Middle stages process */
  1006. /* data is in 11.21(q21) format for the 1024 point as there are 3 middle stages */
  1007. /* data is in 9.23(q23) format for the 256 point as there are 2 middle stages */
  1008. /* data is in 7.25(q25) format for the 64 point as there are 1 middle stage */
  1009. /* data is in 5.27(q27) format for the 16 point as there are no middle stages */
  1010. /* Start of last stage process */
  1011. /* Initializations for the last stage */
  1012. j = fftLen >> 2;
  1013. ptr1 = &pSrc[0];
  1014. /* Calculations of last stage */
  1015. do
  1016. {
  1017. #ifndef ARM_MATH_BIG_ENDIAN
  1018. /* Read xa (real), ya(imag) input */
  1019. xaya = *__SIMD64(ptr1)++;
  1020. xa = (q31_t) xaya;
  1021. ya = (q31_t) (xaya >> 32);
  1022. /* Read xb (real), yb(imag) input */
  1023. xbyb = *__SIMD64(ptr1)++;
  1024. xb = (q31_t) xbyb;
  1025. yb = (q31_t) (xbyb >> 32);
  1026. /* Read xc (real), yc(imag) input */
  1027. xcyc = *__SIMD64(ptr1)++;
  1028. xc = (q31_t) xcyc;
  1029. yc = (q31_t) (xcyc >> 32);
  1030. /* Read xc (real), yc(imag) input */
  1031. xdyd = *__SIMD64(ptr1)++;
  1032. xd = (q31_t) xdyd;
  1033. yd = (q31_t) (xdyd >> 32);
  1034. #else
  1035. /* Read xa (real), ya(imag) input */
  1036. xaya = *__SIMD64(ptr1)++;
  1037. ya = (q31_t) xaya;
  1038. xa = (q31_t) (xaya >> 32);
  1039. /* Read xb (real), yb(imag) input */
  1040. xbyb = *__SIMD64(ptr1)++;
  1041. yb = (q31_t) xbyb;
  1042. xb = (q31_t) (xbyb >> 32);
  1043. /* Read xc (real), yc(imag) input */
  1044. xcyc = *__SIMD64(ptr1)++;
  1045. yc = (q31_t) xcyc;
  1046. xc = (q31_t) (xcyc >> 32);
  1047. /* Read xc (real), yc(imag) input */
  1048. xdyd = *__SIMD64(ptr1)++;
  1049. yd = (q31_t) xdyd;
  1050. xd = (q31_t) (xdyd >> 32);
  1051. #endif
  1052. /* xa' = xa + xb + xc + xd */
  1053. xa_out = xa + xb + xc + xd;
  1054. /* ya' = ya + yb + yc + yd */
  1055. ya_out = ya + yb + yc + yd;
  1056. /* pointer updation for writing */
  1057. ptr1 = ptr1 - 8U;
  1058. /* writing xa' and ya' */
  1059. *ptr1++ = xa_out;
  1060. *ptr1++ = ya_out;
  1061. xc_out = (xa - xb + xc - xd);
  1062. yc_out = (ya - yb + yc - yd);
  1063. /* writing xc' and yc' */
  1064. *ptr1++ = xc_out;
  1065. *ptr1++ = yc_out;
  1066. xb_out = (xa - yb - xc + yd);
  1067. yb_out = (ya + xb - yc - xd);
  1068. /* writing xb' and yb' */
  1069. *ptr1++ = xb_out;
  1070. *ptr1++ = yb_out;
  1071. xd_out = (xa + yb - xc - yd);
  1072. yd_out = (ya - xb - yc + xd);
  1073. /* writing xd' and yd' */
  1074. *ptr1++ = xd_out;
  1075. *ptr1++ = yd_out;
  1076. } while (--j);
  1077. /* output is in 11.21(q21) format for the 1024 point */
  1078. /* output is in 9.23(q23) format for the 256 point */
  1079. /* output is in 7.25(q25) format for the 64 point */
  1080. /* output is in 5.27(q27) format for the 16 point */
  1081. /* End of last stage process */
  1082. }