import matplotlib.pyplot as plt
import sympy as sp
plt.rcParams['font.size'] = '16' # 设置整体的字号大小
s, t = sp.symbols('s, t')
w = sp.symbols('w', real=True) # w要设置为实数
myt = sp.laplace_transform(sp.cos(w*t), t, s)
print(myt[0])
myt1 = sp.inverse_laplace_transform(myt[0], s, t)
print(myt1)
import control as ctrl
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.size'] = '16'
w = np.logspace(-1, 3, 100)
sys = ctrl.tf([200], [1, 8, 100])
fig = plt.figure(figsize=(10, 6))
Gm, Pm, omega = ctrl.bode(sys, w, dB=True)
plt.savefig('伯德图.jpg')
plt.show()
其中Gm是真实计算的值,不是dB,如果要转成dB则要20*log10(Gm)转换。
import control as ctrl
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
config = {
"font.family": 'serif',
"font.size": 15,
"mathtext.fontset": 'stix',
"font.serif": ['SimSun'],
}
rcParams.update(config)
psi = [1, 1.2, 1.4, 1.6]
fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, figsize=(12, 9))
for k in psi:
sys = ctrl.tf([200], [1, 8*k, 100])
t1, y1 = ctrl.impulse_response(sys, T=np.linspace(0, 3, 1000))
t2, y2 = ctrl.step_response(sys, T=np.linspace(0, 3, 1000))
ax1.plot(t1, y1, label='psi='+str(k))
ax1.set_title('impulse_response')
ax1.legend(prop=font)
ax2.plot(t2, y2, label='psi='+str(k))
ax2.set_title('step_response')
ax2.legend(prop=font)
plt.savefig('响应图.jpg')
plt.show()
import control as ctrl
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import lsim
t = np.linspace(0, 1, 1000)
x = np.sin(2*np.pi*1*t)
# font = {'family': 'Times New Roman', 'weight': 'normal', 'size': 12}
fig = plt.figure()
sys = ctrl.tf([200], [1, 8, 100])
a = 200
b = [1, 8, 100]
t1, y1, x1 = lsim((a, b), U=x, T=t) # 此处返回的x1不知道是啥,而且输入不能直接是ctrl.tf传递过来的sys
plt.plot(t1, y1)
# plt.plot(x1, y1)
plt.show()
另外变成状态方程可以用from scipy.signal import lti
lti(A, B, C, D)
上面的传递函数表示可以用
from scipy.signal import TransferFunction
sys1 = TransferFunction(a, b)
这样就能把sys1直接放到lsim的第一个形参中了,即
t1, y1, x1 = lsim(sys1, U=x, T=t)