function y = quant(x, Nqb, Vs) % %A/D quantizer function % x is the input to be quantized % Nqb is the number of quantizer bits % Vs is the peak value to match 2^(Nqb-1) % % values are normalized by 2^{Nqb-1) % values are saturated % % February 20, 2001 KM % February 9, 2006 KM modified Nfscale = 2^(Nqb-1); dv = Vs/Nfscale; NfscaleM1 = Nfscale-1; y = floor((x+dv/2)/dv); t = y > NfscaleM1; y = ~t.*y + t*NfscaleM1; t = y < -Nfscale; y = ~t.*y - t*Nfscale;