Esempio n. 1
0
 def test_freq_range(self):
     # Test that freqresp() finds a reasonable frequency range.
     # 1st order low-pass filter: H(s) = 1 / (s + 1)
     # Expected range is from 0.01 to 10.
     system = lti([1], [1, 1])
     n = 10
     expected_w = np.logspace(-2, 1, n)
     w, H = freqresp(system, n=n)
     assert_almost_equal(w, expected_w)
Esempio n. 2
0
 def test_freq_range(self):
     # Test that freqresp() finds a reasonable frequency range.
     # 1st order low-pass filter: H(s) = 1 / (s + 1)
     # Expected range is from 0.01 to 10.
     system = lti([1], [1, 1])
     n = 10
     expected_w = np.logspace(-2, 1, n)
     w, H = freqresp(system, n=n)
     assert_almost_equal(w, expected_w)
Esempio n. 3
0
 def test_imag_part(self):
     # Test freqresp() imaginary part calculation.
     # 1st order low-pass filter: H(s) = 1 / (s + 1)
     system = lti([1], [1, 1])
     w = [0.1, 1, 10, 100]
     w, H = freqresp(system, w=w)
     jw = w * 1j
     y = np.polyval(system.num, jw) / np.polyval(system.den, jw)
     expected_im = y.imag
     assert_almost_equal(H.imag, expected_im)
Esempio n. 4
0
 def test_imag_part(self):
     # Test freqresp() imaginary part calculation.
     # 1st order low-pass filter: H(s) = 1 / (s + 1)
     system = lti([1], [1, 1])
     w = [0.1, 1, 10, 100]
     w, H = freqresp(system, w=w)
     jw = w * 1j
     y = np.polyval(system.num, jw) / np.polyval(system.den, jw)
     expected_im = y.imag
     assert_almost_equal(H.imag, expected_im)
Esempio n. 5
0
 def test_imag_part_manual(self):
     # Test freqresp() imaginary part calculation (manual sanity check).
     # 1st order low-pass filter: H(s) = 1 / (s + 1),
     #   im(H(s=0.1)) ~= -0.099
     #   im(H(s=1)) ~= -0.5
     #   im(H(s=10)) ~= -0.099
     system = lti([1], [1, 1])
     w = [0.1, 1, 10]
     w, H = freqresp(system, w=w)
     expected_im = [-0.099, -0.5, -0.099]
     assert_almost_equal(H.imag, expected_im, decimal=1)
Esempio n. 6
0
 def test_real_part_manual(self):
     # Test freqresp() real part calculation (manual sanity check).
     # 1st order low-pass filter: H(s) = 1 / (s + 1),
     #   re(H(s=0.1)) ~= 0.99
     #   re(H(s=1)) ~= 0.5
     #   re(H(s=10)) ~= 0.0099
     system = lti([1], [1, 1])
     w = [0.1, 1, 10]
     w, H = freqresp(system, w=w)
     expected_re = [0.99, 0.5, 0.0099]
     assert_almost_equal(H.real, expected_re, decimal=1)
Esempio n. 7
0
 def test_imag_part_manual(self):
     # Test freqresp() imaginary part calculation (manual sanity check).
     # 1st order low-pass filter: H(s) = 1 / (s + 1),
     #   im(H(s=0.1)) ~= -0.099
     #   im(H(s=1)) ~= -0.5
     #   im(H(s=10)) ~= -0.099
     system = lti([1], [1, 1])
     w = [0.1, 1, 10]
     w, H = freqresp(system, w=w)
     expected_im = [-0.099, -0.5, -0.099]
     assert_almost_equal(H.imag, expected_im, decimal=1)
Esempio n. 8
0
 def test_real_part_manual(self):
     # Test freqresp() real part calculation (manual sanity check).
     # 1st order low-pass filter: H(s) = 1 / (s + 1),
     #   re(H(s=0.1)) ~= 0.99
     #   re(H(s=1)) ~= 0.5
     #   re(H(s=10)) ~= 0.0099
     system = lti([1], [1, 1])
     w = [0.1, 1, 10]
     w, H = freqresp(system, w=w)
     expected_re = [0.99, 0.5, 0.0099]
     assert_almost_equal(H.real, expected_re, decimal=1)
