%
%
% Optical Imaging and Spectroscopy
%
% David J. Brady
% Duke University
% www.opticalimaging.org
%
% Figure 9.10
%
%
% Impulse response of Fabry-Perot Etalon
%
%
%
%
%
% Fresnel diffraction
%
%
%
%
figure(1);set(gcf,'color','white');
X=200; %wavelengths
N=2048; % samples per axis
xrange=linspace(-X,X,N);
urange=(-N/(4*X)):(1/(2*X)):(N/2-1)/(2*X);
[x,y]=meshgrid(xrange);
[u,v]=meshgrid(urange);
% 
% Fourier transform of the FP transfer function
%
d=3; %thickness in wavelengths
n=1; %index of refraction
r=0.9; % reflectivity
    hath=exp(2*i*pi*d*sqrt(n^2-u.^2-v.^2))./(1-r^2*exp(4*i*pi*d*sqrt(n^2-u.^2-v.^2)));
    ft=fftshift(ifft2(fftshift(hath)));
    subplot(8,2,1);plot(urange(600:1450),abs(hath(600:1450,N/2)),'-k');title(['Transfer function d=',num2str(d)]);set(gca,'Xtick',[]);
    subplot(8,2,2);plot(xrange((N/4):(3*N/4)),abs(ft(((N/4):(3*N/4)),N/2)).^2/(.021)^2,'-k');title('Impulse response');axis([-20,20, 0,1]);set(gca,'Xtick',[]);
for dd=1:6
    d=d+1/7;
    hath=exp(2*i*pi*d*sqrt(n^2-u.^2-v.^2))./(1-r^2*exp(4*i*pi*d*sqrt(n^2-u.^2-v.^2)));
    ft=fftshift(ifft2(fftshift(hath)));
    subplot(8,2,2*dd+1);plot(urange(600:1450),abs(hath(600:1450,N/2)),'-k');title([' d=',num2str(d)]);set(gca,'Xtick',[]);
    subplot(8,2,2*dd+2);plot(xrange((N/4):(3*N/4)),abs(ft(((N/4):(3*N/4)),N/2).^2/(.021)^2),'-k');axis([-20,20, 0,1]);set(gca,'Xtick',[]);
end
d=d+1/7;
 hath=exp(2*i*pi*d*sqrt(n^2-u.^2-v.^2))./(1-r^2*exp(4*i*pi*d*sqrt(n^2-u.^2-v.^2)));
    ft=fftshift(ifft2(fftshift(hath)));
    subplot(8,2,15);plot(urange(600:1450),abs(hath(600:1450,N/2)),'-k');title(['d=',num2str(d)]);xlabel('u (1/\lambda)');
    subplot(8,2,16);plot(xrange((N/4):(3*N/4)),abs(ft(((N/4):(3*N/4)),N/2)).^2/(.021)^2,'-k');axis([-20,20, 0,1]);xlabel('x (\lambda)');

% hp=surf(xrange,xrange,abs(ft));axis 'square';title('d=10 \lambda'); 
% shading interp;
% light('Position',[-2,2,20]);
% lighting phong;
% material([0.4,0.6,0.5,30]);
% set(hp,'FaceColor',[.5,.5,.5],'BackFaceLighting','lit');


