0% found this document useful (0 votes)
15 views54 pages

CNTL 5-20 Report - 2

The document outlines various experiments related to control systems, including converting state space to transfer functions, analyzing pole-zero locations, and simulating responses to different inputs. It includes MATLAB code snippets for performing these tasks, such as generating step and impulse responses, and visualizing the effects of damping ratios on system behavior. Additionally, it covers advanced topics like Routh-Hurwitz stability criteria and PID controller design.
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)
15 views54 pages

CNTL 5-20 Report - 2

The document outlines various experiments related to control systems, including converting state space to transfer functions, analyzing pole-zero locations, and simulating responses to different inputs. It includes MATLAB code snippets for performing these tasks, such as generating step and impulse responses, and visualizing the effects of damping ratios on system behavior. Additionally, it covers advanced topics like Routh-Hurwitz stability criteria and PID controller design.
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/ 54

EXP 5: State Space to Transfer Function

Code 1:

A=[-2 –1;-3 –5];

B=[1 2]’;

C=[3 2];

D=[0];

[num,den]=ss2tf(A,B,C,D)

printsys(num,den,’s’)
Output:

Code 2:

A=[0 2 3;0 6 5;1 4 2];

B=[0 1 1]';

C=[1 2 0];

D=[0];

[num,den]=ss2tf(A,B,C,D)

printsys(num,den,'s')
Output:

Transfer Function to State Space


Code 1:

num=[24];

den=[1 9 26 24];

[A,B,C,D]=tf2ss(num,den)

Output:
Code 2:

num=[30];

den=[1 8 9 6 1 30];

[A,B,C,D]=tf2ss(num,den)

Output:
EXP 6: Determine Pole Zero Location, Values of Natural Frequency and Damping Ratio
Code a:

y=tf([400],[1 12 400])

pzmap(y);

sgrid

[wn,zeta]=damp(y)

Output:
Code b:

y=tf([900],[1 90 900])

pzmap(y)

sgrid

[wn,zeta]=damp(y)

Output:
Code c:

y=tf([225],[1 30 225])

pzmap(y)

sgrid

[wn,zeta]=damp(y)

Output:
Code d:

y=tf([625],[1 0 625])

pzmap(y)

sgrid

[wn,zeta]=damp(y)

Output:
Code 1:

wn=10;

zeta=0.3;

[num0,den]=ord2(wn,zeta)

num=wn^2;
printsys(num,den,'s')

Output:

Code 2:

wn=20;

zeta=0;

[num0,den]=ord2(wn,zeta)

num=wn^2;
printsys(num,den,'s')

Output:

Code 3:

wn=25;

zeta=0.8;

[num0,den]=ord2(wn,zeta)
num=wn^2;

printsys(wn,zeta,'s')

Output:

Code 4:

wn=30;

zeta=1.0;

[num0,den]=ord2(wn,zeta)

num=wn^2;
printsys(num,den,'s')

Output:
EXP 7: Transient and Steady State Responses

Code:

num = 10;

den = [1 2 10];

subplot(3,1,1); % Unit Step Response

step(num, den);

title('Step');

subplot(3,1,2); % Unit Impulse Response

impulse(num, den);

title('Impulse');

% Unit Ramp Response

r = t; % Ramp input: r(t) = t

t = 0:0.01:5; % Time vector

sys = tf(num, den); % Transfer function

subplot(3,1,3);

lsim(sys, r, t); % Simulate ramp response

title('Ramp');
Output:

EXP 8: Obtain the Unit-Ramp Response of three transfer functions using ‘lsim’ command

Code:

r = t; % Ramp input: r(t) = t

t = 0:0.01:10; % Simulate from t = 0 to 10 seconds

% Define transfer functions

sys1 = tf(1, [1 3 2]); % G1(s) = 1 / (s^2 + 3s + 2)

sys2 = tf([2 5], [1 4 5]); % G2(s) = (2s + 5) / (s^2 + 4s + 5)

sys3 = tf(10, [1 2 10]); % G3(s) = 10 / (s^2 + 2s + 10)


% Simulate ramp responses

y1 = lsim(sys1, r, t);

y2 = lsim(sys2, r, t);

y3 = lsim(sys3, r, t);

subplot(3,1,1); % Plot the results

plot(t, y1);

title('Ramp Response of G1(s) = 1 / (s^2 + 3s + 2)');

subplot(3,1,2);

plot(t, y2);

