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