1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_bitreversal.c
4 * Description: Bitreversal functions
6 * $Date: 27. January 2017
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
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
20 * www.apache.org/licenses/LICENSE-2.0
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.
30 #include "arm_common_tables.h"
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.
41 void arm_bitreversal_f32(
44 uint16_t bitRevFactor
,
45 uint16_t * pBitRevTab
)
47 uint16_t fftLenBy2
, fftLenBy2p1
;
53 fftLenBy2
= fftSize
>> 1U;
54 fftLenBy2p1
= (fftSize
>> 1U) + 1U;
56 /* Bit Reversal Implementation */
57 for (i
= 0U; i
<= (fftLenBy2
- 2U); i
+= 2U)
61 /* pSrc[i] <-> pSrc[j]; */
63 pSrc
[2U * i
] = pSrc
[2U * j
];
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
;
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
;
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
;
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
;
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
;
94 /* Reading the index for the bit reversal */
97 /* Updating the bit reversal index depending on the fft length */
98 pBitRevTab
+= bitRevFactor
;
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.
113 void arm_bitreversal_q31(
116 uint16_t bitRevFactor
,
117 uint16_t * pBitRevTable
)
119 uint32_t fftLenBy2
, fftLenBy2p1
, i
, j
;
122 /* Initializations */
124 fftLenBy2
= fftLen
/ 2U;
125 fftLenBy2p1
= (fftLen
/ 2U) + 1U;
127 /* Bit Reversal Implementation */
128 for (i
= 0U; i
<= (fftLenBy2
- 2U); i
+= 2U)
132 /* pSrc[i] <-> pSrc[j]; */
134 pSrc
[2U * i
] = pSrc
[2U * j
];
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
;
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
;
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
;
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
;
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
;
165 /* Reading the index for the bit reversal */
168 /* Updating the bit reversal index depending on the fft length */
169 pBitRevTable
+= bitRevFactor
;
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.
184 void arm_bitreversal_q15(
187 uint16_t bitRevFactor
,
188 uint16_t * pBitRevTab
)
190 q31_t
*pSrc
= (q31_t
*) pSrc16
;
192 uint32_t fftLenBy2
, fftLenBy2p1
;
195 /* Initializations */
197 fftLenBy2
= fftLen
/ 2U;
198 fftLenBy2p1
= (fftLen
/ 2U) + 1U;
200 /* Bit Reversal Implementation */
201 for (i
= 0U; i
<= (fftLenBy2
- 2U); i
+= 2U)
205 /* pSrc[i] <-> pSrc[j]; */
206 /* pSrc[i+1U] <-> pSrc[j+1U] */
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
;
218 /* pSrc[i+1U] <-> pSrc[j+fftLenBy2]; */
219 /* pSrc[i+2] <-> pSrc[j+fftLenBy2+1U] */
221 pSrc
[i
+ 1U] = pSrc
[j
+ fftLenBy2
];
222 pSrc
[j
+ fftLenBy2
] = in
;
224 /* Reading the index for the bit reversal */
227 /* Updating the bit reversal index depending on the fft length */
228 pBitRevTab
+= bitRevFactor
;