Exemplo 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
Exemplo n.º 2
0
def initialize_sync_algorithm(preamble, K):
    # initialization part
    if not len(preamble) == 2 * K:
        raise ValueError('Preamble length must be equal to 2K!')

    # normalize preamble, maybe it helps
    avg_preamble_ampl = np.sqrt(calculate_average_signal_energy(preamble))
    preamble /= avg_preamble_ampl
    if np.abs(calculate_average_signal_energy(preamble) - 1.0) > 1e-6:
        raise ValueError('preamble not properly normalized!')

    # print 'average preamble amplitude:', avg_preamble_ampl, 'normalized preamble:', calculate_average_signal_energy(preamble)
    return preamble
Exemplo n.º 3
0
def initialize_sync_algorithm(preamble, K):
    # initialization part
    if not len(preamble) == 2 * K:
        raise ValueError('Preamble length must be equal to 2K!')

    # normalize preamble, maybe it helps
    avg_preamble_ampl = np.sqrt(calculate_average_signal_energy(preamble))
    preamble /= avg_preamble_ampl
    if np.abs(calculate_average_signal_energy(preamble) - 1.0) > 1e-6:
        raise ValueError('preamble not properly normalized!')

    # print 'average preamble amplitude:', avg_preamble_ampl, 'normalized preamble:', calculate_average_signal_energy(preamble)
    return preamble
Exemplo n.º 4
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
Exemplo n.º 5
0
def main():
    '''
    This is a comparison for 3 different demodulation approaches.
    matched filter matrix being the 'benchmark'
    The other two should converge towards the matrix approach for overlap -> subcarriers
    Actually, there's a bug in the 'GR' approach, thus it only works for overlap==2
    '''
    timeslots = 25
    subcarriers = 16
    overlap = 2
    time_taps = gfdm_filter_taps('rrc', .5, timeslots, subcarriers, 1)
    freq_taps = gfdm_freq_taps(time_taps)
    sparse_freq_taps = gfdm_freq_taps_sparse(freq_taps, timeslots, overlap)
    A = gfdm_modulation_matrix(time_taps, timeslots, subcarriers, 1, True)
    Ainv = np.linalg.inv(A)
    Amf = np.conjugate(A).T

    tx_syms = get_random_qpsk(timeslots * subcarriers)
    rx_syms = A.dot(tx_syms)

    mf_matrix_rx = Amf.dot(rx_syms)
    inv_matrix_rx = Ainv.dot(rx_syms)
    gr_res = gfdm_demodulate_block(rx_syms, sparse_freq_taps, subcarriers,
                                   timeslots, overlap)
    fft_res = gfdm_demodulate_fft_loop(rx_syms, timeslots, subcarriers,
                                       overlap, sparse_freq_taps)

    mf_matrix_rx *= np.sqrt(
        calculate_average_signal_energy(fft_res) /
        calculate_average_signal_energy(mf_matrix_rx))
    inv_matrix_rx *= np.sqrt(
        calculate_average_signal_energy(fft_res) /
        calculate_average_signal_energy(inv_matrix_rx))
    gr_res *= np.sqrt(
        calculate_average_signal_energy(fft_res) /
        calculate_average_signal_energy(gr_res))

    print 'compare demodulation accuracy for different approaches'
    for e in range(11):
        em = 10**(-1. * e)
        matrixvsloop = np.all(np.abs(fft_res - mf_matrix_rx) < em)
        grvsmatrix = np.all(np.abs(gr_res - mf_matrix_rx) < em)
        grvsloop = np.all(np.abs(gr_res - fft_res) < em)
        print 'error margin {:.1e}\tMFmatriXvsGR: {}\tMFmatriXvsLoop: {}\tGRvsLoop: {}'.format(
            em, grvsmatrix, matrixvsloop, grvsloop)
Exemplo n.º 6
0
def main():
    '''
    This is a comparison for 3 different demodulation approaches.
    matched filter matrix being the 'benchmark'
    The other two should converge towards the matrix approach for overlap -> subcarriers
    Actually, there's a bug in the 'GR' approach, thus it only works for overlap==2
    '''
    timeslots = 25
    subcarriers = 16
    overlap = 2
    time_taps = gfdm_filter_taps('rrc', .5, timeslots, subcarriers, 1)
    freq_taps = gfdm_freq_taps(time_taps)
    sparse_freq_taps = gfdm_freq_taps_sparse(freq_taps, timeslots, overlap)
    A = gfdm_modulation_matrix(time_taps, timeslots, subcarriers, 1, True)
    Ainv = np.linalg.inv(A)
    Amf = np.conjugate(A).T

    tx_syms = get_random_qpsk(timeslots * subcarriers)
    rx_syms = A.dot(tx_syms)

    mf_matrix_rx = Amf.dot(rx_syms)
    inv_matrix_rx = Ainv.dot(rx_syms)
    gr_res = gfdm_demodulate_block(rx_syms, sparse_freq_taps, subcarriers, timeslots, overlap)
    fft_res = gfdm_demodulate_fft_loop(rx_syms, timeslots, subcarriers, overlap, sparse_freq_taps)

    mf_matrix_rx *= np.sqrt(calculate_average_signal_energy(fft_res) / calculate_average_signal_energy(mf_matrix_rx))
    inv_matrix_rx *= np.sqrt(calculate_average_signal_energy(fft_res) / calculate_average_signal_energy(inv_matrix_rx))
    gr_res *= np.sqrt(calculate_average_signal_energy(fft_res) / calculate_average_signal_energy(gr_res))

    print 'compare demodulation accuracy for different approaches'
    for e in range(11):
        em = 10 ** (-1. * e)
        matrixvsloop = np.all(np.abs(fft_res - mf_matrix_rx) < em)
        grvsmatrix = np.all(np.abs(gr_res - mf_matrix_rx) < em)
        grvsloop = np.all(np.abs(gr_res - fft_res) < em)
        print 'error margin {:.1e}\tMFmatriXvsGR: {}\tMFmatriXvsLoop: {}\tGRvsLoop: {}'.format(em, grvsmatrix, matrixvsloop, grvsloop)