Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / CMSIS / DSP / Source / TransformFunctions / arm_bitreversal.c
blobcea48212ad412b1915ac789286a4325aef470b9d
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_bitreversal.c
4 * Description: Bitreversal functions
6 * $Date: 27. January 2017
7 * $Revision: V.1.5.1
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.
29 #include "arm_math.h"
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.
38 * @return none.
41 void arm_bitreversal_f32(
42 float32_t * pSrc,
43 uint16_t fftSize,
44 uint16_t bitRevFactor,
45 uint16_t * pBitRevTab)
47 uint16_t fftLenBy2, fftLenBy2p1;
48 uint16_t i, j;
49 float32_t in;
51 /* Initializations */
52 j = 0U;
53 fftLenBy2 = fftSize >> 1U;
54 fftLenBy2p1 = (fftSize >> 1U) + 1U;
56 /* Bit Reversal Implementation */
57 for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U)
59 if (i < j)
61 /* pSrc[i] <-> pSrc[j]; */
62 in = pSrc[2U * i];
63 pSrc[2U * i] = pSrc[2U * j];
64 pSrc[2U * j] = in;
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 */
95 j = *pBitRevTab;
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.
110 * @return none.
113 void arm_bitreversal_q31(
114 q31_t * pSrc,
115 uint32_t fftLen,
116 uint16_t bitRevFactor,
117 uint16_t * pBitRevTable)
119 uint32_t fftLenBy2, fftLenBy2p1, i, j;
120 q31_t in;
122 /* Initializations */
123 j = 0U;
124 fftLenBy2 = fftLen / 2U;
125 fftLenBy2p1 = (fftLen / 2U) + 1U;
127 /* Bit Reversal Implementation */
128 for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U)
130 if (i < j)
132 /* pSrc[i] <-> pSrc[j]; */
133 in = pSrc[2U * i];
134 pSrc[2U * i] = pSrc[2U * j];
135 pSrc[2U * j] = in;
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 */
166 j = *pBitRevTable;
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.
181 * @return none.
184 void arm_bitreversal_q15(
185 q15_t * pSrc16,
186 uint32_t fftLen,
187 uint16_t bitRevFactor,
188 uint16_t * pBitRevTab)
190 q31_t *pSrc = (q31_t *) pSrc16;
191 q31_t in;
192 uint32_t fftLenBy2, fftLenBy2p1;
193 uint32_t i, j;
195 /* Initializations */
196 j = 0U;
197 fftLenBy2 = fftLen / 2U;
198 fftLenBy2p1 = (fftLen / 2U) + 1U;
200 /* Bit Reversal Implementation */
201 for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U)
203 if (i < j)
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;
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] */
220 in = pSrc[i + 1U];
221 pSrc[i + 1U] = pSrc[j + fftLenBy2];
222 pSrc[j + fftLenBy2] = in;
224 /* Reading the index for the bit reversal */
225 j = *pBitRevTab;
227 /* Updating the bit reversal index depending on the fft length */
228 pBitRevTab += bitRevFactor;