modelRealFFT1
Example demonstrating the use of an FFT calculation during simulation (and storing both amplitudes and phases on file)
Extends from Modelica.Icons.Example (Icon for runnable examples).
Information
In this example the signal y
y = 5 + 3*sin(2*pi*f1) + 1.5*cos(2*pi*f2)
is sampled and an FFT is computed from the sampled signal (default: f1 = 2 Hz, f2 = 3 Hz). In the public part the FFT is stored up to f_max (internally in the protected part the FFT is stored up to 5*f_max). With the default values for f_max (= 4 Hz) and f_resolution (= 0.2 Hz), the following results are achieved:
fi[0] = 0, Ai[0] = 5; // mean value of signal fi[11] = 2, Ai[11] = 3; // frequency/amplitude of sine fi[16] = 3, Ai[16] = 1.5; // frequency/amplitude of cosine
A plot of the resulting FFT is shown in the next image:
Note, phases of small amplitudes (= smaller as 0.0001*maximalAmplitude) are explicitly set to zero, since the corresponding "phase" is numerical noise (and would just be confusing). Furthermore, note that the FFT phases are with respect to a cos(..) signal.
Parameters
| Type | Name | Default | Description |
|---|---|---|---|
| SI.Frequency | f_max | 4 | Maximum frequency of interest |
| SI.Frequency | f_resolution | 0.2 | Frequency resolution |
| SI.Frequency | f1 | 2 | Frequency of sine |
| SI.Frequency | f2 | 3 | Frequency of cosine |
| String | FFT_resultFileName | "RealFFT1_resultFFT.mat" | File where FFT will be stored as [f,A,Phi], with f in [Hz] and A the amplitudes and Phi the phases in [rad] |
| Integer | nfi | max(1, min(integer(ceil(f_max/f_resolution)) + 1, nf)) | Number of frequency points of the interested frequency range (only up to f_max) |
| SI.Frequency[nfi] | fi | FFT frequencies of interested frequency points |
Components
| Type | Name | Default | Description |
|---|---|---|---|
| Real | y | Signal from which FFT is computed | |
| Real[nfi] | Ai | FFT amplitudes of interested frequency points | |
| Real[nfi] | Phii | FFT phases of interested frequency points | |
| Integer | info | Information flag from FFT computation; = 0: FFT successfully computed |
Revisions
| Date | Description |
|---|---|
| Nov. 29, 2015 | Initial version implemented by Martin R. Kuhn and Martin Otter (DLR Institute of System Dynamics and Control. |