forked from BUNPC/Beam-Propagation-Method
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBPM_Model.m
149 lines (95 loc) · 3.59 KB
/
BPM_Model.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
%%
%d=20;% layer distance 100
dz=[ones(1,N_diffuser)]*d;
%Prop_mode = 1;
% % Define Fourier operators
F = @(x) fftshift(fft2(ifftshift(x)));
Ft = @(x) fftshift(ifft2(ifftshift(x)));
dx_obj=dx_pixel;
[x,y] = meshgrid([-N_obj(2)/2:N_obj(2)/2-1]*dx_obj,[-N_obj(1)/2:N_obj(1)/2-1]*dx_obj);
% NA is too large
%N = 500;
% maximum spatial frequency set by NA
um_m = NA/lambda;
% system resolution based on the NA
max_ph=sqrt(d/ls/10)*pi;
%max_ph=0;
%N_illum = 1;
ph_mask = zeros(N_obj(1),N_obj(2),N_diffuser);
for m = 1:N_diffuser
[ph_mask(:,:,m)] = RandPhaseScreen_RealSpaceNM(sigma_x, ...
seed_density, max_ph, dx_pixel, N_obj, lambda);
end
o_slice=exp(1i*ph_mask);
k = 2*pi/lambda;
z1=sum(dz(1:N_diffuser-N_residue));%um
N = min([NA*z1/dx_pixel,N_obj(1),N_obj(2)]);
% % NA is too large
% N = 500;
% incident plane wave
%i0 = exp(1i*k*sqrt(x.^2+y.^2+z1.^2))./sqrt(x.^2+y.^2+z1.^2);
switch sourceType
case 'Plane'
i0=zeros(N_obj(1),N_obj(2));
i0(:,:)=1;
case 'Spherical'
i0 = exp(-1i*k*sqrt(x.^2+y.^2+z1.^2))./sqrt(x.^2+y.^2+z1.^2);
[xx,yy] = meshgrid([-N_obj(2)/2:N_obj(2)/2-1],[-N_obj(1)/2:N_obj(1)/2-1]);
mask = zeros(N_obj(2),N_obj(1));
mask(xx.^2+yy.^2 < N^2)=1;
i0=i0.*mask;
case'Gaussian'
waist0 = lambda/NA/pi;% um
zR=pi*waist0^2/lambda;
z2=z1; % location of the focus
waist=waist0*sqrt(1+z2^2/zR^2);
i0 = exp(-(x.^2+y.^2)./waist.^2).*exp(-1i*k*(x.^2+y.^2)./(2*(z2+zR^2/z2)));
end
%%
phi = zeros(N_obj(1),N_obj(2),N_diffuser);
phi(:,:,1) = i0; % incident field of 1st slice is illumination
% initialize output field at each slice
psi = zeros(N_obj(1),N_obj(2),N_diffuser);
psi(:,:,1) = i0;
% psi(:,:,1)=zeros(N_obj(1),N_obj(2)); % point source
% psi(round(N_obj(1)/2),round(N_obj(2)/2),1)=1;
% um_obj= 1/dx_obj/2;
%
% Xsize = (N_obj(2)-1)*dx_pixel;% total span of x
% du = 2*pi/(Xsize);
% umax = pi/(dx_pixel);
% u = -umax:du:umax;
% ********** should be ********
% Xsize = N_obj(2)*dx_pixel;% total span of x
% du = 2*pi/(Xsize);
% umax = pi/(dx_pixel);
% u = -umax:du:umax-du;
% ************** or new ***********
x=-N_obj(1)/2:N_obj(1)/2-1;
y=-N_obj(2)/2:N_obj(2)/2-1;
LX = N_obj(1)*dx_pixel;
LY = N_obj(2)*dx_pixel;
u=lambda*x/LX;
v=lambda*y/LY;
[uu,vv] = meshgrid(u,v);
% propogator
%k2 = pi*lambda*(U.^2+V.^2);
k2 = (uu.^2+vv.^2);
eva = double(k2/lambda^2<(1/lambda)^2);
for m = 2:(N_diffuser+1)
H =exp(1i*k*dz(m-1)*sqrt((1-uu.^2-vv.^2).*eva));
% H = exp(1i*(dz(m-1))*real(sqrt(((2*pi)^2/lambda^2-k2).*eva)));
% second: H = exp(1i*k*(dz(m-1))*real(sqrt(1-k2).*eva));
% propagate from neiboring slices
phi(:,:,m) = Ft((F(psi(:,:,m-1))).*H); % propagation term
% output field = incidence * object
psi(:,:,m) = phi(:,:,m).*o_slice(:,:,m-1); % phase mask operation
%imagesc(abs(psi(:,:,m)).^2/max(max(abs(psi(:,:,m)).^2)));pause(1)
end
outputWavefront=squeeze(psi(:,:,end-N_residue));
outputXZ=squeeze(psi(:,round(end/2)+1,:));
%save(['Output_g_',num2str(g(ii)),'_ls_',num2str(ls),'config',num2str(jobid),'.mat'],'outputWavefront')
figure; imagesc(abs(squeeze(psi(:,round(end/2),:)))); colormap hot; title('amplitude of XZ profile')
figure;imagesc(x,y,(abs(i0)));title('amplitude of incident field'); xlabel('x (\mum)');ylabel('y (\mum)');
figure
imagesc(x,y,abs(outputWavefront));title('amplitude of output field');xlabel('x (\mum)');ylabel('y (\mum)');