%LagCompenzatör
clear all; close all;
num=5;den=conv([1 1 0],[0.5 1]);
fig1=figure(1);
[Gm Gp Wm Wp]=margin(num,den);
margin(num,den);grid on;
denn=conv([100 1],den);numn=[50 5];
fig2=figure(2)
nichols(numn,denn);hold on;nichols(num,den);
figure(1);hold on;
margin(numn,denn);
title('Kompanze Edilmiþ ve Edilmemiþ sistemin Karþýlaþtýrmasý')
text(Wm,Gm,'\downarrow Kompanze Edilmiþ Sistem')
text(Wp,Gp,'\leftarrow Kompanze Edilmemiþ Sistem')
[Gm Gp Wm Wp]=margin(numn,denn);
sys=feedback(tf(1,den),1);
sys1=feedback(tf(numn,denn),1);
fig3=figure(3);
t = 0:0.02:40;
[c1,x1] = step(sys,t);[c2,x2] = step(sys1,t);
plot (t,c1,'.',t,c2,'-','linewidth',2)
grid on;
title('Kompanze Edilmiþ ve Edilmemiþ Sistemin Adým Giriþ Cevabý')
xlabel('t sn.')
ylabel('Çýkýþlar')
text(0.4,1.31,'\downarrow Kompanze Edilmiþ Sistem')
text(1.55,0.88,'\leftarrow Kompanze Edilmemiþ Sistem')
%*****Unit-ramp responses*****
t = 0:0.02:40;syss=tf(1,[1 0]);
[y1,z1] = step(syss*sys,t);
[y2,z2] = step(syss*sys1,t);
fig4=figure(4);
plot(t,y1,'b.',t,y2,'m-',t,t,'r--','linewidth',2)
grid on;
title('Kompanze Edilmiþ ve Edilmemiþ Sistemin Birim Rampa Giriþe Cevabý')
xlabel('t sn')
ylabel('Çýkýþlar')
text(0.89,3.7,'Kompanze Edilmiþ Sistem \downarrow')
text(2.25,1.1,'\uparrow Kompanze Edilmemiþ Sistem')
% 
zpk(sys1);

% lead-lag compensator
sys=tf(1,[1 3 2 0]);
sys1=tf(20,[1 3 2 0]);
sys2=tf(conv([1 0.7],[1 0.15]),conv([1 7],[1 0.015]))
fig5=figure(5)
bode(sys1);hold on;bode(sys2);hold on;
bode(sys1*sys2)
legend('Bode Diagram of G(s) = 20/[s(s + 1)(s + 2)]','Kompanzatör','Kompanze Edilmiþ Sistem')
grid on;
sys1c=feedback(sys,1)
sys2c=feedback(sys1*sys2,1)
fig6=figure(6);
t = 0:0.02:40;
[c1,x1] = step(sys1c,t);
[c2,x2] = step(sys2c,t);
plot (t,c1,'.',t,c2,'-','linewidth',2)
grid on;
title('Kompanze Edilmiþ ve Edilmemiþ Sistemin Adým Giriþ Cevabý')
xlabel('t sn.')
ylabel('Çýkýþlar')
text(0.4,1.31,'\downarrow Kompanze Edilmiþ Sistem')
text(1.55,0.88,'\leftarrow Kompanze Edilmemiþ Sistem')
%*****Unit-ramp responses*****
t = 0:0.02:40;syss=tf(1,[1 0])
[y1,z1] = step(syss*sys1c,t);
[y2,z2] = step(syss*sys2c,t);
fig7=figure(7);
plot(t,y1,'b.',t,y2,'m-',t,t,'r--','linewidth',2)
grid
title('Kompanze Edilmiþ ve Edilmemiþ Sistemin Birim Rampa Giriþe Cevabý')
xlabel('t sn')
ylabel('Çýkýþlar')
text(0.89,3.7,'Kompanze Edilmiþ Sistem \downarrow')
text(2.25,1.1,'\uparrow Kompanze Edilmemiþ Sistem')
