arm_rfft_init_q31.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_rfft_init_q31.c
  4. * Description: RFFT & RIFFT Q31 initialisation 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. #include "arm_const_structs.h"
  31. /**
  32. @ingroup RealFFT
  33. */
  34. /**
  35. @defgroup RealFFTQ31 Real FFT Q31 Functions
  36. */
  37. /**
  38. @addtogroup RealFFTQ31
  39. @{
  40. */
  41. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  42. #define RFFTINIT_Q31(LEN,CFFTLEN,TWIDMOD) \
  43. arm_status arm_rfft_init_##LEN##_q31( arm_rfft_instance_q31 * S, \
  44. uint32_t ifftFlagR, \
  45. uint32_t bitReverseFlag ) \
  46. { \
  47. /* Initialise the default arm status */ \
  48. arm_status status = ARM_MATH_ARGUMENT_ERROR; \
  49. \
  50. /* Initialize the Real FFT length */ \
  51. S->fftLenReal = (uint16_t) LEN; \
  52. \
  53. /* Initialize the Twiddle coefficientA pointer */ \
  54. S->pTwiddleAReal = (q31_t *) realCoefAQ31; \
  55. \
  56. /* Initialize the Twiddle coefficientB pointer */ \
  57. S->pTwiddleBReal = (q31_t *) realCoefBQ31; \
  58. \
  59. /* Initialize the Flag for selection of RFFT or RIFFT */ \
  60. S->ifftFlagR = (uint8_t) ifftFlagR; \
  61. \
  62. /* Initialize the Flag for calculation Bit reversal or not */\
  63. S->bitReverseFlagR = (uint8_t) bitReverseFlag; \
  64. \
  65. S->twidCoefRModifier = TWIDMOD; \
  66. \
  67. status=arm_cfft_init_##CFFTLEN##_q31(&(S->cfftInst)); \
  68. \
  69. /* return the status of RFFT Init function */ \
  70. return (status); \
  71. }
  72. #else
  73. #define RFFTINIT_Q31(LEN,CFFTLEN,TWIDMOD) \
  74. arm_status arm_rfft_init_##LEN##_q31( arm_rfft_instance_q31 * S, \
  75. uint32_t ifftFlagR, \
  76. uint32_t bitReverseFlag ) \
  77. { \
  78. /* Initialize the Real FFT length */ \
  79. S->fftLenReal = (uint16_t) LEN; \
  80. \
  81. /* Initialize the Twiddle coefficientA pointer */ \
  82. S->pTwiddleAReal = (q31_t *) realCoefAQ31; \
  83. \
  84. /* Initialize the Twiddle coefficientB pointer */ \
  85. S->pTwiddleBReal = (q31_t *) realCoefBQ31; \
  86. \
  87. /* Initialize the Flag for selection of RFFT or RIFFT */ \
  88. S->ifftFlagR = (uint8_t) ifftFlagR; \
  89. \
  90. /* Initialize the Flag for calculation Bit reversal or not */\
  91. S->bitReverseFlagR = (uint8_t) bitReverseFlag; \
  92. \
  93. S->twidCoefRModifier = TWIDMOD; \
  94. \
  95. S->pCfft = &arm_cfft_sR_q31_len##CFFTLEN; \
  96. \
  97. /* return the status of RFFT Init function */ \
  98. return (ARM_MATH_SUCCESS); \
  99. }
  100. #endif
  101. /**
  102. @brief Initialization function for the 8192 pt Q31 real FFT.
  103. @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
  104. @param[in] ifftFlagR flag that selects transform direction
  105. - value = 0: forward transform
  106. - value = 1: inverse transform
  107. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  108. - value = 0: disables bit reversal of output
  109. - value = 1: enables bit reversal of output
  110. @return execution status
  111. - \ref ARM_MATH_SUCCESS : Operation successful
  112. - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
  113. @par
  114. The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
  115. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
  116. @par
  117. The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
  118. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
  119. @par
  120. This function also initializes Twiddle factor table.
  121. */
  122. RFFTINIT_Q31(8192,4096,1)
  123. /**
  124. @brief Initialization function for the 4096 pt Q31 real FFT.
  125. @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
  126. @param[in] ifftFlagR flag that selects transform direction
  127. - value = 0: forward transform
  128. - value = 1: inverse transform
  129. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  130. - value = 0: disables bit reversal of output
  131. - value = 1: enables bit reversal of output
  132. @return execution status
  133. - \ref ARM_MATH_SUCCESS : Operation successful
  134. - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
  135. @par
  136. The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
  137. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
  138. @par
  139. The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
  140. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
  141. @par
  142. This function also initializes Twiddle factor table.
  143. */
  144. RFFTINIT_Q31(4096,2048,2)
  145. /**
  146. @brief Initialization function for the 2048 pt Q31 real FFT.
  147. @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
  148. @param[in] ifftFlagR flag that selects transform direction
  149. - value = 0: forward transform
  150. - value = 1: inverse transform
  151. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  152. - value = 0: disables bit reversal of output
  153. - value = 1: enables bit reversal of output
  154. @return execution status
  155. - \ref ARM_MATH_SUCCESS : Operation successful
  156. - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
  157. @par
  158. The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
  159. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
  160. @par
  161. The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
  162. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
  163. @par
  164. This function also initializes Twiddle factor table.
  165. */
  166. RFFTINIT_Q31(2048,1024,4)
  167. /**
  168. @brief Initialization function for the 1024 pt Q31 real FFT.
  169. @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
  170. @param[in] ifftFlagR flag that selects transform direction
  171. - value = 0: forward transform
  172. - value = 1: inverse transform
  173. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  174. - value = 0: disables bit reversal of output
  175. - value = 1: enables bit reversal of output
  176. @return execution status
  177. - \ref ARM_MATH_SUCCESS : Operation successful
  178. - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
  179. @par
  180. The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
  181. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
  182. @par
  183. The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
  184. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
  185. @par
  186. This function also initializes Twiddle factor table.
  187. */
  188. RFFTINIT_Q31(1024,512,8)
  189. /**
  190. @brief Initialization function for the 512 pt Q31 real FFT.
  191. @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
  192. @param[in] ifftFlagR flag that selects transform direction
  193. - value = 0: forward transform
  194. - value = 1: inverse transform
  195. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  196. - value = 0: disables bit reversal of output
  197. - value = 1: enables bit reversal of output
  198. @return execution status
  199. - \ref ARM_MATH_SUCCESS : Operation successful
  200. - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
  201. @par
  202. The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
  203. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
  204. @par
  205. The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
  206. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
  207. @par
  208. This function also initializes Twiddle factor table.
  209. */
  210. RFFTINIT_Q31(512,256,16)
  211. /**
  212. @brief Initialization function for the 256 pt Q31 real FFT.
  213. @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
  214. @param[in] ifftFlagR flag that selects transform direction
  215. - value = 0: forward transform
  216. - value = 1: inverse transform
  217. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  218. - value = 0: disables bit reversal of output
  219. - value = 1: enables bit reversal of output
  220. @return execution status
  221. - \ref ARM_MATH_SUCCESS : Operation successful
  222. - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
  223. @par
  224. The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
  225. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
  226. @par
  227. The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
  228. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
  229. @par
  230. This function also initializes Twiddle factor table.
  231. */
  232. RFFTINIT_Q31(256,128,32)
  233. /**
  234. @brief Initialization function for the 128 pt Q31 real FFT.
  235. @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
  236. @param[in] ifftFlagR flag that selects transform direction
  237. - value = 0: forward transform
  238. - value = 1: inverse transform
  239. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  240. - value = 0: disables bit reversal of output
  241. - value = 1: enables bit reversal of output
  242. @return execution status
  243. - \ref ARM_MATH_SUCCESS : Operation successful
  244. - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
  245. @par
  246. The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
  247. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
  248. @par
  249. The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
  250. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
  251. @par
  252. This function also initializes Twiddle factor table.
  253. */
  254. RFFTINIT_Q31(128,64,64)
  255. /**
  256. @brief Initialization function for the 64 pt Q31 real FFT.
  257. @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
  258. @param[in] ifftFlagR flag that selects transform direction
  259. - value = 0: forward transform
  260. - value = 1: inverse transform
  261. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  262. - value = 0: disables bit reversal of output
  263. - value = 1: enables bit reversal of output
  264. @return execution status
  265. - \ref ARM_MATH_SUCCESS : Operation successful
  266. - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
  267. @par
  268. The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
  269. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
  270. @par
  271. The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
  272. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
  273. @par
  274. This function also initializes Twiddle factor table.
  275. */
  276. RFFTINIT_Q31(64,32,128)
  277. /**
  278. @brief Initialization function for the 32 pt Q31 real FFT.
  279. @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
  280. @param[in] ifftFlagR flag that selects transform direction
  281. - value = 0: forward transform
  282. - value = 1: inverse transform
  283. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  284. - value = 0: disables bit reversal of output
  285. - value = 1: enables bit reversal of output
  286. @return execution status
  287. - \ref ARM_MATH_SUCCESS : Operation successful
  288. - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
  289. @par
  290. The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
  291. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
  292. @par
  293. The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
  294. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
  295. @par
  296. This function also initializes Twiddle factor table.
  297. */
  298. RFFTINIT_Q31(32,16,256)
  299. /**
  300. @brief Generic initialization function for the Q31 RFFT/RIFFT.
  301. @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
  302. @param[in] fftLenReal length of the FFT
  303. @param[in] ifftFlagR flag that selects transform direction
  304. - value = 0: forward transform
  305. - value = 1: inverse transform
  306. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  307. - value = 0: disables bit reversal of output
  308. - value = 1: enables bit reversal of output
  309. @return execution status
  310. - \ref ARM_MATH_SUCCESS : Operation successful
  311. - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
  312. @par Details
  313. The parameter <code>fftLenReal</code> specifies length of RFFT/RIFFT Process.
  314. Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192.
  315. @par
  316. The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
  317. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
  318. @par
  319. The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
  320. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
  321. @par
  322. This function also initializes Twiddle factor table.
  323. @par
  324. This function should be used only if you don't know the FFT sizes that
  325. you'll need at build time. The use of this function will prevent the
  326. linker from removing the FFT tables that are not needed and the library
  327. code size will be bigger than needed.
  328. @par
  329. If you use CMSIS-DSP as a static library, and if you know the FFT sizes
  330. that you need at build time, then it is better to use the initialization
  331. functions defined for each FFT size.
  332. */
  333. arm_status arm_rfft_init_q31(
  334. arm_rfft_instance_q31 * S,
  335. uint32_t fftLenReal,
  336. uint32_t ifftFlagR,
  337. uint32_t bitReverseFlag)
  338. {
  339. /* Initialise the default arm status */
  340. arm_status status = ARM_MATH_ARGUMENT_ERROR;
  341. /* Initialization of coef modifier depending on the FFT length */
  342. switch (fftLenReal)
  343. {
  344. case 8192U:
  345. status = arm_rfft_init_8192_q31( S,ifftFlagR,bitReverseFlag );
  346. break;
  347. case 4096U:
  348. status = arm_rfft_init_4096_q31( S,ifftFlagR,bitReverseFlag );
  349. break;
  350. case 2048U:
  351. status = arm_rfft_init_2048_q31( S,ifftFlagR,bitReverseFlag );
  352. break;
  353. case 1024U:
  354. status = arm_rfft_init_1024_q31( S,ifftFlagR,bitReverseFlag );
  355. break;
  356. case 512U:
  357. status = arm_rfft_init_512_q31( S,ifftFlagR,bitReverseFlag );
  358. break;
  359. case 256U:
  360. status = arm_rfft_init_256_q31( S,ifftFlagR,bitReverseFlag );
  361. break;
  362. case 128U:
  363. status = arm_rfft_init_128_q31( S,ifftFlagR,bitReverseFlag );
  364. break;
  365. case 64U:
  366. status = arm_rfft_init_64_q31( S,ifftFlagR,bitReverseFlag );
  367. break;
  368. case 32U:
  369. status = arm_rfft_init_32_q31( S,ifftFlagR,bitReverseFlag );
  370. break;
  371. default:
  372. /* Reporting argument error if rfftSize is not valid value */
  373. status = ARM_MATH_ARGUMENT_ERROR;
  374. break;
  375. }
  376. /* return the status of RFFT Init function */
  377. return (status);
  378. }
  379. /**
  380. @} end of RealFFTQ31 group
  381. */