%Chapter 6,  Fig 6.1
%Eric Dubois, updated 2018-12-12
%Plot figure to illustrate sampling of a continuous-domain 2D signal in the
%frequency domain
%Required functions: Lattice_Points_2d, ds2nfu by Michelle Hirsch
%Use rad1 =  1 and rad2 = .85 for the two cases Fig. 6.1(a) and Fig. 6.2(b)
%set rad = rad1 or rad2 as desired

clear all
close all

rad1 = 1;  % results in aliasing
rad2 = .85; % no aliasing

%Continuous-domain spectrum
figure;

rad = rad2;  %choose the desired radius for the example
rectangle('Position',[-rad -rad 2*rad 2*rad],'Curvature',[1 1],'FaceColor',[.95 .95 .95]);
if rad == rad1
     strFc1 = '$$F_{c1}(\mathbf{u})$$';
     text(.7,-.9,strFc1,'Interpreter','latex')
else
    strFc2 = '$$F_{c2}(\mathbf{u})$$';
    text(.7,-.9,strFc2,'Interpreter','latex')
end

axis equal
axis off
set(gca,'ydir','reverse'); 
%set region
xlim([-4.5, 5]);
ylim([-4, 4]);

hold on;

%Draw and label the axes
text(5,-0.4,'\itu','FontName','times')
text(-0.6, 4, '\itv','FontName','times')
%u axis from -4.5 to +4.5
[xaxx,xaxy] = ds2nfu([-4.5 4.5], [0 0]);
annotation('arrow',xaxx,xaxy,'headlength',5,'headwidth',5);
%y axis from -4 to 4
[yaxx,yaxy] = ds2nfu([0.0 0.0],[4 -4]);
annotation('arrow',yaxx,yaxy,'headlength',5,'headwidth',5);

set(gcf,'Color',[1 1 1]);

%Discrete-domain sampled spectrum
figure;

%sampling matrix of reciprocal lattice and portion of R^2 to plot
VLs = [1.5 1.5; 1 -1];
UL = [-4.5 -4]';
LR = [4.5 4]';
%get the points of the lattice in the desired region 
xoutLs = Lattice_Points_2d(VLs,UL,LR);

%plot the points
points = plot(xoutLs(:,1),xoutLs(:,2),'k.');
points(1).MarkerSize= 9;
axis equal
axis off
set(gca,'ydir','reverse'); 
%set region
xlim([-4.5, 4.5]);
ylim([-4, 4]);
hold on;

%Plot spectral repeats
%plot circles on each reciprocal lattice point
%black circles on the points of Gamma*
radii = rad*ones(size(xoutLs,1),1);
viscircles(xoutLs,radii,'Color','k','LineWidth',.5);

%Draw and label the axes
text(5,-0.4,'\itu','FontName','times')
text(-0.6, 4, '\itv','FontName','times')
%u axis from -4.5 to +4.5
[xaxx,xaxy] = ds2nfu([-4.5 4.5], [0 0]);
annotation('arrow',xaxx,xaxy,'headlength',5,'headwidth',5);
%y axis from -4 to 4.4
[yaxx,yaxy] = ds2nfu([0.0 0.0],[4 -4.4]);
annotation('arrow',yaxx,yaxy,'headlength',5,'headwidth',5);

set(gcf,'Color',[1 1 1]);