mbed-os 6.10 versione
cmsis_dsp/TransformFunctions/arm_rfft_fast_f32.c@3:7a284390b0ce, 2013-11-08 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Nov 08 13:45:10 2013 +0000
- Revision:
- 3:7a284390b0ce
Synchronized with git revision e69956aba2f68a2a26ac26b051f8d349deaa1ce8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 3:7a284390b0ce | 1 | /* ---------------------------------------------------------------------- |
mbed_official | 3:7a284390b0ce | 2 | * Copyright (C) 2010-2013 ARM Limited. All rights reserved. |
mbed_official | 3:7a284390b0ce | 3 | * |
mbed_official | 3:7a284390b0ce | 4 | * $Date: 17. January 2013 |
mbed_official | 3:7a284390b0ce | 5 | * $Revision: V1.4.1 |
mbed_official | 3:7a284390b0ce | 6 | * |
mbed_official | 3:7a284390b0ce | 7 | * Project: CMSIS DSP Library |
mbed_official | 3:7a284390b0ce | 8 | * Title: arm_rfft_f32.c |
mbed_official | 3:7a284390b0ce | 9 | * |
mbed_official | 3:7a284390b0ce | 10 | * Description: RFFT & RIFFT Floating point process function |
mbed_official | 3:7a284390b0ce | 11 | * |
mbed_official | 3:7a284390b0ce | 12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 |
mbed_official | 3:7a284390b0ce | 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. |
mbed_official | 3:7a284390b0ce | 39 | * -------------------------------------------------------------------- */ |
mbed_official | 3:7a284390b0ce | 40 | |
mbed_official | 3:7a284390b0ce | 41 | #include "arm_math.h" |
mbed_official | 3:7a284390b0ce | 42 | |
mbed_official | 3:7a284390b0ce | 43 | void stage_rfft_f32( |
mbed_official | 3:7a284390b0ce | 44 | arm_rfft_fast_instance_f32 * S, |
mbed_official | 3:7a284390b0ce | 45 | float32_t * p, float32_t * pOut) |
mbed_official | 3:7a284390b0ce | 46 | { |
mbed_official | 3:7a284390b0ce | 47 | uint32_t k; /* Loop Counter */ |
mbed_official | 3:7a284390b0ce | 48 | float32_t twR, twI; /* RFFT Twiddle coefficients */ |
mbed_official | 3:7a284390b0ce | 49 | float32_t * pCoeff = S->pTwiddleRFFT; /* Points to RFFT Twiddle factors */ |
mbed_official | 3:7a284390b0ce | 50 | float32_t *pA = p; /* increasing pointer */ |
mbed_official | 3:7a284390b0ce | 51 | float32_t *pB = p; /* decreasing pointer */ |
mbed_official | 3:7a284390b0ce | 52 | float32_t xAR, xAI, xBR, xBI; /* temporary variables */ |
mbed_official | 3:7a284390b0ce | 53 | float32_t t1a, t1b; /* temporary variables */ |
mbed_official | 3:7a284390b0ce | 54 | float32_t p0, p1, p2, p3; /* temporary variables */ |
mbed_official | 3:7a284390b0ce | 55 | |
mbed_official | 3:7a284390b0ce | 56 | |
mbed_official | 3:7a284390b0ce | 57 | k = (S->Sint).fftLen - 1; |
mbed_official | 3:7a284390b0ce | 58 | |
mbed_official | 3:7a284390b0ce | 59 | /* Pack first and last sample of the frequency domain together */ |
mbed_official | 3:7a284390b0ce | 60 | |
mbed_official | 3:7a284390b0ce | 61 | xBR = pB[0]; |
mbed_official | 3:7a284390b0ce | 62 | xBI = pB[1]; |
mbed_official | 3:7a284390b0ce | 63 | xAR = pA[0]; |
mbed_official | 3:7a284390b0ce | 64 | xAI = pA[1]; |
mbed_official | 3:7a284390b0ce | 65 | |
mbed_official | 3:7a284390b0ce | 66 | twR = *pCoeff++ ; |
mbed_official | 3:7a284390b0ce | 67 | twI = *pCoeff++ ; |
mbed_official | 3:7a284390b0ce | 68 | |
mbed_official | 3:7a284390b0ce | 69 | // U1 = XA(1) + XB(1); % It is real |
mbed_official | 3:7a284390b0ce | 70 | t1a = xBR + xAR ; |
mbed_official | 3:7a284390b0ce | 71 | |
mbed_official | 3:7a284390b0ce | 72 | // U2 = XB(1) - XA(1); % It is imaginary |
mbed_official | 3:7a284390b0ce | 73 | t1b = xBI + xAI ; |
mbed_official | 3:7a284390b0ce | 74 | |
mbed_official | 3:7a284390b0ce | 75 | // real(tw * (xB - xA)) = twR * (xBR - xAR) - twI * (xBI - xAI); |
mbed_official | 3:7a284390b0ce | 76 | // imag(tw * (xB - xA)) = twI * (xBR - xAR) + twR * (xBI - xAI); |
mbed_official | 3:7a284390b0ce | 77 | *pOut++ = 0.5f * ( t1a + t1b ); |
mbed_official | 3:7a284390b0ce | 78 | *pOut++ = 0.5f * ( t1a - t1b ); |
mbed_official | 3:7a284390b0ce | 79 | |
mbed_official | 3:7a284390b0ce | 80 | // XA(1) = 1/2*( U1 - imag(U2) + i*( U1 +imag(U2) )); |
mbed_official | 3:7a284390b0ce | 81 | pB = p + 2*k; |
mbed_official | 3:7a284390b0ce | 82 | pA += 2; |
mbed_official | 3:7a284390b0ce | 83 | |
mbed_official | 3:7a284390b0ce | 84 | do |
mbed_official | 3:7a284390b0ce | 85 | { |
mbed_official | 3:7a284390b0ce | 86 | /* |
mbed_official | 3:7a284390b0ce | 87 | function X = my_split_rfft(X, ifftFlag) |
mbed_official | 3:7a284390b0ce | 88 | % X is a series of real numbers |
mbed_official | 3:7a284390b0ce | 89 | L = length(X); |
mbed_official | 3:7a284390b0ce | 90 | XC = X(1:2:end) +i*X(2:2:end); |
mbed_official | 3:7a284390b0ce | 91 | XA = fft(XC); |
mbed_official | 3:7a284390b0ce | 92 | XB = conj(XA([1 end:-1:2])); |
mbed_official | 3:7a284390b0ce | 93 | TW = i*exp(-2*pi*i*[0:L/2-1]/L).'; |
mbed_official | 3:7a284390b0ce | 94 | for l = 2:L/2 |
mbed_official | 3:7a284390b0ce | 95 | XA(l) = 1/2 * (XA(l) + XB(l) + TW(l) * (XB(l) - XA(l))); |
mbed_official | 3:7a284390b0ce | 96 | end |
mbed_official | 3:7a284390b0ce | 97 | XA(1) = 1/2* (XA(1) + XB(1) + TW(1) * (XB(1) - XA(1))) + i*( 1/2*( XA(1) + XB(1) + i*( XA(1) - XB(1)))); |
mbed_official | 3:7a284390b0ce | 98 | X = XA; |
mbed_official | 3:7a284390b0ce | 99 | */ |
mbed_official | 3:7a284390b0ce | 100 | |
mbed_official | 3:7a284390b0ce | 101 | xBI = pB[1]; |
mbed_official | 3:7a284390b0ce | 102 | xBR = pB[0]; |
mbed_official | 3:7a284390b0ce | 103 | xAR = pA[0]; |
mbed_official | 3:7a284390b0ce | 104 | xAI = pA[1]; |
mbed_official | 3:7a284390b0ce | 105 | |
mbed_official | 3:7a284390b0ce | 106 | twR = *pCoeff++; |
mbed_official | 3:7a284390b0ce | 107 | twI = *pCoeff++; |
mbed_official | 3:7a284390b0ce | 108 | |
mbed_official | 3:7a284390b0ce | 109 | t1a = xBR - xAR ; |
mbed_official | 3:7a284390b0ce | 110 | t1b = xBI + xAI ; |
mbed_official | 3:7a284390b0ce | 111 | |
mbed_official | 3:7a284390b0ce | 112 | // real(tw * (xB - xA)) = twR * (xBR - xAR) - twI * (xBI - xAI); |
mbed_official | 3:7a284390b0ce | 113 | // imag(tw * (xB - xA)) = twI * (xBR - xAR) + twR * (xBI - xAI); |
mbed_official | 3:7a284390b0ce | 114 | p0 = twR * t1a; |
mbed_official | 3:7a284390b0ce | 115 | p1 = twI * t1a; |
mbed_official | 3:7a284390b0ce | 116 | p2 = twR * t1b; |
mbed_official | 3:7a284390b0ce | 117 | p3 = twI * t1b; |
mbed_official | 3:7a284390b0ce | 118 | |
mbed_official | 3:7a284390b0ce | 119 | *pOut++ = 0.5f * (xAR + xBR + p0 + p3 ); //xAR |
mbed_official | 3:7a284390b0ce | 120 | *pOut++ = 0.5f * (xAI - xBI + p1 - p2 ); //xAI |
mbed_official | 3:7a284390b0ce | 121 | |
mbed_official | 3:7a284390b0ce | 122 | pA += 2; |
mbed_official | 3:7a284390b0ce | 123 | pB -= 2; |
mbed_official | 3:7a284390b0ce | 124 | k--; |
mbed_official | 3:7a284390b0ce | 125 | } while(k > 0u); |
mbed_official | 3:7a284390b0ce | 126 | } |
mbed_official | 3:7a284390b0ce | 127 | |
mbed_official | 3:7a284390b0ce | 128 | /* Prepares data for inverse cfft */ |
mbed_official | 3:7a284390b0ce | 129 | void merge_rfft_f32( |
mbed_official | 3:7a284390b0ce | 130 | arm_rfft_fast_instance_f32 * S, |
mbed_official | 3:7a284390b0ce | 131 | float32_t * p, float32_t * pOut) |
mbed_official | 3:7a284390b0ce | 132 | { |
mbed_official | 3:7a284390b0ce | 133 | uint32_t k; /* Loop Counter */ |
mbed_official | 3:7a284390b0ce | 134 | float32_t twR, twI; /* RFFT Twiddle coefficients */ |
mbed_official | 3:7a284390b0ce | 135 | float32_t *pCoeff = S->pTwiddleRFFT; /* Points to RFFT Twiddle factors */ |
mbed_official | 3:7a284390b0ce | 136 | float32_t *pA = p; /* increasing pointer */ |
mbed_official | 3:7a284390b0ce | 137 | float32_t *pB = p; /* decreasing pointer */ |
mbed_official | 3:7a284390b0ce | 138 | float32_t xAR, xAI, xBR, xBI; /* temporary variables */ |
mbed_official | 3:7a284390b0ce | 139 | float32_t t1a, t1b, r, s, t, u; /* temporary variables */ |
mbed_official | 3:7a284390b0ce | 140 | |
mbed_official | 3:7a284390b0ce | 141 | k = (S->Sint).fftLen - 1; |
mbed_official | 3:7a284390b0ce | 142 | |
mbed_official | 3:7a284390b0ce | 143 | xAR = pA[0]; |
mbed_official | 3:7a284390b0ce | 144 | xAI = pA[1]; |
mbed_official | 3:7a284390b0ce | 145 | |
mbed_official | 3:7a284390b0ce | 146 | pCoeff += 2 ; |
mbed_official | 3:7a284390b0ce | 147 | |
mbed_official | 3:7a284390b0ce | 148 | *pOut++ = 0.5f * ( xAR + xAI ); |
mbed_official | 3:7a284390b0ce | 149 | *pOut++ = 0.5f * ( xAR - xAI ); |
mbed_official | 3:7a284390b0ce | 150 | |
mbed_official | 3:7a284390b0ce | 151 | pB = p + 2*k ; |
mbed_official | 3:7a284390b0ce | 152 | pA += 2 ; |
mbed_official | 3:7a284390b0ce | 153 | |
mbed_official | 3:7a284390b0ce | 154 | while(k > 0u) |
mbed_official | 3:7a284390b0ce | 155 | { |
mbed_official | 3:7a284390b0ce | 156 | /* G is half of the frequency complex spectrum */ |
mbed_official | 3:7a284390b0ce | 157 | //for k = 2:N |
mbed_official | 3:7a284390b0ce | 158 | // Xk(k) = 1/2 * (G(k) + conj(G(N-k+2)) + Tw(k)*( G(k) - conj(G(N-k+2)))); |
mbed_official | 3:7a284390b0ce | 159 | xBI = pB[1] ; |
mbed_official | 3:7a284390b0ce | 160 | xBR = pB[0] ; |
mbed_official | 3:7a284390b0ce | 161 | xAR = pA[0]; |
mbed_official | 3:7a284390b0ce | 162 | xAI = pA[1]; |
mbed_official | 3:7a284390b0ce | 163 | |
mbed_official | 3:7a284390b0ce | 164 | twR = *pCoeff++; |
mbed_official | 3:7a284390b0ce | 165 | twI = *pCoeff++; |
mbed_official | 3:7a284390b0ce | 166 | |
mbed_official | 3:7a284390b0ce | 167 | t1a = xAR - xBR ; |
mbed_official | 3:7a284390b0ce | 168 | t1b = xAI + xBI ; |
mbed_official | 3:7a284390b0ce | 169 | |
mbed_official | 3:7a284390b0ce | 170 | r = twR * t1a; |
mbed_official | 3:7a284390b0ce | 171 | s = twI * t1b; |
mbed_official | 3:7a284390b0ce | 172 | t = twI * t1a; |
mbed_official | 3:7a284390b0ce | 173 | u = twR * t1b; |
mbed_official | 3:7a284390b0ce | 174 | |
mbed_official | 3:7a284390b0ce | 175 | // real(tw * (xA - xB)) = twR * (xAR - xBR) - twI * (xAI - xBI); |
mbed_official | 3:7a284390b0ce | 176 | // imag(tw * (xA - xB)) = twI * (xAR - xBR) + twR * (xAI - xBI); |
mbed_official | 3:7a284390b0ce | 177 | *pOut++ = 0.5f * (xAR + xBR - r - s ); //xAR |
mbed_official | 3:7a284390b0ce | 178 | *pOut++ = 0.5f * (xAI - xBI + t - u ); //xAI |
mbed_official | 3:7a284390b0ce | 179 | |
mbed_official | 3:7a284390b0ce | 180 | pA += 2; |
mbed_official | 3:7a284390b0ce | 181 | pB -= 2; |
mbed_official | 3:7a284390b0ce | 182 | k--; |
mbed_official | 3:7a284390b0ce | 183 | } |
mbed_official | 3:7a284390b0ce | 184 | |
mbed_official | 3:7a284390b0ce | 185 | } |
mbed_official | 3:7a284390b0ce | 186 | |
mbed_official | 3:7a284390b0ce | 187 | /** |
mbed_official | 3:7a284390b0ce | 188 | * @ingroup groupTransforms |
mbed_official | 3:7a284390b0ce | 189 | */ |
mbed_official | 3:7a284390b0ce | 190 | |
mbed_official | 3:7a284390b0ce | 191 | /** |
mbed_official | 3:7a284390b0ce | 192 | * @defgroup Fast Real FFT Functions |
mbed_official | 3:7a284390b0ce | 193 | * |
mbed_official | 3:7a284390b0ce | 194 | * \par |
mbed_official | 3:7a284390b0ce | 195 | * The CMSIS DSP library includes specialized algorithms for computing the |
mbed_official | 3:7a284390b0ce | 196 | * FFT of real data sequences. The FFT is defined over complex data but |
mbed_official | 3:7a284390b0ce | 197 | * in many applications the input is real. Real FFT algorithms take advantage |
mbed_official | 3:7a284390b0ce | 198 | * of the symmetry properties of the FFT and have a speed advantage over complex |
mbed_official | 3:7a284390b0ce | 199 | * algorithms of the same length. |
mbed_official | 3:7a284390b0ce | 200 | * \par |
mbed_official | 3:7a284390b0ce | 201 | * The Fast RFFT algorith relays on the mixed radix CFFT that save processor usage. |
mbed_official | 3:7a284390b0ce | 202 | * \par |
mbed_official | 3:7a284390b0ce | 203 | * The real length N forward FFT of a sequence is computed using the steps shown below. |
mbed_official | 3:7a284390b0ce | 204 | * \par |
mbed_official | 3:7a284390b0ce | 205 | * \image html RFFT.gif "Real Fast Fourier Transform" |
mbed_official | 3:7a284390b0ce | 206 | * \par |
mbed_official | 3:7a284390b0ce | 207 | * The real sequence is initially treated as if it were complex to perform a CFFT. |
mbed_official | 3:7a284390b0ce | 208 | * Later, a processing stage reshapes the data to obtain half of the frequency spectrum |
mbed_official | 3:7a284390b0ce | 209 | * in complex format. Except the first complex number that contains the two real numbers |
mbed_official | 3:7a284390b0ce | 210 | * X[0] and X[N/2] all the data is complex. In other words, the first complex sample |
mbed_official | 3:7a284390b0ce | 211 | * contains two real values packed. |
mbed_official | 3:7a284390b0ce | 212 | * \par |
mbed_official | 3:7a284390b0ce | 213 | * The input for the inverse RFFT should keep the same format as the output of the |
mbed_official | 3:7a284390b0ce | 214 | * forward RFFT. A first processing stage pre-process the data to later perform an |
mbed_official | 3:7a284390b0ce | 215 | * inverse CFFT. |
mbed_official | 3:7a284390b0ce | 216 | * \par |
mbed_official | 3:7a284390b0ce | 217 | * \image html RIFFT.gif "Real Inverse Fast Fourier Transform" |
mbed_official | 3:7a284390b0ce | 218 | * \par |
mbed_official | 3:7a284390b0ce | 219 | * The algorithms for floating-point, Q15, and Q31 data are slightly different |
mbed_official | 3:7a284390b0ce | 220 | * and we describe each algorithm in turn. |
mbed_official | 3:7a284390b0ce | 221 | * \par Floating-point |
mbed_official | 3:7a284390b0ce | 222 | * The main functions are <code>arm_rfft_fast_f32()</code> |
mbed_official | 3:7a284390b0ce | 223 | * and <code>arm_rfft_fast_init_f32()</code>. The older functions |
mbed_official | 3:7a284390b0ce | 224 | * <code>arm_rfft_f32()</code> and <code>arm_rfft_init_f32()</code> have been |
mbed_official | 3:7a284390b0ce | 225 | * deprecated but are still documented. |
mbed_official | 3:7a284390b0ce | 226 | * \par |
mbed_official | 3:7a284390b0ce | 227 | * The FFT of a real N-point sequence has even symmetry in the frequency |
mbed_official | 3:7a284390b0ce | 228 | * domain. The second half of the data equals the conjugate of the first half |
mbed_official | 3:7a284390b0ce | 229 | * flipped in frequency: |
mbed_official | 3:7a284390b0ce | 230 | * <pre> |
mbed_official | 3:7a284390b0ce | 231 | *X[0] - real data |
mbed_official | 3:7a284390b0ce | 232 | *X[1] - complex data |
mbed_official | 3:7a284390b0ce | 233 | *X[2] - complex data |
mbed_official | 3:7a284390b0ce | 234 | *... |
mbed_official | 3:7a284390b0ce | 235 | *X[fftLen/2-1] - complex data |
mbed_official | 3:7a284390b0ce | 236 | *X[fftLen/2] - real data |
mbed_official | 3:7a284390b0ce | 237 | *X[fftLen/2+1] - conjugate of X[fftLen/2-1] |
mbed_official | 3:7a284390b0ce | 238 | *X[fftLen/2+2] - conjugate of X[fftLen/2-2] |
mbed_official | 3:7a284390b0ce | 239 | *... |
mbed_official | 3:7a284390b0ce | 240 | *X[fftLen-1] - conjugate of X[1] |
mbed_official | 3:7a284390b0ce | 241 | * </pre> |
mbed_official | 3:7a284390b0ce | 242 | * Looking at the data, we see that we can uniquely represent the FFT using only |
mbed_official | 3:7a284390b0ce | 243 | * <pre> |
mbed_official | 3:7a284390b0ce | 244 | *N/2+1 samples: |
mbed_official | 3:7a284390b0ce | 245 | *X[0] - real data |
mbed_official | 3:7a284390b0ce | 246 | *X[1] - complex data |
mbed_official | 3:7a284390b0ce | 247 | *X[2] - complex data |
mbed_official | 3:7a284390b0ce | 248 | *... |
mbed_official | 3:7a284390b0ce | 249 | *X[fftLen/2-1] - complex data |
mbed_official | 3:7a284390b0ce | 250 | *X[fftLen/2] - real data |
mbed_official | 3:7a284390b0ce | 251 | * </pre> |
mbed_official | 3:7a284390b0ce | 252 | * Looking more closely we see that the first and last samples are real valued. |
mbed_official | 3:7a284390b0ce | 253 | * They can be packed together and we can thus represent the FFT of an N-point |
mbed_official | 3:7a284390b0ce | 254 | * real sequence by N/2 complex values: |
mbed_official | 3:7a284390b0ce | 255 | * <pre> |
mbed_official | 3:7a284390b0ce | 256 | *X[0],X[N/2] - packed real data: X[0] + jX[N/2] |
mbed_official | 3:7a284390b0ce | 257 | *X[1] - complex data |
mbed_official | 3:7a284390b0ce | 258 | *X[2] - complex data |
mbed_official | 3:7a284390b0ce | 259 | *... |
mbed_official | 3:7a284390b0ce | 260 | *X[fftLen/2-1] - complex data |
mbed_official | 3:7a284390b0ce | 261 | * </pre> |
mbed_official | 3:7a284390b0ce | 262 | * The real FFT functions pack the frequency domain data in this fashion. The |
mbed_official | 3:7a284390b0ce | 263 | * forward transform outputs the data in this form and the inverse transform |
mbed_official | 3:7a284390b0ce | 264 | * expects input data in this form. The function always performs the needed |
mbed_official | 3:7a284390b0ce | 265 | * bitreversal so that the input and output data is always in normal order. The |
mbed_official | 3:7a284390b0ce | 266 | * functions support lengths of [32, 64, 128, ..., 4096] samples. |
mbed_official | 3:7a284390b0ce | 267 | * \par |
mbed_official | 3:7a284390b0ce | 268 | * The forward and inverse real FFT functions apply the standard FFT scaling; no |
mbed_official | 3:7a284390b0ce | 269 | * scaling on the forward transform and 1/fftLen scaling on the inverse |
mbed_official | 3:7a284390b0ce | 270 | * transform. |
mbed_official | 3:7a284390b0ce | 271 | * \par Q15 and Q31 |
mbed_official | 3:7a284390b0ce | 272 | * The real algorithms are defined in a similar manner and utilize N/2 complex |
mbed_official | 3:7a284390b0ce | 273 | * transforms behind the scenes. In the case of fixed-point data, a radix-4 |
mbed_official | 3:7a284390b0ce | 274 | * complex transform is performed and this limits the allows sequence lengths to |
mbed_official | 3:7a284390b0ce | 275 | * 128, 512, and 2048 samples. |
mbed_official | 3:7a284390b0ce | 276 | * \par |
mbed_official | 3:7a284390b0ce | 277 | * TBD. We need to document input and output order of data. |
mbed_official | 3:7a284390b0ce | 278 | * \par |
mbed_official | 3:7a284390b0ce | 279 | * The complex transforms used internally include scaling to prevent fixed-point |
mbed_official | 3:7a284390b0ce | 280 | * overflows. The overall scaling equals 1/(fftLen/2). |
mbed_official | 3:7a284390b0ce | 281 | * \par |
mbed_official | 3:7a284390b0ce | 282 | * A separate instance structure must be defined for each transform used but |
mbed_official | 3:7a284390b0ce | 283 | * twiddle factor and bit reversal tables can be reused. |
mbed_official | 3:7a284390b0ce | 284 | * \par |
mbed_official | 3:7a284390b0ce | 285 | * There is also an associated initialization function for each data type. |
mbed_official | 3:7a284390b0ce | 286 | * The initialization function performs the following operations: |
mbed_official | 3:7a284390b0ce | 287 | * - Sets the values of the internal structure fields. |
mbed_official | 3:7a284390b0ce | 288 | * - Initializes twiddle factor table and bit reversal table pointers. |
mbed_official | 3:7a284390b0ce | 289 | * - Initializes the internal complex FFT data structure. |
mbed_official | 3:7a284390b0ce | 290 | * \par |
mbed_official | 3:7a284390b0ce | 291 | * Use of the initialization function is optional. |
mbed_official | 3:7a284390b0ce | 292 | * However, if the initialization function is used, then the instance structure |
mbed_official | 3:7a284390b0ce | 293 | * cannot be placed into a const data section. To place an instance structure |
mbed_official | 3:7a284390b0ce | 294 | * into a const data section, the instance structure should be manually |
mbed_official | 3:7a284390b0ce | 295 | * initialized as follows: |
mbed_official | 3:7a284390b0ce | 296 | * <pre> |
mbed_official | 3:7a284390b0ce | 297 | *arm_rfft_instance_q31 S = {fftLenReal, fftLenBy2, ifftFlagR, bitReverseFlagR, twidCoefRModifier, pTwiddleAReal, pTwiddleBReal, pCfft}; |
mbed_official | 3:7a284390b0ce | 298 | *arm_rfft_instance_q15 S = {fftLenReal, fftLenBy2, ifftFlagR, bitReverseFlagR, twidCoefRModifier, pTwiddleAReal, pTwiddleBReal, pCfft}; |
mbed_official | 3:7a284390b0ce | 299 | * </pre> |
mbed_official | 3:7a284390b0ce | 300 | * where <code>fftLenReal</code> is the length of the real transform; |
mbed_official | 3:7a284390b0ce | 301 | * <code>fftLenBy2</code> length of the internal complex transform. |
mbed_official | 3:7a284390b0ce | 302 | * <code>ifftFlagR</code> Selects forward (=0) or inverse (=1) transform. |
mbed_official | 3:7a284390b0ce | 303 | * <code>bitReverseFlagR</code> Selects bit reversed output (=0) or normal order |
mbed_official | 3:7a284390b0ce | 304 | * output (=1). |
mbed_official | 3:7a284390b0ce | 305 | * <code>twidCoefRModifier</code> stride modifier for the twiddle factor table. |
mbed_official | 3:7a284390b0ce | 306 | * The value is based on the FFT length; |
mbed_official | 3:7a284390b0ce | 307 | * <code>pTwiddleAReal</code>points to the A array of twiddle coefficients; |
mbed_official | 3:7a284390b0ce | 308 | * <code>pTwiddleBReal</code>points to the B array of twiddle coefficients; |
mbed_official | 3:7a284390b0ce | 309 | * <code>pCfft</code> points to the CFFT Instance structure. The CFFT structure |
mbed_official | 3:7a284390b0ce | 310 | * must also be initialized. Refer to arm_cfft_radix4_f32() for details regarding |
mbed_official | 3:7a284390b0ce | 311 | * static initialization of the complex FFT instance structure. |
mbed_official | 3:7a284390b0ce | 312 | */ |
mbed_official | 3:7a284390b0ce | 313 | |
mbed_official | 3:7a284390b0ce | 314 | /** |
mbed_official | 3:7a284390b0ce | 315 | * @addtogroup RealFFT |
mbed_official | 3:7a284390b0ce | 316 | * @{ |
mbed_official | 3:7a284390b0ce | 317 | */ |
mbed_official | 3:7a284390b0ce | 318 | |
mbed_official | 3:7a284390b0ce | 319 | /** |
mbed_official | 3:7a284390b0ce | 320 | * @brief Processing function for the floating-point real FFT. |
mbed_official | 3:7a284390b0ce | 321 | * @param[in] *S points to an arm_rfft_fast_instance_f32 structure. |
mbed_official | 3:7a284390b0ce | 322 | * @param[in] *p points to the input buffer. |
mbed_official | 3:7a284390b0ce | 323 | * @param[in] *pOut points to an arm_rfft_fast_instance_f32 structure. |
mbed_official | 3:7a284390b0ce | 324 | * @param[in] ifftFlag RFFT if flag is 0, RIFFT if flag is 1 |
mbed_official | 3:7a284390b0ce | 325 | * @return none. |
mbed_official | 3:7a284390b0ce | 326 | */ |
mbed_official | 3:7a284390b0ce | 327 | |
mbed_official | 3:7a284390b0ce | 328 | void arm_rfft_fast_f32( |
mbed_official | 3:7a284390b0ce | 329 | arm_rfft_fast_instance_f32 * S, |
mbed_official | 3:7a284390b0ce | 330 | float32_t * p, float32_t * pOut, |
mbed_official | 3:7a284390b0ce | 331 | uint8_t ifftFlag) |
mbed_official | 3:7a284390b0ce | 332 | { |
mbed_official | 3:7a284390b0ce | 333 | arm_cfft_instance_f32 * Sint = &(S->Sint); |
mbed_official | 3:7a284390b0ce | 334 | Sint->fftLen = S->fftLenRFFT / 2; |
mbed_official | 3:7a284390b0ce | 335 | |
mbed_official | 3:7a284390b0ce | 336 | /* Calculation of Real FFT */ |
mbed_official | 3:7a284390b0ce | 337 | if(ifftFlag) |
mbed_official | 3:7a284390b0ce | 338 | { |
mbed_official | 3:7a284390b0ce | 339 | /* Real FFT comression */ |
mbed_official | 3:7a284390b0ce | 340 | merge_rfft_f32(S, p, pOut); |
mbed_official | 3:7a284390b0ce | 341 | |
mbed_official | 3:7a284390b0ce | 342 | /* Complex radix-4 IFFT process */ |
mbed_official | 3:7a284390b0ce | 343 | arm_cfft_f32( Sint, pOut, ifftFlag, 1); |
mbed_official | 3:7a284390b0ce | 344 | } |
mbed_official | 3:7a284390b0ce | 345 | else |
mbed_official | 3:7a284390b0ce | 346 | { |
mbed_official | 3:7a284390b0ce | 347 | /* Calculation of RFFT of input */ |
mbed_official | 3:7a284390b0ce | 348 | arm_cfft_f32( Sint, p, ifftFlag, 1); |
mbed_official | 3:7a284390b0ce | 349 | |
mbed_official | 3:7a284390b0ce | 350 | /* Real FFT extraction */ |
mbed_official | 3:7a284390b0ce | 351 | stage_rfft_f32(S, p, pOut); |
mbed_official | 3:7a284390b0ce | 352 | } |
mbed_official | 3:7a284390b0ce | 353 | } |
mbed_official | 3:7a284390b0ce | 354 |