예제 #1
0
def std_distance(snr_db, tau=None, width_spec=None, tau_disc_fcm=None, mode='nonmod',
                 K=0.6):
    """(27-29)

    Args:
        snr_db: in dB
        tau: in seconds
        width_spec: in Hz
        tau_disc_fcm: in seconds
        mode ('nonmod', 'lfm', 'fcm'): Default nonmode
        K:

    Returns:

    """
    snr_pow = db2pow(snr_db)
    sigma = None
    if mode == 'nonmod':
        if tau is not None:
            sigma = K * scc.c * tau / np.sqrt(snr_pow)
    elif mode == 'lfm':
        if width_spec is not None:
            sigma = K * scc.c / width_spec / np.sqrt(snr_pow)
    elif mode == 'fcm':
        if tau_disc_fcm is not None:
            sigma = K * scc.c * tau_disc_fcm / np.sqrt(snr_pow)
    return sigma
예제 #2
0
def std_speed(snr_db=0, wavelength=None, tau=None, width_spec=None, T_lfm=None,
              mode='nonmod',
              K=0.6):
    """(27-29)

    Args:
        mode ('nonmod', 'lfm', 'fcm'): Default 'nonmode'
        snr_db: in dB
        wavelength: in m
        tau: in seconds
        width_spec: in Hz
        T_lfm: in seconds
        K:

    Returns:

    """
    snr_pow = db2pow(snr_db)
    sigma_speed = None
    if mode == 'nonmod' or mode == 'fcm':
        if tau is not None:
            sigma_speed = K * wavelength / tau / np.sqrt(snr_pow)
    elif mode == 'lfm':
        if width_spec is not None and T_lfm is not None:
            sigma_speed = np.sqrt(2) * K * scc.c / width_spec / np.sqrt(snr_pow) / T_lfm
    return sigma_speed
예제 #3
0
def test_main():
    H = [[1, 0, 1, 0, 1, 0, 1], [0, 1, 1, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1, 1]]
    #[1 0 0 0 0 0 0] [0 0 0 0 0 0 0]
    r = [
        -0.34808075, 1.26110584, 0.49168568, 0.29461952, 1.1177641, 0.92850077,
        1.25788416
    ]

    #sigma = 1
    sigma = bawgn.noise_sigma(db2pow(8), 4 / 7)
    print(sigma)

    cws = ml.all_codewords()

    max_iter = 5

    Ha = np.array(H)
    ra = np.array(r)

    # can be done once
    msg_store = bpa_init(H)

    c_hat = decode_bpa_awgn(msg_store, ra, Ha, sigma, max_iter, cws)

    print(c_hat)
    print(is_codeword(bawgn.demodulate_hard(ra), Ha))
    print(is_codeword(c_hat, Ha))
예제 #4
0
def simulate_bpa_awgn():
    #H = [[0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
    #     [0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0],
    #     [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],
    #     [0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0],
    #     [0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0],
    #     [0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1],
    #     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0],
    #     [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1],
    #     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0]]
    #n = 21
    #k = 12

    H = [[1, 0, 0, 1, 1, 0, 1], [0, 1, 0, 1, 0, 1, 1], [0, 0, 1, 0, 1, 1, 1]]
    n = 7
    k = 4
    Ha = np.array(H)
    n = Ha.shape[1]
    k = n - Ha.shape[0]

    # max number of iterations of iterative decoding session (per word!)
    max_iter = 10

    msg_store = bpa_init(H)
    #print(msg_store)

    # CW book
    cws = ml.all_codewords()

    # BCRJ trellis
    trellis = bcjr.build_trellis(Ha)

    # max runs of simulations (number of words to be transmitted)
    max_runs = 1e7
    snrDbs = np.arange(-2, 9)
    bers = np.zeros(len(snrDbs))
    i = 0
    for snrDb in snrDbs:
        snr = db2pow(snrDb)
        sigma = bawgn.noise_sigma(snr, k / n)

        #decode = lambda r : decode_bpa_awgn(msg_store, r, Ha, sigma, max_iter)
        #decode = lambda r : ml.decode_ml(cws, r)
        #decode = lambda r : decode_bpa_bec(msg_store, r, Ha, sigma, max_iter)
        decode = lambda r: decide_from_llrs(bcjr.decode(r, trellis, sigma))
        ber = simulate_transmission(n, n, max_runs, bawgn.modulate,
                                    bawgn.transmit(sigma), decode)

        bers[i] = ber
        i += 1
        print(snrDb, ber)
    # save to mat file for plotting purposes
    #scipy.io.savemat('ml_awgn_4', { 'ml_awgn_snrs_4' : snrDbs, 'ml_awgn_bers_4' : bers })
    #scipy.io.savemat('bpa_awgn_4', { 'bpa_awgn_snrs_4' : snrDbs, 'bpa_awgn_bers_4' : bers })
    #scipy.io.savemat('bpa_bec_2', { 'bpa_bec_snrs_2' : snrDbs, 'bpa_bec_bers_2' : bers })
    #scipy.io.savemat('bpa_awgn_h21', { 'bpa_awgn_snrs_h21' : snrDbs, 'bpa_awgn_bers_h21' : bers })
    scipy.io.savemat('bpa_awgn_bcjr_3', {
        'bpa_awgn_snrs_bcjr_3': snrDbs,
        'bpa_awgn_bers_bcjr_3': bers
    })
