clear all 
clf
data=getspeech('erf1s1t0.wav');
Nbits=2; nlevels=2^Nbits;
Fs=12500;
%plot(data)
end1=1000;  end2=13500;
datar=data(end1:end2);
x=datar;
%
mind=min(x); maxd=max(x); 
amax=max(maxd,abs(mind));
range=maxd-mind; qdelta=range/nlevels;
qdata=-amax+qdelta*round((x+amax)/qdelta);
mean(qdata)
qdata=qdata-mean(qdata);
input('Utterance played back at orignal sampling rate, Fs = 12.5 KHz'); 
soundsc(datar,Fs);
input('Utterance played backed with no. of bits equal to'); Nbits
soundsc(qdata,Fs);
subplot(211)
plot(datar)
title('orignal speech data with 12 bits per sample')
subplot(212)
plot(qdata)
title('quanitized data with Nbits per sample')
input('quantization error plotted next');
clf
plot(datar-qdata)
title('quantization error')
dlength=end2-end1+1;
axis([1 dlength mind maxd])
domega=2*pi/8192;
omega=-pi:domega:pi-domega;
daf1=abs(fftshift(fft(datar,8192)));
input('DTFTs plotted next');
clf
subplot(211)
plot(omega,daf1)
axis([-pi pi 0 max(daf1)]);
title('Magnitude of DTFT of original utterance');
xlabel('omega (radians/s)');
subplot(212)
qdaf=abs(fftshift(fft(qdata,8192)));
plot(omega,qdaf)
axis([-pi pi 0 max(qdaf)]);
title('Magnitude of DTFT of quantized waveform');
xlabel('omega (radians/s)');

