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