close all

s = tf('s');
P = 1/(2.2*s^2+8.7*s+20);

step(P)
set(gca,'FontName','Arial','FontSize',12)
set(gcf,'Color',[1 1 1], 'Position', [100, 100, 800, 600])

export_fig 'C:\Users\john.dicecco\Desktop\DT\BME\BME464\BME464_NOTES\CONTROLS\FIGS\STEP_OL001.eps' -despc -r300

%P
Kp = 277;
C = pid(Kp);
T = feedback(C*P,1);

t = 0:0.01:2;

figure
step(T,t)

set(gca,'FontName','Arial','FontSize',12)
set(gcf,'Color',[1 1 1], 'Position', [100, 100, 800, 600])

export_fig 'C:\Users\john.dicecco\Desktop\DT\BME\BME464\BME464_NOTES\CONTROLS\FIGS\STEP_CL001.eps' -despc -r300

%PD
Kp = 277;
Kd = 10;
C = pid(Kp,0,Kd)
T = feedback(C*P,1)

t = 0:0.01:2;

figure
step(T,t)
set(gca,'FontName','Arial','FontSize',12)
set(gcf,'Color',[1 1 1], 'Position', [100, 100, 800, 600])

export_fig 'C:\Users\john.dicecco\Desktop\DT\BME\BME464\BME464_NOTES\CONTROLS\FIGS\STEP_CL002.eps' -despc -r300

%PI
Kp = 30;
Ki = 50;%more integral control reduces steady state error
C = pid(Kp,Ki)
T = feedback(C*P,1)

t = 0:0.01:2;

figure
step(T,t)
set(gca,'FontName','Arial','FontSize',12)
set(gcf,'Color',[1 1 1], 'Position', [100, 100, 800, 600])

export_fig 'C:\Users\john.dicecco\Desktop\DT\BME\BME464\BME464_NOTES\CONTROLS\FIGS\STEP_CL003.eps' -despc -r300

%PID 1
Kp = 300;
Ki = 225;
Kd = 40;
C = pid(Kp,Ki,Kd)
T = feedback(C*P,1);

t = 0:0.01:2;

figure 
step(T,t)
set(gca,'FontName','Arial','FontSize',12)
set(gcf,'Color',[1 1 1], 'Position', [100, 100, 800, 600])

export_fig 'C:\Users\john.dicecco\Desktop\DT\BME\BME464\BME464_NOTES\CONTROLS\FIGS\STEP_CL004.eps' -despc -r300


%PID 2
Kp = 275;
Ki = 225;
Kd = 65;
C = pid(Kp,Ki,Kd)
T = feedback(C*P,1);

t = 0:0.01:2;


figure 
step(T,t)
set(gca,'FontName','Arial','FontSize',12)
set(gcf,'Color',[1 1 1], 'Position', [100, 100, 800, 600])

export_fig 'C:\Users\john.dicecco\Desktop\DT\BME\BME464\BME464_NOTES\CONTROLS\FIGS\STEP_CL005.eps' -despc -r300


pidtool(P,'p')

pidtool(P,C)