1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_cfft_radix4_init_q15.c
4  * Description:  Radix-4 Decimation in Frequency Q15 FFT & IFFT 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.h"
30 #include "arm_common_tables.h"
31 
32 /**
33   @ingroup groupTransforms
34  */
35 
36 
37 /**
38   @addtogroup ComplexFFT
39   @{
40  */
41 
42 
43 /**
44   @brief Initialization function for the Q15 CFFT/CIFFT.
45   @deprecated    Do not use this function. It has been superseded by \ref arm_cfft_q15 and will be removed in the future.
46   @param[in,out] S              points to an instance of the Q15 CFFT/CIFFT structure
47   @param[in]     fftLen         length of the FFT
48   @param[in]     ifftFlag       flag that selects transform direction
49                    - value = 0: forward transform
50                    - value = 1: inverse transform
51   @param[in]     bitReverseFlag flag that enables / disables bit reversal of output
52                    - value = 0: disables bit reversal of output
53                    - value = 1: enables bit reversal of output
54   @return        execution status
55                    - \ref ARM_MATH_SUCCESS        : Operation successful
56                    - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLen</code> is not a supported length
57 
58   @par           Details
59                    The parameter <code>ifftFlag</code> controls whether a forward or inverse transform is computed.
60                    Set(=1) ifftFlag for calculation of CIFFT otherwise  CFFT is calculated
61   @par
62                    The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
63                    Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
64   @par
65                    The parameter <code>fftLen</code> Specifies length of CFFT/CIFFT process. Supported FFT Lengths are 16, 64, 256, 1024.
66   @par
67                    This Function also initializes Twiddle factor table pointer and Bit reversal table pointer.
68  */
69 
arm_cfft_radix4_init_q15(arm_cfft_radix4_instance_q15 * S,uint16_t fftLen,uint8_t ifftFlag,uint8_t bitReverseFlag)70 arm_status arm_cfft_radix4_init_q15(
71   arm_cfft_radix4_instance_q15 * S,
72   uint16_t fftLen,
73   uint8_t ifftFlag,
74   uint8_t bitReverseFlag)
75 {
76   /*  Initialise the default arm status */
77   arm_status status = ARM_MATH_ARGUMENT_ERROR;
78 
79 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES)
80 
81 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_4096)
82 
83   /*  Initialise the default arm status */
84   status = ARM_MATH_SUCCESS;
85   /*  Initialise the FFT length */
86   S->fftLen = fftLen;
87   /*  Initialise the Twiddle coefficient pointer */
88   S->pTwiddle = (q15_t *) twiddleCoef_4096_q15;
89   /*  Initialise the Flag for selection of CFFT or CIFFT */
90   S->ifftFlag = ifftFlag;
91   /*  Initialise the Flag for calculation Bit reversal or not */
92   S->bitReverseFlag = bitReverseFlag;
93 
94 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREV_1024)
95 
96   /*  Initializations of structure parameters depending on the FFT length */
97   switch (S->fftLen)
98   {
99   case 4096U:
100     /*  Initializations of structure parameters for 4096 point FFT */
101 
102     /*  Initialise the twiddle coef modifier value */
103     S->twidCoefModifier = 1U;
104     /*  Initialise the bit reversal table modifier */
105     S->bitRevFactor = 1U;
106     /*  Initialise the bit reversal table pointer */
107     S->pBitRevTable = (uint16_t *) armBitRevTable;
108 
109     break;
110 
111   case 1024U:
112     /*  Initializations of structure parameters for 1024 point FFT */
113     S->twidCoefModifier = 4U;
114     S->bitRevFactor = 4U;
115     S->pBitRevTable = (uint16_t *) & armBitRevTable[3];
116 
117     break;
118 
119   case 256U:
120     /*  Initializations of structure parameters for 256 point FFT */
121     S->twidCoefModifier = 16U;
122     S->bitRevFactor = 16U;
123     S->pBitRevTable = (uint16_t *) & armBitRevTable[15];
124 
125     break;
126 
127   case 64U:
128     /*  Initializations of structure parameters for 64 point FFT */
129     S->twidCoefModifier = 64U;
130     S->bitRevFactor = 64U;
131     S->pBitRevTable = (uint16_t *) & armBitRevTable[63];
132 
133     break;
134 
135   case 16U:
136     /*  Initializations of structure parameters for 16 point FFT */
137     S->twidCoefModifier = 256U;
138     S->bitRevFactor = 256U;
139     S->pBitRevTable = (uint16_t *) & armBitRevTable[255];
140 
141     break;
142 
143   default:
144     /*  Reporting argument error if fftSize is not valid value */
145     status = ARM_MATH_ARGUMENT_ERROR;
146     break;
147   }
148 
149 #endif
150 #endif
151 #endif
152   return (status);
153 }
154 
155 /**
156   @} end of ComplexFFT group
157  */
158