def test_003_block_pinching(self): n_reps = 1 n_subcarriers = 8 n_timeslots = 8 block_len = n_subcarriers * n_timeslots cp_len = 8 ramp_len = 4 cs_len = ramp_len * 2 window_len = get_window_len(cp_len, n_timeslots, n_subcarriers, cs_len) window_taps = get_raised_cosine_ramp(ramp_len, window_len) data = np.arange(block_len, dtype=np.complex) + 1 ref = add_cyclic_starfix(data, cp_len, cs_len) ref = pinch_block(ref, window_taps) data = np.tile(data, n_reps) ref = np.tile(ref, n_reps) print "input is: ", len(data), " -> " , len(ref) # short_window = np.concatenate((window_taps[0:ramp_len], window_taps[-ramp_len:])) prefixer = gfdm.cyclic_prefixer_cc(block_len, cp_len, cs_len, ramp_len, window_taps) src = blocks.vector_source_c(data) dst = blocks.vector_sink_c() self.tb.connect(src, prefixer, dst) self.tb.run() res = np.array(dst.data()) print ref[-10:] print res[-10:] self.assertComplexTuplesAlmostEqual(res, ref, 4)
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 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=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 = 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_001_prefix(self): timeslots = 19 subcarriers = 32 block_len = timeslots * subcarriers cp_len = 16 ramp_len = 4 cs_len = ramp_len * 2 window_len = get_window_len(cp_len, timeslots, subcarriers, cs_len) window_taps = get_raised_cosine_ramp(ramp_len, window_len) data = np.arange(block_len, dtype=complex) + 1 ref = add_cyclic_starfix(data, cp_len, cs_len) ref = pinch_block(ref, window_taps) ref = ref.astype(np.complex64) prefixer = Cyclic_prefixer(block_len, cp_len, cs_len, ramp_len, window_taps) res = prefixer.add_cyclic_prefix(data) self.assertComplexTuplesAlmostEqual(res, ref, 6)
def test_003_prefix_removed(self): timeslots = 3 subcarriers = 32 cyclic_shift = 4 block_len = timeslots * subcarriers cp_len = 16 cs_len = cp_len // 2 ramp_len = 4 frame_len = cp_len + block_len + cs_len window_len = get_window_len(cp_len, timeslots, subcarriers, cs_len) window_taps = get_raised_cosine_ramp(ramp_len, window_len) prefixer = Cyclic_prefixer(block_len, cp_len, cs_len, ramp_len, window_taps, cyclic_shift) data = np.arange(frame_len, dtype=np.complex64) ref = data[cp_len:-cs_len] res = prefixer.remove_cyclic_prefix(data) self.assertEqual(res.size, block_len) self.assertComplexTuplesAlmostEqual(res, ref, 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_002_prefix_shifted(self): timeslots = 3 subcarriers = 32 cyclic_shift = 4 block_len = timeslots * subcarriers cp_len = 16 cs_len = cp_len // 2 ramp_len = 4 window_len = get_window_len(cp_len, timeslots, subcarriers, cs_len) window_taps = get_raised_cosine_ramp(ramp_len, window_len) data = np.arange(block_len, dtype=complex) + 1 ref = add_cyclic_starfix(data, cp_len, cs_len) ref = np.concatenate((data[-(cp_len + cyclic_shift):], data, data[0:cs_len - cyclic_shift])) ref = pinch_block(ref, window_taps) ref = ref.astype(np.complex64) prefixer = Cyclic_prefixer(block_len, cp_len, cs_len, ramp_len, window_taps, cyclic_shift) res = prefixer.add_cyclic_prefix(data) self.assertEqual(res.size, cp_len + block_len + cs_len) self.assertComplexTuplesAlmostEqual(res, ref, 5)