title('Ramp Response of G2(s) = (2s + 5) / (s^2 + 4s + 5)');

subplot(3,1,3);

plot(t, y3);

title('Ramp Response of G3(s) = 10 / (s^2 + 2s + 10)');


Output:

EXP 9: Include step response of overdamped, underdamped, critically damped and


undamped system in a single figure using subplot command.

Code:
t = 0:0.01:1; % Time vector long enough to show all responses

num1 = [625];

den1 = [1 0 625];

t1 = tf(num1, den1);

subplot(2,2,1)

step(t1, t)
title('Undamped')

num2 = [400];

den2 = [1 12 400];

t2 = tf(num2, den2);

subplot(2,2,2)

step(t2, t)

title('Underdamped')

num3 = [225];

den3 = [1 30 225];

t3 = tf(num3, den3);

subplot(2,2,3)

step(t3, t)

title('Critically Damped')

num4 = [900];

den4 = [1 90 900];

t4 = tf(num4, den4);

subplot(2,2,4)

step(t4, t)

title('Overdamped')
Output:

EXP 10: Show graphically how the change of the damping ratio changes the step response
for single transfer function of constant natural frequency of 1rad/sec.
Code:

t = 0:0.01:10; % Time vector

% Transfer function for zeta = 0 (Undamped)

num1 = [1];

den1 = [1 0 1];

t1 = tf(num1,den1);

subplot(3,2,1)

step(t1, t)

title('0')

num2 = [1]; % Transfer function for zeta = 0.2

den2 = [1 2*0.2 1];

t2 = tf(num2,den2);

subplot(3,2,2)

step(t2, t)

title('0.2')
num3 = [1]; % Transfer function for zeta = 0.4

den3 = [1 2*0.4 1];

t3 = tf(num3,den3);

subplot(3,2,3)

step(t3, t)

title('0.4')

num4 = [1]; % Transfer function for zeta = 0.6

den4 = [1 2*0.6 1];

t4 = tf(num4,den4);

subplot(3,2,4)

step(t4, t)

title('0.6')

% Transfer function for zeta = 0.8

num5 = [1];

den5 = [1 2*0.8 1];

t5 = tf(num5,den5);

subplot(3,2,5)

step(t5, t)

title('0.8')

% Transfer function for zeta = 1.0 (Critically damped)


num6 = [1];

den6 = [1 2*1 1];

t6 = tf(num6,den6);

subplot(3,2,6)

step(t6, t)

title('1.0')

Output:
EXP 11: Step Response of 2 nd Order system According to Pole Movement.

Code 1:

den1=poly([-1+2i -1-2i]);

den2=poly([-1.5+2i -1.5-2i]);

den3=poly([-2+2i -2-2i]);

num1=den1(3);
num2=den2(3);

num3=den3(3);

f1=tf(num1,den1)

f2=tf(num2,den2)

f3=tf(num3,den3)

pzmap(f1,f2,f3)

t=0:0.1:10;

c1=step(num1,den1,t);

c2=step(num2,den2,t);

c3=step(num3,den3,t);

plot(t,c1,t,c2,t,c3)
Output:
Code 2:

den1=poly([-1+2i -1-2i]);

den2=poly([-1+4i -1-4i]);

den3=poly([-1+6i -1-6i]);

num1=den1(3);

num2=den2(3);

num3=den3(3);

f1=tf(num1,den1)

f2=tf(num2,den2)
f3=tf(num3,den3)

pzmap(f1,f2,f3)

t=0:0.1:10;

c1=step(num1,den1,t);

c2=step(num2,den2,t);

c3=step(num3,den3,t);

plot(t,c1,t,c2,t,c3)
Output:

Code 3:

den1=poly([-1+2i -1-2i]);

den2=poly([-2+4i -2-4i]);

den3=poly([-3+6i -3-6i]);

num1=den1(3);

num2=den2(3);

num3=den3(3);

f1=tf(num1,den1)
f2=tf(num2,den2)

f3=tf(num3,den3)

pzmap(f1,f2,f3)

t=0:0.1:10;

c1=step(num1,den1,t);

c2=step(num2,den2,t);

c3=step(num3,den3,t);

plot(t,c1,t,c2,t,c3)
Output:

EXP 12: Underdamped System Parameters

Code:
m = 5; % mass (kg)

b = 5; % damping coefficient (N·s/m)

k = 28; % spring constant (N/m)

% Transfer function denominator only

num = 1;

den = [m b k];

