Lab - 06 56

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

LAB # 6 Matlab

What is a First Order Control System?


A first order control system is defined as a type of control system whose input-output
relationship (also known as a transfer function) is a first-order differential equation. A first-
order differential equation contains a first-order derivative, but no derivative higher than the
first order. The order of a differential equation is the order of the highest order derivative
present in the equation.
As an example, let us look at the block diagram of the control system shown below.

The transfer function (input-output relationship) for this control system is defined as

Where:

 K is the DC Gain (DC gain of the system ratio between the input signal and the
steady-state value of output)
 T is the time constant of the system (the time constant is a measure of how quickly a
first-order system responds to a unit step input)
Remember that the order of a differential equation is the order of the highest order derivat ive
present in the equation. Evaluate this with respect to (s).

Since here is to the first power (𝑠 1 = 𝑠), the transfer function above is a first-order
differential equation. Hence the block diagram above represents a first-order control
system.
In a theoretical alternate example, let us say that the transfer function was equal to:
In this example since is to the second power (𝑠 2 ), the transfer function is a second-order
differential equation. Hence a control system with the above transfer function would be a
second-order control system.
Most of the practical models are first-order systems. If a system with higher-order has a
dominant first-order mode it can be considered as a first-order system.

Engineers try to find out techniques for systems to become more efficient and reliable. There
are two methods of controlling the systems. One is an open-loop control system, and another
is a closed-loop feedback control system.
In an open-loop system, the inputs proceed to the given process and produce output. There is
no feedback back into the system as for the system to ‘know’ how close the actual output is to
the desired output comes.

In a closed-loop control system, the system has the ability to check how far the actual output
deviates from the desired output (as the time approaches infinity, this difference is known as
the steady state error). It passes this difference as feedback to the controller who controls the
system. The controller will adjust its control of the system based on this feedback.
If the input is a unit step, the output is a step response. The step response yields a clear vision
of the system’s transient response. We have two types of systems, first-order system, and
second-order system, which are representative of many physical systems.

The first order of the system is defined as the first derivative with respect to time and the
second-order of the system is the second derivative with respect to time.

A first-order system is a system that has one integrator. As the number of orders increases,
the number of integrators in a system also increases. Mathematically, it is the first derivative
of a given function with respect to time.

We have different techniques to solve system equations using differential equations or


Laplace Transform but engineers have found ways to minimize the technique of solving
equations for abrupt output and work efficiency. The total response of the system is the sum
of forced response and natural response.

𝑇𝑜𝑡𝑎𝑙 𝑟𝑒𝑠𝑝𝑜𝑛𝑠𝑒 = 𝐹𝑜𝑟𝑐𝑒𝑑 𝑟𝑒𝑠𝑝𝑜𝑛𝑠𝑒 + 𝑁𝑎𝑡𝑢𝑟𝑎𝑙 𝑅𝑒𝑠𝑝𝑜𝑛𝑠𝑒

The forced response is also called the steady-state response or a particular equation. The
natural response is also called the homogeneous equation.

Before proceeding to this topic, you should be aware of the control engineering concepts of
poles, zeros, and transfer function and fundamental concepts of the feedback control systems.
Here, remind your memory with fundamental concepts of the feedback control system.
3.6.8 Second-Order System
The second-order system is unique in this context, because its characteristic equation may
have complex conjugate roots. The second-order system is the lowest-order system capable
of an oscillatory response to a step input. Typical examples are the spring-mass-damper
system and the electronic RLC circuit. Second-order systems with potential oscillatory
responses require two different and independent types of energy storage, such as the inductor
and the capacitor in RLC filters, or a spring and an inert mass. The transfer function of the
general second-order system has two poles in one of three configurations: both poles can be
real-valued and on the negative real axis, they can form a double-pole on the negative real
axis, or they can form a complex conjugate pole pair. The significance of the pole position of
a second-order system is examined in Section 3.3 and in more detail in Chapter 9.

The unit step response depends on the roots of the characteristic equation. If both roots are
real-valued, the second-order system behaves like a chain of two first-order systems, and the
step response has two exponential components. If the roots are complex, the step response is
a harmonic oscillation with an exponentially decaying amplitude.
Consider a second-order system as follows:
The second-order system is unique in this context, because its characteristic equation may
have complex conjugate roots. The second-order system is the lowest-order system capable
of an oscillatory response to a step input. Typical examples are the spring-mass-damper
system and the electronic RLC circuit. Second-order systems with potential oscillatory
responses require two different and independent types of energy storage, such as the inductor
and the capacitor in RLC filters, or a spring and an inert mass. The transfer function of the
general second-order system has two poles in one of three configurations: both poles can be
real-valued, and on the negative real axis, they can form a double-pole on the negative real
axis, or they can form a complex conjugate pole pair.

