clf
clear all
set(0,'defaultaxesfontsize',20);
N=1024;
%passband edges for speech sampled at 12.5 KHz
omegap=2*0.3/12.5;
Wp2=2*6/12.5;
ML=150;
hbt=remez(ML,[omegap Wp2],[1 1],'Hilbert');
%plot magnitude and phase of FIR HT designed via the Remez-Exchange Algorithm
hbtfft=fftshift(fft(hbt,N));
subplot(211)
hbtmag=20*log10(abs(hbtfft));
hbtang=angle(hbtfft);
freqomega=linspace(-pi,pi-2*pi/N,N);
Mdel=ML/2;
hbtang=angle(exp(j*Mdel*freqomega).*hbtfft);
plot(freqomega,hbtmag,'LineWidth',4);
axis([-pi pi -20 20]);
title('Hilbert Transform Response'),...
xlabel('Omega'), ylabel('Magnitude'), grid
subplot(212)
plot(freqomega,hbtang,'LineWidth',4);
axis([-pi pi -pi pi]);
title('Phase Response')
pause
fp=fopen('enf1s1t0.wav','r','b');
[data,lengthd]=fread(fp,[1,1024],'char');
[data,lengthd]=fread(fp,[1,inf],'short');
fclose(fp);
Fs=12500;
clf
soundsc(data,Fs)
end1=1000; end2=13000; del=end2-end1;
datar=data(end1:end2);
%Hilbert Transform the data by convolving
%with impulse response from remez algorithm
yh=conv(datar,hbt);
delta=zeros(size(hbt));
delta(Mdel+1)=1;
yd=conv(datar,delta);
%create complex analytic signal
yp=yd+j*yh;
%Compute FFT of complex analytic signal
%to show that its DTFT is 0 for -pi < w < 0
Ns=2*16384;
%
x=yp;
wc=7*pi/8;
end1=75;
n=-end1:end1; 
beta=0.15;
n0=n+0.000001;
h0=(sin(wc*n0)./(wc*n0)).*(cos(beta*wc*n0)./(1-(4/pi^2)*beta^2*(wc*n0).^2));
n1=n+(1/3);
h1=(sin(wc*n1)./(wc*n1)).*(cos(beta*wc*n1)./(1-(4/pi^2)*beta^2*(wc*n1).^2));
n2=n+(2/3);
h2=(sin(wc*n2)./(wc*n2)).*(cos(beta*wc*n2)./(1-(4/pi^2)*beta^2*(wc*n2).^2));
y1=conv(x,h0); y2=conv(x,h1); y3=conv(x,h2);
l3=3*length(y1);
y=zeros(1,l3);
y(1:3:l3)=y1; y(2:3:l3)=y2; y(3:3:l3)=y3;
%
xi=real(y);
yimag=2*abs(fftshift(fft(xi,Ns)));
ypfft=fftshift(fft(y,Ns));
clf
ypmag=(abs(ypfft));
ypmax=max(ypmag);
freqomega=linspace(-pi,pi,Ns);
subplot(2,1,1)
plot(freqomega,yimag,'LineWidth',3);
axis([-pi pi 0 ypmax]);
ylabel('Magnitude')
xlabel('Frequency')
title('FT of Real-Valued Signal')
subplot(2,1,2)
plot(freqomega,ypmag,'LineWidth',3);
axis([-pi pi 0 ypmax]);
ylabel('Magnitude')
xlabel('Frequency')
title('FT of Complex-Valued Signal')
pause
%
xi=real(y); xc=imag(y);
Lc=length(y); wc=2*pi/3;
n=0:Lc-1;
%
yssb=xi.*cos(wc*n)-xc.*sin(wc*n);
ydsb=xi.*cos(wc*n);
% 
ymfft=fftshift(fft(yssb,Ns));
ydsbfft=fftshift(fft(ydsb,Ns));
clf
Ymag=(abs(ymfft)); Ymax=max(Ymag);
Ydsbmag=(abs(ydsbfft)); 
%freqomega=linspace(-pi,pi,Ns);
subplot(2,1,1)
plot(freqomega,2*Ydsbmag,'LineWidth',3);
axis([-pi pi 0 Ymax]);
hold on
plot([wc wc],[0 Ymax],'-r','Linewidth',2)
plot([-wc -wc],[0 Ymax],'-r','Linewidth',2)
ylabel('Magnitude')
xlabel('Frequency')
title('Double Sideband')
hold off
subplot(2,1,2)
plot(freqomega,Ymag,'LineWidth',3);
axis([-pi pi 0 Ymax]);
hold on
plot([wc wc],[0 Ymax],'-r','Linewidth',2)
plot([-wc -wc],[0 Ymax],'-r','Linewidth',2)
ylabel('Magnitude')
xlabel('Frequency')
title('Single Sideband')
hold off
