arm_rfft_init_q31.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. S->pCfft = &arm_cfft_sR_q31_len4096;
  85. break;
  86. #endif
  87. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_2048) && defined(ARM_TABLE_BITREVIDX_FXT_2048))
  88. case 4096U:
  89. S->twidCoefRModifier = 2U;
  90. S->pCfft = &arm_cfft_sR_q31_len2048;
  91. break;
  92. #endif
  93. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_1024) && defined(ARM_TABLE_BITREVIDX_FXT_1024))
  94. case 2048U:
  95. S->twidCoefRModifier = 4U;
  96. S->pCfft = &arm_cfft_sR_q31_len1024;
  97. break;
  98. #endif
  99. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_512) && defined(ARM_TABLE_BITREVIDX_FXT_512))
  100. case 1024U:
  101. S->twidCoefRModifier = 8U;
  102. S->pCfft = &arm_cfft_sR_q31_len512;
  103. break;
  104. #endif
  105. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_256) && defined(ARM_TABLE_BITREVIDX_FXT_256))
  106. case 512U:
  107. S->twidCoefRModifier = 16U;
  108. S->pCfft = &arm_cfft_sR_q31_len256;
  109. break;
  110. #endif
  111. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_128) && defined(ARM_TABLE_BITREVIDX_FXT_128))
  112. case 256U:
  113. S->twidCoefRModifier = 32U;
  114. S->pCfft = &arm_cfft_sR_q31_len128;
  115. break;
  116. #endif
  117. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_64) && defined(ARM_TABLE_BITREVIDX_FXT_64))
  118. case 128U:
  119. S->twidCoefRModifier = 64U;
  120. S->pCfft = &arm_cfft_sR_q31_len64;
  121. break;
  122. #endif
  123. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_32) && defined(ARM_TABLE_BITREVIDX_FXT_32))
  124. case 64U:
  125. S->twidCoefRModifier = 128U;
  126. S->pCfft = &arm_cfft_sR_q31_len32;
  127. break;
  128. #endif
  129. #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_16) && defined(ARM_TABLE_BITREVIDX_FXT_16))
  130. case 32U:
  131. S->twidCoefRModifier = 256U;
  132. S->pCfft = &arm_cfft_sR_q31_len16;
  133. break;
  134. #endif
  135. default:
  136. /* Reporting argument error if rfftSize is not valid value */
  137. status = ARM_MATH_ARGUMENT_ERROR;
  138. break;
  139. }
  140. /* return the status of RFFT Init function */
  141. return (status);
  142. }
  143. /**
  144. @} end of RealFFT group
  145. */