⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fpisimulator.m

📁 This program simulates Gaussian beam propagation through a Fabry-Perot interferometer %with adjust
💻 M
字号:
function varargout = fpisimulator(varargin)
% FPISIMULATOR M-file for fpisimulator.fig
%   FPISIMULATOR simulates Gaussian beam propagation through a Fabry-Perot
%   interferometer with adjustable error angles.
%  
%   The parameters are:
%   Screen Distance:    distance from 2nd mirror (infinitely thin) to
%                       observation screen in mm
%   Mirror Spacing:     spacing between mirrors given by multiples of 
%                       wavelength   
%   z:                  distance from position of minimal waist radius
%                       (w0) to 1st mirror in mm
%   Reflectivity:       reflectivity of mirrors (between 0 and 1)
%   Refractive Index:   refractive index of medium in front of, between
%                       and behind the mirrors
%
%   w0:                 minimal beam waist radius in mm
%   Wavelength:         wavelength of radiation in nm
%
%   Theta:              angle between incoming radiation and whole 
%                       cavity (in x-direction) in angular seconds
%   Phi:                x-angle deviation of 2nd mirror in angular seconds
%   Rho:                y-angle deviation of 2nd mirror 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.3
% Copyright: Birk Andreas 20060629

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @fpisimulator_OpeningFcn, ...
                   'gui_OutputFcn',  @fpisimulator_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 fpisimulator_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
initialize_gui(hObject, handles);

function varargout = fpisimulator_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 z_Callback(hObject, eventdata, handles)
handles.z=str2double(get(hObject,'String'));
if handles.z < 0
    handles.z=-handles.z;
end
guidata(hObject, handles);

function z_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 phi_Callback(hObject, eventdata, handles)
handles.phi=str2double(get(hObject,'String'));
guidata(hObject, handles);

function phi_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function rho_Callback(hObject, eventdata, handles)
handles.rho=str2double(get(hObject,'String'));
guidata(hObject, handles);

function rho_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 w0_Callback(hObject, eventdata, handles)
handles.w0=str2double(get(hObject,'String'));
if handles.w0 < 0
    handles.w0=-handles.w0;
end
guidata(hObject, handles);

function w0_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;
z=1e-3*handles.z;
w0=1e-3*handles.w0;
lambda=1e-9*handles.lambda;
n=handles.n;
d=handles.d*lambda;
r=handles.r;
theta=pi/648000*handles.theta;
phi=pi/648000*handles.phi;
rho=pi/648000*handles.rho;
mult=round(handles.mult);
k=2*pi*n/lambda;
c=sqrt(2/(pi*w0^2));
z0=n*pi*w0^2/lambda;
F=4*r/(1-r)^2;
t=1-r;
gr=max([theta phi rho]);
versatz=tan(gr*2*F)*abstand;
pixel2=round((breite+versatz)/breite*pixel*2);
Et=zeros(pixel2);
randfield=rand(2,mult)*(breite+versatz)-(breite+versatz)/2;
for N=1:mult
    x=randfield(1,N);
    y=randfield(2,N);
    for m=1:F
        xim=theta+m*2*phi;
        etam=m*2*rho;
        xm=x-m*2*d*tan(xim);
        ym=y-m*2*d*tan(etam);
        zm=z+m*2*d*2*1/sqrt((tan(xim))^2+(tan(etam))^2+1);
        w=sqrt(w0^2*(1+(zm/z0)^2));
        R=zm*(1+(z0/zm)^2);
        xd=xm+tan(xim)*abstand;
        yd=ym+tan(etam)*abstand;
        zd=zm+abstand*1/sqrt((tan(xim))^2+(tan(etam))^2+1);
        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*r^m*w0/w*exp(-(xd^2+yd^2)/w^2)*exp(-i*(k*zd-atan(zd/z0)))...
            *exp(-i*k*(xd^2+yd^2)/(2*R))*c;
        Et(iy-1,ix)=Et(iy-1,ix)+xf*yc*A;
        Et(iy,ix-1)=Et(iy,ix-1)+xc*yf*A;
        Et(iy-1,ix-1)=Et(iy-1,ix-1)+xc*yc*A;
        Et(iy,ix)=Et(iy,ix)+xf*yf*A;
    end
end
I=Et.*conj(Et);
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));
surf(I);
shading interp;
view(2);
assignin('base','Intensity',I);
P=angle(Et);
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','Phase',P);

function initialize_gui(fig_handle, handles)
handles.breite=3;
handles.pixel=100;
handles.abstand=1000;
handles.z=100;
handles.w0=1;
handles.lambda=532;
handles.n=1;
handles.d=1000;
handles.r=0.3;
handles.theta=0;
handles.phi=0;
handles.rho=0;
handles.mult=3e5;
guidata(handles.figure1, handles);

function axes1_CreateFcn(hObject, eventdata, handles)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -