def test_nonzero_initial_time(self): system = self.lti_nowarn(-1.,1.,1.,0.) t = np.linspace(1,2) u = np.zeros_like(t) tout, y, x = lsim(system, u, t, X0=[1.0]) expected_y = np.exp(-tout) assert_almost_equal(y, expected_y)
def test_integrator(self): # integrator: y' = u system = self.lti_nowarn(0., 1., 1., 0.) t = np.linspace(0,5) u = t tout, y, x = lsim(system, u, t) expected_x = 0.5 * tout**2 assert_almost_equal(x, expected_x) assert_almost_equal(y, expected_x)
def test_first_order(self): # y' = -y # exact solution is y(t) = exp(-t) system = self.lti_nowarn(-1.,1.,1.,0.) t = np.linspace(0,5) u = np.zeros_like(t) tout, y, x = lsim(system, u, t, X0=[1.0]) expected_x = np.exp(-tout) assert_almost_equal(x, expected_x) assert_almost_equal(y, expected_x)
def test_double_integrator(self): # double integrator: y'' = 2u A = np.mat("0. 1.; 0. 0.") B = np.mat("0.; 1.") C = np.mat("2. 0.") system = self.lti_nowarn(A, B, C, 0.) t = np.linspace(0,5) u = np.ones_like(t) tout, y, x = lsim(system, u, t) expected_x = np.transpose(np.array([0.5 * tout**2, tout])) expected_y = tout**2 assert_almost_equal(x, expected_x) assert_almost_equal(y, expected_y)
def test_jordan_block(self): # Non-diagonalizable A matrix # x1' + x1 = x2 # x2' + x2 = u # y = x1 # Exact solution with u = 0 is y(t) = t exp(-t) A = np.mat("-1. 1.; 0. -1.") B = np.mat("0.; 1.") C = np.mat("1. 0.") system = self.lti_nowarn(A, B, C, 0.) t = np.linspace(0,5) u = np.zeros_like(t) tout, y, x = lsim(system, u, t, X0=[0.0, 1.0]) expected_y = tout * np.exp(-tout) assert_almost_equal(y, expected_y)
def test_miso(self): # A system with two state variables, two inputs, and one output. A = np.array([[-1.0, 0.0], [0.0, -2.0]]) B = np.array([[1.0, 0.0], [0.0, 1.0]]) C = np.array([1.0, 0.0]) D = np.zeros((1,2)) system = self.lti_nowarn(A, B, C, D) t = np.linspace(0, 5.0, 101) u = np.zeros_like(t) tout, y, x = lsim(system, u, t, X0=[1.0, 1.0]) expected_y = np.exp(-tout) expected_x0 = np.exp(-tout) expected_x1 = np.exp(-2.0*tout) assert_almost_equal(y, expected_y) assert_almost_equal(x[:,0], expected_x0) assert_almost_equal(x[:,1], expected_x1)
def sim(self, t, U=[]): """ Simulate the PLL with a input Parameters ---------- t : array_like Vector with the time U: array_like Input to the block with the same lenght of t, if a empty is given Return ------ out : array like response to U error : error """ if not len(U): U = np.ones_like(t) t, signal_out, X = lti.lsim(self.H, U=U, T=t) error_out = signal_out - U * self.Navg return signal_out, error_out
def sim(self, t, U = []): """ Simulate the PLL with a input Parameters ---------- t : array_like Vector with the time U: array_like Input to the block with the same lenght of t, if a empty is given Return ------ out : array like response to U error : error """ if not len(U): U = np.ones_like(t) t, signal_out, X = lti.lsim(self.H, U=U, T=t) error_out = signal_out - U * self.Navg return signal_out, error_out