def test_alpha(Simulator, plt): dt = 1e-3 tau = 0.03 b, a = [0.00054336, 0.00053142], [1, -1.9344322, 0.93550699] # ^^^ these coefficients found for tau=0.03 and dt=1e-3 # scipy.signal.cont2discrete(([1], [tau**2, 2*tau, 1]), dt) # b = [0.00054336283526056767, 0.00053142123234546667] # a = [1, -1.9344322009640118, 0.93550698503161778] # ^^^ these coefficients found by the exact algorithm used in Builder t, x, yhat = run_synapse(Simulator, nengo.synapses.Alpha(tau), dt=dt) y = lti(x, (b, a)) assert allclose(t, y, yhat, delay=dt, atol=5e-6, plt=plt)
def test_lti_lowpass(): dt = 1e-3 tend = 3. t = dt * np.arange(tend / dt) nt = len(t) tau = 1e-2 d = -np.expm1(-dt / tau) a = [d] b = [1, d - 1] u = np.random.normal(size=(nt, 10)) x = filt(u, tau / dt) y = lti(u, (a, b)) assert np.allclose(x, y)
def test_general(Simulator, plt): import scipy.signal dt = 1e-3 order = 4 tau = 0.03 num, den = scipy.signal.butter(order, 1. / tau, analog=True) num, den = num.real, den.real numi, deni, dt = scipy.signal.cont2discrete((num, den), dt) t, x, yhat = run_synapse( Simulator, nengo.synapses.LinearFilter(num, den), dt=dt) y = lti(x, (numi, deni)) assert allclose(t, y, yhat, plt=plt)
def test_general(Simulator): import scipy.signal dt = 1e-3 order = 4 tau = 0.03 num, den = scipy.signal.butter(order, 1. / tau, analog=True) num, den = num.real, den.real numi, deni, dt = scipy.signal.cont2discrete((num, den), dt) t, x, yhat = run_synapse(Simulator, nengo.synapses.LinearFilter(num, den), dt=dt) y = lti(x, (numi, deni)) assert allclose(t, y.flatten(), yhat.flatten(), plotter=Plotter(Simulator), filename='test_synapse.test_general.pdf')
def test_alpha(Simulator): dt = 1e-3 tau = 0.03 b, a = [0.00054336, 0.00053142], [1, -1.9344322, 0.93550699] # ^^^ these coefficients found for tau=0.03 and dt=1e-3 # scipy.signal.cont2discrete(([1], [tau**2, 2*tau, 1]), dt) # b = [0.00054336283526056767, 0.00053142123234546667] # a = [1, -1.9344322009640118, 0.93550698503161778] # ^^^ these coefficients found by the exact algorithm used in Builder t, x, yhat = run_synapse(Simulator, nengo.synapses.Alpha(tau), dt=dt) y = lti(x, (b, a)) assert allclose(t, y.flatten(), yhat.flatten(), delay=1, atol=5e-6, plotter=Plotter(Simulator), filename='test_synapse.test_alpha.pdf')