Ejemplo n.º 1
0
def generate_test_sync_samples(M, K, L, alpha, cp_len, ramp_len, snr_dB, test_cfo, init_phase=0.0, ref_data=False):
    block_len = M * K
    data = get_random_qpsk(block_len, seed=generate_seed('awesomepayloadblabla'))
    print 'QPSK source energy: ', calculate_average_signal_energy(data)
    x = get_gfdm_frame(data, alpha, M, K, L, cp_len, ramp_len)

    pn_symbols = get_random_qpsk(K, seed=generate_seed('awesome'))
    preamble, x_preamble = generate_sync_symbol(pn_symbols, 'rrc', alpha, K, L, cp_len, ramp_len)
    print 'frame energy:', calculate_average_signal_energy(x), 'preamble energy:', calculate_average_signal_energy(preamble)

    frame = np.concatenate((preamble, x))
    print 'tx frame len', len(frame), 'len(preamble)', len(preamble)

    # simulate Noise and frequency offset!
    phase_inc = cfo_to_phase_increment(test_cfo, K)
    print 'phase_increment: ', phase_inc
    wave = complex_sine(phase_inc, len(frame), init_phase)
    # phase_shift = np.repeat(np.exp(1j * init_phase), len(frame))
    # wave *= phase_shift
    frame *= wave
    noise_variance = calculate_awgn_noise_variance(frame, snr_dB)
    s = get_complex_noise_vector(2 * block_len + len(frame), noise_variance)
    s[block_len:block_len + len(frame)] += frame
    if ref_data:
        return s, x_preamble, pn_symbols, data
    return s, x_preamble, pn_symbols
