⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex9_4.m

📁 离散控制系统设计的MATLAB 代码
💻 M
字号:
%%%%%%%%%%%%%%%%%% Example 9.4 %%%%%%%%%%%%%%%%%%
%   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                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   ---- Lead-lag controller design ----
%
clear
disp('Example 9.4')

tauP1 = 2; tauP2 = 0.5; tau_sen = 0.05; Kproc = 4; % parameters
Gp = tf(Kproc,conv([tauP1 1],[tauP2 1]));          % plant Gp(s)
H  = tf(1,[tau_sen 1]);                            % sensor H(s)
GH = H*Gp;    % OL transfer function is plant * sensor in s-domain
Ts = 0.1;                                          % sampling period
GHz = c2d(GH,Ts,'zoh')         
GHw = d2c(GHz,'tustin')                            % bilinear transform 

%----- Part (a) set gain and make frequency response plot -------
Kp_reqd = 100;                    % will give ess = 1/101
plant_lfg = dcgain(GHw);
Kldlg = Kp_reqd/plant_lfg
disp('******>'), pause 
figure,bode(Kldlg*GHw),grid;      % make open-loop freq resp plot

%----- Part (b) insert lead, determine its alpha ------
ww1 = 5;                          % lead center frequency
pm_target = 55;                   % phase-margin target in degrees 
[mag1,ph1] = bodedb(Kldlg*GHw,ww1)
del_pm = pm_target - (180 + ph1)  % max phase angle in degrees 
disp('******>'), pause 
Alead = (1+sin(del_pm*pi/180))/(1-sin(del_pm*pi/180)) % Eq (9.21)
Zlead = -ww1/sqrt(Alead)          % lead zero
Gcldw = Kldlg*tf(Alead*[1  -Zlead],[1  -Alead*Zlead])  % lead
disp('******>'), pause 
figure,bode(Gcldw*GHw),grid

%------ Part (c) insert lag & determine its alpha -----------
[mag2,ph2] = bode(Gcldw*GHw,ww1)   % find gain at crossover
Alag = mag2                        % lag alpha
Zlag = -ww1/10                     % lag zero
disp('******>'), pause 
Gclgw = tf([-1/Zlag  1],[-Alag/Zlag  1]) % unity DC gain lag
Gcldlgw = Gcldw*Gclgw              % combine lead & lag for final lead-lag controller
GcldlgGHw = Gcldlgw*GHw            % put controller in series with plant + sensor
disp('******>'), pause 
[km,pm,wkm,wpm] = margin(GcldlgGHw);  % want pm = 50

%-------  OL frequency responses for Fig. 9.9 ------
w = logspace(-2,3);
ph180 = -180*ones(length(w));
%---- first, with gain only
[mag_db_K,ph_K] = bodedb(Kldlg*GHw,w);
%-------- then with final lead-lag design
[mag_db_ldlg,ph_ldlg] = bodedb(GcldlgGHw,w);
%--------- now plot both sets
figure
subplot(211)
semilogx(w,mag_db_ldlg,'-',w,mag_db_K,'--');grid;
text(5,20,'Proportional')
text(0.7,-5,'lead-lag')
xlabel('Frequency (rad/s)')
ylabel('Magnitude (dB)')
title('Bode plots of initial proportional (dashed) and lead-lad (solid) designs for Example 9.4')
subplot(212)
semilogx(w,ph_ldlg,'-',w,ph_K,'--',w,ph180,':');grid
text(0.9,-250,'Proportional')
text(10,-120,'lead-lag')
xlabel('Frequency (rad/s)')
ylabel('Phase angle (deg)')
disp('******>'), pause

%---- Part (d) build CL system for ref input with sensor in fdbk path ---
Gcldlgz = c2d(Gcldlgw,Ts,'tustin')      % convert Gc(w) to Gc(z)
Gcldlgz = ss(Gcldlgz)                   % convert to ss form
disp('******>'), pause 
Gz = c2d(Gp,Ts,'zoh')                   % obtain G(z)
Tz = Gcldlgz*Gz/(1+Gcldlgz*GHz);        % closed-loop system
yss = dcgain(Tz);
figure
[y,tt] = step(Tz,3);                    % step response for 3 s
plot(tt,y,'o');grid
hold on
plot([0 tt(end)],[yss yss],'--')
hold off
xlabel('Time (s)')
ylabel('Amplitude')
title('Unit-step response for the lead-lag design of Example 9.4')
disp('******>'), pause

%----  bandwidth of CL system using narrow freq interval
ww = logspace(0,1.5,100)';               % 1.5-decade freq interval
[mag_db_CL,ph_CL] = bodedb(Tz,ww);       % returns vectors, mag in db       
lfg = dcgain(Tz)                         % low-freq gain 
lfg_db = 20*log10(lfg)                   % low-freq gain in dB
bw_CL = bwcalc(mag_db_CL,ww,lfg_db)      % calc CL bandwidth in rad/s
%%%%%%%%%%

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -