1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_rfft_init_f32.c
4  * Description:  RFFT & RIFFT Floating point 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 
32 
33 /**
34   @ingroup RealFFT
35 */
36 
37 /**
38   @addtogroup DeprecatedRealFFT
39   @{
40  */
41 
42 /**
43   @brief         Initialization function for the floating-point RFFT/RIFFT.
44   @deprecated    Do not use this function. It has been superceded by \ref arm_rfft_fast_init_f32 and will be removed in the future.
45   @param[in,out] S             points to an instance of the floating-point RFFT/RIFFT structure
46   @param[in,out] S_CFFT        points to an instance of the floating-point CFFT/CIFFT structure
47   @param[in]     fftLenReal     length of the FFT.
48   @param[in]     ifftFlagR      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>fftLenReal</code> is not a supported length
57 
58   @par Description
59                    The parameter <code>fftLenReal</code>specifies length of RFFT/RIFFT Process.
60                    Supported FFT Lengths are 128, 512, 2048.
61   @par
62                    The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed.
63                    Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated.
64   @par
65                    The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order.
66                    Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order.
67   @par
68                    This function also initializes Twiddle factor table.
69  */
70 
arm_rfft_init_f32(arm_rfft_instance_f32 * S,arm_cfft_radix4_instance_f32 * S_CFFT,uint32_t fftLenReal,uint32_t ifftFlagR,uint32_t bitReverseFlag)71 arm_status arm_rfft_init_f32(
72   arm_rfft_instance_f32 * S,
73   arm_cfft_radix4_instance_f32 * S_CFFT,
74   uint32_t fftLenReal,
75   uint32_t ifftFlagR,
76   uint32_t bitReverseFlag)
77 {
78    /*  Initialise the default arm status */
79   arm_status status = ARM_MATH_ARGUMENT_ERROR;
80 
81 
82   /*  Initialise the default arm status */
83   status = ARM_MATH_SUCCESS;
84 
85   /*  Initialize the Real FFT length */
86   S->fftLenReal = (uint16_t) fftLenReal;
87 
88   /*  Initialize the Complex FFT length */
89   S->fftLenBy2 = (uint16_t) fftLenReal / 2U;
90 
91   /*  Initialize the Twiddle coefficientA pointer */
92   S->pTwiddleAReal = (float32_t *) realCoefA;
93 
94   /*  Initialize the Twiddle coefficientB pointer */
95   S->pTwiddleBReal = (float32_t *) realCoefB;
96 
97   /*  Initialize the Flag for selection of RFFT or RIFFT */
98   S->ifftFlagR = (uint8_t) ifftFlagR;
99 
100   /*  Initialize the Flag for calculation Bit reversal or not */
101   S->bitReverseFlagR = (uint8_t) bitReverseFlag;
102 
103   /*  Initializations of structure parameters depending on the FFT length */
104   switch (S->fftLenReal)
105   {
106     /* Init table modifier value */
107   case 8192U:
108     S->twidCoefRModifier = 1U;
109     break;
110   case 2048U:
111     S->twidCoefRModifier = 4U;
112     break;
113   case 512U:
114     S->twidCoefRModifier = 16U;
115     break;
116   case 128U:
117     S->twidCoefRModifier = 64U;
118     break;
119   default:
120     /*  Reporting argument error if rfftSize is not valid value */
121     status = ARM_MATH_ARGUMENT_ERROR;
122     break;
123   }
124 
125   /* Init Complex FFT Instance */
126   S->pCfft = S_CFFT;
127 
128   if (S->ifftFlagR)
129   {
130     /* Initializes the CIFFT Module for fftLenreal/2 length */
131     arm_cfft_radix4_init_f32(S->pCfft, S->fftLenBy2, 1U, 0U);
132   }
133   else
134   {
135     /* Initializes the CFFT Module for fftLenreal/2 length */
136     arm_cfft_radix4_init_f32(S->pCfft, S->fftLenBy2, 0U, 0U);
137   }
138 
139   /* return the status of RFFT Init function */
140   return (status);
141 
142 }
143 
144 /**
145   @} end of DeprecatedRealFFT group
146  */
147