Пример #1
0
def test_for_constant_signal():
    size = 1000
    Ts = 0.1
    coef = np.ones(size) * 0.7
    vector = np.array([1., 0, 0])
    inp = system.Input(Ts, coefficients=coef, steeringVector=vector)

    A = np.eye(3, k=-1)
    c = np.eye(3)

    sys = system.System(A, c)

    mixingMatrix = -1e1 * np.eye(3)

    ctrl = system.Control(mixingMatrix, size)

    sim = simulator.Simulator(sys, ctrl)
    t = np.linspace(0., 99., size)
    res = sim.simulate(t, (inp, ))
    plt.figure()
    plt.plot(res['t'], res['output'])
    plt.legend(["%s" % x for x in range(3)])

    recon = reconstruction.WienerFilter(t, sys, (inp, ))

    u_hat, log = recon.filter(ctrl)

    plt.figure()
    plt.plot(t, coef, label="u")
    plt.plot(t, u_hat, label="u_hat")
    plt.legend()
Пример #2
0
def testInputs():
    t = np.linspace(0, 100., 1000)
    coef = np.random.rand(1000)
    vector = np.array([1.])

    zeroOrderHold1 = system.Input(t[1] - t[0],
                                  coefficients=coef,
                                  steeringVector=vector)
    firstOrderHold1 = system.FirstOrderHold(t[1] - t[0],
                                            coefficients=coef,
                                            steeringVector=vector)
    error1 = np.linalg.norm(zeroOrderHold1.fun(t) - firstOrderHold1.fun(t))
    zeroOrderHold2 = system.Input(t[2] - t[0],
                                  coefficients=coef,
                                  steeringVector=vector)
    firstOrderHold2 = system.FirstOrderHold(t[2] - t[0],
                                            coefficients=coef,
                                            steeringVector=vector)
    error2 = np.linalg.norm(zeroOrderHold2.fun(t) - firstOrderHold2.fun(t))

    # Error2 should be larger since it has a larger step size
    assert (error2 > error1)
Пример #3
0
def test_integratorChain():
    size = 1000
    Ts = 0.1
    coef = np.ones(size)
    vector = np.array([1., 0, 0])
    inp = system.Input(Ts, coefficients=coef, steeringVector=vector)

    A = np.eye(3, k=-1)
    c = np.eye(3)

    sys = system.System(A, c)

    mixingMatrix = -1e1 * np.eye(3)

    ctrl = system.Control(mixingMatrix, size)

    sim = simulator.Simulator(sys, ctrl)
    t = np.linspace(0., 99., size)
    res = sim.simulate(t, (inp, ))
    plt.figure()
    plt.plot(res['t'], res['output'])
    plt.legend(["%s" % x for x in range(3)])
Пример #4
0
def testSystemSetup():
    size = 1000
    Ts = 0.1
    coef = np.random.rand(size)
    vector = np.array([1., 0, 0])
    inp = system.Input(Ts, coefficients=coef, steeringVector=vector)

    A = np.random.rand(3, 3)
    c = np.eye(3)

    sys = system.System(A, c)

    mixingMatrix = -np.eye(3)

    ctrl = system.Control(mixingMatrix, size)

    return {
        'size': size,
        'Ts': Ts,
        'inp': inp,
        'sys': sys,
        'ctrl': ctrl,
    }
Пример #5
0
def test_noisy_integratorChain():
    size = 1000
    Ts = 0.1
    order = 3
    coef = np.ones(size)
    vector = np.array([1., 0, 0])
    inp = system.Input(Ts, coefficients=coef, steeringVector=vector)

    A = np.eye(3, k=-1)
    c = np.eye(3)

    noiseVariance = np.ones(3) * 1e-4
    noiseSources = []
    for index in range(order):
        if noiseVariance[index] > 0:
            vector = np.zeros(order)
            vector[index] = 1
            noiseSources.append({
                "std": np.sqrt(noiseVariance[index]),
                "steeringVector": vector,
                "name": "Noise Source %s" % index
            })

    options = {'noise': noiseSources}

    sys = system.System(A, c)

    mixingMatrix = -1e1 * np.eye(3)

    ctrl = system.Control(mixingMatrix, size)

    sim = simulator.Simulator(sys, ctrl, options=options)
    t = np.linspace(0., 99., size)
    res = sim.simulate(t, (inp, ))
    plt.figure()
    plt.plot(res['t'], res['output'])
    plt.legend(["%s" % x for x in range(3)])
Пример #6
0
                }
            }

            mixingMatrix = -kappa * beta * np.eye(N)
            ctrl = system.Control(mixingMatrix, size)
            input_signal = system.Sin(Ts,
                                      amplitude=amplitude,
                                      frequency=frequency,
                                      phase=phase,
                                      steeringVector=input_vector)
            all_inputs = [input_signal]

            order = N
            jitterInputs = [
                system.Input(Ts=Ts,
                             coefficients=np.zeros(len(t)),
                             steeringVector=np.ones(N) * beta)
            ]
            for i in range(1):
                all_inputs.append(jitterInputs[i])

        elif RECONSTRUCTION_METHOD == 'AugmentedSSM':
            A_tmp1 = np.hstack((np.eye(N, k=-1) * beta, -np.eye(N)))
            A_tmp2 = np.hstack(
                (np.zeros((number_of_jitter_estimation_states, N)),
                 np.eye(N, k=-1) * beta))
            A = np.vstack((A_tmp1, A_tmp2))
            print(A)

            input_vector = np.zeros(N + number_of_jitter_estimation_states)
            input_vector[0] = beta