Skip to content

Commit

Permalink
Proposed change to get correct number of output levels, and handle no…
Browse files Browse the repository at this point in the history
…n-symmetric limits.

Closes modelica#4459
  • Loading branch information
HansOlsson committed Sep 4, 2024
1 parent 35ad28d commit 4f69b36
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ extends Clocked.RealSignals.Interfaces.PartialClockedSISO;
parameter Integer bits(min=1)=8
"Number of bits of quantization (if quantized = true)";
protected
parameter Real resolution = if quantized then ((yMax - yMin)/2^bits) else 0;
parameter Real resolution = if quantized then ((yMax - yMin)/(2^bits-1)) else 0;
equation

if quantized then
y = resolution*floor(abs(u/resolution) + 0.5)*
(if u >= 0 then +1 else -1);
y = resolution*floor(((u-yMin)/resolution) + 0.5)+yMin;
else
y = u;
end if;
annotation (Documentation(info="<html>
<p>
The clocked Real input signal is value discretized
(the discretization is defined by parameter <strong>bits</strong>).
This is a mid-riser quantization, which for a symmetric interval imply that it will not output zero.
</p>
</html>", revisions="<html>
<p>2024-09-04: Corrected off-by-one error in number of output levels, and handle non-symmetric limits.</p>
</html>"));
end Quantization;

0 comments on commit 4f69b36

Please sign in to comment.