success = realFFTwriteToFile(t_computed, fileName, f_max, amplitudes, phases, format);
This functions stores the result of an FFT computation on file, so that it can be easily plotted. amplitudes and phases are the vectors that hold the amplitudes and phases values of an FFT computation. If the size of the phases vector is zero, no phases will be stored on file. Otherwise, phases must have the same dimension as the amplitudes vector. The frequency vector f is constructed within the function from the dimension of the amplitudes vector and the information that amplitudes[end] is at frequency f_max. The format argument defines the file format (for details see writeRealMatrix). Argument t_computed is the actual time instant when the FFT was computed. It is used in the print message after the result was stored on file.
The matrix on file has the following structure:
See detailed example model: Examples.RealFFT1.
realFFTinfo, realFFTsamplePoints, realFFT
function realFFTwriteToFile extends Modelica.Icons.Function; import Modelica.Utilities.Streams.print; import Modelica.SIunits.Conversions.to_deg; import Modelica.Utilities.Streams.writeRealMatrix; input Real t_computed "Time instant at which the FFT was computed"; input String fileName "File where FFT shall be stored (if it exists, it is deleted and then re-created)"; input Modelica.SIunits.Frequency f_max "Maximum frequency"; input Real amplitudes[:] "Amplitudes of FFT"; input Real phases[:] = fill(0.0, 0) "Phases of FFT (either provide no argument, or a vector with the same length as amplitudes)"; input String format = "4" "MATLAB MAT-file version: \"4\" -> v4, \"6\" -> v6, \"7\" -> v7" annotation( choices(choice = "4" "MATLAB v4 MAT-file", choice = "6" "MATLAB v6 MAT-file", choice = "7" "MATLAB v7 MAT-file")); output Boolean success "true if successful"; end realFFTwriteToFile;