?? icdtool.m
字號:
% Plot
bode(h1);
title('Bode Diagram h1')
case 'Nyquist Gamma*h1' % User selects sinc
h1=getappdata(hMainGui,'h1');
syms p
g=tf2sym(gamma*h1);
nyqmimo(gamma*h1);
title('Nyquist Diagram of Gamma*h1')
case 'Bode Gamma*h1'
h1=getappdata(hMainGui,'h1');
margin(minreal(gamma*h1))
case 'Nyquist C1'
C1=getappdata(hMainGui,'C1');
% Status Window
[num,den]=tfdata(C1,'v');
den=roots(den);
RHPP=0;
for i=1:length(den)
if sign(real(den))==1
RHPP=RHPP+1;
end
end
vars{1}=sprintf('%-d RHPP in C1',RHPP);
set(handles.status_window,'String',vars)
% Plot
syms p
g=tf2sym(C1);
nyqmimo(C1);
title('Nyquist Diagram of C1')
case 'Bode C1'
C1=getappdata(hMainGui,'C1');
margin(C1);
case 'Step of C1->R1'
C1=getappdata(hMainGui,'C1');
C1cl=C1/(1+C1);
step(C1cl);
grid on
title('Step Response of C1->R1')
case 'Step of C1->R2'
h2=getappdata(hMainGui,'h2');
S1=getappdata(hMainGui,'S1');
Pref1=minreal(((g12/g22)*h2)*S1);
step(Pref1);
grid on
title('Step Response of C1->R2')
end
% --- Executes during object creation, after setting all properties.
function popupmenu_C1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu_C1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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 selection change in popupmenu_C2.
function popupmenu_C2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu_C2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu_C2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu_C2
hMainGui = getappdata(0,'hMainGui');
G = getappdata(hMainGui,'G');
gamma = getappdata(hMainGui,'gamma');
g11 = G(1,1);
g12 = G(1,2);
g21 = G(2,1);
g22 = G(2,2);
val = get(hObject,'Value');
str = get(hObject, 'String');
figure(2)
switch str{val};
case 'Nyquist of Gamma' % User selects peaks
% Status window
[num11,den11]=tfdata(g11,'v');
[num22,den22]=tfdata(g22,'v');
zeros11=roots(num11);
zeros22=roots(num22);
RHPP11=0;
RHPP22=0;
for i=1:length(zeros11)
if sign(real(zeros(i)))==1
RHPP11=RHPP11+1;
end
end
for i=1:length(zeros22)
if sign(real(zeros22(i)))==1
RHPP22=RHPP22+1;
end
end
s1=sprintf('%-d RHPP in g11',RHPP11);
s2=sprintf('%-d RHPP in g22',RHPP22);
vars{1}='RHPP of Gamma';
vars{2}=s1;
vars{3}=s2;
set(handles.status_window,'String',vars)
%Plot
syms p
g=tf2sym(gamma);
nyqmimo(gamma);
title('Nyquist Diagram of Gamma')
case 'Bode k2*g22' % User selects membrane
k2=getappdata(hMainGui,'k2');
margin(k2*g22);
case 'Bode h2'
h2=getappdata(hMainGui,'h2');
% Status Window
[num,den]=tfdata(h2,'v');
den=roots(den);
RHPP=0;
for i=1:length(den)
if sign(real(den))==1
RHPP=RHPP+1;
end
end
vars{1}=sprintf('%-d RHPP in h2',RHPP);
set(handles.status_window,'String',vars)
% Plot
bode(h2);
title('Bode Diagram h2')
case 'Nyquist Gamma*h2' % User selects sinc
h2=getappdata(hMainGui,'h2');
syms p
g=tf2sym(gamma*h2);
nyqmimo(gamma*h2);
title('Nyquist Diagram of Gamma*h2')
case 'Bode Gamma*h2'
h2=getappdata(hMainGui,'h2');
margin(minreal(gamma*h2))
case 'Nyquist C2'
C2=getappdata(hMainGui,'C2');
% Status Window
[num,den]=tfdata(C2,'v');
den=roots(den);
RHPP=0;
for i=1:length(den)
if sign(real(den))==1
RHPP=RHPP+1;
end
end
vars{1}=sprintf('%-d RHPP in C2',RHPP);
set(handles.status_window,'String',vars)
% Plot
syms p
g=tf2sym(C2);
nyqmimo(C2);
title('Nyquist Diagram of C2')
case 'Bode C2'
C2=getappdata(hMainGui,'C2');
margin(C2);
case 'Step of C2->R2'
C2=getappdata(hMainGui,'C2');
C2cl=C2/(1+C2);
step(C2cl);
grid on
title('Step response of C2->R2')
case 'Step of C2->R1'
h1=getappdata(hMainGui,'h1');
S2=getappdata(hMainGui,'S2');
Pref2=minreal(((g21/g11)*h1)*S2);
step(Pref2);
grid on
title('Step response of C2->R1')
end
% --- Executes during object creation, after setting all properties.
function popupmenu_C2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu_C2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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 updatebutton.
function updatebutton_Callback(hObject, eventdata, handles)
% hObject handle to updatebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get user input from GUI
% System data
hMainGui = getappdata(0,'hMainGui');
G = getappdata(hMainGui,'G');
gamma = getappdata(hMainGui,'gamma');
g11 = G(1,1);
g12 = G(1,2);
g21 = G(2,1);
g22 = G(2,2);
% K1 CONTROLLER
gain_k1 = str2double(get(handles.gain_K1,'String'));
poles_k1 = strread(get(handles.poles_K1,'String'));
zeros_k1 = strread(get(handles.zeros_K1,'String'));
% K2 CONTROLLER
gain_k2 = str2double(get(handles.gain_K2,'String'));
poles_k2 = strread(get(handles.poles_K2,'String'));
zeros_k2 = strread(get(handles.zeros_K2,'String'));
% Calculating data
% C1
num_k1=poly(zeros_k1);
den_k1=poly(poles_k1);
k1=tf(gain_k1*num_k1,den_k1);
% C2
num_k2=poly(zeros_k2);
den_k2=poly(poles_k2);
k2=tf(gain_k2*num_k2,den_k2);
% Subsystems and channels
h1=minreal((k1*g11)/(1+k1*g11));
h2=minreal((k2*g22)/(1+k2*g22));
C1=minreal((k1*g11)*(1-(gamma*h2)));
C2=minreal((k2*g22)*(1-(gamma*h1)));
% C1cl=C1/(1+C1);
% C2cl=C2/(1+C2);
% Sensibility channels
S1=minreal(1/(1+C1));
T1=minreal(C1/(1+C1));
S2=minreal(1/(1+C2));
T2=minreal(C2/(1+C2));
% Exporting data
setappdata(hMainGui,'k1',k1);
setappdata(hMainGui,'k2',k2);
setappdata(hMainGui,'h1',h1);
setappdata(hMainGui,'h2',h2);
setappdata(hMainGui,'C1',C1);
setappdata(hMainGui,'C2',C2);
setappdata(hMainGui,'S1',S1);
setappdata(hMainGui,'S2',S2);
setappdata(hMainGui,'T1',T1);
setappdata(hMainGui,'T2',T2);
% --- Executes on selection change in status_window.
function status_window_Callback(hObject, eventdata, handles)
% hObject handle to status_window (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns status_window contents as cell array
% contents{get(hObject,'Value')} returns selected item from status_window
% --- Executes during object creation, after setting all properties.
function status_window_CreateFcn(hObject, eventdata, handles)
% hObject handle to status_window (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 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)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -