1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_rfft_fast_init_f16.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-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 #include "dsp/transform_functions_f16.h"
30 #include "arm_common_tables_f16.h"
31 #include "arm_const_structs_f16.h"
32 
33 #if defined(ARM_FLOAT16_SUPPORTED)
34 
35 /**
36   @ingroup RealFFT
37  */
38 
39 /**
40   @addtogroup RealFFTF16
41   @{
42  */
43 
44 
45 /**
46   @brief         Initialization function for the 32pt floating-point real FFT.
47   @param[in,out] S  points to an arm_rfft_fast_instance_f16 structure
48   @return        execution status
49                    - \ref ARM_MATH_SUCCESS        : Operation successful
50                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
51  */
52 
arm_rfft_fast_init_32_f16(arm_rfft_fast_instance_f16 * S)53 arm_status arm_rfft_fast_init_32_f16( arm_rfft_fast_instance_f16 * S ) {
54 
55   arm_status status;
56 
57   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
58 
59   status=arm_cfft_init_16_f16(&(S->Sint));
60   if (status != ARM_MATH_SUCCESS)
61   {
62     return(status);
63   }
64 
65   S->fftLenRFFT = 32U;
66   S->pTwiddleRFFT    = (float16_t *) twiddleCoefF16_rfft_32;
67 
68   return ARM_MATH_SUCCESS;
69 }
70 
71 /**
72   @brief         Initialization function for the 64pt floating-point real FFT.
73   @param[in,out] S  points to an arm_rfft_fast_instance_f16 structure
74   @return        execution status
75                    - \ref ARM_MATH_SUCCESS        : Operation successful
76                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
77  */
78 
arm_rfft_fast_init_64_f16(arm_rfft_fast_instance_f16 * S)79 arm_status arm_rfft_fast_init_64_f16( arm_rfft_fast_instance_f16 * S ) {
80 
81   arm_status status;
82 
83   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
84 
85   status=arm_cfft_init_32_f16(&(S->Sint));
86   if (status != ARM_MATH_SUCCESS)
87   {
88     return(status);
89   }
90   S->fftLenRFFT = 64U;
91 
92   S->pTwiddleRFFT    = (float16_t *) twiddleCoefF16_rfft_64;
93 
94   return ARM_MATH_SUCCESS;
95 }
96 
97 /**
98   @brief         Initialization function for the 128pt floating-point real FFT.
99   @param[in,out] S  points to an arm_rfft_fast_instance_f16 structure
100   @return        execution status
101                    - \ref ARM_MATH_SUCCESS        : Operation successful
102                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
103  */
104 
arm_rfft_fast_init_128_f16(arm_rfft_fast_instance_f16 * S)105 arm_status arm_rfft_fast_init_128_f16( arm_rfft_fast_instance_f16 * S ) {
106 
107   arm_status status;
108 
109   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
110 
111   status=arm_cfft_init_64_f16(&(S->Sint));
112   if (status != ARM_MATH_SUCCESS)
113   {
114     return(status);
115   }
116   S->fftLenRFFT = 128;
117 
118   S->pTwiddleRFFT    = (float16_t *) twiddleCoefF16_rfft_128;
119 
120   return ARM_MATH_SUCCESS;
121 }
122 
123 /**
124   @brief         Initialization function for the 256pt floating-point real FFT.
125   @param[in,out] S  points to an arm_rfft_fast_instance_f16 structure
126   @return        execution status
127                    - \ref ARM_MATH_SUCCESS        : Operation successful
128                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
129 */
130 
arm_rfft_fast_init_256_f16(arm_rfft_fast_instance_f16 * S)131 arm_status arm_rfft_fast_init_256_f16( arm_rfft_fast_instance_f16 * S ) {
132 
133   arm_status status;
134 
135   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
136 
137   status=arm_cfft_init_128_f16(&(S->Sint));
138   if (status != ARM_MATH_SUCCESS)
139   {
140     return(status);
141   }
142   S->fftLenRFFT = 256U;
143 
144   S->pTwiddleRFFT    = (float16_t *) twiddleCoefF16_rfft_256;
145 
146   return ARM_MATH_SUCCESS;
147 }
148 
149 /**
150   @brief         Initialization function for the 512pt floating-point real FFT.
151   @param[in,out] S  points to an arm_rfft_fast_instance_f16 structure
152   @return        execution status
153                    - \ref ARM_MATH_SUCCESS        : Operation successful
154                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
155  */
156 
arm_rfft_fast_init_512_f16(arm_rfft_fast_instance_f16 * S)157 arm_status arm_rfft_fast_init_512_f16( arm_rfft_fast_instance_f16 * S ) {
158 
159   arm_status status;
160 
161   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
162 
163   status=arm_cfft_init_256_f16(&(S->Sint));
164   if (status != ARM_MATH_SUCCESS)
165   {
166     return(status);
167   }
168   S->fftLenRFFT = 512U;
169 
170   S->pTwiddleRFFT    = (float16_t *) twiddleCoefF16_rfft_512;
171 
172   return ARM_MATH_SUCCESS;
173 }
174 
175 /**
176   @brief         Initialization function for the 1024pt floating-point real FFT.
177   @param[in,out] S  points to an arm_rfft_fast_instance_f16 structure
178   @return        execution status
179                    - \ref ARM_MATH_SUCCESS        : Operation successful
180                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
181  */
182 
arm_rfft_fast_init_1024_f16(arm_rfft_fast_instance_f16 * S)183 arm_status arm_rfft_fast_init_1024_f16( arm_rfft_fast_instance_f16 * S ) {
184 
185   arm_status status;
186 
187   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
188 
189   status=arm_cfft_init_512_f16(&(S->Sint));
190   if (status != ARM_MATH_SUCCESS)
191   {
192     return(status);
193   }
194   S->fftLenRFFT = 1024U;
195 
196   S->pTwiddleRFFT    = (float16_t *) twiddleCoefF16_rfft_1024;
197 
198   return ARM_MATH_SUCCESS;
199 }
200 
201 /**
202   @brief         Initialization function for the 2048pt floating-point real FFT.
203   @param[in,out] S  points to an arm_rfft_fast_instance_f16 structure
204   @return        execution status
205                    - \ref ARM_MATH_SUCCESS        : Operation successful
206                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
207  */
arm_rfft_fast_init_2048_f16(arm_rfft_fast_instance_f16 * S)208 arm_status arm_rfft_fast_init_2048_f16( arm_rfft_fast_instance_f16 * S ) {
209 
210   arm_status status;
211 
212   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
213 
214   status=arm_cfft_init_1024_f16(&(S->Sint));
215   if (status != ARM_MATH_SUCCESS)
216   {
217     return(status);
218   }
219   S->fftLenRFFT = 2048U;
220 
221   S->pTwiddleRFFT    = (float16_t *) twiddleCoefF16_rfft_2048;
222 
223   return ARM_MATH_SUCCESS;
224 }
225 
226 /**
227 * @brief         Initialization function for the 4096pt floating-point real FFT.
228 * @param[in,out] S  points to an arm_rfft_fast_instance_f16 structure
229   @return        execution status
230                    - \ref ARM_MATH_SUCCESS        : Operation successful
231                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
232  */
233 
arm_rfft_fast_init_4096_f16(arm_rfft_fast_instance_f16 * S)234 arm_status arm_rfft_fast_init_4096_f16( arm_rfft_fast_instance_f16 * S ) {
235 
236   arm_status status;
237 
238   if( !S ) return ARM_MATH_ARGUMENT_ERROR;
239 
240   status=arm_cfft_init_2048_f16(&(S->Sint));
241   if (status != ARM_MATH_SUCCESS)
242   {
243     return(status);
244   }
245   S->fftLenRFFT = 4096U;
246 
247   S->pTwiddleRFFT    = (float16_t *) twiddleCoefF16_rfft_4096;
248 
249   return ARM_MATH_SUCCESS;
250 }
251 
252 /**
253   @brief         Generic initialization function for the floating-point real FFT.
254   @param[in,out] S       points to an arm_rfft_fast_instance_f16 structure
255   @param[in]     fftLen  length of the Real Sequence
256   @return        execution status
257                    - \ref ARM_MATH_SUCCESS        : Operation successful
258                    - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLen</code> is not a supported length
259 
260   @par           Description
261                    The parameter <code>fftLen</code> specifies the length of RFFT/CIFFT process.
262                    Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096.
263 
264   @par
265                 This Function also initializes Twiddle factor table pointer and Bit reversal table pointer.
266 
267   @par
268                 This function should be used only if you don't know the FFT sizes that
269                 you'll need at build time. The use of this function will prevent the
270                 linker from removing the FFT tables that are not needed and the library
271                 code size will be bigger than needed.
272 
273   @par
274                 If you use CMSIS-DSP as a static library, and if you know the FFT sizes
275                 that you need at build time, then it is better to use the initialization
276                 functions defined for each FFT size.
277 
278  */
279 
arm_rfft_fast_init_f16(arm_rfft_fast_instance_f16 * S,uint16_t fftLen)280 arm_status arm_rfft_fast_init_f16(
281   arm_rfft_fast_instance_f16 * S,
282   uint16_t fftLen)
283 {
284   arm_status status;
285 
286 
287   switch (fftLen)
288   {
289   case 4096U:
290     status = arm_rfft_fast_init_4096_f16(S);
291     break;
292   case 2048U:
293     status = arm_rfft_fast_init_2048_f16(S);
294     break;
295   case 1024U:
296     status = arm_rfft_fast_init_1024_f16(S);
297     break;
298   case 512U:
299     status = arm_rfft_fast_init_512_f16(S);
300     break;
301   case 256U:
302     status = arm_rfft_fast_init_256_f16(S);
303     break;
304   case 128U:
305     status = arm_rfft_fast_init_128_f16(S);
306     break;
307   case 64U:
308     status = arm_rfft_fast_init_64_f16(S);
309     break;
310   case 32U:
311     status = arm_rfft_fast_init_32_f16(S);
312     break;
313   default:
314     return(ARM_MATH_ARGUMENT_ERROR);
315     break;
316   }
317 
318   return(status);
319 
320 }
321 
322 /**
323   @} end of RealFFTF16 group
324  */
325 
326 #endif /*  #if defined(ARM_FLOAT16_SUPPORTED) */
327