rectangular function in matlab
function y = rect(x);

    x = abs(x);

    if x == 0.5
        y = 0.5;
    else
        if  x &lt; 0.5
            y = 1;
        else
            y = 0;
        end
    end

end


put this in a file and name it "rect.m".  make sure it's on your MATLAB search path.