% Chapter 11, Fig.11.9 (a)
% Eric Dubois, updated 2019-01-14
% Illustration of a downsampling system using the lattices of Example 11.1.
% Spectral view of the input signal.
% Required functions:  Lattice_Points_2d, ds2nfu

clear all
close all

%sampling matrices of reciprocal lattices and portion of R^2 to plot
VLs = [0.5 0; 0 0.625];
VGs = [0.5 0; -0.625 1.25];
UL = [-1 -0.625]';
LR = [1 0.625]';

%get the points of the lattices in the desired region 
xoutLs = Lattice_Points_2d(VLs,UL,LR);
xoutGs = Lattice_Points_2d(VGs,UL,LR);
%create the plot
figure

%plot the points
points = plot(xoutLs(:,1),xoutLs(:,2),'k.',xoutGs(:,1),xoutGs(:,2),'ks');
points(1).MarkerSize= 9;
points(2).MarkerSize= 8;
axis equal
axis off
set(gca,'ydir','reverse'); 
%set region
xlim([-1.2, 1.3]);
ylim([-.7, .7]);
hold on

%plot the spectral support, an octagon at each of the points of Gamma*
oct= polyshape([.3 .1 -.1 -.3 -.3 -.1 .1 .3],[.15 .4 .4 .15 -.15 -.4 -.4 -.15]);
nptGamma = size(xoutGs,1);
for rpt = 1:nptGamma
   octT = translate(oct,xoutGs(rpt,:));
   plot(octT,'Facecolor','white','EdgeColor','blue');
end

%plot the unit cells
rectangle('Position',[-.25,-.3125,.5,.625]);
diamond = polyshape([0 .5 0 -.5],[-.625 0 .625 0]);
plot(diamond,'Facecolor','white')

%label unit cells
strPL = '$$\mathcal{P}_{\Lambda^*}$$';
text(.38,.38,strPL,'Interpreter','latex');
strPG = '$$\mathcal{P}_{\Gamma^*}$$';
text(-.62,-.1,strPG,'Interpreter','latex');
[aGx,aGy] = ds2nfu([-.5 -.37],[.1 .07]);
annotation('arrow',aGx,aGy,'headlength',4,'headwidth',4);
[aLx, aLy] = ds2nfu([.38 .23],[-.3 -.25]); 
annotation('arrow',aLx,aLy,'headlength',4,'headwidth',4);

% Label filter values
text(.15,-.2,'1');
text(.1,-.4,'0');
text(.1,.4,'0');
text(-.37,.1,'0');
text(.35,.1,'0');


text(1.3,-0.05,'\itu')
text(-0.1, .75, '\itv')

%insert axis labels
strX = '$$1/2X$$';
text(0.45,-.07,strX,'Interpreter','latex');
strY = '$$\frac{1}{2Y}$$';
text(0.03,.65,strY,'Interpreter','latex');

%create the axes
%u axis from -1.2 to 1.3
[xaxx,xaxy] = ds2nfu([-1.2 1.3], [0 0]);
annotation('arrow',xaxx,xaxy,'headlength',5,'headwidth',5);
%y axis from -.7 to .7
[yaxx,yaxy] = ds2nfu([0.0 0.0],[.7 -.75]);
annotation('arrow',yaxx,yaxy,'headlength',5,'headwidth',5);
set(gca,'fontname','times')          %set the plot font to Times
set(gcf,'Color',[1 1 1]);
