% ***** MATLAB Code Starts Here ***** %
%DSGN_421_BODE_04_MAT
%
fig_size = [232 84 774 624];
num_p = 5;
den_p = [1 0 0 0];
ess_p = 1/num_p;
PM_p = -90;
ess_spec_cubic = 0.1;
PM_spec = 30;
wx_spec = 1;
Kc = ess_p/ess_spec_cubic;
w = logspace(-3,2,501);
[mag_p,ph_p] = bode(num_p,den_p,w);
figure(1),clf,semilogx(w,20*log10(Kc*mag_p),w,20*log10(mag_p),
'k--',w,ph_p),grid,...xlabel(
'Frequency (r/s)'),ylabel('Magnitude (db) & Phase (deg)'),...title
set(gcf,
'Position',fig_size),text(1.2,24,'K_c = 2')phimax = PM_spec + 10 - PM_p;
phimax2 = phimax/2;
alfa_d = (1 - sin(phimax2*pi/180)) / (1 + sin(phimax2*pi/180));
wxc = 1;
zc_d = wxc*sqrt(alfa_d);
pc_d = zc_d / alfa_d;
num_c_d = conv([1/zc_d 1],[1/zc_d 1]);
den_c_d = conv([1/pc_d 1],[1/pc_d 1]);
[nf_d,df_d] = series(Kc*num_c_d,den_c_d,num_p,den_p);
[mag_d,ph_d] = bode(nf_d,df_d,w);
figure(2),clf,semilogx(w,20*log10(mag_d),w,20*log10(Kc*mag_p),
'k--',w,ph_d,w,ph_p,'k--'),grid,... xlabel('Frequency (r/s)'),ylabel('Magnitude (db) & Phase (deg)'),...title(
'Lead Compensated System'),set(gcf,'Position',fig_size)i2 = find(w==wxc);
alfa_g = Kc*mag_p(i2) / alfa_d;
alfa_g2 = sqrt(alfa_g);
zc_g = wxc/20;
pc_g = zc_g/alfa_g2;
num_c_g = conv([1/zc_g 1],[1/zc_g 1]);
den_c_g = conv([1/pc_g 1],[1/pc_g 1]);
[nf_dg,df_dg] = series(num_c_g,den_c_g,nf_d,df_d);
[mag_dg,ph_dg] = bode(nf_dg,df_dg,w);
figure(3),clf,semilogx(w,20*log10(mag_dg),w,20*log10(mag_d),
'k--',w,ph_dg,w,ph_d,'k--'),grid,... xlabel('Frequency (r/s)'),ylabel('Magnitude (db) & Phase (deg)'),...title(
'Final Lag-Lead Compensated System'),set(gcf,'Position',fig_size)[GM_dg,PM_dg,wphi_dg,wx_dg] = margin(nf_dg,df_dg);
GMdb_dg = 20*log10(GM_dg);
% % ***** MATLAB Code Stops Here *****
Click the
icon to return to the Dr. Beale's home page