function [ handles ] = generateUnitCellPlots( handles )
% Computes the Dirichlet kernels for each unit cell element and displays
% them. Frequency is unitless, i.e. normalized.

xi = linspace(-0.5*handles.fsMultD,0.5*handles.fsMultD,handles.xiSizeD);
eta = linspace(-0.5*handles.fsMultD,0.5*handles.fsMultD,handles.etaSizeD);

Tx = handles.xSizeD;
Ty = handles.ySizeD;

xPitch = 1;
yPitch = 1;

N1 = round(handles.NUC/2-1);
M1 = round(handles.MUC/2-1);

N2 = floor(handles.NUC/2);
M2 = floor(handles.MUC/2);

if handles.showResults == true
    figure(handles.unitCellPlots(1));
    set(handles.unitCellPlots(1),'Name','Available Channels : Real Part','NumberTitle','off');
    clf;    
    if handles.showImagCellGeo == true        
        figure(handles.unitCellPlots(2));
        set(handles.unitCellPlots(2),'Name','Available Channels : Imag Part','NumberTitle','off');
        clf;
    end
end

maxVal = 0;
for k = 1:handles.ySizeD
    for j = 1:handles.xSizeD
        Z{j,k} = Gen2DDirichletKern( xi,eta,Tx,Ty,xPitch,yPitch,N1,N2,M1,M2,j-1,k-1 ); %0
        tempMax = max(max(abs(Z{j,k})));
        if tempMax > maxVal
            maxVal = tempMax;
        end
    end
end

% multT = 256/(2*maxVal);

[XI,ETA] = meshgrid(xi,eta);
if handles.showResults == true
    for k = 1:handles.ySizeD
        for j = 1:handles.xSizeD        
            figure(handles.unitCellPlots(1));            
            subplot(handles.ySizeD,handles.xSizeD,(handles.ySizeD-k)*handles.xSizeD + j);
            imagesc(xi,eta,real(Z{j,k}));
            axis square;
            ax = gca;
            ax.YDir = 'normal';
            colormap(viridis(256));
            caxis([-maxVal maxVal]);
            if handles.showImagCellGeo == true
                figure(handles.unitCellPlots(2));
                subplot(handles.ySizeD,handles.xSizeD,(handles.ySizeD-k)*handles.xSizeD + j);                                    
    %             surf(XI,ETA,1/maxVal*(real(Z{j,k}))+2,'linestyle','none');
    %             hold on
    %             surf(XI,ETA,1/maxVal*(imag(Z{j,k})),'linestyle','none');
    %             shading interp;
    %             view([-40,17]);
    %             axis([])
    %             image(xi,eta,multT*(real(Z{j,k})+maxT));                        
    %             hold on;
                h = imagesc(xi,eta,imag(Z{j,k}));
                colormap(plasma(256));
    %             caxis([-1 3]);

                axis square;
                ax = gca;
                ax.YDir = 'normal';            
                caxis([-maxVal maxVal]);            
            end
        end
    end
end

% figure;
% imagesc(xi,eta,real(Z{1,1}));
        
handles.DirichletZ = Z;
handles.xi = xi;
handles.eta = eta;

handles = genLatticeMatrix(handles);
end

