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