% prechod mezi blizkym a dalekym polem - ctvercova 1D pupila


function sfa3_3

close all


lam=1e-6; z=[0.02,0.08,0.5,100]; D=0.001; 
k=2*pi/lam;

L=0.015, N=2048
del=L/N;
delf=1/N/del;
x1=(-N/2:N/2-1)*del;


g1=rect(x1,D);

figure(1)

plot(x1,g1)
ylim([-0.1,1.5])
xlim([-0.0025,0.0025])


figure(2)

for i=1:length(z)

zz=z(i);
x2=lam*zz*(-N/2:N/2-1)/N/del;
gmod=g1.*exp(-I*k/2/zz.*x1.^2)/sqrt(zz*lam);
g2=ft(gmod,del);

subplot(4,1,i);
%figure(i+1);
plot(x2,abs(g2))
xmax=8*lam*zz/D+8*D;
xlim([-xmax,xmax])

endfor



endfunction


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



function g=rect(x,diam)
g=(abs(x)<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
