python求帮助, 想用代码实现系统频率响应伯德图。用amesim搭建的模型,然后用 amesim中自带的appspace功能(应该和PyQt差不多)做的gui,代码在简单的模型中可以出图,但是在稍微复杂一点的模型中报错。
import traceback
from PySide2 import QtCore, QtGui, QtWidgets
from .ui_mainform import Ui_MainForm
import apps
import amesim
from amesim import *
import os
import amepyplot
import math
from math import *
import scipy
import scipy.signal
os.chdir(r'D:\Ametest')
plot = amepyplot.PlotWidget()
# Retrieve linearization times (if needed)
times=amesim.amela('2redundanceflappervalvetestAPP')
# select the index of the jacfile to use (use 1 to display the second linearization time)
jacfileIndex = 2
[A, B, C, D, x, u, y, t, S] = amesim.ameloadj('2redundanceflappervalvetestAPP', jacfileIndex)
wrange = 2*scipy.pi*scipy.logspace(-1,2,400)
# uindex is the index of the control variable (Note that the indexes start at 0)
uindex = 0
# yindex is the index of the observer variable (Note that the indexes start at 0)
yindex = 0
# Compute bode using scipy
sys_a = scipy.matrix(A)
sys_b = scipy.zeros((len(B[0]), 1))
for k in range(len(B[0])):
sys_b[k, 0] = B[0][k][uindex]
sys_c = scipy.matrix(C[yindex])
sys_d = D[0][yindex][uindex]
system = scipy.signal.lti(sys_a, sys_b, sys_c, sys_d)
wout, y = scipy.signal.freqresp(system, [w for w in wrange if w]) # eliminate w = 0 values
mag = abs(y)
phase = scipy.unwrap(scipy.arctan2(y.imag, y.real)) * 180.0 / scipy.pi
freq_range = wout / (2 * scipy.pi)
mag_dB = 20 * scipy.log10(mag)
# Create 2 graphs on the plot window
plot.setRowCount(2)
# Creation of the Bode graph (Magnitude)
x_item = amepyplot.Item(freq_range, 'Frequency', 'Hz')
y_item = amepyplot.Item(mag_dB, 'Gain', 'dB')
ampl_curve = amepyplot.Curve2D(x_item, y_item, title='Amplitude of frequency response')
ampl_graph = plot.getGraph(0, 0)
ampl_graph.addCurve(ampl_curve)
ampl_graph.xAxis().setLogScale(True)
# Creation of the Bode graph (Phase)
y_item = amepyplot.Item(phase, 'Phase', 'deg')
phase_curve = amepyplot.Curve2D(x_item, y_item, title='Phase of frequency response')
phase_graph = plot.getGraph(1, 0)
phase_graph.addCurve(phase_curve)
phase_graph.xAxis().setLogScale(True)
plot.setWindowTitle('Bode plot at t = {} s'.format(times[jacfileIndex]))
plot.resize(500, 400)
plot.show()
app.exec_()
下面是报错问题:
numpy.linalg.linalg.LinAlgError: Array must not contain infs or NaNs

个人感觉是这两行代码的问题:
system = scipy.signal.lti(sys_a, sys_b, sys_c, sys_d)
wout, y = scipy.signal.freqresp(system, [w for w in wrange if w]) # eliminate w = 0 values
困扰好久了希望能得到解答,万分感谢。