function s = square2(t)
%SQUARE2 Square wave generation.
%   SQUARE2(T) generates a square wave with period 2*Pi for the
%   elements of time vector T.  SQUARE2(T) is like SIN(T), only
%   it creates a square wave with peaks of +1 to -1 instead of
%   a sine wave.
%
%   For example, generate a 30 Hz square wave:
%        t = 0:.001:2.5;
%        y = SQUARE2(2*pi*30*t); plot(t,y)
%
%   see also SQUARE in the Signal Processing Toolbox
%   (SQUARE2 fixes a floating-point ambiguity in SQUARE)

% Compute values of t normalized to (0,2*pi)
tmp = mod(t+eps^0.75,2*pi);		% add a small number, still more than large
								% enough to overcome ambiguity

% Assign 1 values to normalized t between (0,pi), 0 elsewhere
nodd = (tmp < pi);

% The actual square wave computation
s = 2*nodd-1;
