clc
clear all

%%
%%%%%%% PID response
load Data
t = Data(:,1);
r = Data(:,2);
y = Data(:,3);
u = Data(:,4);

figure(1)
clf
subplot(2,1,1)
plot(t,r,'r',t,y,'k','Linewidth',2)
xlim([0,2500])
title('PID closed-loop response')
ylabel('P [Kpa]')
legend('Setpoint','Measurement',2)
grid on
hold on

subplot(2,1,2)
plot(t,u,'k','Linewidth',2)
xlim([0,2500])
title('Valve position (manipulated variable)')
xlabel('time(sec)')
ylabel('Z')
grid on

%%
%%%%%%%% PI response

load Data_PI

t1 = Data_PI(:,1);
r1 = Data_PI(:,2);
y1 = Data_PI(:,3);
u1 = Data_PI(:,4);

figure(2)
clf
subplot(2,1,1)
plot(t1,r1,'r',t1,y1,'k','Linewidth',2)
xlim([0,2500])
title('Inlet pressure(controlled variable)')
ylabel('P [Kpa]')
legend('Setpoint','Measurement',2)
grid on
hold on

subplot(2,1,2)
plot(t1,u1,'k','Linewidth',2)
xlim([0,2500])
title('Valve position (manipulated variable)')
xlabel('time(sec)')
ylabel('Z')
grid on
