close all
clear all
clc

%https://se.mathworks.com/help/matlab/graphics_transition/why-are-plot-lines-different-colors.html

load('Genb_') %Using u but without delays
load('STDb_')

load('GenOK_') %Using u, no delays, works OK
load('GenDob_') %using u, no delays, non unique steady state
load('GenDel_NOfilt_') % with delays, no filter
load('GenDel_filt_') %with delays, with filter
load('Genbat_') %baton strategy
load('Genbatf_') %baton strategy very fast tunings
load('STDdel_')  %standard with delay
load('GenDCS1theta_')   %Baton DCS 1 theta tunings
load('STDdel1theta_')  % Std delay 1 theta to compare
% %%
% uminn=-1;
% umaxx=1.2;
% figure
% subplot(4,1,1)
% plot(Gen_t,Gen_T,'Color', [0.4940    0.1840    0.5560]);
% hold on
% plot(STD_t,STD_Troom,'--','Color', [0.8500    0.3250    0.0980]);
% plot(Gen_t,Gen_Tsp,'k')
% %title('Changes in ambient temperature')
% plot(Gen_t,Gen_Tamb,'Color',[0.4660    0.6740    0.1880])
% ylabel('T (°C)')
% legend('Generalized','Standard','T^{sp}','T^{amb}'); %, 'Location','South','Orientation','horizontal')
% ylim([-10 40])
% legend boxoff 
% 
% subplot(4,1,2)
% plot(STD_t,STD_v1,'Color',[0.3010    0.7450    0.9330])
% hold on
% plot(STD_t,STD_v2,'Color',[0    0.4470    0.7410])
% plot(STD_t,STD_v3,'Color', [0.9290    0.6940    0.1250])
% plot(STD_t,STD_v4,'r')
% title('Standard structure')
% ylabel('u_i (-)')
% ylim([uminn umaxx])
% legend('AC','CW','HW', 'EH','Location','best','Orientation','horizontal')
% legend boxoff 
% 
% subplot(4,1,3)
% plot(Gen_t,Gen_u1,'Color',[0.3010    0.7450    0.9330])
% hold on
% plot(Gen_t,Gen_u2,'Color',[0    0.4470    0.7410])
% plot(Gen_t,Gen_u3,'Color', [0.9290    0.6940    0.1250])
% plot(Gen_t,Gen_u4,'r')
% title('Generalized structure')
% ylabel('u_i (-)')
% ylim([uminn umaxx])
% legend('AC','CW','HW', 'EH','Location','best','Orientation','horizontal')
% legend boxoff 
% 
% subplot(4,1,4)
% h1=plot(Gen_t,Gen_deltav1,'Color',[0.3010    0.7450    0.9330])
% hold on
% h2=plot(Gen_t,Gen_deltav2,'Color',[0    0.4470    0.7410])
% h3=plot(Gen_t,Gen_deltav3,'Color', [0.9290    0.6940    0.1250])
% h4=plot(Gen_t,Gen_deltav4,'r')
% plot(Gen_t,Gen_maxsatplot,'k--')
% plot(Gen_t,Gen_errorplot,'k--')
% legend([h1,h2,h3,h4],'AC','CW','HW', 'EH','','','Location','South','Orientation','horizontal')
% 
% legend boxoff 
% ylabel('u_i^{''} (-)')
% ylim([-2 2])
% xlabel('Time (s)')
% title ('Suggested values in generalized structure')
% 
% %%
% uminn=-1;
% umaxx=1.2;
% figure
% subplot(3,1,1)
% h1= plot(Gen_t,Gen_T,'Color', [0.7500         0    0.7500]);
% hold on
% h2= plot(STD_t,STD_Troom,'--','Color', [  0    0.7500    0.7500]);
% h3= plot(Gen_t,Gen_Tsp,'k--')
% %title('Changes in ambient temperature')
% h4= plot(Gen_t,Gen_Tamb,'Color',[0.4660    0.6740    0.1880])
% ylabel('T (°C)')
% legend([h1,h2],'Generalized','Standard','T^{sp}','T^{amb}'); %, 'Location','South','Orientation','horizontal')
% ylim([-8 30])
% title('Comparison with standard SRC ')
% legend boxoff 
% 
% 
% subplot(3,1,2)
% plot(Gen_t,Gen_u1,'Color',[0.3010    0.7450    0.9330])
% hold on
% plot(Gen_t,Gen_u2,'Color',[0    0.4470    0.7410])
% plot(Gen_t,Gen_u3,'Color', [0.9290    0.6940    0.1250])
% plot(Gen_t,Gen_u4,'r')
% title('Actual u_i')
% ylabel('u_i (-)')
% ylim([uminn umaxx])
% legend('AC','CW','HW', 'EH','Location','best','Orientation','horizontal')
% legend boxoff 
% 
% subplot(3,1,3)
% h1=plot(Gen_t,Gen_deltav1,'Color',[0.3010    0.7450    0.9330])
% hold on
% h2=plot(Gen_t,Gen_deltav2,'Color',[0    0.4470    0.7410])
% h3=plot(Gen_t,Gen_deltav3,'Color', [0.9290    0.6940    0.1250])
% h4=plot(Gen_t,Gen_deltav4,'r')
% plot(Gen_t,Gen_maxsatplot,'k--')
% plot(Gen_t,Gen_errorplot,'k--')
% legend([h1,h2,h3,h4],'AC','CW','HW', 'EH','','','Location','South','Orientation','horizontal')
% 
% legend boxoff 
% ylabel('u_i^{''} (-)')
% ylim([-2 2])
% xlabel('Time (min)')
% title ('Suggested u_i^{''}')

