% Process control course  Exercise 2
%
%  This script initiallizes the necessary parameters and runs the simulink
%  model for task 4
% 
clear all
clc
warning off
% Initializing
dist_feed_time=10 ; feed_dist=0.0 ; dist_comp_time=50; comp_dist=0.0;
Vb_change_time=10; Vb_step=3.55; D_change_time=30; D_step=0.5*1.0; 
B_change_time=40; B_step=0.5*1.0; setpoint_time=10; xd_sp=0.8;
LT_change_time=10; LT_step=3.05*1.0; Vb_change_time=10;
Vb_step=3.55*1.0; D_change_time=10; D_step=0.5*1.0; B_change_time=10;
B_step=0.5*1.0;



% =========identification experiment: open loop (Kc=0) step on LT ================


% Controllers parameters
% PI controller must be turned off here
Kc=0;               % proportional gain
taui=9999999;       % integral time. set it large to get P-controller only


%Level controllers are working 
%Top level controller
Kd=-10;
%Bottom level controller
Kb=-10;

%When reflux rate(LT) changes
LT_change_time=10;
%New LT value -> 3.05 is the nominal value
LT_step=3.05*1.01;

%Simulate open loop
sim('simdist.mdl')
xd=x_out(:,4);

%Plot open loop response
figure(1)
subplot(211)
plot(time,xd)
set(gca,'FontSize',14)
title('Open-loop test')
ylabel('Top composition')
subplot(212)
plot(time,Lt)
set(gca,'FontSize',14)
ylabel('Reflux')
xlabel('Time, min')





