def test_002_commutator(self): # check if commutator works correctly. multiple = 10 L = 4 taps = np.ones(L) # initialize UUT and check results self.smt = fbmc.rx_polyphase_cvc(taps, L) # print "test2 generate data" d = np.arange(1, multiple * L // 2 + 1 + 1, dtype=np.complex) self.src = blocks.vector_source_c(d, vlen=1) self.snk = blocks.vector_sink_c(vlen=L) self.tb.connect(self.src, self.smt, self.snk) self.tb.run() # check data res = self.snk.data() resmatrix = np.array(res).reshape((-1, L)).T print resmatrix print ref = ft.rx(d[: -L // 2], taps, L) print ref self.assertComplexTuplesAlmostEqual(ref.flatten(), resmatrix.flatten())
def test_002_commutator(self): # check if commutator works correctly. multiple = 10 L = 4 taps = np.ones(L) # initialize UUT and check results self.smt = fbmc.rx_polyphase_cvc(taps, L) # print "test2 generate data" d = np.arange(1, multiple * L // 2 + 1 + 1, dtype=np.complex) self.src = blocks.vector_source_c(d, vlen=1) self.snk = blocks.vector_sink_c(vlen=L) self.tb.connect(self.src, self.smt, self.snk) self.tb.run() # check data res = self.snk.data() resmatrix = np.array(res).reshape((-1, L)).T print resmatrix print ref = ft.rx(d[:-L // 2], taps, L) print ref self.assertComplexTuplesAlmostEqual(ref.flatten(), resmatrix.flatten())
def test_005_python_gen(self): # check results against Python implementation print "\n\n\n\nlegacy" multiple = 10 overlap = 4 L = 4 self.cfg = fbmc.fbmc_config(num_used_subcarriers=20, num_payload_sym=16, num_overlap_sym=overlap, modulation="QPSK", preamble="IAM") L = self.cfg.num_total_subcarriers() taps = np.array(self.cfg.prototype_taps_float(), dtype=np.float) print "config: overlap = ", overlap, ", L = ", L # generate data and set it for source. d = np.arange(1, multiple * L // 2 + 1 + 1, dtype=np.complex) self.src = blocks.vector_source_c(d, vlen=1) self.smt = fbmc.rx_polyphase_cvc(taps, L) self.snk0 = blocks.vector_sink_c(vlen=L) self.tb.connect(self.src, self.smt, self.snk0) self.tb.run() # same way to generate data in python as in every test! ref = ft.rx(d[:-L // 2], taps, L) res0 = self.snk0.data() resultMatrix = np.array(res0).reshape((-1, L)).T print resultMatrix[:, 0:5] print np.shape(resultMatrix[:, 0:5]) print L * resultMatrix[0] print "ref", ref[0]
def test_005_python_gen(self): # check results against Python implementation print "\n\n\n\nlegacy" multiple = 10 overlap = 4 L = 4 self.cfg = fbmc.fbmc_config(num_used_subcarriers=20, num_payload_sym=16, num_overlap_sym=overlap, modulation="QPSK", preamble="IAM") L = self.cfg.num_total_subcarriers() taps = np.array(self.cfg.prototype_taps_float(), dtype=np.float) print "config: overlap = ", overlap, ", L = ", L # generate data and set it for source. d = np.arange(1, multiple * L // 2 + 1 + 1, dtype=np.complex) self.src = blocks.vector_source_c(d, vlen=1) self.smt = fbmc.rx_polyphase_cvc(taps, L) self.snk0 = blocks.vector_sink_c(vlen=L) self.tb.connect(self.src, self.smt, self.snk0) self.tb.run() # same way to generate data in python as in every test! ref = ft.rx(d[: -L // 2], taps, L) res0 = self.snk0.data() resultMatrix = np.array(res0).reshape((-1, L)).T print resultMatrix[:, 0:5] print np.shape(resultMatrix[:, 0:5]) print L * resultMatrix[0] print "ref", ref[0]
def test_003_go_big(self): print "test_003_go_big -> try out!" # set up fg L = 32 overlap = 4 multiple = 8 taps = ft.prototype_fsamples(overlap, False) print taps # data = np.arange(1, multiple * L + 1, dtype=np.complex) data = np.zeros(L, dtype=np.complex) data[0] = np.complex(1, 0) data[L / 2] = np.complex(1, 0) data[L / 4] = np.complex(1, -1) data[L / 8] = np.complex(1, 0) data[3 * L / 4] = np.complex(1, 1) # print data # print np.reshape(data, (L, -1)) data = np.repeat(np.reshape(data, (L, -1)), multiple, axis=1) data = data.T.flatten()#np.reshape(data, (L, -1)) print "shape(data) = ", np.shape(data) # print data # get blocks for test src = blocks.vector_source_c(data, vlen=1) rx_domain = fbmc.rx_domain_cvc(taps.tolist(), L) impulse_taps = ft.generate_phydyas_filter(L, overlap) print "fft_size: ", rx_domain.fft_size() snk = blocks.vector_sink_c(vlen=L) pfb = fbmc.rx_polyphase_cvc(impulse_taps.tolist(), L) snk1 = blocks.vector_sink_c(vlen=L) # connect and run self.tb.connect(src, rx_domain, snk) self.tb.connect(src, pfb, snk1) self.tb.run() # check data ref = ft.rx_fdomain(data, taps, L).T.flatten() res = np.array(snk.data()) res1 = np.array(snk1.data()) # print "ref: ", np.shape(ref) # print "res: ", np.shape(res) # print np.reshape(res, (-1, L)).T # mat1 = np.reshape(res1, (L, -1)).T # print np.shape(mat1) self.assertComplexTuplesAlmostEqual(ref, res, 5)
def test_003_go_big(self): print "test_003_go_big -> try out!" # set up fg L = 32 overlap = 4 multiple = 8 taps = ft.prototype_fsamples(overlap, False) print taps # data = np.arange(1, multiple * L + 1, dtype=np.complex) data = np.zeros(L, dtype=np.complex) data[0] = np.complex(1, 0) data[L / 2] = np.complex(1, 0) data[L / 4] = np.complex(1, -1) data[L / 8] = np.complex(1, 0) data[3 * L / 4] = np.complex(1, 1) # print data # print np.reshape(data, (L, -1)) data = np.repeat(np.reshape(data, (L, -1)), multiple, axis=1) data = data.T.flatten() #np.reshape(data, (L, -1)) print "shape(data) = ", np.shape(data) # print data # get blocks for test src = blocks.vector_source_c(data, vlen=1) rx_domain = fbmc.rx_domain_cvc(taps.tolist(), L) impulse_taps = ft.generate_phydyas_filter(L, overlap) print "fft_size: ", rx_domain.fft_size() snk = blocks.vector_sink_c(vlen=L) pfb = fbmc.rx_polyphase_cvc(impulse_taps.tolist(), L) snk1 = blocks.vector_sink_c(vlen=L) # connect and run self.tb.connect(src, rx_domain, snk) self.tb.connect(src, pfb, snk1) self.tb.run() # check data ref = ft.rx_fdomain(data, taps, L).T.flatten() res = np.array(snk.data()) res1 = np.array(snk1.data()) # print "ref: ", np.shape(ref) # print "res: ", np.shape(res) # print np.reshape(res, (-1, L)).T # mat1 = np.reshape(res1, (L, -1)).T # print np.shape(mat1) self.assertComplexTuplesAlmostEqual(ref, res, 5)
def test_001_t(self): # test if input-output ratio is correct multiple = 100 L = 16 overlap = 4 taps = range(overlap * L + 1) d = range(L * multiple) # set up fg self.src = blocks.vector_source_c(d, vlen=1) self.smt = fbmc.rx_polyphase_cvc(taps, L) self.snk = blocks.vector_sink_c(vlen=L) self.tb.connect(self.src, self.smt, self.snk) self.tb.run() # check data res = self.snk.data() self.assertTrue(len(res), len(d) * 2)
def test_004_legacy_big(self): np.set_printoptions(linewidth=150, precision=4) multiple = 4 overlap = 4 self.cfg = fbmc.fbmc_config(num_used_subcarriers=20, num_payload_sym=16, num_overlap_sym=overlap, modulation="QPSK", preamble="IAM") L = self.cfg.num_total_subcarriers() taps = np.array(self.cfg.prototype_taps_float(), dtype=np.float) # test data! d = np.arange(1, multiple * L // 2 + 1 + 1, dtype=np.complex) # initialize fg smt = fbmc.rx_polyphase_cvc(taps, L) self.src = blocks.vector_source_c(d, vlen=1) self.snk = blocks.vector_sink_c(vlen=L) # old chain self.com = fbmc.input_commutator_cvc(L) self.pfb = fbmc.polyphase_filterbank_vcvc(L, taps) self.fft = fft.fft_vcc(L, False, (), False, 1) self.snkold = blocks.vector_sink_c(vlen=L) self.tb.connect(self.src, self.com, self.pfb, self.fft, self.snkold) self.tb.connect(self.src, smt, self.snk) self.tb.run() # check data res = self.snk.data() resmatrix = np.array(res).reshape((-1, L)).T old = self.snkold.data() oldmatrix = np.array(old).reshape((-1, L)).T print np.array(smt.filterbank_taps()) print "\nresult" print resmatrix print "\nold fg" print oldmatrix self.assertComplexTuplesAlmostEqual(oldmatrix.flatten(), resmatrix.flatten())
def test_005_legacy(self): print "\ntest_005_legacy" # test if flowgraph is set up as expected! multiple = 9 overlap = 4 L = 32 taps = ft.generate_phydyas_filter(L, overlap) data = np.arange(1, multiple * L // 2 + 1 + 1, dtype=np.complex) # instatiated blocks and flowgraph phydyas = fbmc.rx_sdft_cvc(taps, L) pfb = fbmc.rx_polyphase_cvc(taps, L) print "phydyas: L = ", phydyas.L(), ", overlap = ", phydyas.overlap() src = blocks.vector_source_c(data, vlen=1) snk0 = blocks.vector_sink_c(L) snk1 = blocks.vector_sink_c(L) tb = gr.top_block() tb.connect(src, phydyas, snk0) tb.connect(src, pfb, snk1) # run fg and get results tb.run() res0 = np.array(snk0.data()) res1 = np.array(snk1.data()) ref = self.get_reference_output(data, taps, L, overlap, multiple) ftref = ft.rx(data[:-L // 2], taps, L) print "\nFBMC blocks" print ftref lcut = 2 rcut = 5 print "\nGR blocks" print res0[lcut * L:-rcut * L].reshape((-1, L)).T print "\nIOTA blocks" print res1[8 * L:].reshape((-1, L)).T ftref = ftref.T ftref = ftref.flatten() self.assertComplexTuplesAlmostEqual(ftref, res0[lcut * L:-rcut * L], 3) self.assertComplexTuplesAlmostEqual(ftref, res1[8 * L:], 3)
def test_005_legacy(self): print "\ntest_005_legacy" # test if flowgraph is set up as expected! multiple = 9 overlap = 4 L = 32 taps = ft.generate_phydyas_filter(L, overlap) data = np.arange(1, multiple * L // 2 + 1 + 1, dtype=np.complex) # instatiated blocks and flowgraph phydyas = fbmc.rx_sdft_cvc(taps, L) pfb = fbmc.rx_polyphase_cvc(taps, L) print "phydyas: L = ", phydyas.L(), ", overlap = ", phydyas.overlap() src = blocks.vector_source_c(data, vlen=1) snk0 = blocks.vector_sink_c(L) snk1 = blocks.vector_sink_c(L) tb = gr.top_block() tb.connect(src, phydyas, snk0) tb.connect(src, pfb, snk1) # run fg and get results tb.run() res0 = np.array(snk0.data()) res1 = np.array(snk1.data()) ref = self.get_reference_output(data, taps, L, overlap, multiple) ftref = ft.rx(data[: -L // 2], taps, L) print "\nFBMC blocks" print ftref lcut = 2 rcut = 5 print "\nGR blocks" print res0[lcut * L: -rcut * L].reshape((-1, L)).T print "\nIOTA blocks" print res1[8 * L:].reshape((-1, L)).T ftref = ftref.T ftref = ftref.flatten() self.assertComplexTuplesAlmostEqual(ftref, res0[lcut * L: -rcut * L], 3) self.assertComplexTuplesAlmostEqual(ftref, res1[8 * L:], 3)
def test_003_legacy_small(self): multiple = 10 L = 4 taps = np.append(np.ones(L), 0.5 * np.ones(L)) # test data! d = np.arange(1, multiple * L // 2 + 1 + 1, dtype=np.complex) # initialize fg smt = fbmc.rx_polyphase_cvc(taps, L) self.src = blocks.vector_source_c(d, vlen=1) self.snk = blocks.vector_sink_c(vlen=L) # old chain self.com = fbmc.input_commutator_cvc(L) self.pfb = fbmc.polyphase_filterbank_vcvc(L, taps) self.fft = fft.fft_vcc(L, False, (), False, 1) self.snkold = blocks.vector_sink_c(vlen=L) self.tb.connect(self.src, self.com, self.pfb, self.fft, self.snkold) self.tb.connect(self.src, smt, self.snk) self.tb.run() # check data res = self.snk.data() resmatrix = np.array(res).reshape((-1, L)).T old = self.snkold.data() oldmatrix = np.array(old).reshape((-1, L)).T print np.array(smt.filterbank_taps()) print "\nresult" print resmatrix print "\nold" print oldmatrix self.assertComplexTuplesAlmostEqual(oldmatrix.flatten(), resmatrix.flatten())
def test_004_kernel(self): L = 32 overlap = 4 multiple = 1 * overlap taps = ft.prototype_fsamples(overlap, False) impulse_taps = ft.generate_phydyas_filter(L, overlap) print taps kernel = fbmc.rx_domain_kernel(taps.tolist(), L) pfbk = fbmc.rx_polyphase_cvc(impulse_taps.tolist(), L) rsdftk = fbmc.rx_sdft_kernel(impulse_taps.tolist(), L) tsdftk = fbmc.tx_sdft_kernel(impulse_taps.tolist(), L) print "L = ", kernel.L() print "overlap = ", kernel.overlap() print "fft_size = ", kernel.fft_size() # print "taps = ", kernel.taps() kernel_taps = kernel.taps() pfb_taps = pfbk.filterbank_taps() # print "pfb taps = ", pfbk.filterbank_taps() data = np.arange(1, L * multiple + 1, dtype=complex) # print data res = kernel.generic_work_python(data) print len(res)