%%
figure
subplot(3,1,1)
plot(GenOK_t,GenOK_Tamb,'Color',[0 0.5 0])
hold on
plot(GenOK_t,GenOK_Tsp,'k--')
title('$d = T^{amb}$','Interpreter','latex')
legend('$T^{amb}$', '$T_0^{amb}$','Location','best','Orientation','horizontal','Interpreter','latex')
legend boxoff 
ylabel('Temperature (°C)')

subplot(3,1,2)
plot(GenOK_t,GenOK_T,'r');
hold on
plot(Genbat_t, Genbat_T)
plot(STD_t,STD_Troom,'--','Color', [ 0.4660    0.6740    0.1880]);
plot(GenOK_t,GenOK_Tsp,'k--')
title('$y = T$','Interpreter','latex')
legend('Previous','Baton','Standard','$T^{sp}$', 'Location','best','Orientation','horizontal','Interpreter','latex')
legend boxoff 
ylabel('Temperature (°C)')

subplot(3,1,3)
plot(GenOK_t,GenOK_u1,'Color',[0.3010    0.7450    0.9330])
hold on
plot(GenOK_t,GenOK_u2,'Color',[0    0.4470    0.7410])
plot(GenOK_t,GenOK_u3,'Color', [0.9290    0.6940    0.1250])
plot(GenOK_t,GenOK_u4,'r')
plot(GenOK_t,GenOK_maxsatplot,'k--')
plot(GenOK_t,GenOK_errorplot,'k--')
%Suggested
plot(GenOK_t,GenOK_deltav1,'--','Color',[0.3010    0.7450    0.9330])
plot(GenOK_t,GenOK_deltav2,'--','Color',[0    0.4470    0.7410])
plot(GenOK_t,GenOK_deltav3,'--','Color', [0.9290    0.6940    0.1250])
plot(GenOK_t,GenOK_deltav4,'r--')
title('$u_i$ and $u_i''$','Interpreter','latex')
legend('$u_{AC}$','$u_{CW}$','$u_{HW}$', '$u_{EH}$','Location','best','Orientation','horizontal','Interpreter','latex')
legend boxoff 
xlabel('Time (s)')
ylabel('u_i (-)')
ytickformat('%.2f')
ylim([-0.5 1.3])

%%
figure
subplot(2,1,1)
plot(GenOK_t,GenOK_Tamb,'Color',[0 0.5 0])
hold on
plot(GenOK_t,GenOK_Tsp,'k--')
title('$d = T^{amb}$','Interpreter','latex')
legend('$T^{amb}$', '$T_0^{amb}$','Location','best','Orientation','horizontal','Interpreter','latex')
legend boxoff 
ylabel('Temperature (°C)')

