The CMSIS DSP 5 library
Dependents: Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more
functions/TransformFunctions/arm_bitreversal.c@3:4098b9d3d571, 2018-06-21 (annotated)
- Committer:
- xorjoep
- Date:
- Thu Jun 21 11:56:27 2018 +0000
- Revision:
- 3:4098b9d3d571
- Parent:
- 1:24714b45cd1b
headers is a folder not a library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xorjoep | 1:24714b45cd1b | 1 | /* ---------------------------------------------------------------------- |
xorjoep | 1:24714b45cd1b | 2 | * Project: CMSIS DSP Library |
xorjoep | 1:24714b45cd1b | 3 | * Title: arm_bitreversal.c |
xorjoep | 1:24714b45cd1b | 4 | * Description: Bitreversal functions |
xorjoep | 1:24714b45cd1b | 5 | * |
xorjoep | 1:24714b45cd1b | 6 | * $Date: 27. January 2017 |
xorjoep | 1:24714b45cd1b | 7 | * $Revision: V.1.5.1 |
xorjoep | 1:24714b45cd1b | 8 | * |
xorjoep | 1:24714b45cd1b | 9 | * Target Processor: Cortex-M cores |
xorjoep | 1:24714b45cd1b | 10 | * -------------------------------------------------------------------- */ |
xorjoep | 1:24714b45cd1b | 11 | /* |
xorjoep | 1:24714b45cd1b | 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. |
xorjoep | 1:24714b45cd1b | 13 | * |
xorjoep | 1:24714b45cd1b | 14 | * SPDX-License-Identifier: Apache-2.0 |
xorjoep | 1:24714b45cd1b | 15 | * |
xorjoep | 1:24714b45cd1b | 16 | * Licensed under the Apache License, Version 2.0 (the License); you may |
xorjoep | 1:24714b45cd1b | 17 | * not use this file except in compliance with the License. |
xorjoep | 1:24714b45cd1b | 18 | * You may obtain a copy of the License at |
xorjoep | 1:24714b45cd1b | 19 | * |
xorjoep | 1:24714b45cd1b | 20 | * www.apache.org/licenses/LICENSE-2.0 |
xorjoep | 1:24714b45cd1b | 21 | * |
xorjoep | 1:24714b45cd1b | 22 | * Unless required by applicable law or agreed to in writing, software |
xorjoep | 1:24714b45cd1b | 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
xorjoep | 1:24714b45cd1b | 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
xorjoep | 1:24714b45cd1b | 25 | * See the License for the specific language governing permissions and |
xorjoep | 1:24714b45cd1b | 26 | * limitations under the License. |
xorjoep | 1:24714b45cd1b | 27 | */ |
xorjoep | 1:24714b45cd1b | 28 | |
xorjoep | 1:24714b45cd1b | 29 | #include "arm_math.h" |
xorjoep | 1:24714b45cd1b | 30 | #include "arm_common_tables.h" |
xorjoep | 1:24714b45cd1b | 31 | |
xorjoep | 1:24714b45cd1b | 32 | /* |
xorjoep | 1:24714b45cd1b | 33 | * @brief In-place bit reversal function. |
xorjoep | 1:24714b45cd1b | 34 | * @param[in, out] *pSrc points to the in-place buffer of floating-point data type. |
xorjoep | 1:24714b45cd1b | 35 | * @param[in] fftSize length of the FFT. |
xorjoep | 1:24714b45cd1b | 36 | * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table. |
xorjoep | 1:24714b45cd1b | 37 | * @param[in] *pBitRevTab points to the bit reversal table. |
xorjoep | 1:24714b45cd1b | 38 | * @return none. |
xorjoep | 1:24714b45cd1b | 39 | */ |
xorjoep | 1:24714b45cd1b | 40 | |
xorjoep | 1:24714b45cd1b | 41 | void arm_bitreversal_f32( |
xorjoep | 1:24714b45cd1b | 42 | float32_t * pSrc, |
xorjoep | 1:24714b45cd1b | 43 | uint16_t fftSize, |
xorjoep | 1:24714b45cd1b | 44 | uint16_t bitRevFactor, |
xorjoep | 1:24714b45cd1b | 45 | uint16_t * pBitRevTab) |
xorjoep | 1:24714b45cd1b | 46 | { |
xorjoep | 1:24714b45cd1b | 47 | uint16_t fftLenBy2, fftLenBy2p1; |
xorjoep | 1:24714b45cd1b | 48 | uint16_t i, j; |
xorjoep | 1:24714b45cd1b | 49 | float32_t in; |
xorjoep | 1:24714b45cd1b | 50 | |
xorjoep | 1:24714b45cd1b | 51 | /* Initializations */ |
xorjoep | 1:24714b45cd1b | 52 | j = 0U; |
xorjoep | 1:24714b45cd1b | 53 | fftLenBy2 = fftSize >> 1U; |
xorjoep | 1:24714b45cd1b | 54 | fftLenBy2p1 = (fftSize >> 1U) + 1U; |
xorjoep | 1:24714b45cd1b | 55 | |
xorjoep | 1:24714b45cd1b | 56 | /* Bit Reversal Implementation */ |
xorjoep | 1:24714b45cd1b | 57 | for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U) |
xorjoep | 1:24714b45cd1b | 58 | { |
xorjoep | 1:24714b45cd1b | 59 | if (i < j) |
xorjoep | 1:24714b45cd1b | 60 | { |
xorjoep | 1:24714b45cd1b | 61 | /* pSrc[i] <-> pSrc[j]; */ |
xorjoep | 1:24714b45cd1b | 62 | in = pSrc[2U * i]; |
xorjoep | 1:24714b45cd1b | 63 | pSrc[2U * i] = pSrc[2U * j]; |
xorjoep | 1:24714b45cd1b | 64 | pSrc[2U * j] = in; |
xorjoep | 1:24714b45cd1b | 65 | |
xorjoep | 1:24714b45cd1b | 66 | /* pSrc[i+1U] <-> pSrc[j+1U] */ |
xorjoep | 1:24714b45cd1b | 67 | in = pSrc[(2U * i) + 1U]; |
xorjoep | 1:24714b45cd1b | 68 | pSrc[(2U * i) + 1U] = pSrc[(2U * j) + 1U]; |
xorjoep | 1:24714b45cd1b | 69 | pSrc[(2U * j) + 1U] = in; |
xorjoep | 1:24714b45cd1b | 70 | |
xorjoep | 1:24714b45cd1b | 71 | /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */ |
xorjoep | 1:24714b45cd1b | 72 | in = pSrc[2U * (i + fftLenBy2p1)]; |
xorjoep | 1:24714b45cd1b | 73 | pSrc[2U * (i + fftLenBy2p1)] = pSrc[2U * (j + fftLenBy2p1)]; |
xorjoep | 1:24714b45cd1b | 74 | pSrc[2U * (j + fftLenBy2p1)] = in; |
xorjoep | 1:24714b45cd1b | 75 | |
xorjoep | 1:24714b45cd1b | 76 | /* pSrc[i+fftLenBy2p1+1U] <-> pSrc[j+fftLenBy2p1+1U] */ |
xorjoep | 1:24714b45cd1b | 77 | in = pSrc[(2U * (i + fftLenBy2p1)) + 1U]; |
xorjoep | 1:24714b45cd1b | 78 | pSrc[(2U * (i + fftLenBy2p1)) + 1U] = |
xorjoep | 1:24714b45cd1b | 79 | pSrc[(2U * (j + fftLenBy2p1)) + 1U]; |
xorjoep | 1:24714b45cd1b | 80 | pSrc[(2U * (j + fftLenBy2p1)) + 1U] = in; |
xorjoep | 1:24714b45cd1b | 81 | |
xorjoep | 1:24714b45cd1b | 82 | } |
xorjoep | 1:24714b45cd1b | 83 | |
xorjoep | 1:24714b45cd1b | 84 | /* pSrc[i+1U] <-> pSrc[j+1U] */ |
xorjoep | 1:24714b45cd1b | 85 | in = pSrc[2U * (i + 1U)]; |
xorjoep | 1:24714b45cd1b | 86 | pSrc[2U * (i + 1U)] = pSrc[2U * (j + fftLenBy2)]; |
xorjoep | 1:24714b45cd1b | 87 | pSrc[2U * (j + fftLenBy2)] = in; |
xorjoep | 1:24714b45cd1b | 88 | |
xorjoep | 1:24714b45cd1b | 89 | /* pSrc[i+2U] <-> pSrc[j+2U] */ |
xorjoep | 1:24714b45cd1b | 90 | in = pSrc[(2U * (i + 1U)) + 1U]; |
xorjoep | 1:24714b45cd1b | 91 | pSrc[(2U * (i + 1U)) + 1U] = pSrc[(2U * (j + fftLenBy2)) + 1U]; |
xorjoep | 1:24714b45cd1b | 92 | pSrc[(2U * (j + fftLenBy2)) + 1U] = in; |
xorjoep | 1:24714b45cd1b | 93 | |
xorjoep | 1:24714b45cd1b | 94 | /* Reading the index for the bit reversal */ |
xorjoep | 1:24714b45cd1b | 95 | j = *pBitRevTab; |
xorjoep | 1:24714b45cd1b | 96 | |
xorjoep | 1:24714b45cd1b | 97 | /* Updating the bit reversal index depending on the fft length */ |
xorjoep | 1:24714b45cd1b | 98 | pBitRevTab += bitRevFactor; |
xorjoep | 1:24714b45cd1b | 99 | } |
xorjoep | 1:24714b45cd1b | 100 | } |
xorjoep | 1:24714b45cd1b | 101 | |
xorjoep | 1:24714b45cd1b | 102 | |
xorjoep | 1:24714b45cd1b | 103 | |
xorjoep | 1:24714b45cd1b | 104 | /* |
xorjoep | 1:24714b45cd1b | 105 | * @brief In-place bit reversal function. |
xorjoep | 1:24714b45cd1b | 106 | * @param[in, out] *pSrc points to the in-place buffer of Q31 data type. |
xorjoep | 1:24714b45cd1b | 107 | * @param[in] fftLen length of the FFT. |
xorjoep | 1:24714b45cd1b | 108 | * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table |
xorjoep | 1:24714b45cd1b | 109 | * @param[in] *pBitRevTab points to bit reversal table. |
xorjoep | 1:24714b45cd1b | 110 | * @return none. |
xorjoep | 1:24714b45cd1b | 111 | */ |
xorjoep | 1:24714b45cd1b | 112 | |
xorjoep | 1:24714b45cd1b | 113 | void arm_bitreversal_q31( |
xorjoep | 1:24714b45cd1b | 114 | q31_t * pSrc, |
xorjoep | 1:24714b45cd1b | 115 | uint32_t fftLen, |
xorjoep | 1:24714b45cd1b | 116 | uint16_t bitRevFactor, |
xorjoep | 1:24714b45cd1b | 117 | uint16_t * pBitRevTable) |
xorjoep | 1:24714b45cd1b | 118 | { |
xorjoep | 1:24714b45cd1b | 119 | uint32_t fftLenBy2, fftLenBy2p1, i, j; |
xorjoep | 1:24714b45cd1b | 120 | q31_t in; |
xorjoep | 1:24714b45cd1b | 121 | |
xorjoep | 1:24714b45cd1b | 122 | /* Initializations */ |
xorjoep | 1:24714b45cd1b | 123 | j = 0U; |
xorjoep | 1:24714b45cd1b | 124 | fftLenBy2 = fftLen / 2U; |
xorjoep | 1:24714b45cd1b | 125 | fftLenBy2p1 = (fftLen / 2U) + 1U; |
xorjoep | 1:24714b45cd1b | 126 | |
xorjoep | 1:24714b45cd1b | 127 | /* Bit Reversal Implementation */ |
xorjoep | 1:24714b45cd1b | 128 | for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U) |
xorjoep | 1:24714b45cd1b | 129 | { |
xorjoep | 1:24714b45cd1b | 130 | if (i < j) |
xorjoep | 1:24714b45cd1b | 131 | { |
xorjoep | 1:24714b45cd1b | 132 | /* pSrc[i] <-> pSrc[j]; */ |
xorjoep | 1:24714b45cd1b | 133 | in = pSrc[2U * i]; |
xorjoep | 1:24714b45cd1b | 134 | pSrc[2U * i] = pSrc[2U * j]; |
xorjoep | 1:24714b45cd1b | 135 | pSrc[2U * j] = in; |
xorjoep | 1:24714b45cd1b | 136 | |
xorjoep | 1:24714b45cd1b | 137 | /* pSrc[i+1U] <-> pSrc[j+1U] */ |
xorjoep | 1:24714b45cd1b | 138 | in = pSrc[(2U * i) + 1U]; |
xorjoep | 1:24714b45cd1b | 139 | pSrc[(2U * i) + 1U] = pSrc[(2U * j) + 1U]; |
xorjoep | 1:24714b45cd1b | 140 | pSrc[(2U * j) + 1U] = in; |
xorjoep | 1:24714b45cd1b | 141 | |
xorjoep | 1:24714b45cd1b | 142 | /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */ |
xorjoep | 1:24714b45cd1b | 143 | in = pSrc[2U * (i + fftLenBy2p1)]; |
xorjoep | 1:24714b45cd1b | 144 | pSrc[2U * (i + fftLenBy2p1)] = pSrc[2U * (j + fftLenBy2p1)]; |
xorjoep | 1:24714b45cd1b | 145 | pSrc[2U * (j + fftLenBy2p1)] = in; |
xorjoep | 1:24714b45cd1b | 146 | |
xorjoep | 1:24714b45cd1b | 147 | /* pSrc[i+fftLenBy2p1+1U] <-> pSrc[j+fftLenBy2p1+1U] */ |
xorjoep | 1:24714b45cd1b | 148 | in = pSrc[(2U * (i + fftLenBy2p1)) + 1U]; |
xorjoep | 1:24714b45cd1b | 149 | pSrc[(2U * (i + fftLenBy2p1)) + 1U] = |
xorjoep | 1:24714b45cd1b | 150 | pSrc[(2U * (j + fftLenBy2p1)) + 1U]; |
xorjoep | 1:24714b45cd1b | 151 | pSrc[(2U * (j + fftLenBy2p1)) + 1U] = in; |
xorjoep | 1:24714b45cd1b | 152 | |
xorjoep | 1:24714b45cd1b | 153 | } |
xorjoep | 1:24714b45cd1b | 154 | |
xorjoep | 1:24714b45cd1b | 155 | /* pSrc[i+1U] <-> pSrc[j+1U] */ |
xorjoep | 1:24714b45cd1b | 156 | in = pSrc[2U * (i + 1U)]; |
xorjoep | 1:24714b45cd1b | 157 | pSrc[2U * (i + 1U)] = pSrc[2U * (j + fftLenBy2)]; |
xorjoep | 1:24714b45cd1b | 158 | pSrc[2U * (j + fftLenBy2)] = in; |
xorjoep | 1:24714b45cd1b | 159 | |
xorjoep | 1:24714b45cd1b | 160 | /* pSrc[i+2U] <-> pSrc[j+2U] */ |
xorjoep | 1:24714b45cd1b | 161 | in = pSrc[(2U * (i + 1U)) + 1U]; |
xorjoep | 1:24714b45cd1b | 162 | pSrc[(2U * (i + 1U)) + 1U] = pSrc[(2U * (j + fftLenBy2)) + 1U]; |
xorjoep | 1:24714b45cd1b | 163 | pSrc[(2U * (j + fftLenBy2)) + 1U] = in; |
xorjoep | 1:24714b45cd1b | 164 | |
xorjoep | 1:24714b45cd1b | 165 | /* Reading the index for the bit reversal */ |
xorjoep | 1:24714b45cd1b | 166 | j = *pBitRevTable; |
xorjoep | 1:24714b45cd1b | 167 | |
xorjoep | 1:24714b45cd1b | 168 | /* Updating the bit reversal index depending on the fft length */ |
xorjoep | 1:24714b45cd1b | 169 | pBitRevTable += bitRevFactor; |
xorjoep | 1:24714b45cd1b | 170 | } |
xorjoep | 1:24714b45cd1b | 171 | } |
xorjoep | 1:24714b45cd1b | 172 | |
xorjoep | 1:24714b45cd1b | 173 | |
xorjoep | 1:24714b45cd1b | 174 | |
xorjoep | 1:24714b45cd1b | 175 | /* |
xorjoep | 1:24714b45cd1b | 176 | * @brief In-place bit reversal function. |
xorjoep | 1:24714b45cd1b | 177 | * @param[in, out] *pSrc points to the in-place buffer of Q15 data type. |
xorjoep | 1:24714b45cd1b | 178 | * @param[in] fftLen length of the FFT. |
xorjoep | 1:24714b45cd1b | 179 | * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table |
xorjoep | 1:24714b45cd1b | 180 | * @param[in] *pBitRevTab points to bit reversal table. |
xorjoep | 1:24714b45cd1b | 181 | * @return none. |
xorjoep | 1:24714b45cd1b | 182 | */ |
xorjoep | 1:24714b45cd1b | 183 | |
xorjoep | 1:24714b45cd1b | 184 | void arm_bitreversal_q15( |
xorjoep | 1:24714b45cd1b | 185 | q15_t * pSrc16, |
xorjoep | 1:24714b45cd1b | 186 | uint32_t fftLen, |
xorjoep | 1:24714b45cd1b | 187 | uint16_t bitRevFactor, |
xorjoep | 1:24714b45cd1b | 188 | uint16_t * pBitRevTab) |
xorjoep | 1:24714b45cd1b | 189 | { |
xorjoep | 1:24714b45cd1b | 190 | q31_t *pSrc = (q31_t *) pSrc16; |
xorjoep | 1:24714b45cd1b | 191 | q31_t in; |
xorjoep | 1:24714b45cd1b | 192 | uint32_t fftLenBy2, fftLenBy2p1; |
xorjoep | 1:24714b45cd1b | 193 | uint32_t i, j; |
xorjoep | 1:24714b45cd1b | 194 | |
xorjoep | 1:24714b45cd1b | 195 | /* Initializations */ |
xorjoep | 1:24714b45cd1b | 196 | j = 0U; |
xorjoep | 1:24714b45cd1b | 197 | fftLenBy2 = fftLen / 2U; |
xorjoep | 1:24714b45cd1b | 198 | fftLenBy2p1 = (fftLen / 2U) + 1U; |
xorjoep | 1:24714b45cd1b | 199 | |
xorjoep | 1:24714b45cd1b | 200 | /* Bit Reversal Implementation */ |
xorjoep | 1:24714b45cd1b | 201 | for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U) |
xorjoep | 1:24714b45cd1b | 202 | { |
xorjoep | 1:24714b45cd1b | 203 | if (i < j) |
xorjoep | 1:24714b45cd1b | 204 | { |
xorjoep | 1:24714b45cd1b | 205 | /* pSrc[i] <-> pSrc[j]; */ |
xorjoep | 1:24714b45cd1b | 206 | /* pSrc[i+1U] <-> pSrc[j+1U] */ |
xorjoep | 1:24714b45cd1b | 207 | in = pSrc[i]; |
xorjoep | 1:24714b45cd1b | 208 | pSrc[i] = pSrc[j]; |
xorjoep | 1:24714b45cd1b | 209 | pSrc[j] = in; |
xorjoep | 1:24714b45cd1b | 210 | |
xorjoep | 1:24714b45cd1b | 211 | /* pSrc[i + fftLenBy2p1] <-> pSrc[j + fftLenBy2p1]; */ |
xorjoep | 1:24714b45cd1b | 212 | /* pSrc[i + fftLenBy2p1+1U] <-> pSrc[j + fftLenBy2p1+1U] */ |
xorjoep | 1:24714b45cd1b | 213 | in = pSrc[i + fftLenBy2p1]; |
xorjoep | 1:24714b45cd1b | 214 | pSrc[i + fftLenBy2p1] = pSrc[j + fftLenBy2p1]; |
xorjoep | 1:24714b45cd1b | 215 | pSrc[j + fftLenBy2p1] = in; |
xorjoep | 1:24714b45cd1b | 216 | } |
xorjoep | 1:24714b45cd1b | 217 | |
xorjoep | 1:24714b45cd1b | 218 | /* pSrc[i+1U] <-> pSrc[j+fftLenBy2]; */ |
xorjoep | 1:24714b45cd1b | 219 | /* pSrc[i+2] <-> pSrc[j+fftLenBy2+1U] */ |
xorjoep | 1:24714b45cd1b | 220 | in = pSrc[i + 1U]; |
xorjoep | 1:24714b45cd1b | 221 | pSrc[i + 1U] = pSrc[j + fftLenBy2]; |
xorjoep | 1:24714b45cd1b | 222 | pSrc[j + fftLenBy2] = in; |
xorjoep | 1:24714b45cd1b | 223 | |
xorjoep | 1:24714b45cd1b | 224 | /* Reading the index for the bit reversal */ |
xorjoep | 1:24714b45cd1b | 225 | j = *pBitRevTab; |
xorjoep | 1:24714b45cd1b | 226 | |
xorjoep | 1:24714b45cd1b | 227 | /* Updating the bit reversal index depending on the fft length */ |
xorjoep | 1:24714b45cd1b | 228 | pBitRevTab += bitRevFactor; |
xorjoep | 1:24714b45cd1b | 229 | } |
xorjoep | 1:24714b45cd1b | 230 | } |