block ContinuousMean "Calculates the empirical expectation (mean) value of its input signal"
extends Modelica.Blocks.Icons.Block;
parameter Modelica.SIunits.Time t_eps(min = 100 * Modelica.Constants.eps) = 1e-7 "Mean value calculation starts at startTime + t_eps"
annotation (Dialog(group = "Advanced"));
Modelica.Blocks.Interfaces.RealInput u "Noisy input signal"
annotation (Placement(transformation(extent = {
{-140, -20},
{-100, 20}})));
Modelica.Blocks.Interfaces.RealOutput y "Expectation (mean) value of the input signal"
annotation (Placement(transformation(extent = {
{100, -10},
{120, 10}})));
protected
Real mu "Internal integrator variable";
parameter Real t_0(fixed = false) "Start time";
initial equation
mu = u;
t_0 = time;
equation
y = noEvent(if t_0 + t_eps <= time then mu else u);
der(mu) = noEvent(if t_0 + t_eps <= time then (u - mu) / (time - t_0) else 0);
annotation (
Documentation(
revisions = "<html>\n<table border=1 cellspacing=0 cellpadding=2>\n<tr><th>Date</th> <th align=\"left\">Description</th></tr>\n\n<tr><td> June 22, 2015 </td>\n <td>\n\n<table border=0>\n<tr><td>\n <img src=\"modelica://Modelica/Resources/Images/Blocks/Noise/dlr_logo.png\">\n</td><td valign=\"bottom\">\n Initial version implemented by\n A. Klöckner, F. v.d. Linden, D. Zimmer, M. Otter.<br>\n <a href=\"http://www.dlr.de/rmc/sr/en\">DLR Institute of System Dynamics and Control</a>\n</td></tr></table>\n</td></tr>\n\n</table>\n</html>",
info = "<html>\n<p>This block continuously calculates the mean value of its input signal. It uses the function:</p>\n<blockquote>\n<pre> integral( u over time)\ny = ----------------------\n time - startTime</pre>\n</blockquote>\n<p>This can be used to determine the empirical expectation value of a random signal, such as generated by the <a href=\"modelica://Modelica.Blocks.Noise\">Noise</a> blocks.</p>\n<p>The parameter t_eps is used to guard against division by zero (the mean value computation\nstarts at <<em>simulation start time</em>> + t_eps and before that time instant y = u).</p>\n<p>See also the <a href=\"modelica://Modelica.Blocks.Math.Mean\">Mean</a> block for a sampled implementation.</p>\n\n<p>\nThis block is demonstrated in the examples\n<a href=\"modelica://Modelica.Blocks.Examples.NoiseExamples.UniformNoiseProperties\">UniformNoiseProperties</a> and\n<a href=\"modelica://Modelica.Blocks.Examples.NoiseExamples.NormalNoiseProperties\">NormalNoiseProperties</a>.\n</p>\n</html>"),
Icon(
coordinateSystem(
preserveAspectRatio = false,
extent = {
{-100, -100},
{100, 100}}),
graphics = {
Polygon(
points = {
{94, 0},
{72, 8},
{72, -8},
{94, 0}},
lineColor = {192, 192, 192},
fillColor = {192, 192, 192},
fillPattern = FillPattern.Solid),
Line(
points = {
{-86, 0},
{72, 0}},
color = {192, 192, 192}),
Line(
points = {
{-76, 68},
{-76, -80}},
color = {192, 192, 192}),
Polygon(
points = {
{-76, 90},
{-84, 68},
{-68, 68},
{-76, 90}},
lineColor = {192, 192, 192},
fillColor = {192, 192, 192},
fillPattern = FillPattern.Solid),
Line(
points = {
{-76, -31},
{-62, -31},
{-62, -15},
{-54, -15},
{-54, -63},
{-46, -63},
{-46, -41},
{-38, -41},
{-38, 43},
{-30, 43},
{-30, 11},
{-30, 11},
{-30, -49},
{-20, -49},
{-20, -31},
{-10, -31},
{-10, -59},
{0, -59},
{0, 23},
{6, 23},
{6, 37},
{12, 37},
{12, -19},
{22, -19},
{22, -7},
{28, -7},
{28, -37},
{38, -37},
{38, 35},
{48, 35},
{48, 1},
{56, 1},
{56, -65},
{66, -65}},
color = {215, 215, 215}),
Line(points = {
{-76, -24},
{70, -24}})}));
end ContinuousMean;