Beispiel #1
0
def coupled_siw():
    s2p_file = './resource/two_SIW_antenna_39GHz_50mil.s2p'
    freq, n, z, s, z0 = vecfit.read_snp(s2p_file)
    s_z0 = np.zeros(z.shape, dtype=z.dtype)
    cs = freq * 2j * np.pi
    # z0 = 50
    z0 = 190
    for i in range(len(freq)):
        s_z0[:, :,
             i] = np.matrix(z[:, :, i] / z0 - np.identity(n)) * np.linalg.inv(
                 np.matrix(z[:, :, i] / z0 + np.identity(n)))

    s_model, bound = vecfit.mode_fitting(s_z0, cs, True)
    bound_error = s_model.bound_error(s_z0, cs, reflect=np.inf)
    ant_integral = vecfit.bound_integral(s_z0, cs, np.inf)
    print(
        'Bound is {:.5e}, Bound error is {:.5e}, The integral of the antenna is {:.5e}'
        .format(bound, bound_error, ant_integral))

    # plots
    axs = vecfit.plot_freq_resp_matrix(cs, s_z0, y_scale='db')
    s_model.plot(cs, axs=axs, y_scale='db', linestyle='--')
    vecfit.plot_freq_resp_matrix(cs,
                                 s_z0 - s_model.model(cs),
                                 axs=axs,
                                 y_scale='db',
                                 linestyle='--')
Beispiel #2
0
def coupled_dipole():
    s2p_file = './resource/coupled_dipoles.s2p'
    freq, n, z_data, s_data, z0_data = vecfit.read_snp(s2p_file)
    cs = freq * 2j * np.pi

    # Fit even and odd mode separately
    s_even = ((s_data[0, 0, :] + s_data[0, 1, :] + s_data[1, 0, :] +
               s_data[1, 1, :]) / 2).reshape(len(freq))
    s_odd = ((s_data[0, 0, :] - s_data[0, 1, :] - s_data[1, 0, :] +
              s_data[1, 1, :]) / 2).reshape(len(freq))
    # Even and odd mode
    # f_even = vecfit.fit_s(s_even, cs, n_pole=3, n_iter=20, s_inf=-1)
    # f_odd = vecfit.fit_s(s_odd, cs, n_pole=3, n_iter=20, s_inf=-1)
    # f_even = vecfit.bound_tightening(s_even, cs)
    # f_odd = vecfit.bound_tightening(s_odd, cs)
    f_even, log_even = vecfit.bound_tightening_sweep(s_even, cs, np.inf)
    f_odd, log_odd = vecfit.bound_tightening_sweep(s_odd, cs, np.inf)

    bound_even, bw_even = f_even.bound(np.inf, f0=2.4e9)
    bound_error_even = f_even.bound_error(s_even, cs, reflect=np.inf)
    bound_odd, bw_odd = f_odd.bound(np.inf, f0=2.4e9)
    bound_error_odd = f_odd.bound_error(s_odd, cs, reflect=np.inf)
    print('Manual even/odd mode decomposition:')
    print(
        'Even mode, # poles {}, bound {:.5e}, bound error {:.5e}, sum {:.5e}'.
        format(len(f_even.pole), bound_even, bound_error_even,
               bound_even + bound_error_even))
    print('Odd mode, # poles {}, bound {:.5e}, bound error {:.5e}, sum {:.5e}'.
          format(len(f_odd.pole), bound_odd, bound_error_odd,
                 bound_odd + bound_error_odd))
    fig = plt.figure(figsize=(8, 5.5))
    ax1 = fig.add_subplot(211)
    ax2 = fig.add_subplot(212)
    vecfit.plot_freq_resp(cs, s_even, ax=ax1, y_scale='db')
    f_even.plot(cs, ax=ax1, y_scale='db', linestyle='--')
    vecfit.plot_freq_resp(cs, s_odd, ax=ax2, y_scale='db')
    f_odd.plot(cs, ax=ax2, y_scale='db', linestyle='--')

    # Try to fit S
    # fixed_pole = np.concatenate([f_even.pole, f_odd.pole])
    # s_model = vecfit.matrix_fitting_rescale(s_data, cs, n_pole=6, n_iter=20, has_const=True, has_linear=False, fixed_pole=fixed_pole)
    # s_model = s_model.rank_one()
    # s_model = vecfit.matrix_fitting_rank_one_rescale(s_data, cs, n_pole=6, n_iter=50, has_const=True, has_linear=True)
    s_model, bound = vecfit.mode_fitting(s_data, cs, True)
    bound_error = s_model.bound_error(s_data, cs, reflect=np.inf)
    ant_integral = vecfit.bound_integral(s_data, cs, np.inf)
    print(
        'Bound is {:.5e}, Bound error is {:.5e}, The integral of the antenna is {:.5e}'
        .format(bound, bound_error, ant_integral))

    axs = vecfit.plot_freq_resp_matrix(cs, s_data, y_scale='db')
    s_model.plot(cs, axs=axs, y_scale='db', linestyle='--')