Esempio n. 9
0
 def test_freq_range(self):
     # Test that freqresp() finds a reasonable frequency range.
     # 1st order low-pass filter: H(s) = 1 / (s + 1)
     # Expected range is from 0.01 to 10.
     system = lti([1], [1, 1])
     vals = linalg.eigvals(system.A)
     minpole = min(abs(np.real(vals)))
     maxpole = max(abs(np.real(vals)))
     n = 10
     expected_w = np.logspace(-2, 1, n)
     w, H = freqresp(system, n=n)
     assert_almost_equal(w, expected_w)
Esempio n. 10
0
 def test_freq_range(self):
     # Test that freqresp() finds a reasonable frequency range.
     # 1st order low-pass filter: H(s) = 1 / (s + 1)
     # Expected range is from 0.01 to 10.
     system = lti([1], [1, 1])
     vals = linalg.eigvals(system.A)
     minpole = min(abs(np.real(vals)))
     maxpole = max(abs(np.real(vals)))
     n = 10
     expected_w = np.logspace(-2, 1, n)
     w, H = freqresp(system, n=n)
     assert_almost_equal(w, expected_w)
Esempio n. 11
0
 def test_from_state_space(self):
     # Ensure that freqresp works with a system that was created from the
     # state space representation matrices A, B, C, D.  In this case,
     # system.num will be a 2-D array with shape (1, n+1), where (n,n) is
     # the shape of A.
     # A Butterworth lowpass filter is used, so we know the exact
     # frequency response.
     a = np.array([1.0, 2.0, 2.0, 1.0])
     A = linalg.companion(a).T
     B = np.array([[0.0], [0.0], [1.0]])
     C = np.array([[1.0, 0.0, 0.0]])
     D = np.array([[0.0]])
     with warnings.catch_warnings():
         warnings.simplefilter("ignore", BadCoefficients)
         system = lti(A, B, C, D)
     w, H = freqresp(system, n=100)
     expected_magnitude = np.sqrt(1.0 / (1.0 + w**6))
     assert_almost_equal(np.abs(H), expected_magnitude)
Esempio n. 12
0
 def test_from_state_space(self):
     # Ensure that freqresp works with a system that was created from the
     # state space representation matrices A, B, C, D.  In this case,
     # system.num will be a 2-D array with shape (1, n+1), where (n,n) is
     # the shape of A.
     # A Butterworth lowpass filter is used, so we know the exact
     # frequency response.
     a = np.array([1.0, 2.0, 2.0, 1.0])
     A = linalg.companion(a).T
     B = np.array([[0.0],[0.0],[1.0]])
     C = np.array([[1.0, 0.0, 0.0]])
     D = np.array([[0.0]])
     with warnings.catch_warnings():
         warnings.simplefilter("ignore", BadCoefficients)
         system = lti(A, B, C, D)
         w, H = freqresp(system, n=100)
     expected_magnitude = np.sqrt(1.0 / (1.0 + w**6))
     assert_almost_equal(np.abs(H), expected_magnitude)
Esempio n. 13
0
 def test_pole_zero(self):
     # Test that freqresp() doesn't fail on a system with a pole at 0.
     # integrator, pole at zero: H(s) = 1 / s
     system = lti([1], [1, 0])
     w, H = freqresp(system, n=2)
     assert_equal(w[0], 0.01)  # a fail would give not-a-number
Esempio n. 14
0
 def test_pole_zero(self):
     # Test that freqresp() doesn't fail on a system with a pole at 0.
     # integrator, pole at zero: H(s) = 1 / s
     system = lti([1], [1, 0])
     w, H = freqresp(system, n=2)
     assert_equal(w[0], 0.01)  # a fail would give not-a-number