
% Fraunhoferova difrakce pro ctvercovou pupilu


function sfa3_2

close all


lam=1e-6; z=0.01; clona=8; 

L=0.008, N=128
del=L/N;
delf=1/N/del;
xin=(-N/2:N/2-1)*del;
xout=lam*z*(-N/2:N/2-1)/N/del;
max(xout)

[x1,y1]=meshgrid(xin);
[x2,y2]=meshgrid(xout);


% ctvercova pupila

g1=rect2(x1,y1,z/clona);

figure(1);
pcolor(x1,y1,g1);
axis('square');
shading('flat');
colormap('gray');


g2=ft2(g1,del)/lam/z;
maximum=max(max(g2))

figure(2);

pcolor(x2,y2,abs(g2));
caxis([0,maximum/1.5])
axis('square');
shading('flat');
colormap('gray');



endfunction


function g=circ(x,y,diam)
r2=x.^2+y.^2;
g=double(r2<diam^2);
endfunction



function g=rect2(x,y,diam)
g=(abs(x)<diam/2).*(abs(y)<diam/2);
endfunction

function G=ft2(g,del)
 G=fftshift(fft2(ifftshift(g)))*del^2;
end


function g=ift2(G,delf)
 g=fftshift(ifft2(ifftshift(G)))*delf^2*length(G)^2;
end



function G=ft(g,del)
 G=fftshift(fft(ifftshift(g)))*del;
end


function g=ift(G,delf)
 g=fftshift(ifft(ifftshift(G)))*delf*length(G);
end
