No BSD License  

Highlights from
Model of Fraunhofer Difraction on a Rectangular Hole

image thumbnail
from Model of Fraunhofer Difraction on a Rectangular Hole by Dmitry Klyuykov
Model of Fraunhofer difraction on a rectangular hole.

Difract(varargin)
function varargout = Difract(varargin)
% DIFRACT M-file for Difract.fig
%      DIFRACT, by itself, creates a new DIFRACT or raises the existing
%      singleton*.
%
%      H = DIFRACT returns the handle to a new DIFRACT or the handle to
%      the existing singleton*.
%
%      DIFRACT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in DIFRACT.M with the given input arguments.
%
%      DIFRACT('Property','Value',...) creates a new DIFRACT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Difract_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Difract_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

% Copyright 2002-2003 The MathWorks, Inc.

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

% Last Modified by GUIDE v2.5 11-Oct-2005 23:08:25

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Difract_OpeningFcn, ...
                   'gui_OutputFcn',  @Difract_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 Difract is made visible.
function Difract_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 Difract (see VARARGIN)

% Choose default command line output for Difract
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = Difract_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;



function txtA_Callback(hObject, eventdata, handles)
% hObject    handle to txtA (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtA as text
%        str2double(get(hObject,'String')) returns contents of txtA as a double


% --- Executes during object creation, after setting all properties.
function txtA_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtA (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function txtB_Callback(hObject, eventdata, handles)
% hObject    handle to txtB (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtB as text
%        str2double(get(hObject,'String')) returns contents of txtB as a double


% --- Executes during object creation, after setting all properties.
function txtB_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtB (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


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

%length of wave
lambda = 10^(-4);
%size of a hole
a = str2double(get(handles.txtA, 'String'));
b = str2double(get(handles.txtB, 'String'));
%base intensity
Eo = str2double(get(handles.txtEo, 'String'));
%wave number
k = 2*pi/lambda;
%massive for difraction picture
In = zeros(a*10,b*10);
%Calculating and filling of difraction picture with Fraunhofer integral
for m = 1:a*10
    for n = 1:b*10
        In(m,n) = Eo*10^33*((2*sin(k*m/20)/(k*m/10)))*((2*sin(k*n/20)/(k*n/10)));
    end
end
%fast fourier transform for 100x100 screen
Tran = fft2(In,10*10,10*10);
Tran2 = fftshift(Tran);
%displaying of difraction picture
axes(handles.axeDifract);
subimage(log(abs(Tran2)),[3 20]);


function txtEo_Callback(hObject, eventdata, handles)
% hObject    handle to txtEo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of txtEo as text
%        str2double(get(hObject,'String')) returns contents of txtEo as a double


% --- Executes during object creation, after setting all properties.
function txtEo_CreateFcn(hObject, eventdata, handles)
% hObject    handle to txtEo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


Contact us at files@mathworks.com