Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /* ---------------------------------------------------------------------- |
| 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. |
||
| 3 | * |
||
| 4 | * $Date: 19. March 2015 |
||
| 5 | * $Revision: V.1.4.5 |
||
| 6 | * |
||
| 7 | * Project: CMSIS DSP Library |
||
| 8 | * Title: arm_bitreversal.c |
||
| 9 | * |
||
| 10 | * Description: This file has common tables like Bitreverse, reciprocal etc which are used across different functions |
||
| 11 | * |
||
| 12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 |
||
| 13 | * |
||
| 14 | * Redistribution and use in source and binary forms, with or without |
||
| 15 | * modification, are permitted provided that the following conditions |
||
| 16 | * are met: |
||
| 17 | * - Redistributions of source code must retain the above copyright |
||
| 18 | * notice, this list of conditions and the following disclaimer. |
||
| 19 | * - Redistributions in binary form must reproduce the above copyright |
||
| 20 | * notice, this list of conditions and the following disclaimer in |
||
| 21 | * the documentation and/or other materials provided with the |
||
| 22 | * distribution. |
||
| 23 | * - Neither the name of ARM LIMITED nor the names of its contributors |
||
| 24 | * may be used to endorse or promote products derived from this |
||
| 25 | * software without specific prior written permission. |
||
| 26 | * |
||
| 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||
| 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||
| 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
||
| 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
||
| 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
| 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
||
| 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
| 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||
| 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||
| 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
||
| 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
| 38 | * POSSIBILITY OF SUCH DAMAGE. |
||
| 39 | * -------------------------------------------------------------------- */ |
||
| 40 | |||
| 41 | #include "arm_math.h" |
||
| 42 | #include "arm_common_tables.h" |
||
| 43 | |||
| 44 | /* |
||
| 45 | * @brief In-place bit reversal function. |
||
| 46 | * @param[in, out] *pSrc points to the in-place buffer of floating-point data type. |
||
| 47 | * @param[in] fftSize length of the FFT. |
||
| 48 | * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table. |
||
| 49 | * @param[in] *pBitRevTab points to the bit reversal table. |
||
| 50 | * @return none. |
||
| 51 | */ |
||
| 52 | |||
| 53 | void arm_bitreversal_f32( |
||
| 54 | float32_t * pSrc, |
||
| 55 | uint16_t fftSize, |
||
| 56 | uint16_t bitRevFactor, |
||
| 57 | uint16_t * pBitRevTab) |
||
| 58 | { |
||
| 59 | uint16_t fftLenBy2, fftLenBy2p1; |
||
| 60 | uint16_t i, j; |
||
| 61 | float32_t in; |
||
| 62 | |||
| 63 | /* Initializations */ |
||
| 64 | j = 0u; |
||
| 65 | fftLenBy2 = fftSize >> 1u; |
||
| 66 | fftLenBy2p1 = (fftSize >> 1u) + 1u; |
||
| 67 | |||
| 68 | /* Bit Reversal Implementation */ |
||
| 69 | for (i = 0u; i <= (fftLenBy2 - 2u); i += 2u) |
||
| 70 | { |
||
| 71 | if(i < j) |
||
| 72 | { |
||
| 73 | /* pSrc[i] <-> pSrc[j]; */ |
||
| 74 | in = pSrc[2u * i]; |
||
| 75 | pSrc[2u * i] = pSrc[2u * j]; |
||
| 76 | pSrc[2u * j] = in; |
||
| 77 | |||
| 78 | /* pSrc[i+1u] <-> pSrc[j+1u] */ |
||
| 79 | in = pSrc[(2u * i) + 1u]; |
||
| 80 | pSrc[(2u * i) + 1u] = pSrc[(2u * j) + 1u]; |
||
| 81 | pSrc[(2u * j) + 1u] = in; |
||
| 82 | |||
| 83 | /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */ |
||
| 84 | in = pSrc[2u * (i + fftLenBy2p1)]; |
||
| 85 | pSrc[2u * (i + fftLenBy2p1)] = pSrc[2u * (j + fftLenBy2p1)]; |
||
| 86 | pSrc[2u * (j + fftLenBy2p1)] = in; |
||
| 87 | |||
| 88 | /* pSrc[i+fftLenBy2p1+1u] <-> pSrc[j+fftLenBy2p1+1u] */ |
||
| 89 | in = pSrc[(2u * (i + fftLenBy2p1)) + 1u]; |
||
| 90 | pSrc[(2u * (i + fftLenBy2p1)) + 1u] = |
||
| 91 | pSrc[(2u * (j + fftLenBy2p1)) + 1u]; |
||
| 92 | pSrc[(2u * (j + fftLenBy2p1)) + 1u] = in; |
||
| 93 | |||
| 94 | } |
||
| 95 | |||
| 96 | /* pSrc[i+1u] <-> pSrc[j+1u] */ |
||
| 97 | in = pSrc[2u * (i + 1u)]; |
||
| 98 | pSrc[2u * (i + 1u)] = pSrc[2u * (j + fftLenBy2)]; |
||
| 99 | pSrc[2u * (j + fftLenBy2)] = in; |
||
| 100 | |||
| 101 | /* pSrc[i+2u] <-> pSrc[j+2u] */ |
||
| 102 | in = pSrc[(2u * (i + 1u)) + 1u]; |
||
| 103 | pSrc[(2u * (i + 1u)) + 1u] = pSrc[(2u * (j + fftLenBy2)) + 1u]; |
||
| 104 | pSrc[(2u * (j + fftLenBy2)) + 1u] = in; |
||
| 105 | |||
| 106 | /* Reading the index for the bit reversal */ |
||
| 107 | j = *pBitRevTab; |
||
| 108 | |||
| 109 | /* Updating the bit reversal index depending on the fft length */ |
||
| 110 | pBitRevTab += bitRevFactor; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | |||
| 115 | |||
| 116 | /* |
||
| 117 | * @brief In-place bit reversal function. |
||
| 118 | * @param[in, out] *pSrc points to the in-place buffer of Q31 data type. |
||
| 119 | * @param[in] fftLen length of the FFT. |
||
| 120 | * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table |
||
| 121 | * @param[in] *pBitRevTab points to bit reversal table. |
||
| 122 | * @return none. |
||
| 123 | */ |
||
| 124 | |||
| 125 | void arm_bitreversal_q31( |
||
| 126 | q31_t * pSrc, |
||
| 127 | uint32_t fftLen, |
||
| 128 | uint16_t bitRevFactor, |
||
| 129 | uint16_t * pBitRevTable) |
||
| 130 | { |
||
| 131 | uint32_t fftLenBy2, fftLenBy2p1, i, j; |
||
| 132 | q31_t in; |
||
| 133 | |||
| 134 | /* Initializations */ |
||
| 135 | j = 0u; |
||
| 136 | fftLenBy2 = fftLen / 2u; |
||
| 137 | fftLenBy2p1 = (fftLen / 2u) + 1u; |
||
| 138 | |||
| 139 | /* Bit Reversal Implementation */ |
||
| 140 | for (i = 0u; i <= (fftLenBy2 - 2u); i += 2u) |
||
| 141 | { |
||
| 142 | if(i < j) |
||
| 143 | { |
||
| 144 | /* pSrc[i] <-> pSrc[j]; */ |
||
| 145 | in = pSrc[2u * i]; |
||
| 146 | pSrc[2u * i] = pSrc[2u * j]; |
||
| 147 | pSrc[2u * j] = in; |
||
| 148 | |||
| 149 | /* pSrc[i+1u] <-> pSrc[j+1u] */ |
||
| 150 | in = pSrc[(2u * i) + 1u]; |
||
| 151 | pSrc[(2u * i) + 1u] = pSrc[(2u * j) + 1u]; |
||
| 152 | pSrc[(2u * j) + 1u] = in; |
||
| 153 | |||
| 154 | /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */ |
||
| 155 | in = pSrc[2u * (i + fftLenBy2p1)]; |
||
| 156 | pSrc[2u * (i + fftLenBy2p1)] = pSrc[2u * (j + fftLenBy2p1)]; |
||
| 157 | pSrc[2u * (j + fftLenBy2p1)] = in; |
||
| 158 | |||
| 159 | /* pSrc[i+fftLenBy2p1+1u] <-> pSrc[j+fftLenBy2p1+1u] */ |
||
| 160 | in = pSrc[(2u * (i + fftLenBy2p1)) + 1u]; |
||
| 161 | pSrc[(2u * (i + fftLenBy2p1)) + 1u] = |
||
| 162 | pSrc[(2u * (j + fftLenBy2p1)) + 1u]; |
||
| 163 | pSrc[(2u * (j + fftLenBy2p1)) + 1u] = in; |
||
| 164 | |||
| 165 | } |
||
| 166 | |||
| 167 | /* pSrc[i+1u] <-> pSrc[j+1u] */ |
||
| 168 | in = pSrc[2u * (i + 1u)]; |
||
| 169 | pSrc[2u * (i + 1u)] = pSrc[2u * (j + fftLenBy2)]; |
||
| 170 | pSrc[2u * (j + fftLenBy2)] = in; |
||
| 171 | |||
| 172 | /* pSrc[i+2u] <-> pSrc[j+2u] */ |
||
| 173 | in = pSrc[(2u * (i + 1u)) + 1u]; |
||
| 174 | pSrc[(2u * (i + 1u)) + 1u] = pSrc[(2u * (j + fftLenBy2)) + 1u]; |
||
| 175 | pSrc[(2u * (j + fftLenBy2)) + 1u] = in; |
||
| 176 | |||
| 177 | /* Reading the index for the bit reversal */ |
||
| 178 | j = *pBitRevTable; |
||
| 179 | |||
| 180 | /* Updating the bit reversal index depending on the fft length */ |
||
| 181 | pBitRevTable += bitRevFactor; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | |||
| 185 | |||
| 186 | |||
| 187 | /* |
||
| 188 | * @brief In-place bit reversal function. |
||
| 189 | * @param[in, out] *pSrc points to the in-place buffer of Q15 data type. |
||
| 190 | * @param[in] fftLen length of the FFT. |
||
| 191 | * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table |
||
| 192 | * @param[in] *pBitRevTab points to bit reversal table. |
||
| 193 | * @return none. |
||
| 194 | */ |
||
| 195 | |||
| 196 | void arm_bitreversal_q15( |
||
| 197 | q15_t * pSrc16, |
||
| 198 | uint32_t fftLen, |
||
| 199 | uint16_t bitRevFactor, |
||
| 200 | uint16_t * pBitRevTab) |
||
| 201 | { |
||
| 202 | q31_t *pSrc = (q31_t *) pSrc16; |
||
| 203 | q31_t in; |
||
| 204 | uint32_t fftLenBy2, fftLenBy2p1; |
||
| 205 | uint32_t i, j; |
||
| 206 | |||
| 207 | /* Initializations */ |
||
| 208 | j = 0u; |
||
| 209 | fftLenBy2 = fftLen / 2u; |
||
| 210 | fftLenBy2p1 = (fftLen / 2u) + 1u; |
||
| 211 | |||
| 212 | /* Bit Reversal Implementation */ |
||
| 213 | for (i = 0u; i <= (fftLenBy2 - 2u); i += 2u) |
||
| 214 | { |
||
| 215 | if(i < j) |
||
| 216 | { |
||
| 217 | /* pSrc[i] <-> pSrc[j]; */ |
||
| 218 | /* pSrc[i+1u] <-> pSrc[j+1u] */ |
||
| 219 | in = pSrc[i]; |
||
| 220 | pSrc[i] = pSrc[j]; |
||
| 221 | pSrc[j] = in; |
||
| 222 | |||
| 223 | /* pSrc[i + fftLenBy2p1] <-> pSrc[j + fftLenBy2p1]; */ |
||
| 224 | /* pSrc[i + fftLenBy2p1+1u] <-> pSrc[j + fftLenBy2p1+1u] */ |
||
| 225 | in = pSrc[i + fftLenBy2p1]; |
||
| 226 | pSrc[i + fftLenBy2p1] = pSrc[j + fftLenBy2p1]; |
||
| 227 | pSrc[j + fftLenBy2p1] = in; |
||
| 228 | } |
||
| 229 | |||
| 230 | /* pSrc[i+1u] <-> pSrc[j+fftLenBy2]; */ |
||
| 231 | /* pSrc[i+2] <-> pSrc[j+fftLenBy2+1u] */ |
||
| 232 | in = pSrc[i + 1u]; |
||
| 233 | pSrc[i + 1u] = pSrc[j + fftLenBy2]; |
||
| 234 | pSrc[j + fftLenBy2] = in; |
||
| 235 | |||
| 236 | /* Reading the index for the bit reversal */ |
||
| 237 | j = *pBitRevTab; |
||
| 238 | |||
| 239 | /* Updating the bit reversal index depending on the fft length */ |
||
| 240 | pBitRevTab += bitRevFactor; |
||
| 241 | } |
||
| 242 | } |