Beispiel #3
0
def four_ifa():
    snp_file = './resource/4Port_IFA_Free_Space.s4p'
    freq, n, z_data, s_data, z0_data = vecfit.read_snp(snp_file)
    cs = freq * 2j * np.pi

    # Fit modes separately
    s_matrix, bound = vecfit.mode_fitting(s_data, cs, True)
    bound_error = s_matrix.bound_error(s_data, cs, reflect=np.inf)
    ant_integral = vecfit.bound_integral(s_data, cs, np.inf)
    print(
        'Bound is {:.5e}, Bound error is {:.5e}, The integral of the antenna is {:.5e}'
        .format(bound, bound_error, ant_integral))

    # plot the s_matrix
    axs = vecfit.plot_freq_resp_matrix(cs, s_data, y_scale='db')
    s_matrix.plot(cs, axs=axs, y_scale='db', linestyle='--')
Beispiel #4
0
def example2():
    s_test = 1j * np.linspace(1, 1e5, 800)
    poles_test = [
        -4500, -41000, -100 + 5000j, -100 - 5000j, -120 + 15000j,
        -120 - 15000j, -3000 + 35000j, -3000 - 35000j, -200 + 45000j,
        -200 - 45000j, -1500 + 45000j, -1500 - 45000j, -500 + 70000j,
        -500 - 70000j, -1000 + 73000j, -1000 - 73000j, -2000 + 90000j,
        -2000 - 90000j
    ]
    tmp_list = [
        -3000, -83000, -5 + 7000j, -5 - 7000j, -20 + 18000j, -20 - 18000j,
        6000 + 45000j, 6000 - 45000j, 40 + 60000j, 40 - 60000j, 90 + 10000j,
        90 - 10000j, 50000 + 80000j, 50000 - 80000j, 1000 + 45000j,
        1000 - 45000j, -5000 + 92000j, -5000 - 92000j
    ]
    ndim = 2
    n_pole = len(poles_test)
    ns = len(s_test)

    residues_test = np.zeros([ndim, ndim, n_pole], dtype=np.complex128)
    for i, r in enumerate(tmp_list):
        residues_test[:, :, i] = r * np.array([[1, 0.5], [0.5, 1]])
    d_test = .2 * np.array([[1, -0.2], [-0.2, 1]])
    h_test = 5e-4 * np.array([[1, -0.5], [-0.5, 1]])

    f_in = vecfit.RationalMtx(poles_test, residues_test, d_test, h_test)
    f_test = f_in.model(s_test)

    # f_out = vecfit.matrix_fitting(f_test, s_test, n_pole=18, n_iter=20, has_const=True, has_linear=True)
    f_out = vecfit.matrix_fitting_rescale(
        f_test,
        s_test,
        n_pole=18,
        n_iter=10,
        has_const=True,
        has_linear=True,
        fixed_pole=[-1000, -5 + 6000j, -5 - 6000j])
    # f_out = f_out.rank_one()

    axs = vecfit.plot_freq_resp_matrix(s_test, f_test, y_scale='db')
    f_out.plot(s_test, axs, y_scale='db', linestyle='--')
    (f_out - f_in).plot(s_test, axs, y_scale='db', linestyle='--')
Beispiel #5
0
def skycross_antennas():
    snp_file = './resource/Skycross_4_parallel_fine2.s4p'
    freq, n, z_data, s_data, z0_data = vecfit.read_snp(snp_file)
    cs = freq * 2j * np.pi

    s_matrix, bound = vecfit.mode_fitting(s_data, cs, True)
    bound_error = s_matrix.bound_error(s_data, cs, reflect=np.inf)
    ant_integral = vecfit.bound_integral(s_data, cs, np.inf)
    print(
        'Bound is {:.5e}, Bound error is {:.5e}, The integral of the antenna is {:.5e}'
        .format(bound, bound_error, ant_integral))

    # plot per mode response
    # calculate the bound error
    s_fit = s_matrix.model(cs)
    s_error = s_fit - s_data

    u, sigma, vh = np.linalg.svd(np.moveaxis(s_error, -1, 0))
    sigma_error = sigma[:, 0].flatten()
    u, sigma, vh = np.linalg.svd(np.moveaxis(s_data, -1, 0))
    sigma_max = sigma[:, 0].flatten()
    sigma_min = sigma[:, -1].flatten()

    rho = (2 * sigma_error) / (
        1 - np.power(sigma_max, 2)) * np.sqrt(1 +
                                              (sigma_max**2 - sigma_min**2) /
                                              (1 - sigma_max)**2)

    tau = 0.3162278
    int_fct = vecfit.f_integral(
        cs.imag, 0) / 2 * np.log(1 + (1 - tau**2) / tau**2 * rho)
    delta_b = vecfit.num_integral(cs.imag, int_fct)
    print('Bound error is {:.2e}'.format(delta_b))

    int_fct = vecfit.f_integral(cs.imag, 0) * (1 - np.sum(sigma**2, 1) / n)
    unmatched_integral = vecfit.num_integral(cs.imag, int_fct)
    print('Unmatched integral is {:.2e}'.format(unmatched_integral))

    # plot the s_matrix
    axs = vecfit.plot_freq_resp_matrix(cs, s_data, y_scale='db')
    s_matrix.plot(cs, axs=axs, y_scale='db', linestyle='--')