|·|

Absolute Value

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

The Absolute Value block computes the mathematical magnitude (absolute value) ∣u(t)∣|u(t)| of the input signal. The output is always non-negative regardless of the sign of the input.

In control engineering and instrumentation, this block is fundamental for computing tracking error magnitudes (such as Integral of Absolute Error, IAE), rectifying alternating signals (AC to pulsating DC), formulating Lyapunov candidate functions, and bounding state variables.

Mathematical Model

y(t)=∣u(t)∣={u(t),if u(t)≥0−u(t),if u(t)<0y(t) = |u(t)| = \begin{cases} u(t), & \text{if } u(t) \ge 0 \\ -u(t), & \text{if } u(t) < 0 \end{cases}

The function is continuous everywhere but non-differentiable at the origin u=0u = 0, where the subdifferential is the set [−1,1][-1, 1].

Inputs & Outputs

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

Usage Examples

Example 1: Full-Wave Signal Rectification

Connecting an alternating sine wave u(t)=Asin⁡(ωt)u(t) = A \sin(\omega t) with amplitude A=5 VA = 5\,\text{V} and frequency f=50 Hzf = 50\,\text{Hz} to the Abs block folds the negative half-cycles into positive peaks. The output exhibits a DC component of 2A/π≈3.18 V2A/\pi \approx 3.18\,\text{V} and an AC ripple fundamental frequency of 2f=100 Hz2f = 100\,\text{Hz}, modeling an ideal diode bridge rectifier.

Example 2: Integral of Absolute Error (IAE) Performance Index

In closed-loop controller benchmarking, the error signal e(t)=r(t)−y(t)e(t) = r(t) - y(t) from a Subtraction block feeds into an Abs block, whose output ∣e(t)∣|e(t)| is integrated by an Integrator block. The resulting metric IAE=∫0T∣e(t)∣ dt\text{IAE} = \int_0^T |e(t)|\,dt provides a non-cancelling penalty for transient deviations, essential for automated PID tuning algorithms.

Remarks & Best Practices

  • Non-negative Output: Output signal is strictly y(t)≥0y(t) \ge 0 for all real input values.
  • Zero-Crossing Singularity: The derivative d∣u∣du=sgn(u)\frac{d|u|}{du} = \text{sgn}(u) exhibits a jump discontinuity at u=0u = 0; numerical variable-step solvers may refine step sizes near zero crossings to maintain accuracy.
  • Computational Efficiency: Implemented as native IEEE-754 floating-point bitmasking (f64::abs) in the WebAssembly engine with zero loop overhead.
  • Euclidean Norms: Combine with Product and SquareRoot blocks to compute Euclidean distances and vector magnitudes: ∥x∥2=∑xi2\|x\|_2 = \sqrt{\sum x_i^2}.

Related Components

  • Product: Signal multiplication and squaring
  • SquareRoot: Calculation of root-mean-square (RMS) values
  • Saturation: Clamps signals between upper and lower bounds