Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /* ---------------------------------------------------------------------- |
2 | * Project: CMSIS DSP Library |
||
3 | * Title: arm_rfft_init_q15.c |
||
4 | * Description: RFFT & RIFFT Q15 initialisation function |
||
5 | * |
||
6 | * $Date: 27. January 2017 |
||
7 | * $Revision: V.1.5.1 |
||
8 | * |
||
9 | * Target Processor: Cortex-M cores |
||
10 | * -------------------------------------------------------------------- */ |
||
11 | /* |
||
12 | * Copyright (C) 2010-2017 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 | * @ingroup RealFFT |
||
35 | */ |
||
36 | |||
37 | /** |
||
38 | * @addtogroup RealFFT_Table Real FFT Tables |
||
39 | * @{ |
||
40 | */ |
||
41 | |||
42 | /** |
||
43 | * \par |
||
44 | * Generation fixed-point realCoefAQ15 array in Q15 format: |
||
45 | * \par |
||
46 | * n = 4096 |
||
47 | * <pre>for (i = 0; i < n; i++) |
||
48 | * { |
||
49 | * pATable[2 * i] = 0.5 * (1.0 - sin (2 * PI / (double) (2 * n) * (double) i)); |
||
50 | * pATable[2 * i + 1] = 0.5 * (-1.0 * cos (2 * PI / (double) (2 * n) * (double) i)); |
||
51 | * } </pre> |
||
52 | * \par |
||
53 | * Convert to fixed point Q15 format |
||
54 | * round(pATable[i] * pow(2, 15)) |
||
55 | *//** |
||
56 | * \par |
||
57 | * Generation of real_CoefB array: |
||
58 | * \par |
||
59 | * n = 4096 |
||
60 | * <pre>for (i = 0; i < n; i++) |
||
61 | * { |
||
62 | * pBTable[2 * i] = 0.5 * (1.0 + sin (2 * PI / (double) (2 * n) * (double) i)); |
||
63 | * pBTable[2 * i + 1] = 0.5 * (1.0 * cos (2 * PI / (double) (2 * n) * (double) i)); |
||
64 | * } </pre> |
||
65 | * \par |
||
66 | * Convert to fixed point Q15 format |
||
67 | * round(pBTable[i] * pow(2, 15)) |
||
68 | * |
||
69 | *//** |
||
70 | * @} end of RealFFT_Table group |
||
71 | */ |
||
72 | |||
73 | /** |
||
74 | * @addtogroup RealFFT |
||
75 | * @{ |
||
76 | */ |
||
77 | |||
78 | /** |
||
79 | * @brief Initialization function for the Q15 RFFT/RIFFT. |
||
80 | * @param[in, out] *S points to an instance of the Q15 RFFT/RIFFT structure. |
||
81 | * @param[in] fftLenReal length of the FFT. |
||
82 | * @param[in] ifftFlagR flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. |
||
83 | * @param[in] bitReverseFlag flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. |
||
84 | * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLenReal</code> is not a supported value. |
||
85 | * |
||
86 | * \par Description: |
||
87 | * \par |
||
88 | * The parameter <code>fftLenReal</code> Specifies length of RFFT/RIFFT Process. Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192. |
||
89 | * \par |
||
90 | * The parameter <code>ifftFlagR</code> controls whether a forward or inverse transform is computed. |
||
91 | * Set(=1) ifftFlagR to calculate RIFFT, otherwise RFFT is calculated. |
||
92 | * \par |
||
93 | * The parameter <code>bitReverseFlag</code> controls whether output is in normal order or bit reversed order. |
||
94 | * Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order. |
||
95 | * \par |
||
96 | * This function also initializes Twiddle factor table. |
||
97 | */ |
||
98 | arm_status arm_rfft_init_q15( |
||
99 | arm_rfft_instance_q15 * S, |
||
100 | uint32_t fftLenReal, |
||
101 | uint32_t ifftFlagR, |
||
102 | uint32_t bitReverseFlag) |
||
103 | { |
||
104 | /* Initialise the default arm status */ |
||
105 | arm_status status = ARM_MATH_SUCCESS; |
||
106 | |||
107 | /* Initialize the Real FFT length */ |
||
108 | S->fftLenReal = (uint16_t) fftLenReal; |
||
109 | |||
110 | /* Initialize the Twiddle coefficientA pointer */ |
||
111 | S->pTwiddleAReal = (q15_t *) realCoefAQ15; |
||
112 | |||
113 | /* Initialize the Twiddle coefficientB pointer */ |
||
114 | S->pTwiddleBReal = (q15_t *) realCoefBQ15; |
||
115 | |||
116 | /* Initialize the Flag for selection of RFFT or RIFFT */ |
||
117 | S->ifftFlagR = (uint8_t) ifftFlagR; |
||
118 | |||
119 | /* Initialize the Flag for calculation Bit reversal or not */ |
||
120 | S->bitReverseFlagR = (uint8_t) bitReverseFlag; |
||
121 | |||
122 | /* Initialization of coef modifier depending on the FFT length */ |
||
123 | switch (S->fftLenReal) |
||
124 | { |
||
125 | case 8192U: |
||
126 | S->twidCoefRModifier = 1U; |
||
127 | S->pCfft = &arm_cfft_sR_q15_len4096; |
||
128 | break; |
||
129 | case 4096U: |
||
130 | S->twidCoefRModifier = 2U; |
||
131 | S->pCfft = &arm_cfft_sR_q15_len2048; |
||
132 | break; |
||
133 | case 2048U: |
||
134 | S->twidCoefRModifier = 4U; |
||
135 | S->pCfft = &arm_cfft_sR_q15_len1024; |
||
136 | break; |
||
137 | case 1024U: |
||
138 | S->twidCoefRModifier = 8U; |
||
139 | S->pCfft = &arm_cfft_sR_q15_len512; |
||
140 | break; |
||
141 | case 512U: |
||
142 | S->twidCoefRModifier = 16U; |
||
143 | S->pCfft = &arm_cfft_sR_q15_len256; |
||
144 | break; |
||
145 | case 256U: |
||
146 | S->twidCoefRModifier = 32U; |
||
147 | S->pCfft = &arm_cfft_sR_q15_len128; |
||
148 | break; |
||
149 | case 128U: |
||
150 | S->twidCoefRModifier = 64U; |
||
151 | S->pCfft = &arm_cfft_sR_q15_len64; |
||
152 | break; |
||
153 | case 64U: |
||
154 | S->twidCoefRModifier = 128U; |
||
155 | S->pCfft = &arm_cfft_sR_q15_len32; |
||
156 | break; |
||
157 | case 32U: |
||
158 | S->twidCoefRModifier = 256U; |
||
159 | S->pCfft = &arm_cfft_sR_q15_len16; |
||
160 | break; |
||
161 | default: |
||
162 | /* Reporting argument error if rfftSize is not valid value */ |
||
163 | status = ARM_MATH_ARGUMENT_ERROR; |
||
164 | break; |
||
165 | } |
||
166 | |||
167 | /* return the status of RFFT Init function */ |
||
168 | return (status); |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * @} end of RealFFT group |
||
173 | */ |
||
174 | |||
175 |