%双缝干涉可改D或f和间距
%等倾干涉可改厚度和角度
%等厚干涉可改波长
%衍射的焦距是公共的
%距孔衍射是以长为基的正方孔
% HUAS 201611030117
function varargout = GS_YS(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GS_YS_OpeningFcn, ...
'gui_OutputFcn', @GS_YS_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
% --- Executes just before GS_YS is made visible.
function GS_YS_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = GS_YS_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1_ShF.
function pushbutton1_ShF_Callback(hObject, eventdata, handles)
lambda=632e-9;
% d=0.002; %双缝间距d
d=str2num(get(handles.ShF_jianju,'string'));
D=str2num(get(handles.D_or_f,'string')); %
ymax=0.035;
xs=ymax;
ny=101;
ys=linspace(-ymax,ymax,ny);
for i=1:ny
L1=sqrt((ys(i)-d/2).^2+D/2);
L2=sqrt((ys(i)+d/2).^2+D/2);
phi=2*pi*(L1-L2)/lambda;
% b(i,:)=4*cos(phi/2).^2; %每个元素的平方,
b(i,:)=4*cos(phi/2)^2; %整体的平方
end
figure(gcf);
nclevels=255;
br=(b/4.014)*nclevels;
% subplot(1,2,1)
% title('双缝干涉');
figure(1);
image(xs,ys,br);
colormap(gray(nclevels));
% subplot(1,2,2)
% plot(b(:),ys)
% --- Executes on button press in pushbutton2_DQ.
function pushbutton2_DQ_Callback(hObject, eventdata, handles)
f=0.2;
lambda=500*10^(-9);
% d=input('薄膜厚度='); d=0.00004;%薄膜厚度e-5量级
% theta=input('倾斜角度='); theta=0.8;%倾斜角度0.1-1
d=str2num(get(handles.DQ_hd,'string'));%获取
theta=str2num(get(handles.DQ_jd,'string'));%倾斜角度0.1-1
rMax=f*tan(theta/2);
N=501;
for i=1:N
x(i)=(i-1)*2*rMax/(N-1)-rMax;
for j=1:N
y(i)=(j-1)*2*rMax/(N-1)-rMax;
r(i,j)=sqrt(x(i)^2+y(i)^2);
delta(i,j)=2*d/sqrt(1+r(i,j)^2/f^2);
Phi(i,j)=2*pi*delta(i,j)/lambda;
B(i,j)=4*cos(Phi(i,j)/2)^2;
end
end
NCLevels=255;
Br=B/4*NCLevels;
% title('等倾干涉');
figure(2);
image(x,y,Br);
colormap(gray(NCLevels));
axis square;
% --- Executes on button press in pushbutton3_DH.
function pushbutton3_DH_Callback(hObject, eventdata, handles)
% lamda = 0.000632;
lamda = str2num(get(handles.lamada,'string'));
[X,Y] = meshgrid(-2:0.01:2);
for R=3200:-500:200
I=cos(pi/lamda*(X.^2+Y.^2)/(R)+pi/2);
% title('等厚干涉');
figure(3);
imshow(I) %将光强显示为灰度值
% pause(0.8)
end
function DQ_hd_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function DQ_hd_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function DQ_jd_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function DQ_jd_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function ShF_jianju_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function ShF_jianju_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function D_or_f_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function D_or_f_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function lamada_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function lamada_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function slit_wid_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function slit_wid_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function rec_len_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function rec_len_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function rec_wid_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function rec_wid_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function focus_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function focus_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton7_yuankong.
function pushbutton7_yuankong_Callback(hObject, eventdata, handles)
lambda=632e-9;
f=str2num(get(handles.focus,'string'));
a=2e-3;
m=200;
ym=2000*lambda*f;
ys=linspace(-ym,ym,m);
xs=ys;
n=255;
for i=1:m
r=xs(i)^2+ys.^2;
sinth=sqrt(r./(r+f^2));
x=2*pi*a*sinth./lambda;
hh=(2*besselj(1,x)).^2./x.^2;
%b(:,i)=(hh).*5000;
b(:,i)=(hh).*10000;
end
figure(4);
% imshow(b)%失去了颜色
% figure(2);
% subplot(1,2,1);
image(xs,ys,b)
% subplot(1,2,2);
% plot(hh,x)
% colormap(gray(n));
% --- Executes on button press in pushbutton8_jukong.
function pushbutton8_jukong_Callback(hObject, eventdata, handles)
len= str2num(get(handles.rec_len,'string'));%获取距孔长
wid= str2num(get(handles.rec_wid,'string'));
foc= str2num(get(handles.focus,'string'));
lamr=650e-9;
%lamg=520e-9;
%lamb=450e-9;
f=foc;
%定义波长以及透镜长度
xmax=len;
ymax=wid;
% xmax=0.025e-4;
% ymax=0.025e-4;
sinix=0;
siniy=0;
%定义矩形孔尺寸以及x,y轴偏移量
cx=0.3;
cy=0.3;
%观察屏尺寸
N=10e2;
x=linspace(-xmax,xmax,N);
y=linspace(-ymax,ymax,N);
%如果采用积分法需要使用的光源坐标坐标
x1=linspace(-cx,cx,N);
y1=linspace(-cy,cy,N);
%观察屏坐标
numx=length(x);
numy=length(y);
I=zeros(numx,numy,3);
%定义三色矩阵
for t=1:numx
for tt=1:numy
alphar=pi*2*xmax/lamr*(x1(t)/f-sinix);
% alphag=pi*2*xmax/lamg*(x1(t)/f-sinix);
% alphab=pi*2*xmax/lamb*(x1(t)/f-sinix);
betar=pi*2*xmax/lamr*(x1(tt)/f-siniy);
% betag=pi*2*xmax/lamg*(x1(tt)/f-siniy);
% betab=pi*2*xmax/lamb*(x1(tt)/f-siniy);
I(t,tt,1)=(sin(alphar)/alphar)^2*(sin(betar)/betar)^2;
Ix(t)=(sin(alphar)/alphar)^2;
Iy(tt)=(sin(betar)/betar)^2;
% I(t,tt,2)=(sin(alphag)/alphag)^2*(sin(betag)/betag)^2;
% I(t,tt,3)=(sin(alphab)/alphab)^2*(sin(betab)/betab)^2;
end
end
Ix=Ix/max(Ix);
Iy=Iy/max(Iy);
I=I/max(max(max(I)));
% subplot(2,2,1);
% imshow(255*I)
% subplot(2,2,2);
% plot(Ix,x)
% subplot(2,2,3);
% plot(y,Iy)
figure(5);
subplot(2,2,1);
imshow(255*I)
subplot(2,2,2);
plo