1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_cfft_radix2_init_f16.c
4  * Description:  Radix-2 Decimation in Frequency Floating-point CFFT & CIFFT Initialization 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_f16.h"
30 #include "arm_common_tables.h"
31 #include "arm_common_tables_f16.h"
32 
33 /**
34   @ingroup groupTransforms
35  */
36 
37 /**
38   @addtogroup ComplexFFT
39   @{
40  */
41 
42 /**
43   @brief         Initialization function for the floating-point CFFT/CIFFT.
44   @deprecated    Do not use this function. It has been superseded by \ref arm_cfft_f16 and will be removed in the future.
45   @param[in,out] S              points to an instance of the floating-point CFFT/CIFFT structure
46   @param[in]     fftLen         length of the FFT
47   @param[in]     ifftFlag       flag that selects transform direction
48                    - value = 0: forward transform
49                    - value = 1: inverse transform
50   @param[in]     bitReverseFlag flag that enables / disables bit reversal of output
51                    - value = 0: disables bit reversal of output
52                    - value = 1: enables bit reversal of output
53   @return        execution status
54                    - \ref ARM_MATH_SUCCESS        : Operation successful
55                    - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLen</code> is not a supported length
56 
57   @par           Details
58                    The parameter <code>ifftFlag</code> controls whether a forward or inverse transform is computed.
59                    Set(=1) ifftFlag for calculation of CIFFT otherwise  CFFT is calculated
60   @par
61                    The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
62                    Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
63   @par
64                    The parameter <code>fftLen</code> Specifies length of CFFT/CIFFT process. Supported FFT Lengths are 16, 64, 256, 1024.
65   @par
66                    This Function also initializes Twiddle factor table pointer and Bit reversal table pointer.
67 */
68 
69 #if defined(ARM_FLOAT16_SUPPORTED)
70 
arm_cfft_radix2_init_f16(arm_cfft_radix2_instance_f16 * S,uint16_t fftLen,uint8_t ifftFlag,uint8_t bitReverseFlag)71 arm_status arm_cfft_radix2_init_f16(
72   arm_cfft_radix2_instance_f16 * S,
73   uint16_t fftLen,
74   uint8_t ifftFlag,
75   uint8_t bitReverseFlag)
76 {
77    /*  Initialise the default arm status */
78   arm_status status = ARM_MATH_ARGUMENT_ERROR;
79 
80 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES)
81 
82 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_4096)
83 
84 
85   /*  Initialise the default arm status */
86   status = ARM_MATH_SUCCESS;
87 
88   /*  Initialise the FFT length */
89   S->fftLen = fftLen;
90 
91   /*  Initialise the Twiddle coefficient pointer */
92   S->pTwiddle = (float16_t *) twiddleCoefF16_4096;
93 
94   /*  Initialise the Flag for selection of CFFT or CIFFT */
95   S->ifftFlag = ifftFlag;
96 
97   /*  Initialise the Flag for calculation Bit reversal or not */
98   S->bitReverseFlag = bitReverseFlag;
99 
100 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREV_1024)
101 
102   /*  Initializations of structure parameters depending on the FFT length */
103   switch (S->fftLen)
104   {
105 
106   case 4096U:
107     /*  Initializations of structure parameters for 4096 point FFT */
108 
109     /*  Initialise the twiddle coef modifier value */
110     S->twidCoefModifier = 1U;
111     /*  Initialise the bit reversal table modifier */
112     S->bitRevFactor = 1U;
113     /*  Initialise the bit reversal table pointer */
114     S->pBitRevTable = (uint16_t *) armBitRevTable;
115     /*  Initialise the 1/fftLen Value */
116     S->onebyfftLen = 0.000244140625;
117     break;
118 
119   case 2048U:
120     /*  Initializations of structure parameters for 2048 point FFT */
121 
122     /*  Initialise the twiddle coef modifier value */
123     S->twidCoefModifier = 2U;
124     /*  Initialise the bit reversal table modifier */
125     S->bitRevFactor = 2U;
126     /*  Initialise the bit reversal table pointer */
127     S->pBitRevTable = (uint16_t *) & armBitRevTable[1];
128     /*  Initialise the 1/fftLen Value */
129     S->onebyfftLen = 0.00048828125;
130     break;
131 
132   case 1024U:
133     /*  Initializations of structure parameters for 1024 point FFT */
134 
135     /*  Initialise the twiddle coef modifier value */
136     S->twidCoefModifier = 4U;
137     /*  Initialise the bit reversal table modifier */
138     S->bitRevFactor = 4U;
139     /*  Initialise the bit reversal table pointer */
140     S->pBitRevTable = (uint16_t *) & armBitRevTable[3];
141     /*  Initialise the 1/fftLen Value */
142     S->onebyfftLen = 0.0009765625f;
143     break;
144 
145   case 512U:
146     /*  Initializations of structure parameters for 512 point FFT */
147 
148     /*  Initialise the twiddle coef modifier value */
149     S->twidCoefModifier = 8U;
150     /*  Initialise the bit reversal table modifier */
151     S->bitRevFactor = 8U;
152     /*  Initialise the bit reversal table pointer */
153     S->pBitRevTable = (uint16_t *) & armBitRevTable[7];
154     /*  Initialise the 1/fftLen Value */
155     S->onebyfftLen = 0.001953125;
156     break;
157 
158   case 256U:
159     /*  Initializations of structure parameters for 256 point FFT */
160     S->twidCoefModifier = 16U;
161     S->bitRevFactor = 16U;
162     S->pBitRevTable = (uint16_t *) & armBitRevTable[15];
163     S->onebyfftLen = 0.00390625f;
164     break;
165 
166   case 128U:
167     /*  Initializations of structure parameters for 128 point FFT */
168     S->twidCoefModifier = 32U;
169     S->bitRevFactor = 32U;
170     S->pBitRevTable = (uint16_t *) & armBitRevTable[31];
171     S->onebyfftLen = 0.0078125;
172     break;
173 
174   case 64U:
175     /*  Initializations of structure parameters for 64 point FFT */
176     S->twidCoefModifier = 64U;
177     S->bitRevFactor = 64U;
178     S->pBitRevTable = (uint16_t *) & armBitRevTable[63];
179     S->onebyfftLen = 0.015625f;
180     break;
181 
182   case 32U:
183     /*  Initializations of structure parameters for 64 point FFT */
184     S->twidCoefModifier = 128U;
185     S->bitRevFactor = 128U;
186     S->pBitRevTable = (uint16_t *) & armBitRevTable[127];
187     S->onebyfftLen = 0.03125;
188     break;
189 
190   case 16U:
191     /*  Initializations of structure parameters for 16 point FFT */
192     S->twidCoefModifier = 256U;
193     S->bitRevFactor = 256U;
194     S->pBitRevTable = (uint16_t *) & armBitRevTable[255];
195     S->onebyfftLen = 0.0625f;
196     break;
197 
198 
199   default:
200     /*  Reporting argument error if fftSize is not valid value */
201     status = ARM_MATH_ARGUMENT_ERROR;
202     break;
203   }
204 
205 #endif
206 #endif
207 #endif
208   return (status);
209 }
210 
211 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
212 /**
213   @} end of ComplexFFT group
214  */
215