realFFTReturn amplitude and phase vectors for a real FFT |
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.
(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.
u |
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) |
---|---|
nfi |
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) |
info |
Type: Integer Description: Information flag (0: FFT computed, 1: nu is not even, 3: another error) |
---|---|
amplitudes |
Type: Real[nfi] Description: Amplitudes of FFT |
phases |
Type: Real[nfi] Description: Phases of FFT in [deg] |