forked from python-control/python-control
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfreqresp_test.py
More file actions
69 lines (55 loc) · 1.77 KB
/
Copy pathfreqresp_test.py
File metadata and controls
69 lines (55 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
#
# freqresp_test.py - test frequency response functions
# RMM, 30 May 2016 (based on timeresp_test.py)
#
# This is a rudimentary set of tests for frequency response functions,
# including bode plots.
import unittest
import numpy as np
from control.statesp import StateSpace
from control.matlab import ss, tf, bode
from control.exception import slycot_check
import matplotlib.pyplot as plt
class TestFreqresp(unittest.TestCase):
def setUp(self):
self.A = np.matrix('1,1;0,1')
self.C = np.matrix('1,0')
self.omega = np.linspace(10e-2,10e2,1000)
def test_siso(self):
B = np.matrix('0;1')
D = 0
sys = StateSpace(self.A,B,self.C,D)
# test frequency response
frq=sys.freqresp(self.omega)
# test bode plot
bode(sys)
# Convert to transfer function and test bode
systf = tf(sys)
bode(systf)
def test_doubleint(self):
# 30 May 2016, RMM: added to replicate typecast bug in freqresp.py
A = np.matrix('0, 1; 0, 0');
B = np.matrix('0; 1');
C = np.matrix('1, 0');
D = 0;
sys = ss(A, B, C, D);
bode(sys);
@unittest.skipIf(not slycot_check(), "slycot not installed")
def test_mimo(self):
# MIMO
B = np.matrix('1,0;0,1')
D = np.matrix('0,0')
sysMIMO = ss(self.A,B,self.C,D)
frqMIMO = sysMIMO.freqresp(self.omega)
tfMIMO = tf(sysMIMO)
#bode(sysMIMO) # - should throw not implemented exception
#bode(tfMIMO) # - should throw not implemented exception
#plt.figure(3)
#plt.semilogx(self.omega,20*np.log10(np.squeeze(frq[0])))
#plt.figure(4)
#bode(sysMIMO,self.omega)
def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestTimeresp)
if __name__ == '__main__':
unittest.main()