1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_rfft_init_q31.c
4 * Description: RFFT & RIFFT Q31 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
29 #include "dsp/transform_functions.h"
30 #include "arm_common_tables.h"
31 #include "arm_const_structs.h"
32
33 /**
34 @ingroup RealFFT
35 */
36
37 /**
38 @defgroup RealFFTQ31 Real FFT Q31 Functions
39 */
40
41 /**
42 @addtogroup RealFFTQ31
43 @{
44 */
45
46
47 #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
48 #define RFFTINIT_Q31(LEN,CFFTLEN,TWIDMOD) \
49 arm_status arm_rfft_init_##LEN##_q31( arm_rfft_instance_q31 * S, \
50 uint32_t ifftFlagR, \
51 uint32_t bitReverseFlag ) \
52 { \
53 /* Initialise the default arm status */ \
54 arm_status status = ARM_MATH_ARGUMENT_ERROR; \
55 \
56 /* Initialize the Real FFT length */ \
57 S->fftLenReal = (uint16_t) LEN; \
58 \
59 /* Initialize the Twiddle coefficientA pointer */ \
60 S->pTwiddleAReal = (q31_t *) realCoefAQ31; \
61 \
62 /* Initialize the Twiddle coefficientB pointer */ \
63 S->pTwiddleBReal = (q31_t *) realCoefBQ31; \
64 \
65 /* Initialize the Flag for selection of RFFT or RIFFT */ \
66 S->ifftFlagR = (uint8_t) ifftFlagR; \
67 \
68 /* Initialize the Flag for calculation Bit reversal or not */\
69 S->bitReverseFlagR = (uint8_t) bitReverseFlag; \
70 \
71 S->twidCoefRModifier = TWIDMOD; \
72 \
73 status=arm_cfft_init_##CFFTLEN##_q31(&(S->cfftInst)); \
74 \
75 /* return the status of RFFT Init function */ \
76 return (status); \
77 }
78 #else
79 #define RFFTINIT_Q31(LEN,CFFTLEN,TWIDMOD) \
80 arm_status arm_rfft_init_##LEN##_q31( arm_rfft_instance_q31 * S, \
81 uint32_t ifftFlagR, \
82 uint32_t bitReverseFlag ) \
83 { \
84 /* Initialize the Real FFT length */ \
85 S->fftLenReal = (uint16_t) LEN; \
86 \
87 /* Initialize the Twiddle coefficientA pointer */ \
88 S->pTwiddleAReal = (q31_t *) realCoefAQ31; \
89 \
90 /* Initialize the Twiddle coefficientB pointer */ \
91 S->pTwiddleBReal = (q31_t *) realCoefBQ31; \
92 \
93 /* Initialize the Flag for selection of RFFT or RIFFT */ \
94 S->ifftFlagR = (uint8_t) ifftFlagR; \
95 \
96 /* Initialize the Flag for calculation Bit reversal or not */\
97 S->bitReverseFlagR = (uint8_t) bitReverseFlag; \
98 \
99 S->twidCoefRModifier = TWIDMOD; \
100 \
101 S->pCfft = &arm_cfft_sR_q31_len##CFFTLEN; \
102 \
103 /* return the status of RFFT Init function */ \
104 return (ARM_MATH_SUCCESS); \
105 }
106 #endif
107
108
109 /**
110 @brief Initialization function for the 8192 pt Q31 real FFT.
111 @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
112 @param[in] ifftFlagR flag that selects transform direction
113 - value = 0: forward transform
114 - value = 1: inverse transform
115 @param[in] bitReverseFlag flag that enables / disables bit reversal of output
116 - value = 0: disables bit reversal of output
117 - value = 1: enables bit reversal of output
118 @return execution status
119 - \ref ARM_MATH_SUCCESS : Operation successful
120 - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
121
122 @par
123 The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
124 Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
125 @par
126 The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
127 Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
128 @par
129 This function also initializes Twiddle factor table.
130 */
131 RFFTINIT_Q31(8192,4096,1);
132
133 /**
134 @brief Initialization function for the 4096 pt Q31 real FFT.
135 @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
136 @param[in] ifftFlagR flag that selects transform direction
137 - value = 0: forward transform
138 - value = 1: inverse transform
139 @param[in] bitReverseFlag flag that enables / disables bit reversal of output
140 - value = 0: disables bit reversal of output
141 - value = 1: enables bit reversal of output
142 @return execution status
143 - \ref ARM_MATH_SUCCESS : Operation successful
144 - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
145
146 @par
147 The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
148 Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
149 @par
150 The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
151 Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
152 @par
153 This function also initializes Twiddle factor table.
154 */
155 RFFTINIT_Q31(4096,2048,2);
156
157 /**
158 @brief Initialization function for the 2048 pt Q31 real FFT.
159 @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
160 @param[in] ifftFlagR flag that selects transform direction
161 - value = 0: forward transform
162 - value = 1: inverse transform
163 @param[in] bitReverseFlag flag that enables / disables bit reversal of output
164 - value = 0: disables bit reversal of output
165 - value = 1: enables bit reversal of output
166 @return execution status
167 - \ref ARM_MATH_SUCCESS : Operation successful
168 - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
169
170 @par
171 The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
172 Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
173 @par
174 The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
175 Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
176 @par
177 This function also initializes Twiddle factor table.
178 */
179 RFFTINIT_Q31(2048,1024,4);
180
181 /**
182 @brief Initialization function for the 1024 pt Q31 real FFT.
183 @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
184 @param[in] ifftFlagR flag that selects transform direction
185 - value = 0: forward transform
186 - value = 1: inverse transform
187 @param[in] bitReverseFlag flag that enables / disables bit reversal of output
188 - value = 0: disables bit reversal of output
189 - value = 1: enables bit reversal of output
190 @return execution status
191 - \ref ARM_MATH_SUCCESS : Operation successful
192 - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
193
194 @par
195 The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
196 Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
197 @par
198 The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
199 Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
200 @par
201 This function also initializes Twiddle factor table.
202 */
203 RFFTINIT_Q31(1024,512,8);
204
205 /**
206 @brief Initialization function for the 512 pt Q31 real FFT.
207 @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
208 @param[in] ifftFlagR flag that selects transform direction
209 - value = 0: forward transform
210 - value = 1: inverse transform
211 @param[in] bitReverseFlag flag that enables / disables bit reversal of output
212 - value = 0: disables bit reversal of output
213 - value = 1: enables bit reversal of output
214 @return execution status
215 - \ref ARM_MATH_SUCCESS : Operation successful
216 - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
217
218 @par
219 The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
220 Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
221 @par
222 The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
223 Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
224 @par
225 This function also initializes Twiddle factor table.
226 */
227 RFFTINIT_Q31(512,256,16);
228
229 /**
230 @brief Initialization function for the 256 pt Q31 real FFT.
231 @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
232 @param[in] ifftFlagR flag that selects transform direction
233 - value = 0: forward transform
234 - value = 1: inverse transform
235 @param[in] bitReverseFlag flag that enables / disables bit reversal of output
236 - value = 0: disables bit reversal of output
237 - value = 1: enables bit reversal of output
238 @return execution status
239 - \ref ARM_MATH_SUCCESS : Operation successful
240 - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
241
242 @par
243 The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
244 Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
245 @par
246 The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
247 Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
248 @par
249 This function also initializes Twiddle factor table.
250 */
251 RFFTINIT_Q31(256,128,32);
252
253 /**
254 @brief Initialization function for the 128 pt Q31 real FFT.
255 @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
256 @param[in] ifftFlagR flag that selects transform direction
257 - value = 0: forward transform
258 - value = 1: inverse transform
259 @param[in] bitReverseFlag flag that enables / disables bit reversal of output
260 - value = 0: disables bit reversal of output
261 - value = 1: enables bit reversal of output
262 @return execution status
263 - \ref ARM_MATH_SUCCESS : Operation successful
264 - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
265
266 @par
267 The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
268 Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
269 @par
270 The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
271 Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
272 @par
273 This function also initializes Twiddle factor table.
274 */
275 RFFTINIT_Q31(128,64,64);
276
277 /**
278 @brief Initialization function for the 64 pt Q31 real FFT.
279 @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
280 @param[in] ifftFlagR flag that selects transform direction
281 - value = 0: forward transform
282 - value = 1: inverse transform
283 @param[in] bitReverseFlag flag that enables / disables bit reversal of output
284 - value = 0: disables bit reversal of output
285 - value = 1: enables bit reversal of output
286 @return execution status
287 - \ref ARM_MATH_SUCCESS : Operation successful
288 - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
289
290 @par
291 The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
292 Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
293 @par
294 The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
295 Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
296 @par
297 This function also initializes Twiddle factor table.
298 */
299 RFFTINIT_Q31(64,32,128);
300
301 /**
302 @brief Initialization function for the 32 pt Q31 real FFT.
303 @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
304 @param[in] ifftFlagR flag that selects transform direction
305 - value = 0: forward transform
306 - value = 1: inverse transform
307 @param[in] bitReverseFlag flag that enables / disables bit reversal of output
308 - value = 0: disables bit reversal of output
309 - value = 1: enables bit reversal of output
310 @return execution status
311 - \ref ARM_MATH_SUCCESS : Operation successful
312 - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
313
314 @par
315 The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
316 Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
317 @par
318 The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
319 Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
320 @par
321 This function also initializes Twiddle factor table.
322 */
323 RFFTINIT_Q31(32,16,256);
324
325
326 /**
327 @brief Generic initialization function for the Q31 RFFT/RIFFT.
328 @param[in,out] S points to an instance of the Q31 RFFT/RIFFT structure
329 @param[in] fftLenReal length of the FFT
330 @param[in] ifftFlagR flag that selects transform direction
331 - value = 0: forward transform
332 - value = 1: inverse transform
333 @param[in] bitReverseFlag flag that enables / disables bit reversal of output
334 - value = 0: disables bit reversal of output
335 - value = 1: enables bit reversal of output
336 @return execution status
337 - \ref ARM_MATH_SUCCESS : Operation successful
338 - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
339
340 @par Details
341 The parameter <code>fftLenReal</code> specifies length of RFFT/RIFFT Process.
342 Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192.
343 @par
344 The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
345 Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
346 @par
347 The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
348 Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
349 @par
350 This function also initializes Twiddle factor table.
351
352 @par
353 This function should be used only if you don't know the FFT sizes that
354 you'll need at build time. The use of this function will prevent the
355 linker from removing the FFT tables that are not needed and the library
356 code size will be bigger than needed.
357
358 @par
359 If you use CMSIS-DSP as a static library, and if you know the FFT sizes
360 that you need at build time, then it is better to use the initialization
361 functions defined for each FFT size.
362
363 */
364
arm_rfft_init_q31(arm_rfft_instance_q31 * S,uint32_t fftLenReal,uint32_t ifftFlagR,uint32_t bitReverseFlag)365 arm_status arm_rfft_init_q31(
366 arm_rfft_instance_q31 * S,
367 uint32_t fftLenReal,
368 uint32_t ifftFlagR,
369 uint32_t bitReverseFlag)
370 {
371 /* Initialise the default arm status */
372 arm_status status = ARM_MATH_ARGUMENT_ERROR;
373 /* Initialization of coef modifier depending on the FFT length */
374 switch (fftLenReal)
375 {
376 case 8192U:
377 status = arm_rfft_init_8192_q31( S,ifftFlagR,bitReverseFlag );
378 break;
379 case 4096U:
380 status = arm_rfft_init_4096_q31( S,ifftFlagR,bitReverseFlag );
381 break;
382 case 2048U:
383 status = arm_rfft_init_2048_q31( S,ifftFlagR,bitReverseFlag );
384 break;
385 case 1024U:
386 status = arm_rfft_init_1024_q31( S,ifftFlagR,bitReverseFlag );
387 break;
388 case 512U:
389 status = arm_rfft_init_512_q31( S,ifftFlagR,bitReverseFlag );
390 break;
391 case 256U:
392 status = arm_rfft_init_256_q31( S,ifftFlagR,bitReverseFlag );
393 break;
394 case 128U:
395 status = arm_rfft_init_128_q31( S,ifftFlagR,bitReverseFlag );
396 break;
397 case 64U:
398 status = arm_rfft_init_64_q31( S,ifftFlagR,bitReverseFlag );
399 break;
400 case 32U:
401 status = arm_rfft_init_32_q31( S,ifftFlagR,bitReverseFlag );
402 break;
403 default:
404 /* Reporting argument error if rfftSize is not valid value */
405 status = ARM_MATH_ARGUMENT_ERROR;
406 break;
407 }
408
409 /* return the status of RFFT Init function */
410 return (status);
411 }
412 /**
413 @} end of RealFFTQ31 group
414 */
415