Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Gaussian pulse signal source #4017

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
improved GaussianPulse to enable a series of pulses
  • Loading branch information
AHaumer committed Jul 31, 2022
commit dec9cad86052741e6092647e83acd18345d5803e
19 changes: 17 additions & 2 deletions Modelica/Blocks/Sources.mo
Original file line number Diff line number Diff line change
Expand Up @@ -814,10 +814,21 @@ The Real output y is a pulse signal:
parameter Real amplitude=1 "Amplitude of pulse";
parameter SI.Time duration(final min=Modelica.Constants.small)=0.25
"Equivalent pulse duration";
parameter SI.Time period(final min=Modelica.Constants.small)=1
"Time for one period";
parameter Integer nperiod=1
"Number of periods (< 0 means infinite number of periods)";
parameter Real offset=0 "Offset of output signal y";
parameter SI.Time startTime=0.5 "Time instant of pulse maximum";
protected
SI.Time t0(start=startTime, fixed=true);
initial equation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be deleted.

equation
y = offset + amplitude*exp(-pi*((time - startTime)/duration)^2);
y = offset + (if nperiod==0 then 0 else amplitude*exp(-pi*((time - t0)/duration)^2));
when time >= pre(t0) + period/2 then
t0 = pre(t0) +
(if nperiod>0 and (time - startTime)>=(nperiod - 0.5)*period then 0 else period);
end when;
annotation (
Icon(coordinateSystem(
preserveAspectRatio=true,
Expand Down Expand Up @@ -845,12 +856,16 @@ The Real output y is a pulse signal:
smooth=Smooth.Bezier)}),
Documentation(info="<html>
<p>
The Real output y is a (single) Gaussian pulse signal: <code>y = offset + amplitude*exp(-&pi;*((t-startTime)/duration)<sup>2</sup>)</code>
The Real output y is a series of Gaussian pulses, the first pulse is defined by: <code>y = offset + amplitude*exp(-&pi;*((t-startTime)/duration)<sup>2</sup>)</code>
</p>
<p>
Parameter <code>startTime</code> is the time instant when the pulse maximum occurs.
Parameter <code>duration</code> is the duration of an equivalent rectangular pulse with same amplitude and area under the pulse.
</p>
<p>
The Gaussian pulse is repeated <code>nperiod</code> times, with a time span of <code>period</code> between the pulses.
The next pulse supersedes the previous pulse.
</p>
</html>"));
end GaussianPulse;

Expand Down
12 changes: 7 additions & 5 deletions Modelica/Blocks/package.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1578,14 +1578,16 @@ The output is constant from the beginning.

model ComparePulses "Compare Gaussian and rectangular pulse"
extends Modelica.Icons.Example;
Modelica.Blocks.Sources.GaussianPulse gaussianPulse(duration=1, startTime=2)
Modelica.Blocks.Sources.GaussianPulse gaussianPulse(duration=1,
period=4, startTime=2)
annotation (Placement(transformation(extent={{-30,10},{-10,30}})));
Modelica.Blocks.Continuous.Integrator integrator1
annotation (Placement(transformation(extent={{10,10},{30,30}})));
Modelica.Blocks.Sources.Pulse pulse(
amplitude=gaussianPulse.amplitude,
period=2*gaussianPulse.duration,
nperiod=1,
width=gaussianPulse.duration/gaussianPulse.period*100,
period=gaussianPulse.period,
nperiod=gaussianPulse.nperiod,
offset=gaussianPulse.offset,
startTime=gaussianPulse.startTime - gaussianPulse.duration/2)
annotation (Placement(transformation(extent={{-30,-30},{-10,-10}})));
Expand All @@ -1600,10 +1602,10 @@ The output is constant from the beginning.
smooth=Smooth.Bezier));
annotation (experiment(
StopTime=4,
Interval=0.0001,
Interval=0.001,
Tolerance=1e-06), Documentation(info="<html>
<p>
Compare a Gaussian pulse with a rectangular pulse with same amplitude and same area under the pulse.
Compare a single Gaussian pulse with a single rectangular pulse with same amplitude and same area under the pulse.
</p>
</html>"));
end ComparePulses;
Expand Down