如何为 MIMO 系统使用 scipy 信号

How to use scipy signal for MIMO systems

我正在寻找一种方法来模拟各种输入信号的信号输出。更准确地说,我有一个由其传递函数 H 定义的系统,它接受一个输入并有一个输出。我生成了几个信号(存储在一个 numpy 数组中)。我想做的是在不使用 for 循环的情况下获得系统对每个输入信号的响应。有办法继续吗?以下是我到目前为止编写的代码。

from __future__ import division
import numpy as np
from scipy import signal

nbr_inputs = 5
t_in = np.arange(0,10,0.2)
dim = (nbr_inputs, len(t_in))

x = np.cumsum(np.random.normal(0,2e-3, dim), axis=1)
H = signal.TransferFunction([1, 3, 3], [1, 2, 1])
t_out, y, _ = signal.lsim(H, x[0], t_in) # here, I would just like to simply write x

感谢您的帮助

这不是一个 MIMO 系统,它是一个 SISO 系统,但你有多个输入。

您可以创建一个 MIMO 系统并同时应用所有输入,这将逐个通道同时计算。此外,您还不能对 MIMO 系统使用 scipy.signal.lsim。您可以使用其他选项,例如 python-control(如果您有 slycot 扩展,否则再次没有 MIMO)或 harold 如果您有 Python 3.6 或更高版本(免责声明:我是作者)。

import numpy as np
from harold import *
import matplotlib.pyplot
nbr_inputs = 5
t_in = np.arange(0,10,0.2)
dim = (nbr_inputs, len(t_in))

x = np.cumsum(np.random.normal(0,2e-3, dim), axis=1)

# Forming a 1x5 system, common denominator will be completed automatically
H = Transfer([[[1, 3, 3]]*nbr_inputs], [1, 2, 1])

关键字 per_channel=True 将第一个输入应用到第一个通道,将第二个输入应用到第二个通道,依此类推。否则返回组合响应。你可以通过玩弄它来检查形状,看看我的意思。

# Notice it is x.T below -> input shape = <num samples>, <num inputs>
y, t = simulate_linear_system(H, x.T, t_in, per_channel=True)

plt.plot(t, y)

这给出了