CMSIS DSP Lib

Fork of mbed-dsp by mbed official

Committer:
emilmont
Date:
Thu May 30 17:10:11 2013 +0100
Revision:
2:da51fb522205
Parent:
1:fdd22bb7aa52
Child:
3:7a284390b0ce
Keep "cmsis-dsp" module in synch with its source

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:fdd22bb7aa52 1 /* ----------------------------------------------------------------------
emilmont 1:fdd22bb7aa52 2 * Copyright (C) 2010 ARM Limited. All rights reserved.
emilmont 1:fdd22bb7aa52 3 *
emilmont 1:fdd22bb7aa52 4 * $Date: 15. February 2012
emilmont 2:da51fb522205 5 * $Revision: V1.1.0
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 *
emilmont 1:fdd22bb7aa52 14 * Version 1.1.0 2012/02/15
emilmont 1:fdd22bb7aa52 15 * Updated with more optimizations, bug fixes and minor API changes.
emilmont 1:fdd22bb7aa52 16 *
emilmont 1:fdd22bb7aa52 17 * Version 1.0.10 2011/7/15
emilmont 1:fdd22bb7aa52 18 * Initial Version
emilmont 1:fdd22bb7aa52 19 * -------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 20
emilmont 1:fdd22bb7aa52 21 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 22 #include "arm_common_tables.h"
emilmont 1:fdd22bb7aa52 23
emilmont 1:fdd22bb7aa52 24 /*
emilmont 1:fdd22bb7aa52 25 * @brief In-place bit reversal function.
emilmont 1:fdd22bb7aa52 26 * @param[in, out] *pSrc points to the in-place buffer of floating-point data type.
emilmont 1:fdd22bb7aa52 27 * @param[in] fftSize length of the FFT.
emilmont 1:fdd22bb7aa52 28 * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table.
emilmont 1:fdd22bb7aa52 29 * @param[in] *pBitRevTab points to the bit reversal table.
emilmont 1:fdd22bb7aa52 30 * @return none.
emilmont 1:fdd22bb7aa52 31 */
emilmont 1:fdd22bb7aa52 32
emilmont 1:fdd22bb7aa52 33 void arm_bitreversal_f32(
emilmont 1:fdd22bb7aa52 34 float32_t * pSrc,
emilmont 1:fdd22bb7aa52 35 uint16_t fftSize,
emilmont 1:fdd22bb7aa52 36 uint16_t bitRevFactor,
emilmont 1:fdd22bb7aa52 37 uint16_t * pBitRevTab)
emilmont 1:fdd22bb7aa52 38 {
emilmont 1:fdd22bb7aa52 39 uint16_t fftLenBy2, fftLenBy2p1;
emilmont 1:fdd22bb7aa52 40 uint16_t i, j;
emilmont 1:fdd22bb7aa52 41 float32_t in;
emilmont 1:fdd22bb7aa52 42
emilmont 1:fdd22bb7aa52 43 /* Initializations */
emilmont 1:fdd22bb7aa52 44 j = 0u;
emilmont 1:fdd22bb7aa52 45 fftLenBy2 = fftSize >> 1u;
emilmont 1:fdd22bb7aa52 46 fftLenBy2p1 = (fftSize >> 1u) + 1u;
emilmont 1:fdd22bb7aa52 47
emilmont 1:fdd22bb7aa52 48 /* Bit Reversal Implementation */
emilmont 1:fdd22bb7aa52 49 for (i = 0u; i <= (fftLenBy2 - 2u); i += 2u)
emilmont 1:fdd22bb7aa52 50 {
emilmont 1:fdd22bb7aa52 51 if(i < j)
emilmont 1:fdd22bb7aa52 52 {
emilmont 1:fdd22bb7aa52 53 /* pSrc[i] <-> pSrc[j]; */
emilmont 1:fdd22bb7aa52 54 in = pSrc[2u * i];
emilmont 1:fdd22bb7aa52 55 pSrc[2u * i] = pSrc[2u * j];
emilmont 1:fdd22bb7aa52 56 pSrc[2u * j] = in;
emilmont 1:fdd22bb7aa52 57
emilmont 1:fdd22bb7aa52 58 /* pSrc[i+1u] <-> pSrc[j+1u] */
emilmont 1:fdd22bb7aa52 59 in = pSrc[(2u * i) + 1u];
emilmont 1:fdd22bb7aa52 60 pSrc[(2u * i) + 1u] = pSrc[(2u * j) + 1u];
emilmont 1:fdd22bb7aa52 61 pSrc[(2u * j) + 1u] = in;
emilmont 1:fdd22bb7aa52 62
emilmont 1:fdd22bb7aa52 63 /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */
emilmont 1:fdd22bb7aa52 64 in = pSrc[2u * (i + fftLenBy2p1)];
emilmont 1:fdd22bb7aa52 65 pSrc[2u * (i + fftLenBy2p1)] = pSrc[2u * (j + fftLenBy2p1)];
emilmont 1:fdd22bb7aa52 66 pSrc[2u * (j + fftLenBy2p1)] = in;
emilmont 1:fdd22bb7aa52 67
emilmont 1:fdd22bb7aa52 68 /* pSrc[i+fftLenBy2p1+1u] <-> pSrc[j+fftLenBy2p1+1u] */
emilmont 1:fdd22bb7aa52 69 in = pSrc[(2u * (i + fftLenBy2p1)) + 1u];
emilmont 1:fdd22bb7aa52 70 pSrc[(2u * (i + fftLenBy2p1)) + 1u] =
emilmont 1:fdd22bb7aa52 71 pSrc[(2u * (j + fftLenBy2p1)) + 1u];
emilmont 1:fdd22bb7aa52 72 pSrc[(2u * (j + fftLenBy2p1)) + 1u] = in;
emilmont 1:fdd22bb7aa52 73
emilmont 1:fdd22bb7aa52 74 }
emilmont 1:fdd22bb7aa52 75
emilmont 1:fdd22bb7aa52 76 /* pSrc[i+1u] <-> pSrc[j+1u] */
emilmont 1:fdd22bb7aa52 77 in = pSrc[2u * (i + 1u)];
emilmont 1:fdd22bb7aa52 78 pSrc[2u * (i + 1u)] = pSrc[2u * (j + fftLenBy2)];
emilmont 1:fdd22bb7aa52 79 pSrc[2u * (j + fftLenBy2)] = in;
emilmont 1:fdd22bb7aa52 80
emilmont 1:fdd22bb7aa52 81 /* pSrc[i+2u] <-> pSrc[j+2u] */
emilmont 1:fdd22bb7aa52 82 in = pSrc[(2u * (i + 1u)) + 1u];
emilmont 1:fdd22bb7aa52 83 pSrc[(2u * (i + 1u)) + 1u] = pSrc[(2u * (j + fftLenBy2)) + 1u];
emilmont 1:fdd22bb7aa52 84 pSrc[(2u * (j + fftLenBy2)) + 1u] = in;
emilmont 1:fdd22bb7aa52 85
emilmont 1:fdd22bb7aa52 86 /* Reading the index for the bit reversal */
emilmont 1:fdd22bb7aa52 87 j = *pBitRevTab;
emilmont 1:fdd22bb7aa52 88
emilmont 1:fdd22bb7aa52 89 /* Updating the bit reversal index depending on the fft length */
emilmont 1:fdd22bb7aa52 90 pBitRevTab += bitRevFactor;
emilmont 1:fdd22bb7aa52 91 }
emilmont 1:fdd22bb7aa52 92 }
emilmont 1:fdd22bb7aa52 93
emilmont 1:fdd22bb7aa52 94
emilmont 1:fdd22bb7aa52 95
emilmont 1:fdd22bb7aa52 96 /*
emilmont 1:fdd22bb7aa52 97 * @brief In-place bit reversal function.
emilmont 1:fdd22bb7aa52 98 * @param[in, out] *pSrc points to the in-place buffer of Q31 data type.
emilmont 1:fdd22bb7aa52 99 * @param[in] fftLen length of the FFT.
emilmont 1:fdd22bb7aa52 100 * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table
emilmont 1:fdd22bb7aa52 101 * @param[in] *pBitRevTab points to bit reversal table.
emilmont 1:fdd22bb7aa52 102 * @return none.
emilmont 1:fdd22bb7aa52 103 */
emilmont 1:fdd22bb7aa52 104
emilmont 1:fdd22bb7aa52 105 void arm_bitreversal_q31(
emilmont 1:fdd22bb7aa52 106 q31_t * pSrc,
emilmont 1:fdd22bb7aa52 107 uint32_t fftLen,
emilmont 1:fdd22bb7aa52 108 uint16_t bitRevFactor,
emilmont 1:fdd22bb7aa52 109 uint16_t * pBitRevTable)
emilmont 1:fdd22bb7aa52 110 {
emilmont 1:fdd22bb7aa52 111 uint32_t fftLenBy2, fftLenBy2p1, i, j;
emilmont 1:fdd22bb7aa52 112 q31_t in;
emilmont 1:fdd22bb7aa52 113
emilmont 1:fdd22bb7aa52 114 /* Initializations */
emilmont 1:fdd22bb7aa52 115 j = 0u;
emilmont 1:fdd22bb7aa52 116 fftLenBy2 = fftLen / 2u;
emilmont 1:fdd22bb7aa52 117 fftLenBy2p1 = (fftLen / 2u) + 1u;
emilmont 1:fdd22bb7aa52 118
emilmont 1:fdd22bb7aa52 119 /* Bit Reversal Implementation */
emilmont 1:fdd22bb7aa52 120 for (i = 0u; i <= (fftLenBy2 - 2u); i += 2u)
emilmont 1:fdd22bb7aa52 121 {
emilmont 1:fdd22bb7aa52 122 if(i < j)
emilmont 1:fdd22bb7aa52 123 {
emilmont 1:fdd22bb7aa52 124 /* pSrc[i] <-> pSrc[j]; */
emilmont 1:fdd22bb7aa52 125 in = pSrc[2u * i];
emilmont 1:fdd22bb7aa52 126 pSrc[2u * i] = pSrc[2u * j];
emilmont 1:fdd22bb7aa52 127 pSrc[2u * j] = in;
emilmont 1:fdd22bb7aa52 128
emilmont 1:fdd22bb7aa52 129 /* pSrc[i+1u] <-> pSrc[j+1u] */
emilmont 1:fdd22bb7aa52 130 in = pSrc[(2u * i) + 1u];
emilmont 1:fdd22bb7aa52 131 pSrc[(2u * i) + 1u] = pSrc[(2u * j) + 1u];
emilmont 1:fdd22bb7aa52 132 pSrc[(2u * j) + 1u] = in;
emilmont 1:fdd22bb7aa52 133
emilmont 1:fdd22bb7aa52 134 /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */
emilmont 1:fdd22bb7aa52 135 in = pSrc[2u * (i + fftLenBy2p1)];
emilmont 1:fdd22bb7aa52 136 pSrc[2u * (i + fftLenBy2p1)] = pSrc[2u * (j + fftLenBy2p1)];
emilmont 1:fdd22bb7aa52 137 pSrc[2u * (j + fftLenBy2p1)] = in;
emilmont 1:fdd22bb7aa52 138
emilmont 1:fdd22bb7aa52 139 /* pSrc[i+fftLenBy2p1+1u] <-> pSrc[j+fftLenBy2p1+1u] */
emilmont 1:fdd22bb7aa52 140 in = pSrc[(2u * (i + fftLenBy2p1)) + 1u];
emilmont 1:fdd22bb7aa52 141 pSrc[(2u * (i + fftLenBy2p1)) + 1u] =
emilmont 1:fdd22bb7aa52 142 pSrc[(2u * (j + fftLenBy2p1)) + 1u];
emilmont 1:fdd22bb7aa52 143 pSrc[(2u * (j + fftLenBy2p1)) + 1u] = in;
emilmont 1:fdd22bb7aa52 144
emilmont 1:fdd22bb7aa52 145 }
emilmont 1:fdd22bb7aa52 146
emilmont 1:fdd22bb7aa52 147 /* pSrc[i+1u] <-> pSrc[j+1u] */
emilmont 1:fdd22bb7aa52 148 in = pSrc[2u * (i + 1u)];
emilmont 1:fdd22bb7aa52 149 pSrc[2u * (i + 1u)] = pSrc[2u * (j + fftLenBy2)];
emilmont 1:fdd22bb7aa52 150 pSrc[2u * (j + fftLenBy2)] = in;
emilmont 1:fdd22bb7aa52 151
emilmont 1:fdd22bb7aa52 152 /* pSrc[i+2u] <-> pSrc[j+2u] */
emilmont 1:fdd22bb7aa52 153 in = pSrc[(2u * (i + 1u)) + 1u];
emilmont 1:fdd22bb7aa52 154 pSrc[(2u * (i + 1u)) + 1u] = pSrc[(2u * (j + fftLenBy2)) + 1u];
emilmont 1:fdd22bb7aa52 155 pSrc[(2u * (j + fftLenBy2)) + 1u] = in;
emilmont 1:fdd22bb7aa52 156
emilmont 1:fdd22bb7aa52 157 /* Reading the index for the bit reversal */
emilmont 1:fdd22bb7aa52 158 j = *pBitRevTable;
emilmont 1:fdd22bb7aa52 159
emilmont 1:fdd22bb7aa52 160 /* Updating the bit reversal index depending on the fft length */
emilmont 1:fdd22bb7aa52 161 pBitRevTable += bitRevFactor;
emilmont 1:fdd22bb7aa52 162 }
emilmont 1:fdd22bb7aa52 163 }
emilmont 1:fdd22bb7aa52 164
emilmont 1:fdd22bb7aa52 165
emilmont 1:fdd22bb7aa52 166
emilmont 1:fdd22bb7aa52 167 /*
emilmont 1:fdd22bb7aa52 168 * @brief In-place bit reversal function.
emilmont 1:fdd22bb7aa52 169 * @param[in, out] *pSrc points to the in-place buffer of Q15 data type.
emilmont 1:fdd22bb7aa52 170 * @param[in] fftLen length of the FFT.
emilmont 1:fdd22bb7aa52 171 * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table
emilmont 1:fdd22bb7aa52 172 * @param[in] *pBitRevTab points to bit reversal table.
emilmont 1:fdd22bb7aa52 173 * @return none.
emilmont 1:fdd22bb7aa52 174 */
emilmont 1:fdd22bb7aa52 175
emilmont 1:fdd22bb7aa52 176 void arm_bitreversal_q15(
emilmont 1:fdd22bb7aa52 177 q15_t * pSrc16,
emilmont 1:fdd22bb7aa52 178 uint32_t fftLen,
emilmont 1:fdd22bb7aa52 179 uint16_t bitRevFactor,
emilmont 1:fdd22bb7aa52 180 uint16_t * pBitRevTab)
emilmont 1:fdd22bb7aa52 181 {
emilmont 1:fdd22bb7aa52 182 q31_t *pSrc = (q31_t *) pSrc16;
emilmont 1:fdd22bb7aa52 183 q31_t in;
emilmont 1:fdd22bb7aa52 184 uint32_t fftLenBy2, fftLenBy2p1;
emilmont 1:fdd22bb7aa52 185 uint32_t i, j;
emilmont 1:fdd22bb7aa52 186
emilmont 1:fdd22bb7aa52 187 /* Initializations */
emilmont 1:fdd22bb7aa52 188 j = 0u;
emilmont 1:fdd22bb7aa52 189 fftLenBy2 = fftLen / 2u;
emilmont 1:fdd22bb7aa52 190 fftLenBy2p1 = (fftLen / 2u) + 1u;
emilmont 1:fdd22bb7aa52 191
emilmont 1:fdd22bb7aa52 192 /* Bit Reversal Implementation */
emilmont 1:fdd22bb7aa52 193 for (i = 0u; i <= (fftLenBy2 - 2u); i += 2u)
emilmont 1:fdd22bb7aa52 194 {
emilmont 1:fdd22bb7aa52 195 if(i < j)
emilmont 1:fdd22bb7aa52 196 {
emilmont 1:fdd22bb7aa52 197 /* pSrc[i] <-> pSrc[j]; */
emilmont 1:fdd22bb7aa52 198 /* pSrc[i+1u] <-> pSrc[j+1u] */
emilmont 1:fdd22bb7aa52 199 in = pSrc[i];
emilmont 1:fdd22bb7aa52 200 pSrc[i] = pSrc[j];
emilmont 1:fdd22bb7aa52 201 pSrc[j] = in;
emilmont 1:fdd22bb7aa52 202
emilmont 1:fdd22bb7aa52 203 /* pSrc[i + fftLenBy2p1] <-> pSrc[j + fftLenBy2p1]; */
emilmont 1:fdd22bb7aa52 204 /* pSrc[i + fftLenBy2p1+1u] <-> pSrc[j + fftLenBy2p1+1u] */
emilmont 1:fdd22bb7aa52 205 in = pSrc[i + fftLenBy2p1];
emilmont 1:fdd22bb7aa52 206 pSrc[i + fftLenBy2p1] = pSrc[j + fftLenBy2p1];
emilmont 1:fdd22bb7aa52 207 pSrc[j + fftLenBy2p1] = in;
emilmont 1:fdd22bb7aa52 208 }
emilmont 1:fdd22bb7aa52 209
emilmont 1:fdd22bb7aa52 210 /* pSrc[i+1u] <-> pSrc[j+fftLenBy2]; */
emilmont 1:fdd22bb7aa52 211 /* pSrc[i+2] <-> pSrc[j+fftLenBy2+1u] */
emilmont 1:fdd22bb7aa52 212 in = pSrc[i + 1u];
emilmont 1:fdd22bb7aa52 213 pSrc[i + 1u] = pSrc[j + fftLenBy2];
emilmont 1:fdd22bb7aa52 214 pSrc[j + fftLenBy2] = in;
emilmont 1:fdd22bb7aa52 215
emilmont 1:fdd22bb7aa52 216 /* Reading the index for the bit reversal */
emilmont 1:fdd22bb7aa52 217 j = *pBitRevTab;
emilmont 1:fdd22bb7aa52 218
emilmont 1:fdd22bb7aa52 219 /* Updating the bit reversal index depending on the fft length */
emilmont 1:fdd22bb7aa52 220 pBitRevTab += bitRevFactor;
emilmont 1:fdd22bb7aa52 221 }
emilmont 1:fdd22bb7aa52 222 }