0% found this document useful (0 votes)
5 views15 pages

lab program

The document contains several programs related to control systems, including block diagram reduction, signal flow graphs, and time response specifications. Each program provides MATLAB code to implement specific control system techniques, such as calculating transfer functions, analyzing poles and zeros, and evaluating system stability using the Routh stability criterion. The programs are designed for educational purposes, demonstrating various aspects of control theory and system analysis.

Uploaded by

chinnudeepub
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views15 pages

lab program

The document contains several programs related to control systems, including block diagram reduction, signal flow graphs, and time response specifications. Each program provides MATLAB code to implement specific control system techniques, such as calculating transfer functions, analyzing poles and zeros, and evaluating system stability using the Routh stability criterion. The programs are designed for educational purposes, demonstrating various aspects of control theory and system analysis.

Uploaded by

chinnudeepub
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

PROGRAM 01: Implement Block diagram reduction

technique to obtain transfer function a control system.

CODE:
% Define the transfer functions for the blocks
G1 = tf([1], [1 1]); % Example transfer function for G1 (numerator: 1, denominator: s+1)
G2 = tf([2], [1 2]); % Example transfer function for G2 (numerator: 2, denominator: s+2)
H = tf([1], [1 3]); % Example transfer function for H (numerator: 1, denominator: s+3)

% Combine G1 and G2 in series


G_series = series(G1, G2);

% Combine the series block with the feedback H


G_total = feedback(G_series, H);

% Display the resulting transfer function


disp('The overall transfer function is:');
G_total

OUTPUT:
PROGRAM 02: Implement Signal Flow graph to obtain
transfer function a control system.

CODE:
function T = masons_gain(nodes, forward_paths, loops)
% Mason's Gain Formula to find transfer function from a signal flow graph
% nodes - total number of nodes
% forward_paths - cell array of forward paths and their gains
% loops - cell array of loops and their gains

% Calculate Delta
delta = 1 - sum(cellfun(@(x) x{2}, loops));

% Calculate Delta_i for each forward path


deltas = zeros(length(forward_paths), 1);
for i = 1:length(forward_paths)
path = forward_paths{i}{1};
touching_loops = find_touching_loops(path, loops);
deltas(i) = 1 - sum(cellfun(@(x) x{2}, touching_loops));
end

% Calculate transfer function using Mason's Gain Formula


T = 0;
for i = 1:length(forward_paths)
T = T + forward_paths{i}{2} * deltas(i);
end
T = T / delta;
end

function touching_loops = find_touching_loops(path, loops)


% Find loops touching the given path
touching_loops = {};
for i = 1:length(loops)
loop_nodes = loops{i}{1};
if ~isempty(intersect(path, loop_nodes))
touching_loops{end+1} = loops{i};
end
end
end

% Example usage:
% Define the nodes (This is illustrative, nodes are typically implied in paths and loops)
nodes = 4;

% Define forward paths and their gains


% Each forward path is defined as a cell {nodes_in_path, gain}
forward_paths = {
{ [1 2 3 4], 1*2*3 }; % Example path 1 -> 2 -> 3 -> 4 with gain 1*2*3
{ [1 3 4], 1*4 }; % Example path 1 -> 3 -> 4 with gain 1*4
};

% Define loops and their gains


% Each loop is defined as a cell {nodes_in_loop, gain}
loops = {
{ [2 3 2], -2*3 }; % Example loop 2 -> 3 -> 2 with gain -2*3
{ [1 2 3 1], -1*2*3 }; % Example loop 1 -> 2 -> 3 -> 1 with gain -1*2*3
};

% Calculate the transfer function


T = masons_gain(nodes, forward_paths, loops);
disp('The transfer function is:');
disp(T);
OUTPUT:
PROGRAM 03: Simulation of poles and zeros of a transfer
function.

CODE:
% Define the numerator and denominator of the transfer function
num = [1 3 5]; % Example numerator coefficients
den = [1 2 3 4]; % Example denominator coefficients

% Create the transfer function


sys = tf(num, den);

% Compute the poles and zeros


poles = pole(sys);
zeros = zero(sys);

% Display poles and zeros


disp('Poles of the transfer function:');
disp(poles);
disp('Zeros of the transfer function:');
disp(zeros);

% Plot the poles and zeros on the complex plane


figure;
pzmap(sys);
title('Poles and Zeros of the Transfer Function');
grid on;

OUTPUT:
PROGRAM 04: Implement time response specification of a
second order Under damped System, for different
damping factors.

CODE:
% Define parameters
zeta = 0.5; % Damping factor
omega_n = 5; % Natural frequency

% Define the transfer function of the second-order system


num = [omega_n^2];
den = [1 2*zeta*omega_n omega_n^2];
sys = tf(num, den);

% Compute time response specifications


info = stepinfo(sys);

% Display time response specifications


disp('Time Response Specifications:');
disp(['Rise Time (Tr): ', num2str(info.RiseTime)]);
disp(['Peak Time (Tp): ', num2str(info.PeakTime)]);
disp(['Settling Time (Ts): ', num2str(info.SettlingTime)]);
disp(['Maximum Overshoot (Mp): ', num2str(info.Overshoot), '%']);

