[Control engineering] Graphing transfer functions using Python

1.First of all

・ I created this page when I received a comment on the qiita page (https://qiita.com/sato235/items/f991411074c578d1640c) that I wrote last time that it would be interesting to output a waveform graph and consider it.

2. Reference

2.1. Books

[1] Hiroki Minami, Ohmsha, "Introduction to Control Engineering with Python"

2.2. Web page

a) Author support page of [1], https://y373.sakura.ne.jp/minami/pyctrl b) Last self-page, https://qiita.com/sato235/items/f991411074c578d1640c c) Graphing function of matlab function of control module, http://matsulib.hatenablog.jp/entry/2013/04/27/093008

3. Transfer function and graphing

First, import the module.

import sympy
from control import matlab
import numpy as np
import matplotlib.pyplot as plt

Create transfer function

Np = [0,1]
Dp = [1,2,3]
P = matlab.tf(Np, Dp)
print(P)

Transfer function output

      1
-------------
s^2 + 2 s + 3

When a step function is input to the above transfer function.

t = np.linspace(0, 3, 1000)
yout, T = matlab.step(P, t)
plt.plot(T, yout,label="test")
plt.axhline(1, color="b", linestyle="--")
plt.legend(bbox_to_anchor=(1, 0.25), loc='upper right', borderaxespad=0, fontsize=11)

step_20200224.png

When an impulse response function is input to the transfer function P.

yout, T = matlab.impulse(P, t)
plt.plot(T, yout,label="test")
plt.axhline(0, color="b", linestyle="--")
plt.xlim(0, 3)
plt.legend(bbox_to_anchor=(1, 1), loc='upper right', borderaxespad=0, fontsize=11)

impulse_20200224.png

4. Conclusion

-I learned that the control module has a matlab calculation function. -Similarly, there was also a drawing function of matplotlib. ・ Next, I would like to consider the results obtained by changing the input function.

Recommended Posts

[Control engineering] Graphing transfer functions using Python
[Control engineering] Calculation of transfer functions and state space models by Python
Instrument control using Python [pyvisa]
Python control syntax, functions (Python learning memo ②)
Using global variables in python functions
Python functions
Try using Python with Google Cloud Functions
[Circuit x Python] How to expand and calculate transfer functions using Lcapy
Start using Python
#Python basics (functions)
[Beginner] Python functions
Install Python Control
Python Easy-to-use functions
Python basics: functions
Scraping using Python
Get and automate ASP Datepicker control using Python and Selenium
Python Beginner's Guide (Functions)
Operate Redmine using Python Redmine
Fibonacci sequence using Python
Data analysis using Python 0
[Python] Memo about functions
Data cleaning using Python
[Azure] Try using Azure Functions
Using Python #external packages
WiringPi-SPI communication using Python
Python control syntax (memories)
Age calculation using python
# 4 [python] Basics of functions
Python built-in functions ~ Zip ~
Search Twitter using Python
Name identification using python
Notes using Python subprocesses
Wrap Python built-in functions
Memo using trigonometric functions
Try using Tweepy [Python2.7]
Control smart light "Yeelight" from Python without using the cloud
Serial communication control with python and I2C communication (using USBGPIO8 device)
Serial communication control with python and SPI communication (using USBGPIO8 device)
This and that for using Step Functions with CDK + Python