CMSIS DSP library

Dependents:   KL25Z_FFT_Demo Hat_Board_v5_1 KL25Z_FFT_Demo_tony KL25Z_FFT_Demo_tony ... more

Fork of mbed-dsp by mbed official

Committer:
mbed_official
Date:
Fri Nov 08 13:45:10 2013 +0000
Revision:
3:7a284390b0ce
Parent:
2:da51fb522205
Synchronized with git revision e69956aba2f68a2a26ac26b051f8d349deaa1ce8

Who changed what in which revision?

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