For Unstable system

The Graphical User Interface, understood as the use of graphic
icons and a pointing device to control a computer, has a four decade
history of incremental refinements built on some constant core
principles.
In MATLAB, the Graphical User Interface (GUI) is a convenient
tool which allows us to design and implement interactive software that
performs specific tasks. In this project, we integrated the basic concepts
and knowledge from Module 5 entitled Stability and Frequency
Response to come up with interactive software that enables the user to
input required data and obtain desired outputs that is based from the
objectives of the module.
In the GUI, the user can enter the type of input R(t), system
transfer function G(s), and the feedback H(s), all in vector form, and
click the ‘plot’ button to obtain four types of displays namely bode
plot, nyquist plot, step response, and pole-zero map. With all these
display windows, we can visually evaluate if the system is stable or
unstable or we can just click the ‘margin’ button which displays
parameters taken from the bode plot, and the user can also click the
‘stability’ button which finally answers the question ‘is the system
stable?’
1
Of
Stability and Frequency Response
The total response of a system is the sum of the forced and natural
reponses
c(t )  c forced (t )  cnatural (t )
With the use of these concepts here are the following definitions
of stability, instability, and marginal stability:
 Stable if the natural response approaches zero as time
approaches infinity.
 Unstable if the natural response grows without bound as
time approaches infinity.
 Marginally stable if the natural response neither decays or
