def test_001_t(self): # set up fg n_frames = 3 active_subcarriers = 110 subcarriers = 128 timeslots = 205 smap = np.arange(active_subcarriers) + (subcarriers - active_subcarriers) // 2 data = get_random_qpsk(active_subcarriers * timeslots) ref = map_to_waveform_resources(data, active_subcarriers, subcarriers, smap, True) for i in range(n_frames - 1): d = get_random_qpsk(active_subcarriers * timeslots) data = np.concatenate((data, d)) ref = np.concatenate( (ref, map_to_waveform_resources(d, active_subcarriers, subcarriers, smap, True))) src = blocks.vector_source_c(data) mapper = gfdm.resource_mapper_cc(timeslots, subcarriers, active_subcarriers, smap, True) snk = blocks.vector_sink_c() self.tb.connect(src, mapper, snk) self.tb.run() # check data res = snk.data() self.assertComplexTuplesAlmostEqual(ref, res)
def test_001_t(self): np.set_printoptions(precision=2) n_frames = 3 alpha = .5 active = 8 M = 8 K = 16 L = 2 cp_len = 8 cs_len = 4 ramp_len = 4 block_len = M * K window_len = get_window_len(cp_len, M, K, cs_len) taps = get_frequency_domain_filter('rrc', alpha, M, K, L) taps /= np.sqrt(calculate_signal_energy(taps) / M) window_taps = get_raised_cosine_ramp(ramp_len, window_len) pn_symbols = get_random_qpsk(K) H_preamble = get_frequency_domain_filter('rrc', alpha, 2, K, L) preamble = get_sync_symbol(pn_symbols, H_preamble, K, L, cp_len, ramp_len)[0] smap = get_subcarrier_map(K, active, dc_free=True) ref = np.array([], dtype=complex) data = np.array([], dtype=complex) frame_len = window_len + len(preamble) frame_gap = np.zeros(frame_len) for i in range(n_frames): d = get_random_qpsk(active * M) dd = map_to_waveform_resources(d, active, K, smap) D = get_data_matrix(dd, K, group_by_subcarrier=False) b = gfdm_modulate_block(D, taps, M, K, L, False) b = add_cyclic_starfix(b, cp_len, cs_len) b = pinch_block(b, window_taps) ref = np.concatenate((ref, frame_gap, preamble, b)) data = np.concatenate((data, d)) src = blocks.vector_source_c(data) mapper = gfdm.resource_mapper_cc(active, K, M, smap, True) mod = gfdm.simple_modulator_cc(M, K, L, taps) prefixer = gfdm.cyclic_prefixer_cc(block_len, cp_len, cs_len, ramp_len, window_taps) preambler = blocks.vector_insert_c(preamble, window_len + len(preamble), 0) gapper = blocks.vector_insert_c(frame_gap, frame_len + len(frame_gap), 0) dst = blocks.vector_sink_c() self.tb.connect(src, mapper, mod, prefixer, preambler, gapper, dst) # self.tb.connect(src, mapper, dst) self.tb.run() res = np.array(dst.data())[0:len(ref)] self.assertComplexTuplesAlmostEqual(ref, res, 5)
def test_001_t(self): np.set_printoptions(precision=2) n_frames = 7 alpha = .5 active_subcarriers = 52 timeslots = 9 subcarriers = 64 overlap = 2 cp_len = 8 cs_len = 4 ramp_len = 4 window_len = get_window_len(cp_len, timeslots, subcarriers, cs_len) taps = get_frequency_domain_filter('rrc', alpha, timeslots, subcarriers, overlap) # taps /= np.sqrt(calculate_signal_energy(taps) / time) window_taps = get_raised_cosine_ramp(ramp_len, window_len) pn_symbols = get_random_qpsk(subcarriers) H_preamble = get_frequency_domain_filter('rrc', alpha, 2, subcarriers, overlap) preamble = get_sync_symbol(pn_symbols, H_preamble, subcarriers, overlap, cp_len, ramp_len)[0] smap = get_subcarrier_map(subcarriers, active_subcarriers, True) ref = np.array([], dtype=np.complex) data = np.array([], dtype=np.complex) for i in range(n_frames): d = get_random_qpsk(active_subcarriers * timeslots) dd = map_to_waveform_resources(d, active_subcarriers, subcarriers, smap) D = get_data_matrix(dd, subcarriers, group_by_subcarrier=False) b = gfdm_modulate_block(D, taps, timeslots, subcarriers, overlap, False) b = add_cyclic_starfix(b, cp_len, cs_len) b = pinch_block(b, window_taps) ref = np.concatenate((ref, preamble, b)) data = np.concatenate((data, d)) src = blocks.vector_source_c(data) dut = gfdm.transmitter_cc(timeslots, subcarriers, active_subcarriers, cp_len, cs_len, ramp_len, smap, True, overlap, taps, window_taps, preamble, "packet_len") dst = blocks.vector_sink_c() self.tb.connect(src, dut, dst) self.tb.run() res = np.array(dst.data())[0:len(ref)] self.assertComplexTuplesAlmostEqual(ref, res, 5) tags = dst.tags() for t in tags: print(t.offset, t.value)
def test_001_t(self): np.set_printoptions(precision=2) n_frames = 3 alpha = .5 active = 8 M = 8 K = 16 L = 2 cp_len = 8 cs_len = 4 ramp_len = 4 block_len = M * K window_len = get_window_len(cp_len, M, K, cs_len) taps = get_frequency_domain_filter('rrc', alpha, M, K, L) taps /= np.sqrt(calculate_signal_energy(taps) / M) window_taps = get_raised_cosine_ramp(ramp_len, window_len) pn_symbols = get_random_qpsk(K) H_preamble = get_frequency_domain_filter('rrc', alpha, 2, K, L) preamble = get_sync_symbol(pn_symbols, H_preamble, K, L, cp_len, ramp_len)[0] smap = get_subcarrier_map(K, active, dc_free=True) ref = np.array([], dtype=np.complex) data = np.array([], dtype=np.complex) frame_len = window_len + len(preamble) frame_gap = np.zeros(frame_len) for i in range(n_frames): d = get_random_qpsk(active * M) dd = map_to_waveform_resources(d, active, K, smap) D = get_data_matrix(dd, K, group_by_subcarrier=False) b = gfdm_modulate_block(D, taps, M, K, L, False) b = add_cyclic_starfix(b, cp_len, cs_len) b = pinch_block(b, window_taps) ref = np.concatenate((ref, frame_gap, preamble, b)) data = np.concatenate((data, d)) src = blocks.vector_source_c(data) mapper = gfdm.resource_mapper_cc(active, K, M, smap, True) mod = gfdm.simple_modulator_cc(M, K, L, taps) prefixer = gfdm.cyclic_prefixer_cc(block_len, cp_len, cs_len, ramp_len, window_taps) preambler = blocks.vector_insert_c(preamble, window_len + len(preamble), 0) gapper = blocks.vector_insert_c(frame_gap, frame_len + len(frame_gap), 0) dst = blocks.vector_sink_c() self.tb.connect(src, mapper, mod, prefixer, preambler, gapper, dst) # self.tb.connect(src, mapper, dst) self.tb.run() res = np.array(dst.data())[0:len(ref)] self.assertComplexTuplesAlmostEqual(ref, res, 5)
def test_002_big_data(self): print "big data test" reps = 5 alpha = .5 M = 127 K = 16 L = 4 taps = get_frequency_domain_filter('rrc', alpha, M, K, L) data = np.array([], dtype=np.complex) ref = np.array([], dtype=np.complex) for i in range(reps): d = get_random_qpsk(M * K) D = get_data_matrix(d, K, group_by_subcarrier=False) ref = np.append(ref, gfdm_modulate_block(D, taps, M, K, L, False)) data = np.append(data, d) # print data # print ref # print "MAXIMUM ref value: ", np.max(abs(ref)) src = blocks.vector_source_c(data) mod = gfdm.simple_modulator_cc(M, K, L, taps) dst = blocks.vector_sink_c() self.tb.connect(src, mod, dst) # set up fg self.tb.run() # check data res = np.array(dst.data()) # res /= M * K # print "MAXIMUM result value: ", np.max(abs(res)) self.assertComplexTuplesAlmostEqual(ref, res, 2)
def test_001_simple_receiver(self): # make sure advanced receiver works like simple receiver in case no IC iterations are applied! reps = 5 alpha = .5 M = 127 K = 16 L = 2 taps = filters.get_frequency_domain_filter('rrc', alpha, M, K, L) data = np.array([], dtype=np.complex) ref = np.array([], dtype=np.complex) for i in xrange(reps): d = utils.get_random_qpsk(M * K) ref = np.append(ref, gfdm_demodulate_block(d, taps, K, M, L)) data = np.append(data, d) # print data # print ref # print "MAXIMUM ref value: ", np.max(abs(ref)) src = blocks.vector_source_c(data) est_data = np.ones(len(data), dtype=np.complex) est_src = blocks.vector_source_c(est_data) gfdm_constellation = digital.constellation_qpsk().base() mod = gfdm.advanced_receiver_sb_cc(M, K, L, 0, taps, gfdm_constellation, np.arange(K)) dst = blocks.vector_sink_c() self.tb.connect(src, (mod, 0), dst) self.tb.connect(est_src, (mod, 1)) # set up fg self.tb.run() # check data res = np.array(dst.data()) self.assertComplexTuplesAlmostEqual(ref, res, 4)
def test_002_big_data(self): print("big data test") reps = 5 alpha = .5 M = 127 K = 16 L = 2 taps = get_frequency_domain_filter('rrc', alpha, M, K, L) data = np.array([], dtype=complex) ref = np.array([], dtype=complex) for i in range(reps): d = get_random_qpsk(M * K) ref = np.append(ref, gfdm_demodulate_block(d, taps, K, M, L)) data = np.append(data, d) src = blocks.vector_source_c(data) mod = gfdm.simple_receiver_cc(M, K, L, taps) dst = blocks.vector_sink_c() self.tb.connect(src, mod, dst) # set up fg self.tb.run() # check data res = np.array(dst.data()) self.assertComplexTuplesAlmostEqual(ref, res, 4)
def test_001_t(self): nsubcarrier = 4 ntimeslots = 16 filter_alpha = 0.35 tag_key = "frame_len" fft_length = nsubcarrier * ntimeslots taps = get_frequency_domain_filter('rrc', filter_alpha, ntimeslots, nsubcarrier, 2) data = get_random_qpsk(nsubcarrier * ntimeslots) D = get_data_matrix(data, nsubcarrier, group_by_subcarrier=False) print D md = gfdms.modulator_cc(nsubcarrier, ntimeslots, filter_alpha, fft_length, 1, tag_key) tagger = blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, fft_length, tag_key) src = blocks.vector_source_c(data) dst = blocks.vector_sink_c() self.tb.connect(src, tagger, md, dst) self.tb.run() res = np.array(dst.data()) print res ref = gfdm_modulate_block(D, taps, ntimeslots, nsubcarrier, 2, True) print ref self.assertComplexTuplesAlmostEqual(ref, res, 2)
def test_001_t(self): nsubcarrier = 4 ntimeslots = 16 filter_alpha = 0.35 tag_key = "frame_len" fft_length = nsubcarrier * ntimeslots taps = get_frequency_domain_filter('rrc', filter_alpha, ntimeslots, nsubcarrier, 2) data = get_random_qpsk(nsubcarrier * ntimeslots) # data = np.zeros(nsubcarrier) # data[0] = 1 # data = np.repeat(data, ntimeslots) D = get_data_matrix(data, nsubcarrier, group_by_subcarrier=False) print D md = gfdms.modulator_cc(nsubcarrier, ntimeslots, filter_alpha, fft_length, 1, tag_key) tagger = blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, fft_length, tag_key) src = blocks.vector_source_c(data) dst = blocks.vector_sink_c() self.tb.connect(src, tagger, md, dst) self.tb.run() res = np.array(dst.data()) print res ref = gfdm_modulate_block(D, taps, ntimeslots, nsubcarrier, 2, True) print ref self.assertComplexTuplesAlmostEqual(ref, res, 2)
def test_005_steps(self): timeslots = 5 subcarriers = 32 overlap = 2 filter_alpha = 0.35 taps = get_frequency_domain_filter('rrc', filter_alpha, timeslots, subcarriers, overlap) data = get_random_qpsk(timeslots * subcarriers) D = get_data_matrix(data, subcarriers, group_by_subcarrier=False) frame = gfdm_modulate_block(D, taps, timeslots, subcarriers, overlap, False) ref = gfdm_demodulate_block( frame, taps, subcarriers, timeslots, overlap) demod = Demodulator(timeslots, subcarriers, overlap, taps) fd_res = demod.fft_filter_downsample(frame) res = demod.transform_subcarriers_to_td(fd_res) self.assertComplexTuplesAlmostEqual(ref, res, 5) for _ in range(2): ic_res = demod.cancel_sc_interference(data, fd_res) res = demod.transform_subcarriers_to_td(ic_res) self.assertComplexTuplesAlmostEqual(data, res, 1)
def test_001_t(self): alpha = .5 M = 8 K = 4 L = 2 taps = get_frequency_domain_filter('rrc', alpha, M, K, L) # data = np.repeat(np.arange(1, K + 1), M) data = get_random_qpsk(M * K) D = get_data_matrix(data, K, group_by_subcarrier=False) # print data # print D src = blocks.vector_source_c(data) mod = gfdm.simple_modulator_cc(M, K, L, taps) dst = blocks.vector_sink_c() self.tb.connect(src, mod, dst) # set up fg self.tb.run() # check data res = np.array(dst.data()) # res /= M * K # F = gfdm_transform_subcarriers_to_fd(D, M) # F = gfdm_upsample_subcarriers_in_fd(F, K, L) # F = gfdm_filter_subcarriers_in_fd(F, taps, M, K, L) ref = gfdm_modulate_block(D, taps, M, K, L, False) self.assertComplexTuplesAlmostEqual(ref, res, 5)
def test_001_t(self): alpha = .5 M = 8 K = 4 L = 2 taps = get_frequency_domain_filter('rrc', alpha, M, K, L) taps /= np.sqrt(calculate_signal_energy(taps) / M) # data = np.repeat(np.arange(1, K + 1), M) data = get_random_qpsk(M * K) D = get_data_matrix(data, K, group_by_subcarrier=False) src = blocks.vector_source_c(data) mod = gfdm.simple_modulator_cc(M, K, L, taps) dst = blocks.vector_sink_c() self.tb.connect(src, mod, dst) # set up fg self.tb.run() # check data res = np.array(dst.data()) # res /= M * K # F = gfdm_transform_subcarriers_to_fd(D, M) # F = gfdm_upsample_subcarriers_in_fd(F, K, L) # F = gfdm_filter_subcarriers_in_fd(F, taps, M, K, L) ref = gfdm_modulate_block(D, taps, M, K, L, False) self.assertComplexTuplesAlmostEqual(ref, res, 5)
def test_001_simple_receiver(self): # make sure advanced receiver works like simple receiver in case no IC iterations are applied! reps = 5 alpha = .5 M = 127 K = 16 L = 2 taps = filters.get_frequency_domain_filter('rrc', alpha, M, K, L) data = np.array([], dtype=np.complex) ref = np.array([], dtype=np.complex) for i in xrange(reps): d = utils.get_random_qpsk(M * K) ref = np.append(ref, gfdm_demodulate_block(d, taps, K, M, L)) data = np.append(data, d) # print data # print ref # print "MAXIMUM ref value: ", np.max(abs(ref)) src = blocks.vector_source_c(data) est_data = np.ones(len(data), dtype=np.complex) est_src = blocks.vector_source_c(est_data) gfdm_constellation = digital.constellation_qpsk().base() mod = gfdm.advanced_receiver_sb_cc(M, K, L, 0, taps, gfdm_constellation, np.arange(K), 0) dst = blocks.vector_sink_c() self.tb.connect(src, (mod, 0), dst) self.tb.connect(est_src, (mod, 1)) # set up fg self.tb.run() # check data res = np.array(dst.data()) self.assertComplexTuplesAlmostEqual(ref, res, 4)
def create_frame(config, tag_key): symbols = get_random_qpsk(config.timeslots * config.active_subcarriers) d_block = modulate_mapped_gfdm_block( symbols, config.timeslots, config.subcarriers, config.active_subcarriers, 2, 0.2, dc_free=True, ) preamble = config.full_preambles[0] frame = add_cyclic_starfix(d_block, config.cp_len, config.cs_len) frame = np.concatenate((preamble, frame)) tag = gr.tag_t() tag.key = pmt.string_to_symbol(tag_key) d = pmt.make_dict() d = pmt.dict_add(d, pmt.mp("xcorr_idx"), pmt.from_uint64(42)) d = pmt.dict_add(d, pmt.mp("xcorr_offset"), pmt.from_uint64(4711)) d = pmt.dict_add(d, pmt.mp("sc_rot"), pmt.from_complex(1.0 + 0.0j)) # tag.offset = data.size + cp_len tag.srcid = pmt.string_to_symbol("qa") tag.value = d return frame, symbols, tag
def test_003_active_subcarriers(self): n_frames = 1 timeslots = 9 subcarriers = 32 active_subcarriers = 20 overlap = 2 f_taps = filters.get_frequency_domain_filter('rrc', .5, timeslots, subcarriers, overlap) gfdm_constellation = digital.constellation_qpsk().base() subcarrier_map = get_subcarrier_map(subcarriers, active_subcarriers) data = get_random_qpsk(n_frames * timeslots * active_subcarriers) src = blocks.vector_source_c(data) mapper = gfdm.resource_mapper_cc(timeslots, subcarriers, active_subcarriers, subcarrier_map, True) mod = gfdm.simple_modulator_cc(timeslots, subcarriers, overlap, f_taps) demod = gfdm.advanced_receiver_sb_cc(timeslots, subcarriers, overlap, 64, f_taps, gfdm_constellation, subcarrier_map, 0) demapper = gfdm.resource_demapper_cc(timeslots, subcarriers, active_subcarriers, subcarrier_map, True) snk = blocks.vector_sink_c() self.tb.connect(src, mapper, mod, demod, demapper, snk) self.tb.run() res = np.array(snk.data()) self.assertComplexTuplesAlmostEqual(data, res, 2)
def test_002_big_data(self): print("big data test") reps = 5 alpha = .5 M = 127 K = 16 L = 2 taps = get_frequency_domain_filter('rrc', alpha, M, K, L) data = np.array([], dtype=np.complex) ref = np.array([], dtype=np.complex) for i in xrange(reps): d = get_random_qpsk(M * K) ref = np.append(ref, gfdm_demodulate_block(d, taps, K, M, L)) data = np.append(data, d) # print data # print ref # print "MAXIMUM ref value: ", np.max(abs(ref)) src = blocks.vector_source_c(data) mod = gfdm.simple_receiver_cc(M, K, L, taps) dst = blocks.vector_sink_c() self.tb.connect(src, mod, dst) # set up fg self.tb.run() # check data res = np.array(dst.data()) self.assertComplexTuplesAlmostEqual(ref, res, 4)
def test_002_big_data(self): print("big data test") reps = 5 alpha = .5 M = 127 K = 16 L = 4 taps = get_frequency_domain_filter('rrc', alpha, M, K, L) taps /= np.sqrt(calculate_signal_energy(taps) / M) data = np.array([], dtype=complex) ref = np.array([], dtype=complex) for i in range(reps): d = get_random_qpsk(M * K) D = get_data_matrix(d, K, group_by_subcarrier=False) ref = np.append(ref, gfdm_modulate_block(D, taps, M, K, L, False)) data = np.append(data, d) src = blocks.vector_source_c(data) mod = gfdm.simple_modulator_cc(M, K, L, taps) dst = blocks.vector_sink_c() self.tb.connect(src, mod, dst) # set up fg self.tb.run() # check data res = np.array(dst.data()) # res /= M * K self.assertComplexTuplesAlmostEqual(ref, res, 2)
def test_001_t(self): np.set_printoptions(precision=2) n_frames = 7 active_subcarriers = 52 timeslots = 9 subcarriers = 64 cp_len = subcarriers // 4 cs_len = cp_len // 2 taps = get_frequency_domain_filter(self.filter_type, self.alpha, timeslots, subcarriers, self.overlap) window_taps = get_raised_cosine_ramp( cs_len, get_window_len(cp_len, timeslots, subcarriers, cs_len)) smap = get_subcarrier_map(subcarriers, active_subcarriers, True) preambles = get_full_preambles(self.filter_type, self.alpha, active_subcarriers, subcarriers, smap, self.overlap, cp_len, cs_len, [ 0, ]) frame_size = preambles[ 0].size + cp_len + timeslots * subcarriers + cs_len ref = np.array([], dtype=np.complex) data = np.array([], dtype=np.complex) for i in range(n_frames): d = get_random_qpsk(active_subcarriers * timeslots) frame = generate_reference_frame(d, timeslots, subcarriers, active_subcarriers, smap, taps, self.overlap, cp_len, cs_len, window_taps, [ 0, ], preambles) ref = np.concatenate((ref, frame[0])) data = np.concatenate((data, d)) src = blocks.vector_source_c(data) dut = gfdm.transmitter_cc(timeslots, subcarriers, active_subcarriers, cp_len, cs_len, cs_len, smap, True, self.overlap, taps, window_taps, [ 0, ], preambles, "packet_len") dst = blocks.vector_sink_c() self.tb.connect(src, dut, dst) self.tb.run() res = np.array(dst.data())[0:len(ref)] self.assertComplexTuplesAlmostEqual(ref, res, 5) tags = dst.tags() for i, t in enumerate(tags): print(f't={i}, offset={t.offset}, value={pmt.to_python(t.value)}') self.assertEqual(t.offset, i * frame_size) self.assertEqual(pmt.to_python(t.value), frame_size)
def test_002_cyclic_delay_diversity(self): np.set_printoptions(precision=2) n_frames = 7 active_subcarriers = 52 timeslots = 9 subcarriers = 64 cp_len = subcarriers // 4 cs_len = cp_len // 2 cyclic_shifts = [0, 3, 7, 8] taps = get_frequency_domain_filter(self.filter_type, self.alpha, timeslots, subcarriers, self.overlap) window_taps = get_raised_cosine_ramp( cs_len, get_window_len(cp_len, timeslots, subcarriers, cs_len)) smap = get_subcarrier_map(subcarriers, active_subcarriers, True) preambles = get_full_preambles(self.filter_type, self.alpha, active_subcarriers, subcarriers, smap, self.overlap, cp_len, cs_len, cyclic_shifts) frame_size = preambles[0].size + cp_len + timeslots * subcarriers + cs_len ref = [np.array([], dtype=complex) for _ in cyclic_shifts] data = np.array([], dtype=complex) for i in range(n_frames): d = get_random_qpsk(active_subcarriers * timeslots) frame = generate_reference_frame(d, timeslots, subcarriers, active_subcarriers, smap, taps, self.overlap, cp_len, cs_len, window_taps, cyclic_shifts, preambles) ref = [np.concatenate((r, f)) for r, f in zip(ref, frame)] data = np.concatenate((data, d)) src = blocks.vector_source_c(data) dut = gfdm.transmitter_cc(timeslots, subcarriers, active_subcarriers, cp_len, cs_len, cs_len, smap, True, self.overlap, taps, window_taps, cyclic_shifts, preambles, "packet_len") snks = [blocks.vector_sink_c() for _ in cyclic_shifts] self.tb.connect(src, dut) for i, s in enumerate(snks): self.tb.connect((dut, i), s) self.tb.run() for snk, refport in zip(snks, ref): res = np.array(snk.data())[0:refport.size] self.assertComplexTuplesAlmostEqual(refport, res, 5) for j, snk in enumerate(snks): tags = snk.tags() for i, t in enumerate(tags): print(f'p={j}, t={i}, offset={t.offset}, value={pmt.to_python(t.value)}') self.assertEqual(t.offset, i * frame_size) self.assertEqual(pmt.to_python(t.value), frame_size)
def cp_test(): M = 5 K = 16 window_taps = get_raised_cosine_ramp(4, M * K + 4) cpler = cgfdm.py_add_cyclic_prefix_cc(M * K, 4, 0, 4, window_taps) print cpler.block_size() print cpler.frame_size() in_buf = get_random_qpsk(M * K, dtype=np.complex64) block = cpler.add_cyclic_prefix(in_buf) print np.shape(block)
def test_001_t(self): n_frames = 20 timeslots = 9 subcarriers = 128 active_subcarriers = 110 cp_len = subcarriers // 2 smap = get_subcarrier_map(subcarriers, active_subcarriers) seed = 4711 ftype = 'rrc' falpha = .5 preamble, x_preamble = mapped_preamble(seed, ftype, falpha, active_subcarriers, subcarriers, smap, 2, cp_len, cp_len // 2) frame_len = len(preamble) + timeslots * subcarriers + cp_len frame_gap = np.zeros(frame_len, dtype=np.complex) data = frame_gap ref = np.array([], dtype=np.complex) for i in range(n_frames): d_block = modulate_mapped_gfdm_block( get_random_qpsk(timeslots * active_subcarriers), timeslots, subcarriers, active_subcarriers, 2, falpha) frame = pinch_cp_add_block(d_block, timeslots, subcarriers, cp_len, cp_len // 2) frame = np.concatenate((preamble, frame)) ref = np.concatenate((ref, frame)) data = np.concatenate((data, frame, frame_gap)) # print np.sum(np.abs(x_preamble) ** 2) # import matplotlib.pyplot as plt # plt.plot(data.real) # plt.plot(data.imag) # plt.show() backoff = 80 src = blocks.vector_source_c(data) e_detector = gfdm.frame_energy_detector_cc(10., 32, frame_len, backoff, 'energy') detector = gfdm.simple_preamble_sync_cc(frame_len, subcarriers, cp_len, x_preamble, 'energy', 'frame') snk = blocks.vector_sink_c() self.tb.connect(src, e_detector, detector, snk) self.tb.run() # check data res = np.array(snk.data()) tags = snk.tags() for t in tags: print 'srcid {}, key {}, offset {}, value {}'.format( t.srcid, t.key, t.offset, t.value) self.assertComplexTuplesAlmostEqual(res, ref[0:len(res)], 5)
def test_001_t(self): np.set_printoptions(precision=2) n_frames = 3 alpha = .5 M = 8 K = 4 L = 2 cp_len = 8 ramp_len = 4 block_len = M * K window_len = get_window_len(cp_len, M, K) taps = get_frequency_domain_filter('rrc', alpha, M, K, L) window_taps = get_raised_cosine_ramp(ramp_len, window_len) pn_symbols = get_random_qpsk(K) H_preamble = get_frequency_domain_filter('rrc', alpha, 2, K, L) preamble = get_sync_symbol(pn_symbols, H_preamble, K, L, cp_len, ramp_len) ref = np.array([], dtype=np.complex) data = np.array([], dtype=np.complex) for i in range(n_frames): d = get_random_qpsk(block_len) D = get_data_matrix(d, K, group_by_subcarrier=False) b = gfdm_modulate_block(D, taps, M, K, L, False) b = add_cyclic_prefix(b, cp_len) b = pinch_block(b, window_taps) ref = np.concatenate((ref, preamble, b)) data = np.concatenate((data, d)) src = blocks.vector_source_c(data) mod = gfdm.simple_modulator_cc(M, K, L, taps) prefixer = gfdm.cyclic_prefixer_cc(cp_len, ramp_len, block_len, window_taps) preambler = blocks.vector_insert_c(preamble, window_len + len(preamble), 0) dst = blocks.vector_sink_c() self.tb.connect(src, mod, prefixer, preambler, dst) self.tb.run() res = np.array(dst.data())[0:len(ref)] self.assertComplexTuplesAlmostEqual(ref, res, 5)
def test_001_t(self): n_frames = 20 timeslots = 9 subcarriers = 128 active_subcarriers = 110 cp_len = subcarriers // 2 smap = get_subcarrier_map(subcarriers, active_subcarriers) seed = 4711 ftype = 'rrc' falpha = .5 tag_key = 'frame_start' preamble, x_preamble = mapped_preamble(seed, ftype, falpha, active_subcarriers, subcarriers, smap, 2, cp_len, cp_len // 2) block_len = timeslots * subcarriers offset = len(preamble) + cp_len frame_len = len(preamble) + timeslots * subcarriers + cp_len data = np.array([], dtype=np.complex) ref = np.array([], dtype=np.complex) tags = [] print 'frame_len: ', frame_len for i in range(n_frames): d_block = modulate_mapped_gfdm_block( get_random_qpsk(timeslots * active_subcarriers), timeslots, subcarriers, active_subcarriers, 2, falpha) frame = pinch_cp_add_block(d_block, timeslots, subcarriers, cp_len, cp_len // 2) frame = np.concatenate((preamble, frame)) r = frame[offset:offset + block_len] ref = np.concatenate((ref, r)) tag = gr.tag_t() tag.key = pmt.string_to_symbol(tag_key) tag.offset = len(data) tag.srcid = pmt.string_to_symbol('qa') tag.value = pmt.from_long(block_len) tags.append(tag) data = np.concatenate((data, frame)) src = blocks.vector_source_c(data, False, 1, tags) cp_rm = gfdm.remove_prefix_cc(frame_len, block_len, offset, tag_key) snk = blocks.vector_sink_c() self.tb.connect(src, cp_rm, snk) self.tb.run() # # check data res = np.array(snk.data()) tags = snk.tags() self.assertTrue(len(tags) == 0) # propagation policy is TPP_DONT self.assertComplexTuplesAlmostEqual(res, ref, 5)
def test_001_t(self): # set up fg n_frames = 3 active_subcarriers = 110 subcarriers = 128 timeslots = 205 smap = np.arange(active_subcarriers) + (subcarriers - active_subcarriers) // 2 data = get_random_qpsk(active_subcarriers * timeslots) ref = map_to_waveform_resources(data, active_subcarriers, subcarriers, smap, True) for i in range(n_frames - 1): d = get_random_qpsk(active_subcarriers * timeslots) data = np.concatenate((data, d)) ref = np.concatenate((ref, map_to_waveform_resources(d, active_subcarriers, subcarriers, smap, True))) src = blocks.vector_source_c(data) mapper = gfdm.resource_mapper_cc(timeslots, subcarriers, active_subcarriers, smap, True) snk = blocks.vector_sink_c() self.tb.connect(src, mapper, snk) self.tb.run() # check data res = snk.data() self.assertComplexTuplesAlmostEqual(ref, res)
def test_002_subcarrier_first(self): timeslots = 9 subcarriers = 32 active_subcarriers = 20 subcarrier_map = get_subcarrier_map(subcarriers, active_subcarriers) data = get_random_qpsk(10 * timeslots * active_subcarriers) src = blocks.vector_source_c(data) mapper = gfdm.resource_mapper_cc(timeslots, subcarriers, active_subcarriers, subcarrier_map, False) demapper = gfdm.resource_demapper_cc(timeslots, subcarriers, active_subcarriers, subcarrier_map, False) snk = blocks.vector_sink_c() self.tb.connect(src, mapper, demapper, snk) self.tb.run() # check data res = np.array(snk.data()) self.assertComplexTuplesAlmostEqual(data, res)
def test_001_t(self): n_frames = 20 timeslots = 9 subcarriers = 128 active_subcarriers = 110 cp_len = subcarriers // 2 smap = get_subcarrier_map(subcarriers, active_subcarriers) seed = 4711 ftype = 'rrc' falpha = .5 tag_key = 'frame_start' preamble, x_preamble = mapped_preamble(seed, ftype, falpha, active_subcarriers, subcarriers, smap, 2, cp_len, cp_len // 2) block_len = timeslots * subcarriers offset = len(preamble) + cp_len frame_len = len(preamble) + timeslots * subcarriers + cp_len data = np.array([], dtype=np.complex) ref = np.array([], dtype=np.complex) tags = [] print 'frame_len: ', frame_len for i in range(n_frames): d_block = modulate_mapped_gfdm_block(get_random_qpsk(timeslots * active_subcarriers), timeslots, subcarriers, active_subcarriers, 2, falpha) frame = pinch_cp_add_block(d_block, timeslots, subcarriers, cp_len, cp_len // 2) frame = np.concatenate((preamble, frame)) r = frame[offset:offset + block_len] ref = np.concatenate((ref, r)) tag = gr.tag_t() tag.key = pmt.string_to_symbol(tag_key) tag.offset = len(data) tag.srcid = pmt.string_to_symbol('qa') tag.value = pmt.from_long(block_len) tags.append(tag) data = np.concatenate((data, frame)) src = blocks.vector_source_c(data, False, 1, tags) cp_rm = gfdm.remove_prefix_cc(frame_len, block_len, offset, tag_key) snk = blocks.vector_sink_c() self.tb.connect(src, cp_rm, snk) self.tb.run() # # check data res = np.array(snk.data()) tags = snk.tags() self.assertTrue(len(tags) == 0) # propagation policy is TPP_DONT self.assertComplexTuplesAlmostEqual(res, ref, 5)
def test_001_t(self): n_frames = 20 timeslots = 9 subcarriers = 128 active_subcarriers = 110 cp_len = subcarriers // 2 smap = get_subcarrier_map(subcarriers, active_subcarriers) seed = 4711 ftype = 'rrc' falpha = .5 preamble, x_preamble = mapped_preamble(seed, ftype, falpha, active_subcarriers, subcarriers, smap, 2, cp_len, cp_len // 2) frame_len = len(preamble) + timeslots * subcarriers + cp_len frame_gap = np.zeros(frame_len, dtype=np.complex) data = frame_gap ref = np.array([], dtype=np.complex) for i in range(n_frames): d_block = modulate_mapped_gfdm_block(get_random_qpsk(timeslots * active_subcarriers), timeslots, subcarriers, active_subcarriers, 2, falpha) frame = pinch_cp_add_block(d_block, timeslots, subcarriers, cp_len, cp_len // 2) frame = np.concatenate((preamble, frame)) ref = np.concatenate((ref, frame)) data = np.concatenate((data, frame, frame_gap)) # print np.sum(np.abs(x_preamble) ** 2) # import matplotlib.pyplot as plt # plt.plot(data.real) # plt.plot(data.imag) # plt.show() backoff = 80 src = blocks.vector_source_c(data) e_detector = gfdm.frame_energy_detector_cc(10., 32, frame_len, backoff, 'energy') detector = gfdm.simple_preamble_sync_cc(frame_len, subcarriers, cp_len, x_preamble, 'energy', 'frame') snk = blocks.vector_sink_c() self.tb.connect(src, e_detector, detector, snk) self.tb.run() # check data res = np.array(snk.data()) tags = snk.tags() for t in tags: print 'srcid {}, key {}, offset {}, value {}'.format(t.srcid, t.key, t.offset, t.value) self.assertComplexTuplesAlmostEqual(res, ref[0:len(res)], 5)
def test_002_big(self): timeslots = 21 subcarriers = 128 overlap = 2 filter_alpha = 0.35 taps = get_frequency_domain_filter("rrc", filter_alpha, timeslots, subcarriers, overlap) data = get_random_qpsk(timeslots * subcarriers) D = get_data_matrix(data, subcarriers, group_by_subcarrier=False) ref = gfdm_modulate_block(D, taps, timeslots, subcarriers, overlap, False) mod = Modulator(timeslots, subcarriers, overlap, taps) res = mod.modulate(data) self.assertComplexTuplesAlmostEqual(ref, res, 5)
def test_004_active_subcarriers(self): n_frames = 1 timeslots = 9 subcarriers = 32 active_subcarriers = 20 overlap = 2 ic_iterations = 64 f_taps = filters.get_frequency_domain_filter("rrc", 0.5, timeslots, subcarriers, overlap) gfdm_constellation = digital.constellation_qpsk().base() print(gfdm_constellation.points()) subcarrier_map = get_subcarrier_map(subcarriers, active_subcarriers) data = get_random_qpsk(n_frames * timeslots * active_subcarriers) data *= 2.0 src = blocks.vector_source_c(data) mapper = gfdm.resource_mapper_cc(timeslots, subcarriers, active_subcarriers, subcarrier_map, True) mod = gfdm.simple_modulator_cc(timeslots, subcarriers, overlap, f_taps) demod = gfdm.advanced_receiver_sb_cc( timeslots, subcarriers, overlap, ic_iterations, f_taps, gfdm_constellation, subcarrier_map, 0, ) demod.set_ic(64) demapper = gfdm.resource_demapper_cc(timeslots, subcarriers, active_subcarriers, subcarrier_map, True) snk = blocks.vector_sink_c() self.tb.connect(src, mapper, mod, demod, demapper, snk) self.tb.run() res = np.array(snk.data()) print(data[0:10]) print(res[0:10]) self.assertComplexTuplesAlmostEqual(data, res, 1)
def test_002_small(self): timeslots = 16 subcarriers = 4 overlap = 2 filter_alpha = 0.35 taps = get_frequency_domain_filter("rrc", filter_alpha, timeslots, subcarriers, overlap) data = get_random_qpsk(timeslots * subcarriers) D = get_data_matrix(data, subcarriers, group_by_subcarrier=False) frame = gfdm_modulate_block(D, taps, timeslots, subcarriers, overlap, False) ref = gfdm_demodulate_block(frame, taps, subcarriers, timeslots, overlap) demod = Demodulator(timeslots, subcarriers, overlap, taps) res = demod.demodulate(frame) self.assertComplexTuplesAlmostEqual(ref, res, 6)
def test_001_t(self): alpha = .5 M = 8 K = 4 L = 2 taps = get_frequency_domain_filter('rrc', alpha, M, K, L) taps /= np.sqrt(calculate_signal_energy(taps) / M) data = get_random_qpsk(M * K) src = blocks.vector_source_c(data) mod = gfdm.simple_receiver_cc(M, K, L, taps) dst = blocks.vector_sink_c() self.tb.connect(src, mod, dst) self.tb.run() res = np.array(dst.data()) ref = gfdm_demodulate_block(data, taps, K, M, L) res *= np.sqrt( calculate_signal_energy(ref) / calculate_signal_energy(res)) self.assertComplexTuplesAlmostEqual(ref, res, 5)
def test_001_t(self): alpha = .5 M = 8 K = 4 L = 2 taps = get_frequency_domain_filter('rrc', alpha, M, K, L) taps /= np.sqrt(calculate_signal_energy(taps) / M) data = get_random_qpsk(M * K) src = blocks.vector_source_c(data) mod = gfdm.simple_receiver_cc(M, K, L, taps) dst = blocks.vector_sink_c() self.tb.connect(src, mod, dst) self.tb.run() res = np.array(dst.data()) ref = gfdm_demodulate_block(data, taps, K, M, L) # print calculate_signal_energy(ref), calculate_signal_energy(res) res *= np.sqrt(calculate_signal_energy(ref) / calculate_signal_energy(res)) self.assertComplexTuplesAlmostEqual(ref, res, 5)
def test_004_big_equalize(self): timeslots = 21 subcarriers = 128 overlap = 2 filter_alpha = 0.35 taps = get_frequency_domain_filter("rrc", filter_alpha, timeslots, subcarriers, overlap) data = get_random_qpsk(timeslots * subcarriers) D = get_data_matrix(data, subcarriers, group_by_subcarrier=False) frame = gfdm_modulate_block(D, taps, timeslots, subcarriers, overlap, False) ref = gfdm_demodulate_block(frame, taps, subcarriers, timeslots, overlap) eq_vals = np.ones(ref.size, ref.dtype) * np.exp(1.0j) demod = Demodulator(timeslots, subcarriers, overlap, taps) res = demod.demodulate_equalize(frame * np.exp(1.0j), eq_vals) self.assertComplexTuplesAlmostEqual(ref, res, 5)
def test_003_active_subcarriers(self): n_frames = 1 timeslots = 9 subcarriers = 32 active_subcarriers = 20 overlap = 2 f_taps = filters.get_frequency_domain_filter('rrc', .5, timeslots, subcarriers, overlap) gfdm_constellation = digital.constellation_qpsk().base() subcarrier_map = get_subcarrier_map(subcarriers, active_subcarriers) data = get_random_qpsk(n_frames * timeslots * active_subcarriers) src = blocks.vector_source_c(data) mapper = gfdm.resource_mapper_cc(timeslots, subcarriers, active_subcarriers, subcarrier_map, True) mod = gfdm.simple_modulator_cc(timeslots, subcarriers, overlap, f_taps) demod = gfdm.advanced_receiver_sb_cc(timeslots, subcarriers, overlap, 64, f_taps, gfdm_constellation, subcarrier_map) demapper = gfdm.resource_demapper_cc(timeslots, subcarriers, active_subcarriers, subcarrier_map, True) snk = blocks.vector_sink_c() self.tb.connect(src, mapper, mod, demod, demapper, snk) self.tb.run() res = np.array(snk.data()) self.assertComplexTuplesAlmostEqual(data, res, 2)
def test_006_steps_equalize(self): timeslots = 5 subcarriers = 32 overlap = 2 filter_alpha = 0.35 taps = get_frequency_domain_filter('rrc', filter_alpha, timeslots, subcarriers, overlap) data = get_random_qpsk(timeslots * subcarriers) D = get_data_matrix(data, subcarriers, group_by_subcarrier=False) frame = gfdm_modulate_block(D, taps, timeslots, subcarriers, overlap, False) ref = gfdm_demodulate_block( frame, taps, subcarriers, timeslots, overlap) eq_vals = np.ones(ref.size, ref.dtype) * np.exp(1.j) demod = Demodulator(timeslots, subcarriers, overlap, taps) fd_res = demod.fft_equalize_filter_downsample( frame * np.exp(1.j), eq_vals) res = demod.transform_subcarriers_to_td(fd_res) self.assertComplexTuplesAlmostEqual(ref, res, 5)