Example part a
% Define the transfer function G(s)

num = 2;

den = [1 2.5];

G = tf(num, den);

% Calculate the time constant

time_constant = 1 / abs(pole(G));

% Calculate the settling time

settling_time = 4 / (real(pole(G)));

% Calculate the system DC gain

dc_gain = dcgain(G);

% Calculate the step response

t = 0:0.01:10;

[y, t] = step(G, t);

% Calculate the percent overshoot, maximum amplitude, and peak time

[peak_amplitude, peak_index] = max(y);

peak_time = t(peak_index);

percent_overshoot = ((peak_amplitude - dc_gain) / dc_gain) * 100;


% Display the results

disp(['Time Constant: ' num2str(time_constant)]);

disp(['Settling Time: ' num2str(settling_time)]);

disp(['System DC Gain: ' num2str(dc_gain)]);

disp(['Percent Overshoot: ' num2str(percent_overshoot)]);

disp(['Maximum Amplitude: ' num2str(peak_amplitude)]);

disp(['Peak Time: ' num2str(peak_time)]);

Example part 2
% Define the transfer function G(s)

num = 6;

den = [1 1 8];

G = tf(num, den);

% Calculate the time constant

time_constant = 1 / abs(pole(G));

% Calculate the settling time

settling_time = 4 / (real(pole(G)));

% Calculate the system DC gain

dc_gain = dcgain(G);

% Calculate the step response

t = 0:0.01:20;

[y, t] = step(G, t);

% Calculate the percent overshoot, maximum amplitude, and peak time

[peak_amplitude, peak_index] = max(y);

peak_time = t(peak_index);

percent_overshoot = ((peak_amplitude - dc_gain) / dc_gain) * 100;


% Display the results

disp(['Time Constant: ' num2str(time_constant)]);

disp(['Settling Time: ' num2str(settling_time)]);

disp(['System DC Gain: ' num2str(dc_gain)]);

disp(['Percent Overshoot: ' num2str(percent_overshoot)]);

disp(['Maximum Amplitude: ' num2str(peak_amplitude)]);

disp(['Peak Time: ' num2str(peak_time)]);

Exercise 01 part a
% Define the transfer function G(s)

num = 100;

den = conv([1 2], [1 5]); % Convolution of (s+2) and (s+5)


G = tf(num, den);

% Define the closed-loop system with negative unity feedback

H = 1;

sys = feedback(G, H);


% Calculate the steady-state error for a unit step input

step_error = 1 / (1 + dcgain(G));

% Display the result

disp(['Steady-State Error: ' num2str(step_error)]);


Exercise 01 part b
% Define the transfer function G(s)
num = 100;

den = conv([1 2], [1 5]); % Convolution of (s+2) and (s+5)

G = tf(num, den);

% Define the closed-loop system with negative unity feedback


H = 1;

sys = feedback(G, H);

% Calculate the overshoot of the step response

[y, t] = step(sys);
peak_amplitude = max(y);

dc_gain = dcgain(sys);

overshoot = ((peak_amplitude - dc_gain) / dc_gain) * 100;

% Calculate the time constant


time_constant = 1 / abs(pole(G));

% Calculate the settling time

tolerance = 0.02; % 2% tolerance for settling time

settling_time = settleTime(sys, tolerance);


% Display the results

disp(['Overshoot: ' num2str(overshoot)]);

disp(['Time Constant: ' num2str(time_constant)]);


disp(['Settling Time: ' num2str(settling_time)]);
disp(['System DC Gain: ' num2str(dc_gain)]);

Exersice 2 part a
% Define the transfer function G(s)

K = 40;

num = K;
den = conv([1 0], [1 14]); % Convolution of s and (s+14)

G = tf(num, den);

% Define the closed-loop system with negative unity feedback


H = 1;

sys = feedback(G, H);

% Set the step input


t = 0:0.01:10;

u = ones(size(t));

% Calculate the step response


[y, t] = step(sys, t);

% Calculate the percent overshoot

