📄 twobeamsimulator.m
字号:
function varargout = twobeamsimulator(varargin)
% TWOBEAMSIMULATOR M-file for twobeamsimulator.fig
% TWOBEAMSIMULATOR simulates interference pattern for 2 Gaussian beams
%
% The parameters are:
% Screen Distance: distance from 2nd mirror (infinitely thin) to
% observation screen in mm
% z_1,z_2: distance from position of minimal waist radius
% (w0_1,w0_2) to beam combiner in mm
% Reflectivity: reflectivity of beam combiner (1st beam
% transmitted; value between 0 and 1)
% Refractive Index: refractive index of medium in front of
% and behind the beam combiner (beam combiner itself
% neglected)
%
% w0_1,w0_2: minimal beam waist radius in mm
% Wavelength: wavelength of radiation in nm
%
% Theta: tilt of beam combiner (in x-direction) in angular
% seconds
% Calculation-Window Width: width of observation screen
% Number of Pixels: larger number means better resolution but
% longer waiting times
% Number of Rays: number of simulated beam paths
% Version: 1.1
% Copyright: Birk Andreas 20060704
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @twobeamsimulator_OpeningFcn, ...
'gui_OutputFcn', @twobeamsimulator_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
function twobeamsimulator_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
initialize_gui(hObject, handles);
function varargout = twobeamsimulator_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function abstand_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function abstand_Callback(hObject, eventdata, handles)
handles.abstand=str2double(get(hObject,'String'));
if handles.abstand < 0
handles.abstand=-handles.abstand;
end
guidata(hObject, handles);
function d_Callback(hObject, eventdata, handles)
handles.d=str2double(get(hObject,'String'));
if handles.d < 0
handles.d=-handles.d;
end
guidata(hObject, handles);
function d_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function z1_Callback(hObject, eventdata, handles)
handles.z1=str2double(get(hObject,'String'));
if handles.z1 < 0
handles.z1=-handles.z1;
end
guidata(hObject, handles);
function z1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function z2_Callback(hObject, eventdata, handles)
handles.z2=str2double(get(hObject,'String'));
if handles.z2 < 0
handles.z2=-handles.z2;
end
guidata(hObject, handles);
function z2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function r_Callback(hObject, eventdata, handles)
handles.r=str2double(get(hObject,'String'));
if handles.r < 0
handles.r=-handles.r;
end
guidata(hObject, handles);
function r_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function theta_Callback(hObject, eventdata, handles)
handles.theta=str2double(get(hObject,'String'));
guidata(hObject, handles);
function theta_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function breite_Callback(hObject, eventdata, handles)
handles.breite=str2double(get(hObject,'String'));
if handles.breite < 0
handles.breite=-handles.breite;
end
guidata(hObject, handles);
function breite_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function pixel_Callback(hObject, eventdata, handles)
handles.pixel=str2double(get(hObject,'String'));
if handles.pixel < 0
handles.pixel=-handles.pixel;
end
guidata(hObject, handles);
function pixel_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function mult_Callback(hObject, eventdata, handles)
handles.mult=str2double(get(hObject,'String'));
if handles.mult < 0
handles.mult=-handles.mult;
end
guidata(hObject, handles);
function mult_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function w01_Callback(hObject, eventdata, handles)
handles.w01=str2double(get(hObject,'String'));
if handles.w01 < 0
handles.w01=-handles.w01;
end
guidata(hObject, handles);
function w01_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function w02_Callback(hObject, eventdata, handles)
handles.w02=str2double(get(hObject,'String'));
if handles.w02 < 0
handles.w02=-handles.w02;
end
guidata(hObject, handles);
function w02_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function lambda_Callback(hObject, eventdata, handles)
handles.lambda=str2double(get(hObject,'String'));
if handles.lambda < 0
handles.lambda=-handles.lambda;
end
guidata(hObject, handles);
function lambda_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function n_Callback(hObject, eventdata, handles)
handles.n=str2double(get(hObject,'String'));
guidata(hObject, handles);
function n_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function calculate_Callback(hObject, eventdata, handles)
breite=1e-3*handles.breite;
pixel=round(handles.pixel);
abstand=1e-3*handles.abstand;
z1=1e-3*handles.z1;
z2=1e-3*handles.z2;
w01=1e-3*handles.w01;
w02=1e-3*handles.w02;
lambda=1e-9*handles.lambda;
n=handles.n;
r=handles.r;
theta=pi/648000*handles.theta;
mult=round(handles.mult);
k=2*pi*n/lambda;
z01=n*pi*w01^2/lambda;
z02=n*pi*w02^2/lambda;
t=1-r;
versatz=tan(theta)*abstand;
pixel2=round((breite+versatz)/breite*pixel*2);
Et1=zeros(pixel2);
Et2=zeros(pixel2);
randfield=rand(2,mult)*(breite+versatz)-(breite+versatz)/2;
for N=1:mult
x=randfield(1,N);
y=randfield(2,N);
xd1=x;
xd2=x+tan(theta)*abstand;
yd1=y;
yd2=y;
zd1=z1+abstand;
zd2=z2+abstand/cos(theta);
w1=sqrt(w01^2*(1+(zd1/z01)^2));
w2=sqrt(w02^2*(1+(zd2/z02)^2));
R1=zd1*(1+(z01/zd1)^2);
R2=zd2*(1+(z02/zd2)^2);
ix=ceil(randfield(1,N)/breite*pixel+pixel2/2);
iy=ceil(randfield(2,N)/breite*pixel+pixel2/2);
xc=ceil(randfield(1,N)/breite*pixel+pixel2/2)-(randfield(1,N)...
/breite*pixel+pixel2/2);
yc=ceil(randfield(2,N)/breite*pixel+pixel2/2)-(randfield(2,N)...
/breite*pixel+pixel2/2);
xf=(randfield(1,N)/breite*pixel+pixel2/2)-floor(randfield(1,N)...
/breite*pixel+pixel2/2);
yf=(randfield(2,N)/breite*pixel+pixel2/2)-floor(randfield(2,N)...
/breite*pixel+pixel2/2);
A=t*w01/w1*exp(-(xd1^2+yd1^2)/w1^2)*exp(-i*(k*zd1-atan(zd1/z01)))...
*exp(-i*k*(xd1^2+yd1^2)/(2*R1));
Et1(iy-1,ix)=Et1(iy-1,ix)+xf*yc*A;
Et1(iy,ix-1)=Et1(iy,ix-1)+xc*yf*A;
Et1(iy-1,ix-1)=Et1(iy-1,ix-1)+xc*yc*A;
Et1(iy,ix)=Et1(iy,ix)+xf*yf*A;
A=r*w02/w2*exp(-(xd2^2+yd2^2)/w2^2)...
*exp(-i*(k*zd2-atan(zd2/z02)))*exp(-i*k*(xd2^2+yd2^2)/(2*R2));
Et2(iy-1,ix)=Et2(iy-1,ix)+xf*yc*A;
Et2(iy,ix-1)=Et2(iy,ix-1)+xc*yf*A;
Et2(iy-1,ix-1)=Et2(iy-1,ix-1)+xc*yc*A;
Et2(iy,ix)=Et2(iy,ix)+xf*yf*A;
end
I=(Et1+Et2).*conj(Et1+Et2);
I=I/sum(sum(I));
[zl,sp]=size(I);
I=I(floor(zl/2)-floor(pixel/2)+1:floor(zl/2)+floor(pixel/2),floor(sp/2)...
-floor(pixel/2)+1:floor(sp/2)+floor(pixel/2));
assignin('base','I',I);
P=angle(Et1+Et2);
P=P(floor(zl/2)-floor(pixel/2)+1:floor(zl/2)+floor(pixel/2),floor(sp/2)...
-floor(pixel/2)+1:floor(sp/2)+floor(pixel/2));
assignin('base','P',P);
figure;
surf(P);
shading interp;
view(2);
colorbar;
figure;
surf(I);
shading interp;
view(2);
colorbar;
function initialize_gui(fig_handle, handles)
handles.breite=5;
handles.pixel=100;
handles.abstand=100;
handles.z1=100;
handles.z2=100;
handles.w01=1.5;
handles.w02=1.5;
handles.lambda=532;
handles.n=1;
handles.r=0.5;
handles.theta=0;
handles.mult=3e5;
guidata(handles.figure1, handles);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -