- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » How to plot Sin wave using only OMShell
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!
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.
- adeas
- 454 Posts
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.
- adeas
- 454 Posts
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');
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.
- adeas
- 454 Posts
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.
Re: How to plot Sin wave using only OMShell
I have no idea about it.
Maybe someone else can help on this.
Adeel.
- adeas
- 454 Posts
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.
- dersh
- 66 Posts
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.
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.
- dersh
- 66 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » How to plot Sin wave using only OMShell