def test_003_frame_detect(self): alpha = 3. average_len = 8 frame_len = 25 backoff_len = 4 tag_key = 'enertest' # set up fg detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key) data = np.zeros(100) data[50:] = 100 src = blocks.vector_source_c(data) snk = blocks.vector_sink_c() self.tb.connect(src, 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) p = tags[0].offset self.assertEqual(p, 0) v = pmt.to_long(tags[0].value) fl = frame_len + 2 * backoff_len self.assertEqual(int(v), int(fl)) self.assertComplexTuplesAlmostEqual(res, data[44:44 + len(res)])
def test_003_frame_detect(self): alpha = 3. average_len = 8 frame_len = 25 backoff_len = 4 tag_key = 'enertest' # set up fg detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key) data = np.zeros(100) data[50:] = 100 src = blocks.vector_source_c(data) snk = blocks.vector_sink_c() self.tb.connect(src, 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) p = tags[0].offset self.assertEqual(p, 0) v = pmt.to_long(tags[0].value) fl = frame_len + 2 * backoff_len self.assertEqual(int(v), int(fl)) self.assertComplexTuplesAlmostEqual(res, data[44:44 + len(res)])
def test_002_simple_passthru(self): alpha = 3. average_len = 8 frame_len = 25 backoff_len = 0 tag_key = 'enertest' # set up fg detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key) data = np.zeros(100) data[50:] = 100 src = blocks.vector_source_c(data) snk = blocks.vector_sink_c() self.tb.connect(src, detector, snk) self.tb.run() # check data res = snk.data() # make sure output is a multiple of average_len! self.assertTrue(len(res) == frame_len) tags = snk.tags() for t in tags: print 'srcid {}, key {}, offset {}, value {}'.format( t.srcid, t.key, t.offset, t.value) p = tags[0].offset self.assertEqual(p, 0) self.assertComplexTuplesAlmostEqual(res, data[48:48 + len(res)])
def test_002_simple_passthru(self): alpha = 3. average_len = 8 frame_len = 25 backoff_len = 0 tag_key = 'enertest' # set up fg detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key) data = np.zeros(100) data[50:] = 100 src = blocks.vector_source_c(data) snk = blocks.vector_sink_c() self.tb.connect(src, detector, snk) self.tb.run() # check data res = snk.data() # make sure output is a multiple of average_len! self.assertTrue(len(res) == frame_len) tags = snk.tags() for t in tags: print 'srcid {}, key {}, offset {}, value {}'.format(t.srcid, t.key, t.offset, t.value) p = tags[0].offset self.assertEqual(p, 0) self.assertComplexTuplesAlmostEqual(res, data[48:48 + len(res)])
def test_005_long_frame(self): alpha = 3. average_len = 32 frame_len = 5000 backoff_len = 2 * average_len tag_key = 'enertest' # set up fg detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key) test_frame = np.zeros(frame_len + 2 * backoff_len) test_frame[backoff_len:-backoff_len] = 100. data = np.zeros(10 * frame_len) p = 6 * average_len data[p:p + len(test_frame)] = test_frame src = blocks.vector_source_c(data) snk = blocks.vector_sink_c() self.tb.connect(src, detector, snk) self.tb.run() # check data res = np.array(snk.data()) # make sure output is a multiple of average_len! tags = snk.tags() for t in tags: print 'srcid {}, key {}, offset {}, value {}'.format(t.srcid, t.key, t.offset, t.value) p = tags[0].offset self.assertEqual(p, 0) v = pmt.to_long(tags[0].value) fl = frame_len + 2 * backoff_len self.assertEqual(int(v), int(fl)) self.assertComplexTuplesAlmostEqual(res[0:len(test_frame)], test_frame)
def test_004_frames(self): alpha = 3. average_len = 8 frame_len = 25 backoff_len = 2 * average_len tag_key = 'enertest' # set up fg detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key) test_frame = np.zeros(frame_len + 2 * backoff_len) test_frame[backoff_len:-backoff_len] = 100. data = np.zeros(1000) p = 6 * average_len data[p:p + len(test_frame)] = test_frame p = 60 * average_len data[p:p + len(test_frame)] = test_frame ref = np.tile(test_frame, 2) src = blocks.vector_source_c(data) snk = blocks.vector_sink_c() self.tb.connect(src, detector, snk) self.tb.run() # check data res = np.array(snk.data()) # make sure output is a multiple of average_len! tags = snk.tags() p = tags[0].offset self.assertEqual(p, 0) v = pmt.to_long(tags[0].value) fl = frame_len + 2 * backoff_len self.assertEqual(int(v), int(fl)) self.assertComplexTuplesAlmostEqual(res[0:len(test_frame)], test_frame)
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_setup(self): alpha = 3. average_len = 8 frame_len = 25 backoff_len = average_len tag_key = 'enertest' detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key) self.assertEqual(backoff_len, detector.backoff_len()) self.assertAlmostEqual(alpha, detector.alpha()) alpha = 5.0 detector.set_alpha(alpha) backoff_len = 16 detector.set_backoff_len(backoff_len) self.assertEqual(backoff_len, detector.backoff_len()) self.assertAlmostEqual(alpha, detector.alpha())
def test_001_setup(self): alpha = 3. average_len = 8 frame_len = 25 backoff_len = average_len tag_key = 'enertest' detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key) self.assertEqual(backoff_len, detector.backoff_len()) self.assertAlmostEqual(alpha, detector.alpha()) alpha = 5.0 detector.set_alpha(alpha) backoff_len = 16 detector.set_backoff_len(backoff_len) self.assertEqual(backoff_len, detector.backoff_len()) self.assertAlmostEqual(alpha, detector.alpha())
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_005_long_frame(self): alpha = 3. average_len = 32 frame_len = 5000 backoff_len = 2 * average_len tag_key = 'enertest' # set up fg detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key) test_frame = np.zeros(frame_len + 2 * backoff_len) test_frame[backoff_len:-backoff_len] = 100. data = np.zeros(10 * frame_len) p = 6 * average_len data[p:p + len(test_frame)] = test_frame src = blocks.vector_source_c(data) snk = blocks.vector_sink_c() self.tb.connect(src, detector, snk) self.tb.run() # check data res = np.array(snk.data()) # make sure output is a multiple of average_len! tags = snk.tags() for t in tags: print 'srcid {}, key {}, offset {}, value {}'.format( t.srcid, t.key, t.offset, t.value) p = tags[0].offset self.assertEqual(p, 0) v = pmt.to_long(tags[0].value) fl = frame_len + 2 * backoff_len self.assertEqual(int(v), int(fl)) self.assertComplexTuplesAlmostEqual(res[0:len(test_frame)], test_frame)
def test_004_frames(self): alpha = 3. average_len = 8 frame_len = 25 backoff_len = 2 * average_len tag_key = 'enertest' # set up fg detector = gfdm.frame_energy_detector_cc(alpha, average_len, frame_len, backoff_len, tag_key) test_frame = np.zeros(frame_len + 2 * backoff_len) test_frame[backoff_len:-backoff_len] = 100. data = np.zeros(1000) p = 6 * average_len data[p:p + len(test_frame)] = test_frame p = 60 * average_len data[p:p + len(test_frame)] = test_frame ref = np.tile(test_frame, 2) src = blocks.vector_source_c(data) snk = blocks.vector_sink_c() self.tb.connect(src, detector, snk) self.tb.run() # check data res = np.array(snk.data()) # make sure output is a multiple of average_len! tags = snk.tags() p = tags[0].offset self.assertEqual(p, 0) v = pmt.to_long(tags[0].value) fl = frame_len + 2 * backoff_len self.assertEqual(int(v), int(fl)) self.assertComplexTuplesAlmostEqual(res[0:len(test_frame)], test_frame)