173Appendix D: MATLAB® Simulation Function Files
end
%%%%%%%%%%%%%%
lambda_micron = 0.633; % Wavelength (microns)
lambda = lambda_micron*10^(-3);% Wavelength (mm)
xmax = 50;
xstp = 0.001;
x = -xmax:xstp:xmax-xstp;
[tmp,szx] = size(x);
xf = (1/(1*xstp)*(1/szx)).*((-szx/2):(szx/2)-1);
x2 = (lambda*z_mm).*xf;
midx = round(szx/2);
xh = round(wh/xstp);
xL = round(L/xstp);
k_1d = 2*pi/lambda;
%%%%%%%%%%%%%%%%%%%%%%%%%%%
sh = uicontrol(fh,’Style’,’slider’,...
‘Max’,13.5,’Min’,1.15,’Value’,slider_valueDiste,...
‘SliderStep’,[0.05 0.2],...
‘Units’,’Normalized’,...
‘Position’,[30/fwndw_H 100/fwndw_V 20/fwndw_H 250/
fwndw_V],...
‘Callback’,{@slider1_Callback});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
text_lambda_mark = uicontrol(‘Style’,’text’,...
‘String’,’Wavelength’,...
‘Units’,’Normalized’,...
‘Position’,[7/fwndw_H,50/fwndw_V,90/fwndw_H,25/
fwndw_V],...
‘BackgroundColor’,[0.925 0.914 0.847]);
text_lambda_mark = uicontrol(‘Style’,’text’,...
‘String’,’(microns) ‘,...
‘Units’,’Normalized’,...
‘Position’,[8/fwndw_H,35/fwndw_V,90/fwndw_H,25/
fwndw_V],...
‘BackgroundColor’,[0.925 0.914 0.847]);
function textin_lambda(source,eventdata)
174 Appendix D: MATLAB® Simulation Function Files
lambda_micron = str2double(get(source, ‘String’));
lambda = lambda_micron*10^(-3);% Wavelength (mm)
Ufrl_calc
end
lambda_micron_string = num2str(lambda_micron,’%2.3f’);
text_lambda = uicontrol(‘Style’,’edit’,...
‘String’,lambda_micron_string,...
‘Units’,’Normalized’,...
‘Position’,[20/fwndw_H,15/fwndw_V,55/fwndw_H,25/
fwndw_V],...
‘BackgroundColor’,[1 1 1],...
‘Value’,lambda_micron,’Callback’,{@textin_lambda});
lambda = lambda_micron*10^(-3);% Wavelength (mm)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function slider1_Callback(source,eventdata)
slider_valueDiste = get(source, ‘Value’);
slider_valueDist = exp(slider_valueDiste);
slider_value_dsp1 = num2str(slider_valueDist,’%2.1f’);
set(textinputSlidervalueDist, ‘String’, slider_value_dsp1);
Ufrl_calc
slider_valueDist = exp(slider_valueDiste);
end
z_mm_input_string = num2str(z_mm,’%2.1f’);
textinputSlidervalueDist = uicontrol(‘Style’,’edit’,...
‘Value’,z_mm,...
‘Units’,’Normalized’,...
‘Position’,[20/fwndw_H,360/fwndw_V,45/fwndw_H,25/
fwndw_V],...
‘BackgroundColor’,[1 1 1],...
‘String’,z_mm_input_string,...
‘Callback’,{@z_mm_Callback});
text_z_mm_mark = uicontrol(‘Style’,’text’,...
‘String’,’Distance (mm) ‘,...
‘Units’,’Normalized’,...
‘Position’,[10/fwndw_H,385/fwndw_V,80/fwndw_H,25/
fwndw_V],...
‘BackgroundColor’,[0.925 0.914 0.847]);
function z_mm_Callback(source,eventdata)
z_mm = str2double(get(source, ‘String’));
slider_valueDist = z_mm;
sh = uicontrol(fh,’Style’,’slider’,...
‘Max’,13.5,’Min’,1.15,’Value’,slider_valueDiste,...
‘SliderStep’,[0.05 0.2],...
175Appendix D: MATLAB® Simulation Function Files
‘Units’,’Normalized’,...
‘Position’,[30/fwndw_H 100/fwndw_V 20/fwndw_H 250/
fwndw_V],...
‘Callback’,{@slider1_Callback});
z_mm = exp(slider_valueDiste);
Ufrl_calc
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%
zne = 0;
rng_val_Fra = (2*z_mm)/(k_1d*(wh^2));
tmpwmax = [L+2*wh wh];
wMax = max(tmpwmax);
rng_val_Frl = (4*lambda*(z_mm^3))/((wMax)^4);
if rng_val_Frl > 35;
zne = 1; % Fresnel
end
if rng_val_Fra > 30;
zne = 2; % Fraunhofer
end
if zne < 1
disp(‘Not in Fresnel or Fraunhofer Zone’)
disp(‘Try larger z’)
disp(‘ ‘)
return
end
%%% End. Zone Calc%%%
Uo = 0.*x;
Uo(midx - round(xL/2) - xh : midx - round(xL/2) + xh) = 1;
Uo(midx + round(xL/2) - xh : midx + round(xL/2) + xh) = 1;
% end
%%%%%%%%%%% Fresnel
%%%%%%%%%% Beg. Ufrl_calc%%%%%%%%
%%%%%%%%%%%%%%%%%
Ufrl_calc
function Ufrl_calc
z_mm = slider_valueDist;
k_1d = 2*pi/lambda;
xh = round(wh/xstp);
xL = round(L/xstp);
176 Appendix D: MATLAB® Simulation Function Files
%%%%% Zone Calc%%%
zne = 0;
rng_val_Fra = (2*z_mm)/(k_1d*(wh^2));
rng_val_Frl = (4*lambda*(z_mm^3))/((wh)^4);
if rng_val_Frl > 35;
zne = 1; % Fresnel
end
if rng_val_Fra > 30;
zne = 2; % Fraunhofer
end
disp(‘ ‘)
if zne < 1
disp(‘Not in Fresnel or Fraunhofer Zone’)
disp(‘Try larger z’)
disp(‘ ‘)
return
end
%%% End. Zone Calc%%%
Uo = 0.*x;
Uo(midx - round(xL/2) - xh : midx - round(xL/2) + xh) = 1;
Uo(midx + round(xL/2) - xh : midx + round(xL/2) + xh) = 1;
U_preFFT = Uo.*exp((i*k_1d/(2*z_mm)).*(x.^2));
Ufrl = fft(U_preFFT);
Ufrl = fftshift(Ufrl);
Ufrl_max = max(abs(Ufrl));
Ufrlmx1 = (1/Ufrl_max).*Ufrl;
x2 = (lambda*z_mm).*xf;
x2limit = 1000*(lambda*(sqrt(z_mm)))+0.8;
I_diff = (abs(Ufrl)).^2;
I_diff_max = max(I_diff);
I_diff_norm = (1/I_diff_max).*I_diff;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
axes(a_ax1)
177Appendix D: MATLAB® Simulation Function Files
plot(x2,abs(Ufrl))
axis([-x2limit x2limit -0.1*max(abs(Ufrl)) 1.1*max(abs(Ufrl))]);
plot(x2,I_diff_norm)
axis([-x2limit x2limit -0.1 1.1]);
ylabel(‘Intensity’)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
axes(a_ax2B);
plot(x,Uo)
axis([-1.5*(2*wh+L) 1.5*(2*wh+L) -0.1 1.1]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
end
SIMULATION D.5: POLARIZATION
Purpose: To familiarize with polarizers, quarter- and half-wave plates
Related chapter: 5–Polarization
Simulation le: Polarization_GUI.m
file coNteNt
function Polarization_GUI
% Polarization
% Copyright Araz Yacoubian 2013, 2014
clear
close(‘all’)
%%%%
option_wv_pol = 21;% In, qrtwv
%%%%
x = -125:125;
q1 = 30;45;
q2 = 135;
r1 = 50;
r2 = 55;
sgm = pi/2;

Get Optics Essentials now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.