No BSD License  

Highlights from
GUI for Control System Design & Analysis

image thumbnail
from GUI for Control System Design & Analysis by Imtiaz Hussain
An easy to use GUI for control system analysis and design

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

% Last Modified by GUIDE v2.5 30-Jun-2007 19:50:08

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = ssanalysis_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 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)
num=get(handles.edit1,'string');
den=get(handles.edit2,'string');
num=str2num(num);
den=str2num(den);
[A B C D]=tf2ss(num,den);
CM=ctrb(A,B);

if rank(CM)==length(A)
    set(handles.text1,'string','System is State Controllable')
else
    set(handles.text1,'string','System is not State Controllable')
end

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% 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)
num=get(handles.edit1,'string');
den=get(handles.edit2,'string');
num=str2num(num);
den=str2num(den);
[A B C D]=tf2ss(num,den);
OM=obsv(A,C);

if rank(OM)==length(A)
    set(handles.text1,'string','System is State Observable')
else
    set(handles.text1,'string','System is not State Observable')
end

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% 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)

num=get(handles.edit1,'string');
den=get(handles.edit2,'string');
num=str2num(num);
den=str2num(den);
[A B C D]=tf2ss(num,den);
len=length(A);

for i=1:1:len
    OPM(i)=C*A^(i-1)*B;
end

if rank(OPM)==len
    set(handles.text1,'string','System is Output controlable')
else
    set(handles.text1,'string','System is Not Output controlable')
end

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
num=get(handles.edit1,'string');
den=get(handles.edit2,'string');
num=str2num(num);
den=str2num(den);
[A B C D]=tf2ss(num,den);
[y  t   X]=step(A,B,C,D);
axes(handles.axes1)
plot(X)

% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% 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)
num=get(handles.edit1,'string');
den=get(handles.edit2,'string');
num=str2num(num);
den=str2num(den);
[A B C D]=tf2ss(num,den);
len=length(A);
Q=eye(len);
P=lyap(A,Q);

%---------------------------------------------------------------------

if len==2;
    d1=det(A(1:2,1:2));
    detm=d1;
elseif len==3
     d1=det(A(1:2,1:2));
     d2=det(A(1:3,1:3));
     detm=[d1 d2];
elseif len==4
     d1=det(A(1:2,1:2));
     d2=det(A(1:3,1:3));
     d3=det(A(1:4,1:4));
     detm=[d1 d2 d3];
elseif len==5
     d1=det(A(1:2,1:2));
     d2=det(A(1:3,1:3));
     d3=det(A(1:4,1:4));
     d4=det(A(1:5,1:5))
     detm=[d1 d2 d3 d4];
else
    set(handles.text1,'String','Higher Orders Not Supported');
    detm=0;
end

%------------------------------------------------------------------------

for i=1:len-1
        sig(i)=sign(detm(i));
end

%---------------------------------------------------------------------

if min(sig)==-1
    set(handles.text1,'string','System is Unstable');
elseif min(sig)==0
    set(handles.text1,'string','System is Asymptotically Stable')
elseif min(sig)==1
    set(handles.text1,'string','System is Asymptotically Stable in Large')
end

%---------------------------------------------------------------------

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

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end




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

close

Contact us at files@mathworks.com