一阶滞后系统传递函数的阶跃响应`Python`表达

一阶滞后系统的定义

一阶滞后系统(First-order Lag System)是动态系统中常见的惯性环节模型,表示输出信号相对于输入信号存在时间滞后。

它的时域模型可以表示为微分方程:

M y ˙ ( t ) + μ y ( t ) = u ( t ) M\dot{y}(t)+ \mu y(t) = u(t) My˙(t)+μy(t)=u(t)

将上式进行拉普拉斯变化,得其传递函数模型:

G ( s ) = 1 M s + μ = 1 μ M μ s + 1 G(s) = \frac{1}{Ms + \mu} = \frac{\frac{1}{\mu}}{\frac{M}{\mu}s + 1} G(s)=Ms+μ1=μMs+1μ1

K = 1 μ K = \frac{1}{\mu} K=μ1 T = M μ T = \frac{M}{\mu} T=μM,其传递函数可写成如下形式:

G ( s ) = K T s + 1 G(s) = \frac{K}{Ts + 1} G(s)=Ts+1K

其中, T T T时间常数 K K K增益,又称为放大系数。时间常数 T T T是决定系统响应速度的重要参数。

Python 实现基础绘图函数

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

plt.rcParams['font.family'] ='sans-serif' # 设置字体
plt.rcParams['xtick.direction'] = 'in' # x轴刻度线方向,向内为in,向外为out,双向为inout
plt.rcParams['ytick.direction'] = 'in' # y轴刻度线方向,向内为in,向外为out,双向为inout
plt.rcParams['xtick.major.width'] = 1.0 # x轴刻度线线宽
plt.rcParams['ytick.major.width'] = 1.0 # y轴刻度线线宽
plt.rcParams['font.size'] = 10 # 字体大小
plt.rcParams['axes.linewidth'] = 1.0 # 坐标轴线宽
plt.rcParams['mathtext.default'] = 'regular'
plt.rcParams['axes.xmargin'] = '0' #'.05'
plt.rcParams['axes.ymargin'] = '0.05'
plt.rcParams['savefig.facecolor'] = 'None'
plt.rcParams['savefig.edgecolor'] = 'None'
  • 绘图线型生成器
def linestyle_generator():
    linestyle = ['-', '--', '-.', ':']
    line_id = 0
    while True:
        yield linestyle[line_id]
        line_id = (line_id + 1) % len(linestyle)
  • 绘图属性设置函数
def plot_set(fig_ax, *args):
    fig_ax.set_xlabel(args[0])  # 通过参数1设置x轴标签
    fig_ax.set_ylabel(args[1])  # 通过参数2设置y轴标签
    fig_ax.grid(ls=':')
    if len(args)==3:
        fig_ax.legend(loc=args[2])  # 通过参数3设置图例位置

一阶滞后系统的传递函数Python表达

  • 一阶滞后系统的阶跃响应

对于传递函数 G ( s ) = K T s + 1 G(s) = \frac{K}{Ts + 1} G(s)=Ts+1K,设 T = 0.5 T = 0.5 T=0.5 K = 1 K = 1 K=1,其阶跃响应(step)可以通过以下代码实现。

def cross_lines(x, y, **kwargs):
    ax = plt.gca()
    ax.axhline(y, **kwargs)
    ax.axvline(x, **kwargs)
    ax.scatter(T, 0.632, **kwargs)

fig, ax = plt.subplots(figsize=(3, 2.3))

(T, K) = (0.5, 1)   # 设置时间常数和增益
P = tf([0, K], [T, 1])  # 表达一阶滞后系统
y, t = step(P, np.arange(0, 5, 0.01))   # 阶跃响应
ax.plot(t,y, color='k')

cross_lines(T, 0.632, color='k',lw=0.5) # 绘制交点
ax.annotate('$(0.5, 0.632)$', xy=(0.7, 0.5))

ax.set_xticks(np.linspace(0, 5, 6))
plot_set(ax, 't', 'y')

阶跃函数
从上图可见,y值从初始值0开始不断增大,经约3秒后达到1.0。图中标注的圆点为 t = T = 0.5 t = T = 0.5 t=T=0.5时的点,此时 y = 0.632 y = 0.632 y=0.632。可见,实际上时间常数 T T T是输出达到稳定值(经过足够长时间后的值)的63.2%时所需的时间。

  • 一阶滞后系统的阶跃响应(改变T值)

T ≥ 0 T \ge 0 T0,当 T T T值改变时,系统响应也会发生变化,当增大 T T T值时,系统响应会变慢,减小 T T T值时,系统响应会变快。

fig, ax = plt.subplots(figsize=(3, 2.3))
LS = linestyle_generator()

K = 1
T = [1, 0.5, 0.1]   # 时间常数T分别取1,0.5和0.1
for i in range(len(T)):
    y, t = step(tf([0, K], [T[i], 1]), np.arange(0, 5, 0.01))   # 输入信号为单位阶跃
    ax.plot(t, y, ls = next(LS), label='T='+str(T[i]))


ax.set_xticks(np.linspace(0, 5, 6))
ax.set_yticks(np.linspace(0, 1, 6))
plot_set(ax, 't', 'y', 'best')

# fig.savefig("1st_step1.pdf", transparent=True, bbox_inches="tight", pad_inches=0.0)

变T
T = 0 T = 0 T=0时,则这是一个“理想化”的无延时阶跃响应。

fig, ax = plt.subplots(figsize=(3, 2.3))

(T, K) = (0, 1)   # 设置时间常数和增益
P = tf([0, K], [T, 1])  # 表达一阶滞后系统
y, t = step(P, np.arange(0, 5, 0.01))   # 阶跃响应
ax.plot(t,y, color='k')

ax.set_xticks(np.linspace(0, 5, 6))
plot_set(ax, 't', 'y')

T=0
T < 0 T < 0 T<0,其响应会发散,即不会收敛到稳定值。

fig, ax = plt.subplots(figsize=(3, 2.3))

(T, K) = (-1, 1)   # 设置时间常数和增益,T=-1
P = tf([0, K], [T, 1])  # 表达一阶滞后系统
y, t = step(P, np.arange(0, 5, 0.01))   # 阶跃响应
ax.plot(t,y, color='k')

ax.set_xticks(np.linspace(0, 5, 6))
plot_set(ax, 't', 'y')

T<0

  • 一阶滞后系统的阶跃响应(改变K值)

同样,改变增益 K K K,我们可以看出,系统响应的阶跃响应也会改变。表现为y的稳定值发生变化,有 y ( ∞ ) = K y(\infty) = K y()=K

fig, ax = plt.subplots(figsize=(3, 2.3))

LS = linestyle_generator()

T = 0.5 # 时间常数T取0.5
K = [1, 2, 3]   # 增益值K取1,2,3
for i in range(len(K)):
    y, t = step(tf([0, K[i]], [T, 1]), np.arange(0, 5, 0.01))   # 阶跃信号
    ax.plot(t,y,ls=next(LS), label='K='+str(K[i]))

ax.set_xticks(np.arange(0, 5.2, step=1.0))
ax.set_yticks(np.arange(0, 3.2, step=1))
plot_set(ax, 't', 'y', 'upper left')

# fig.savefig("1st_step2.pdf", transparent=True, bbox_inches="tight", pad_inches=0.0)

变K

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Humbunklung

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值