• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_rfft_init_q31.c
4  * Description:  RFFT & RIFFT Q31 initialisation function
5  *
6  * $Date:        18. March 2019
7  * $Revision:    V1.6.0
8  *
9  * Target Processor: Cortex-M cores
10  * -------------------------------------------------------------------- */
11 /*
12  * Copyright (C) 2010-2019 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 "arm_math.h"
30 #include "arm_common_tables.h"
31 #include "arm_const_structs.h"
32 
33 
34 
35 /**
36   @addtogroup RealFFT
37   @{
38  */
39 
40 /**
41   @brief         Initialization function for the Q31 RFFT/RIFFT.
42   @param[in,out] S              points to an instance of the Q31 RFFT/RIFFT structure
43   @param[in]     fftLenReal     length of the FFT
44   @param[in]     ifftFlagR      flag that selects transform direction
45                    - value = 0: forward transform
46                    - value = 1: inverse transform
47   @param[in]     bitReverseFlag flag that enables / disables bit reversal of output
48                    - value = 0: disables bit reversal of output
49                    - value = 1: enables bit reversal of output
50   @return        execution status
51                    - \ref ARM_MATH_SUCCESS        : Operation successful
52                    - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
53 
54   @par           Details
55                    The parameter <code>fftLenReal</code> specifies length of RFFT/RIFFT Process.
56                    Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192.
57   @par
58                    The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
59                    Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT 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                    This function also initializes Twiddle factor table.
65 */
66 
arm_rfft_init_q31(arm_rfft_instance_q31 * S,uint32_t fftLenReal,uint32_t ifftFlagR,uint32_t bitReverseFlag)67 arm_status arm_rfft_init_q31(
68     arm_rfft_instance_q31 * S,
69     uint32_t fftLenReal,
70     uint32_t ifftFlagR,
71     uint32_t bitReverseFlag)
72 {
73     /*  Initialise the default arm status */
74     arm_status status = ARM_MATH_SUCCESS;
75 
76     /*  Initialize the Real FFT length */
77     S->fftLenReal = (uint16_t) fftLenReal;
78 
79     /*  Initialize the Twiddle coefficientA pointer */
80     S->pTwiddleAReal = (q31_t *) realCoefAQ31;
81 
82     /*  Initialize the Twiddle coefficientB pointer */
83     S->pTwiddleBReal = (q31_t *) realCoefBQ31;
84 
85     /*  Initialize the Flag for selection of RFFT or RIFFT */
86     S->ifftFlagR = (uint8_t) ifftFlagR;
87 
88     /*  Initialize the Flag for calculation Bit reversal or not */
89     S->bitReverseFlagR = (uint8_t) bitReverseFlag;
90 
91     /*  Initialization of coef modifier depending on the FFT length */
92     switch (S->fftLenReal)
93     {
94 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_4096) && defined(ARM_TABLE_BITREVIDX_FXT_4096))
95     case 8192U:
96 
97 
98         S->twidCoefRModifier = 1U;
99 
100         #if defined(ARM_MATH_MVEI)
101            status=arm_cfft_init_q31(&(S->cfftInst),4096);
102            if (status != ARM_MATH_SUCCESS)
103            {
104                return(status);
105            }
106         #else
107            S->pCfft = &arm_cfft_sR_q31_len4096;
108         #endif
109         break;
110 #endif
111 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_2048) && defined(ARM_TABLE_BITREVIDX_FXT_2048))
112     case 4096U:
113         S->twidCoefRModifier = 2U;
114 
115         #if defined(ARM_MATH_MVEI)
116            status=arm_cfft_init_q31(&(S->cfftInst),2048);
117            if (status != ARM_MATH_SUCCESS)
118            {
119                return(status);
120            }
121         #else
122            S->pCfft = &arm_cfft_sR_q31_len2048;
123         #endif
124         break;
125 #endif
126 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_1024) && defined(ARM_TABLE_BITREVIDX_FXT_1024))
127     case 2048U:
128         S->twidCoefRModifier = 4U;
129 
130         #if defined(ARM_MATH_MVEI)
131            status=arm_cfft_init_q31(&(S->cfftInst),1024);
132            if (status != ARM_MATH_SUCCESS)
133            {
134                return(status);
135            }
136         #else
137           S->pCfft = &arm_cfft_sR_q31_len1024;
138         #endif
139         break;
140 #endif
141 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_512) && defined(ARM_TABLE_BITREVIDX_FXT_512))
142     case 1024U:
143         S->twidCoefRModifier = 8U;
144         #if defined(ARM_MATH_MVEI)
145            status=arm_cfft_init_q31(&(S->cfftInst),512);
146            if (status != ARM_MATH_SUCCESS)
147            {
148                return(status);
149            }
150         #else
151            S->pCfft = &arm_cfft_sR_q31_len512;
152         #endif
153         break;
154 #endif
155 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_256) && defined(ARM_TABLE_BITREVIDX_FXT_256))
156     case 512U:
157         S->twidCoefRModifier = 16U;
158         #if defined(ARM_MATH_MVEI)
159            status=arm_cfft_init_q31(&(S->cfftInst),256);
160            if (status != ARM_MATH_SUCCESS)
161            {
162                return(status);
163            }
164         #else
165            S->pCfft = &arm_cfft_sR_q31_len256;
166         #endif
167         break;
168 #endif
169 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_128) && defined(ARM_TABLE_BITREVIDX_FXT_128))
170     case 256U:
171         S->twidCoefRModifier = 32U;
172         #if defined(ARM_MATH_MVEI)
173            status=arm_cfft_init_q31(&(S->cfftInst),128);
174            if (status != ARM_MATH_SUCCESS)
175            {
176                return(status);
177            }
178         #else
179            S->pCfft = &arm_cfft_sR_q31_len128;
180         #endif
181         break;
182 #endif
183 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_64) && defined(ARM_TABLE_BITREVIDX_FXT_64))
184     case 128U:
185         S->twidCoefRModifier = 64U;
186         #if defined(ARM_MATH_MVEI)
187            status=arm_cfft_init_q31(&(S->cfftInst),64);
188            if (status != ARM_MATH_SUCCESS)
189            {
190                return(status);
191            }
192         #else
193            S->pCfft = &arm_cfft_sR_q31_len64;
194         #endif
195         break;
196 #endif
197 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_32) && defined(ARM_TABLE_BITREVIDX_FXT_32))
198     case 64U:
199         S->twidCoefRModifier = 128U;
200         #if defined(ARM_MATH_MVEI)
201            status=arm_cfft_init_q31(&(S->cfftInst),32);
202            if (status != ARM_MATH_SUCCESS)
203            {
204                return(status);
205            }
206         #else
207            S->pCfft = &arm_cfft_sR_q31_len32;
208         #endif
209         break;
210 #endif
211 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_16) && defined(ARM_TABLE_BITREVIDX_FXT_16))
212     case 32U:
213         S->twidCoefRModifier = 256U;
214         #if defined(ARM_MATH_MVEI)
215            status=arm_cfft_init_q31(&(S->cfftInst),16);
216            if (status != ARM_MATH_SUCCESS)
217            {
218                return(status);
219            }
220         #else
221            S->pCfft = &arm_cfft_sR_q31_len16;
222         #endif
223         break;
224 #endif
225     default:
226         /*  Reporting argument error if rfftSize is not valid value */
227         status = ARM_MATH_ARGUMENT_ERROR;
228         break;
229     }
230 
231     /* return the status of RFFT Init function */
232     return (status);
233 }
234 
235 /**
236   @} end of RealFFT group
237  */
238