arm_rfft_init_q15.c 20 KB

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