Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

FFT Examples

FFT Examples

How ist it possible to get the result plots of the FFT´s?
In the example" Modelica.Math.FastFourierTransform.Examples.RealFFT1" is the resulting plot shown in the dokumentation but if I open the resulting mat file there are just two different values and I can´t plot the same results.
Also if I try to use the"RealFFTBlock" and try to see the harmonics by the example "Modelica.Blocks.Examples.Rectifier6pulseFFT", there are only 0 values in my resulting mat file.

Can anyone explain me what I´m doing wrong?

Re: FFT Examples

Can someone pls help me and explain the given examples?

Re: FFT Examples

I'm having the same issue described below. When I run the example models under Modelica.Blocks.Examples.Rectifier6pulseFFT or Modelica.Blocks.Examples.Rectifier6pulseFFT I don't see any amplitude or phase data in the .mat output file. I don't change anything with the example files prior to running the simulations, and when I open the .mat file in octave I only get data in the first column (frequency). The amplitude and phase columns are all zeros.

I also tried running the RealFFT function contained in Modelica.Blocks on other rotational dynamics models I've created, and I get a similar output file. Has the RealFFT function worked for anyone else?

Re: FFT Examples

Hi there,

unfortunately I don't have a solution to the problem, I just experienced the same issues as you guys.

So I decided to implement a DFT on my own and I think I may found the issue of the realFFT example.

Have a look at the following basic example I implemented:

Code:


block DFT
  import Modelica.Constants.pi;

  parameter Integer N = 360 "Total number of samples";
 
  Integer iTick;//(start=0, fixed=true);
  Real y_buf[N];//(start=vector([6.5; fill(0, N - 1)]),each fixed=true);
 

algorithm

when sample(0, 0.1) then     
  iTick :=iTick + 1;
 
  if iTick >= 1 and iTick <= N then
    y_buf[iTick] := iTick;
  end if;
end when;

end DFT;

I copied some parts of the realFFT example to sample a simple sine function but it didn't work! No values were written into the y_buf array.
So tried to simply assign the value of "iTick" to the buffer array but it still doesn't work..

My guess is that it has something to do with the when environment together with the sample() function because the following example works fine:

Code:


block DFT
  import Modelica.Constants.pi;

  parameter Integer N = 360 "Total number of samples";
 
  //Integer iTick;//(start=0, fixed=true);
  Real y_buf[N];//(start=vector([6.5; fill(0, N - 1)]),each fixed=true);
 

algorithm

for i in 1:N loop
y_buf[i] := i;
end for;

end DFT;

So if anyone has an idea why the first example doesn't work but the second does it would be a great help for my work!

Hopefully I can contribute with this post to motivate the discussion about these issues.

Re: FFT Examples

I experimented a little bit with your sample code. The trick seems to be, to define y_buf as a discrete variable. The buffer will be filled then.

Code:


block bufferTest
  import Modelica.Constants.pi;

  parameter Integer N = 360 "Total number of samples";

  Integer iTick;
  discrete Real y_buf[N](each fixed = true);

initial algorithm
iTick := 0;

algorithm
when sample(0, 0.01) then     
  iTick :=iTick + 1;
  if iTick > 0 and iTick <= N then
    y_buf[iTick] := Modelica.Math.sin(time);
  end if;
end when;

equation

annotation(experiment(StartTime = 0, StopTime = 4));
end bufferTest;

This model runs in OMEdit and fills the y_buf.

I have attached a modified example RealFFT1, that provides the described results.

Regards Ulrich
RealFFT1-discretemo.zip

Edited by: ulrich1a - Oct-05-19 20:24:48
There are 0 guests and 0 other users also viewing this topic