STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
arm_rfft_fast_f32.c
Go to the documentation of this file.
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_rfft_f32.c
9 *
10 * Description: RFFT & RIFFT Floating point process function
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 
45  float32_t * p, float32_t * pOut)
46 {
47  uint32_t k; /* Loop Counter */
48  float32_t twR, twI; /* RFFT Twiddle coefficients */
49  float32_t * pCoeff = S->pTwiddleRFFT; /* Points to RFFT Twiddle factors */
50  float32_t *pA = p; /* increasing pointer */
51  float32_t *pB = p; /* decreasing pointer */
52  float32_t xAR, xAI, xBR, xBI; /* temporary variables */
53  float32_t t1a, t1b; /* temporary variables */
54  float32_t p0, p1, p2, p3; /* temporary variables */
55 
56 
57  k = (S->Sint).fftLen - 1;
58 
59  /* Pack first and last sample of the frequency domain together */
60 
61  xBR = pB[0];
62  xBI = pB[1];
63  xAR = pA[0];
64  xAI = pA[1];
65 
66  twR = *pCoeff++ ;
67  twI = *pCoeff++ ;
68 
69  // U1 = XA(1) + XB(1); % It is real
70  t1a = xBR + xAR ;
71 
72  // U2 = XB(1) - XA(1); % It is imaginary
73  t1b = xBI + xAI ;
74 
75  // real(tw * (xB - xA)) = twR * (xBR - xAR) - twI * (xBI - xAI);
76  // imag(tw * (xB - xA)) = twI * (xBR - xAR) + twR * (xBI - xAI);
77  *pOut++ = 0.5f * ( t1a + t1b );
78  *pOut++ = 0.5f * ( t1a - t1b );
79 
80  // XA(1) = 1/2*( U1 - imag(U2) + i*( U1 +imag(U2) ));
81  pB = p + 2*k;
82  pA += 2;
83 
84  do
85  {
86  /*
87  function X = my_split_rfft(X, ifftFlag)
88  % X is a series of real numbers
89  L = length(X);
90  XC = X(1:2:end) +i*X(2:2:end);
91  XA = fft(XC);
92  XB = conj(XA([1 end:-1:2]));
93  TW = i*exp(-2*pi*i*[0:L/2-1]/L).';
94  for l = 2:L/2
95  XA(l) = 1/2 * (XA(l) + XB(l) + TW(l) * (XB(l) - XA(l)));
96  end
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))));
98  X = XA;
99  */
100 
101  xBI = pB[1];
102  xBR = pB[0];
103  xAR = pA[0];
104  xAI = pA[1];
105 
106  twR = *pCoeff++;
107  twI = *pCoeff++;
108 
109  t1a = xBR - xAR ;
110  t1b = xBI + xAI ;
111 
112  // real(tw * (xB - xA)) = twR * (xBR - xAR) - twI * (xBI - xAI);
113  // imag(tw * (xB - xA)) = twI * (xBR - xAR) + twR * (xBI - xAI);
114  p0 = twR * t1a;
115  p1 = twI * t1a;
116  p2 = twR * t1b;
117  p3 = twI * t1b;
118 
119  *pOut++ = 0.5f * (xAR + xBR + p0 + p3 ); //xAR
120  *pOut++ = 0.5f * (xAI - xBI + p1 - p2 ); //xAI
121 
122  pA += 2;
123  pB -= 2;
124  k--;
125  } while(k > 0u);
126 }
127 
128 /* Prepares data for inverse cfft */
131 float32_t * p, float32_t * pOut)
132 {
133  uint32_t k; /* Loop Counter */
134  float32_t twR, twI; /* RFFT Twiddle coefficients */
135  float32_t *pCoeff = S->pTwiddleRFFT; /* Points to RFFT Twiddle factors */
136  float32_t *pA = p; /* increasing pointer */
137  float32_t *pB = p; /* decreasing pointer */
138  float32_t xAR, xAI, xBR, xBI; /* temporary variables */
139  float32_t t1a, t1b, r, s, t, u; /* temporary variables */
140 
141  k = (S->Sint).fftLen - 1;
142 
143  xAR = pA[0];
144  xAI = pA[1];
145 
146  pCoeff += 2 ;
147 
148  *pOut++ = 0.5f * ( xAR + xAI );
149  *pOut++ = 0.5f * ( xAR - xAI );
150 
151  pB = p + 2*k ;
152  pA += 2 ;
153 
154  while(k > 0u)
155  {
156  /* G is half of the frequency complex spectrum */
157  //for k = 2:N
158  // Xk(k) = 1/2 * (G(k) + conj(G(N-k+2)) + Tw(k)*( G(k) - conj(G(N-k+2))));
159  xBI = pB[1] ;
160  xBR = pB[0] ;
161  xAR = pA[0];
162  xAI = pA[1];
163 
164  twR = *pCoeff++;
165  twI = *pCoeff++;
166 
167  t1a = xAR - xBR ;
168  t1b = xAI + xBI ;
169 
170  r = twR * t1a;
171  s = twI * t1b;
172  t = twI * t1a;
173  u = twR * t1b;
174 
175  // real(tw * (xA - xB)) = twR * (xAR - xBR) - twI * (xAI - xBI);
176  // imag(tw * (xA - xB)) = twI * (xAR - xBR) + twR * (xAI - xBI);
177  *pOut++ = 0.5f * (xAR + xBR - r - s ); //xAR
178  *pOut++ = 0.5f * (xAI - xBI + t - u ); //xAI
179 
180  pA += 2;
181  pB -= 2;
182  k--;
183  }
184 
185 }
186 
326 float32_t * p, float32_t * pOut,
327 uint8_t ifftFlag)
328 {
329  arm_cfft_instance_f32 * Sint = &(S->Sint);
330  Sint->fftLen = S->fftLenRFFT / 2;
331 
332  /* Calculation of Real FFT */
333  if(ifftFlag)
334  {
335  /* Real FFT compression */
336  merge_rfft_f32(S, p, pOut);
337 
338  /* Complex radix-4 IFFT process */
339  arm_cfft_f32( Sint, pOut, ifftFlag, 1);
340  }
341  else
342  {
343  /* Calculation of RFFT of input */
344  arm_cfft_f32( Sint, p, ifftFlag, 1);
345 
346  /* Real FFT extraction */
347  stage_rfft_f32(S, p, pOut);
348  }
349 }
350 
void arm_cfft_f32(const arm_cfft_instance_f32 *S, float32_t *p1, uint8_t ifftFlag, uint8_t bitReverseFlag)
Processing function for the floating-point complex FFT.
Definition: arm_cfft_f32.c:574
float float32_t
32-bit floating-point type definition.
Definition: arm_math.h:407
arm_cfft_instance_f32 Sint
Definition: arm_math.h:2237
Instance structure for the floating-point RFFT/RIFFT function.
Definition: arm_math.h:2235
void stage_rfft_f32(arm_rfft_fast_instance_f32 *S, float32_t *p, float32_t *pOut)
Instance structure for the floating-point CFFT/CIFFT function.
Definition: arm_math.h:2141
void arm_rfft_fast_f32(arm_rfft_fast_instance_f32 *S, float32_t *p, float32_t *pOut, uint8_t ifftFlag)
Processing function for the floating-point real FFT.
void merge_rfft_f32(arm_rfft_fast_instance_f32 *S, float32_t *p, float32_t *pOut)
uint32_t ifftFlag
Definition: FFT.c:112