
% Demo of discrete-time resampling in time domain
% Last revised 2/20/18 - rms

clear all
close all

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);

% Downsampling by a factor of 2

subplot(2,1,1),stem(n,x)
title('Original waveform','color','r','fontsize',14)


h = [1 zeros(1,20)];
%m12 = resample(m,1,2,h);
m12 = decimate(m,2);
fs = 3500;

n12 = 0:63;
x12 = (m12(1500:((3128/2)-1)));
f12 = w*fs/(2*pi);
[X12] = dtft(x12',n12,w);

subplot(2,1,2),stem(n12,x12)
title('Downsampling by 2','color','r','fontsize',14)


pause



subplot(2,1,1),stem(n,x)
title('Original waveform','color','r','fontsize',14)
axis([0 140 -2 2])


subplot(2,1,2),stem(n12,x12)
title('Downsampling by 2','color','r','fontsize',14)
axis([0 140 -2 2])



pause


% Upsampling by a factor of 2

subplot(2,1,1),stem(n,x)
title('Original waveform','color','r','fontsize',14)
 

m21 = interp(m,2);
fs = 14000;
n21 = 0:255;
x21 = (m21(6000:((2*3128)-1)));
f21 = w*fs/(2*pi);
[X21] = dtft(x21',n21,w);

subplot(2,1,2),stem(n21,x21)
axis([0 300 -2 2])
title('Upsampling by 2','color','r','fontsize',14)
pause


subplot(2,1,1),stem(n,x)
title('Original waveform','color','r','fontsize',14)
 axis([0 120 -2 2])

 
subplot(2,1,2),stem(n21,x21)
axis([0 300 -2 2])
title('Upsampling by 2','color','r','fontsize',14)
 axis([0 120 -2 2])
 

 