sys = tf(num,den);

% Get step response info

info = stepinfo(sys);

% Display

fprintf('Rise Time %.4f sec\n', info.RiseTime);

fprintf('Peak Time %.4f sec\n', info.PeakTime);

fprintf('Overshoot %.4f %% \n', info.Overshoot);

fprintf('Settling Time %.4f sec\n', info.SettlingTime);

Output:
EXP 13: Second Order Approximation

Code:

% Base second-order system

num = [1];
den = [1 2 10]; % Example: wn=√10, zeta=0.316

sys = tf(num, den);

% 1. Add far pole (at -50)

sysPF = tf(num, conv(den, [1 50])); %PF=PoleFar

% 2. Add far zero (at -50)

sysZF = tf(conv(num, [1 50]), den); %ZF=ZeroFar

% 3. Add right-half-plane zero (at +2)

sysNM = tf(conv(num, [1 -2]), den); %NM=NonMinimum

% Plot all step responses

step(sys,'b', sysPF,'g--', sysZF,'r-.', sysNM,'m:');

Output:
EXP 14: Reduction of Multiple Subsystems

Code 1:

numg=[1 1];

deng=[500 0 0];
numh=[1 1];

denh=[1 2];

[num,den]=feedback(numg,deng,numh,denh,-1);

printsys(num,den)

Output 1:

Code 2:
% Define G(s)

numg = [1 1]; % Numerator of G(s): s + 1

deng = [500 0 0]; % Denominator of G(s): 500s^2

% Define Gc(s)

numh = [1 1]; % Numerator of Gc(s): s + 1

denh = [1 2]; % Denominator of Gc(s): s + 2


% Series connection: multiply numerators and denominators

num = conv(numg, numh); % (s+1)*(s+1)

den = conv(deng, denh); % (500s^2)*(s+2)

% Display result

printsys(num, den)

Output:

Code 3
Output

EXP 15: Steady State Error

Code:

num=1000*[1 8];

den=poly([-7 -9]);
G=tf(num,den);

kp=dcgain(G)

estep=1/(1+kp)

Output:

EXP 16: Root Locus Technique


Code:

G=1/(s*(s+2)(s^2+2s+10)); % Plot the root locus

rlocus(G);

% Plot root locus with a damping ratio line (for example: zeta = 0.5)
zeta=0.5; % Damping ratio

sgrid(zeta,0) % Plot constant damping ratio line

Output:
EXP 17: Frequency Response Analysis

Code a:

G = 10 / (s * (s + 1) * (s + 2));

bode(G)

Output:
Code b:

G = 1000 / ((s + 3) * (s + 4) * (s + 5) * (s + 6));

bode(G)

Output:
Code c:

G = 50 * (s + 3) / ((s + 2) * (s + 4));

bode(G)

Output:
Q: Determine the Gain Margin, Phase Margin, Gain Crossover Frequency, phase crossover
frequency of any transfer function using both figure and margin command.

Code:

G = 10 / (s * (s + 2) * (s + 5)); % Using margin command (prints and plots all info)

figure;

margin(G); % This gives GM, PM, ω_gc, ω_pc on the plot


% Using margin() function to extract values numerically

[GM, PM, w_gc, w_pc] = margin(G);

% Convert to dB

GM_dB = 20 * log10(GM);

Output:
Code a:

a=[0 1;-25 -4];

b=[0;25];

c=[1 0];

d=[0];

bode(a,b,c,d)

Output:
EXP 18: Routh-Hurwitz Criterion for Stability
Question

Code:

syms K; a3 = 1; a2 = K - 1; a1 = 2*K - 4; a0 = 24;


r1 = [a3, a1];

r2 = [a2, a0];

r3_1 = simplify((a2a1 - a3a0)/a2); % Avoid division by 0

ineq1 = a2 > 0; ineq2 = r3_1 > 0;

assume(K, 'real'); S1 = solve(ineq1, K, 'ReturnConditions', true); S2 = solve(ineq2, K,


'ReturnConditions', true);

disp('Condition from a2 > 0:'); disp(S1.conditions);

disp('Condition from Routh array row 3 > 0:'); disp(S2.conditions);

% Optional: Find intersection of intervals manually fplot(r3_1, [0, 10]); grid on; xlabel('K');
ylabel('Routh Row 3 Value'); title('Routh Criterion Condition for Stability');
Output:
EXP 19: Improvement of a system using PID Controller
Question:

Code:
Output:

You might also like