-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Modelica Noise with AdvancedNoise
- Loading branch information
Showing
185 changed files
with
9,092 additions
and
0 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
Modelica_Noise 1.0 Beta.1/Blocks/Examples/NoiseExamples/ActuatorWithNoise.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
within Modelica_Noise.Blocks.Examples.NoiseExamples; | ||
model ActuatorWithNoise | ||
"Demonstrates how to model measurement noise in an actuator" | ||
extends Modelica.Icons.Example; | ||
Utilities.Parts.MotorWithCurrentControl Motor | ||
annotation (Placement(transformation(extent={{-86,-10},{-66,10}}))); | ||
Utilities.Parts.Controller controller | ||
annotation (Placement(transformation(extent={{0,60},{20,80}}))); | ||
Modelica.Blocks.Sources.Step Speed(startTime=0.5, height=50) | ||
annotation (Placement(transformation(extent={{-72,66},{-52,86}}))); | ||
Modelica.Mechanics.Rotational.Components.Gearbox gearbox( | ||
lossTable=[0,0.85,0.8,0.1,0.1], | ||
c=1e6, | ||
d=1e4, | ||
ratio=10, | ||
w_rel(fixed=true), | ||
b=0.0017453292519943, | ||
phi_rel(fixed=true)) | ||
annotation (Placement(transformation(extent={{-60,-10},{-40,10}}))); | ||
Modelica.Mechanics.Translational.Components.IdealGearR2T idealGearR2T(ratio= | ||
300) annotation (Placement(transformation(extent={{-32,-10},{-12,10}}))); | ||
Modelica.Mechanics.Translational.Components.Mass mass(m=100) | ||
annotation (Placement(transformation(extent={{50,-10},{70,10}}))); | ||
Modelica.Mechanics.Translational.Sources.ConstantForce constantForce( | ||
f_constant=10000) annotation (Placement(transformation( | ||
extent={{10,-10},{-10,10}}, | ||
origin={86,0}))); | ||
Modelica.Blocks.Nonlinear.SlewRateLimiter slewRateLimiter(Rising=50) | ||
annotation (Placement(transformation(extent={{-40,66},{-20,86}}))); | ||
Modelica.Mechanics.Translational.Components.Mass rodMass(m=3) | ||
annotation (Placement(transformation(extent={{-4,-10},{16,10}}))); | ||
Modelica.Mechanics.Translational.Components.SpringDamper elastoGap(c=1e8, d= | ||
1e5, | ||
v_rel(fixed=true), | ||
s_rel(fixed=true)) | ||
annotation (Placement(transformation(extent={{22,-10},{42,10}}))); | ||
inner Noise.GlobalSeed globalSeed(enableNoise=true) | ||
annotation (Placement(transformation(extent={{60,60},{80,80}}))); | ||
equation | ||
connect(controller.y1, Motor.iq_rms1) annotation (Line( | ||
points={{21,70},{30,70},{30,20},{-96,20},{-96,6},{-88,6}}, | ||
color={0,0,127})); | ||
connect(Motor.phi, controller.positionMeasured) annotation (Line( | ||
points={{-71,8},{-66,8},{-66,52},{-12,52},{-12,64},{-2,64},{-2,64}}, | ||
color={0,0,127})); | ||
connect(Motor.flange, gearbox.flange_a) annotation (Line( | ||
points={{-66,0},{-60,0}})); | ||
connect(gearbox.flange_b, idealGearR2T.flangeR) annotation (Line( | ||
points={{-40,0},{-32,0}})); | ||
connect(constantForce.flange, mass.flange_b) annotation (Line( | ||
points={{76,0},{70,0}}, | ||
color={0,127,0})); | ||
connect(Speed.y, slewRateLimiter.u) annotation (Line( | ||
points={{-51,76},{-42,76}}, | ||
color={0,0,127})); | ||
connect(slewRateLimiter.y, controller.positionReference) annotation (Line( | ||
points={{-19,76},{-2,76}}, | ||
color={0,0,127})); | ||
connect(rodMass.flange_a, idealGearR2T.flangeT) annotation (Line( | ||
points={{-4,0},{-12,0}}, | ||
color={0,127,0})); | ||
connect(rodMass.flange_b, elastoGap.flange_a) annotation (Line( | ||
points={{16,0},{22,0}}, | ||
color={0,127,0})); | ||
connect(elastoGap.flange_b, mass.flange_a) annotation (Line( | ||
points={{42,0},{50,0}}, | ||
color={0,127,0})); | ||
annotation ( | ||
experiment(StopTime=8, Interval = 0.01, Tolerance=1e-005), | ||
Documentation(info="<html> | ||
<p> | ||
This example models an actuator with a noisy sensor (which is in the Motor component): | ||
</p> | ||
<blockquote> | ||
<p> | ||
<img src=\"modelica://Modelica_Noise/Resources/Images/Blocks/Examples/NoiseExamples/ActuatorNoiseDiagram.png\"/> | ||
</p></blockquote> | ||
<p> | ||
The drive train consists of a synchronous motor with a current controller (= Motor) and a gear box. | ||
The gearbox drives a rod through a linear translation model. Softly attached to the rod is | ||
another mass representing the actual actuator (= mass). The actuator is loaded with a constant force. | ||
</p> | ||
<p> | ||
The whole drive is steered by a rate limited speed step command through a controller model. | ||
In the Motor the shaft angle is measured and this measurement signal is modelled by adding | ||
additive noise to the Motor angle. | ||
</p> | ||
<p> | ||
In the following figure, the position of the actuator and the Motor output torque are | ||
shown with and without noise. The noise is not very strong, such that it has no visible effect | ||
on the position of the actuator. The effect of the noise can be seen in the Motor torque. | ||
</p> | ||
<blockquote><p> | ||
<img src=\"modelica://Modelica_Noise/Resources/Images/Blocks/Examples/NoiseExamples/ActuatorNoise.png\"/> | ||
</p></blockquote> | ||
<p> | ||
Note, the noise in all components can be easily switched off by setting parameter | ||
enableNoise = false in the globalSeed component. | ||
</p> | ||
</html>", revisions="<html> | ||
<p> | ||
<table border=1 cellspacing=0 cellpadding=2> | ||
<tr><th>Date</th> <th align=\"left\">Description</th></tr> | ||
<tr><td valign=\"top\"> June 22, 2015 </td> | ||
<td valign=\"top\"> | ||
<table border=0> | ||
<tr><td valign=\"top\"> | ||
<img src=\"modelica://Modelica_Noise/Resources/Images/Blocks/Noise/dlr_logo.png\"> | ||
</td><td valign=\"bottom\"> | ||
Initial version implemented by | ||
A. Klöckner, F. v.d. Linden, D. Zimmer, M. Otter.<br> | ||
<a href=\"http://www.dlr.de/rmc/sr/en\">DLR Institute of System Dynamics and Control</a> | ||
</td></tr></table> | ||
</td></tr> | ||
</table> | ||
</p> | ||
</html>")); | ||
end ActuatorWithNoise; |
105 changes: 105 additions & 0 deletions
105
Modelica_Noise 1.0 Beta.1/Blocks/Examples/NoiseExamples/AutomaticSeed.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
within Modelica_Noise.Blocks.Examples.NoiseExamples; | ||
model AutomaticSeed | ||
"Demonstrates noise with startTime and automatic local seed for UniformNoise" | ||
import Modelica_Noise; | ||
extends Modelica.Icons.Example; | ||
parameter Real startTime = 0.5 "Start time of noise"; | ||
parameter Real y_off = -1.0 "Output of block before startTime"; | ||
|
||
inner Modelica_Noise.Blocks.Noise.GlobalSeed globalSeed(useAutomaticSeed=false, enableNoise=true) | ||
annotation (Placement(transformation(extent={{60,60},{80,80}}))); | ||
|
||
Modelica_Noise.Blocks.Noise.UniformNoise automaticSeed1( | ||
samplePeriod=0.01, | ||
startTime=startTime, | ||
y_off=y_off, | ||
y_min=-1, y_max=3) | ||
annotation (Placement(transformation(extent={{-60,20},{-40,40}}))); | ||
Modelica_Noise.Blocks.Noise.UniformNoise automaticSeed2( | ||
samplePeriod=0.01, | ||
startTime=startTime, | ||
y_off=y_off,y_min=-1, y_max=3) | ||
annotation (Placement(transformation(extent={{-60,-20},{-40,0}}))); | ||
Modelica_Noise.Blocks.Noise.UniformNoise automaticSeed3( | ||
samplePeriod=0.01, | ||
startTime=startTime, | ||
y_off=y_off, y_min=-1, y_max=3) | ||
annotation (Placement(transformation(extent={{-60,-60},{-40,-40}}))); | ||
Modelica_Noise.Blocks.Noise.UniformNoise manualSeed1( | ||
samplePeriod=0.01, | ||
startTime=startTime, | ||
y_off=y_off, | ||
useAutomaticLocalSeed=false, | ||
fixedLocalSeed=1,y_min=-1, y_max=3, | ||
enableNoise=true) | ||
annotation (Placement(transformation(extent={{0,20},{20,40}}))); | ||
Modelica_Noise.Blocks.Noise.UniformNoise manualSeed2( | ||
samplePeriod=0.01, | ||
startTime=startTime, | ||
y_off=y_off, | ||
useAutomaticLocalSeed=false, | ||
fixedLocalSeed=2,y_min=-1, y_max=3) | ||
annotation (Placement(transformation(extent={{0,-20},{20,0}}))); | ||
Modelica_Noise.Blocks.Noise.UniformNoise manualSeed3( | ||
samplePeriod=0.01, | ||
startTime=startTime, | ||
y_off=y_off, | ||
useAutomaticLocalSeed=false,y_min=-1, y_max=3, | ||
fixedLocalSeed=3) | ||
annotation (Placement(transformation(extent={{0,-60},{20,-40}}))); | ||
annotation (experiment(StopTime=2), Documentation(info="<html> | ||
<p> | ||
This example demonstrates manual and automatic seed selection of | ||
<a href=\"Modelica_Noise.Blocks.Noise.UniformNoise\">UniformNoise</a> blocks, as well | ||
as starting the noise at startTime = 0.5 s with an output value of y = -1 before this | ||
time. All noise blocks in this example generate uniform noise in the | ||
band y_min=-1 .. y_max=3 with samplePeriod = 0.01 s. | ||
</p> | ||
<p> | ||
The blocks automaticSeed1, automaticSeed2, automaticSeed3 use the default | ||
option to automatically initialize the pseudo random number generators | ||
of the respective block. As a result, different noise is generated, see next | ||
diagram: | ||
</p> | ||
<p><blockquote> | ||
<img src=\"modelica://Modelica_Noise/Resources/Images/Blocks/Examples/NoiseExamples/AutomaticSeed1.png\"> | ||
</blockquote></p> | ||
<p> | ||
The blocks manualSeed1, manualSeed2, manualSeed3 use manual selection of the local seed | ||
(useAutomaticLocalSeed = false). They use a fixedLocalSeed of 1, 2, and 3 respectively. | ||
Again, different noise is generated, see next diagram: | ||
</p> | ||
<p><blockquote> | ||
<img src=\"modelica://Modelica_Noise/Resources/Images/Blocks/Examples/NoiseExamples/AutomaticSeed2.png\"> | ||
</blockquote></p> | ||
<p> | ||
Try to set fixedLocalSeed = 1 in block manualSeed2. As a result, the blocks manualSeed1 and | ||
manualSeed2 will produce exactly the same noise. | ||
</p> | ||
</html>", revisions="<html> | ||
<p> | ||
<table border=1 cellspacing=0 cellpadding=2> | ||
<tr><th>Date</th> <th align=\"left\">Description</th></tr> | ||
<tr><td valign=\"top\"> June 22, 2015 </td> | ||
<td valign=\"top\"> | ||
<table border=0> | ||
<tr><td valign=\"top\"> | ||
<img src=\"modelica://Modelica_Noise/Resources/Images/Blocks/Noise/dlr_logo.png\"> | ||
</td><td valign=\"bottom\"> | ||
Initial version implemented by | ||
A. Klöckner, F. v.d. Linden, D. Zimmer, M. Otter.<br> | ||
<a href=\"http://www.dlr.de/rmc/sr/en\">DLR Institute of System Dynamics and Control</a> | ||
</td></tr></table> | ||
</td></tr> | ||
</table> | ||
</p> | ||
</html>")); | ||
end AutomaticSeed; |
71 changes: 71 additions & 0 deletions
71
Modelica_Noise 1.0 Beta.1/Blocks/Examples/NoiseExamples/Densities.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
within Modelica_Noise.Blocks.Examples.NoiseExamples; | ||
model Densities | ||
"Demonstrates how to compute distribution densities (= Probability Density Function)" | ||
extends Modelica.Icons.Example; | ||
|
||
Utilities.UniformDensity | ||
uniformDensity(u_min=-4, u_max=4) | ||
annotation (Placement(transformation(extent={{10,20},{30,40}}))); | ||
Modelica.Blocks.Sources.Clock clock | ||
annotation (Placement(transformation(extent={{-80,10},{-60,30}}))); | ||
Modelica.Blocks.Sources.Constant const(k=-10) | ||
annotation (Placement(transformation(extent={{-80,-30},{-60,-10}}))); | ||
Modelica.Blocks.Math.Add add | ||
annotation (Placement(transformation(extent={{-46,-10},{-26,10}}))); | ||
Utilities.NormalDensity | ||
normalDensity(mu=0, sigma=2) | ||
annotation (Placement(transformation(extent={{10,-10},{30,10}}))); | ||
Utilities.WeibullDensity | ||
weibullDensity(lambda=3, k=1.5) | ||
annotation (Placement(transformation(extent={{10,-40},{30,-20}}))); | ||
equation | ||
connect(clock.y, add.u1) annotation (Line( | ||
points={{-59,20},{-53.5,20},{-53.5,6},{-48,6}}, | ||
color={0,0,127})); | ||
connect(const.y, add.u2) annotation (Line( | ||
points={{-59,-20},{-54,-20},{-54,-6},{-48,-6}}, | ||
color={0,0,127})); | ||
connect(add.y, uniformDensity.u) annotation (Line( | ||
points={{-25,0},{-14,0},{-14,30},{8,30}}, | ||
color={0,0,127})); | ||
connect(add.y, normalDensity.u) annotation (Line( | ||
points={{-25,0},{8,0}}, | ||
color={0,0,127})); | ||
connect(add.y, weibullDensity.u) annotation (Line( | ||
points={{-25,0},{-14,0},{-14,-30},{8,-30}}, | ||
color={0,0,127})); | ||
annotation (experiment(StopTime=20, Interval=2e-2), | ||
Documentation(info="<html> | ||
<p> | ||
This example demonstrates how to compute the probability density functions (pdfs) of | ||
various distributions. | ||
In the following diagram simulations results for the uniform, normal, and Weibull distribution | ||
are shown. The outputs of the blocks are the pdfs that are plotted over one of the | ||
inputs: | ||
</p> | ||
<p><blockquote> | ||
<img src=\"modelica://Modelica_Noise/Resources/Images/Blocks/Examples/NoiseExamples/Densities.png\"> | ||
</blockquote></p> | ||
</html>", revisions="<html> | ||
<p> | ||
<table border=1 cellspacing=0 cellpadding=2> | ||
<tr><th>Date</th> <th align=\"left\">Description</th></tr> | ||
<tr><td valign=\"top\"> June 22, 2015 </td> | ||
<td valign=\"top\"> | ||
<table border=0> | ||
<tr><td valign=\"top\"> | ||
<img src=\"modelica://Modelica_Noise/Resources/Images/Blocks/Noise/dlr_logo.png\"> | ||
</td><td valign=\"bottom\"> | ||
Initial version implemented by | ||
A. Klöckner, F. v.d. Linden, D. Zimmer, M. Otter.<br> | ||
<a href=\"http://www.dlr.de/rmc/sr/en\">DLR Institute of System Dynamics and Control</a> | ||
</td></tr></table> | ||
</td></tr> | ||
</table> | ||
</p> | ||
</html>")); | ||
end Densities; |
62 changes: 62 additions & 0 deletions
62
Modelica_Noise 1.0 Beta.1/Blocks/Examples/NoiseExamples/Distributions.mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
within Modelica_Noise.Blocks.Examples.NoiseExamples; | ||
model Distributions "Demonstrates noise with different types of distributions" | ||
extends Modelica.Icons.Example; | ||
parameter Modelica.SIunits.Period samplePeriod=0.02 | ||
"Sample period of all blocks"; | ||
parameter Real y_min = -1 "Minimum value of band for random values"; | ||
parameter Real y_max = 3 "Maximum value of band for random values"; | ||
inner Noise.GlobalSeed globalSeed(useAutomaticSeed=false) | ||
annotation (Placement(transformation(extent={{40,60},{60,80}}))); | ||
|
||
Integer n=if time < 0.5 then 12 else 2; | ||
|
||
Noise.UniformNoise uniformNoise( | ||
useAutomaticLocalSeed=false, | ||
fixedLocalSeed=1, | ||
samplePeriod=samplePeriod,y_min=y_min, y_max=y_max) | ||
annotation (Placement(transformation(extent={{-60,70},{-40,90}}))); | ||
Noise.TruncatedNormalNoise truncatedNormalNoise( | ||
useAutomaticLocalSeed=false, | ||
fixedLocalSeed=1, | ||
samplePeriod=samplePeriod, y_min=y_min, y_max=y_max) | ||
annotation (Placement(transformation(extent={{-60,20},{-40,40}}))); | ||
annotation (experiment(StopTime=2), Documentation(info="<html> | ||
<p> | ||
This example demonstrates different noise distributions methods that can be selected | ||
for a Noise block. Both noise blocks use samplePeriod = 0.02 s, y_min=-1, y_max=3, and have | ||
identical fixedLocalSeed. This means that the same random numbers are drawn for the blocks. | ||
However, the random numbers are differently transformed according to the selected distributions | ||
(uniform and truncated normal distribution), and therefore the blocks have different output values. | ||
Simulation results are shown in the next diagram: | ||
</p> | ||
<p><blockquote> | ||
<img src=\"modelica://Modelica_Noise/Resources/Images/Blocks/Examples/NoiseExamples/Distributions.png\"> | ||
</blockquote></p> | ||
<p> | ||
As can be seen, uniform noise is distributed evenly between -1 and 3, and | ||
truncated normal distriution has more values centered around the mean value 1. | ||
</p> | ||
</html>", revisions="<html> | ||
<p> | ||
<table border=1 cellspacing=0 cellpadding=2> | ||
<tr><th>Date</th> <th align=\"left\">Description</th></tr> | ||
<tr><td valign=\"top\"> June 22, 2015 </td> | ||
<td valign=\"top\"> | ||
<table border=0> | ||
<tr><td valign=\"top\"> | ||
<img src=\"modelica://Modelica_Noise/Resources/Images/Blocks/Noise/dlr_logo.png\"> | ||
</td><td valign=\"bottom\"> | ||
Initial version implemented by | ||
A. Klöckner, F. v.d. Linden, D. Zimmer, M. Otter.<br> | ||
<a href=\"http://www.dlr.de/rmc/sr/en\">DLR Institute of System Dynamics and Control</a> | ||
</td></tr></table> | ||
</td></tr> | ||
</table> | ||
</p> | ||
</html>")); | ||
end Distributions; |
Oops, something went wrong.