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

Proposed changes quantization #4460

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
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;