• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-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 #include "arm_const_structs.h"
32 
33 /**
34   @addtogroup RealFFT
35   @{
36  */
37 
38 /**
39   @brief         Initialization function for the Q15 RFFT/RIFFT.
40   @param[in,out] S              points to an instance of the Q15 RFFT/RIFFT structure
41   @param[in]     fftLenReal     length of the FFT
42   @param[in]     ifftFlagR      flag that selects transform direction
43                    - value = 0: forward transform
44                    - value = 1: inverse transform
45   @param[in]     bitReverseFlag flag that enables / disables bit reversal of output
46                    - value = 0: disables bit reversal of output
47                    - value = 1: enables bit reversal of output
48   @return        execution status
49                    - \ref ARM_MATH_SUCCESS        : Operation successful
50                    - \ref ARM_MATH_ARGUMENT_ERROR : <code>fftLenReal</code> is not a supported length
51 
52   @par           Details
53                    The parameter <code>fftLenReal</code> specifies length of RFFT/RIFFT Process.
54                    Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192.
55   @par
56                    The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
57                    Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
58   @par
59                    The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
60                    Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
61   @par
62                    This function also initializes Twiddle factor table.
63  */
64 
arm_rfft_init_q15(arm_rfft_instance_q15 * S,uint32_t fftLenReal,uint32_t ifftFlagR,uint32_t bitReverseFlag)65 arm_status arm_rfft_init_q15(
66     arm_rfft_instance_q15 * S,
67     uint32_t fftLenReal,
68     uint32_t ifftFlagR,
69     uint32_t bitReverseFlag)
70 {
71      /*  Initialise the default arm status */
72     arm_status status = ARM_MATH_ARGUMENT_ERROR;
73 
74 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES)
75 
76 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_Q15)
77 
78     /*  Initialise the default arm status */
79     status = ARM_MATH_SUCCESS;
80 
81     /*  Initialize the Real FFT length */
82     S->fftLenReal = (uint16_t) fftLenReal;
83 
84     /*  Initialize the Twiddle coefficientA pointer */
85     S->pTwiddleAReal = (q15_t *) realCoefAQ15;
86 
87     /*  Initialize the Twiddle coefficientB pointer */
88     S->pTwiddleBReal = (q15_t *) realCoefBQ15;
89 
90     /*  Initialize the Flag for selection of RFFT or RIFFT */
91     S->ifftFlagR = (uint8_t) ifftFlagR;
92 
93     /*  Initialize the Flag for calculation Bit reversal or not */
94     S->bitReverseFlagR = (uint8_t) bitReverseFlag;
95 
96     /*  Initialization of coef modifier depending on the FFT length */
97     switch (S->fftLenReal)
98     {
99 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_4096) && defined(ARM_TABLE_BITREVIDX_FXT_4096))
100     case 8192U:
101         S->twidCoefRModifier = 1U;
102 
103         #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
104            status=arm_cfft_init_q15(&(S->cfftInst),4096);
105            if (status != ARM_MATH_SUCCESS)
106            {
107                return(status);
108            }
109         #else
110           S->pCfft = &arm_cfft_sR_q15_len4096;
111         #endif
112         break;
113 #endif
114 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_2048) && defined(ARM_TABLE_BITREVIDX_FXT_2048))
115     case 4096U:
116         S->twidCoefRModifier = 2U;
117 
118         #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
119            status=arm_cfft_init_q15(&(S->cfftInst),2048);
120            if (status != ARM_MATH_SUCCESS)
121            {
122                return(status);
123            }
124         #else
125            S->pCfft = &arm_cfft_sR_q15_len2048;
126         #endif
127         break;
128 #endif
129 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_1024) && defined(ARM_TABLE_BITREVIDX_FXT_1024))
130     case 2048U:
131         S->twidCoefRModifier = 4U;
132 
133         #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
134            status=arm_cfft_init_q15(&(S->cfftInst),1024);
135            if (status != ARM_MATH_SUCCESS)
136            {
137                return(status);
138            }
139         #else
140            S->pCfft = &arm_cfft_sR_q15_len1024;
141         #endif
142         break;
143 #endif
144 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_512) && defined(ARM_TABLE_BITREVIDX_FXT_512))
145     case 1024U:
146         S->twidCoefRModifier = 8U;
147 
148         #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
149            status=arm_cfft_init_q15(&(S->cfftInst),512);
150            if (status != ARM_MATH_SUCCESS)
151            {
152                return(status);
153            }
154         #else
155           S->pCfft = &arm_cfft_sR_q15_len512;
156         #endif
157         break;
158 #endif
159 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_256) && defined(ARM_TABLE_BITREVIDX_FXT_256))
160     case 512U:
161         S->twidCoefRModifier = 16U;
162 
163         #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
164            status=arm_cfft_init_q15(&(S->cfftInst),256);
165            if (status != ARM_MATH_SUCCESS)
166            {
167                return(status);
168            }
169         #else
170            S->pCfft = &arm_cfft_sR_q15_len256;
171         #endif
172         break;
173 #endif
174 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_128) && defined(ARM_TABLE_BITREVIDX_FXT_128))
175     case 256U:
176         S->twidCoefRModifier = 32U;
177 
178         #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
179            status=arm_cfft_init_q15(&(S->cfftInst),128);
180            if (status != ARM_MATH_SUCCESS)
181            {
182                return(status);
183            }
184         #else
185            S->pCfft = &arm_cfft_sR_q15_len128;
186         #endif
187         break;
188 #endif
189 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_64) && defined(ARM_TABLE_BITREVIDX_FXT_64))
190     case 128U:
191         S->twidCoefRModifier = 64U;
192 
193         #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
194            status=arm_cfft_init_q15(&(S->cfftInst),64);
195            if (status != ARM_MATH_SUCCESS)
196            {
197                return(status);
198            }
199         #else
200            S->pCfft = &arm_cfft_sR_q15_len64;
201         #endif
202         break;
203 #endif
204 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_32) && defined(ARM_TABLE_BITREVIDX_FXT_32))
205     case 64U:
206         S->twidCoefRModifier = 128U;
207 
208         #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
209            status=arm_cfft_init_q15(&(S->cfftInst),32);
210            if (status != ARM_MATH_SUCCESS)
211            {
212                return(status);
213            }
214         #else
215           S->pCfft = &arm_cfft_sR_q15_len32;
216         #endif
217         break;
218 #endif
219 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q15_16) && defined(ARM_TABLE_BITREVIDX_FXT_16))
220     case 32U:
221         S->twidCoefRModifier = 256U;
222 
223         #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
224            status=arm_cfft_init_q15(&(S->cfftInst),16);
225            if (status != ARM_MATH_SUCCESS)
226            {
227                return(status);
228            }
229         #else
230            S->pCfft = &arm_cfft_sR_q15_len16;
231         #endif
232         break;
233 #endif
234     default:
235         /*  Reporting argument error if rfftSize is not valid value */
236         status = ARM_MATH_ARGUMENT_ERROR;
237         break;
238     }
239 
240 #endif
241 #endif
242     /* return the status of RFFT Init function */
243     return (status);
244 }
245 
246 /**
247   @} end of RealFFT group
248  */
249