Professional Documents
Culture Documents
Fprintf
Fprintf
b=3;
N=120;
n=0:(N-1);
switch choice
case 'Sine'
x=sin(2*pi*n/N);
case 'Sawtooth'
x=sawtooth(2*pi*n/N);
case 'Random'
x=randn(1,N);
x=x/max(abs(x));
end
x(x>=1)=(1-eps);
x(x<-1)=-1;
xq=floor((x+1)*2^(b-1));
xq=xq/(2^(b)-1)/2^(b);
xe=x-xq;
stem(x,'b');
hold on;
stem(xq,'r');
hold on;
stem(xe,'g');
legend('exact','quantized','error','Location','Southeast')
hold off