source: S-port/trunk/Drivers/CMSIS/DSP/Source/TransformFunctions/arm_bitreversal.c

Last change on this file was 1, checked in by AlexLir, 3 years ago
File size: 7.0 KB
Line 
1/* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_bitreversal.c
4 * Description: Bitreversal functions
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
32/*
33* @brief In-place bit reversal function.
34* @param[in, out] *pSrc points to the in-place buffer of floating-point data type.
35* @param[in] fftSize length of the FFT.
36* @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table.
37* @param[in] *pBitRevTab points to the bit reversal table.
38* @return none.
39*/
40
41void arm_bitreversal_f32(
42float32_t * pSrc,
43uint16_t fftSize,
44uint16_t bitRevFactor,
45uint16_t * pBitRevTab)
46{
47 uint16_t fftLenBy2, fftLenBy2p1;
48 uint16_t i, j;
49 float32_t in;
50
51 /* Initializations */
52 j = 0U;
53 fftLenBy2 = fftSize >> 1U;
54 fftLenBy2p1 = (fftSize >> 1U) + 1U;
55
56 /* Bit Reversal Implementation */
57 for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U)
58 {
59 if (i < j)
60 {
61 /* pSrc[i] <-> pSrc[j]; */
62 in = pSrc[2U * i];
63 pSrc[2U * i] = pSrc[2U * j];
64 pSrc[2U * j] = in;
65
66 /* pSrc[i+1U] <-> pSrc[j+1U] */
67 in = pSrc[(2U * i) + 1U];
68 pSrc[(2U * i) + 1U] = pSrc[(2U * j) + 1U];
69 pSrc[(2U * j) + 1U] = in;
70
71 /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */
72 in = pSrc[2U * (i + fftLenBy2p1)];
73 pSrc[2U * (i + fftLenBy2p1)] = pSrc[2U * (j + fftLenBy2p1)];
74 pSrc[2U * (j + fftLenBy2p1)] = in;
75
76 /* pSrc[i+fftLenBy2p1+1U] <-> pSrc[j+fftLenBy2p1+1U] */
77 in = pSrc[(2U * (i + fftLenBy2p1)) + 1U];
78 pSrc[(2U * (i + fftLenBy2p1)) + 1U] =
79 pSrc[(2U * (j + fftLenBy2p1)) + 1U];
80 pSrc[(2U * (j + fftLenBy2p1)) + 1U] = in;
81
82 }
83
84 /* pSrc[i+1U] <-> pSrc[j+1U] */
85 in = pSrc[2U * (i + 1U)];
86 pSrc[2U * (i + 1U)] = pSrc[2U * (j + fftLenBy2)];
87 pSrc[2U * (j + fftLenBy2)] = in;
88
89 /* pSrc[i+2U] <-> pSrc[j+2U] */
90 in = pSrc[(2U * (i + 1U)) + 1U];
91 pSrc[(2U * (i + 1U)) + 1U] = pSrc[(2U * (j + fftLenBy2)) + 1U];
92 pSrc[(2U * (j + fftLenBy2)) + 1U] = in;
93
94 /* Reading the index for the bit reversal */
95 j = *pBitRevTab;
96
97 /* Updating the bit reversal index depending on the fft length */
98 pBitRevTab += bitRevFactor;
99 }
100}
101
102
103
104/*
105* @brief In-place bit reversal function.
106* @param[in, out] *pSrc points to the in-place buffer of Q31 data type.
107* @param[in] fftLen length of the FFT.
108* @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table
109* @param[in] *pBitRevTab points to bit reversal table.
110* @return none.
111*/
112
113void arm_bitreversal_q31(
114q31_t * pSrc,
115uint32_t fftLen,
116uint16_t bitRevFactor,
117uint16_t * pBitRevTable)
118{
119 uint32_t fftLenBy2, fftLenBy2p1, i, j;
120 q31_t in;
121
122 /* Initializations */
123 j = 0U;
124 fftLenBy2 = fftLen / 2U;
125 fftLenBy2p1 = (fftLen / 2U) + 1U;
126
127 /* Bit Reversal Implementation */
128 for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U)
129 {
130 if (i < j)
131 {
132 /* pSrc[i] <-> pSrc[j]; */
133 in = pSrc[2U * i];
134 pSrc[2U * i] = pSrc[2U * j];
135 pSrc[2U * j] = in;
136
137 /* pSrc[i+1U] <-> pSrc[j+1U] */
138 in = pSrc[(2U * i) + 1U];
139 pSrc[(2U * i) + 1U] = pSrc[(2U * j) + 1U];
140 pSrc[(2U * j) + 1U] = in;
141
142 /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */
143 in = pSrc[2U * (i + fftLenBy2p1)];
144 pSrc[2U * (i + fftLenBy2p1)] = pSrc[2U * (j + fftLenBy2p1)];
145 pSrc[2U * (j + fftLenBy2p1)] = in;
146
147 /* pSrc[i+fftLenBy2p1+1U] <-> pSrc[j+fftLenBy2p1+1U] */
148 in = pSrc[(2U * (i + fftLenBy2p1)) + 1U];
149 pSrc[(2U * (i + fftLenBy2p1)) + 1U] =
150 pSrc[(2U * (j + fftLenBy2p1)) + 1U];
151 pSrc[(2U * (j + fftLenBy2p1)) + 1U] = in;
152
153 }
154
155 /* pSrc[i+1U] <-> pSrc[j+1U] */
156 in = pSrc[2U * (i + 1U)];
157 pSrc[2U * (i + 1U)] = pSrc[2U * (j + fftLenBy2)];
158 pSrc[2U * (j + fftLenBy2)] = in;
159
160 /* pSrc[i+2U] <-> pSrc[j+2U] */
161 in = pSrc[(2U * (i + 1U)) + 1U];
162 pSrc[(2U * (i + 1U)) + 1U] = pSrc[(2U * (j + fftLenBy2)) + 1U];
163 pSrc[(2U * (j + fftLenBy2)) + 1U] = in;
164
165 /* Reading the index for the bit reversal */
166 j = *pBitRevTable;
167
168 /* Updating the bit reversal index depending on the fft length */
169 pBitRevTable += bitRevFactor;
170 }
171}
172
173
174
175/*
176 * @brief In-place bit reversal function.
177 * @param[in, out] *pSrc points to the in-place buffer of Q15 data type.
178 * @param[in] fftLen length of the FFT.
179 * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table
180 * @param[in] *pBitRevTab points to bit reversal table.
181 * @return none.
182*/
183
184void arm_bitreversal_q15(
185q15_t * pSrc16,
186uint32_t fftLen,
187uint16_t bitRevFactor,
188uint16_t * pBitRevTab)
189{
190 q31_t *pSrc = (q31_t *) pSrc16;
191 q31_t in;
192 uint32_t fftLenBy2, fftLenBy2p1;
193 uint32_t i, j;
194
195 /* Initializations */
196 j = 0U;
197 fftLenBy2 = fftLen / 2U;
198 fftLenBy2p1 = (fftLen / 2U) + 1U;
199
200 /* Bit Reversal Implementation */
201 for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U)
202 {
203 if (i < j)
204 {
205 /* pSrc[i] <-> pSrc[j]; */
206 /* pSrc[i+1U] <-> pSrc[j+1U] */
207 in = pSrc[i];
208 pSrc[i] = pSrc[j];
209 pSrc[j] = in;
210
211 /* pSrc[i + fftLenBy2p1] <-> pSrc[j + fftLenBy2p1]; */
212 /* pSrc[i + fftLenBy2p1+1U] <-> pSrc[j + fftLenBy2p1+1U] */
213 in = pSrc[i + fftLenBy2p1];
214 pSrc[i + fftLenBy2p1] = pSrc[j + fftLenBy2p1];
215 pSrc[j + fftLenBy2p1] = in;
216 }
217
218 /* pSrc[i+1U] <-> pSrc[j+fftLenBy2]; */
219 /* pSrc[i+2] <-> pSrc[j+fftLenBy2+1U] */
220 in = pSrc[i + 1U];
221 pSrc[i + 1U] = pSrc[j + fftLenBy2];
222 pSrc[j + fftLenBy2] = in;
223
224 /* Reading the index for the bit reversal */
225 j = *pBitRevTab;
226
227 /* Updating the bit reversal index depending on the fft length */
228 pBitRevTab += bitRevFactor;
229 }
230}
Note: See TracBrowser for help on using the repository browser.