dc_gain = dcgain(sys);
[peak_amplitude, ~] = max(y);
percent_overshoot = ((peak_amplitude - dc_gain) / dc_gain) * 100;

% Plot the step response

plot(t, y);

title('Step Response');

xlabel('Time');
ylabel('Output');

grid on;

% Display the percent overshoot


disp(['Percent Overshoot: ' num2str(percent_overshoot)]);

Exersice 2 part b
% Define the transfer function G(s)

num = [1];
den = [1 14 0];

G = tf(num, den);

% Define the closed-loop system with negative unity feedback

H = 1;

sys = feedback(G, H);

% Set desired overshoot

desired_overshoot = 5; % 5%

% Initialize variables

k = 1;
overshoot = 100; % Initialize overshoot to a high value

% Iterate until overshoot is within the desired range

while overshoot > desired_overshoot

% Calculate the step response

[y, t] = step(sys);

% Calculate the percent overshoot

dc_gain = dcgain(sys);

[peak_amplitude, ~] = max(y);
overshoot = ((peak_amplitude - dc_gain) / dc_gain) * 100;

% Increase the value of K

k = k + 1;

% Update the transfer function with the new K value

G = tf(k, den);
sys = feedback(G, H);

end

% Display the value of K

disp(['Suitable value of K: ' num2str(k)]);

Exersice 3 part a
manually part

In this case, the plant transfer function G(s) is given as G(s) = 2(s+8)/(s(s+4)), and the
feedback transfer function H(s) is 1 (negative unity feedback). Substituting these
values into the feedback loop equation:

