本文使用MATLAB介绍简单的衍射光学元件的设计步骤和参考实例。能对入射光波振幅进行调制的衍射光栅称为振幅光栅,又称黑白光栅。本例中的衍射光学元件为一维二元振幅光栅,透射率分别为T=1和T=0。%%1D Amplitudegrating%%%1D Amplitude grating%%% Defining GratingParametersN=500; %Define MatrixsizeA=zeros(1,N); %Define arow Matrix by assigning 0 to all pixelsP=100; %Define theperiod of the gratingFF=0.5; %Define fillfactor% Constructing the Gratingif rem(q,P),P*FF; %Useremainder function ¡®rem¡¯to constructA=repmat(A,N,1);%replicate the row to create a 2D grating% Alternative code forconstructing the gratingA=repmat(unit,1,N/P);%replicate to create a 1D grating%Observing the gratingoutput in the far fieldE=fftshift(fft2(A));%fftshift is used to re-order the termsIN=(abs(E)/(N*N)).*(abs(E)/(N*N));% Calculating intensitycolormap(gray);%colormap(gray) is used to display grayscaleimagesc(A);% imagesc isused to display a high constrast image本例中的衍射光学元件为一维正弦相位光栅,透射率是空间的正弦函数。% Defining GratingParametersN=500; %Define MatrixsizeA=ones(1,N); %Define aMatrix by assigning 1 to all pixelsP=100; %Define theperiod of the gratingFF=0.5; %Define fillfactor%%1D sinusoidal phasegrating%%A(1,q)=exp(1i*0.59*pi*(sin(rem(q,P)*(2*pi)/P)));%Observing the gratingoutput in the far-fieldE=fftshift(fft2(A));%fftshift is used to re-order the terms in their natural orderIN=(abs(E)/(N*N)).*(abs(E)/(N*N));% Calculating intensity%%Checkerboard phasegrating%%% Defining GratingParametersN=500; %Define MatrixsizeA1=zeros(N,N); %DefineMatrices by assigning 0 to all pixelsPx=100; %Define theperiods of the gratingsFFx=0.5; %Define fillfactors% Constructing thegratingA=exp(1i*pi*xor(A1,A2));%%XOR operation between A1 and A2%Observing the gratingoutput in the far-fieldE=fftshift(fft2(A));%fftshift is used to re-order the terms in their natural orderIN=(abs(E)/(N*N)).*(abs(E)/(N*N));% Calculating intensityN=500; %Define MatrixsizesM=32;%Define the numberof grating linesA=ones(N,N); %DefineMatrices by assigning 1 to all pixelsf=3000;%Define the focallength of FZP in micrometerslambda=0.633;%Definewavelength in micrometersfor n=1:M; %Calculatethe width of the grating linesr(p,q)=sqrt((p-N/2)*(p-N/2)+(q-N/2)*(q-N/2));if r(p,q)>r1(n)&& r(p,q)<r1(n+1);%Observing the gratingoutput in the far-fieldE=fftshift(fft2(A));%fftshift is used to re-order the terms in their natural orderIN=(abs(E)/(N*N)).*(abs(E)/(N*N));% Calculating intensity通常把衍射光学元件m级次的衍射效率定义为m级衍射光的能量Em与入射到衍射光学元件上的总能量E0之比,即  衍射光学元件的衍射效率与台阶数有关。计算得不同台阶数台阶状相位光栅的一级衍射效率如下表:衍射效率随着台阶数的增多而增大,当台阶数L=32时接近于1,但由于工艺复杂,实际应用中多2台阶、4台阶或8台阶。一维4阶相位光栅的最大衍射效率约为81%,其相位和对应的厚度值(@633nm)如图6所示。图6:4阶相位DOE对应的相位和厚度值@633nm%% Defining gratingparametersA1=ones(P,N); % Size offundamental building block of gratingg=4; % Number of phaselevelsdelphase= 2*pi/g; %Phasestep size% Constructing onen-level section of the phase gratingA1((count-1)*sub+1:count*sub,:)=exp(1i*(count-1)*delphase);%Constructing the fullgrating%Observation of thediffraction patternE=fftshift(fft2(A2));%fftshift is used to re-order the terms inIN=(abs(E)/(N*N)).*(abs(E)/(N*N));% Calculating intensitycolormap(gray);%colormap(gray) is used to display grayscaleimagesc(angle(A2));%imagesc is used to display a high constrast 图8:4阶相位DOE的剖面图 一维8阶相位光栅的最大衍射效率约为95%,其相位如图9所示。%% Defining gratingparametersA1=ones(P,N); % Size offundamental building block of gratingg=4; % Number of phaselevelsdelphase= 2*pi/g; %Phasestep size% Constructing onen-level section of the phase gratingA1((count-1)*sub+1:count*sub,:)=exp(1i*(count-1)*delphase);%Constructing the fullgrating%Observation of thediffraction patternE=fftshift(fft2(A2));%fftshift is used to re-order the terms inIN=(abs(E)/(N*N)).*(abs(E)/(N*N));% Calculating intensitycolormap(gray);%colormap(gray) is used to display grayscaleimagesc(angle(A2));%imagesc is used to display a high constrast |