% EE 438 Digital Signal Processing with Applications 
%
%Matlab file used for class demo conducted during Session 9
%illustrating upsampling by a factor of 2 using the
%efficient polyphase implementation of upsampling.
%A word utterance is sampled at 12.5 KHz, upsampled by
%a factor of 2 and played back at 25 KHz
clear all
clf
set(0,'defaultaxesfontsize',16);
h=remez(50,[0 .333 .5 1],[1 1 0 0]);
hd1=h(1:2:50); hd2=h(2:2:50);
data=load('enf1s1t0');
Fs=8192;

%plot(data)
%end1=input('end1?');
%end2=input('end2?');
%datar=data(end1:end2);
datar=data;
disp('Utterance played back at orignal'); 
input(' sampling rate, Fs = 12.5 KHz...'); 
soundsc(datar,Fs)

y1=conv(hd1,datar); y2=conv(hd2,datar);
y1size=length(y1); ly=2*y1size;
y=zeros(1,ly);
y(1:2:ly)=y1; y(2:2:ly)=y2;
disp('Utterance interpolated by a factor of two');
input(' played at twice sampling rate, 2*Fs = 25 KHz...'); 
soundsc(y,2*Fs)
domega=2*pi/8192;
omega=-pi:domega:pi-domega;
yf1=abs(fftshift(fft(datar,8192)));
yf2=abs(fftshift(fft(y,8192)));
subplot(211)
plot(omega,yf1,'Linewidth',2)
axis([-pi pi 0 max(yf1)])
title('DTFT of original utterance');
%xlabel('omega (radians/s)');
subplot(212)
plot(omega,yf2,'Linewidth',2)
axis([-pi pi 0 max(yf2)])
title('DTFT of utterance interpolated by a factor of 2');
xlabel('omega (radians/s)');
disp('Original played back at twice');
input(' orignal sampling rate, 2*Fs = 50 KHz...'); 
soundsc(datar,2*Fs)
disp('Interpolated data played back at'); 
input(' orignal sampling rate, Fs = 12.5 KHz...'); 
soundsc(y,Fs)