T(s) = [2(s+8)/(s(s+4))] / (1 + [2(s+8)/(s(s+4))] * 1

Simplifying the equation:

T(s) = 2(s+8) / [s(s+4) + 2(s+8)]

T(s) = 2(s+8) / [s^2 + 4s + 2s + 8]

T(s) = 2(s+8) / [s^2 + 6s + 8]

So, the closed-loop transfer function T(s) is T(s) = 2(s+8) / (s^2 + 6s + 8).

Matlab cod
% Define the transfer function G(s)

num = [2 16];

den = [1 4 0];
G = tf(num, den);

% Define the feedback transfer function H(s)

H = 1;

% Calculate the closed-loop transfer function T(s)


T = feedback(G, H);

% Display the closed-loop transfer function

disp('Closed-Loop Transfer Function:');


disp(T);

Exersice 3 part b
% Define the transfer function G(s)
num = [2 16];
den = [1 4 0];

G = tf(num, den);

% Define the closed-loop system with negative unity feedback

H = 1;

sys = feedback(G, H);

% Set the time range

t = 0:0.01:10;

% Generate the unit step input

u = ones(size(t));

% Calculate the time response


[y, t] = step(sys, t);

% Plot the time response

plot(t, y);
title('Time Response for Unit Step Input');

xlabel('Time (s)');

ylabel('Output');

grid on;
exersice 3 part c
% Define the transfer function G(s)

num = [2 16];

den = [1 4 0];

G = tf(num, den);

% Define the closed-loop system with negative unity feedback

H = 1;

sys = feedback(G, H);

% Set the unit step input

t = 0:0.01:10;

u = ones(size(t));

% Calculate the step response and extract step information

[y, t] = step(sys, t);

step_info = stepinfo(y, t, 'SettlingTimeThreshold', 0.02);


% Extract the overshoot from the step information
overshoot = step_info.Overshoot;

% Display the overshoot

disp(['Overshoot: ' num2str(overshoot) '%']);

exersice 3 part d
% Define the transfer function G(s)

num = [2 16];
den = [1 4 0];

G = tf(num, den);

% Define the closed-loop system with negative unity feedback


H = 1;

sys = feedback(G, H);

% Set the unit step input


t = 0:0.01:100; % Extend the time range to capture the steady-state behavior

u = ones(size(t));

% Calculate the step response


[y, t] = step(sys, t);
% Plot the step response
plot(t, y);

title('Step Response');

xlabel('Time (s)');

ylabel('Output');
grid on;

% Find the steady-state value

steady_state_value = y(end);

% Display the steady-state value


disp(['Steady-State Value of Y(t): ' num2str(steady_state_value)]);

exersice 3 part e
manually find:
Manually, you can observe the step response plot and identify the time it takes for the
response to settle within a certain percentage of the final value. Typically, settling time is
defined as the time it takes for the response to stay within a 2% or 5% tolerance band
around the steady-state value.
Code :
% Define the transfer function G(s)

num = [2 16];

den = [1 4 0];

G = tf(num, den);

% Define the closed-loop system with negative unity feedback

H = 1;

sys = feedback(G, H);

% Set the unit step input

t = 0:0.01:20; % Extend the time range to observe settling behavior

u = ones(size(t));

% Calculate the step response

[y, t] = step(sys, t);

% Plot the step response

plot(t, y);

title('Step Response');

xlabel('Time (s)');
ylabel('Output');

grid on;

% Define the tolerance for settling time


tolerance = 0.02; % 2% tolerance

% Find the settling time manually


final_value = y(end);
settling_time_manual = max(t(y >= (1-tolerance)*final_value & y <=
(1+tolerance)*final_value));

% Use MATLAB's stepinfo function to find the settling time


step_info = stepinfo(y, t, 'SettlingTimeThreshold', tolerance);

settling_time_plot = step_info.SettlingTime;

% Display the settling time


disp(['Settling Time (Manual): ' num2str(settling_time_manual) 's']);

disp(['Settling Time (Plot): ' num2str(settling_time_plot) 's']);

exersice 4 part a
upper side 2 transfer function are cascade so using cascade command cascade it

sys = cascade (sys1, sys2, ...)


then last two function are feedback each other so using feedback command

sys_cl = feedback (sys1, sys2, sign)

so transfer function is given below:


𝐾𝑠 2 + 1.4𝐾𝑠 + 11.4𝑠 + 114
𝐺(𝑠) =
𝑠 3 + 11.4𝑠 2 + 14𝑠 + 𝑘𝑠 2 + 1.4𝑘𝑠 + 11.4𝑠 + 114
exersice 4 part b

% Define the values of K

K_values = [0.7, 3, 6];

% Loop over each value of K

for i = 1:length(K_values)
K = K_values(i);

% Define the numerator and denominator coefficients

num = [K 1.4*K 11.4 114];


den = [1 11.4 14 K 1.4*K 11.4 114];

% Calculate the roots

r = roots(den - num);

% Display the roots for the current value of K

disp(['Roots for K = ' num2str(K) ':']);

disp(r);
disp('------------------');

end
exersice 4 part c
% Define the values of K

K_values = [0.7, 3, 6];

% Loop over each value of K

for i = 1:length(K_values)

K = K_values(i);

% Define the numerator and denominator coefficients

num = [K 1.4*K 11.4 114];

den = [1 11.4 14 K 1.4*K 11.4 114];

% Create the transfer function

G = tf(num, den);

% Set the step input


t = 0:0.01:10;

u = ones(size(t));

% Calculate the step response


[y, ~] = step(G, t);

% Calculate the step info

step_info = stepinfo(y, t);

% Display the overshoot for the current value of K

disp(['Overshoot for K = ' num2str(K) ': ' num2str(step_info.Overshoot) '%']);

disp('------------------');
end
exersice 4 part d
% Define the desired percentage overshoot

desired_overshoot = 16; % 16%

% Define the range of K values to search within


K_values = 0:0.01:10;

% Initialize variables to store the best K value and the resulting peak time

best_K = 0;
best_peak_time = Inf;

% Iterate over each K value and find the resulting peak time

for i = 1:length(K_values)
K = K_values(i);

% Define the numerator and denominator coefficients

num = [K 1.4*K 11.4 114];


den = [1 11.4 14 K 1.4*K 11.4 114];

% Create the transfer function

G = tf(num, den);
% Set the step input

t = 0:0.01:10;
u = ones(size(t));

% Calculate the step response

[y, ~] = step(G, t);

% Calculate the peak time and overshoot

[~, peak_index] = max(y);

peak_time = t(peak_index);
overshoot = max(y) - 1; % Assuming the initial value is 1

% Check if the current overshoot matches the desired overshoot

if abs(overshoot - desired_overshoot) < 0.01 && peak_time < best_peak_time


best_K = K;

best_peak_time = peak_time;

end

end

% Display the resulting gain and peak time

disp(['Desired Percentage Overshoot: ' num2str(desired_overshoot) '%']);

disp(['Resulting Gain (K): ' num2str(best_K)]);


disp(['Resulting Peak Time: ' num2str(best_peak_time) 's']);

You might also like