CS LAB PROGRAM
CS LAB PROGRAM
INTRODUCTION TO OCTAVE
GNU Octave is a high-level language primarily intended for numerical computations. It is typically used
for such problems as solving linear and nonlinear equations, numerical linear algebra, statistical
analysis, and for performing other numerical experiments. It may also be used as a batch-oriented
language for automated data processing.
The current version of Octave executes in a graphical user interface (GUI). The GUI hosts an Integrated
Development Environment (IDE) which includes a code editor with syntax highlighting, built-in
debugger, documentation browser, as well as the interpreter for the language itself. A command-line
interface for Octave is also available.
GNU Octave is freely redistributable software. You may redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation. The GPL is included
in this manual, see GNU GENERAL PUBLIC LICENSE.
This manual provides comprehensive documentation on how to install, run, use, and extend GNU
Octave. Additional chapters describe how to report bugs and help contribute code.
Octave version 8.4.0.
Among the many tasks that Octave can perform, the following are the most commonly used in the
scientific community :
• simple algebra
• trigonometry
• control structures
• linear algebra
• differential equations
• numerical integration
1
Page
PROGRAM 01
BLOCK DIAGRAM REDUCTION TECHNIQUE
AIM
To implement block diagram reduction technique to obtain transfer function of a control system using
octave.
APPARATUS REQUIRED
THEORY
• Block diagrams are a visual representation of a system's components and their relationships,
using blocks (representing operations) and arrows (representing signal flow).
• They are used to model and analyse control systems, helping engineers understand how different
parts interact.
• The simplest form of the block diagram is the single block, with one input and one output.
• Block diagram reduction techniques simplify complex control system diagrams by combining
blocks, moving summing/pickoff points, and eliminating feedback loops to find the overall
transfer function.
• Common Block Diagram Reduction Techniques:
1. Combining Blocks in Cascade:
Ø If blocks are connected in series (one after another), their transfer functions are
multiplied.
2
Page
MANUAL CALCULATION
4
Page
OCTAVE CODE
Clc;
Disp (‘Block diagram reduction technique’);
p = [4 0];
q = [2 1 1 2];
a = tf (p, q); %First transfer function
r = [1 3];
s = [1 2 2];
b = tf (r, s); %Second transfer function
5
Clc;
Disp (‘Block diagram reduction technique’);
p = [4 1 1];
q = [2 1 1 2];
a = tf (p, q); %First transfer function
r = [1 3];
s = [1 2 2];
b = tf (r, s); %Second transfer function
z = series (a, b); % Multiply 1st and 2nd transfer function
x = [2 4 4];
y = [3 5 7 2];
c= tf (x, y); %Third transfer function
d = series (z, c); % Multiply 1st and 2nd result with 3rd transfer function
ars = feedback (d, 1, -1);
OUTPUT
RESULT: Block diagram reduction technique is implemented and the transfer function of a control
6
Page
7
Page
PROGRAM 02
POLES AND ZEROS OF A TRANSFER FUNCTION
AIM
To determine poles and zeros from a given transfer function of a control system using octave.
APPARATUS REQUIRED
THEORY
• A transfer function H(s) is a mathematical representation of the relationship between the output
and input of a system in the frequency domain. It is typically expressed as a ratio of two
polynomials in the complex variables:
𝐶(𝑠)
𝐻(𝑠) =
𝑅(𝑠)
• Where:
C(s) is the numerator polynomial = b.
R(s) is the denominator polynomial = a.
• ZEROS
Ø Zeros are the values of s that make the numerator C(s) equal to zero C(s) = 0.
Ø Zeros correspond to frequencies at which the system’s output is zero (i.e., the system
"cancels out" the input at that frequency).
Ø Zeros impact the system's frequency response by modifying the gain or phase.
• POLES
Ø Poles are the values of s that make the denominator R(s) equal to zero i.e R(s) = 0.
Ø Poles correspond to frequencies where the system’s response can become infinite or exhibit
resonance.
Ø Poles play a crucial role in the stability of the system and in shaping its transient response.
8
Page
MANUAL CALCULATION
𝟐𝒔#𝟑
1. Given transfer function is 𝑯(𝒔) = 𝟏 𝟏
𝒔𝟐 # 𝒔#𝟒
√𝟐
𝒙𝟐 #𝟑𝒙#𝟐
2. Given transfer function is 𝑯(𝒔) =
𝒙𝟐 #𝟐𝒙&𝟖
9
Page
OCTAVE CODE
𝟐𝒔#𝟑
1. Given transfer function is 𝑯(𝒔) = 𝟏 𝟏
𝒔𝟐 # 𝒔#𝟒
√𝟐
clc;
a = [2 3]
b = [1 1/sqrt(2) 1/4]
[z,p,k] = tf2zp (b,a)
zplane (b,a)
𝒙𝟐 #𝟑𝒙#𝟐
2. Given transfer function is 𝑯(𝒔) = 𝒙𝟐 #𝟐𝒙&𝟖
clc;
a = [1 3 2]
b = [1 2 -8]
[z,p,k] = tf2zp (b,a)
zplane (b,a)
OUTPUT
FIGURE WINDOW
10
RESULT: Zeros and poles are calculated for the given transfer function of a control system and
Page
11
Page
PROGRAM 03
SECOND ORDER UNDER DAMPED SYSTEM
AIM
To determine transfer function of a second order Under damped System, for different damping factors
of a control system using octave.
APPARATUS REQUIRED
THEORY
• In control systems, a second-order system is characterized by a transfer function with a
denominator having a highest power of 's' equal to 2, leading to potential oscillatory responses
and described by parameters like damping ratio and natural frequency.
• Damping is a measure of oscillation in a system factor which decay over time. Example for
damping is a swing which does not swing forever once pushed, it eventually comes to rest which
passes over time.
• The second order general transfer function is given by:
𝐾. 𝑊)*
𝐻(𝑠) =
𝑠 * + 2𝜁𝑊) 𝑠 + 𝑊)*
Where: Wn is the natural frequency, K is the system gain (constant) and 𝜁 (zeta) is the damping
factor
• Damping types and their behaviour:
12
Page
MANUAL CALCULATION
1. For the given Wn = 4; 𝜁 = 0.5 (underdamped 𝜁 < 1)); K = 2
𝐾. 𝑊)*
𝐻(𝑠) =
𝑠 * + 2𝜁𝑊) 𝑠 + 𝑊)*
𝐾. 𝑊)*
𝐻(𝑠) =
𝑠 * + 2𝜁𝑊) 𝑠 + 𝑊)*
13
Page
OCTAVE CODE
clc;
clear all;
Wn = input (‘Enter the natural frequency Wn:’);
zeta = input (‘Enter the damping factor zeta:’);
K = input (‘Enter the system gain K:’);
num = [K*Wn^2]
den = [ 1 2*zeta*Wn Wn^2]
g = tf (num, den)
OUTPUT
RESULT: The transfer function of a second order Under damped System is determined for different
Page
15
Page
PROGRAM 04
FREQUENCY RESPONSE OF SECOND ORDER SYSTEM
AIM
To determine frequency step response of a second order system of a control system using octave.
APPARATUS REQUIRED
THEORY
• In control systems, a second-order system is characterized by a transfer function with a
denominator having a highest power of 's' equal to 2, leading to potential oscillatory responses
and described by parameters like damping ratio and natural frequency.
• The second order general transfer function is given by:
𝐾. 𝑊)*
𝐻(𝑠) =
𝑠 * + 2𝜁𝑊) 𝑠 + 𝑊)*
Where: Wn is the natural frequency, K is the system gain (constant) and 𝜁 (zeta) is the damping
factor.
• Frequency response: In control systems, frequency response refers to how a system behaves
when presented with sinusoidal inputs at various frequencies. It's a method for analyzing the
steady-state response, providing insights into system dynamics like gain, phase, and stability.
• Step response: the step response refers to how a system reacts to a sudden, constant input change,
typically from zero to one, called a step input.
MANUAL CALCULATION
1. For the given Wn = 4; 𝜁 = 0.5; K = 2
𝐾. 𝑊)*
𝐻(𝑠) =
𝑠 * + 2𝜁𝑊) 𝑠 + 𝑊)*
16
Page
OCTAVE CODE
clc;
clear all;
Wn = input (‘Enter the natural frequency Wn:’);
zeta = input (‘Enter the damping factor zeta:’);
K = input (‘Enter the system gain K:’);
num = [K*Wn^2]
den = [ 1 2*zeta*Wn Wn^2]
g = tf (num, den)
t = feedback (g, 1)
step (t, ‘r’)
OUTPUT
FIGURE WINDOW
RESULT: The frequency step response of a second order system is determined for a control system
using octave.
18
Page
PROGRAM 05
FREQUENCY RESPONSE OF LEAD AND LAG
COMPENSATOR
AIM
To implement frequency response of lead and lag compensator of a control system using octave.
APPARATUS REQUIRED
Sl. No. Name of the equipment / Software Quantity
1 PC with Windows 1
2 Octave (GUI) 8.4.0 1
THEORY
• In control systems, lead and lag compensators are types of filters that modify the system's
frequency response to improve performance.
• Lead compensators introduce phase lead, primarily at higher frequencies, to improve transient
response and stability.
• Lag compensators, on the other hand, introduce phase lag, mainly at lower frequencies, to
enhance steady-state accuracy.
• Lead-lag compensators combine both lead and lag characteristics to balance transient and steady-
state performance.
• It modifies open loop frequency response to achieve desired stability and transient behaviour.
Low system change with input before reaching steady state.
• Purpose of lead and lag compensator: Stability margin enhancement and steady state accuracy
should reach.
• General transfer function of lead and lag compensator is:
(𝑆 + 𝑍+ )(𝑆 + 𝑍* )
𝐺(𝑆) = 𝐾
(𝑆 + 𝑃+ )(𝑆 + 𝑃* )
Where K = Gain
Z1 and Z2 = Lead and lag zero locations
P1 and P2 = Lead and lag pole locations
19
OCTAVE CODE
clc;
clear all;
% Lead-lag compensator parameters
K = 1;
z_lead = 1;
p_lead = 10;
z_lag = 5;
p_lag = 1;
% Transfer function of lead-lag compensator
num = K * conv([1 z_lead], [1 z_lag]);
den = conv([1 p_lead], [1 p_lag]);
C = tf(num, den);
% Plot Bode plot (magnitude and phase)
bode(C);
grid on;
title('Frequency Response of Lead-Lag Compensator');
FIGURE WINDOW
20
RESULT: The frequency response of lead and lag compensator is implemented for a control system
Page
using octave.
21
Page