%% Experiment 4.2
%% Name:
%% Objectives
% To evaluate the effect of additional poles and zeros upon the time response of second-order systems.
%% Minimum Required Software Packages
% MATLAB, Simulink, and the Control System Toolbox.
%
%
%% Prelab
%% Problem 1
%% 1.a.
% Given the transfer function G(s) = \frac{25}{s^2 + 4s + 25}, evaluate the percent overshoot, settling time, peak time, and rise time. Also, plot the poles.
% Answer:
% T_S =1.6819
% %\textrm{OS}=25\ldotp 3741
% T_P =0\ldotp 6908
% T_R =0\ldotp 2930
%
%%
%% 1.b.
% Add a pole at -200 to the system of Prelab 1a. Estimate whether the transient response in Prelab 1a will be appreciably affected.
% Answer:
% G(s)={25 \over (s+200)(s^2 + 4s + 25)}={25 \over s^3 + 204s^2 + 825s + 5000
% Since -200 is far away from the existing poles, it will not affect the transient behavior of the system much. However, since -200 has significant magnitude, it will greatly affect the steady state value of the system.
%
%% 1.c.
% Repeat Prelab 1b with the pole successively placed at -20, -10, and -2.
% Answer:
% G(s) = {25 \over (s+20)(s^2 + 4s + 25)} = {25 \over s^3 + 24^2 + 105s + 500}
% This pole is much closer to the original poles, so it will affect the transient behavior more than s=-200, but it will only decrease the steady state value by a factor of 20 rather than 200.
% G(s) = {25 \over (s+10)(s^2 + 4s + 25)} = {25 \over s^3 + 14s^2 + 65s + 250}
% Adding a pole at s=-10 will impact the transient behavior more than s=-20, but again, it will only scale the steady state value down by a factor of 10.
% G(s) ={25 \over (s+2)(s^2 + 4s + 25)} = {25 \over s^3 + 6s^2 + 33s + 50}
% Adding a pole at s=-2 will completely change the behavior of the transient response, but its steady state value will only be half of the original.
%
%
%% Problem 2
% A zero is added to the system of Prelab 1a at -200 and then moved to -50, -20, -10, -5, and -2. List the values of zero location in order of the greatest to the least effect upon the pure second-order transient response.
% Answer:
%
% In decreasing order of magnitude of effect upon the second-order response, s=-2, s=-5, s=-10, s=-20, s=-50, s=-200. While having a pole at s=-2 will affect the steady state value less than having a pole at s=-200, having a pole at s=-2 will impact the transient behavior much more than the pole at s=-200.
%
%%
%% Problem 3
% Given the transfer function G(s) = \frac{(25b/a)(s+1)}{(s+b)(s^2 + 4s + 25)}, let a=3 and b=3.01, 3.1, 3.3, 3.5, and 4.0. Which values of b will have minimal effect upon the pure second-order transient response?
% Answer:
%
% G is the original response, where b=3. As the difference between b and 3 increases, the transient response becomes more distorted. For b=3.01, the change is almost imperceptable. For b=3.1, the difference is still very small. Even for b=3.3, the response is still acceptably similar, but for b=3.5 and b=4.0, the difference is rather significant.
%
%
%% Problem 4
% Given the transfer function G(s) = \frac{(2500b/a)(s+a)}{(s+b)(s^2 + 4s + 25)}, let a=30 and b=30.01, 30.1, 30.5, 31, 35, and 40. Which values of b will have minimal effect upon the pure second-order transient response?
% Answer:
%
% Since 2500 is significantly larger (by two orders of magnitude) than b and a, even with a difference of 10 between a and b, the respose of the system is almost unoticably affected.
%
%
%%
%
%
%
%% Lab
%
%% Problem 1
% Using Simulink, add a pole to the second-order system of Prelab 1a and plot the step responses of the system when the higher order pole is nonexistent, at  -200, -20, -10,  and -2. Make your plots on a single graph, using the Simulink LTI Viewer. Normalize all plots to a steady-state value of unity. Record percent overshoot, settling time, peak time, and rise time for each response.
% For your Simulink, please provide a screenshot that clearly shows the system.
%
%
%
% Pole at s=-200:
% T_S = 1.6870
% T_R = 0.2934
% T_P = 0.6908
% \%OS = 25.3746
% Pole at s=-20:
% T_S = 1.7325
% T_R = 0.3065
% T_P = 0.7368
% \%OS =24.5106
% Pole at s=-10:
% T_S=1.7787
% T_R=0.3357
% T_P = 0.8013
% \%OS = 21.9285
% Pole at s=-2:
% T_S = 2.0911
% T_R = 0.7500
% T_P = 3.4309
% \%OS = 0
%
%% Problem 2
% Using Simulink, add a zero to the second-order system of Prelab 1a and plot the step responses of the system when the zero is nonexistent, at  -200, -50, -20, -10, -5, and -2. Make your plots on a single graph, using the Simulink LTI Viewer. Normalize all plots to a steady-state value of unity. Record percent overshoot, settling time, peak time, and rise time for each response.
% For your Simulink, please provide a screenshot that clearly shows the system.
%
%
%
% Zero at s=-200:
% T_R = 0.2928
% T_S = 1.6769
% \%OS = 25.3577
% T_P  = 0.6908
% Zero at s=-50:
% T_R = 0.2909
% T_S = 1.6617
% \%OS = 25.5136
% T_P = 0.6677
% Zero at s=-20:
% T_R = 0.2795
% T_S = 1.6312
% \%OS = 26.2529
% T_P = 0.6217
% Zero at s=-10:
% T_R = 0.2795
% T_S = 1.6312
% \%OS = 26.2529
% T_P = 0.6217
% Zero at s=-5:
% T_R = 0.1699
% T_S = 2.0104
% \%OS = 42.8127
% T_P = 0.4605
% Zero at s=-2:
% T_R = 0.0716
% T_S = 2.0392
% \%OS = 115.4281
% T_P = 0.3454
%
%% Problem 3
% Using Simulink and the transfer function of Prelab 3 with a = 3, plot the step responses of the system when the value of b is 3, 3.01, 3.1, 3.3, 3.5, and 4.0. Make your plots on a single graph using the Simulink LTI Viewer. Record percent overshoot, settling time, peak time, and rise time for each response.
%
% For your Simulink, please provide a screenshot that clearly shows the system.
%
% b
% T_R
% T_S
% \%OS
% T_P
% 3
% 0.1399
% 2.2784
% 133.4651
% 0.5296
% 3.01
% 0.1396
% 2.2781
% 133.8106
% 0.5296
% 3.1
% 0.1373
% 2.2754
% 136.8440
% 0.5296
% 3.3
% 0.1326
% 2.2701
% 143.1150
% 0.5296
% 3.5
% 0.1283
% 2.2653
% 148.7843
% 0.5296
% 4
% 0.1191
% 2.6454
% 161.7819
% 0.5066
%
%
%% Problem 4
% Using Simulink and the transfer function of Prelab 4 with a = 30, plot the step responses of the system when the value of  b is 30, 30.01, 30.1, 30.5, 31, 35, and 40. Make your plots on a single graph, using the Simulink LTI Viewer. Record percent overshoot, settling time, peak time, and rise time for each response.
% For your Simulink, please provide a screenshot that clearly shows the system.
%
% b
% T_R
% T_S
% \%OS
% T_P
% 30
% 0.2930
% 1.6819
% 25.3741
% 0.6908
% 30.01
% 0.2930
% 1.6819
% 25.3743
% 0.6908
% 30.1
% 0.2930
% 1.6818
% 25.3763
% 0.6908
% 30.5
% 0.2928
% 1.6813
% 25.3848
% 0.6908
% 31
% 0.2926
% 1.6808
% 25.3947
% 0.6908
% 35
% 0.2912
% 1.6771
% 25.4521
% 0.6908
% 40
% 0.2930
% 1.6819
% 25.4741
% 0.6908
%
%
%% Postlab
%
%% Problem 1
% Discuss the effect upon the transient response of the proximity of a higher-order pole to the dominant second-order pole pair.
% As an extra pole approaches the dominant second-order pole pair, the steady state decreases, and the system behaves as if it were more damped.
%
%
%
%% Problem 2
% Discuss the effect upon the transient response of the proximity of a zero to the dominant second-order pole pair. Explore the relationship between the length of the vector from the zero to the dominant pole and the zero’s effect upon the pure second-order step response.
% As the distance between the zero and the second-order pole pair decreases, the percent overshoot increases. The magnitude of the effect is an inverse relationship to the distance. For example the difference in magnitude for a zero at s=-200 and s=-5 is smaller than the difference between s=-5 and s=-2.
%
%
%
%% Problem 3
% Discuss the effect of pole-zero cancellation upon the transient response of a dominant second-order pole pair. Allude to how close the canceling pole and zero should be and the relationships of (1) the distance between them and (2) the distance between the zero and the dominant second-order poles.
%
%%