%Matlab file used for class demo conducted during Session 11.
%A word utterance is effectively sampled at four different
%rates and played back to hear the effects of ZOH
clf
clear all
set(0,'defaultaxesfontsize',20);
%these commands read in the speech file
data=getspeech('00f1s2t0.wav');
Fs=12500;
%plot data to cut off silence
plot(data)
end1=input('end1?')
end2=input('end2?')
data2=data(end1:end2);
clear data
[d,dsize]=size(data2);
d8=4*dsize;
dZOH4=resample(data2,4,1);
%data1=data2(1:2:dsize);
data1=resample(data2,1,2);
input('playback speech at original');
input('sampling rate of 6.25 KHz');
soundsc(data1,Fs/2)
dZOH1=zeros(1,d8);
for k=1:8,
[kvec,dt]=size(k:8:d8);
clear kvec
dZOH1(1,k:8:d8)=data1(1,1:dt);
end
Fp=50e3;
plot(dZOH1(10000:10200),'b','Linewidth',3)
hold on
plot(dZOH4(10000:10200),'r-','Linewidth',3)
legend('ZOH reconstruction at 6.25 KHz','Original waveform');
hold off
pause
input('ZOH D/A at Fs= 6.25 KHz ');
%input('- ZOH - hold for 8 samples');
soundsc(dZOH1,Fp)
%clear dZOH1
dZOH2=zeros(1,d8);
for k=1:4,
[kvec,dt]=size(k:4:d8);
clear kvec
dZOH2(1,k:4:d8)=data2(1,1:dt);
end
plot(dZOH2(10000:10200),'b','Linewidth',3)
hold on
plot(dZOH4(10000:10200),'r-','Linewidth',3)
legend('Upsample L=2, ZOH D/A @ 12.5 KHz','Original waveform');
hold off
pause
input('Upample L=2: from Fs=6.25 KHz to Fr=12.5 KHz');
input('-- ZOH D/A at Fr=12.5 KHz');
soundsc(dZOH2,Fp)
%clear dZOH2
data3=resample(data2,2,1);
dZOH3=zeros(1,d8);
for k=1:2,
[kvec,dt]=size(k:2:d8);
clear kvec
dZOH3(1,k:2:d8)=data3(1,1:dt);
end
plot(dZOH3(10000:10200),'b','Linewidth',3)
hold on
plot(dZOH4(10000:10200),'r-','Linewidth',3)
legend('Upsample L=4, ZOH D/A @ 25 KHz','Original waveform');
hold off
pause
input('Upsample L=4: from Fs=6.25 KHz to Fr=25 KHz');
input('- ZOH at Fr=25 KHz');
soundsc(dZOH3,Fp)
%clear dZOH3
pause
input('Upsample from Fs=6.25 KHz to Fr=50 KHz');
input('-- ZOH hold for 1 sample');
soundsc(dZOH4,Fp)

