% INTSIGNED converts to a signed n-bit integer.
%
%   Y=INTSIGNED(X,N) converts the elements of the array X into signed N-bit
%   integers. X can be any numeric object, such as a DOUBLE. The values of
%   an INTSIGNED range from -2^(N-1) to 2^(N-1)-1.
%   Values outside this range do not saturate on the extremes range,
%   turning around the scale and mapped into de range specified.

function y=intsigned(x,n)

max=2^n;
max_2=max/2;

y=x+max*(floor(x/max)-floor(x/max_2));
