-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample_simple_freespace_propagate.m
64 lines (52 loc) · 1.92 KB
/
example_simple_freespace_propagate.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
% example of how to call simple_freespace_propagate
% first construct x,y position matrices
% generate a Gaussian beam
% call simple_freespace_propagate with position wavelength, x matrix, y matrix, field, and distance to propagate
wavelength = 1000e-9; % 1000 nm
prop_dist = 15e-3; % 15 mm
%% construct x,y position matrices
% Make 1mm x 1mm grid with 100x100 points centered around 0,0
Lx = 1e-3;
Ly = 1e-3;
nx = 100;
ny = 100;
[ymat, xmat] = meshgrid(linspace(-Ly/2, Ly/2, ny), linspace(-Lx/2, Lx/2, nx));
dx = xmat(2,2) - xmat(1,1);
dy = ymat(2,2) - ymat(1,1);
%% generate electric field this
% (symmetric) Gaussian beam width (fwhm) of 250 um with flat phase profile, centered about x,y=0
% (or substitute your own electric field)
diameter = 250e-6;
Irrad = exp(-log(2) * ((2./diameter.*ymat).^2 + (2./diameter.*xmat).^2) );
field = sqrt(Irrad);
%% propagate field with call to simple_freespace_propagate function
propagated_field = simple_freespace_propagate(wavelength, xmat, ymat, field, prop_dist);
%% Visualize input and output irradiances
% make a new figure to plot our results (or re-use a previous made one)
fh = findobj('tag', 'ex_propagation_fig');
if isempty(fh)
fh = figure('tag', 'ex_propagation_fig');
else
clf(fh);
figure(fh);
end
% add a couple of axes to the figure
ax1 = axes('parent', fh);
ax2 = axes('parent', fh);
% make side-by-side plots
subplot(1,2,1,ax1);
subplot(1,2,2,ax2);
% stick mesh plot of input irradiance in left plot
mh1 = mesh(ax1, xmat*1e3, ymat*1e3, Irrad);
xlabel(ax1, 'x [mm]');
ylabel(ax1, 'y [mm]');
zlabel(ax1, 'Input field [arb]');
% stick mesh plot of propagated irradiance in right plot
mh2 = mesh(ax2, xmat*1e3, ymat*1e3, abs(propagated_field).^2);
xlabel(ax2, 'x [mm]');
ylabel(ax2, 'y [mm]');
zlabel(ax2, 'Propagated field [arb]');
daspect(ax1, [1,1,1]);
daspect(ax2, [1,1,1]);
box(ax1,'on');
box(ax2,'on');