コード例 #1
0
 def testEvalfr_mimo(self, mimo):
     """Test evalfr() MIMO"""
     fr = evalfr(mimo.ss1, 1j)
     ref = np.array([[44.8 - 21.4j, 0.], [0., 44.8 - 21.4j]])
     np.testing.assert_array_almost_equal(fr, ref)
コード例 #2
0
s1 = signal.lti([1, 2], [1, 12, 47, 60, 0])

#signal.bode takes transfer function as input and returns frequency,magnitude and phase arrays
w, mag, phase = signal.bode(s1)

#Finding frequency at which phase =-140 degree
#Can't be done using builtin Wgc function since K is unknown
#Using interpolation
s = ml.tf('s')
freq_as_fn_of_w = interp1d(phase, w)
Wgc = freq_as_fn_of_w(-140)

#Evaluating Gain of T(s) at Wgc of G(s)
gain_at_Wgc = 20 * log10(
    abs(
        ml.evalfr(((s + 2) /
                   (s**4 + 12 * s**3 + 47 * s**2 + 60 * s)), complex(0, Wgc))))

plt.subplot(2, 1, 1)
plt.semilogx(w, mag, 'b', label='_nolegend_')  # Bode Magnitude plot
plt.plot(Wgc, gain_at_Wgc, 'o', label='_nolegend_')
plt.xlabel('Frequency(rad/s)')
plt.ylabel('Mag')
plt.axhline(y=0, xmin=0, xmax=1, color='b', linestyle='dashed')
plt.text(1, -70, '({}, {})'.format(Wgc.round(2), round(gain_at_Wgc, 2)))
plt.axvline(x=Wgc, ymin=0.60, ymax=0.88, color='k')
plt.text(Wgc + 0.5, -25, 'len=20log(K)')  #len = length of black line
plt.legend(['0 dB line'], loc='lower left')
plt.grid()

plt.subplot(2, 1, 2)
plt.semilogx(w, phase, label='_nolegend_')  #Bode phase plot
コード例 #3
0
 def testEvalfr(self, siso):
     """Call evalfr()"""
     w = 1j
     np.testing.assert_almost_equal(evalfr(siso.ss1, w), 44.8 - 21.4j)
     evalfr(siso.ss2, w)
     evalfr(siso.ss3, w)
     evalfr(siso.tf1, w)
     evalfr(siso.tf2, w)
     evalfr(siso.tf3, w)