arm_rfft_init_q31.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_rfft_init_q31.c
  4. * Description: RFFT & RIFFT Q31 initialisation function
  5. *
  6. * $Date: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #include "arm_math.h"
  29. #include "arm_common_tables.h"
  30. #include "arm_const_structs.h"
  31. /**
  32. @addtogroup RealFFT
  33. @{
  34. */
  35. /**
  36. @brief Initialization function for the Q31 RFFT/RIFFT.
  37. @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
  38. @param[in] fftLenReal length of the FFT
  39. @param[in] ifftFlagR flag that selects transform direction
  40. - value = 0: forward transform
  41. - value = 1: inverse transform
  42. @param[in] bitReverseFlag flag that enables / disables bit reversal of output
  43. - value = 0: disables bit reversal of output
  44. - value = 1: enables bit reversal of output
  45. @return execution status
  46. - \ref ARM_MATH_SUCCESS : Operation successful
  47. - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
  48. @par Details
  49. The parameter <code>fftLenReal</code> specifies length of RFFT/RIFFT Process.
  50. Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192.
  51. @par
  52. The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
  53. Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
  54. @par
  55. The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
  56. Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
  57. @par
  58. This function also initializes Twiddle factor table.
  59. */
  60. arm_status arm_rfft_init_q31(
  61. arm_rfft_instance_q31 * S,
  62. uint32_t fftLenReal,
  63. uint32_t ifftFlagR,
  64. uint32_t bitReverseFlag)
  65. {
  66. /* Initialise the default arm status */
  67. arm_status status = ARM_MATH_SUCCESS;
  68. /* Initialize the Real FFT length */
  69. S->fftLenReal = (uint16_t) fftLenReal;
  70. /* Initialize the Twiddle coefficientA pointer */
  71. S->pTwiddleAReal = (q31_t *) realCoefAQ31;
  72. /* Initialize the Twiddle coefficientB pointer */
  73. S->pTwiddleBReal = (q31_t *) realCoefBQ31;
  74. /* Initialize the Flag for selection of RFFT or RIFFT */
  75. S->ifftFlagR = (uint8_t) ifftFlagR;
  76. /* Initialize the Flag for calculation Bit reversal or not */
  77. S->bitReverseFlagR = (uint8_t) bitReverseFlag;
  78. /* Initialization of coef modifier depending on the FFT length */
  79. switch (S->fftLenReal)
  80. {
  81. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_4096) && defined(ARM_TABLE_BITREVIDX_FXT_4096))
  82. case 8192U:
  83. S->twidCoefRModifier = 1U;
  84. #if defined(ARM_MATH_MVEI)
  85. status=arm_cfft_init_q31(&(S->cfftInst),4096);
  86. if (status != ARM_MATH_SUCCESS)
  87. {
  88. return(status);
  89. }
  90. #else
  91. S->pCfft = &arm_cfft_sR_q31_len4096;
  92. #endif
  93. break;
  94. #endif
  95. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_2048) && defined(ARM_TABLE_BITREVIDX_FXT_2048))
  96. case 4096U:
  97. S->twidCoefRModifier = 2U;
  98. #if defined(ARM_MATH_MVEI)
  99. status=arm_cfft_init_q31(&(S->cfftInst),2048);
  100. if (status != ARM_MATH_SUCCESS)
  101. {
  102. return(status);
  103. }
  104. #else
  105. S->pCfft = &arm_cfft_sR_q31_len2048;
  106. #endif
  107. break;
  108. #endif
  109. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_1024) && defined(ARM_TABLE_BITREVIDX_FXT_1024))
  110. case 2048U:
  111. S->twidCoefRModifier = 4U;
  112. #if defined(ARM_MATH_MVEI)
  113. status=arm_cfft_init_q31(&(S->cfftInst),1024);
  114. if (status != ARM_MATH_SUCCESS)
  115. {
  116. return(status);
  117. }
  118. #else
  119. S->pCfft = &arm_cfft_sR_q31_len1024;
  120. #endif
  121. break;
  122. #endif
  123. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_512) && defined(ARM_TABLE_BITREVIDX_FXT_512))
  124. case 1024U:
  125. S->twidCoefRModifier = 8U;
  126. #if defined(ARM_MATH_MVEI)
  127. status=arm_cfft_init_q31(&(S->cfftInst),512);
  128. if (status != ARM_MATH_SUCCESS)
  129. {
  130. return(status);
  131. }
  132. #else
  133. S->pCfft = &arm_cfft_sR_q31_len512;
  134. #endif
  135. break;
  136. #endif
  137. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_256) && defined(ARM_TABLE_BITREVIDX_FXT_256))
  138. case 512U:
  139. S->twidCoefRModifier = 16U;
  140. #if defined(ARM_MATH_MVEI)
  141. status=arm_cfft_init_q31(&(S->cfftInst),256);
  142. if (status != ARM_MATH_SUCCESS)
  143. {
  144. return(status);
  145. }
  146. #else
  147. S->pCfft = &arm_cfft_sR_q31_len256;
  148. #endif
  149. break;
  150. #endif
  151. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_128) && defined(ARM_TABLE_BITREVIDX_FXT_128))
  152. case 256U:
  153. S->twidCoefRModifier = 32U;
  154. #if defined(ARM_MATH_MVEI)
  155. status=arm_cfft_init_q31(&(S->cfftInst),128);
  156. if (status != ARM_MATH_SUCCESS)
  157. {
  158. return(status);
  159. }
  160. #else
  161. S->pCfft = &arm_cfft_sR_q31_len128;
  162. #endif
  163. break;
  164. #endif
  165. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_64) && defined(ARM_TABLE_BITREVIDX_FXT_64))
  166. case 128U:
  167. S->twidCoefRModifier = 64U;
  168. #if defined(ARM_MATH_MVEI)
  169. status=arm_cfft_init_q31(&(S->cfftInst),64);
  170. if (status != ARM_MATH_SUCCESS)
  171. {
  172. return(status);
  173. }
  174. #else
  175. S->pCfft = &arm_cfft_sR_q31_len64;
  176. #endif
  177. break;
  178. #endif
  179. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_32) && defined(ARM_TABLE_BITREVIDX_FXT_32))
  180. case 64U:
  181. S->twidCoefRModifier = 128U;
  182. #if defined(ARM_MATH_MVEI)
  183. status=arm_cfft_init_q31(&(S->cfftInst),32);
  184. if (status != ARM_MATH_SUCCESS)
  185. {
  186. return(status);
  187. }
  188. #else
  189. S->pCfft = &arm_cfft_sR_q31_len32;
  190. #endif
  191. break;
  192. #endif
  193. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_16) && defined(ARM_TABLE_BITREVIDX_FXT_16))
  194. case 32U:
  195. S->twidCoefRModifier = 256U;
  196. #if defined(ARM_MATH_MVEI)
  197. status=arm_cfft_init_q31(&(S->cfftInst),16);
  198. if (status != ARM_MATH_SUCCESS)
  199. {
  200. return(status);
  201. }
  202. #else
  203. S->pCfft = &arm_cfft_sR_q31_len16;
  204. #endif
  205. break;
  206. #endif
  207. default:
  208. /* Reporting argument error if rfftSize is not valid value */
  209. status = ARM_MATH_ARGUMENT_ERROR;
  210. break;
  211. }
  212. /* return the status of RFFT Init function */
  213. return (status);
  214. }
  215. /**
  216. @} end of RealFFT group
  217. */