GRATING Analysis of a diffraction grating.

by Chuck DiMarzio Northeastern University 2010

!! This file may be copied, used, or modified for educational and
!! research purposes provided that this header information is not
!! removed or altered, and provided that the book is cited in
!! publications, as DiMarzio, Charles A., Optics for Engineers,
!! CRC Press, Boca Raton, FL, 2011.
!! http://www.crcpress.com
!! Other distribution is prohibited without permission.

Contents

Start

x=fftaxisshift((0:8191)*8/8192);
slitwidth=1/16;
w=1/2;
intrep=256;
f=fftaxisshift(fftaxis(x));
xlim=2;
pr=find(abs(x)<xlim);
fpr=find(abs(f)<75);
slit=zeros(size(x));
slit(find(abs(x)<1/16))=1;
fig21=figure;plot(x(pr),slit(pr),'k');axis([-xlim,xlim,0,1.2]);
xlabel('x, Position in Grating');
ylabel('Slit');
%print('-depsc',[epspath,'8-21-gr.eps']);
fslit=fftshift(fft(fftshift(slit)));
fig22=figure;plot(f(fpr),real(fslit(fpr)),'k',...
            f(fpr),imag(fslit(fpr)),'k');
xlabel('f, Position in Diffraction Pattern');
ylabel('Slit Diffraction Pattern');
%print('-depsc',[epspath,'8-22-gr.eps']);

comb=zeros(size(x));
comb(intrep+1:intrep:end)=1;
fig23=figure;plot(x(pr),comb(pr),'k');axis([-xlim,xlim,0,1.2]);
xlabel('x, Position in Grating');
ylabel('Comb');
%print('-depsc',[epspath,'8-23-gr.eps']);
fcomb=fftshift(fft(fftshift(comb)));
fig24=figure;plot(f(fpr),abs(fcomb(fpr)),'k');
xlabel('f, Position in Diffraction Pattern');
ylabel('Comb');
%print('-depsc',[epspath,'8-24-gr.eps']);

fgrt=fslit.*fcomb;
grt=fftshift(ifft(fftshift(fgrt)));
fig25=figure;plot(x(pr),abs(grt(pr)),'k');axis([-xlim,xlim,0,1.2]);
xlabel('x, Position in Grating');
ylabel('Grating');
%print('-depsc',[epspath,'8-25-gr.eps']);
fig26=figure;plot(f(fpr),real(fgrt(fpr)),'k');
xlabel('f, Position in Diffraction Pattern');
ylabel('Grating Diffraction Pattern');
%print('-depsc',[epspath,'8-26-gr.eps']);

apodization=exp(-x.^2/w.^2);
fig27=figure;plot(x(pr),apodization(pr),'k');axis([-xlim,xlim,0,1.2]);
xlabel('x, Position in Grating');
ylabel('Apodization');
%print('-depsc',[epspath,'8-27-gr.eps']);
fapodization=fftshift(fft(fftshift(apodization)));
fig28=figure;plot(f(fpr),abs(fapodization(fpr)),'k');
xlabel('f, Position in Diffraction Pattern');
ylabel('Apodization');
%print('-depsc',[epspath,'8-28-gr.eps']);

apgr=apodization.*grt;
fig29=figure;plot(x(pr),abs(apgr(pr)),'k');axis([-xlim,xlim,0,1.2]);
xlabel('x, Position in Grating');
ylabel('Apodized Grating');
%print('-depsc',[epspath,'8-29-gr.eps']);
fapgr=fftshift(fft(fftshift(apgr)));
fig30=figure;plot(f(fpr),real(fapgr(fpr)),'k');
xlabel('f, Position in Diffraction Pattern');
ylabel('Apodized Grating Diffraction Pattern');
%print('-depsc',[epspath,'8-30-gr.eps']);