예제 #5
0
def real_potential_rls(pt, gain_db, wavelength, loss_db, p_min, F=1):
    """(6)

    Args:
        pt (float): Power in Watts
        gain_db (float): Faint in dB
        wavelength (float): in m
        loss_db (float): Loaa in dB
        F (float): norm DNA. def=1
        p_min: min power in Watts.

    Returns:
        Real potential in dB.
    """
    gain_pow = db2pow(gain_db)
    loss_pow = db2pow(loss_db)
    potential_tmp = pt * gain_pow * gain_pow * np.power(wavelength, 2) * loss_pow * F * F
    potential = potential_tmp / (np.power(4 * np.pi, 3) * p_min)
    return pow2db(potential)
예제 #6
0
def simulate_turbo_7_5():
    ## PCCC
    #trellis = build_5_7_trellis(True)
    #punc1 = odd_puncturer()
    #punc2 = even_puncturer()
    #rate = 1/2
    #punc1 = no_puncturer()
    #punc2 = no_puncturer()

    ## SCCC
    #trellis1 = build_acc_trellis()
    #trellis1 = build_7_1_trellis(False)
    #trellis1 = trellis_7_5_nonsys()
    trellis1 = build_7_5_trellis(True)
    #trellis1 = build_7_5_trellis(False) # rate-1 INNER ENCODER TRELLIS - NON-SYSTEMATIC
    trellis2 = build_7_5_trellis(True)  # rate-1/2 OUTER ENCODER TRELLIS - SYSTEMATIC
    #rate = 1
    #rate = 1 / 4
    rate = 1 / 2

    max_runs = 1e4
    max_iter = 8
    k = 1000
    #k = 128
    n = int(k / rate)

    #snrDbs = np.arange(2, 5)
    snrDbs = [0.5, 1, 1.5, 1.8, 2, 2.2, 2.5, 2.7, 3.0, 3.5]
    #snrDbs = [2.4]
    #snrDbs = [4,5,6,7,8,9]
    bers = np.zeros(len(snrDbs))
    fers = np.zeros(len(snrDbs))
    i = 0
    for snrDb in snrDbs:
        snr = db2pow(snrDb)
        sigma = bawgn.noise_sigma(snr, rate)

        #decode = lambda r : decide_from_llrs(decode_pccc_7_5(r, k, sigma, max_iter, trellis, punc1, punc2))
        decode = lambda r : decide_from_llrs(decode_sccc_7_5(r, k, sigma, max_iter, trellis1, trellis2))
        ber, fer = simulate_transmission(n, k, max_runs, bawgn.modulate, bawgn.transmit(sigma), decode)

        bers[i] = ber
        fers[i] = fer
        i += 1
        print(snrDb, ber, fer)

    # save to mat file for plotting purposes
    scipy.io.savemat('sccc_7_5_fancypunc', {
        'sccc_7_5_fancypunc_snrs' : snrDbs,
        'sccc_7_5_fancypunc_bers' : bers,
        'sccc_7_5_fancypunc_fers' : fers
        })
예제 #7
0
def radareqrange(potential_db, rcs, ro):
    """(3)Max distance.

    Args:
        potential_db (float): In dB
        rcs (float): In m^2
        ro (float): probability limit log(Pa)/log(Pd) ?????????? in dB??????

    Returns:

    """
    potential_rls_power = db2pow(potential_db)
    return np.power(potential_rls_power * rcs / ro, 0.25)
예제 #8
0
def probability_limit(potential_db, distance, rcs):
    """(20)
    
    Args:
        potential_db: in dB
        distance: in m
        rcs: in m^2

    Returns:

    """
    potential_pow = db2pow(potential_db)
    return potential_pow * rcs / np.power(distance, 4)
예제 #9
0
def std_angle(wavelength, aperture, alpha, snr_db, K=0.6):
    """(23, 24)

    Args:
        wavelength: in m
        aperture: in m
        alpha: in radian
        snr_db: in dB
        K:

    Returns:

    """
    beam_width = beam_width_by_aperture(wavelength, aperture, alpha, K)
    snr_pow = db2pow(snr_db)
    return beam_width / np.sqrt(snr_pow)
예제 #10
0
def main():
    max_runs = 100000
    snrDbs = np.arange(-2, 10)
    bers = np.zeros(len(snrDbs))
    i = 0
    for snrDb in snrDbs:
        snr = db2pow(snrDb)
        sigma = bawgn.noise_sigma(snr, 1)  # uncoded transmission
        n = 100
        ber = simulate_transmission(n, n, max_runs, bawgn.modulate,
                                    bawgn.transmit(sigma),
                                    bawgn.demodulate_hard)
        bers[i] = ber
        i += 1
        th = norm.sf(1 / sigma)
        print(snrDb, ber, th)
    # save to mat file for plotting purposes
    scipy.io.savemat('uncoded', {'uncsnrs': snrDbs, 'uncbers': bers})