function y = rectangularPulse(a, b, t)
    %RECTANGULARPULSE - Rectangular pulse function.
    %
    % y = rectangularPulse(a, b, t) returns:
    %   0, t < a
    %   1, a < t < b
    %   1/2, t == a or t == b
    %   0, t > b
    narginchk(3, 3);

    sp = sympy__sp();
    a = sympy.to_sp_object(a);
    b = sympy.to_sp_object(b);
    t = sympy.to_sp_object(t);

    half = sp.Rational(1, 2);
    y = sp.Piecewise( ...
        pytuple(0, t < a), ...
        pytuple(half, sp.Eq(t, a)), ...
        pytuple(1, t < b), ...
        pytuple(half, sp.Eq(t, b)), ...
        pytuple(0, true));

    y = sympy.Expr(y);
end
