clf
clear all
set(0,'defaultaxesfontsize',22);
t=-1.5:.001:1.5;
t=t+0.0000001;
ws=50;
Ts=2*pi/ws;
%
%x=(pi/5)*(sin(5*t).*sin(15*t))./(pi*t).^2;
t0=pi/20; %t0=pi/40;
%
x=0.5*sin(20*(t-t0))./(pi*(t-t0))-0.5*sin(20*(t+t0))./(pi*(t+t0));
%
plot(t,x,'Linewidth',3)
%
wmax=20;
w1=(ws/2)-wmax;  scf=2*pi/(ws-2*wmax);
ts=-1.5:Ts:1.5;
ts=ts-0.05+Ts/2;
%ts=ts-0.125;
%xs=(pi/5)*(sin(5*ts).*sin(15*ts))./(pi*ts).^2;
xs=0.5*sin(20*(ts-t0))./(pi*(ts-t0))-0.5*sin(20*(ts+t0))./(pi*(ts+t0));
%
xr=zeros(size(t));
for k=1:length(ts),
kthterm=Ts*xs(k)*(sin((pi/Ts)*(t-ts(k)))./(pi*(t-ts(k))));
kthterm=kthterm.*(scf*sin(w1*(t-ts(k)))./(pi*(t-ts(k))));
xr=xr+kthterm;
end
plot(t,x,'Linewidth',3)
grid
axis([min(t) max(t) -4 5])
set(gca,'XTick',[min(t):0.5:max(t)],'YTick',[-1:5])
hold on
plot([0 0],[-4 5],'k','Linewidth',3)
plot([-1.5 1.5],[0 0],'k','Linewidth',2)
plot(ts,xs,'rx','MarkerSize',18,'Linewidth',4)
plot(t,xr,'r','Linewidth',3)
for kk=9:15,
Y(kk-8,:)=Ts*xs(kk)*(sin((pi/Ts)*(t-ts(kk)))./(pi*(t-ts(kk))));
end
plot(t,Y(1,:),'--',t,Y(2,:),'--',t,Y(3,:),'--',t,Y(4,:),'--', ...
    t,Y(5,:),'--',t,Y(6,:),'--',t,Y(7,:),'--','Linewidth',2)
title('Sampling Theory');
hold off
