Return amplitude and phase vectors for a real FFT

Wolfram Language



This information is part of the Modelica Standard Library maintained by the Modelica Association.


(info, amplitudes, phases) = realFFT(u);


The input argument of this function is a Real vector u. size(u,1) must be even. An efficient computation is performed, if size(u,1) = 2^a*3^b*5^c (a,b,c Integer ≥ 0). An appropriate length of vector u can be computed with function realFFTsamplePoints. Function realFFT computes a real FFT (Fast Fourier Transform) of u and returns the result in form of the outputs amplitudes and phases. Argument info provides additional information:

   info = 0: Successful FFT computation.
   info = 1: size(u,1) is not even.
   info = 3: Another error.

Note, in the original publication about the efficient computation of FFT (Cooley and Tukey, 1965), the number of sample points must be 2^a. However, all newer FFT algorithms do not have this strong restriction and especially not the open source software KissFFT from Mark Borgerding used in this function.

The function returns the FFT such that amplitudes[1] is the mean value of u (= sum(u)/size(u,1)), and amplitudes[i] is the amplitude of a sine-function at the i-th frequency.


Mark Borgerding (2010):
KissFFT, version 1.3.0. http://sourceforge.net/projects/kissfft/.
James W. Cooley, John W. Tukey (1965):
An algorithm for the machine calculation of complex Fourier series. Math. Comput. 19: 297-301. doi:10.2307/2003354.
Martin R. Kuhn, Martin Otter, Tim Giese (2015):
Model Based Specifications in Aircraft Systems Design. Modelica 2015 Conference, Versailles, France, pp. 491-500, Sept.23-25, 2015. Download from: http://www.ep.liu.se/ecp/118/053/ecp15118491.pdf


(info, A) = realFFT({0,0.1,0.2,0.4,0.5, 0.6})

See also Examples.RealFFT1 which is a complete example where an FFT is computed during simulation and stored on file.

See also

realFFTinfo, realFFTsamplePoints, realFFTwriteToFile


(info, amplitudes, phases) = realFFT(u, nfi)

Inputs (2)


Type: Real[:]

Description: Signal for which FFT shall be computed (size(nu,1) MUST be EVEN and should be an integer multiple of 2,3,5, that is size(nu,1) = 2^a*3^b*5^c, with a,b,c Integer >= 0)


Type: Integer

Description: Number of frequency points that shall be returned in amplitudes and phases (typically: nfi = max(1,min(integer(ceil(f_max/f_resolution))+1,nf))); the maximal possible value is nfi=div(size(u,1),2)+1)

Outputs (3)


Type: Integer

Description: Information flag (0: FFT computed, 1: nu is not even, 3: another error)


Type: Real[nfi]

Description: Amplitudes of FFT


Type: Real[nfi]

Description: Phases of FFT in [deg]