📄 ex9_2b.m
字号:
%%%%%%%%%%%%%%%% Example 9.2(b) %%%%%%%%%%%%%%%%%
% Discrete-Time Control Problems using %
% MATLAB and the Control System Toolbox %
% by J.H. Chow, D.K. Frederick, & N.W. Chbat %
% Brooks/Cole Publishing Company %
% September 2002 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ---- Select lag zero & calc phase margin ----
%
disp('Example 9.2(b)')
%---- Assume that variables defined in Script 9.2(a) are in workspace
% so run ex9_2a first, and do NOT do a clear command
w_Zlag = input('Enter corner freq for lag zero [0.157]..... ')
Zlag = -w_Zlag % lag zero must be negative
Gcw = tf(Klag*[1 -Zlag],[1 -Zlag/Alag]) % lag controller
GcGHw = Gcw*GHw % connect lag in series with plant and sensor
disp('******>'), pause
lfg = dcgain(GcGHw) % low-freq gain of current design
[km,pm,wkm,wpm] = margin(GcGHw); % open-loop frequency response
disp('Gain margin and phase crossover frequency')
disp([20*log10(km) wkm]) % gain margin in dB & omega_gm
disp('Phase margin and gain crossover frequency')
disp([pm wpm]) % phase margin in degrees & omega_pm
ess = 1/(1 + dcgain(GcGHw)) % verify that steady-state error is OK
Gcz = c2d(Gcw,Ts,'tustin') % controller in z domain
disp('******>'), pause
%---------- OL frequency responses for Fig. 9.5 -----
w = logspace(-3,1);
ph180 = -180*ones(length(w));
%---- first, with gain only -----
[mag_db_K,ph_K] = bodedb(Klag*GHw,w); % bodedb returns mag in dB
%---- then with final lag design
[mag_db_lag,ph_lag] = bodedb(GcGHw,w);
%----- now plot both sets
figure
subplot(211)
semilogx(w,mag_db_lag,'-',w,mag_db_K,'--');grid;
text(0.004,7,'Proportional')
text(0.05,30,'lag')
xlabel('Frequency (rad/s)')
ylabel('Magnitude (dB)')
title('Bode plot for initial (proportional) and final (lag) design of Example 9.2')
subplot(212)
semilogx(w,ph_lag,'-',w,ph_K,'--',w,ph180,':');grid
text(0.3,-25,'Proportional')
text(0.02,-70,'lag')
xlabel('Frequency (rad/s)')
ylabel('Phase angle (deg)')
disp('******>'), pause
%--------- CL step responses for Fig. 9.6 ------
% reference response
Gz = c2d(Gp,Ts,'zoh') % discretize plant
disp('******>'), pause
Gcz = ss(Gcz) % convert to ss form for better numerics
disp('******>'), pause
Tz = Gz*Gcz/(1+GHz*Gcz) % closed-loop transfer function
disp('******>'), pause
[y,tt] = step(Tz,8); % step response to 8 s
yss = dcgain(Tz);
figure
plot(tt,y,'o');grid
hold on
plot([0 8],[yss yss],'--')
hold off
xlabel('Time (s)')
ylabel('Amplitude')
title('Unit-step response in the reference input for the final lag design of Example 9.2')
%%%%%%%%%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -