Sie sind auf Seite 1von 10

function varargout = z_domain_plot(varargin)

% Z_DOMAIN_PLOT MATLAB code for z_domain_plot.fig


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

% Last Modified by GUIDE v2.5 18-Feb-2017 19:08:42

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @z_domain_plot_OpeningFcn, ...
'gui_OutputFcn', @z_domain_plot_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 z_domain_plot is made visible.


function z_domain_plot_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 z_domain_plot (see VARARGIN)
cla(handles.axes1, 'reset')
cla(handles.axes2, 'reset')
set(handles.axes1, 'Visible', 'off')
set(handles.axes2, 'Visible', 'off')
clc;
% Choose default command line output for z_domain_plot
handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes z_domain_plot wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = z_domain_plot_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 Zcoeff1_Callback(hObject, eventdata, handles)


% hObject handle to Zcoeff1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str2num(get(handles.Zcoeff1, 'String'));
% Hints: get(hObject,'String') returns contents of Zcoeff1 as text
% str2double(get(hObject,'String')) returns contents of Zcoeff1 as a
double

% --- Executes during object creation, after setting all properties.


function Zcoeff1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Zcoeff1 (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 Pcoeff1_Callback(hObject, eventdata, handles)


% hObject handle to Pcoeff1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str2num(get(handles.Pcoeff1, 'String')); %#ok<*ST2NM>
% Hints: get(hObject,'String') returns contents of Pcoeff1 as text
% str2double(get(hObject,'String')) returns contents of Pcoeff1 as a
double

% --- Executes during object creation, after setting all properties.


function Pcoeff1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pcoeff1 (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 Zcoeff2_Callback(hObject, eventdata, handles)


% hObject handle to Zcoeff2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str2num(get(handles.Zcoeff2, 'String'));
% Hints: get(hObject,'String') returns contents of Zcoeff2 as text
% str2double(get(hObject,'String')) returns contents of Zcoeff2 as a
double

% --- Executes during object creation, after setting all properties.


function Zcoeff2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Zcoeff2 (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 Pcoeff2_Callback(hObject, eventdata, handles)


% hObject handle to Pcoeff2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str2num(get(handles.Pcoeff2, 'String'));
% Hints: get(hObject,'String') returns contents of Pcoeff2 as text
% str2double(get(hObject,'String')) returns contents of Pcoeff2 as a
double

% --- Executes during object creation, after setting all properties.


function Pcoeff2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pcoeff2 (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 Zcoeff3_Callback(hObject, eventdata, handles)


% hObject handle to Zcoeff3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str2num(get(handles.Zcoeff3, 'String'));
% Hints: get(hObject,'String') returns contents of Zcoeff3 as text
% str2double(get(hObject,'String')) returns contents of Zcoeff3 as a
double

% --- Executes during object creation, after setting all properties.


function Zcoeff3_CreateFcn(hObject, eventdata, handles)
% hObject handle to Zcoeff3 (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 Pcoeff3_Callback(hObject, eventdata, handles)


% hObject handle to Pcoeff3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str2num(get(handles.Pcoeff3, 'String'));
% Hints: get(hObject,'String') returns contents of Pcoeff3 as text
% str2double(get(hObject,'String')) returns contents of Pcoeff3 as a
double

% --- Executes during object creation, after setting all properties.


function Pcoeff3_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pcoeff3 (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 pz_plot_pb.


function pz_plot_pb_Callback(hObject, eventdata, handles)
% hObject handle to pz_plot_pb (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Ts
global HZ
global a0 a1 a2 a3 b0 b1 b2 b3
global num den
global Poles Zeros

Ts = 0.1;
a0 = str2num(get(handles.Pcoeff1, 'String'));
a1 = str2num(get(handles.Pcoeff2, 'String'));
a2 = str2num(get(handles.Pcoeff3, 'String'));
a3 = str2num(get(handles.Pcoeff4, 'String'));

b0 = str2num(get(handles.Zcoeff1, 'String'));
b1 = str2num(get(handles.Zcoeff2, 'String'));
b2 = str2num(get(handles.Zcoeff3, 'String'));
b3 = str2num(get(handles.Zcoeff4, 'String'));

if isempty(b0) || isempty(b1) || isempty(b2) || isempty(b3) ||...


isempty(a0) || isempty(a1) || isempty(a2) || isempty(a3)
errordlg('There is a missing input field(s) !!!', 'Error')
elseif b0 == 0 && b1 == 0 && b2 == 0 && b3 == 0 &&...
a0 == 0 && a1 == 0 && a2 == 0 && a3 == 0
errordlg('All Values cannot be equal ZERO !!!', 'Error')
elseif a0 == 0 && a1 == 0 && a2 == 0 && a3 == 0
errordlg('The denominators specified must be nonzero.', 'Error')
else
num = [b0, b1, b2, b3]; % b
den = [a0, a1, a2, a3]; % a
HZ = tf(num, den, Ts, 'variable', 'z^-1');

Zeros = zero(HZ);
Poles = pole(HZ);
set(handles.zT, 'String', num2str(Zeros, '% 2.3g'))
set(handles.pT, 'String', num2str(Poles, '% 2.3g'))

T = evalc('HZ');
set(handles.textT, 'String', T);
axes(handles.axes1)
pzplot(HZ)
axis equal
end

% --- Executes on button press in imp_plot_pb.


function imp_plot_pb_Callback(hObject, eventdata, handles)
% hObject handle to imp_plot_pb (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global HZ
global Ts
global a0 a1 a2 a3 b0 b1 b2 b3
global num den
global Poles Zeros

a0 = str2num(get(handles.Pcoeff1, 'String'));
a1 = str2num(get(handles.Pcoeff2, 'String'));
a2 = str2num(get(handles.Pcoeff3, 'String'));
a3 = str2num(get(handles.Pcoeff4, 'String'));

b0 = str2num(get(handles.Zcoeff1, 'String'));
b1 = str2num(get(handles.Zcoeff2, 'String'));
b2 = str2num(get(handles.Zcoeff3, 'String'));
b3 = str2num(get(handles.Zcoeff4, 'String'));

num = [b0, b1, b2, b3]; % b


den = [a0, a1, a2, a3]; % a

if isempty(b0) || isempty(b1) || isempty(b2) || isempty(b3) ||...


isempty(a0) || isempty(a1) || isempty(a2) || isempty(a3)
errordlg('There is a missing input field(s) !!!', 'Error')
elseif b0 == 0 && b1 == 0 && b2 == 0 && b3 == 0 && ...
a0 == 0 && a1 == 0 && a2 == 0 && a3 == 0
errordlg('All Values cannot be equal ZERO !!!', 'Error')
elseif a0 == 0 && a1 == 0 && a2 == 0 && a3
errordlg('The denominators specified must be nonzero.', 'Error')
elseif nnz(Zeros) > nnz(Poles)
if den(1) == 0
errordlg('First coefficient of denimenator must be non-zero.')
else
n = 5;
num = [num, zeros(1, n-1)];

[q, ~] = deconv(num, den);


HZ = tf(q, 1, Ts, 'variable', 'z^-1');

axes(handles.axes2)
response = impulse(HZ)*Ts;
Nvector = 0:length(response)-1;
stem(Nvector, response, 'r','linewidth', 1.2);
xlim([0 6])
grid minor
title('n VS h(n)_{Closed Form}', 'FontSize', 11)
end
else
HZ = tf(num, den, Ts, 'variable', 'z^-1');

T = evalc('HZ');
set(handles.textT, 'String', T);

axes(handles.axes2)
response = impulse(HZ)*Ts;
Nvector = 0:length(response)-1;
stem(Nvector, response, 'linewidth', 1.2);
xlim([0 100])
grid minor
title('n VS h(n)')
end

% --------------------------------------------------------------------
function Author_Callback(hObject, eventdata, handles)
% hObject handle to Author (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
msgbox(sprintf(['This product is developed by Osama Abbas,' ...
'\nCurrently a Teaching Assistant at AAST.' ...
'\nContact me: osama_abbas@student.aast.edu']), 'Author', 'Help')

% --------------------------------------------------------------------
%%
% $function common_pairs_Callback(hObject, eventdata, handles)$
% hObject handle to common_pairs (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fileName = 'Z-Transform Common Pairs.pdf';
winopen(fileName);

% --- Executes during object creation, after setting all properties.


function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
movegui('center')

% --- Executes when figure1 is resized.


function figure1_SizeChangedFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(gcf, 'Resize', 'on')

function Zcoeff4_Callback(hObject, eventdata, handles)


% hObject handle to Zcoeff4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str2num(get(handles.Zcoeff4, 'String'));
% Hints: get(hObject,'String') returns contents of Zcoeff4 as text
% str2double(get(hObject,'String')) returns contents of Zcoeff4 as a
double

% --- Executes during object creation, after setting all properties.


function Zcoeff4_CreateFcn(hObject, eventdata, handles)
% hObject handle to Zcoeff4 (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 Pcoeff4_Callback(hObject, eventdata, handles)


% hObject handle to Pcoeff4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str2num(get(handles.Pcoeff4, 'String'));
% Hints: get(hObject,'String') returns contents of Pcoeff4 as text
% str2double(get(hObject,'String')) returns contents of Pcoeff4 as a
double

% --- Executes during object creation, after setting all properties.


function Pcoeff4_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pcoeff4 (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 clear_data.


function clear_data_Callback(hObject, eventdata, handles)
% hObject handle to clear_data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.Pcoeff1, 'String', '')
set(handles.Pcoeff2, 'String', '')
set(handles.Pcoeff3, 'String', '')
set(handles.Pcoeff4, 'String', '')
set(handles.Zcoeff1, 'String', '')
set(handles.Zcoeff2, 'String', '')
set(handles.Zcoeff3, 'String', '')
set(handles.Zcoeff4, 'String', '')
cla(handles.axes1, 'reset')
cla(handles.axes2, 'reset')
set(handles.axes1, 'Visible', 'off')
set(handles.axes2, 'Visible', 'off')
set(handles.textT, 'String', '')
set(handles.pT, 'String', '')
set(handles.zT, 'String', '')
msgbox('All data cleared', 'Clear', 'Warn')
beep

% --- Executes on button press in rand_data.


function rand_data_Callback(hObject, eventdata, handles)
% hObject handle to rand_data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
rng('shuffle')
gen_data = rand(1, 8);
gen_data(1) = round(gen_data(1), 1);
gen_data(2) = round(gen_data(2), 1);
gen_data(3) = round(gen_data(3), 1);
gen_data(4) = round(gen_data(4), 1);
gen_data(5) = round(gen_data(5), 1);
gen_data(6) = round(gen_data(6), 1);
gen_data(7) = round(gen_data(7), 1);
gen_data(8) = round(gen_data(8), 1);
set(handles.Zcoeff1, 'String', gen_data(1))
set(handles.Zcoeff2, 'String', gen_data(2))
set(handles.Zcoeff3, 'String', gen_data(3))
set(handles.Zcoeff4, 'String', gen_data(4))
set(handles.Pcoeff1, 'String', gen_data(5))
set(handles.Pcoeff2, 'String', gen_data(6))
set(handles.Pcoeff3, 'String', gen_data(7))
set(handles.Pcoeff4, 'String', gen_data(8))

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

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

% --------------------------------------------------------------------
function Quit_Callback(hObject, eventdata, handles)
% hObject handle to Quit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(handles.figure1);

% --------------------------------------------------------------------
function Save_Callback(hObject, eventdata, handles)
% hObject handle to Save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
f = figure;
copyobj(handles.axes2, f)
copyobj(handles.axes1, f)
saveas(f, 'Plotting Panel.png')

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

Das könnte Ihnen auch gefallen