function [ handles ] = genLatticeMatrix( handles )
% The unit cell geometry determines the number of recipricol lattice
% points within the Nyquist square (0.5,0.5) to (-0.5,-0.5). The unit cell
% geometry also determines the permutations of delta function weights. This
% function computes the weights for each unit cell element as a matrix row,
% allowing for filter weights to be computed via a matrix equation.
%   

xiStepSize = 1/handles.xSizeD;
etaStepSize = 1/handles.ySizeD;

xiStepVecT = -1*handles.fsMultD:xiStepSize:1*handles.fsMultD;
etaStepVecT = -1*handles.fsMultD:etaStepSize:1*handles.fsMultD;

ind = find(abs(xiStepVecT) <=0.5*handles.fsMultD);
xiStepVec = xiStepVecT(ind);

ind = find(abs(etaStepVecT) <=0.5*handles.fsMultD);
etaStepVec = etaStepVecT(ind);

numXiSteps = length(xiStepVec);
numEtaSteps = length(etaStepVec);

for k = 1:handles.ySizeD
    for j = 1:handles.xSizeD
        Z = handles.DirichletZ{j,k};        
        for l = 1:numEtaSteps
            for m = 1:numXiSteps
                xiIdx = find(abs(handles.xi-xiStepVec(m)) < 10^-12);
                etaIdx = find(abs(handles.eta - etaStepVec(l)) < 10^-12);
                tempRow((l-1)*numXiSteps + m) = Z(etaIdx,xiIdx);
            end
        end
        L(((k-1)*handles.xSizeD + j),:) = tempRow;
    end
end
L = L./(max(max(abs(L))));
handles.L = L;
handles.latticeXiSteps = numXiSteps;
handles.latticeEtaSteps = numEtaSteps;
handles.xiStepVec = xiStepVec;
handles.etaStepVec = etaStepVec;
end

