%% Customized Plot Response of Multiple Systems to Same Input
% lsimplot allows you to plot the simulated responses of multiple dynamic systems on the same axis. For instance, compare the closed-loop response of a system with a PI controller and a PID controller. Then, customize the plot by enabling normalization and turning the grid on.
% First, create a transfer function of the system and tune the controllers.

H = tf(4,[1 10 25]);
C1 = pidtune(H,'PI');
C2 = pidtune(H,'PID');

% Form the closed-loop systems.

sys1 = feedback(H*C1,1);
sys2 = feedback(H*C2,1);

% Plot the responses of both systems to a square wave with a period of 4 s.

[u,t] = gensig("square",4,12);
h1 = lsimplot(sys1,sys2,u,t);
legend("PI","PID")

%
% Use setoptions to enable normalization and to turn on the grid.

setoptions(h1,'Normalize','on','Grid','on')

% The plot automatically updates when you call setoptions.
%
% By default, lsimplot chooses distinct colors for each system that you plot. You can specify colors and line styles using the LineSpec input argument.

h2 = lsimplot(sys1,"r--",sys2,"b",u,t);
legend("PI","PID")
setoptions(h2,'Normalize','on','Grid','on')

% The first LineSpec "r--" specifies a dashed red line for the response with the PI controller. The second LineSpec "b" specifies a solid blue line for the response with the PID controller. The legend reflects the specified colors and line styles.
%
% Copyright 2021 The MathWorks, Inc.