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