示例#1
0
def test_seq(signal, N):

    snrindB_range = range(1, 11)
    itr = len(snrindB_range)
    ber = [None] * itr

    for n in range(0, itr):
        snrindB = snrindB_range[n]
        snr = 10.0**(snrindB / 10.0)
        # sigma^2 = N0/2
        noise_std = 1 / sqrt(2 * snr)

        noise_mean = 0
        no_errors = 0

        # ВЫПОЛНЯЕМ N испітаний по отправке сигнала размером bit_length
        for m in range(0, N):

            noise = generate_noise(noise_mean, noise_std, len(signal))
            rx_sig = received_sig(signal, noise)
            det_sig = detected_sig(rx_sig)
            no_errors += err(det_sig, signal)

        ber[n] = no_errors / (N * len(signal))

        print_info(snrindB, no_errors, ber[n])
    print(ber)
    plot.build_BER(snrindB_range, ber)
示例#2
0
def test_seq_symbol2(signal):

    snrindB_range = range(0, 10)
    itr = len(snrindB_range)
    ber = [None] * itr
    N = 20000

    sig = signal
    # cds = CDS(N)
    # sig = cds.table[5]

    for n in range(0, itr):
        snrindB = snrindB_range[n]
        # linear snr
        snr = 10.0**(snrindB / 10.0)
        noise_std = 1 / sqrt(2 * snr)
        noise_mean = 0
        no_errors = 0

        # Передаем cигнал побитово
        for m in range(0, N):
            # transported 4symbol(frame) of signal
            tx_sig = sig[(4 * m) % len(sig):(4 * (m + 1)) % len(sig)]

            noise = generate_noise(noise_mean, noise_std, len(tx_sig))
            # received symbol(applying noise to transported sig)
            rx_sig = received_sig(tx_sig, noise)
            # detecting signal
            # if rx_symbol >=0 then det_symbol = 1
            # else det_symbol = -1
            det_sig = detected_sig(rx_sig)

            # if detected symbols not the same as transmitted then +plus error
            no_errors = err(det_sig, tx_sig)

        ber[n] = no_errors / (N * len(tx_sig))

        print_info(snrindB, no_errors, ber[n])

    print(ber)
    plot.build_BER(snrindB_range, ber)
示例#3
0
def test_seq_symbol(signal, N):

    snrindB_range = range(1, 11)
    itr = len(snrindB_range)
    ber = [None] * itr

    sig = signal
    # cds = CDS(N)
    # sig = cds.table[5]

    for n in range(0, itr):
        snrindB = snrindB_range[n]
        # linear snr
        snr = 10.0**(snrindB / 10.0)
        noise_std = 1 / sqrt(2 * snr)
        noise_mean = 0
        no_errors = 0

        # Передаем cигнал побитово
        for m in range(0, N):
            # transported symbol of signal
            tx_symbol = sig[m % len(sig)]
            # generating noise
            noise = random.gauss(noise_mean, noise_std)
            # received symbol(applying noise to transported sig)
            rx_symbol = tx_symbol + noise
            # detecting signal
            # if rx_symbol >=0 then det_symbol = 1
            # else det_symbol = -1
            det_symbol = 2 * (rx_symbol >= 0) - 1

            # if detected symbols not the same as transmitted then +plus error
            no_errors += 1 * (tx_symbol != det_symbol)

        ber[n] = no_errors / N

        print_info(snrindB, no_errors, ber[n])

    print(ber)
    plot.build_BER(snrindB_range, ber)
示例#4
0
def test_agwn_analytical():
    f_zero = 1
    w_zero = 2 * math.pi * f_zero
    V = 1
    T = 1 / V
    Pw = 1
    k = 4

    N = 20
    M = 10000
    a = math.sqrt((8 / 5) * Pw)

    x = math.floor(np.random.randint(0, 2 ** k))
    print('X: ', x)

    x_high = math.floor(x / 2 ** 2)
    x_low = round(math.fmod(x, 2 ** 2))

    print('High: {0} Low: {1}'.format(x_high, x_low))

    s = lambda t: a * ((3 / 2) - x_high) * np.sin(w_zero * t) - a * ((3 / 2) - x_low) * np.cos(w_zero * t)

    p_sn = []

    for s_n in range(1, N):
        print(s_n)
        count = 0
        n_zero = 1 / s_n
        for i in range(0, M):
            r = np.random.normal(0, math.sqrt(n_zero / 4), 10)

            # fourier
            noise = lambda t: r[0] / 2 + np.sum(
                [r[2 * j - 1] * np.sin((2 * math.pi * j / 2 * T) * t) + r[2 * j] * np.cos((2 * math.pi * j / 2 * T) * t)
                 for j in range(0, 4)])

            # signal with noise
            st = lambda t: s(t) + noise(t)

            # demodulation
            function_alpha = lambda t: st(t) * np.sin(w_zero * t)
            alpha = quad(function_alpha, 0, 1)
            res_alpha = (2 / (T * a)) * alpha[0]

            function_beta = lambda t: st(t) * np.cos(w_zero * t)
            beta = quad(function_beta, 0, 1)
            res_beta = (2 / (T * a)) * beta[0]

            high_1 = round((3 / 2) - res_alpha)
            if high_1 < 0:
                high_1 = 0
            elif high_1 > (2 ** k) - 1:
                high_1 = (2 ** k) - 1
            else:
                high_1 = high_1

            low_1 = round((3 / 2) + res_beta)
            if low_1 < 0:
                low_1 = 0
            elif low_1 > (2 ** k) - 1:
                low_1 = (2 ** k) - 1
            else:
                low_1 = low_1

            x1 = high_1 * (2 ** 2) + low_1

            dif = diffrence(x, x1, k)
            # print(x,x1,dif)

            count += dif

        p_sn.append(count / (k * M))
        print_info(s_n, s_n, p_sn[s_n - 1])


    print(p_sn)

    snr_inDb = range(0,20)
    build_BER(snr_inDb,p_sn)
示例#5
0
            if high_1 < 0:
                high_1 = 0
            elif high_1>(2**k)-1:
                high_1 = (2**k)-1
            else:
                high_1 = high_1

            low_1 = round((3 / 2) + res_beta)
            if low_1 < 0:
                low_1 = 0
            elif low_1 > (2 ** k) - 1:
                low_1 = (2 ** k) - 1
            else:
                low_1 = low_1

            x1 = high_1*(2**2)+low_1


            dif = diffrence(x,x1,k)
            # print(x,x1,dif)

            count+=dif

        p_sn.append(count/(k*M))
        print_info(s_n, count, p_sn[s_n - 1])



    print(p_sn)

    build_BER(snr_in_db_range,p_sn)