% Practice Problems 6.2, 6.3, 6.12

% Practice problems 6.2, 6.3, 6.12

% Jeff Pieper

% March 2004

clear

% Problem 6.2

w = [ 1 2 5 10 20 50 100 ] ;

G = tf(1,[1 10]) ;

[m,p]=bode(G,w) ;

for k=1:length(w),

mdb(k) = 20*log10(m(:,:,k)) ;

ph(k) = p(:,:,k) ;

end

mlow = 20*log10(1/10) ;

figure(1)

clf

subplot(2,1,1)

semilogx(w,mdb,'x',[1 10],[mlow mlow],'-b',[10 100],[mlow mlow-20],'-b')

xlabel('Frequency (r/s)')

ylabel('magnitude (dB)')

title('Exact versus asymptote frequency response of 1/s+10')

axis([1 100 -50 -10])

subplot(2,1,2)

semilogx(w,ph,'x',[1 10],[0 0],'-b',[10 10],[0 -90],'-b',[10 100],[-90 -90],'-b')

xlabel('Frequency (r/s)')

ylabel('phase (deg)')

axis([1 100 -100 10])

% problem 6.3

clear

Ga = tf(4000,[1 400 0]) ;

Gb = tf(100,conv([0.1 1 0],[0.5 1])) ;

Gc = tf(1,conv([1 1 0],[0.02 1])) ;

Gd = tf(1,conv([1 2 1],[1 2 4])) ;

Ge = tf([10 40],conv([1 1 0],[1 2 5])) ;

Gf = tf([1000 100],conv([1 1 0],[1 8 64])) ;

Gg = tf(conv([1 5],[1 3]),conv([1 1 0],[1 1 4])) ;

Gh = tf([4 40 0],conv([1 100],[4 5 4])) ;

Gi = tf([1 0],conv([1 1],conv([1 10],[1 2 2500]))) ;

w= logspace(-2,4,200) ;

for j=1:9,

switch j

case 1

G=Ga ;

msg = 'part a' ;

case 2

G=Gb ;

msg = 'part b' ;

case 3

G=Gc ;

msg = 'part c' ;

case 4

G=Gd ;

msg = 'part d' ;

case 5

G=Ge ;

msg = 'part e' ;

case 6

G=Gf ;

msg = 'part f' ;

case 7

G=Gg ;

msg = 'part g' ;

case 8

G=Gh ;

msg = 'part h' ;

case 9

G=Gi ;

msg = 'part i' ;

end

[m,p]=bode(G,w) ;

for k=1:length(w),

mdb(k) = 20*log10(m(:,:,k)) ;

ph(k) = p(:,:,k) ;

end

figure(1+j)

clf

subplot(2,1,1)

semilogx(w,mdb)

xlabel('Freq (r/s)')

ylabel('mag (dB)')

title(msg)

subplot(2,1,2)

semilogx(w,ph)

xlabel('Freq (r/s)')

ylabel('Phase (deg)')

end

% problem 6.12

clear

pole=[0.01 0.1 1 10 100] ;

w = logspace(-2,2,100) ;

figure(11)

clf

hold on

for j=1:5,

G = tf(1,conv([1/pole(j) 1],[1 1 1])) ;

[m,p] = bode(G,w) ;

for k=1:length(w),

mdb(k) = 20*log10(m(:,:,k)) ;

ph(k) = p(:,:,k) ;

end

msg = ['pole = ',num2str(pole(j))] ;

subplot(2,1,1)

semilogx(w,mdb)

hold on

xlabel('Freq (r/s)')

ylabel('mag (dB)')

text(1,mdb(50),msg)

subplot(2,1,2)

semilogx(w,ph)

hold on

xlabel('Freq (r/s)')

ylabel('Phase (deg)')

text(1,ph(50),msg)

end