光学基于matlab GUI菲涅尔系数计算含Matlab源码 1165期

Posted 紫极神光

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了光学基于matlab GUI菲涅尔系数计算含Matlab源码 1165期相关的知识,希望对你有一定的参考价值。

一、简介

基于matlab GUI菲涅尔系数计算:通过平面波反射系数演示,解释不儒斯特角,展示垂直极化系数与水平极化系数的幅度和相位关系。

二、源代码

function varargout = Fresnel(varargin)
% FRESNEL MATLAB code for Fresnel.fig
%      FRESNEL, by itself, creates a new FRESNEL or raises the existing
%      singleton*.
%
%      H = FRESNEL returns the handle to a new FRESNEL or the handle to
%      the existing singleton*.
%
%      FRESNEL('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FRESNEL.M with the given input arguments.
%
%      FRESNEL('Property','Value',...) creates a new FRESNEL or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Fresnel_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Fresnel_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Fresnel

% Last Modified by GUIDE v2.5 28-May-2021 12:02:27

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Fresnel_OpeningFcn, ...
                   'gui_OutputFcn',  @Fresnel_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 Fresnel is made visible.
function Fresnel_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Fresnel (see VARARGIN)

% Choose default command line output for Fresnel
set(handles.uipanel11,'Visible','off');
set(handles.uipanel7,'Visible','on');
set(handles.uipanel8,'Visible','on');
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Fresnel wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Fresnel_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in radiobutton_Rs.
function radiobutton_Rs_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton_Rs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton_Rs


% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton2


% --- Executes on button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton3


% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton4


% --- Executes on button press in radiobutton5.
function radiobutton5_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton5


% --- Executes on button press in radiobutton6.
function radiobutton6_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton6


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
n1 = str2double(get(handles.edit_n1,'String'));
n2 = str2double(get(handles.edit_n2,'String'));

if isnan(n1)
    errordlg('Input must be a number','Error');
end
if isnan(n2)
    errordlg('Input must be a number','Error');
end
Incidence = pi/2;%入射角范围

d = 0.1*pi/180;
xx = 0:d:Incidence;%入射角

%画图的横坐标
X = xx.*180/pi;

Transmission = asin((n1*sin(xx))./n2);%透射角
[ver,hor] = find((n1*sin(xx))./n2 > 1);%大于全反射角置零
Transmission(ver,hor) = 0;

%选择输出参数
line_rs = get(handles.radiobutton_rrs,'Value');
line_rp = get(handles.radiobutton_rp,'Value');
line_ts = get(handles.radiobutton_ts,'Value');
line_tp = get(handles.radiobutton_tp,'Value'); 
line_ps = get(handles.radiobutton_ps,'Value'); 
line_Ts = get(handles.radiobutton_Ts,'Value'); 
line_Tp = get(handles.radiobutton_Tp,'Value');
line_pp = get(handles.radiobutton_pp,'Value');
line_Tn = get(handles.radiobutton_Tn,'Value');
line_pn = get(handles.radiobutton_pn,'Value');

%计算透反射系数
rs = -sin(xx - Transmission)./sin(xx + Transmission);
ts = 2*sin(Transmission).*cos(xx)./sin(xx + Transmission);
rp = tan(xx - Transmission)./tan(xx + Transmission);
tp = 2*sin(Transmission).*cos(xx)./(sin(xx + Transmission).*cos(xx - Transmission));

%计算透反射比
ps = rs.*rs;
Ts = n2.*cosd(Transmission)./(n1.*cosd(xx)).*ts.*ts;
pp = rp.*rp;
Tp = n2.*cosd(Transmission)./(n1.*cosd(xx)).*tp.*tp;

%选择光波类型
Model = get(handles.popupmenu_model,'Value');%1为线偏光,2为自然光
if Model == 1 %线偏光
    %绘图

    %透、反射系数部分
    axes(handles.axes1);

    if line_rs == 1
        plot(X,rs,'color','r');
        hold on
    end
    if line_ts == 1
        plot(X,ts,'color','m');
        hold on
    end
    if line_rp == 1
        plot(X,rp,'color','g');
        hold on
    end
    if line_tp == 1 
        plot(X,tp,'color','c');
    end

    hold off

    %透、反射比部分
    axes(handles.axes2);

    if line_ps == 1
        plot(X,ps,'b');
        hold on
    end
    if line_Ts == 1
        plot(X,Ts,'y');
        hold on
    end
    if line_pp == 1
        plot(X,pp,'r');
    end
    if line_Tp == 1
        plot(X,Tp,'g'); 
    end
    hold off
else%自然光
    axes(handles.axes1);
    cla reset
    %set(handles.axes1,'Visible','off')
    pn = (ps + pp)./2;
    Tn = 1 - pn;

三、运行结果


四、备注

版本:2014a

以上是关于光学基于matlab GUI菲涅尔系数计算含Matlab源码 1165期的主要内容,如果未能解决你的问题,请参考以下文章

光学基于matlab GUI双孔干涉含Matlab源码 2119期

光学基于matlab GUI双孔干涉含Matlab源码 2119期

光学基于matlab GUI光栅条纹投影生成含Matlab源码 2118期

光学基于matlab GUI光栅条纹投影生成含Matlab源码 2118期

光学基于matlab GUI矩阵法和等效界面法光学薄膜对反射率影响含Matlab源码 2102期

光学基于matlab GUI矩阵法和等效界面法光学薄膜对反射率影响含Matlab源码 2102期