Transfer Functions with Python - halvorsen.blog
Transcript of Transfer Functions with Python - halvorsen.blog
Hans-Petter Halvorsen
https://www.halvorsen.blog
Transfer Functions with Python
https://www.halvorsen.blog/documents/programming/python/
Free Textbook with lots of Practical Examples
Additional Python Resources
https://www.halvorsen.blog/documents/programming/python/
โข Introduction to Control Systemsโข Transfer Functionsโข Step Responseโข Poles and Zerosโข Python ExamplesโSciPy (SciPy.signal)โThe Python Control Systems Library
Contents
Control System
Controller Process
Sensors
Actuators
Filtering
๐ ๐ข๐
โ
๐ฅ
๐ฃReference Value
Control Signal
Noise/Disturbance
Process Output
๐ฆ
Control Systemโข ๐ โ Reference Value, SP (Set-point), SV (Set Value)โข ๐ฆ โ Measurement Value (MV), Process Value (PV)โข ๐ โ Error between the reference value and the
measurement value (๐ = ๐ โ ๐ฆ)โข ๐ฃ โ Disturbance, makes it more complicated to control
the processโข ๐ข - Control Signal from the Controller
Control System
Controller Process๐ ๐ข๐
โ
๐ฆ
Reference Value
Control Signal
Measurements๐ฆ
Simplified Control System:
๐ป!(๐ ) ๐ป"(๐ )
The Controller is typically a PID Controller that has ๐พ", ๐#and ๐$ as Tuning Parameters
The purpose with the controller is to make sure the process stays on a desired level, e.g., it could be level in a liquid tank or the temperature at a specific value, e.g., 30โ
โข Transfer functions are a model form based on the Laplace transform. โข Transfer functions are very useful in
analysis and design of linear dynamic systems.
Transfer Functions
Transfer FunctionsA general Transfer function is on the form:
๐ป ๐ =๐ฆ(๐ )๐ข(๐ )
Where ๐ฆ is the output and ๐ข is the input.s is the Laplace operator
๐ป ๐ ๐ข(๐ ) ๐ฆ(๐ )
Transfer FunctionsA general transfer function can be written on the following general form:
๐ป ๐ =๐๐ข๐๐๐๐๐ก๐๐(๐ )๐๐๐๐๐๐๐๐๐ก๐๐(๐ )
=๐-๐ - + ๐-./๐ -./ +โฏ+ ๐/ ๐ + ๐0๐1๐ 1 + ๐1./๐ 1./ +โฏ+ ๐/ ๐ + ๐0
The Numerators of transfer function models describe the locations of the zeros of the system, while the Denominators of transfer function models describe the locations of the poles of the system.
Transfer Functions - Examples
๐ป(๐ ) =3
๐ (2๐ + 1)๐ป(๐ ) =1
3๐ + 1
๐ป ๐ = !"#$%
๐&'# ๐ป(๐ ) =4
3๐ ' โ 2๐ + 1
1. Order System:
1. Order System with Time Delay: 2. Order System:
1. Order System with Integrator:
Transfer Functions - Python๐ป ๐ = 2
3 435/ = 243!53๐ป(๐ ) =
23๐ + 1
๐ป(๐ ) =4
3๐ % โ 2๐ + 1
import numpy as npimport control
num = np.array ([2])den = np.array ([3 , 1])
H = control.tf(num , den)
print ('H(s) =', H)
import numpy as npimport control
num = np.array ([3])den = np.array ([2 , 1, 0])
H = control.tf(num , den)
print ('H(s) =', H)
import numpy as npimport control
num = np.array ([4])den = np.array ([3 , -2, 1])
H = control.tf(num , den)
print ('H(s) =', H)๐ป(๐ ) =
4๐ + 12๐ % + 5๐ โ 2
import numpy as npimport control
num = np.array ([4, 1])den = np.array ([2 , 5, -2])
H = control.tf(num , den)
print ('H(s) =', H)
Transfer Functions1.order Transfer Function:
๐ป(๐ ) =๐พ
๐๐ + 1
๐ป(๐ ) =๐พ๐
Integrator:
๐ป(๐ ) =๐พ
๐๐ + 1๐.=3๐ป(๐ ) = ๐.=3
Transfer Function for Time Delay:1. order Transfer Function with Time Delay:
2. order Transfer Function: ๐ป(๐ ) =๐พ
๐๐ 4 + ๐๐ + ๐
๐ป(๐ ) =๐พ
(๐/ + 1)(๐4๐ + 1)
or:
More about the different types of Transfer Functions later in this Tutorial
Control System
Controller Process
Sensors
Actuators
Filtering
๐ ๐ข๐
โ
๐ฅ
๐ฃReference Value
Control Signal
Noise/Disturbance
Process Output
๐ฆ
๐ป( ๐
๐ป) ๐ ๐ป# ๐
๐ป* ๐ ๐ป+ ๐
Back to the Control System: Each block can be described by a Transfer Function:
Hans-Petter Halvorsen
https://www.halvorsen.blog
Python Examples
Python Examplesโข SciPy (SciPy.signal)โ Included with Anaconda Distributionโ Limited Functions and Features for Control Systems
โข Python Control Systems Libraryโ I will refer to it as the โControlโ Libraryโ Very similar features as the MATLAB Control System
Toolboxโ You need to install it (โpip install controlโ)
Hans-Petter Halvorsen
https://www.halvorsen.blog
SciPy.signal
โข The SciPy.signal contains Signal Processing functionsโข SciPy is also included with the Anaconda distribution โข If you have installed Python using the Anaconda
distribution, you donโt need to install anythingโข https://docs.scipy.org/doc/scipy/reference/signal.html
SciPy.signal
Python import numpy as npimport scipy.signal as signalimport matplotlib.pyplot as plt
# Define Transfer Functionnum = np.array([2])den = np.array([3 , 1])
H = signal.TransferFunction(num , den)
print ('H(s) =', H)
# Step Responset, y = signal.step(H)
# Plottingplt.plot(t, y)plt.title("Step Response")plt.xlabel("t")plt.ylabel("y")plt.grid()plt.show()
๐ป(๐ ) =2
3๐ + 1
Transfer Function:
H(s) = TransferFunctionContinuous(array([0.66666667]),array([1., 0.33333333]),dt: None)
Comments to Results
๐ป(๐ ) =2
3๐ + 1
Transfer Function:
H(s) = TransferFunctionContinuous(array([0.66666667]),array([1., 0.33333333]),dt: None)
๐ป(๐ ) =23
33 ๐ +
13
๐ป(๐ ) =0.67
๐ + 0.33
Hans-Petter Halvorsen
https://www.halvorsen.blog
Python Control Systems Library
โข The Python Control Systems Library (control) is a Python package that implements basic operations for analysis and design of feedback control systems.
โข Existing MATLAB user? The functions and the features are very similar to the MATLAB Control Systems Toolbox.
โข Python Control Systems Library Homepage: https://pypi.org/project/control
โข Python Control Systems Library Documentation: https://python-control.readthedocs.io
Python Control Systems Library
The Python Control Systems Library package may be installed using pip:
Installation
pip install control
โข PIP is a Package Manager for Python packages/modules.
โข You find more information here: https://pypi.org
โข Search for โcontrolโ.โข The Python Package Index (PyPI) is a
repository of Python packages where you use PIP in order to install them
Anaconda PromptIf you have installed Python with Anaconda Distribution, use the Anaconda Prompt in order to install it (just search for it using the Search field in Windows).
pip install control
pip list
Command Prompt - PIP
C:\Users\hansha\AppData\Local\Programs\Python\Python37-32\Scripts\pip install control
Example: Install Python package โcamelCaseโ:
pip install control
pip list or โPython37_64โ for Python 64bits
Python Control Systems Library - FunctionsFunctions for Model Creation and Manipulation:โข tf()- Create a transfer function systemโข ss()- Create a state space systemโข c2d()- Return a discrete-time systemโข tf2ss()- Transform a transfer function to a state space systemโข ss2tf()- Transform a state space system to a transfer function.โข series()- Return the series of 2 or more subsystemsโข parallel()- Return the parallel of 2 or more subsystemsโข feedback()- Return the feedback of systemโข pade()- Creates a Pade Aproxomation, which is a Transfer function
representation of a Time Delay
Python Control Systems Library - FunctionsFunctions for Model Simulations:โข step_response()- Step response of a linear systemโข lsim()- Simulate the output of a linear systemFunctions for Stability Analysis:โข step_response()- Step response of a linear systemโข lsim()- Simulate the output of a linear systemโข pole()- Compute system polesโข zero()- Compute system zerosโข pzmap()- Plot a pole/zero map for a linear systemโข margin()- Calculate gain and phase margins and frequenciesโข stability_margins()- Calculate stability margins and frequencies+++ Many more Functions โฆ
Python
๐ป(๐ ) =2
3๐ + 1
import controlimport numpy as npimport matplotlib.pyplot as plt
num = np.array([2])den = np.array([3 , 1])
H = control.tf(num , den)print ('H(s) =', H)
t, y = control.step_response(H)
plt.plot(t,y)plt.title("Step Response")plt.grid()
Transfer Function:
Alternative
๐ป(๐ ) =2
3๐ + 1
import controlimport matplotlib.pyplot as plt
s = control.TransferFunction.s
H = (2)/(3*s + 1)
print ('H(s) =', H)
t, y = control.step_response(H)
plt.plot(t,y)plt.title("Step Response")plt.grid()
Transfer Function:
Alternative
๐ป(๐ ) =6๐ + 1
๐ ! + 4๐ + 8
import controlimport matplotlib.pyplot as plt
s = control.TransferFunction.s
H = (6*s + 1)/(s**2 + 4*s + 8)
print ('H(s) =', H)
t, y = control.step_response(H)
plt.plot(t,y)plt.title("Step Response")plt.grid()
Transfer Function:
Which approach you should use is a matter of taste and what kind of system you are implementing, etc.
Hans-Petter Halvorsen
https://www.halvorsen.blog
Types of Transfer Functions
Types of Transfer Functionsโข 1. order Transfer Functionsโข Integrator โข Time Delayโข 1. order Transfer Function with Time Delayโข 2. order Transfer Functions
Hans-Petter Halvorsen
https://www.halvorsen.blog
1.order Transfer Function
1.order Transfer Functions
๐ป ๐ =๐ฆ(๐ )๐ข(๐ )
=๐พ
๐๐ + 1
A 1.order transfer function is given by:
Where ๐พ is the Gain and ๐ is the Time constant
In the time domain we get the following equation (using Inverse Laplace):
๐ฆ ๐ก = ๐พ๐(1 โ ๐"#$)
(After a Step ๐ for the input signal ๐ข(๐ ))
1.order โ Step Response100%
63%
๐พ๐
๐ก๐
๐ฆ ๐ก = ๐พ๐(1 โ ๐.?@)
๐ป ๐ =๐ฆ(๐ )๐ข(๐ )
=๐พ
๐๐ + 1
๐ฆ(๐ก)
Why ๐ = 63%?
๐ฆ ๐ก = ๐พ๐(1 โ ๐.?@)
We have:
๐ป ๐ =๐ฆ(๐ )๐ข(๐ )
=๐พ
๐๐ + 1
We set ๐ก = ๐:
๐ฆ ๐ก = ๐พ๐ 1 โ ๐!"" = ๐พ๐ 1 โ ๐!# = ๐พ๐ 1 โ 0.37 = 0.63 9 ๐พ๐
This means the step response has reached 63% after ๐ seconds
Python import numpy as npimport matplotlib.pyplot as pltimport control
K = 3T = 4
num = np.array ([K])den = np.array ([T , 1])
H = control.tf(num , den)print ('H(s) =', H)
t, y = control.step_response(H)
plt.plot(t,y)plt.title("Step Response")plt.grid()
๐ป(๐ ) =3
4๐ + 1
Transfer Function:
1.order Transfer Functions
๐ป ๐ =๐ฆ(๐ )๐ข(๐ )
=๐พ
๐๐ + 1
A 1.order transfer function is given by:
Where ๐พ is the Gain and ๐ is the Time constant
In the time domain we get the following equation (using Inverse Laplace):
๐ฆ ๐ก = ๐พ๐(1 โ ๐"#$)
(After a Step ๐ for the input signal ๐ข(๐ ))
Time Constant ๐import numpy as npimport controlimport matplotlib.pyplot as plt
K = 10Tarray = [5, 10, 30, 50]
start = 0stop = 200step = 0.1t = np.arange(start, stop, step)
for T in Tarray:#Create Transfer Functionnum = np.array ([K])den = np.array ([T , 1])
H = control.tf(num , den)
print ('H(s) =', H)# Step Responset, y = control.step_response(H, t)# Plotplt.plot(t, y)
plt.title("Step Response for different T")plt.xlabel("t")plt.ylabel("y")plt.legend(Tarray)plt.grid()plt.show()
Conclusion:Larger ๐ โ Slower SystemSmaller ๐ โ Faster System
Transfer Function:
๐ป ๐ =๐ฆ(๐ )๐ข(๐ ) =
10๐๐ + 1 We try with
different values for ๐
๐ฆ ๐ก = ๐พ๐(1 โ ๐.?@)
Step Response:
Gain Kimport numpy as npimport controlimport matplotlib.pyplot as plt
T = 10Karray = [1, 3, 5, 10]
start = 0stop = 60step = 0.1t = np.arange(start, stop, step)
for K in Karray:#Create Transfer Functionnum = np.array ([K])den = np.array ([T , 1])
H = control.tf(num , den)
print ('H(s) =', H)# Step Responset, y = control.step_response(H, t)# Plotplt.plot(t, y)
plt.title("Step Response for different K")plt.xlabel("t")plt.ylabel("y")plt.legend(Karray)plt.grid()plt.show()
Transfer Function;
๐ป ๐ =๐ฆ(๐ )๐ข(๐ ) =
๐พ10๐ + 1 We try with
different values for ๐พ
Steady State Response:
๐ฆ ๐ก = ๐พ๐(1 โ ๐.?@)
๐ฆ& = lim'โ)
๐ฆ ๐ก = ๐พ๐
(We used ๐ = 1 in the simulations)
Step Response:
Hans-Petter Halvorsen
https://www.halvorsen.blog
Integrator
Integrator
๐ป ๐ =๐ฆ(๐ )๐ข(๐ )
=๐พ๐
A Transfer Function for an Integrator is given by:
Where ๐พ is the Gain
In the time domain we get the following equation (using Inverse Laplace):
๐ฆ ๐ก = ๐พ๐๐ก๐ป(๐ ) =๐พ๐
(After a Step ๐ for the unput signal ๐ข(๐ ))
Example of an Integrator: A Water/Liquid Tank
Python import numpy as npimport matplotlib.pyplot as pltimport control
K = 3
num = np.array ([K])den = np.array ([1, 0])
H = control.tf(num , den)print ('H(s) =', H)
t, y = control.step_response(H)
plt.plot(t,y)plt.title("Step Response")plt.grid()
๐ป(๐ ) =๐พ๐
๐ป(๐ ) =3๐
We set ๐พ = 3 in this example:
Hans-Petter Halvorsen
https://www.halvorsen.blog
Time Delay
Time Delay
๐ป ๐ =๐ฆ(๐ )๐ข(๐ )
=๐พ
๐๐ + 1๐"%&
๐ป ๐ =๐ฆ(๐ )๐ข(๐ ) = ๐!"#
Transfer Function for Time Delay:
1. order Transfer Function with Time Delay:
Time Delay
๐ป(๐ ) = ๐!"#Transfer Function for Time Delay:
Step Response for Time Delay:
๐๐ก
1
Padรฉ ApproximationIn some situations, it is necessary to substitute ๐*+& with an approximation, e.g., the Padรฉ Approximation:
๐*+& โ1 โ ๐,๐ + ๐%๐ % +โฏ ยฑ ๐-๐ -
1 + ๐,๐ + ๐%๐ % +โฏ+ ๐-๐ -
๐ป(๐ ) = ๐*+&Transfer Function for Time Delay:
1.order Padรฉ Approximation: 2.order Padรฉ Approximation:
๐!$% โ1 โ ๐#๐ 1 + ๐#๐
=โ๐#๐ + 1๐#๐ + 1
Where ๐, =+%
Where n is the order of the approximation and ๐,, ๐%, โฆ are constants
๐.=3 โ /.K"35K!3!
/5K"35K!3!
Where ๐, =+%
and ๐% =+!
,%etc.
Padรฉ Approx.import numpy as npimport matplotlib.pyplot as pltimport control
# Time DelayTau = 2
# Approximation OrderN = 5
[num_pade,den_pade] = control.pade(Tau,N)Hpade = control.tf(num_pade,den_pade)print ('Hpade(s) =', Hpade)
start = 0stop = 10step = 0.1
t = np.arange(start, stop, step)
t, y = control.step_response(Hpade, t)
plt.plot(t,y)title = "Pade Aprroximation, N=" + str(N)plt.title(title)plt.grid()
๐ป(๐ ) = ๐&'#
We can use the pade()Function:
If you want a more accurate approximation, you can increase the order N. Padรฉ approximations with order ๐ > 10 should be avoided.
Padรฉ Approx.import numpy as npimport matplotlib.pyplot as pltimport control
# Time DelayTau = 2
N = 5
start = 0stop = 10step = 0.1t = np.arange(start, stop, step)
N = [1, 2, 3, 5, 10]
for n in N:[num_pade,den_pade] = control.pade(Tau,n)Hpade = control.tf(num_pade,den_pade)print ('Hpade(s) =', Hpade)
t, y = control.step_response(Hpade, t)
plt.plot(t,y)
plt.title("Pade Aprroximations") plt.legend(N)plt.grid()
๐ป(๐ ) = ๐&'#
We plot Padรฉ Approximations with different orders in the same Plot:
1. order with Time Delay
๐ป(๐ ) =๐พ
๐๐ + 1๐"%&
1. order Transfer Function with Time Delay:
Where ๐พ is the Gain, ๐ is the Time constant and ๐ is the Time Delay
1. order with Time DelayStep Response
100%
63%
๐พ๐
๐ก
๐๐
๐ป(๐ ) =๐พ
๐๐ + 1๐"%&
Pythonimport numpy as npimport matplotlib.pyplot as pltimport control
K = 3T = 4
num = np.array ([K])den = np.array ([T , 1])
H1 = control.tf(num , den)print ('H1(s) =', H1)
Tau = 2N = 5 # Order of the Approximation[num_pade,den_pade] = control.pade(Tau,N)Hpade = control.tf(num_pade,den_pade)print ('Hpade(s) =', Hpade)
H = control.series(H1, Hpade)print ('H(s) =', H)
t, y = control.step_response(H)
plt.plot(t,y)plt.title("H(s)")plt.grid()
๐ป(๐ ) = '(&)*
๐"!&Transfer Function:
Hans-Petter Halvorsen
https://www.halvorsen.blog
2.order Transfer Function
2.order Transfer Functions
๐ป(๐ ) =๐พ
๐๐ 4 + ๐๐ + ๐๐ป(๐ ) =
๐พ(๐/๐ + 1)(๐4๐ + 1)
2. order Transfer Function can be given on the following form:
Or like this:
Or like this:
Where ๐, and ๐% are Time Constants
๐พ is the gain๐ zeta is the relative damping factor๐![rad/s] is the undamped resonance frequency
๐ป ๐ =๐พ๐&'
๐ ' + 2๐๐&๐ + ๐&'=
๐พ๐ ๐&
'+ 2๐ ๐
๐&+ 1
2.order Transfer FunctionsSpecial case: When ๐ > 0 and the poles are real and distinct we have:
๐ป(๐ ) =๐พ
(๐,๐ + 1)(๐%๐ + 1)
We see that this system can be considered as two 1.order systems in series:
๐ป ๐ = ๐ป, ๐ ๐ป, ๐ =๐พ
(๐,๐ + 1)N
1(๐%๐ + 1)
=๐พ
(๐,๐ + 1)(๐%๐ + 1)
Python import numpy as npimport scipy.signal as signalimport matplotlib.pyplot as plt
# Define Transfer Functionnum = np.array([4])den = np.array([3 , 2, 1])
H = signal.TransferFunction(num , den)
print ('H(s) =', H)
# Step Responset, y = signal.step(H)
# Plottingplt.plot(t, y)plt.title("Step Response")plt.xlabel("t")plt.ylabel("y")plt.grid()plt.show()
๐ป(๐ ) =4
3๐ ' + 2๐ + 1
SciPy.signal
Python import controlimport numpy as npimport matplotlib.pyplot as plt
# Define Transfer Functionnum = np.array([4])den = np.array([3 , 2, 1])
H = control.tf(num , den)print ('H(s) =', H)
# Step Responset, y = control.step_response(H)
# Plottingplt.plot(t, y)plt.title("Step Response")plt.xlabel("t")plt.ylabel("y")plt.grid()plt.show()
๐ป(๐ ) =4
3๐ ' + 2๐ + 1
The Python Control Systems Library
Hans-Petter Halvorsen
https://www.halvorsen.blog
Poles and Zeros
Transfer FunctionsA general transfer function can be written on the following general form:
๐ป ๐ =๐๐ข๐๐๐๐๐ก๐๐(๐ )๐๐๐๐๐๐๐๐๐ก๐๐(๐ )
=๐-๐ - + ๐-./๐ -./ +โฏ+ ๐/ ๐ + ๐0๐1๐ 1 + ๐1./๐ 1./ +โฏ+ ๐/ ๐ + ๐0
The Numerators of transfer function models describe the locations of the Zerosof the system, while the Denominators of transfer function models describe the locations of the Poles of the system.
Transfer FunctionsA general transfer function can be written on the following general form:
๐ป ๐ =๐1/๐ + 1 ๐14๐ + 1 โฏ ๐1K๐ + 1๐O/๐ + 1 ๐O4๐ + 1 โฏ ๐O-๐ + 1
๐ป ๐ =๐๐๐๐๐ ๐๐๐๐๐
Example:
๐ป ๐ =๐ + 1 2๐ + 13๐ + 1 4๐ + 1
Zeros:
Poles:
๐ + 1 = 0
2๐ + 1 = 0
3๐ + 1 = 04๐ + 1 = 0
๐ง, = โ1
๐ง% = โ0.5
๐, = โ0.33
๐% = โ0.25
Pythonimport numpy as npimport control
num = np.array([1, 1])den = np.array([3 , 1])H1 = control.tf(num , den)
num = np.array([2, 1])den = np.array([4 , 1])H2 = control.tf(num , den)
H = control.series(H1,H2)print ('H(s) =', H)
z = control.zero(H)print ('z =', z)
p = control.pole(H)print ('p =', p)
control.pzmap(H)
Transfer Function:
๐ป ๐ =๐ + 1 2๐ + 13๐ + 1 4๐ + 1 ๐ป ๐ =
๐ + 13๐ + 1 N
2๐ + 14๐ + 1
Alternatively we can multiply:
๐ป ๐ =2๐ % + ๐ + 2๐ + 112๐ % + 3๐ + 4๐ + 1 =
2๐ % + 3๐ + 112๐ % + 7๐ + 1
num = np.array([2, 3, 1])den = np.array([12 , 7, 1])H = control.tf(num , den) num1 = np.array([1, 1])
num2 = np.array([2, 1])num = np.convolve(num1, num2)
den1 = np.array([3 , 1])den2 = np.array([4 , 1])den = np.convolve(den1, den2)
H = control.tf(num , den)
Or we can use the np.convolve() function:
Results๐ป ๐ =
๐ + 1 2๐ + 13๐ + 1 4๐ + 1
๐ง, = โ1
๐ง% = โ0.5
๐, = โ0.33
๐% = โ0.25
control.pzmap(H)
z = [-1. -0.5]
z = control.zero(H)
p = control.pole(H)
p = [-0.33333333 -0.25]
Poles and Stability of the SystemThe poles are important when analyzing the stability of a system. The Figure below gives an overview of the poles impact on the stability of a system.
Unstable System
(right side)Stable System
(left side) Re
ImWe have 3 different Alternatives:1. Asymptotically Stable System2. Marginally Stable System3. Unstable System
Poles and Stability
๐ก ๐ก
lim(โ*
๐ฆ ๐ก = โ
๐ก
0 < lim(โ*
๐ฆ ๐ก < โlim(โ*
๐ฆ ๐ก = ๐
Re
ImPoles:
Step Response:
Re
Im
Re
Im
Asymptotically Stable System Marginally Stable System Unstable System
Asymptotically Stable System
Re
Im
Each of the poles of the transfer function lies strictly in the left half plane (has strictly negative real part)
๐ก
lim(โ*
๐ฆ ๐ก = ๐
Python import controlimport numpy as npimport matplotlib.pyplot as plt
# Define Transfer Functionnum = np.array([2])den = np.array([3 , 1])
H = control.tf(num , den)print ('H(s) =', H)
# Polesp = control.pole(H)print ('p =', p)
# Step Responset, y = control.step_response(H)
plt.plot(t,y)plt.title("Step Response")plt.grid()
control.pzmap(H)
Transfer Function:
๐ป ๐ =๐ฆ(๐ )๐ข(๐ )
=2
3๐ + 1
p = [-0.33333333]
lim(โ*
๐ฆ ๐ก = ๐
Asymptotically Stable System
Marginally Stable System
Re
Im
๐ก
0 < lim(โ*
๐ฆ ๐ก < โ
One or more poles lies on the imaginary axis (have real part equal to zero), and all these poles are distinct. Besides, no poles lie in the right half plane.
Python import controlimport numpy as npimport matplotlib.pyplot as plt
# Define Transfer Functionnum = np.array([3])den = np.array([1, 0, 1])
H = control.tf(num , den)print ('H(s) =', H)
# Polesp = control.pole(H)print ('p =', p)
# Step Responsetstart = 0; tstop = 20; tstep = 0.1t = np.arange(tstart, tstop, tstep)t, y = control.step_response(H, t)
plt.plot(t,y)plt.title("Step Response")plt.grid()
control.pzmap(H)
Transfer Function:
๐ป(๐ ) =3
๐ % + 1
Marginally Stable System
Unstable System
Re
Im
Re
Im
or
๐ก
lim(โ*
๐ฆ ๐ก = โ
At least one pole lies in the right half plane (has real part greater than zero).
Or: There are multiple and coincident poles on the imaginary axis.Example: double integrator ๐ป(๐ ) = ,
&!
Python import controlimport numpy as npimport matplotlib.pyplot as plt
# Define Transfer Functionnum = np.array([2])den = np.array([3 , -1])
H = control.tf(num , den)print ('H(s) =', H)
# Polesp = control.pole(H)print ('p =', p)
# Step Responset, y = control.step_response(H)
plt.plot(t,y)plt.title("Step Response")plt.grid()
control.pzmap(H)
Transfer Function:
๐ป(๐ ) =2
3๐ โ 1
Unstable System
lim(โ*
๐ฆ ๐ก = โ
Pythonimport controlimport numpy as npimport matplotlib.pyplot as plt
# Define Transfer Functionnum = np.array([2, 1])den = np.array([3 , -1, -2])
H = control.tf(num , den)print ('H(s) =', H)
# Polesp = control.pole(H)print ('p =', p)
# Step Responset, y = control.step_response(H)
plt.plot(t,y)plt.title("Step Response")plt.grid()
control.pzmap(H)
Transfer Function:
๐ป ๐ =2๐ + 1
3๐ % โ ๐ โ 2
Unstable System
lim(โ*
๐ฆ ๐ก = โ
Pythonimport controlimport numpy as npimport matplotlib.pyplot as plt
# Define Transfer Functionnum = np.array([2])den = np.array([1, 0, 0])
H = control.tf(num , den)print ('H(s) =', H)
# Polesp = control.pole(H)print ('p =', p)
# Step Responset, y = control.step_response(H)
plt.plot(t,y)plt.title("Step Response")plt.grid()
control.pzmap(H)
Transfer Function:
๐ป(๐ ) =2๐ 4
Unstable System
๐, = 0, ๐% = 0
Additional Python Resources
https://www.halvorsen.blog/documents/programming/python/
Hans-Petter Halvorsen
University of South-Eastern Norwaywww.usn.no
E-mail: [email protected]: https://www.halvorsen.blog