%Chapter 5, Example 5.1, Fig 5.1
%Eric Dubois, updated 2018-11-16
%Plot figure for example of continuous domain periodic rect function
%Required functions: Lattice_Points_2d, ds2nfu by Michelle Hirsch
clear all
close all
%Sampling matrix and extent for periodicity lattice
VG = [1 0; 0 1];
UL = [-1.5 -1.5]';
LR = [1.5 1.5]';
%get the points of the lattice in the desired region 
xoutG = Lattice_Points_2d(VG,UL,LR);

%create the plot
figure

%plot the points
points = plot(xoutG(:,1),xoutG(:,2),'k.');
points(1).MarkerSize= 9;

axis equal
axis off
set(gca,'ydir','reverse'); 

%set region
xlim([-1.4, 1.4]);
ylim([-1.2, 1.2]);
hold on

%plot the rect at each of the points of Gamma
rect= polyshape([.25 -.25 -.25 .25],[.25 .25 -.25  -.25]);
nptG = size(xoutG,1);
for rpt = 1:nptG
   rectT = translate(rect,xoutG(rpt,:));
   plot(rectT,'Facecolor','white','EdgeColor','black');
end;

%create the axes
text(1.4,-0.08,'\itx','FontName','times')
text(-0.15, 1.2, '\ity','FontName','times')
%x axis from -1.1 to 1.1
[xaxx,xaxy] = ds2nfu([-1.2 1.4], [0 0]);
annotation('arrow',xaxx,xaxy,'headlength',5,'headwidth',5);
%y axis from -1.2 to 1.2
[yaxx,yaxy] = ds2nfu([0.0 0.0],[1.2 -1.2]);
annotation('arrow',yaxx,yaxy,'headlength',5,'headwidth',5);

%Label axes
text(.97,.09,'\itZ','FontName','times');
text(-1.04,.09,'-\itZ','FontName','times');
text(.05,1.0,'\itZ','FontName','times');
text(.05,-1.0,'-\itZ','FontName','times');

strA = '$$A/2$$';
text(.27,.09,strA,'Interpreter','latex');
text(.03,.32,strA,'Interpreter','latex');

%Label signal values
text(-.5, -.5, '0','FontName','times');
for rpt = 1:nptG
   text(xoutG(rpt,1)-.15,xoutG(rpt,2)-.15,'1','FontName','times');
end;
set(gca,'fontname','times')          %set the plot font to times

set(gcf,'Color',[1 1 1]);
