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

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

% Last Modified by GUIDE v2.5 30-Jun-2007 20:06:06

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = csdesign_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');
p1=get(handles.edit3,'string');
p2=get(handles.edit4,'string');
num=str2num(num);
den=str2num(den);
p1=str2num(p1);
p2=str2num(p2);
P=[p1   p2];
[A  B  C  D]=tf2ss(num,den);
K=place(A,B,P);
syms s
csys=C*inv(s*eye(2)-(A-B*K))*B;
[numc  denc]=numden(csys);
numc=sym2poly(numc);
denc=sym2poly(denc);
numcs=poly2str(numc,'s');
dencs=poly2str(denc,'s');
n=strcat('Num= ', numcs);
d=strcat('Den= ', dencs);
set(handles.text4,'string',n)
set(handles.text8,'string',d)

% --- 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);
R=1;
[A  B  C  D]=tf2ss(num,den);
Q=eye(2);
K=lqr(A,B,Q,R);
syms s
csys=C*inv(s*eye(2)-(A-B*K))*B;
[numc  denc]=numden(csys);
numc=sym2poly(numc);
denc=sym2poly(denc);
numcs=poly2str(numc,'s');
dencs=poly2str(denc,'s');
n=strcat('Num= ', numcs);
d=strcat('Den= ', dencs);
set(handles.text4,'string',n)
set(handles.text8,'string',d)

% --- 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');
p1=get(handles.edit3,'string');
p2=get(handles.edit4,'string');
num=str2num(num);
den=str2num(den);
p1=str2num(p1);
p2=str2num(p2);
P=[p1   p2];
[A  B  C  D]=tf2ss(num,den);
K=place(A',C',P')';
set(handles.text4,'string','Observer Gain Matrix')
set(handles.text8,'string',K)

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 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');
p1=get(handles.edit3,'string');
p2=get(handles.edit4,'string');
num=str2num(num);
den=str2num(den);
p1=str2num(p1);
p2=str2num(p2);
P=[p1   p2];
[A  B  C  D]=tf2ss(num,den);
K=place(A,B,P);
syms s
csys=C*inv(s*eye(2)-(A-B*K))*B;
[numc  denc]=numden(csys);
numc=sym2poly(numc);
denc=sym2poly(denc);
axes(handles.axes1);
T=0:0.1:10;
[y  t]=step(numc,denc,T);
cla
plot(T,y);


% --- 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');
p1=get(handles.edit3,'string');
p2=get(handles.edit4,'string');
num=str2num(num);
den=str2num(den);
p1=str2num(p1);
p2=str2num(p2);
P=[p1   p2];
[A  B  C  D]=tf2ss(num,den);
K=place(A,B,P);
syms s
csys=C*inv(s*eye(2)-(A-B*K))*B;
[numc  denc]=numden(csys);
numc=sym2poly(numc);
denc=sym2poly(denc);
axes(handles.axes1);
T=0:0.1:10;
[y  t]=impulse(numc,denc,T);
cla
plot(T,y);

% --- 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)
num=get(handles.edit1,'string');
den=get(handles.edit2,'string');
p1=get(handles.edit3,'string');
p2=get(handles.edit4,'string');
num=str2num(num);
den=str2num(den);
p1=str2num(p1);
p2=str2num(p2);
P=[p1   p2];
[A  B  C  D]=tf2ss(num,den);
K=place(A,B,P);
syms s
csys=C*inv(s*eye(2)-(A-B*K))*B;
[numc  denc]=numden(csys);
numc=sym2poly(numc);
denc=sym2poly(denc);
w=0:1:10000;
axes(handles.axes1)
[M Ph]=bode(num,den,w);
cla
semilogx(w,M)



% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (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');
p1=get(handles.edit3,'string');
p2=get(handles.edit4,'string');
num=str2num(num);
den=str2num(den);
p1=str2num(p1);
p2=str2num(p2);
P=[p1   p2];
[A  B  C  D]=tf2ss(num,den);
K=place(A,B,P);
syms s
csys=C*inv(s*eye(2)-(A-B*K))*B;
[numc  denc]=numden(csys);
numc=sym2poly(numc);
denc=sym2poly(denc);
axes(handles.axes1)
[R Kr]=rlocus(numc,denc);
cla
plot(R)





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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
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


% --- 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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end




% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (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');
p1=get(handles.edit3,'string');
p2=get(handles.edit4,'string');
num=str2num(num);
den=str2num(den);
p1=str2num(p1);
p2=str2num(p2);
P=[p1   p2];
[A  B  C  D]=tf2ss(num,den);
K=place(A,B,P);
syms s
csys=C*inv(s*eye(2)-(A-B*K))*B;
[numc  denc]=numden(csys);
numc=sym2poly(numc);
denc=sym2poly(denc);
axes(handles.axes1)
[Pol Zer]=pzmap(numc,denc);
hold off
plot(Pol,'x')
hold on
plot(Zer,'o')
hold off


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



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

myhelp


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

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

grid off

Contact us at files@mathworks.com