% Chapter 11, Fig.11.14
% Eric Dubois, updated 2019-01-15
% Frequency domain situation for upconversion from Lambda_3 to Lambda_2 in example 11.3.
% Required functions:  Lattice_Points_2d, ds2nfu
clear all
close all

%sampling matrices of reciprocal lattices and portion of R^2 to plot
VL2s = [0.5 0; -0.25 0.5];
VL3s = [1 0; 0 1.];
UL = [-1.3 -1.1]';
LR = [1.3 1.1]';

%get the points of the lattices in the desired region 
xoutL2s = Lattice_Points_2d(VL2s,UL,LR);
xoutL3s = Lattice_Points_2d(VL3s,UL,LR);
%create the plot

figure

%plot the points
points = plot(xoutL2s(:,1),xoutL2s(:,2),'ks',xoutL3s(:,1),xoutL3s(:,2),'kd');
points(1).MarkerSize= 9;
points(2).MarkerSize= 5;
axis equal
axis off
set(gca,'ydir','reverse'); 
%set region
xlim([-1.3, 1.3]);
ylim([-1.1, 1.1]);
hold on

%plot the spectral support, a diamond at each of the points of Lambda3*
diam= polyshape([.35 0 -.35 0],[0 .45 0  -.45]);
nptL3s = size(xoutL3s,1);
for rpt = 1:nptL3s
   diamT = translate(diam,xoutL3s(rpt,:));
   plot(diamT,'Facecolor','white','EdgeColor','blue','FaceAlpha',0.0);
end

%plot the unit cells
rectangle('Position',[-.5,-.5,1,1]);
hexagon = polyshape([.3125 .1875 -.1875 -.3125 -.1875 .1875],[0 .25 .25 0 -.25 -.25]);
plot(hexagon,'Facecolor','white','EdgeColor','red','FaceAlpha',0.0)

%label unit cells
strPL3 = '$$\mathcal{P}_{\Lambda_3^*}$$';
text(.53,-.53,strPL3,'Interpreter','latex');
strPL2 = '$$\mathcal{P}_{\Lambda_2^*}$$';
text(.21,-.26,strPL2,'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');
% % 
%create the axes
text(1.5,-0.08,'\itu')
text(-0.15, 1.14, '\itv')
%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);
%v axis from -1.1 to 1.1
[yaxx,yaxy] = ds2nfu([0.0 0.0],[1.1 -1.17]);
annotation('arrow',yaxx,yaxy,'headlength',5,'headwidth',5);


%insert axis labels
strX = '1';
text(.97,-.1,strX)
strY = '1';
text(0.06,1,strY);
% 

set(gcf,'Color',[1 1 1]);
