arm_cfft_init_q31.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cfft_init_q31.c
  4. * Description: Initialization function for cfft q31 instance
  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. /**
  29. * @defgroup ComplexFFTQ31 Complex FFT Q31
  30. */
  31. /**
  32. @ingroup groupTransforms
  33. */
  34. /**
  35. @addtogroup ComplexFFT
  36. @{
  37. */
  38. /**
  39. @addtogroup ComplexFFTQ31
  40. @{
  41. */
  42. #include "dsp/transform_functions.h"
  43. #include "arm_common_tables.h"
  44. #include "arm_const_structs.h"
  45. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  46. #include "arm_vec_fft.h"
  47. #include "arm_mve_tables.h"
  48. #define CFFT_RADIX4BY2_REARRANGE_TWIDDLES_Q31(LEN) \
  49. static arm_status arm_cfft_radix4by2_rearrange_twiddles_##LEN##_q31(arm_cfft_instance_q31 *S)\
  50. { \
  51. S->rearranged_twiddle_tab_stride1_arr = rearranged_twiddle_tab_stride1_arr_##LEN##_q31; \
  52. S->rearranged_twiddle_stride1 = rearranged_twiddle_stride1_##LEN##_q31; \
  53. \
  54. S->rearranged_twiddle_tab_stride2_arr = rearranged_twiddle_tab_stride2_arr_##LEN##_q31; \
  55. S->rearranged_twiddle_stride2 = rearranged_twiddle_stride2_##LEN##_q31; \
  56. \
  57. S->rearranged_twiddle_tab_stride3_arr = rearranged_twiddle_tab_stride3_arr_##LEN##_q31; \
  58. S->rearranged_twiddle_stride3 = rearranged_twiddle_stride3_##LEN##_q31; \
  59. return(ARM_MATH_SUCCESS); \
  60. }
  61. CFFT_RADIX4BY2_REARRANGE_TWIDDLES_Q31(4096);
  62. CFFT_RADIX4BY2_REARRANGE_TWIDDLES_Q31(1024);
  63. CFFT_RADIX4BY2_REARRANGE_TWIDDLES_Q31(256);
  64. CFFT_RADIX4BY2_REARRANGE_TWIDDLES_Q31(64);
  65. CFFT_RADIX4BY2_REARRANGE_TWIDDLES_Q31(16);
  66. #define CFFTINIT_Q31(LEN,LENTWIDDLE) \
  67. arm_status arm_cfft_init_##LEN##_q31( \
  68. arm_cfft_instance_q31 * S) \
  69. { \
  70. /* Initialise the default arm status */ \
  71. arm_status status = ARM_MATH_SUCCESS; \
  72. \
  73. /* Initialise the FFT length */ \
  74. S->fftLen = LEN; \
  75. \
  76. /* Initialise the Twiddle coefficient pointer */ \
  77. S->pTwiddle = NULL; \
  78. \
  79. /* Initialise the bit reversal table modifier */ \
  80. S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_##LEN##_TABLE_LENGTH; \
  81. S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_##LEN; \
  82. S->pTwiddle = (q31_t *)twiddleCoef_##LEN##_q31; \
  83. status=arm_cfft_radix4by2_rearrange_twiddles_##LENTWIDDLE##_q31(S);\
  84. \
  85. return (status); \
  86. }
  87. #else
  88. #define FFTINIT(EXT,SIZE) \
  89. S->bitRevLength = arm_cfft_sR_##EXT##_len##SIZE.bitRevLength; \
  90. S->pBitRevTable = arm_cfft_sR_##EXT##_len##SIZE.pBitRevTable; \
  91. S->pTwiddle = arm_cfft_sR_##EXT##_len##SIZE.pTwiddle;
  92. #define CFFTINIT_Q31(LEN,LENTWIDDLE) \
  93. arm_status arm_cfft_init_##LEN##_q31(arm_cfft_instance_q31 * S)\
  94. { \
  95. /* Initialise the default arm status */ \
  96. arm_status status = ARM_MATH_SUCCESS; \
  97. \
  98. /* Initialise the FFT length */ \
  99. S->fftLen = LEN; \
  100. \
  101. /* Initialise the Twiddle coefficient pointer */ \
  102. S->pTwiddle = NULL; \
  103. \
  104. FFTINIT(q31,LEN); \
  105. \
  106. return (status); \
  107. }
  108. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  109. /**
  110. @brief Initialization function for the cfft q31 function for 4096 samples
  111. @param[in,out] S points to an instance of the floating-point CFFT structure
  112. @return execution status
  113. - \ref ARM_MATH_SUCCESS : Operation successful
  114. - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
  115. @par Use of this function is mandatory only for the MVE version of the FFT.
  116. Other versions can still initialize directly the data structure using
  117. variables declared in arm_const_structs.h
  118. */
  119. CFFTINIT_Q31(4096,4096)
  120. /**
  121. @brief Initialization function for the cfft q31 function for 2048 samples
  122. @param[in,out] S points to an instance of the floating-point CFFT structure
  123. @return execution status
  124. - \ref ARM_MATH_SUCCESS : Operation successful
  125. - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
  126. @par Use of this function is mandatory only for the MVE version of the FFT.
  127. Other versions can still initialize directly the data structure using
  128. variables declared in arm_const_structs.h
  129. */
  130. CFFTINIT_Q31(2048,1024)
  131. /**
  132. @brief Initialization function for the cfft q31 function for 1024 samples
  133. @param[in,out] S points to an instance of the floating-point CFFT structure
  134. @return execution status
  135. - \ref ARM_MATH_SUCCESS : Operation successful
  136. - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
  137. @par Use of this function is mandatory only for the MVE version of the FFT.
  138. Other versions can still initialize directly the data structure using
  139. variables declared in arm_const_structs.h
  140. */
  141. CFFTINIT_Q31(1024,1024)
  142. /**
  143. @brief Initialization function for the cfft q31 function for 512 samples
  144. @param[in,out] S points to an instance of the floating-point CFFT structure
  145. @return execution status
  146. - \ref ARM_MATH_SUCCESS : Operation successful
  147. - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
  148. @par Use of this function is mandatory only for the MVE version of the FFT.
  149. Other versions can still initialize directly the data structure using
  150. variables declared in arm_const_structs.h
  151. */
  152. CFFTINIT_Q31(512,256)
  153. /**
  154. @brief Initialization function for the cfft q31 function for 256 samples
  155. @param[in,out] S points to an instance of the floating-point CFFT structure
  156. @return execution status
  157. - \ref ARM_MATH_SUCCESS : Operation successful
  158. - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
  159. @par Use of this function is mandatory only for the MVE version of the FFT.
  160. Other versions can still initialize directly the data structure using
  161. variables declared in arm_const_structs.h
  162. */
  163. CFFTINIT_Q31(256,256)
  164. /**
  165. @brief Initialization function for the cfft q31 function for 128 samples
  166. @param[in,out] S points to an instance of the floating-point CFFT structure
  167. @return execution status
  168. - \ref ARM_MATH_SUCCESS : Operation successful
  169. - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
  170. @par Use of this function is mandatory only for the MVE version of the FFT.
  171. Other versions can still initialize directly the data structure using
  172. variables declared in arm_const_structs.h
  173. */
  174. CFFTINIT_Q31(128,64)
  175. /**
  176. @brief Initialization function for the cfft q31 function for 64 samples
  177. @param[in,out] S points to an instance of the floating-point CFFT structure
  178. @return execution status
  179. - \ref ARM_MATH_SUCCESS : Operation successful
  180. - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
  181. @par Use of this function is mandatory only for the MVE version of the FFT.
  182. Other versions can still initialize directly the data structure using
  183. variables declared in arm_const_structs.h
  184. */
  185. CFFTINIT_Q31(64,64)
  186. /**
  187. @brief Initialization function for the cfft q31 function for 32 samples
  188. @param[in,out] S points to an instance of the floating-point CFFT structure
  189. @return execution status
  190. - \ref ARM_MATH_SUCCESS : Operation successful
  191. - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
  192. @par Use of this function is mandatory only for the MVE version of the FFT.
  193. Other versions can still initialize directly the data structure using
  194. variables declared in arm_const_structs.h
  195. */
  196. CFFTINIT_Q31(32,16)
  197. /**
  198. @brief Initialization function for the cfft q31 function for 16 samples
  199. @param[in,out] S points to an instance of the floating-point CFFT structure
  200. @return execution status
  201. - \ref ARM_MATH_SUCCESS : Operation successful
  202. - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
  203. @par Use of this function is mandatory only for the MVE version of the FFT.
  204. Other versions can still initialize directly the data structure using
  205. variables declared in arm_const_structs.h
  206. */
  207. CFFTINIT_Q31(16,16)
  208. /**
  209. @brief Generic initialization function for the cfft q31 function
  210. @param[in,out] S points to an instance of the floating-point CFFT structure
  211. @param[in] fftLen fft length (number of complex samples)
  212. @return execution status
  213. - \ref ARM_MATH_SUCCESS : Operation successful
  214. - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
  215. @par Use of this function is mandatory only for the MVE version of the FFT.
  216. Other versions can still initialize directly the data structure using
  217. variables declared in arm_const_structs.h
  218. @par
  219. This function should be used only if you don't know the FFT sizes that
  220. you'll need at build time. The use of this function will prevent the
  221. linker from removing the FFT tables that are not needed and the library
  222. code size will be bigger than needed.
  223. @par
  224. If you use CMSIS-DSP as a static library, and if you know the FFT sizes
  225. that you need at build time, then it is better to use the initialization
  226. functions defined for each FFT size.
  227. */
  228. arm_status arm_cfft_init_q31(
  229. arm_cfft_instance_q31 * S,
  230. uint16_t fftLen)
  231. {
  232. /* Initialise the default arm status */
  233. arm_status status = ARM_MATH_SUCCESS;
  234. /* Initializations of Instance structure depending on the FFT length */
  235. switch (fftLen) {
  236. /* Initializations of structure parameters for 4096 point FFT */
  237. case 4096U:
  238. /* Initialise the bit reversal table modifier */
  239. status=arm_cfft_init_4096_q31(S);
  240. break;
  241. /* Initializations of structure parameters for 2048 point FFT */
  242. case 2048U:
  243. /* Initialise the bit reversal table modifier */
  244. status=arm_cfft_init_2048_q31(S);
  245. break;
  246. /* Initializations of structure parameters for 1024 point FFT */
  247. case 1024U:
  248. /* Initialise the bit reversal table modifier */
  249. status=arm_cfft_init_1024_q31(S);
  250. break;
  251. /* Initializations of structure parameters for 512 point FFT */
  252. case 512U:
  253. /* Initialise the bit reversal table modifier */
  254. status=arm_cfft_init_512_q31(S);
  255. break;
  256. case 256U:
  257. status=arm_cfft_init_256_q31(S);
  258. break;
  259. case 128U:
  260. status=arm_cfft_init_128_q31(S);
  261. break;
  262. case 64U:
  263. status=arm_cfft_init_64_q31(S);
  264. break;
  265. case 32U:
  266. status=arm_cfft_init_32_q31(S);
  267. break;
  268. case 16U:
  269. /* Initializations of structure parameters for 16 point FFT */
  270. status=arm_cfft_init_16_q31(S);
  271. break;
  272. default:
  273. /* Reporting argument error if fftSize is not valid value */
  274. status = ARM_MATH_ARGUMENT_ERROR;
  275. break;
  276. }
  277. return (status);
  278. }
  279. /**
  280. @} end of ComplexFFTQ31 group
  281. */
  282. /**
  283. @} end of ComplexFFT group
  284. */