0% found this document useful (0 votes)
5 views

Good Examples in MATLAB

The document provides examples of transfer functions in both continuous and discrete forms, utilizing MATLAB code to analyze system properties such as rise time, settling time, and overshoot. It includes the creation of transfer functions, zero/pole/gain models, and stability analysis using Bode and Nyquist plots. Key parameters such as damping ratios and natural frequencies are computed and displayed for various systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Good Examples in MATLAB

The document provides examples of transfer functions in both continuous and discrete forms, utilizing MATLAB code to analyze system properties such as rise time, settling time, and overshoot. It includes the creation of transfer functions, zero/pole/gain models, and stability analysis using Bode and Nyquist plots. Key parameters such as damping ratios and natural frequencies are computed and displayed for various systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

%% Examples (Transfer Functions in (num,den) and zpk form

clc, clear, close all


w=25;
zeta=0.3;
num=w^2;
den = [1 2*zeta*w w^2];
Gs = tf(num,den)

Gs =
625
----------------
s^2 + 15 s + 625

Continuous-time transfer function.


Model Properties

vals=stepinfo(4*Gs)

vals = struct with fields:


RiseTime: 0.0529
TransientTime: 0.4492
SettlingTime: 0.4492
SettlingMin: 3.4455
SettlingMax: 5.4856
Overshoot: 37.1410
Undershoot: 0
Peak: 5.4856
PeakTime: 0.1289

Ts=vals.SettlingTime

Ts = 0.4492

Tr=vals.RiseTime

Tr = 0.0529

Tt=vals.TransientTime

Tt = 0.4492

Tp=vals.PeakTime
Tp = 0.1289

Mp=vals.Peak

Mp = 5.4856

Os=vals.Overshoot;
fprintf('Overshoot: %0.4f %%', Os);% Percentage Os

Overshoot: 37.1410 %

z = 0; % Zeros
p = [-0.2500+0.6614i -0.2500-0.6614i]; % Poles
k = 2; % Gain
Hs=zpk(z,p,k)

Hs =

2 s
---------------------
(s^2 + 0.5s + 0.4999)

Continuous-time zero/pole/gain model.


Model Properties

zplane(z,p)
sgrid
figure
zgrid
axis('equal')

damp(Hs)

Pole Damping Frequency Time


Constant
(rad/seconds)
(seconds)

-2.50e-01 + 6.61e-01i 3.54e-01 7.07e-01


4.00e+00
-2.50e-01 - 6.61e-01i 3.54e-01 7.07e-01
4.00e+00

[wn,zeta]=damp(Hs)

wn = 2×1
0.7071
0.7071
zeta = 2×1
0.3536
0.3536
sys = zpk({0;-0.5},{0.3;[0.1+1i,0.1-1i]},[1;2],0.1)

sys =

From input to output...


z
1: -------
(z-0.3)

2 (z+0.5)
2: -------------------
(z^2 - 0.2z + 1.01)

Sample time: 0.1 seconds


Discrete-time zero/pole/gain model.
Model Properties

num = [10];
den = [1 2];
G = tf(num,den)

G =

10
-----
s + 2

Continuous-time transfer function.


Model Properties

%% code number one


[MAG, PHASE] = bode(G);
PHASE = PHASE(1,:)

PHASE = 1×48

6.3811 ⋯
-2.8624 -2.9277 -3.4225 -4.0005 -4.6754 -5.4629 -

MAG = MAG(1,:)

MAG = 1×48

4.9690 ⋯
4.9938 4.9935 4.9911 4.9878 4.9834 4.9773
polar(PHASE*pi/180, MAG)

%% code number two


nyquist(G)
grid

stabilty=isstable(G)

stabilty = logical
1
z = 0; % Zeros
p = [-0.2500+0.6614i -0.2500-0.6614i]; % Poles
k = 2; % Gain
Hs=zpk(z,p,k)

Hs =

2 s
---------------------
(s^2 + 0.5s + 0.4999)

Continuous-time zero/pole/gain model.


Model Properties

zplane(z,p)
sgrid

figure
zgrid
axis('equal')
damp(Hs)

Pole Damping Frequency Time


Constant
(rad/seconds)
(seconds)

-2.50e-01 + 6.61e-01i 3.54e-01 7.07e-01


4.00e+00
-2.50e-01 - 6.61e-01i 3.54e-01 7.07e-01
4.00e+00

[wn,zeta]=damp(Hs)

wn = 2×1
0.7071
0.7071
zeta = 2×1
0.3536
0.3536
sys = zpk({0;-0.5},{0.3;[0.1+1i,0.1-1i]},[1;2])

sys =
From input to output...
s
1: -------
(s-0.3)

2 (s+0.5)
2: -------------------
(s^2 - 0.2s + 1.01)
Continuous-time zero/pole/gain model.

sys = zpk({[] ;-0.5},{0.3;[-1,-2]},[1;2])

sys =
From input to output...
1
1: -------
(s-0.3)

2 (s+0.5)
2: -----------
(s+1) (s+2)
Continuous-time zero/pole/gain model.

sys = zpk({[] ;-0.5;[]},{0.3;[-1,-2];0},[1;2;10])

sys =
From input to output...
1
1: -------
(s-0.3)

2 (s+0.5)
2: -----------
(s+1) (s+2)

10
3: --
s
Continuous-time zero/pole/gain model.
sys = zpk({0;-0.5},{0.3;[0.1+1i,0.1-1i]},[1;2],0.1)

sys =

From input to output...


z
1: -------
(z-0.3)

2 (z+0.5)
2: -------------------
(z^2 - 0.2z + 1.01)

Sample time: 0.1 seconds


Discrete-time zero/pole/gain model.

num = [1,2];
den = [3,4,5];
Sysc=tf(num,den)

Sysc =

s + 2
---------------
3 s^2 + 4 s + 5

Continuous-time transfer function.

[wn,zeta]=damp(Sysc)

wn = 2×1
1.2910
1.2910
zeta = 2×1
0.5164
0.5164
w = wn(1); % for example 3 rad/s
val = polyval(num,j*w)/polyval(den,j*w)

val = 0.2500 - 0.3873i

polarplot(val)

num = [10];
den = [1 2];
G = tf(num,den)

G =

10
-----
s + 2

Continuous-time transfer function.

[MAG, PHASE] = bode(G);


PHASE = PHASE(1,:)

PHASE = 1×48

6.3811 ⋯
-2.8624 -2.9277 -3.4225 -4.0005 -4.6754 -5.4629 -
MAG = MAG(1,:)

MAG = 1×48

4.9690 ⋯
4.9938 4.9935 4.9911 4.9878 4.9834 4.9773

polar(PHASE*pi/180, MAG)

stabilty=isstable(G)

stabilty = logical

You might also like