Ejemplo n.º 2
0
def main():
    np.set_printoptions(precision=4, suppress=True)
    # preamble_auto_corr_test()
    sync_test()
    return
    # cfo = 1.024e-5
    samp_rate = 12.5e6
    freq = 20.
    fft_len = 256
    sc_bw = samp_rate / fft_len
    cfo = freq_to_cfo(freq, fft_len, samp_rate)
    ph_i = cfo_to_phase_increment(cfo, fft_len)
    phase_inc = phase_increment(freq, samp_rate)
    print 'samp_rate: {}, frequency: {}, fft_len: {}'.format(
        samp_rate, freq, fft_len)
    print 'subcarrier bandwidth: {}, cfo: {}, phase increment: {}/{}'.format(
        sc_bw, cfo, ph_i, phase_inc)

    # wave = get_complex_sine(freq, samp_rate, 129)
    # s = np.ones(129)
    # s = correct_frequency_offset(s, cfo, fft_len)
    # # print wave
    # print np.abs(wave - s)

    preamble, x_preamble = generate_sync_symbol(
        get_random_qpsk(fft_len, seed=generate_seed('awesome')), 'rrc', .5,
        fft_len, 2, fft_len // 2, fft_len // 8)

    init_phase = 0.8
    wave = complex_sine(cfo_to_phase_increment(cfo, fft_len), len(preamble))
    # phase_shift = np.repeat(, len(preamble))
    wave *= np.exp(1j * init_phase)
    preamble *= wave

    print phase_inc

    ac = auto_correlate_halfs(preamble[64:64 + 2 * fft_len])
    fp = np.angle(ac)
    ac_phase_inc = fp / fft_len
    print 'auto corr phase: {}, AC phase {}, phase_inc: {}'.format(
        phase_inc, fp, ac_phase_inc)

    xc = cross_correlate_signal(preamble, x_preamble)
    ap = np.angle(xc[64])
    # print ap, (ap - init_phase) / (cfo * 2 * np.pi)

    residual = ap - init_phase
    res_phase = residual / (2 * fft_len)
    print residual, res_phase, phase_inc / res_phase
    # print fp, fp / (2 * np.pi)
    # print (ap - init_phase) - fp

    plt.plot(np.abs(xc) / 10000.)
    plt.plot(np.angle(xc))
    plt.show()
Ejemplo n.º 3
0
def main():
    import matplotlib.pyplot as plt
    np.set_printoptions(precision=4, suppress=True)
    # preamble_auto_corr_test()
    sync_test()
    return
    # cfo = 1.024e-5
    samp_rate = 12.5e6
    freq = 20.
    fft_len = 256
    sc_bw = samp_rate / fft_len
    cfo = freq_to_cfo(freq, fft_len, samp_rate)
    ph_i = cfo_to_phase_increment(cfo, fft_len)
    phase_inc = phase_increment(freq, samp_rate)
    print 'samp_rate: {}, frequency: {}, fft_len: {}'.format(samp_rate, freq, fft_len)
    print 'subcarrier bandwidth: {}, cfo: {}, phase increment: {}/{}'.format(sc_bw, cfo, ph_i, phase_inc)


    # wave = get_complex_sine(freq, samp_rate, 129)
    # s = np.ones(129)
    # s = correct_frequency_offset(s, cfo, fft_len)
    # # print wave
    # print np.abs(wave - s)

    preamble, x_preamble = generate_sync_symbol(get_random_qpsk(fft_len, seed=generate_seed('awesome')), 'rrc', .5, fft_len, 2, fft_len // 2, fft_len // 8)

    init_phase = 0.8
    wave = complex_sine(cfo_to_phase_increment(cfo, fft_len), len(preamble))
    # phase_shift = np.repeat(, len(preamble))
    wave *= np.exp(1j * init_phase)
    preamble *= wave

    print phase_inc

    ac = auto_correlate_halfs(preamble[64:64 + 2 * fft_len])
    fp = np.angle(ac)
    ac_phase_inc = fp / fft_len
    print 'auto corr phase: {}, AC phase {}, phase_inc: {}'.format(phase_inc, fp, ac_phase_inc)

    xc = cross_correlate_signal(preamble, x_preamble)
    ap = np.angle(xc[64])
    # print ap, (ap - init_phase) / (cfo * 2 * np.pi)

    residual = ap - init_phase
    res_phase = residual / (2 * fft_len)
    print residual, res_phase, phase_inc / res_phase
    # print fp, fp / (2 * np.pi)
    # print (ap - init_phase) - fp

    plt.plot(np.abs(xc) / 10000.)
    plt.plot(np.angle(xc))
    plt.show()
Ejemplo n.º 4
0
def preamble_auto_corr_test():
    K = 32
    pn_seq = get_random_qpsk(K)
    pn_symbols = np.tile(pn_seq, 2)
    D = get_data_matrix(pn_symbols, K, True)
    # print np.shape(D)
    print 'subcarriers bear same symbols:', np.all(D[0] == D[1])

    pl, p = generate_sync_symbol(pn_seq, 'rrc', .5, K, 2, K, K / 2)
    # print np.shape(p)
    acc = auto_correlate_halfs(p)
    print acc, np.angle(acc)

    taps = gfdm_filter_taps('rrc', .5, 2, K, 1)
    A = gfdm_modulation_matrix(taps, 2, K)
    x = A.dot(pn_symbols)
    # print np.shape(x)
    acc = auto_correlate_halfs(x)
    print acc, np.angle(acc)
Ejemplo n.º 5
0
def preamble_auto_corr_test():
    K = 32
    pn_seq = get_random_qpsk(K)
    pn_symbols = np.tile(pn_seq, 2)
    D = get_data_matrix(pn_symbols, K, True)
    # print np.shape(D)
    print 'subcarriers bear same symbols:', np.all(D[0] == D[1])

    pl, p = generate_sync_symbol(pn_seq, 'rrc', .5, K, 2, K, K / 2)
    # print np.shape(p)
    acc = auto_correlate_halfs(p)
    print acc, np.angle(acc)

    taps = gfdm_filter_taps('rrc', .5, 2, K, 1)
    A = gfdm_modulation_matrix(taps, 2, K)
    x = A.dot(pn_symbols)
    # print np.shape(x)
    acc = auto_correlate_halfs(x)
    print acc, np.angle(acc)
Ejemplo n.º 6
0
def generate_test_sync_samples(M, K, L, alpha, cp_len, ramp_len, snr_dB,
                               test_cfo):
    block_len = M * K
    data = get_random_qpsk(block_len,
                           seed=generate_seed('awesomepayloadblabla'))
    x = get_gfdm_frame(data, alpha, M, K, L, cp_len, ramp_len)

    preamble, x_preamble = generate_sync_symbol(
        get_random_qpsk(K, seed=generate_seed('awesome')), 'rrc', alpha, K, L,
        cp_len, ramp_len)
    print 'frame energy:', calculate_average_signal_energy(
        x), 'preamble energy:', calculate_average_signal_energy(preamble)
    preamble *= np.sqrt(
        calculate_average_signal_energy(x) /
        calculate_average_signal_energy(preamble))

    frame = np.concatenate((preamble, x))

    # simulate Noise and frequency offset!
    frame = correct_frequency_offset(frame, test_cfo / (-2. * K))
    noise_variance = calculate_awgn_noise_variance(frame, snr_dB)
    s = get_complex_noise_vector(2 * block_len + len(frame), noise_variance)
    s[block_len:block_len + len(frame)] += frame
    return s, x_preamble