subplot(2,1,2)
plot(GenOK_t,GenOK_T,'r');
hold on
plot(Genbat_t, Genbat_T)
plot(Genbatf_t, Genbatf_T)
plot(STD_t,STD_Troom,'--','Color', [ 0.4660    0.6740    0.1880]);
plot(GenOK_t,GenOK_Tsp,'k--')
title('$y = T$','Interpreter','latex')
legend('Previous','Baton','Baton fast', 'Standard','$T^{sp}$', 'Location','best','Orientation','horizontal','Interpreter','latex')
legend boxoff 
ylabel('Temperature (°C)')

figure
subplot(3,1,1)
plot(GenOK_t,GenOK_u1,'Color',[0.3010    0.7450    0.9330])
hold on
plot(GenOK_t,GenOK_u2,'Color',[0    0.4470    0.7410])
plot(GenOK_t,GenOK_u3,'Color', [0.9290    0.6940    0.1250])
plot(GenOK_t,GenOK_u4,'r')
plot(GenOK_t,GenOK_maxsatplot,'k--')
plot(GenOK_t,GenOK_errorplot,'k--')
%Suggested
plot(GenOK_t,GenOK_deltav1,'--','Color',[0.3010    0.7450    0.9330])
plot(GenOK_t,GenOK_deltav2,'--','Color',[0    0.4470    0.7410])
plot(GenOK_t,GenOK_deltav3,'--','Color', [0.9290    0.6940    0.1250])
plot(GenOK_t,GenOK_deltav4,'r--')
title('$u_i$ and $u_i''$ previous strategy','Interpreter','latex')
legend('$u_{AC}$','$u_{CW}$','$u_{HW}$', '$u_{EH}$','Location','best','Orientation','horizontal','Interpreter','latex')
legend boxoff 
xlabel('Time (s)')
ylabel('u_i (-)')
ytickformat('%.2f')
ylim([-0.5 1.3])

subplot(3,1,2)
plot(Genbat_t,Genbat_u1,'Color',[0.3010    0.7450    0.9330])
hold on
plot(Genbat_t,Genbat_u2,'Color',[0    0.4470    0.7410])
plot(Genbat_t,Genbat_u3,'Color', [0.9290    0.6940    0.1250])
plot(Genbat_t,Genbat_u4,'r')
plot(Genbat_t,Genbat_maxsatplot,'k--')
plot(Genbat_t,Genbat_errorplot,'k--')
%Suggested
plot(Genbat_t,Genbat_deltav1,'--','Color',[0.3010    0.7450    0.9330])
plot(Genbat_t,Genbat_deltav2,'--','Color',[0    0.4470    0.7410])
plot(Genbat_t,Genbat_deltav3,'--','Color', [0.9290    0.6940    0.1250])
plot(Genbat_t,Genbat_deltav4,'r--')
title('$u_i$ and $u_i''$ baton strategy- same tuning','Interpreter','latex')
legend('AC','CW','HW', 'EH','Location','best','Orientation','horizontal')
legend boxoff 

subplot(3,1,3)
plot(Genbatf_t,Genbatf_u1,'Color',[0.3010    0.7450    0.9330])
hold on
plot(Genbatf_t,Genbatf_u2,'Color',[0    0.4470    0.7410])
plot(Genbatf_t,Genbatf_u3,'Color', [0.9290    0.6940    0.1250])
plot(Genbatf_t,Genbatf_u4,'r')
plot(Genbatf_t,Genbatf_maxsatplot,'k--')
plot(Genbatf_t,Genbatf_errorplot,'k--')
%Suggested
plot(Genbatf_t,Genbatf_deltav1,'--','Color',[0.3010    0.7450    0.9330])
plot(Genbatf_t,Genbatf_deltav2,'--','Color',[0    0.4470    0.7410])
plot(Genbatf_t,Genbatf_deltav3,'--','Color', [0.9290    0.6940    0.1250])
plot(Genbatf_t,Genbatf_deltav4,'r--')
title('$u_i$ and $u_i''$ baton strategy- very fast tunings','Interpreter','latex')
legend('AC','CW','HW', 'EH','Location','best','Orientation','horizontal')
legend boxoff 