Exemple #1
0
    # In[Plot]
    plt.figure()
    plt.plot(t, y_meas, 'k', label="$y$")
    plt.plot(t, y_hat, 'b', label="$\hat y$")
    plt.plot(t, y_meas - y_hat, 'r', label="$e$")
    plt.grid(True)
    plt.xlabel('Time (s)')
    plt.ylabel('Voltage (V)')
    plt.legend(loc='upper right')
    #    plt.savefig('WH_fit.pdf')
    plt.show()

    # In[Inspect linear model]

    n_imp = 128
    G1_num, G1_den = G1.get_tfdata()
    G1_sys = control.TransferFunction(G1_num, G1_den, ts)
    plt.figure()
    plt.title("$G_1$ impulse response")
    _, y_imp = control.impulse_response(G1_sys, np.arange(n_imp) * ts)
    #    plt.plot(G1_num)
    plt.plot(y_imp)
    #    plt.savefig(os.path.join("models", model_name, "G1_imp.pdf"))
    plt.show()
    plt.figure()
    mag_G1, phase_G1, omega_G1 = control.bode(G1_sys, omega_limits=[1e2, 1e5])
    plt.suptitle("$G_1$ bode plot")
    #    plt.savefig(os.path.join("models", model_name, "G1_bode.pdf"))
    plt.show()

    # G2_b = G2.G.weight.detach().numpy()[0, 0, ::-1]
    with torch.no_grad():
        out_nl = F_nl(torch.as_tensor(in_nl))

    plt.figure()
    plt.plot(in_nl, out_nl, 'b')
    plt.plot(in_nl, out_nl, 'b')
    #plt.plot(y1_lin, y1_nl, 'b*')
    plt.xlabel('Static non-linearity input (-)')
    plt.ylabel('Static non-linearity input (-)')
    plt.grid(True)
    plt.show()

    # In[Plot]

    # Inspect process noise blocks
    n_imp = 128
    H_inv_num, H_inv_den = H_inv.get_tfdata()
    H_inv_sys = 1 + control.TransferFunction(H_inv_num, H_inv_den, ts)
    H_sys = 1 / H_inv_sys

    plt.figure()
    mag_H, phase_H, omega_H = control.bode(H_sys, omega_limits=[1e1, 1e5])
    plt.suptitle("$H_inv$ bode plot")
    #    plt.savefig(os.path.join("models", model_name, "G1_bode.pdf"))

    # In[]
    control.bode(H_sys)
    control.bode(Hud * 1000)
    plt.show()