1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_rfft_fast_init_f32.c
4  * Description:  Split Radix Decimation in Frequency CFFT Floating point processing 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 
32 /**
33   @ingroup groupTransforms
34  */
35 
36 /**
37   @addtogroup RealFFT
38   @{
39  */
40 
41 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_16) && defined(ARM_TABLE_BITREVIDX_FLT_16) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_32))
42 
43 /**
44   @private
45   @brief         Initialization function for the 32pt floating-point real FFT.
46   @param[in,out] S  points to an arm_rfft_fast_instance_f32 structure
47   @return        execution status
48                    - \ref ARM_MATH_SUCCESS        : Operation successful
49                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
50  */
51 
arm_rfft_32_fast_init_f32(arm_rfft_fast_instance_f32 * S)52 static arm_status arm_rfft_32_fast_init_f32( arm_rfft_fast_instance_f32 * S ) {
53 
54   arm_status status;
55 
56   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
57 
58   status=arm_cfft_init_f32(&(S->Sint),16);
59   if (status != ARM_MATH_SUCCESS)
60   {
61     return(status);
62   }
63 
64   S->fftLenRFFT = 32U;
65   S->pTwiddleRFFT    = (float32_t *) twiddleCoef_rfft_32;
66 
67   return ARM_MATH_SUCCESS;
68 }
69 #endif
70 
71 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_32) && defined(ARM_TABLE_BITREVIDX_FLT_32) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_64))
72 
73 /**
74   @private
75   @brief         Initialization function for the 64pt floating-point real FFT.
76   @param[in,out] S  points to an arm_rfft_fast_instance_f32 structure
77   @return        execution status
78                    - \ref ARM_MATH_SUCCESS        : Operation successful
79                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
80  */
81 
arm_rfft_64_fast_init_f32(arm_rfft_fast_instance_f32 * S)82 static arm_status arm_rfft_64_fast_init_f32( arm_rfft_fast_instance_f32 * S ) {
83 
84   arm_status status;
85 
86   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
87 
88   status=arm_cfft_init_f32(&(S->Sint),32);
89   if (status != ARM_MATH_SUCCESS)
90   {
91     return(status);
92   }
93   S->fftLenRFFT = 64U;
94 
95   S->pTwiddleRFFT    = (float32_t *) twiddleCoef_rfft_64;
96 
97   return ARM_MATH_SUCCESS;
98 }
99 #endif
100 
101 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_64) && defined(ARM_TABLE_BITREVIDX_FLT_64) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_128))
102 
103 /**
104   @private
105   @brief         Initialization function for the 128pt floating-point real FFT.
106   @param[in,out] S  points to an arm_rfft_fast_instance_f32 structure
107   @return        execution status
108                    - \ref ARM_MATH_SUCCESS        : Operation successful
109                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
110  */
111 
arm_rfft_128_fast_init_f32(arm_rfft_fast_instance_f32 * S)112 static arm_status arm_rfft_128_fast_init_f32( arm_rfft_fast_instance_f32 * S ) {
113 
114   arm_status status;
115 
116   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
117 
118   status=arm_cfft_init_f32(&(S->Sint),64);
119   if (status != ARM_MATH_SUCCESS)
120   {
121     return(status);
122   }
123   S->fftLenRFFT = 128;
124 
125   S->pTwiddleRFFT    = (float32_t *) twiddleCoef_rfft_128;
126 
127   return ARM_MATH_SUCCESS;
128 }
129 #endif
130 
131 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_128) && defined(ARM_TABLE_BITREVIDX_FLT_128) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_256))
132 
133 /**
134   @private
135   @brief         Initialization function for the 256pt floating-point real FFT.
136   @param[in,out] S  points to an arm_rfft_fast_instance_f32 structure
137   @return        execution status
138                    - \ref ARM_MATH_SUCCESS        : Operation successful
139                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
140 */
141 
arm_rfft_256_fast_init_f32(arm_rfft_fast_instance_f32 * S)142 static arm_status arm_rfft_256_fast_init_f32( arm_rfft_fast_instance_f32 * S ) {
143 
144   arm_status status;
145 
146   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
147 
148   status=arm_cfft_init_f32(&(S->Sint),128);
149   if (status != ARM_MATH_SUCCESS)
150   {
151     return(status);
152   }
153   S->fftLenRFFT = 256U;
154 
155   S->pTwiddleRFFT    = (float32_t *) twiddleCoef_rfft_256;
156 
157   return ARM_MATH_SUCCESS;
158 }
159 #endif
160 
161 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_256) && defined(ARM_TABLE_BITREVIDX_FLT_256) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_512))
162 
163 /**
164   @private
165   @brief         Initialization function for the 512pt floating-point real FFT.
166   @param[in,out] S  points to an arm_rfft_fast_instance_f32 structure
167   @return        execution status
168                    - \ref ARM_MATH_SUCCESS        : Operation successful
169                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
170  */
171 
arm_rfft_512_fast_init_f32(arm_rfft_fast_instance_f32 * S)172 static arm_status arm_rfft_512_fast_init_f32( arm_rfft_fast_instance_f32 * S ) {
173 
174   arm_status status;
175 
176   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
177 
178   status=arm_cfft_init_f32(&(S->Sint),256);
179   if (status != ARM_MATH_SUCCESS)
180   {
181     return(status);
182   }
183   S->fftLenRFFT = 512U;
184 
185   S->pTwiddleRFFT    = (float32_t *) twiddleCoef_rfft_512;
186 
187   return ARM_MATH_SUCCESS;
188 }
189 #endif
190 
191 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_512) && defined(ARM_TABLE_BITREVIDX_FLT_512) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_1024))
192 /**
193   @private
194   @brief         Initialization function for the 1024pt floating-point real FFT.
195   @param[in,out] S  points to an arm_rfft_fast_instance_f32 structure
196   @return        execution status
197                    - \ref ARM_MATH_SUCCESS        : Operation successful
198                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
199  */
200 
arm_rfft_1024_fast_init_f32(arm_rfft_fast_instance_f32 * S)201 static arm_status arm_rfft_1024_fast_init_f32( arm_rfft_fast_instance_f32 * S ) {
202 
203   arm_status status;
204 
205   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
206 
207   status=arm_cfft_init_f32(&(S->Sint),512);
208   if (status != ARM_MATH_SUCCESS)
209   {
210     return(status);
211   }
212   S->fftLenRFFT = 1024U;
213 
214   S->pTwiddleRFFT    = (float32_t *) twiddleCoef_rfft_1024;
215 
216   return ARM_MATH_SUCCESS;
217 }
218 #endif
219 
220 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_1024) && defined(ARM_TABLE_BITREVIDX_FLT_1024) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_2048))
221 /**
222   @private
223   @brief         Initialization function for the 2048pt floating-point real FFT.
224   @param[in,out] S  points to an arm_rfft_fast_instance_f32 structure
225   @return        execution status
226                    - \ref ARM_MATH_SUCCESS        : Operation successful
227                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
228  */
arm_rfft_2048_fast_init_f32(arm_rfft_fast_instance_f32 * S)229 static arm_status arm_rfft_2048_fast_init_f32( arm_rfft_fast_instance_f32 * S ) {
230 
231   arm_status status;
232 
233   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
234 
235   status=arm_cfft_init_f32(&(S->Sint),1024);
236   if (status != ARM_MATH_SUCCESS)
237   {
238     return(status);
239   }
240   S->fftLenRFFT = 2048U;
241 
242   S->pTwiddleRFFT    = (float32_t *) twiddleCoef_rfft_2048;
243 
244   return ARM_MATH_SUCCESS;
245 }
246 #endif
247 
248 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_2048) && defined(ARM_TABLE_BITREVIDX_FLT_2048) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_4096))
249 /**
250   @private
251 * @brief         Initialization function for the 4096pt floating-point real FFT.
252 * @param[in,out] S  points to an arm_rfft_fast_instance_f32 structure
253   @return        execution status
254                    - \ref ARM_MATH_SUCCESS        : Operation successful
255                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
256  */
257 
arm_rfft_4096_fast_init_f32(arm_rfft_fast_instance_f32 * S)258 static arm_status arm_rfft_4096_fast_init_f32( arm_rfft_fast_instance_f32 * S ) {
259 
260   arm_status status;
261 
262   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
263 
264   status=arm_cfft_init_f32(&(S->Sint),2048);
265   if (status != ARM_MATH_SUCCESS)
266   {
267     return(status);
268   }
269   S->fftLenRFFT = 4096U;
270 
271   S->pTwiddleRFFT    = (float32_t *) twiddleCoef_rfft_4096;
272 
273   return ARM_MATH_SUCCESS;
274 }
275 #endif
276 
277 /**
278   @brief         Initialization function for the floating-point real FFT.
279   @param[in,out] S       points to an arm_rfft_fast_instance_f32 structure
280   @param[in]     fftLen  length of the Real Sequence
281   @return        execution status
282                    - \ref ARM_MATH_SUCCESS        : Operation successful
283                    - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLen</code> is not a supported length
284 
285   @par           Description
286                    The parameter <code>fftLen</code> specifies the length of RFFT/CIFFT process.
287                    Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096.
288   @par
289                    This Function also initializes Twiddle factor table pointer and Bit reversal table pointer.
290  */
291 
arm_rfft_fast_init_f32(arm_rfft_fast_instance_f32 * S,uint16_t fftLen)292 arm_status arm_rfft_fast_init_f32(
293   arm_rfft_fast_instance_f32 * S,
294   uint16_t fftLen)
295 {
296   typedef arm_status(*fft_init_ptr)( arm_rfft_fast_instance_f32 *);
297   fft_init_ptr fptr = 0x0;
298 
299   switch (fftLen)
300   {
301 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_2048) && defined(ARM_TABLE_BITREVIDX_FLT_2048) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_4096))
302   case 4096U:
303     fptr = arm_rfft_4096_fast_init_f32;
304     break;
305 #endif
306 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_1024) && defined(ARM_TABLE_BITREVIDX_FLT_1024) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_2048))
307   case 2048U:
308     fptr = arm_rfft_2048_fast_init_f32;
309     break;
310 #endif
311 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_512) && defined(ARM_TABLE_BITREVIDX_FLT_512) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_1024))
312   case 1024U:
313     fptr = arm_rfft_1024_fast_init_f32;
314     break;
315 #endif
316 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_256) && defined(ARM_TABLE_BITREVIDX_FLT_256) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_512))
317   case 512U:
318     fptr = arm_rfft_512_fast_init_f32;
319     break;
320 #endif
321 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_128) && defined(ARM_TABLE_BITREVIDX_FLT_128) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_256))
322   case 256U:
323     fptr = arm_rfft_256_fast_init_f32;
324     break;
325 #endif
326 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_64) && defined(ARM_TABLE_BITREVIDX_FLT_64) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_128))
327   case 128U:
328     fptr = arm_rfft_128_fast_init_f32;
329     break;
330 #endif
331 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_32) && defined(ARM_TABLE_BITREVIDX_FLT_32) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_64))
332   case 64U:
333     fptr = arm_rfft_64_fast_init_f32;
334     break;
335 #endif
336 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F32_16) && defined(ARM_TABLE_BITREVIDX_FLT_16) && defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_32))
337   case 32U:
338     fptr = arm_rfft_32_fast_init_f32;
339     break;
340 #endif
341   default:
342     return ARM_MATH_ARGUMENT_ERROR;
343   }
344 
345   if( ! fptr ) return ARM_MATH_ARGUMENT_ERROR;
346   return fptr( S );
347 
348 }
349 
350 /**
351   @} end of RealFFT group
352  */
353