% Demo of discrete-time resampling % Last revised 9/14/99 - rms load mtlb; m = mtlb; fs = 7000; % sampling freq for the Matlab utterance x = (mtlb(3000:3127)); w = -pi:2*pi/257:pi; f = w*fs/(2*pi); n = 0:127; [X] = dtft(x',n,w); subplot(2,1,1),stem(n,x) title('Original waveform','color','r','fontsize',14) subplot(2,1,2),plot(f,abs(X)) title('Its DTFT','color','r','fontsize',14) sound(mtlb,fs) pause % Upsampling by a factor of 2 m21 = resample(m,2,1); fs = 14000; n21 = 0:255; x21 = (m21(6000:((2*3128)-1))); f21 = w*fs/(2*pi); [X21] = dtft(x21',n21,w); subplot(2,1,1),stem(n,x) title('Upsampling by 2','color','r','fontsize',14) axis([0 150 -2 2]) subplot(2,1,2),stem(n21,x21) axis([0 300 -2 2]) sound(mtlb,7000) sound(m21, 14000); pause subplot(2,1,1),plot(w/pi,abs(X)) title('Original DTFT','color','r','fontsize',14) xlabel('\omega/\pi','fontsize',14) subplot(2,1,2),plot(w/pi,abs(X21)) title('DTFT for Upsampling by 2','color','r','fontsize',14) xlabel('\omega/\pi','fontsize',14) pause % Downsampling by a factor of 2 h = [1 zeros(1,20)]; m12 = resample(m,1,2,h); fs = 3500; n12 = 0:63; x12 = (m12(1500:((3128/2)-1))); f12 = w*fs/(2*pi); [X12] = dtft(x12',n12,w); subplot(2,1,1),stem(n,x) title('Downsampling by 2','color','r','fontsize',14) subplot(2,1,2),stem(n12,x12) sound(mtlb,7000) sound(m12, 3500); pause subplot(2,1,1),plot(w/pi,abs(X)) title('Original DTFT','color','r','fontsize',14) xlabel('\omega/\pi','fontsize',14) subplot(2,1,2),plot(w/pi,abs(X12)) title('DTFT for Downsampling by 2','color','r','fontsize',14) xlabel('\omega/\pi','fontsize',14) pause % Downsampling by a factor of 3 m13 = resample(m,1,3,h); fs = 7000/3; n13 = 0:floor(128/3); x13 = (m13(1000:1042,1)); f13 = w*fs/(2*pi); [X13] = dtft(x13',n13,w); subplot(2,1,1),stem(n,x) title('Downsampling by 3','color','r','fontsize',14) subplot(2,1,2),stem(n13,x13) sound(mtlb,7000) sound(m13, 2333); pause subplot(2,1,1),plot(w/pi,abs(X)) title('Original DTFT','color','r','fontsize',14) xlabel('\omega/\pi','fontsize',14) subplot(2,1,2),plot(w/pi,abs(X13)) title('DTFT for Downsampling by 3','color','r','fontsize',14) xlabel('\omega/\pi','fontsize',14) sound(mtlb,7000) sound(m13, 2333); pause