%MARF algorithm for the generation of Holograms of arbitrary designed beam shape close all clear all clc % l=0;%the lth iteration for lth m % for m=0.1:0.1:1 % l=l+1; %First step: generate initial phase 第一步产生初始相位 shift=33;%period of blazed grating 闪耀光栅的周期 m=1;%mixing parameter when iterating,if m=1,then it is totally GS algorithm 混合参数进行迭代时,如果m = 1,那么它是完全GS算法 row=1080;%resolution of DOE in x direction column=1080;%resolution of DOE in y direction [x,y]=meshgrid(1:row,1:column); R=0.0003;%curvature of quadratic phase profile 二次相轮廓的曲率 Alpha=0.5;%aspect ratio of quadratic phase profile 二次相轮廓的长宽比 B_line=0.0;%strength of the gradient of linear gradient phase 强度梯度的线性渐变的阶段 u=3*pi/4;%angle of linear gradient phase 线性梯度相位的角度 B_conical=0;%strength of the gradient of conical phase 锥形相位的强度 Phase=zeros(size(x));%initial phase 初始相位i K1=zeros(size(x)); K2=zeros(size(x)); K3=zeros(size(x)); for j=1:row for k=1:column K1(j,k)=4*R*(Alpha*(j-row/2)^2+(1-Alpha)*(k-column/2)^2);%initial quadratic phase 最初的二次相 K2(j,k)=B_line*((j-row/2)*cos(u)+(k-column/2)*sin(u));%initial linear phase 最初的线性相位 K3(j,k)=B_conical*sqrt((j-column/2)^2+(k-row/2)^2);%initial conical phase 最初的锥形阶段 Phase(j,k)=mod(K1(j,k)+K2(j,k)+K3(j,k),2*pi); end end figure,imshow(mod(Phase.*255./(2*pi),256),[0 255]); % Phii=double(imread('E:\cache\axicon\1\60.bmp')); % Phii=Phii(:,:,1); % Phase=Phii./255.*2.*pi; %Second step: iterative fourier transform to generate final phase A=imread('m2.tif');%target pattern A=A(:,:,1); A1=zeros(1080,1080); A1(241:840,241:840)=A; A=A1; % A=255-A; % A(A~=0)=255; % [a,b]=size(A); % % if a<601&&b<601 % B=zeros(size(x)); % B(row/2-a/2+1:row/2+a/2,column/2-b/2+1:column/2+b/2)=A; % else % B=A; % end B=A; goals=double(B);%target pattern figure(),surfc(x,y,goals), title('Target intensity distribution'), colormap jet, axis equal, axis tight, view([45, 45]), shading interp SigRegion=zeros(size(x)); % SigRegion(row/2-a/2+1:row/2+a/2,column/2-b/2+1:column/2+b/2)=ones(a,b);%*——“signal region, need to be decided manually”—— for xi=400:680 for yi=400:680 if (xi-ceil(row/2))^2+(yi-ceil(row/2))^2<(100)^2 SigRegion(xi,yi)=1; end end end%圆形兴趣区 % SigRegion(520:560,520:560)=ones(41,41);%矩形兴趣区 [dot_num,nonsense]=size(find(B~=0)); % r0=750; %waist radius selected这里是以像素为单位的,Chameloen的光斑直径是1.2mm % A0=(1./(pi*r0^2)).*exp(-((x-row./2).^2+(y-column./2).^2)./(r0^2));%Gauss beam A0=exp(-((x-row/2).^2+(y-column/2).^2)./(750^2));%Gaussian incident % A0=1;%Plane wave incident Efficiency=[];%diffraction efficiency Accuracy=[];%accuracy of the generated laser pattern Roughness=[];%roughness of the generated laser pattern tic h=waitbar(0,'Caculating ...'); index=0; loop=100;%times of iterative for k=1:loop f=exp(1i.*Phase).*A0; f1=fftshift(fft2(f)); f1=f1.*sqrt(sum(sum(abs(A0).^2))/sum(sum(abs(f1).^2))); factor=sqrt(sum(sum(abs(A0).^2))/sum(sum(abs(f1).^2))); disp(factor); f2=(m*sqrt(goals.*SigRegion)+(1-m)*abs(f1.*~SigRegion)).*exp(1i.*(angle(f1))); f3=ifft2(ifftshift(f2)); Phase=angle(f3); Efficiency=[Efficiency sum(sum(abs(f1.*goals./255).^2))/sum(sum(abs(f1).^2))]; fTarget=abs(f1).*goals./255; goals_u=1-((max((fTarget(:))))^2-(min((fTarget(fTarget~=0))))^2)./((max((fTarget(:))))^2+(min((fTarget(fTarget~=0))))^2); Accuracy=[Accuracy goals_u]; index=index+1; waitbar(index./loop); end close(h); toc Intensity=abs(f1).^2./sum(sum(abs(f1).^2))*100000; % IntenDistr(:,:,l)=Intensity; figure(),surfc(x,y,Intensity), title('Simulated intensity distribution'), colormap jet, axis equal, axis tight, view([45, 45]), shading interp; figure(),imshow(abs(f1),[]) % Effi(:,l)=Efficiency; figure,plot(Efficiency,'*'),title('efficiency');%Efficiency varies with iterative % Accu(:,l)=Accuracy; figure,plot(Accuracy,'*'),title('accuracy');%Accuracy varies with iterative for j=1:row %region:0-2pi for k=1:column %Phase(j,k)=Phase(j,k)+2*pi*mod(k,shift)/shift; if Phase(j,k)<0 Phase(j,k)=Phase(j,k)+2*pi; end end end Phase=mod(Phase,2*pi); hologram=Phase.*255./(2.*pi); figure(),imshow(hologram,[0 255]); imwrite(uint8(hologram),'U3.bmp'); % Addition=zeros(1080,420); % hologramStandard=[Addition hologram Addition]; % figure,imshow(hologramStandard,[]); % imwrite(uint8(hologram),'E:\CGH\MRAF\letter\APL\apl30点\holo\L1920_03.bmp');