function xq = ChangeBitRes_Truncate(x, Nbits)
% x - original clip in the range -1 to nearly 1, [-1,1)
% Nbits - number of bits in output
L = 2^Nbits; % number of levels
xq_int = floor((x+1) * (L/2)) - L/2; % quantization level, details below
% The steps are:
%   +1: shift to [0,2)
%   *(L/2): shift to [0,L), still floating point
%   floor: for non-negative, discard fractional part: [0,L) as integer
%   -L/2: shift to signed range [L/2,L/2-1]
% For example, if Nbits is 6, there are 64 levels in the range [-32,31].
% If the user accidentally inputs a value of exactly +1, it will get
% quantized to, e.g., 32, which doesn't fit in a 6-bit signed integer.
 
% Now, convert back to values in [-1,1)
xq = (xq_int) / (L/2); % quantized value (+1/2 rounds to nearest)
