▦

Quantizer

Discontinuous
Run the live example Free · no sign-up · runs in your browser

Discretizes continuous signal amplitude into discrete staircase quantization levels. Supports two operational modes: Resolution mode, which rounds incoming signals to the nearest integer multiple of a specified step interval qq, and ADC mode, which simulates physical Analog-to-Digital Converter behavior parameterized by input voltage range and bit depth BB. Essential for modeling sensor resolution limits, ADC word-length effects, finite precision embedded arithmetic, and quantization noise in digital control systems.

Mathematical Model

In Resolution mode (mode = "resolution"), the output rounds the input to the nearest multiple of interval qq:

y(t)=q⋅round(u(t)q)y(t) = q \cdot \text{round}\left( \frac{u(t)}{q} \right)

The instantaneous quantization error eq(t)=y(t)−u(t)e_q(t) = y(t) - u(t) is strictly bounded by half the step size:

∣eq(t)∣≤q2|e_q(t)| \le \frac{q}{2}

In ADC mode (mode = "adc"), the signal is first clamped to the range [Vmin,Vmax][V_{\text{min}}, V_{\text{max}}] and quantized across 2B2^B discrete levels:

q=Vmax−Vmin2B−1q = \frac{V_{\text{max}} - V_{\text{min}}}{2^B - 1}

The resulting discrete integer code and reconstructed output voltage are:

n=round(max⁡(Vmin,min⁡(Vmax,u(t)))−Vminq),y(t)=Vmin+n⋅qn = \text{round}\left( \frac{\max(V_{\text{min}}, \min(V_{\text{max}}, u(t))) - V_{\text{min}}}{q} \right), \quad y(t) = V_{\text{min}} + n \cdot q

The theoretical Signal-to-Quantization-Noise Ratio (SQNR) for a full-scale sinusoidal input is:

SQNR≈6.02⋅B+1.76 dB\text{SQNR} \approx 6.02 \cdot B + 1.76\text{ dB}

Inputs & Outputs

Direction ID Label Type Status
→ In in Input number Required
← Out out Output number Output

Parameters

Parameters Label Type Default Description
mode Mode select resolution Resolution: specify quantization interval directly. ADC: specify min, max, and bit depth.
interval Quantization Interval number 1 Used in Resolution mode
minValue Min Value number 0 Minimum input range (ADC mode)
maxValue Max Value number 5 Maximum input range (ADC mode)
bits Number of Bits number 8 Bit depth for ADC quantization (ADC mode)

Usage Examples

Example 1: 10-Bit Embedded Microcontroller ADC Modeling

In microcontroller sensor interfaces (e.g. STM32 or Arduino), analog sensors are digitized by a 10-bit ADC spanning 0V0\text{V} to 3.3V3.3\text{V}. Setting mode = "adc", minValue = 0.0, maxValue = 3.3, and bits = 10 produces discrete voltage steps of q=3.3/1023≈3.226 mVq = 3.3 / 1023 \approx 3.226\text{ mV}, reproducing realistic ADC quantization noise and code-stepping in simulation.

Example 2: Discrete Actuator Power Throttling in Resolution Mode

In industrial thermal management, a high-power immersion heater's thyristor controller only accepts discrete power demands in 250 W250\text{ W} increments. Connecting a continuous PID controller's output to a Quantizer configured with mode = "resolution" and interval = 250.0 converts the smooth control signal into discrete stair-step commands (0,250,500,750,1000 W0, 250, 500, 750, 1000\text{ W}), preventing continuous micro-adjustments.

Remarks & Best Practices

  • Live Quantization Staircase Preview: The property editor displays the discrete staircase transfer curve y=Q(u)y = Q(u), reporting LSB step size qq, peak error, or ADC dynamic range and theoretical SNR.
  • Quantization Noise Statistics: For dynamic signals crossing multiple quantization bands, quantization error approximates white noise with uniform distribution and variance σ2=q2/12\sigma^2 = q^2 / 12.
  • Dual Mode Flexibility: Resolution mode provides symmetric unbounded quantization around zero, while ADC mode enforces physical voltage clipping and discrete bit depth.
  • Closed-Loop Limit Cycles: When placed inside high-gain feedback loops, quantization non-linearities can induce small-amplitude sustained limit-cycle oscillations.
  • Deterministic High Speed: Evaluated in Rust using branchless math, ensuring fast simulation execution with zero dynamic memory allocation.

Related Components

  • DeadZone: Suppresses signals within an insensitivity interval around zero.
  • Saturation: Clamps signal amplitudes between upper and lower limits without stair-stepping.
  • Relay: Two-state hysteretic threshold switching.
  • MathFunction: Evaluates mathematical rounding, floor, and ceiling operations.