% Compute and plot step response


t = 0:0.01:5; % Time vector
[y, t] = step(sys, t);

figure;
plot(t, y, 'LineWidth', 2);
title('Step Response of a Second-Order Underdamped System');
xlabel('Time (seconds)');
ylabel('Response');
grid on;

% Annotate plot with time response specifications


hold on;
plot(info.PeakTime, y(find(t >= info.PeakTime, 1)), 'ro'); % Peak point
text(info.PeakTime, y(find(t >= info.PeakTime, 1)), sprintf('Peak (%.2f)', info.PeakTime),
'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'left');

plot(info.SettlingTime, 1, 'go'); % Settling time point


text(info.SettlingTime, 1, sprintf('Settling (%.2f)', info.SettlingTime), 'VerticalAlignment',
'bottom', 'HorizontalAlignment', 'left');

plot(info.RiseTime, y(find(t >= info.RiseTime, 1)), 'bo'); % Rise time point


text(info.RiseTime, y(find(t >= info.RiseTime, 1)), sprintf('Rise (%.2f)', info.RiseTime),
'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'left');

% Plot reference lines


yline(1, '--k'); % Final value
hold off;

OUTPUT:
PROGRAM 05: Implement frequency response of a second
order System.

CODE:
% Parameters for the second-order system
% Define the natural frequency (omega_n) and damping ratio (zeta)
omega_n = 10; % Natural frequency (rad/s)
zeta = 0.5; % Damping ratio

% Define the transfer function of the second-order system


num = [omega_n^2];
den = [1 2*zeta*omega_n omega_n^2];
sys = tf(num, den);

% Display the transfer function


fprintf('Transfer Function: \n');
disp(sys);

% Plot the frequency response (Bode plot)


figure;
bode(sys);
grid on;
title('Frequency Response of Second-Order System');
OUTPUT:
PROGRAM 06: Implement frequency response of a lead
lag compensator.

CODE:
% Lead-lag compensator parameters
% Adjust these parameters as needed
K = 1; % Gain
alpha = 0.1; % Lead compensator zero/pole ratio
beta = 10; % Lag compensator zero/pole ratio
T1 = 0.1; % Time constant of the lead compensator
T2 = 1; % Time constant of the lag compensator

% Transfer function of the lead compensator


% G_lead(s) = K * (1 + alpha*T1*s) / (1 + T1*s)
num_lead = [K*alpha*T1 K];
den_lead = [T1 1];
G_lead = tf(num_lead, den_lead);

% Transfer function of the lag compensator


% G_lag(s) = (1 + T2*s) / (1 + beta*T2*s)
num_lag = [T2 1];
den_lag = [beta*T2 1];
G_lag = tf(num_lag, den_lag);

% Combined lead-lag compensator transfer function


G_lead_lag = G_lead * G_lag;

% Display the transfer function


fprintf('Lead Compensator Transfer Function: \n');
disp(G_lead);
fprintf('Lag Compensator Transfer Function: \n');
disp(G_lag);
fprintf('Lead-Lag Compensator Transfer Function: \n');
disp(G_lead_lag);

% Plot the frequency response (Bode plot)


figure;
bode(G_lead_lag);
grid on;
title('Frequency Response of Lead-Lag Compensator');

OUTPUT:
PROGRAM 07: Analyze the stability of the given system
using Routh stability criterion.
CODE:
function routh_stability(coefficients)
% coefficients: Vector of the coefficients of the characteristic polynomial
% Example: coefficients = [1 3 5 6] for the polynomial s^3 + 3s^2 + 5s + 6

n = length(coefficients);
routh_table = zeros(n, ceil(n/2));

% Fill the first two rows of the Routh array


routh_table(1, :) = coefficients(1:2:end);
if mod(n, 2) == 0
routh_table(2, :) = coefficients(2:2:end);
else
routh_table(2, 1:end-1) = coefficients(2:2:end);
end

% Calculate the rest of the Routh array


for i = 3:n
for j = 1:ceil((n-i+1)/2)
routh_table(i, j) = (routh_table(i-1, 1) * routh_table(i-2, j+1) - routh_table(i-2, 1) *
routh_table(i-1, j+1)) / routh_table(i-1, 1);
end
% Special case: row of all zeros
if all(routh_table(i, :) == 0)
order = n - i + 1;
poly_derivative = polyder(coefficients(1:order+1));
routh_table(i, 1:length(poly_derivative)) = poly_derivative;
end
% Special case: zero in the first column
if routh_table(i, 1) == 0
routh_table(i, 1) = eps;
end
end

% Display the Routh table


disp('Routh Table:');
disp(routh_table);

% Check the number of sign changes in the first column


first_column = routh_table(:, 1);
sign_changes = sum(diff(sign(first_column)) ~= 0);

if sign_changes == 0
disp('The system is stable.');
else
disp(['The system is unstable with ', num2str(sign_changes), ' poles in the right half-
plane.']);
end
end

% Example usage
coefficients = [1 3 5 6]; % Define the coefficients of your system's characteristic polynomial
routh_stability(coefficients);

OUTPUT:

You might also like