figure(1); clf;
N = 100;
x = 0; y = 0;

while 1
    
    subplot(211);
    imagesc([0:N-1],[0:N-1],ones(N,N)); axis image;
    grid on;
    hold on;
    han = plot(x,y,'rs');
    hold off;

    subplot(212);
    Z = zeros(N,N);
    Z(x+1,y+1) = 1;
    z = real(ifft2(Z));
    imagesc(z); axis image;
    str = sprintf('(kx,ky) = (%d,%d)',x,y);
    title(str);

    subplot(211);
    [x,y] = ginput(1);
    x = round(x);
    y = round(y);
    if(x<0)
        x = 0;
    end
    if(x>N-1)
        x = N-1;
    end
    if(y<0)
        y = 0;
    end
    if(y>N-1)
        y = N-1;
    end
end
