Skip to content

Commit

Permalink
Add discrete intermediate variable to Mean block (#3269)
Browse files Browse the repository at this point in the history
Add discrete intermediate variable to Mean block to clarify that the block output is a continuous-time variable
  • Loading branch information
beutlich committed Dec 18, 2019
1 parent e440600 commit 2e42302
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Modelica/Blocks/Math.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2839,16 +2839,18 @@ y_im = u_abs * sin( u_arg )
protected
parameter Modelica.SIunits.Time t0(fixed=false) "Start time of simulation";
Real x "Integrator state";
discrete Real y_last "Last sampled mean value";
initial equation
t0 = time;
x = x0;
y = 0;
y_last = 0;
equation
der(x) = u;
when sample(t0 + 1/f, 1/f) then
y = if not yGreaterOrEqualZero then f*pre(x) else max(0.0, f*pre(x));
y_last = if not yGreaterOrEqualZero then f*pre(x) else max(0.0, f*pre(x));
reinit(x, 0);
end when;
y = y_last;
annotation (Documentation(info="<html>
<p>
This block calculates the mean of the input signal u over the given period 1/f:
Expand Down

0 comments on commit 2e42302

Please sign in to comment.