grows, but remains constant or oscillates as time approaches
infinity.
Stability for linear time-invariant systems can be determined
from the location of the poles is the pole-zero map. If the poles
poles are in the left half-plane, the system is said to be stable. On
the other hand, if any poles in the right half-plane, the system is
said to be unstable. Lastly, if the poles are on the jω axis and in
the left-half plane, the system is marginally stable as long as the
poles on the jω axis are of unit multiplicity, it is unstable if there
are any multiple jωpoles.
The frequency response method may be less intuitive than other
methods you have studied previously. However, it has certain
2
advantages, especially in real-life situations such as modeling transfer
functions from physical data.
The frequency response is a representation of the system's
response to sinusoidal inputs at varying frequencies. The output of a
linear system to a sinusoidal input is a sinusoid of the same frequency
but with a different magnitude and phase. The frequency response is
defined as the magnitude and phase differences between the input
and output sinusoids. In this tutorial, we will see how we can use the
open-loop frequency response of a system to predict its behavior in
closed-loop.
To plot the frequency response, we create a vector of frequencies
(varying between zero or "DC" and infinity) and compute the value of
the plant transfer function at those frequencies. If G(s) is the open loop
transfer function of a system and w is the frequency vector, we then
plot G(jω) versusω. Since G(jω) is a complex number, we can plot both
its magnitude and phase (the Bode plot) or its position in the complex
plane (the Nyquist plot).
3
function varargout = module5_gui(varargin)
% MODULE5_GUI M-file for module5_gui.fig
%
MODULE5_GUI, by itself, creates a new MODULE5_GUI or raises the existing
%
singleton*.
%
%
H = MODULE5_GUI returns the handle to a new MODULE5_GUI or the handle to
%
the existing singleton*.
%
%
MODULE5_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%
function named CALLBACK in MODULE5_GUI.M with the given input arguments.
%
%
MODULE5_GUI('Property','Value',...) creates a new MODULE5_GUI or raises the
%
existing singleton*. Starting from the left, property value pairs are
%
applied to the GUI before module5_gui_OpeningFcn gets called. An
%
unrecognized property name or invalid value makes property application
%
stop. All inputs are passed to module5_gui_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 module5_gui
% Last Modified by GUIDE v2.5 10-Sep-2010 19:31:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @module5_gui_OpeningFcn, ...
'gui_OutputFcn', @module5_gui_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 module5_gui is made visible.
4
function module5_gui_OpeningFcn(hObject, eventdata, handles, varargin)
backgroundImage = importdata('butter.jpg');
axes(handles.axes1);
image(backgroundImage);
axes(handles.axes2);
image(backgroundImage);
axes(handles.axes3);
image(backgroundImage);
axes(handles.axes4);
image(backgroundImage);
% 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 module5_gui (see VARARGIN)
% Choose default command line output for module5_gui
handles.output = hObject;
% Update handles structure
set(hObject,'toolbar','figure');
guidata(hObject, handles);
% UIWAIT makes module5_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = module5_gui_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 edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
%
str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
5
% 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 edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
%
str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
x1=findobj(gcf,'tag','edit1');
z1=str2num(get(x1,'string'))
y1=findobj(gcf,'tag','edit2');
p1=str2num(get(y1,'string'))
x2=findobj(gcf,'tag','edit3');
z2=str2num(get(x2,'string'))
y2=findobj(gcf,'tag','edit4');
p2=str2num(get(y2,'string'))
x3=findobj(gcf,'tag','edit5');
z3=str2num(get(x3,'string'))
y3=findobj(gcf,'tag','edit6');
p3=str2num(get(y3,'string'))
r=tf([z1],[p1])
g=tf([z2],[p2])
h=tf([z3],[p3])
ht=feedback(g,h)
c=series(r,ht);
T=evalc('c');
set(handles.text6,'String',T);
6
cla(handles.axes1,'reset')
cla(handles.axes2,'reset')
cla(handles.axes3,'reset')
cla(handles.axes4,'reset')
a1=(handles.axes1);
step(a1,ht);
grid on
a2=(handles.axes2);
pzmap(a2,ht);
grid on
a3=(handles.axes3);
nyquist(a3,ht)
grid on
a4=(handles.axes4);
bode(a4,g)
grid on
% 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)
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit3 as text
%
str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (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 edit4 as text
%
str2double(get(hObject,'String')) returns contents of edit4 as a double
7
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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 edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (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 edit5 as text
%
str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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 edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (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 edit6 as text
%
str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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.
8
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
x2=findobj(gcf,'tag','edit3');
z2=str2num(get(x2,'string'))
y2=findobj(gcf,'tag','edit4');
p2=str2num(get(y2,'string'))
g=tf([z2],[p2])
[gm,pm,wcg,wcp]=margin(g)
set(handles.text7,'string',gm);
set(handles.text8,'string',pm);
set(handles.text9,'string',wcg);
set(handles.text10,'string',wcp);
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
x1=findobj(gcf,'tag','edit1');
z1=str2num(get(x1,'string'))
y1=findobj(gcf,'tag','edit2');
p1=str2num(get(y1,'string'))
x2=findobj(gcf,'tag','edit3');
z2=str2num(get(x2,'string'))
y2=findobj(gcf,'tag','edit4');
p2=str2num(get(y2,'string'))
x3=findobj(gcf,'tag','edit5');
z3=str2num(get(x3,'string'))
y3=findobj(gcf,'tag','edit6');
p3=str2num(get(y3,'string'))
r=tf([z1],[p1])
g=tf([z2],[p2])
h=tf([z3],[p3])
ht=feedback(g,h)
if all(real(pole(ht))<0.05)
set(handles.text17,'String','Yes')
else
set(handles.text17,'String','No')
end
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
9
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
backgroundImage = importdata('butter.jpg');
axes(handles.axes1);
image(backgroundImage);
axes(handles.axes2);
image(backgroundImage);
axes(handles.axes3);
image(backgroundImage);
axes(handles.axes4);
image(backgroundImage);
set(handles.text17,'string','')
set(handles.text7,'string','')
set(handles.text8,'string','')
set(handles.text9,'string','')
set(handles.text10,'string','')
set(handles.edit1,'string','')
set(handles.edit2,'string','')
set(handles.edit3,'string','')
set(handles.edit4,'string','')
set(handles.edit5,'string','')
set(handles.edit6,'string','')
set(handles.text6,'String','');
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
10
SIMULATION (EXAMPLE):
For Unstable system:
Given:
𝑅(𝑠) =
5
𝑠
𝐺(𝑠) =
30
𝑠 2 −4𝑠+9
𝐻(𝑠) =
11
2
𝑠
OUTPUT:
12