def test_add_fc32(self): tb = gr.top_block() src0 = blocks.vector_source_c([1, 3j, 5, 7j, 9], False) src1 = blocks.vector_source_c([0, 2j, 4, 6j, 8], False) adder = add_2_fc32_1_fc32() sink = blocks.vector_sink_c() tb.connect((src0, 0), (adder, 0)) tb.connect((src1, 0), (adder, 1)) tb.connect(adder, sink) tb.run() self.assertEqual(sink.data(), (1, 5j, 9, 13j, 17))
def test04(self): # QPSK Convergence test with static rotation natfreq = 0.25 order = 4 self.test = digital.costas_loop_cc(natfreq, order) rot = cmath.exp(0.2j) # some small rotation data = [complex(2*random.randint(0,1)-1, 2*random.randint(0,1)-1) for i in xrange(100)] N = 40 # settling time expected_result = data[N:] data = [rot*d for d in data] self.src = blocks.vector_source_c(data, False) self.snk = blocks.vector_sink_c() self.tb.connect(self.src, self.test, self.snk) self.tb.run() dst_data = self.snk.data()[N:] # generously compare results; the loop will converge near to, but # not exactly on, the target data self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 2)
def transform(self, src_data): SRC = blocks.vector_source_c(src_data, False) EQU = digital.cma_equalizer_cc(4, 1.0, .001, 1) DST = blocks.vector_sink_c() self.tb.connect(SRC, EQU, DST) self.tb.run() return DST.data()
def test_fir_filter_ccf_002(self): self.generate_ccf_source() expected_data = ((6.419439159799367e-05-0.0006292851758189499j), (-0.00037074743886478245+0.0013245552545413375j), (0.0006853155209682882-0.0023769831750541925j), (-0.001427714480087161+0.002608160488307476j), (0.0015907397028058767-0.000811046629678458j), (-0.0004226673918310553-0.0024389736354351044j), (-0.0013841050677001476+0.006231029983609915j), (0.0035029184073209763-0.009738259017467499j), (-0.005924836732447147+0.010320881381630898j), (0.006831614300608635-0.003950652200728655j), (-0.0021247887052595615-0.015604906715452671j), (-0.04283163696527481+0.09995654970407486j), (-0.01391829177737236+0.07924056798219681j), (0.010886997915804386-0.02463012933731079j), (-0.0056075905449688435+0.004998659715056419j), (0.0016976913902908564+0.004312459379434586j), (0.0007344821933656931-0.007861112244427204j), (-0.002173811662942171+0.007211671676486731j), (0.0022051059640944004-0.00402153329923749j), (-0.0011226903880015016+0.0009080505697056651j)) src = blocks.vector_source_c(self.src_data) op = filter.freq_xlating_fir_filter_ccf(4, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
def test_002_cc(self): N = 10000 # number of samples to use fs = 1000 # baseband sampling rate rrate = 1.123 # resampling rate freq = 10 data = sig_source_c(fs, freq, 1, N) signal = blocks.vector_source_c(data) op = filter.fractional_resampler_cc(0.0, rrate) snk = blocks.vector_sink_c() self.tb.connect(signal, op, snk) self.tb.run() Ntest = 5000 L = len(snk.data()) t = map(lambda x: float(x)/(fs/rrate), xrange(L)) phase = 0.1884 expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \ 1j*math.sin(2.*math.pi*freq*x+phase), t) dst_data = snk.data() self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
def test_fir_filter_ccf_002(self): self.generate_ccf_source() expected_data = ((6.419439159799367e-05 - 0.0006292851758189499j), (-0.00037074743886478245 + 0.0013245552545413375j), (0.0006853155209682882 - 0.0023769831750541925j), (-0.001427714480087161 + 0.002608160488307476j), (0.0015907397028058767 - 0.000811046629678458j), (-0.0004226673918310553 - 0.0024389736354351044j), (-0.0013841050677001476 + 0.006231029983609915j), (0.0035029184073209763 - 0.009738259017467499j), (-0.005924836732447147 + 0.010320881381630898j), (0.006831614300608635 - 0.003950652200728655j), (-0.0021247887052595615 - 0.015604906715452671j), (-0.04283163696527481 + 0.09995654970407486j), (-0.01391829177737236 + 0.07924056798219681j), (0.010886997915804386 - 0.02463012933731079j), (-0.0056075905449688435 + 0.004998659715056419j), (0.0016976913902908564 + 0.004312459379434586j), (0.0007344821933656931 - 0.007861112244427204j), (-0.002173811662942171 + 0.007211671676486731j), (0.0022051059640944004 - 0.00402153329923749j), (-0.0011226903880015016 + 0.0009080505697056651j)) src = blocks.vector_source_c(self.src_data) op = filter.freq_xlating_fir_filter_ccf(4, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
def test_fir_filter_ccc_002(self): self.generate_ccc_source() expected_data = ( (-0.000650451984257 + 0.00120697380044j), (-9.59713361226e-05 + 0.00102412770502j), (0.000958710326813 - 0.00145424995571j), (0.000901343999431 - 0.00290832063183j), (-0.000822560978122 + 0.000296717538731j), (-0.00211223773658 + 0.00519825471565j), (-0.00037001183955 + 0.00358242215589j), (0.00327983591706 - 0.00616005761549j), (0.00356886954978 - 0.0117237549275j), (-0.00328874029219 + 0.00182871113066j), (-0.0139285130426 + 0.0320657044649j), (-0.0198133718222 + 0.0562113076448j), (-0.0157803222537 + 0.0530290603638j), (-0.00550725404173 + 0.0255754813552j), (0.00252919178456 - 0.00232240976766j), (0.00368427345529 - 0.0114002330229j), (0.000506620621309 - 0.00402843113989j), (-0.00180401885882 + 0.00427213776857j), (-0.00122803344857 + 0.00427243299782j), (0.000414476031438 - 0.000383919978049j)) src = blocks.vector_source_c(self.src_data) op = filter.freq_xlating_fir_filter_ccc(4, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
def test_003_multiburst (self): """ Send several bursts, see if the number of detects is correct. Burst lengths and content are random. """ n_bursts = 42 fft_len = 32 cp_len = 4 tx_signal = [] for i in xrange(n_bursts): sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2 tx_signal += [0,] * random.randint(0, 2*fft_len) + \ sync_symbol[-cp_len:] + \ sync_symbol + \ [(random.randint(0, 1)*2)-1 for x in range(fft_len * random.randint(5,23))] add = blocks.add_cc() sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = blocks.vector_sink_f() sink_detect = blocks.vector_sink_b() channel = channels.channel_model(0.005) self.tb.connect(blocks.vector_source_c(tx_signal), channel, sync) self.tb.connect((sync, 0), sink_freq) self.tb.connect((sync, 1), sink_detect) self.tb.run() n_bursts_detected = numpy.sum(sink_detect.data()) # We allow for one false alarm or missed burst self.assertTrue(abs(n_bursts_detected - n_bursts) <= 1, msg="""Because of statistics, it is possible (though unlikely) that the number of detected bursts differs slightly. If the number of detects is off by one or two, run the test again and see what happen. Detection error was: %d """ % (numpy.sum(sink_detect.data()) - n_bursts) )
def test_fir_filter_ccc_002(self): self.generate_ccc_source() expected_data = ((-0.000650451984257+0.00120697380044j), (-9.59713361226e-05+0.00102412770502j), (0.000958710326813-0.00145424995571j), (0.000901343999431-0.00290832063183j), (-0.000822560978122+0.000296717538731j), (-0.00211223773658+0.00519825471565j), (-0.00037001183955+0.00358242215589j), (0.00327983591706-0.00616005761549j), (0.00356886954978-0.0117237549275j), (-0.00328874029219+0.00182871113066j), (-0.0139285130426+0.0320657044649j), (-0.0198133718222+0.0562113076448j), (-0.0157803222537+0.0530290603638j), (-0.00550725404173+0.0255754813552j), (0.00252919178456-0.00232240976766j), (0.00368427345529-0.0114002330229j), (0.000506620621309-0.00402843113989j), (-0.00180401885882+0.00427213776857j), (-0.00122803344857+0.00427243299782j), (0.000414476031438-0.000383919978049j)) src = blocks.vector_source_c(self.src_data) op = filter.freq_xlating_fir_filter_ccc(4, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
def test_quad_demod_001(self): f = 1000.0 fs = 8000.0 src_data = [] for i in xrange(200): ti = i/fs src_data.append(cmath.exp(2j*cmath.pi*f*ti)) # f/fs is a quarter turn per sample. # Set the gain based on this to get 1 out. gain = 1.0/(cmath.pi/4) expected_result = [0,] + 199*[1.0] src = blocks.vector_source_c(src_data) op = analog.quadrature_demod_cf(gain) dst = blocks.vector_sink_f() self.tb.connect(src, op) self.tb.connect(op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5)
def helper(self, v0, v1, fft_length, preamble): tb = self.tb src0 = blocks.vector_source_c(v0) src1 = blocks.vector_source_b(v1) s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, fft_length) # print "len(v) = %d" % (len(v)) op = digital.ofdm_insert_preamble(fft_length, preamble) v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, fft_length) dst0 = blocks.vector_sink_c() dst1 = blocks.vector_sink_b() tb.connect(src0, s2v, (op, 0)) tb.connect(src1, (op, 1)) tb.connect((op, 0), v2s, dst0) tb.connect((op, 1), dst1) tb.run() r0 = dst0.data() r0v = [] for i in range(len(r0) // fft_length): r0v.append(r0[i * fft_length:(i + 1) * fft_length]) r1 = dst1.data() self.assertEqual(len(r0v), len(r1)) return (r1, r0v)
def helper(self, v0, v1, fft_length, preamble): tb = self.tb src0 = blocks.vector_source_c(v0) src1 = blocks.vector_source_b(v1) s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, fft_length) # print "len(v) = %d" % (len(v)) op = digital.ofdm_insert_preamble(fft_length, preamble) v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, fft_length) dst0 = blocks.vector_sink_c() dst1 = blocks.vector_sink_b() tb.connect(src0, s2v, (op, 0)) tb.connect(src1, (op, 1)) tb.connect((op, 0), v2s, dst0) tb.connect((op, 1), dst1) tb.run() r0 = dst0.data() r0v = [] for i in range(len(r0)//fft_length): r0v.append(r0[i*fft_length:(i+1)*fft_length]) r1 = dst1.data() self.assertEqual(len(r0v), len(r1)) return (r1, r0v)
def test_002(self): data = range(1,9) self.src = blocks.vector_source_c(data) self.p1 = blocks.ctrlport_probe_c("aaa","C++ exported variable") self.p2 = blocks.ctrlport_probe_c("bbb","C++ exported variable") probe_name = self.p2.alias() self.tb.connect(self.src, self.p1) self.tb.connect(self.src, self.p2) self.tb.start() # Probes return complex values as list of floats with re, im # Imaginary parts of this data set are 0. expected_result = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0] # Make sure we have time for flowgraph to run time.sleep(0.1) # Get available endpoint ep = gr.rpcmanager_get().endpoints()[0] # Initialize a simple Ice client from endpoint ic = Ice.initialize(sys.argv) base = ic.stringToProxy(ep) radio = GNURadio.ControlPortPrx.checkedCast(base) # Get all exported knobs ret = radio.get([probe_name + "::bbb"]) for name in ret.keys(): result = ret[name].value self.assertEqual(result, expected_result) self.tb.stop()
def test_fir_filter_ccf_001(self): self.generate_ccf_source() expected_data = ((0.001697700354270637+0.004312471952289343j), (0.003520616563037038-0.003014103975147009j), (0.004252811893820763-0.008337559178471565j), (0.0030743128154426813-0.010262271389365196j), (0.0007344777695834637-0.007861139252781868j), (-0.0011067686136811972-0.0028924935031682253j), (-0.002371778478845954+0.0019914964213967323j), (-0.003023319412022829+0.005717850290238857j), (-0.0021738125942647457+0.007211698684841394j), (-0.0004628606839105487+0.005501383915543556j), (0.0007428556564264+0.0019867848604917526j), (0.001634795218706131-0.0013514887541532516j), (0.002205110155045986-0.00402155052870512j), (0.0015480631263926625-0.005179159343242645j), (0.00026722141774371266-0.003887997241690755j), (-0.0004911854630336165-0.0013578246580436826j), (-0.0011226939968764782+0.0009080552263185382j), (-0.0016229727771133184+0.0028335191309452057j), (-0.0010890064295381308+0.0037298379465937614j), (-0.00012392725329846144+0.0027196139562875032j)) src = blocks.vector_source_c(self.src_data) op = filter.freq_xlating_fir_filter_ccf(1, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
def test_005_packet_len_tag (self): """ Standard test """ fft_len = 16 tx_symbols = range(1, 16); tx_symbols = (0, 1, 1j, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 2j, 6, 0, 0, 7, 8, 3j, 9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0, 0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 2j, 0, 0) expected_result = tuple(range(1, 16)) occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),) n_syms = len(tx_symbols)/fft_len tag_name = "len" tag = gr.tag_t() tag.offset = 0 tag.key = pmt.string_to_symbol(tag_name) tag.value = pmt.from_long(n_syms) tag2 = gr.tag_t() tag2.offset = 0 tag2.key = pmt.string_to_symbol("packet_len") tag2.value = pmt.from_long(len(expected_result)) src = blocks.vector_source_c(tx_symbols, False, fft_len, (tag, tag2)) serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name, "packet_len", 0, "", False) sink = blocks.vector_sink_c() self.tb.connect(src, serializer, sink) self.tb.run () self.assertEqual(sink.data(), expected_result) self.assertEqual(len(sink.tags()), 1) result_tag = sink.tags()[0] self.assertEqual(pmt.symbol_to_string(result_tag.key), "packet_len") self.assertEqual(pmt.to_long(result_tag.value), len(expected_result))
def test_003_channel_no_carroffset(self): """ Add a channel, check if it's correctly estimated """ fft_len = 16 carr_offset = 0 sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0) sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0, 0) data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0) tx_data = sync_symbol1 + sync_symbol2 + data_symbol channel = (0, 0, 0, 2, -2, 2, 3j, 2, 0, 2, 2, 2, 2, 3, 0, 0) src = blocks.vector_source_c(tx_data, False, fft_len) chan = blocks.multiply_const_vcc(channel) chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1) sink = blocks.vector_sink_c(fft_len) sink_chanest = blocks.vector_sink_c(fft_len) self.tb.connect(src, chan, chanest, sink) self.tb.connect((chanest, 1), sink_chanest) self.tb.run() tags = sink.tags() self.assertEqual(shift_tuple(sink.data(), -carr_offset), tuple(numpy.multiply(data_symbol, channel))) for tag in tags: if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset': self.assertEqual(pmt.to_long(tag.value), carr_offset) if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': self.assertEqual(pmt.c32vector_elements(tag.value), channel) self.assertEqual(sink_chanest.data(), channel)
def test_fir_filter_ccc_001(self): self.generate_ccc_source() expected_data = ((0.0036842757836-0.0114002721384j), (0.00324621866457-0.0108166672289j), (0.00206564785913-0.00923090614378j), (0.00109899020754-0.00656201224774j), (0.000506619049702-0.00402844604105j), (-0.000523390364833-0.00166808743961j), (-0.00140534969978+0.00103991874494j), (-0.00154365820345+0.00315759982914j), (-0.00180402118713+0.00427215453237j), (-0.00216706306674+0.00524478312582j), (-0.00178848754149+0.0057489364408j), (-0.00129876169376+0.00512680830434j), (-0.00122803379782+0.00427244976163j), (-0.000722666736692+0.00351428100839j), (5.53092104383e-05+0.00207865727134j), (0.000227351076319+0.000517217209563j), (0.000414477253798-0.000383921898901j), (0.000998671515845-0.00135387131013j), (0.00104933069088-0.00243046949618j), (0.000765930046327-0.0026717747096j)) src = blocks.vector_source_c(self.src_data) op = filter.freq_xlating_fir_filter_ccc(1, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
def test_001_detect (self): """ Send two bursts, with zeros in between, and check they are both detected at the correct position and no false alarms occur """ n_zeros = 15 fft_len = 32 cp_len = 4 sig_len = (fft_len + cp_len) * 10 sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2 tx_signal = [0,] * n_zeros + \ sync_symbol[-cp_len:] + \ sync_symbol + \ [(random.randint(0, 1)*2)-1 for x in range(sig_len)] tx_signal = tx_signal * 2 add = blocks.add_cc() sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = blocks.vector_sink_f() sink_detect = blocks.vector_sink_b() self.tb.connect(blocks.vector_source_c(tx_signal), (add, 0)) self.tb.connect(analog.noise_source_c(analog.GR_GAUSSIAN, .01), (add, 1)) self.tb.connect(add, sync) self.tb.connect((sync, 0), sink_freq) self.tb.connect((sync, 1), sink_detect) self.tb.run() sig1_detect = sink_detect.data()[0:len(tx_signal)/2] sig2_detect = sink_detect.data()[len(tx_signal)/2:] self.assertTrue(abs(sig1_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len) self.assertTrue(abs(sig2_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len) self.assertEqual(numpy.sum(sig1_detect), 1) self.assertEqual(numpy.sum(sig2_detect), 1)
def test_006_channel_and_carroffset(self): """ Add a channel, check if it's correctly estimated """ fft_len = 16 carr_offset = 2 # Index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0) sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0, 0) data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0) # Channel 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # Shifted (0, 0, 0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1) chanest_exp = (0, 0, 0, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 0, 0) tx_data = shift_tuple(sync_symbol1, carr_offset) + \ shift_tuple(sync_symbol2, carr_offset) + \ shift_tuple(data_symbol, carr_offset) channel = range(fft_len) src = blocks.vector_source_c(tx_data, False, fft_len) chan = blocks.multiply_const_vcc(channel) chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1) sink = blocks.vector_sink_c(fft_len) self.tb.connect(src, chan, chanest, sink) self.tb.run() tags = sink.tags() chan_est = None for tag in tags: if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset': self.assertEqual(pmt.to_long(tag.value), carr_offset) if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': chan_est = pmt.c32vector_elements(tag.value) self.assertEqual(chan_est, chanest_exp) self.assertEqual( sink.data(), tuple( numpy.multiply(shift_tuple(data_symbol, carr_offset), channel)))
def test_with_tags_2s_rolloff(self): " With tags and a 2-sample rolloff " fft_len = 8 cp_len = 2 tag_name = "length" expected_result = (7.0/2, 8, 1, 2, 3, 4, 5, 6, 7, 8, # 1.0/2 7.0/2+1.0/2, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1.0/2) tag = gr.tag_t() tag.offset = 0 tag.key = pmt.string_to_symbol(tag_name) tag.value = pmt.from_long(2) tag2 = gr.tag_t() tag2.offset = 1 tag2.key = pmt.string_to_symbol("random_tag") tag2.value = pmt.from_long(42) src = blocks.vector_source_c(range(1, fft_len+1) * 2, False, fft_len, (tag, tag2)) cp = digital.ofdm_cyclic_prefixer(fft_len, fft_len + cp_len, 2, tag_name) sink = blocks.vector_sink_c() self.tb.connect(src, cp, sink) self.tb.run() self.assertEqual(sink.data(), expected_result) tags = [gr.tag_to_python(x) for x in sink.tags()] tags = sorted([(x.offset, x.key, x.value) for x in tags]) expected_tags = [ (0, tag_name, len(expected_result)), (fft_len+cp_len, "random_tag", 42) ] self.assertEqual(tags, expected_tags)
def transform(self, src_data, gain, const): SRC = blocks.vector_source_c(src_data, False) EQU = digital.lms_dd_equalizer_cc(4, gain, 1, const.base()) DST = blocks.vector_sink_c() self.tb.connect(SRC, EQU, DST) self.tb.run() return DST.data()
def test_fir_filter_ccc_001(self): self.generate_ccc_source() expected_data = ( (0.0036842757836 - 0.0114002721384j), (0.00324621866457 - 0.0108166672289j), (0.00206564785913 - 0.00923090614378j), (0.00109899020754 - 0.00656201224774j), (0.000506619049702 - 0.00402844604105j), (-0.000523390364833 - 0.00166808743961j), (-0.00140534969978 + 0.00103991874494j), (-0.00154365820345 + 0.00315759982914j), (-0.00180402118713 + 0.00427215453237j), (-0.00216706306674 + 0.00524478312582j), (-0.00178848754149 + 0.0057489364408j), (-0.00129876169376 + 0.00512680830434j), (-0.00122803379782 + 0.00427244976163j), (-0.000722666736692 + 0.00351428100839j), (5.53092104383e-05 + 0.00207865727134j), (0.000227351076319 + 0.000517217209563j), (0.000414477253798 - 0.000383921898901j), (0.000998671515845 - 0.00135387131013j), (0.00104933069088 - 0.00243046949618j), (0.000765930046327 - 0.0026717747096j)) src = blocks.vector_source_c(self.src_data) op = filter.freq_xlating_fir_filter_ccc(1, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
def test_003_channel_no_carroffset (self): """ Add a channel, check if it's correctly estimated """ fft_len = 16 carr_offset = 0 sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0) sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0, 0) data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0) tx_data = sync_symbol1 + sync_symbol2 + data_symbol channel = (0, 0, 0, 2, -2, 2, 3j, 2, 0, 2, 2, 2, 2, 3, 0, 0) src = blocks.vector_source_c(tx_data, False, fft_len) chan = blocks.multiply_const_vcc(channel) chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1) sink = blocks.vector_sink_c(fft_len) sink_chanest = blocks.vector_sink_c(fft_len) self.tb.connect(src, chan, chanest, sink) self.tb.connect((chanest, 1), sink_chanest) self.tb.run() tags = sink.tags() self.assertEqual(shift_tuple(sink.data(), -carr_offset), tuple(numpy.multiply(data_symbol, channel))) for tag in tags: if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset': self.assertEqual(pmt.to_long(tag.value), carr_offset) if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': self.assertEqual(pmt.c32vector_elements(tag.value), channel) self.assertEqual(sink_chanest.data(), channel)
def test_fir_filter_ccf_001(self): self.generate_ccf_source() expected_data = ((0.001697700354270637 + 0.004312471952289343j), (0.003520616563037038 - 0.003014103975147009j), (0.004252811893820763 - 0.008337559178471565j), (0.0030743128154426813 - 0.010262271389365196j), (0.0007344777695834637 - 0.007861139252781868j), (-0.0011067686136811972 - 0.0028924935031682253j), (-0.002371778478845954 + 0.0019914964213967323j), (-0.003023319412022829 + 0.005717850290238857j), (-0.0021738125942647457 + 0.007211698684841394j), (-0.0004628606839105487 + 0.005501383915543556j), (0.0007428556564264 + 0.0019867848604917526j), (0.001634795218706131 - 0.0013514887541532516j), (0.002205110155045986 - 0.00402155052870512j), (0.0015480631263926625 - 0.005179159343242645j), (0.00026722141774371266 - 0.003887997241690755j), (-0.0004911854630336165 - 0.0013578246580436826j), (-0.0011226939968764782 + 0.0009080552263185382j), (-0.0016229727771133184 + 0.0028335191309452057j), (-0.0010890064295381308 + 0.0037298379465937614j), (-0.00012392725329846144 + 0.0027196139562875032j)) src = blocks.vector_source_c(self.src_data) op = filter.freq_xlating_fir_filter_ccf(1, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data[-20:], 5)
def test_006_channel_and_carroffset (self): """ Add a channel, check if it's correctly estimated """ fft_len = 16 carr_offset = 2 # Index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0) sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0, 0) data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0) # Channel 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # Shifted (0, 0, 0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1) chanest_exp = (0, 0, 0, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 0, 0) tx_data = shift_tuple(sync_symbol1, carr_offset) + \ shift_tuple(sync_symbol2, carr_offset) + \ shift_tuple(data_symbol, carr_offset) channel = range(fft_len) src = blocks.vector_source_c(tx_data, False, fft_len) chan = blocks.multiply_const_vcc(channel) chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1) sink = blocks.vector_sink_c(fft_len) self.tb.connect(src, chan, chanest, sink) self.tb.run() tags = sink.tags() chan_est = None for tag in tags: if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset': self.assertEqual(pmt.to_long(tag.value), carr_offset) if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': chan_est = pmt.c32vector_elements(tag.value) self.assertEqual(chan_est, chanest_exp) self.assertEqual(sink.data(), tuple(numpy.multiply(shift_tuple(data_symbol, carr_offset), channel)))
def test04(self): # QPSK Convergence test with static rotation natfreq = 0.25 order = 4 self.test = digital.costas_loop_cc(natfreq, order) rot = cmath.exp(0.2j) # some small rotation data = [ complex(2 * random.randint(0, 1) - 1, 2 * random.randint(0, 1) - 1) for i in xrange(100) ] N = 40 # settling time expected_result = data[N:] data = [rot * d for d in data] self.src = blocks.vector_source_c(data, False) self.snk = blocks.vector_sink_c() self.tb.connect(self.src, self.test, self.snk) self.tb.run() dst_data = self.snk.data()[N:] # generously compare results; the loop will converge near to, but # not exactly on, the target data self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 2)
def run_flow_graph(sync_sym1, sync_sym2, data_sym): top_block = gr.top_block() carr_offset = random.randint(-max_offset/2, max_offset/2) * 2 tx_data = shift_tuple(sync_sym1, carr_offset) + \ shift_tuple(sync_sym2, carr_offset) + \ shift_tuple(data_sym, carr_offset) channel = [rand_range(min_chan_ampl, max_chan_ampl) * numpy.exp(1j * rand_range(0, 2 * numpy.pi)) for x in range(fft_len)] src = blocks.vector_source_c(tx_data, False, fft_len) chan = blocks.multiply_const_vcc(channel) noise = analog.noise_source_c(analog.GR_GAUSSIAN, wgn_amplitude) add = blocks.add_cc(fft_len) chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1) sink = blocks.vector_sink_c(fft_len) top_block.connect(src, chan, (add, 0), chanest, sink) top_block.connect(noise, blocks.stream_to_vector(gr.sizeof_gr_complex, fft_len), (add, 1)) top_block.run() channel_est = None carr_offset_hat = 0 rx_sym_est = [0,] * fft_len tags = sink.tags() for tag in tags: if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset': carr_offset_hat = pmt.to_long(tag.value) self.assertEqual(carr_offset, carr_offset_hat) if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': channel_est = shift_tuple(pmt.c32vector_elements(tag.value), carr_offset) shifted_carrier_mask = shift_tuple(carrier_mask, carr_offset) for i in range(fft_len): if shifted_carrier_mask[i] and channel_est[i]: self.assertAlmostEqual(channel[i], channel_est[i], places=0) rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real return (carr_offset, list(shift_tuple(rx_sym_est, -carr_offset_hat)))
def test05(self): # 8PSK Convergence test with static rotation natfreq = 0.25 order = 8 self.test = digital.costas_loop_cc(natfreq, order) rot = cmath.exp(-cmath.pi/8.0j) # rotate to match Costas rotation const = psk.psk_constellation(order) data = [random.randint(0,7) for i in xrange(100)] data = [2*rot*const.points()[d] for d in data] N = 40 # settling time expected_result = data[N:] rot = cmath.exp(0.1j) # some small rotation data = [rot*d for d in data] self.src = blocks.vector_source_c(data, False) self.snk = blocks.vector_sink_c() self.tb.connect(self.src, self.test, self.snk) self.tb.run() dst_data = self.snk.data()[N:] # generously compare results; the loop will converge near to, but # not exactly on, the target data self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 2)
def test_001_t (self): """ pretty simple (the carrier allocation is not a practical OFDM configuration!) """ fft_len = 6 tx_symbols = (1, 2, 3) # ^ this gets mapped to the DC carrier because occupied_carriers[0][0] == 0 pilot_symbols = ((1j,),) occupied_carriers = ((0, 1, 2),) pilot_carriers = ((3,),) sync_word = (range(fft_len),) expected_result = tuple(sync_word[0] + [1j, 0, 0, 1, 2, 3]) # ^ DC carrier tag_name = "len" tag = gr.tag_t() tag.offset = 0 tag.key = pmt.string_to_symbol(tag_name) tag.value = pmt.from_long(len(tx_symbols)) src = blocks.vector_source_c(tx_symbols, False, 1, (tag,)) alloc = digital.ofdm_carrier_allocator_cvc(fft_len, occupied_carriers, pilot_carriers, pilot_symbols, sync_word, tag_name) sink = blocks.vector_sink_c(fft_len) self.tb.connect(src, alloc, sink) self.tb.run () self.assertEqual(sink.data(), expected_result)
def test_001_t2 (self): """ pretty simple (same as before, but odd fft len) """ fft_len = 5 tx_symbols = (1, 2, 3) # ^ this gets mapped to the DC carrier because occupied_carriers[0][0] == 0 occupied_carriers = ((0, 1, 2),) pilot_carriers = ((-2,),) pilot_symbols = ((1j,),) expected_result = (1j, 0, 1, 2, 3) # ^ DC carrier tag_name = "len" tag = gr.tag_t() tag.offset = 0 tag.key = pmt.string_to_symbol(tag_name) tag.value = pmt.from_long(len(tx_symbols)) src = blocks.vector_source_c(tx_symbols, False, 1, (tag,)) alloc = digital.ofdm_carrier_allocator_cvc(fft_len, occupied_carriers, pilot_carriers, pilot_symbols, (), tag_name) sink = blocks.vector_sink_c(fft_len) self.tb.connect(src, alloc, sink) self.tb.run () self.assertEqual(sink.data(), expected_result)
def test_002_t (self): """ same, but using negative carrier indices """ fft_len = 6 tx_symbols = (1, 2, 3) pilot_symbols = ((1j,),) occupied_carriers = ((-1, 1, 2),) pilot_carriers = ((3,),) expected_result = (1j, 0, 1, 0, 2, 3) tag_name = "len" tag = gr.tag_t() tag.offset = 0 tag.key = pmt.string_to_symbol(tag_name) tag.value = pmt.from_long(len(tx_symbols)) src = blocks.vector_source_c(tx_symbols, False, 1, (tag,)) alloc = digital.ofdm_carrier_allocator_cvc(fft_len, occupied_carriers, pilot_carriers, pilot_symbols, (), tag_name) sink = blocks.vector_sink_c(fft_len) self.tb.connect(src, alloc, sink) self.tb.run () self.assertEqual(sink.data(), expected_result)
def test_004_channel_no_carroffset_1sym(self): """ Add a channel, check if it's correctly estimated. Only uses 1 synchronisation symbol. """ fft_len = 16 carr_offset = 0 sync_symbol = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0) data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0) tx_data = sync_symbol + data_symbol channel = (0, 0, 0, 2, 2, 2, 2, 3, 3, 2.5, 2.5, -3, -3, 1j, 1j, 0) #channel = (0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0) src = blocks.vector_source_c(tx_data, False, fft_len) chan = blocks.multiply_const_vcc(channel) chanest = digital.ofdm_chanest_vcvc(sync_symbol, (), 1) sink = blocks.vector_sink_c(fft_len) sink_chanest = blocks.vector_sink_c(fft_len) self.tb.connect(src, chan, chanest, sink) self.tb.connect((chanest, 1), sink_chanest) self.tb.run() self.assertEqual(sink_chanest.data(), channel) tags = sink.tags() for tag in tags: if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset': self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset) if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': self.assertEqual(pmt.pmt_c32vector_elements(tag.value), channel)
def test_002_static_wo_tags (self): fft_len = 8 # 4 5 6 7 0 1 2 3 tx_data = [-1, -1, 1, 2, -1, 3, 0, -1, # 0 -1, -1, 0, 2, -1, 2, 0, -1, # 8 -1, -1, 3, 0, -1, 1, 0, -1, # 16 (Pilot symbols) -1, -1, 1, 1, -1, 0, 2, -1] # 24 cnst = digital.constellation_qpsk() tx_signal = [cnst.map_to_points_v(x)[0] if x != -1 else 0 for x in tx_data] occupied_carriers = ((1, 2, 6, 7),) pilot_carriers = ((), (), (1, 2, 6, 7), ()) pilot_symbols = ( [], [], [cnst.map_to_points_v(x)[0] for x in (1, 0, 3, 0)], [] ) equalizer = digital.ofdm_equalizer_static(fft_len, occupied_carriers, pilot_carriers, pilot_symbols) channel = [ 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, # These coefficients will be rotated slightly... 0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here! 0, 0, 1j, 1j, 0, 1j, 1j, 0 # ...and again here. ] for idx in range(fft_len, 2*fft_len): channel[idx] = channel[idx-fft_len] * numpy.exp(1j * .1 * numpy.pi * (numpy.random.rand()-.5)) idx2 = idx+2*fft_len channel[idx2] = channel[idx2] * numpy.exp(1j * 0 * numpy.pi * (numpy.random.rand()-.5)) src = blocks.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len) sink = blocks.vector_sink_c(fft_len) eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, "", False, 4) self.tb.connect(src, eq, sink) self.tb.run () rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()] self.assertEqual(tx_data, rx_data)
def test_001b_shifted (self): """ Same as before, but shifted, because that's the normal mode in OFDM Rx """ fft_len = 16 tx_symbols = ( 0, 0, 0, 0, 0, 0, 1, 2, 0, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 6, 1j, 7, 8, 0, 9, 10, 1j, 11, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 0, 15, 16, 17, 0, 0, 0, 0, ) expected_result = tuple(range(18)) occupied_carriers = ((13, 14, 15, 1, 2, 3), (-4, -2, -1, 1, 2, 4),) n_syms = len(tx_symbols)/fft_len tag_name = "len" tag = gr.tag_t() tag.offset = 0 tag.key = pmt.string_to_symbol(tag_name) tag.value = pmt.from_long(n_syms) src = blocks.vector_source_c(tx_symbols, False, fft_len, (tag,)) serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name) sink = blocks.vector_sink_c() self.tb.connect(src, serializer, sink) self.tb.run () self.assertEqual(sink.data(), expected_result) self.assertEqual(len(sink.tags()), 1) result_tag = sink.tags()[0] self.assertEqual(pmt.symbol_to_string(result_tag.key), tag_name) self.assertEqual(pmt.to_long(result_tag.value), n_syms * len(occupied_carriers[0]))
def test05(self): # 8PSK Convergence test with static rotation natfreq = 0.25 order = 8 self.test = digital.costas_loop_cc(natfreq, order) rot = cmath.exp(-cmath.pi / 8.0j) # rotate to match Costas rotation const = psk.psk_constellation(order) data = [random.randint(0, 7) for i in xrange(100)] data = [2 * rot * const.points()[d] for d in data] N = 40 # settling time expected_result = data[N:] rot = cmath.exp(0.1j) # some small rotation data = [rot * d for d in data] self.src = blocks.vector_source_c(data, False) self.snk = blocks.vector_sink_c() self.tb.connect(self.src, self.test, self.snk) self.tb.run() dst_data = self.snk.data()[N:] # generously compare results; the loop will converge near to, but # not exactly on, the target data self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 2)
def test_ccf_000(self): N = 1000 # number of samples to use fs = 1000 # baseband sampling rate rrate = 1.123 # resampling rate nfilts = 32 taps = filter.firdes.low_pass_2( nfilts, nfilts * fs, fs / 2, fs / 10, attenuation_dB=80, window=filter.firdes.WIN_BLACKMAN_hARRIS) freq = 100 data = sig_source_c(fs, freq, 1, N) signal = blocks.vector_source_c(data) pfb = filter.pfb_arb_resampler_ccf(rrate, taps) snk = blocks.vector_sink_c() self.tb.connect(signal, pfb, snk) self.tb.run() Ntest = 50 L = len(snk.data()) t = map(lambda x: float(x) / (fs * rrate), xrange(L)) phase = 0.53013 expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \ 1j*math.sin(2.*math.pi*freq*x+phase), t) dst_data = snk.data() self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
def test_wo_tags_2s_rolloff(self): " No tags, but have a 2-sample rolloff " fft_len = 8 cp_len = 2 rolloff = 2 expected_result = ( 7.0 / 2, 8, 1, 2, 3, 4, 5, 6, 7, 8, # 1.0/2 7.0 / 2 + 1.0 / 2, 8, 1, 2, 3, 4, 5, 6, 7, 8) src = blocks.vector_source_c(range(1, fft_len + 1) * 2, False, fft_len) cp = digital.ofdm_cyclic_prefixer(fft_len, fft_len + cp_len, rolloff) sink = blocks.vector_sink_c() self.tb.connect(src, cp, sink) self.tb.run() self.assertEqual(sink.data(), expected_result)
def test_001_detect(self): """ Send two bursts, with zeros in between, and check they are both detected at the correct position and no false alarms occur """ n_zeros = 15 fft_len = 32 cp_len = 4 sig_len = (fft_len + cp_len) * 10 sync_symbol = [(random.randint(0, 1) * 2) - 1 for x in range(fft_len / 2)] * 2 tx_signal = [0,] * n_zeros + \ sync_symbol[-cp_len:] + \ sync_symbol + \ [(random.randint(0, 1)*2)-1 for x in range(sig_len)] tx_signal = tx_signal * 2 add = blocks.add_cc() sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = blocks.vector_sink_f() sink_detect = blocks.vector_sink_b() self.tb.connect(blocks.vector_source_c(tx_signal), (add, 0)) self.tb.connect(analog.noise_source_c(analog.GR_GAUSSIAN, .01), (add, 1)) self.tb.connect(add, sync) self.tb.connect((sync, 0), sink_freq) self.tb.connect((sync, 1), sink_detect) self.tb.run() sig1_detect = sink_detect.data()[0:len(tx_signal) / 2] sig2_detect = sink_detect.data()[len(tx_signal) / 2:] self.assertTrue( abs(sig1_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len) self.assertTrue( abs(sig2_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len) self.assertEqual(numpy.sum(sig1_detect), 1) self.assertEqual(numpy.sum(sig2_detect), 1)
def test_quad_demod_001(self): f = 1000.0 fs = 8000.0 src_data = [] for i in xrange(200): ti = i / fs src_data.append(cmath.exp(2j * cmath.pi * f * ti)) # f/fs is a quarter turn per sample. # Set the gain based on this to get 1 out. gain = 1.0 / (cmath.pi / 4) expected_result = [ 0, ] + 199 * [1.0] src = blocks.vector_source_c(src_data) op = analog.quadrature_demod_cf(gain) dst = blocks.vector_sink_f() self.tb.connect(src, op) self.tb.connect(op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5)
def test_002(self): data = range(1, 9) self.src = blocks.vector_source_c(data) self.p1 = blocks.ctrlport_probe_c("aaa", "C++ exported variable") self.p2 = blocks.ctrlport_probe_c("bbb", "C++ exported variable") probe_name = self.p2.alias() self.tb.connect(self.src, self.p1) self.tb.connect(self.src, self.p2) self.tb.start() # Probes return complex values as list of floats with re, im # Imaginary parts of this data set are 0. expected_result = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0] # Make sure we have time for flowgraph to run time.sleep(0.1) # Get available endpoint ep = gr.rpcmanager_get().endpoints()[0] # Initialize a simple Ice client from endpoint ic = Ice.initialize(sys.argv) base = ic.stringToProxy(ep) radio = GNURadio.ControlPortPrx.checkedCast(base) # Get all exported knobs ret = radio.get([probe_name + "::bbb"]) for name in ret.keys(): result = ret[name].value self.assertEqual(result, expected_result) self.tb.stop()
def test_003_multiburst(self): """ Send several bursts, see if the number of detects is correct. Burst lengths and content are random. """ n_bursts = 42 fft_len = 32 cp_len = 4 tx_signal = [] for i in xrange(n_bursts): sync_symbol = [(random.randint(0, 1) * 2) - 1 for x in range(fft_len / 2)] * 2 tx_signal += [0,] * random.randint(0, 2*fft_len) + \ sync_symbol[-cp_len:] + \ sync_symbol + \ [(random.randint(0, 1)*2)-1 for x in range(fft_len * random.randint(5,23))] add = blocks.add_cc() sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = blocks.vector_sink_f() sink_detect = blocks.vector_sink_b() channel = channels.channel_model(0.005) self.tb.connect(blocks.vector_source_c(tx_signal), channel, sync) self.tb.connect((sync, 0), sink_freq) self.tb.connect((sync, 1), sink_detect) self.tb.run() n_bursts_detected = numpy.sum(sink_detect.data()) # We allow for one false alarm or missed burst self.assertTrue( abs(n_bursts_detected - n_bursts) <= 1, msg="""Because of statistics, it is possible (though unlikely) that the number of detected bursts differs slightly. If the number of detects is off by one or two, run the test again and see what happen. Detection error was: %d """ % (numpy.sum(sink_detect.data()) - n_bursts))
def test_004_channel_no_carroffset_1sym (self): """ Add a channel, check if it's correctly estimated. Only uses 1 synchronisation symbol. """ fft_len = 16 carr_offset = 0 sync_symbol = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0) data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0) tx_data = sync_symbol + data_symbol channel = (0, 0, 0, 2, 2, 2, 2, 3, 3, 2.5, 2.5, -3, -3, 1j, 1j, 0) #channel = (0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0) src = blocks.vector_source_c(tx_data, False, fft_len) chan = blocks.multiply_const_vcc(channel) chanest = digital.ofdm_chanest_vcvc(sync_symbol, (), 1) sink = blocks.vector_sink_c(fft_len) sink_chanest = blocks.vector_sink_c(fft_len) self.tb.connect(src, chan, chanest, sink) self.tb.connect((chanest, 1), sink_chanest) self.tb.run() self.assertEqual(sink_chanest.data(), channel) tags = sink.tags() for tag in tags: if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset': self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset) if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': self.assertEqual(pmt.pmt_c32vector_elements(tag.value), channel)
def test_001_t(self): """ pretty simple (the carrier allocation is not a practical OFDM configuration!) """ fft_len = 6 tx_symbols = (1, 2, 3) # ^ this gets mapped to the DC carrier because occupied_carriers[0][0] == 0 pilot_symbols = ((1j, ), ) occupied_carriers = ((0, 1, 2), ) pilot_carriers = ((3, ), ) sync_word = (range(fft_len), ) expected_result = tuple(sync_word[0] + [1j, 0, 0, 1, 2, 3]) # ^ DC carrier tag_name = "len" tag = gr.tag_t() tag.offset = 0 tag.key = pmt.string_to_symbol(tag_name) tag.value = pmt.from_long(len(tx_symbols)) src = blocks.vector_source_c(tx_symbols, False, 1, (tag, )) alloc = digital.ofdm_carrier_allocator_cvc(fft_len, occupied_carriers, pilot_carriers, pilot_symbols, sync_word, tag_name) sink = blocks.vector_sink_c(fft_len) self.tb.connect(src, alloc, sink) self.tb.run() self.assertEqual(sink.data(), expected_result)
def test_001_t2(self): """ pretty simple (same as before, but odd fft len) """ fft_len = 5 tx_symbols = (1, 2, 3) # ^ this gets mapped to the DC carrier because occupied_carriers[0][0] == 0 occupied_carriers = ((0, 1, 2), ) pilot_carriers = ((-2, ), ) pilot_symbols = ((1j, ), ) expected_result = (1j, 0, 1, 2, 3) # ^ DC carrier tag_name = "len" tag = gr.tag_t() tag.offset = 0 tag.key = pmt.string_to_symbol(tag_name) tag.value = pmt.from_long(len(tx_symbols)) src = blocks.vector_source_c(tx_symbols, False, 1, (tag, )) alloc = digital.ofdm_carrier_allocator_cvc(fft_len, occupied_carriers, pilot_carriers, pilot_symbols, (), tag_name) sink = blocks.vector_sink_c(fft_len) self.tb.connect(src, alloc, sink) self.tb.run() self.assertEqual(sink.data(), expected_result)
def test01(self): # Test complex/complex version omega = 2 gain_omega = 0.001 mu = 0.5 gain_mu = 0.01 omega_rel_lim = 0.001 self.test = digital.clock_recovery_mm_cc(omega, gain_omega, mu, gain_mu, omega_rel_lim) data = 100*[complex(1, 1),] self.src = blocks.vector_source_c(data, False) self.snk = blocks.vector_sink_c() self.tb.connect(self.src, self.test, self.snk) self.tb.run() expected_result = 100*[complex(0.99972, 0.99972)] # doesn't quite get to 1.0 dst_data = self.snk.data() # Only compare last Ncmp samples Ncmp = 30 len_e = len(expected_result) len_d = len(dst_data) expected_result = expected_result[len_e - Ncmp:] dst_data = dst_data[len_d - Ncmp:] #print expected_result #print dst_data self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 5)
def test03(self): # Test complex/complex version with varying input omega = 2 gain_omega = 0.01 mu = 0.25 gain_mu = 0.1 omega_rel_lim = 0.0001 self.test = digital.clock_recovery_mm_cc(omega, gain_omega, mu, gain_mu, omega_rel_lim) data = 1000*[complex(1, 1), complex(1, 1), complex(-1, -1), complex(-1, -1)] self.src = blocks.vector_source_c(data, False) self.snk = blocks.vector_sink_c() self.tb.connect(self.src, self.test, self.snk) self.tb.run() expected_result = 1000*[complex(-1.2, -1.2), complex(1.2, 1.2)] dst_data = self.snk.data() # Only compare last Ncmp samples Ncmp = 100 len_e = len(expected_result) len_d = len(dst_data) expected_result = expected_result[len_e - Ncmp:] dst_data = dst_data[len_d - Ncmp:] #print expected_result #print dst_data self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 1)
def test_complex_to_real(self): src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) expected_data = (1.0, 3.0, 5.0, 7.0, 9.0) src = blocks.vector_source_c(src_data) op = blocks.complex_to_real() dst = blocks.vector_sink_f() self.tb.connect(src, op, dst) self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
def test_complex_to_interleaved_short(self): src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) expected_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) src = blocks.vector_source_c(src_data) op = blocks.complex_to_interleaved_short() dst = blocks.vector_sink_s() self.tb.connect(src, op, dst) self.tb.run() self.assertEqual(expected_data, dst.data())
def test_complex_to_mag(self): src_data = (1 + 2j, 3 - 4j, 5 + 6j, 7 - 8j, -9 + 10j) expected_data = (sqrt(5), sqrt(25), sqrt(61), sqrt(113), sqrt(181)) src = blocks.vector_source_c(src_data) op = blocks.complex_to_mag() dst = blocks.vector_sink_f() self.tb.connect(src, op, dst) self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 5)
def test_complex_to_real(self): src_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j) expected_data = (1.0, 3.0, 5.0, 7.0, 9.0) src = blocks.vector_source_c(src_data) op = blocks.complex_to_real() dst = blocks.vector_sink_f() self.tb.connect(src, op, dst) self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
def test_complex_to_interleaved_short(self): src_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j) expected_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) src = blocks.vector_source_c(src_data) op = blocks.complex_to_interleaved_short() dst = blocks.vector_sink_s() self.tb.connect(src, op, dst) self.tb.run() self.assertEqual(expected_data, dst.data())
def test_complex_to_mag_squared(self): src_data = (1 + 2j, 3 - 4j, 5 + 6j, 7 - 8j, -9 + 10j) expected_data = (5.0, 25.0, 61.0, 113.0, 181.0) src = blocks.vector_source_c(src_data) op = blocks.complex_to_mag_squared() dst = blocks.vector_sink_f() self.tb.connect(src, op, dst) self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data())