function y = uquantvec(x,delta,num_levels)
% Uniform scalar quantizer with step size = delta
% num_levels is the number of quantization output
% levels, and the output levels are mid-points
% of the quantization regions
% if x is a vector, y is the quantized version of all samples in x.
if(num_levels < 1)
  error('num_levels must be positive integer')
end
N=length(x);
y=zeros(1,N);
for n=1:N
 if mod(num_levels,2) == 0
  s=1;
  if x(n)<0
    s=-1;
  end
  i=floor(abs(x(n))/delta);
  i=min(i,(num_levels/2)-1);
  y(n)=s*(i+0.5)*delta;
 else
  i=round(x(n)/delta);
  i=max(min(i,(num_levels-1)/2),-(num_levels-1)/2);
  y(n)=i*delta;
 end
end
