import numpy as np import matplotlib.pyplot as plt N = 1000 # number of timesteps T = 50 # time will vary from 0 to T with step delt ts = np.linspace(0,T,N+1) delt = T/N gamma = .05 # damping, 0 is no damping A = np.zeros((2,2)) B = np.zeros((2,1)) C = np.zeros((1,2)) A[0,0] = 1 A[0,1] = (1-gamma*delt/2)*delt A[1,1] = 1 - gamma*delt B[0,0] = delt**2/2 B[1,0] = delt C[0,0] = 1 np.random.seed(30010) x = np.zeros((2,N+1)) x[:,0] = [0,0] y = np.zeros((1,N)) w = np.random.randn(1,N) n = np.random.randn(1,N) for t in range(N): y[:,t] = C.dot(x[:,t]) + n[:,t] x[:,t+1] = A.dot(x[:,t]) + B.dot(w[:,t]) x_true = x.copy() w_true = w.copy() n_true = n.copy() plt.figure(figsize=(8,6), dpi=100) plt.subplot(2,1,1) plt.plot(ts,x[0,:], linewidth=3, label='Position (ground-truth)') plt.plot(ts[:-1],y[0,:], '.', color='gray', linewidth=2, alpha=0.3, \ label='Position (measured)') plt.ylabel(r'$p$') plt.legend() plt.grid() plt.subplot(2,1,2) plt.plot(ts,x[1,:], linewidth=3, label='Velocity (ground-truth)') plt.xlabel('time') plt.ylabel(r'$v$') plt.legend() plt.grid() plt.show() plt.figure(figsize=(8,6), dpi=100) plt.subplot(2,1,1) plt.plot(ts[:-1],w_true[0,:], label='Wind force (ground-truth)') plt.ylabel(r"$w$") plt.legend() plt.grid() plt.subplot(2,1,2) plt.plot(ts[:-1],n_true[0,:], label='Sensor noise (ground-truth)') plt.xlabel('time') plt.ylabel(r'$n$') plt.legend() plt.grid() plt.show() # your code here import scipy.signal as sps bw_p = 2 bw_v = 0.2 lpf_p = sps.cont2discrete(([bw_p],[1.,bw_p]), delt, method='bilinear') lpf_v = sps.cont2discrete(([bw_v],[1.,bw_v]), delt, method='bilinear') print(lpf_p) print(lpf_v) # your code here # your code here # your code here