Professional Documents
Culture Documents
Lab 1 Sampling and Quantization Using MATLAB
Lab 1 Sampling and Quantization Using MATLAB
Lab 1 Sampling and Quantization Using MATLAB
Equipments:
xe=x-xq; %Error
stem(x,'b');
hold on;
stem(xq,'r');
hold on;
stem(xe,'g');
legend('exact','quantized','error','Location','Southeast')
title(sprintf('Signal, Quantized signal and Error for %g bits, %g quantization
levels',n,2^n));
hold off
Questions:
Change the ex 1’ code to create a quantizer function that access a zero-mean input and produce an
integer output after n-bit quantization.
% Quantizing
B=3;
xs(xs>=1)=(1-eps);
xq=floor((xs+1)*2^(B-1));
xq=xq/(2^(B-1));
xq=xq-(2^(B)-1)/2^(B);
subplot(313);
stem((0:n),xq);
title('Quantized Signal xq[n]')