arm_rfft_init_q15.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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-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. @addtogroup RealFFT
  33. @{
  34. */
  35. /**
  36. @brief Initialization function for the Q15 RFFT/RIFFT.
  37. @param[in,out] S points to an instance of the Q15 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_q15(
  61. arm_rfft_instance_q15 * 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_ARGUMENT_ERROR;
  68. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES)
  69. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_Q15)
  70. /* Initialise the default arm status */
  71. status = ARM_MATH_SUCCESS;
  72. /* Initialize the Real FFT length */
  73. S->fftLenReal = (uint16_t) fftLenReal;
  74. /* Initialize the Twiddle coefficientA pointer */
  75. S->pTwiddleAReal = (q15_t *) realCoefAQ15;
  76. /* Initialize the Twiddle coefficientB pointer */
  77. S->pTwiddleBReal = (q15_t *) realCoefBQ15;
  78. /* Initialize the Flag for selection of RFFT or RIFFT */
  79. S->ifftFlagR = (uint8_t) ifftFlagR;
  80. /* Initialize the Flag for calculation Bit reversal or not */
  81. S->bitReverseFlagR = (uint8_t) bitReverseFlag;
  82. /* Initialization of coef modifier depending on the FFT length */
  83. switch (S->fftLenReal)
  84. {
  85. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_4096) && defined(ARM_TABLE_BITREVIDX_FXT_4096))
  86. case 8192U:
  87. S->twidCoefRModifier = 1U;
  88. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  89. status=arm_cfft_init_q15(&(S->cfftInst),4096);
  90. if (status != ARM_MATH_SUCCESS)
  91. {
  92. return(status);
  93. }
  94. #else
  95. S->pCfft = &arm_cfft_sR_q15_len4096;
  96. #endif
  97. break;
  98. #endif
  99. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_2048) && defined(ARM_TABLE_BITREVIDX_FXT_2048))
  100. case 4096U:
  101. S->twidCoefRModifier = 2U;
  102. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  103. status=arm_cfft_init_q15(&(S->cfftInst),2048);
  104. if (status != ARM_MATH_SUCCESS)
  105. {
  106. return(status);
  107. }
  108. #else
  109. S->pCfft = &arm_cfft_sR_q15_len2048;
  110. #endif
  111. break;
  112. #endif
  113. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_1024) && defined(ARM_TABLE_BITREVIDX_FXT_1024))
  114. case 2048U:
  115. S->twidCoefRModifier = 4U;
  116. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  117. status=arm_cfft_init_q15(&(S->cfftInst),1024);
  118. if (status != ARM_MATH_SUCCESS)
  119. {
  120. return(status);
  121. }
  122. #else
  123. S->pCfft = &arm_cfft_sR_q15_len1024;
  124. #endif
  125. break;
  126. #endif
  127. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_512) && defined(ARM_TABLE_BITREVIDX_FXT_512))
  128. case 1024U:
  129. S->twidCoefRModifier = 8U;
  130. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  131. status=arm_cfft_init_q15(&(S->cfftInst),512);
  132. if (status != ARM_MATH_SUCCESS)
  133. {
  134. return(status);
  135. }
  136. #else
  137. S->pCfft = &arm_cfft_sR_q15_len512;
  138. #endif
  139. break;
  140. #endif
  141. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_256) && defined(ARM_TABLE_BITREVIDX_FXT_256))
  142. case 512U:
  143. S->twidCoefRModifier = 16U;
  144. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  145. status=arm_cfft_init_q15(&(S->cfftInst),256);
  146. if (status != ARM_MATH_SUCCESS)
  147. {
  148. return(status);
  149. }
  150. #else
  151. S->pCfft = &arm_cfft_sR_q15_len256;
  152. #endif
  153. break;
  154. #endif
  155. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_128) && defined(ARM_TABLE_BITREVIDX_FXT_128))
  156. case 256U:
  157. S->twidCoefRModifier = 32U;
  158. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  159. status=arm_cfft_init_q15(&(S->cfftInst),128);
  160. if (status != ARM_MATH_SUCCESS)
  161. {
  162. return(status);
  163. }
  164. #else
  165. S->pCfft = &arm_cfft_sR_q15_len128;
  166. #endif
  167. break;
  168. #endif
  169. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_64) && defined(ARM_TABLE_BITREVIDX_FXT_64))
  170. case 128U:
  171. S->twidCoefRModifier = 64U;
  172. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  173. status=arm_cfft_init_q15(&(S->cfftInst),64);
  174. if (status != ARM_MATH_SUCCESS)
  175. {
  176. return(status);
  177. }
  178. #else
  179. S->pCfft = &arm_cfft_sR_q15_len64;
  180. #endif
  181. break;
  182. #endif
  183. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_32) && defined(ARM_TABLE_BITREVIDX_FXT_32))
  184. case 64U:
  185. S->twidCoefRModifier = 128U;
  186. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  187. status=arm_cfft_init_q15(&(S->cfftInst),32);
  188. if (status != ARM_MATH_SUCCESS)
  189. {
  190. return(status);
  191. }
  192. #else
  193. S->pCfft = &arm_cfft_sR_q15_len32;
  194. #endif
  195. break;
  196. #endif
  197. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_16) && defined(ARM_TABLE_BITREVIDX_FXT_16))
  198. case 32U:
  199. S->twidCoefRModifier = 256U;
  200. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  201. status=arm_cfft_init_q15(&(S->cfftInst),16);
  202. if (status != ARM_MATH_SUCCESS)
  203. {
  204. return(status);
  205. }
  206. #else
  207. S->pCfft = &arm_cfft_sR_q15_len16;
  208. #endif
  209. break;
  210. #endif
  211. default:
  212. /* Reporting argument error if rfftSize is not valid value */
  213. status = ARM_MATH_ARGUMENT_ERROR;
  214. break;
  215. }
  216. #endif
  217. #endif
  218. /* return the status of RFFT Init function */
  219. return (status);
  220. }
  221. /**
  222. @} end of RealFFT group
  223. */