fftinit.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Python Wrapper
  3. * Title: fftinit.c
  4. * Description: FFT init functions for the Python wrapper
  5. *
  6. * $Date: 25. March 2019
  7. * $Revision: V0.0.1
  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. #define FFTINIT(SIZE) \
  32. S->bitRevLength = arm_cfft_sR_f32_len##SIZE.bitRevLength; \
  33. S->pBitRevTable = arm_cfft_sR_f32_len##SIZE.pBitRevTable; \
  34. S->pTwiddle = arm_cfft_sR_f32_len##SIZE.pTwiddle;
  35. #define FFTFXTINIT(EXT,SIZE) \
  36. S->bitRevLength = arm_cfft_sR_##EXT##_len##SIZE.bitRevLength; \
  37. S->pBitRevTable = arm_cfft_sR_##EXT##_len##SIZE.pBitRevTable; \
  38. S->pTwiddle = arm_cfft_sR_##EXT##_len##SIZE.pTwiddle;
  39. arm_status arm_cfft_init_f32(
  40. arm_cfft_instance_f32 * S,
  41. uint16_t fftLen)
  42. {
  43. /* Initialise the default arm status */
  44. arm_status status = ARM_MATH_SUCCESS;
  45. /* Initialise the FFT length */
  46. S->fftLen = fftLen;
  47. /* Initialise the Twiddle coefficient pointer */
  48. S->pTwiddle = (float32_t *)twiddleCoef_4096;
  49. /* Initializations of Instance structure depending on the FFT length */
  50. switch (S->fftLen) {
  51. /* Initializations of structure parameters for 4096 point FFT */
  52. case 4096U:
  53. /* Initialise the bit reversal table modifier */
  54. FFTINIT(4096);
  55. break;
  56. /* Initializations of structure parameters for 2048 point FFT */
  57. case 2048U:
  58. /* Initialise the bit reversal table modifier */
  59. FFTINIT(2048);
  60. break;
  61. /* Initializations of structure parameters for 1024 point FFT */
  62. case 1024U:
  63. /* Initialise the bit reversal table modifier */
  64. FFTINIT(1024);
  65. break;
  66. /* Initializations of structure parameters for 512 point FFT */
  67. case 512U:
  68. /* Initialise the bit reversal table modifier */
  69. FFTINIT(512);
  70. break;
  71. case 256U:
  72. FFTINIT(256);
  73. break;
  74. case 128U:
  75. FFTINIT(128);
  76. break;
  77. case 64U:
  78. FFTINIT(64);
  79. break;
  80. case 32U:
  81. FFTINIT(32);
  82. break;
  83. case 16U:
  84. /* Initializations of structure parameters for 16 point FFT */
  85. FFTINIT(16);
  86. break;
  87. default:
  88. /* Reporting argument error if fftSize is not valid value */
  89. status = ARM_MATH_ARGUMENT_ERROR;
  90. break;
  91. }
  92. return (status);
  93. }
  94. arm_status arm_cfft_init_q31(
  95. arm_cfft_instance_q31 * S,
  96. uint16_t fftLen)
  97. {
  98. /* Initialise the default arm status */
  99. arm_status status = ARM_MATH_SUCCESS;
  100. /* Initialise the FFT length */
  101. S->fftLen = fftLen;
  102. /* Initialise the Twiddle coefficient pointer */
  103. S->pTwiddle = (float32_t *)twiddleCoef_4096;
  104. /* Initializations of Instance structure depending on the FFT length */
  105. switch (S->fftLen) {
  106. /* Initializations of structure parameters for 4096 point FFT */
  107. case 4096U:
  108. /* Initialise the bit reversal table modifier */
  109. FFTFXTINIT(q31,4096);
  110. break;
  111. /* Initializations of structure parameters for 2048 point FFT */
  112. case 2048U:
  113. /* Initialise the bit reversal table modifier */
  114. FFTFXTINIT(q31,2048);
  115. break;
  116. /* Initializations of structure parameters for 1024 point FFT */
  117. case 1024U:
  118. /* Initialise the bit reversal table modifier */
  119. FFTFXTINIT(q31,1024);
  120. break;
  121. /* Initializations of structure parameters for 512 point FFT */
  122. case 512U:
  123. /* Initialise the bit reversal table modifier */
  124. FFTFXTINIT(q31,512);
  125. break;
  126. case 256U:
  127. FFTFXTINIT(q31,256);
  128. break;
  129. case 128U:
  130. FFTFXTINIT(q31,128);
  131. break;
  132. case 64U:
  133. FFTFXTINIT(q31,64);
  134. break;
  135. case 32U:
  136. FFTFXTINIT(q31,32);
  137. break;
  138. case 16U:
  139. /* Initializations of structure parameters for 16 point FFT */
  140. FFTFXTINIT(q31,16);
  141. break;
  142. default:
  143. /* Reporting argument error if fftSize is not valid value */
  144. status = ARM_MATH_ARGUMENT_ERROR;
  145. break;
  146. }
  147. return (status);
  148. }
  149. arm_status arm_cfft_init_q15(
  150. arm_cfft_instance_q15 * S,
  151. uint16_t fftLen)
  152. {
  153. /* Initialise the default arm status */
  154. arm_status status = ARM_MATH_SUCCESS;
  155. /* Initialise the FFT length */
  156. S->fftLen = fftLen;
  157. /* Initialise the Twiddle coefficient pointer */
  158. S->pTwiddle = (float32_t *)twiddleCoef_4096;
  159. /* Initializations of Instance structure depending on the FFT length */
  160. switch (S->fftLen) {
  161. /* Initializations of structure parameters for 4096 point FFT */
  162. case 4096U:
  163. /* Initialise the bit reversal table modifier */
  164. FFTFXTINIT(q15,4096);
  165. break;
  166. /* Initializations of structure parameters for 2048 point FFT */
  167. case 2048U:
  168. /* Initialise the bit reversal table modifier */
  169. FFTFXTINIT(q15,2048);
  170. break;
  171. /* Initializations of structure parameters for 1024 point FFT */
  172. case 1024U:
  173. /* Initialise the bit reversal table modifier */
  174. FFTFXTINIT(q15,1024);
  175. break;
  176. /* Initializations of structure parameters for 512 point FFT */
  177. case 512U:
  178. /* Initialise the bit reversal table modifier */
  179. FFTFXTINIT(q15,512);
  180. break;
  181. case 256U:
  182. FFTFXTINIT(q15,256);
  183. break;
  184. case 128U:
  185. FFTFXTINIT(q15,128);
  186. break;
  187. case 64U:
  188. FFTFXTINIT(q15,64);
  189. break;
  190. case 32U:
  191. FFTFXTINIT(q15,32);
  192. break;
  193. case 16U:
  194. /* Initializations of structure parameters for 16 point FFT */
  195. FFTFXTINIT(q15,16);
  196. break;
  197. default:
  198. /* Reporting argument error if fftSize is not valid value */
  199. status = ARM_MATH_ARGUMENT_ERROR;
  200. break;
  201. }
  202. return (status);
  203. }