OpenModelica


Forgot password? | Forgot username? | Register

How to plot Sin wave using only OMShell

How to plot Sin wave using only OMShell

Hi... I am new to modelica and right now I am struggling with OMShell... I figured ou how to plot signals when I load model created in OMEdit. But what I want to know is how to plot Sine wave for example, using only OMShell.

Thanks!

Administrator has disabled public posting. Please login or register in order to proceed.

Re: How to plot Sin wave using only OMShell

You need to call plot function after simulating the model.
https://build.openmodelica.org/Document … .plot.html

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: How to plot Sin wave using only OMShell

Well ok.. how do I create simple Sine model using OMShell then? I can't get it to work..

Administrator has disabled public posting. Please login or register in order to proceed.

Re: How to plot Sin wave using only OMShell

You could create your model in any text editor, save the file as .mo and then load it in OMShell.

Code:

loadFile("Sine.mo")

simulate(Sine)
plot(x)

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: How to plot Sin wave using only OMShell

So if I understand this.. I can't just simply create variable x:= sin(x*y*z) and then simulate(x) and plot(x) right?

Administrator has disabled public posting. Please login or register in order to proceed.

Re: How to plot Sin wave using only OMShell

This is how it is done in matlab and I am asking if it is possible to do in Shell. 

%% Time specifications:
   Fs = 8000;                   % samples per second
   dt = 1/Fs;                   % seconds per sample
   StopTime = 0.25;             % seconds
   t = (0:dt:StopTime-dt)';     % seconds
   %% Sine wave:
   Fc = 60;                     % hertz
   x = cos(2*pi*Fc*t);
   % Plot the signal versus time:
   figure;
   plot(t,x);
   xlabel('time (in seconds)');
   title('Signal versus Time');

Administrator has disabled public posting. Please login or register in order to proceed.

Re: How to plot Sin wave using only OMShell

You need to create classes in Modelica.

Create a file called Sine.mo with the following contents,

Code:

model Sine "Generate sine signal"

  parameter Real amplitude=1 "Amplitude of sine wave";
  parameter Real freqHz(start=1) "Frequency of sine wave";
  parameter Real phase=0 "Phase of sine wave";
  parameter Real offset=0 "Offset of output signal";
  parameter Real startTime=0 "Output = offset for time < startTime";
  Real y;
protected
  constant Real pi=Modelica.Constants.pi;

equation
  y = offset + (if time < startTime then 0 else amplitude*
    Modelica.Math.sin(2*pi*freqHz*(time - startTime) + phase));
end Sine;

Call the following command in OMShell,

Code:

loadModel(Modelica)

loadFile("Sine.mo")
simulate(Sine)
plot(y)

You can read more about Modelica here https://openmodelica.org/useresresource … ca-courses

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: How to plot Sin wave using only OMShell

Oh ok Thank you very much! also not to bother you much more but is it possible to input some kind of audio (speech,  song) and then plot that?

Edit: Not using only Shell but OMEdit also.

Edited by: TobeyHarris - Feb-02-17 12:11:13
Administrator has disabled public posting. Please login or register in order to proceed.

Re: How to plot Sin wave using only OMShell

I have no idea about it.
Maybe someone else can help on this.

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: How to plot Sin wave using only OMShell

If you can save the audio data in an accessible file format, you could then read it in with CombiTable1D and then can plot the data. 

Administrator has disabled public posting. Please login or register in order to proceed.

Re: How to plot Sin wave using only OMShell

dersh wrote:


If you can save the audio data in an accessible file format, you could then read it in with CombiTable1D and then can plot the data. 

I see how that should work... but even if I had the file to load table from. It won't let me choose the file path. It is grayed out no matter what I do.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: How to plot Sin wave using only OMShell

It looks like there was a missing feature in OMEdit to do that edit in the diagram view, but you could still do it in the text view.  See here:  Title  That link also helps explain how to use tables. 
I don't see that problem now, as I can edit the file names, so I think that it has been fixed in newer versions of OMEdit. 

Administrator has disabled public posting. Please login or register in order to proceed.
There are 0 guests and 0 other users also viewing this topic
You are here: