diff options
216 files changed, 6642 insertions, 4274 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_flowgraph.py b/gnuradio-runtime/python/gnuradio/gr/qa_flowgraph.py index 1907656592..893b02cb07 100644 --- a/gnuradio-runtime/python/gnuradio/gr/qa_flowgraph.py +++ b/gnuradio-runtime/python/gnuradio/gr/qa_flowgraph.py @@ -13,12 +13,13 @@ import time import pmt from gnuradio import gr, gr_unittest, blocks + class test_flowgraph (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_000(self): @@ -42,6 +43,6 @@ class test_flowgraph (gr_unittest.TestCase): data = pmt.u8vector_elements(pmt.cdr(dbg.get_message(0))) self.assertEqual([1, 2, 3], data) + if __name__ == '__main__': gr_unittest.run(test_flowgraph) - diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_hier_block2.py b/gnuradio-runtime/python/gnuradio/gr/qa_hier_block2.py index a5895e8db0..3e42c79b7d 100644 --- a/gnuradio-runtime/python/gnuradio/gr/qa_hier_block2.py +++ b/gnuradio-runtime/python/gnuradio/gr/qa_hier_block2.py @@ -15,27 +15,27 @@ import pmt class test_hblk(gr.hier_block2): - def __init__(self, io_sig=1*[gr.sizeof_gr_complex], ndebug=2): + def __init__(self, io_sig=1 * [gr.sizeof_gr_complex], ndebug=2): # parent constructor - gr.hier_block2.__init__(self, - "test_hblk", - gr.io_signature(len(io_sig), len(io_sig), io_sig[0]), - gr.io_signature(0,0,0)) + gr.hier_block2.__init__( + self, "test_hblk", gr.io_signature( + len(io_sig), len(io_sig), io_sig[0]), gr.io_signature( + 0, 0, 0)) - self.message_port_register_hier_in("msg_in"); + self.message_port_register_hier_in("msg_in") # Internal Stream Blocks self.vsnk = blocks.vector_sink_c() # Internal Msg Blocks - self.blks = []; + self.blks = [] for i in range(0, ndebug): - self.blks.append( blocks.message_debug() ) + self.blks.append(blocks.message_debug()) # Set up internal connections - self.connect( self, self.vsnk ) + self.connect(self, self.vsnk) for blk in self.blks: - self.msg_connect( self, "msg_in", blk, "print" ) + self.msg_connect(self, "msg_in", blk, "print") class test_hier_block2(gr_unittest.TestCase): @@ -103,30 +103,42 @@ class test_hier_block2(gr_unittest.TestCase): self.multi(self.Block(), 5) def test_010(self): - s, h, k = analog.sig_source_c(44100, analog.GR_COS_WAVE, 440, 1.0, 0.0), blocks.head(gr.sizeof_gr_complex, 1000), test_hblk([gr.sizeof_gr_complex], 0) + s, h, k = analog.sig_source_c(44100, analog.GR_COS_WAVE, 440, 1.0, 0.0), blocks.head( + gr.sizeof_gr_complex, 1000), test_hblk([gr.sizeof_gr_complex], 0) tb = gr.top_block() - tb.connect(s,h,k) + tb.connect(s, h, k) tb.run() def test_011(self): - s, st, h, k = analog.sig_source_c(44100, analog.GR_COS_WAVE, 440, 1.0, 0.0), blocks.message_strobe(pmt.PMT_NIL, 100), blocks.head(gr.sizeof_gr_complex, 1000), test_hblk([gr.sizeof_gr_complex], 1) + s, st, h, k = analog.sig_source_c( + 44100, analog.GR_COS_WAVE, 440, 1.0, 0.0), blocks.message_strobe( + pmt.PMT_NIL, 100), blocks.head( + gr.sizeof_gr_complex, 1000), test_hblk( + [ + gr.sizeof_gr_complex], 1) tb = gr.top_block() - tb.connect(s,h,k) - tb.msg_connect(st,"strobe",k,"msg_in") + tb.connect(s, h, k) + tb.msg_connect(st, "strobe", k, "msg_in") tb.start() time.sleep(1) tb.stop() tb.wait() def test_012(self): - s, st, h, k = analog.sig_source_c(44100, analog.GR_COS_WAVE, 440, 1.0, 0.0), blocks.message_strobe(pmt.PMT_NIL, 100), blocks.head(gr.sizeof_gr_complex, 1000), test_hblk([gr.sizeof_gr_complex], 16) + s, st, h, k = analog.sig_source_c( + 44100, analog.GR_COS_WAVE, 440, 1.0, 0.0), blocks.message_strobe( + pmt.PMT_NIL, 100), blocks.head( + gr.sizeof_gr_complex, 1000), test_hblk( + [ + gr.sizeof_gr_complex], 16) tb = gr.top_block() - tb.connect(s,h,k) - tb.msg_connect(st,"strobe",k,"msg_in") + tb.connect(s, h, k) + tb.msg_connect(st, "strobe", k, "msg_in") tb.start() time.sleep(1) tb.stop() tb.wait() + if __name__ == '__main__': gr_unittest.run(test_hier_block2) diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_kludged_imports.py b/gnuradio-runtime/python/gnuradio/gr/qa_kludged_imports.py index 401fa7ddae..257aa3a761 100644 --- a/gnuradio-runtime/python/gnuradio/gr/qa_kludged_imports.py +++ b/gnuradio-runtime/python/gnuradio/gr/qa_kludged_imports.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest + class test_kludged_imports (gr_unittest.TestCase): def setUp(self): diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_prefs.py b/gnuradio-runtime/python/gnuradio/gr/qa_prefs.py index fcda8f7b53..f5a8c93baf 100644 --- a/gnuradio-runtime/python/gnuradio/gr/qa_prefs.py +++ b/gnuradio-runtime/python/gnuradio/gr/qa_prefs.py @@ -9,9 +9,9 @@ # - from gnuradio import gr, gr_unittest + class test_prefs (gr_unittest.TestCase): def test_001(self): @@ -21,7 +21,9 @@ class test_prefs (gr_unittest.TestCase): self.assertFalse(p.has_option('doesnt', 'exist')) # At the time these tests are run, there is not necessarily a default - # configuration on the build system, so not much to do with testing here + # configuration on the build system, so not much to do with testing + # here + if __name__ == '__main__': gr_unittest.run(test_prefs) diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_random.py b/gnuradio-runtime/python/gnuradio/gr/qa_random.py index 24823487e2..fa8c44917b 100644 --- a/gnuradio-runtime/python/gnuradio/gr/qa_random.py +++ b/gnuradio-runtime/python/gnuradio/gr/qa_random.py @@ -14,7 +14,8 @@ import numpy as np class test_random(gr_unittest.TestCase): - # NOTE: For tests on the output distribution of the random numbers, see gnuradio-runtime/apps/evaluation_random_numbers.py. + # NOTE: For tests on the output distribution of the random numbers, see + # gnuradio-runtime/apps/evaluation_random_numbers.py. # Check for range [0,1) of uniform distributed random numbers def test_1(self): diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_tag_utils.py b/gnuradio-runtime/python/gnuradio/gr/qa_tag_utils.py index b3a510f98a..96706377a3 100644 --- a/gnuradio-runtime/python/gnuradio/gr/qa_tag_utils.py +++ b/gnuradio-runtime/python/gnuradio/gr/qa_tag_utils.py @@ -9,18 +9,16 @@ # - from gnuradio import gr, gr_unittest import pmt class test_tag_utils (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () - + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_001(self): @@ -100,4 +98,3 @@ class test_tag_utils (gr_unittest.TestCase): if __name__ == '__main__': print('hi') gr_unittest.run(test_tag_utils) - diff --git a/gnuradio-runtime/python/pmt/qa_pmt.py b/gnuradio-runtime/python/pmt/qa_pmt.py index 9a08ed39b4..1e879aae29 100644 --- a/gnuradio-runtime/python/pmt/qa_pmt.py +++ b/gnuradio-runtime/python/pmt/qa_pmt.py @@ -12,10 +12,11 @@ import unittest import pmt + class test_pmt(unittest.TestCase): - MAXINT32 = (2**31)-1 - MININT32 = (-MAXINT32)-1 + MAXINT32 = (2**31) - 1 + MININT32 = (-MAXINT32) - 1 def setUp(self): from ctypes import sizeof, c_long @@ -204,7 +205,8 @@ class test_pmt(unittest.TestCase): out_str = pmt.serialize_str(d) self.assertEqual(out_str, in_str) in_str = b'\t\x07\x02\x00\x03vec\n\x00\x00\x00\x00\x04\x01\x00\x01\x02\x03\x04\x06' - d = pmt.dict_add(pmt.make_dict(), pmt.intern('vec'), pmt.init_u8vector(4, [1, 2, 3, 4])) + d = pmt.dict_add(pmt.make_dict(), pmt.intern('vec'), + pmt.init_u8vector(4, [1, 2, 3, 4])) out_pmt = pmt.deserialize_str(in_str) self.assertTrue(pmt.equal(out_pmt, d)) @@ -340,7 +342,7 @@ class test_pmt(unittest.TestCase): self.assertEqual(out_vec, in_vec) # c32_vector SERDES - in_vec = [0x01020304-1j, 3.1415+99.99j] + in_vec = [0x01020304 - 1j, 3.1415 + 99.99j] # old serialization (c32 serialized as c64): # in_str = b'\n\n\x00\x00\x00\x02\x01\x00Ap 0@\x00\x00\x00\xbf\xf0\x00\x00\x00\x00\x00\x00@\t!\xca\xc0\x00\x00\x00@X\xff\\ \x00\x00\x00' in_str = b'\n\n\x00\x00\x00\x02\x01\x00\xbf\x80\x00\x00K\x81\x01\x82B\xc7\xfa\xe1@I\x0eV' @@ -349,7 +351,7 @@ class test_pmt(unittest.TestCase): # old serialization (c32 serialized as c64): # in_str = b'\n\n\x00\x00\x00\x02\x01\x00?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00?\xc0\x00\x00\x00\x00\x00\x00\xc1c\x12\xcf\xe0\x00\x00\x00' in_str = b'\n\n\x00\x00\x00\x02\x01\x00?\x80\x00\x00?\x80\x00\x00\xcb\x18\x96\x7f>\x00\x00\x00' - in_vec = [1+1j, .125-9999999j] + in_vec = [1 + 1j, .125 - 9999999j] out_vec = pmt.c32vector_elements(pmt.deserialize_str(in_str)) self.assertEqual(out_vec, in_vec) @@ -359,7 +361,7 @@ class test_pmt(unittest.TestCase): out_str = pmt.serialize_str(pmt.init_c64vector(len(in_vec), in_vec)) self.assertEqual(out_str, in_str) in_str = b'\n\x0b\x00\x00\x00\x02\x01\x00?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00?\xc0\x00\x00\x00\x00\x00\x00\xc1c\x12\xcf\xe0\x00\x00\x00' - in_vec = [1+1j, .125-9999999j] + in_vec = [1 + 1j, .125 - 9999999j] out_vec = pmt.c64vector_elements(pmt.deserialize_str(in_str)) self.assertEqual(out_vec, in_vec) diff --git a/gnuradio-runtime/python/pmt/qa_pmt_to_python.py b/gnuradio-runtime/python/pmt/qa_pmt_to_python.py index 3fed489d8c..0d96cb800d 100644 --- a/gnuradio-runtime/python/pmt/qa_pmt_to_python.py +++ b/gnuradio-runtime/python/pmt/qa_pmt_to_python.py @@ -9,11 +9,11 @@ # - import unittest import pmt from pmt import pmt_to_python as pmt2py + class test_pmt_to_python(unittest.TestCase): def test_pmt_from_double(self): @@ -29,10 +29,9 @@ class test_pmt_to_python(unittest.TestCase): narr.imag[:] = np.random.uniform(size=N) uvector = pmt2py.numpy_to_uvector(narr) nparr = pmt2py.uvector_to_numpy(uvector) - self.assertTrue(nparr.dtype==narr.dtype) + self.assertTrue(nparr.dtype == narr.dtype) self.assertTrue(np.alltrue(nparr == narr)) - if __name__ == '__main__': unittest.main() diff --git a/gr-analog/python/analog/qa_agc.py b/gr-analog/python/analog/qa_agc.py index 28bcd54342..b65456a8c0 100644 --- a/gr-analog/python/analog/qa_agc.py +++ b/gr-analog/python/analog/qa_agc.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, analog, blocks + class test_agc(gr_unittest.TestCase): def setUp(self): @@ -37,62 +38,62 @@ class test_agc(gr_unittest.TestCase): tb = self.tb expected_result = ( - (100.000244140625+7.2191943445432116e-07j), - (72.892257690429688+52.959323883056641j), - (25.089065551757812+77.216217041015625j), - (-22.611061096191406+69.589706420898438j), - (-53.357715606689453+38.766635894775391j), - (-59.458671569824219+3.4792964243024471e-07j), - (-43.373462677001953-31.512666702270508j), - (-14.94139289855957-45.984889984130859j), - (13.478158950805664-41.48150634765625j), - (31.838506698608398-23.132022857666016j), - (35.519271850585938-3.1176801940091536e-07j), - (25.942903518676758+18.848621368408203j), - (8.9492912292480469+27.5430908203125j), - (-8.0852642059326172+24.883890151977539j), - (-19.131628036499023+13.899936676025391j), - (-21.383295059204102+3.1281737733479531e-07j), - (-15.650330543518066-11.370632171630859j), - (-5.4110145568847656-16.65339469909668j), - (4.9008159637451172-15.083160400390625j), - (11.628337860107422-8.4484796524047852j), - (13.036135673522949-2.288476110834381e-07j), - (9.5726661682128906+6.954948902130127j), - (3.3216962814331055+10.223132133483887j), - (-3.0204284191131592+9.2959251403808594j), - (-7.1977195739746094+5.2294478416442871j), - (-8.1072216033935547+1.8976157889483147e-07j), - (-5.9838657379150391-4.3475332260131836j), - (-2.0879747867584229-6.4261269569396973j), - (1.9100792407989502-5.8786196708679199j), - (4.5814824104309082-3.3286411762237549j), - (5.1967458724975586-1.3684227440080576e-07j), - (3.8647139072418213+2.8078789710998535j), - (1.3594740629196167+4.1840314865112305j), - (-1.2544282674789429+3.8607344627380371j), - (-3.0366206169128418+2.2062335014343262j), - (-3.4781389236450195+1.1194014604143376e-07j), - (-2.6133756637573242-1.8987287282943726j), - (-0.9293016791343689-2.8600969314575195j), - (0.86727333068847656-2.6691930294036865j), - (2.1243946552276611-1.5434627532958984j), - (2.4633183479309082-8.6486437567145913e-08j), - (1.8744727373123169+1.3618841171264648j), - (0.67528903484344482+2.0783262252807617j), - (-0.63866174221038818+1.965599536895752j), - (-1.5857341289520264+1.152103066444397j), - (-1.8640764951705933+7.6355092915036948e-08j), - (-1.4381576776504517-1.0448826551437378j), - (-0.52529704570770264-1.6166983842849731j), - (0.50366902351379395-1.5501341819763184j), - (1.26766037940979-0.92100900411605835j)) + (100.000244140625 + 7.2191943445432116e-07j), + (72.892257690429688 + 52.959323883056641j), + (25.089065551757812 + 77.216217041015625j), + (-22.611061096191406 + 69.589706420898438j), + (-53.357715606689453 + 38.766635894775391j), + (-59.458671569824219 + 3.4792964243024471e-07j), + (-43.373462677001953 - 31.512666702270508j), + (-14.94139289855957 - 45.984889984130859j), + (13.478158950805664 - 41.48150634765625j), + (31.838506698608398 - 23.132022857666016j), + (35.519271850585938 - 3.1176801940091536e-07j), + (25.942903518676758 + 18.848621368408203j), + (8.9492912292480469 + 27.5430908203125j), + (-8.0852642059326172 + 24.883890151977539j), + (-19.131628036499023 + 13.899936676025391j), + (-21.383295059204102 + 3.1281737733479531e-07j), + (-15.650330543518066 - 11.370632171630859j), + (-5.4110145568847656 - 16.65339469909668j), + (4.9008159637451172 - 15.083160400390625j), + (11.628337860107422 - 8.4484796524047852j), + (13.036135673522949 - 2.288476110834381e-07j), + (9.5726661682128906 + 6.954948902130127j), + (3.3216962814331055 + 10.223132133483887j), + (-3.0204284191131592 + 9.2959251403808594j), + (-7.1977195739746094 + 5.2294478416442871j), + (-8.1072216033935547 + 1.8976157889483147e-07j), + (-5.9838657379150391 - 4.3475332260131836j), + (-2.0879747867584229 - 6.4261269569396973j), + (1.9100792407989502 - 5.8786196708679199j), + (4.5814824104309082 - 3.3286411762237549j), + (5.1967458724975586 - 1.3684227440080576e-07j), + (3.8647139072418213 + 2.8078789710998535j), + (1.3594740629196167 + 4.1840314865112305j), + (-1.2544282674789429 + 3.8607344627380371j), + (-3.0366206169128418 + 2.2062335014343262j), + (-3.4781389236450195 + 1.1194014604143376e-07j), + (-2.6133756637573242 - 1.8987287282943726j), + (-0.9293016791343689 - 2.8600969314575195j), + (0.86727333068847656 - 2.6691930294036865j), + (2.1243946552276611 - 1.5434627532958984j), + (2.4633183479309082 - 8.6486437567145913e-08j), + (1.8744727373123169 + 1.3618841171264648j), + (0.67528903484344482 + 2.0783262252807617j), + (-0.63866174221038818 + 1.965599536895752j), + (-1.5857341289520264 + 1.152103066444397j), + (-1.8640764951705933 + 7.6355092915036948e-08j), + (-1.4381576776504517 - 1.0448826551437378j), + (-0.52529704570770264 - 1.6166983842849731j), + (0.50366902351379395 - 1.5501341819763184j), + (1.26766037940979 - 0.92100900411605835j)) sampling_freq = 100 src1 = analog.sig_source_c(sampling_freq, analog.GR_SIN_WAVE, sampling_freq * 0.10, 100.0) dst1 = blocks.vector_sink_c() - head = blocks.head(gr.sizeof_gr_complex, int (5*sampling_freq * 0.10)) + head = blocks.head(gr.sizeof_gr_complex, int(5 * sampling_freq * 0.10)) agc = analog.agc_cc(1e-3, 1, 1) @@ -176,18 +177,18 @@ class test_agc(gr_unittest.TestCase): sampling_freq = 100 src1 = analog.sig_source_f(sampling_freq, analog.GR_SIN_WAVE, sampling_freq * 0.10, 100.0) - dst1 = blocks.vector_sink_f () - head = blocks.head (gr.sizeof_float, int (5*sampling_freq * 0.10)) + dst1 = blocks.vector_sink_f() + head = blocks.head(gr.sizeof_float, int(5 * sampling_freq * 0.10)) agc = analog.agc_ff(1e-3, 1, 1) - tb.connect (src1, head) - tb.connect (head, agc) - tb.connect (agc, dst1) + tb.connect(src1, head) + tb.connect(head, agc) + tb.connect(agc, dst1) - tb.run () - dst_data = dst1.data () - self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 4) + tb.run() + dst_data = dst1.data() + self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 4) def test_003_sets(self): agc = analog.agc2_cc(1e-3, 1e-1, 1, 1) @@ -209,62 +210,62 @@ class test_agc(gr_unittest.TestCase): tb = self.tb expected_result = \ - ((100.000244140625+7.2191943445432116e-07j), - (0.80881959199905396+0.58764183521270752j), - (0.30894950032234192+0.95084899663925171j), - (-0.30895623564720154+0.95086973905563354j), - (-0.80887287855148315+0.58768033981323242j), - (-0.99984413385391235+5.850709250410091e-09j), - (-0.80889981985092163-0.58770018815994263j), - (-0.30897706747055054-0.95093393325805664j), - (0.30898112058639526-0.95094609260559082j), - (0.80893135070800781-0.58772283792495728j), - (0.99990922212600708-8.7766354184282136e-09j), - (0.80894720554351807+0.58773452043533325j), - (0.30899339914321899+0.95098406076431274j), - (-0.30899572372436523+0.95099133253097534j), - (-0.80896598100662231+0.58774799108505249j), - (-0.99994778633117676+1.4628290578855285e-08j), - (-0.80897533893585205-0.58775502443313599j), - (-0.30900305509567261-0.95101380348205566j), - (0.30900448560714722-0.95101797580718994j), - (0.80898630619049072-0.58776277303695679j), - (0.99997037649154663-1.7554345532744264e-08j), - (0.80899184942245483+0.58776694536209106j), - (0.30900871753692627+0.95103120803833008j), - (-0.30900952219963074+0.95103377103805542j), - (-0.8089984655380249+0.58777159452438354j), - (-0.99998390674591064+2.3406109050938539e-08j), - (-0.809001624584198-0.58777409791946411j), - (-0.30901208519935608-0.95104163885116577j), - (0.30901262164115906-0.95104306936264038j), - (0.80900543928146362-0.587776780128479j), - (0.99999171495437622-2.6332081404234486e-08j), - (0.80900734663009644+0.58777821063995361j), - (0.30901408195495605+0.95104765892028809j), - (-0.30901429057121277+0.95104855298995972j), - (-0.80900967121124268+0.58777981996536255j), - (-0.99999648332595825+3.2183805842578295e-08j), - (-0.80901080369949341-0.58778077363967896j), - (-0.30901527404785156-0.95105135440826416j), - (0.30901545286178589-0.95105189085006714j), - (0.80901217460632324-0.58778166770935059j), - (0.99999916553497314-3.5109700036173308e-08j), - (0.809012770652771+0.58778214454650879j), - (0.30901595950126648+0.9510534405708313j), - (-0.30901598930358887+0.95105385780334473j), - (-0.80901366472244263+0.58778274059295654j), - (-1.0000008344650269+4.0961388947380328e-08j), - (-0.8090139627456665-0.58778303861618042j), - (-0.30901634693145752-0.95105475187301636j), - (0.30901640653610229-0.95105493068695068j), - (0.80901449918746948-0.5877833366394043j)) + ((100.000244140625 + 7.2191943445432116e-07j), + (0.80881959199905396 + 0.58764183521270752j), + (0.30894950032234192 + 0.95084899663925171j), + (-0.30895623564720154 + 0.95086973905563354j), + (-0.80887287855148315 + 0.58768033981323242j), + (-0.99984413385391235 + 5.850709250410091e-09j), + (-0.80889981985092163 - 0.58770018815994263j), + (-0.30897706747055054 - 0.95093393325805664j), + (0.30898112058639526 - 0.95094609260559082j), + (0.80893135070800781 - 0.58772283792495728j), + (0.99990922212600708 - 8.7766354184282136e-09j), + (0.80894720554351807 + 0.58773452043533325j), + (0.30899339914321899 + 0.95098406076431274j), + (-0.30899572372436523 + 0.95099133253097534j), + (-0.80896598100662231 + 0.58774799108505249j), + (-0.99994778633117676 + 1.4628290578855285e-08j), + (-0.80897533893585205 - 0.58775502443313599j), + (-0.30900305509567261 - 0.95101380348205566j), + (0.30900448560714722 - 0.95101797580718994j), + (0.80898630619049072 - 0.58776277303695679j), + (0.99997037649154663 - 1.7554345532744264e-08j), + (0.80899184942245483 + 0.58776694536209106j), + (0.30900871753692627 + 0.95103120803833008j), + (-0.30900952219963074 + 0.95103377103805542j), + (-0.8089984655380249 + 0.58777159452438354j), + (-0.99998390674591064 + 2.3406109050938539e-08j), + (-0.809001624584198 - 0.58777409791946411j), + (-0.30901208519935608 - 0.95104163885116577j), + (0.30901262164115906 - 0.95104306936264038j), + (0.80900543928146362 - 0.587776780128479j), + (0.99999171495437622 - 2.6332081404234486e-08j), + (0.80900734663009644 + 0.58777821063995361j), + (0.30901408195495605 + 0.95104765892028809j), + (-0.30901429057121277 + 0.95104855298995972j), + (-0.80900967121124268 + 0.58777981996536255j), + (-0.99999648332595825 + 3.2183805842578295e-08j), + (-0.80901080369949341 - 0.58778077363967896j), + (-0.30901527404785156 - 0.95105135440826416j), + (0.30901545286178589 - 0.95105189085006714j), + (0.80901217460632324 - 0.58778166770935059j), + (0.99999916553497314 - 3.5109700036173308e-08j), + (0.809012770652771 + 0.58778214454650879j), + (0.30901595950126648 + 0.9510534405708313j), + (-0.30901598930358887 + 0.95105385780334473j), + (-0.80901366472244263 + 0.58778274059295654j), + (-1.0000008344650269 + 4.0961388947380328e-08j), + (-0.8090139627456665 - 0.58778303861618042j), + (-0.30901634693145752 - 0.95105475187301636j), + (0.30901640653610229 - 0.95105493068695068j), + (0.80901449918746948 - 0.5877833366394043j)) sampling_freq = 100 src1 = analog.sig_source_c(sampling_freq, analog.GR_SIN_WAVE, sampling_freq * 0.10, 100) dst1 = blocks.vector_sink_c() - head = blocks.head(gr.sizeof_gr_complex, int(5*sampling_freq * 0.10)) + head = blocks.head(gr.sizeof_gr_complex, int(5 * sampling_freq * 0.10)) agc = analog.agc2_cc(1e-2, 1e-3, 1, 1) @@ -351,7 +352,7 @@ class test_agc(gr_unittest.TestCase): src1 = analog.sig_source_f(sampling_freq, analog.GR_SIN_WAVE, sampling_freq * 0.10, 100) dst1 = blocks.vector_sink_f() - head = blocks.head(gr.sizeof_float, int(5*sampling_freq * 0.10)) + head = blocks.head(gr.sizeof_float, int(5 * sampling_freq * 0.10)) agc = analog.agc2_ff(1e-2, 1e-3, 1, 1) @@ -363,68 +364,67 @@ class test_agc(gr_unittest.TestCase): dst_data = dst1.data() self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 4) - def test_005(self): ''' Test the complex AGC loop (attack and decay rate inputs) ''' tb = self.tb expected_result = \ - ((100.000244140625+7.2191943445432116e-07j), - (0.80881959199905396+0.58764183521270752j), - (0.30894950032234192+0.95084899663925171j), - (-0.30895623564720154+0.95086973905563354j), - (-0.80887287855148315+0.58768033981323242j), - (-0.99984413385391235+5.850709250410091e-09j), - (-0.80889981985092163-0.58770018815994263j), - (-0.30897706747055054-0.95093393325805664j), - (0.30898112058639526-0.95094609260559082j), - (0.80893135070800781-0.58772283792495728j), - (0.99990922212600708-8.7766354184282136e-09j), - (0.80894720554351807+0.58773452043533325j), - (0.30899339914321899+0.95098406076431274j), - (-0.30899572372436523+0.95099133253097534j), - (-0.80896598100662231+0.58774799108505249j), - (-0.99994778633117676+1.4628290578855285e-08j), - (-0.80897533893585205-0.58775502443313599j), - (-0.30900305509567261-0.95101380348205566j), - (0.30900448560714722-0.95101797580718994j), - (0.80898630619049072-0.58776277303695679j), - (0.99997037649154663-1.7554345532744264e-08j), - (0.80899184942245483+0.58776694536209106j), - (0.30900871753692627+0.95103120803833008j), - (-0.30900952219963074+0.95103377103805542j), - (-0.8089984655380249+0.58777159452438354j), - (-0.99998390674591064+2.3406109050938539e-08j), - (-0.809001624584198-0.58777409791946411j), - (-0.30901208519935608-0.95104163885116577j), - (0.30901262164115906-0.95104306936264038j), - (0.80900543928146362-0.587776780128479j), - (0.99999171495437622-2.6332081404234486e-08j), - (0.80900734663009644+0.58777821063995361j), - (0.30901408195495605+0.95104765892028809j), - (-0.30901429057121277+0.95104855298995972j), - (-0.80900967121124268+0.58777981996536255j), - (-0.99999648332595825+3.2183805842578295e-08j), - (-0.80901080369949341-0.58778077363967896j), - (-0.30901527404785156-0.95105135440826416j), - (0.30901545286178589-0.95105189085006714j), - (0.80901217460632324-0.58778166770935059j), - (0.99999916553497314-3.5109700036173308e-08j), - (0.809012770652771+0.58778214454650879j), - (0.30901595950126648+0.9510534405708313j), - (-0.30901598930358887+0.95105385780334473j), - (-0.80901366472244263+0.58778274059295654j), - (-1.0000008344650269+4.0961388947380328e-08j), - (-0.8090139627456665-0.58778303861618042j), - (-0.30901634693145752-0.95105475187301636j), - (0.30901640653610229-0.95105493068695068j), - (0.80901449918746948-0.5877833366394043j)) + ((100.000244140625 + 7.2191943445432116e-07j), + (0.80881959199905396 + 0.58764183521270752j), + (0.30894950032234192 + 0.95084899663925171j), + (-0.30895623564720154 + 0.95086973905563354j), + (-0.80887287855148315 + 0.58768033981323242j), + (-0.99984413385391235 + 5.850709250410091e-09j), + (-0.80889981985092163 - 0.58770018815994263j), + (-0.30897706747055054 - 0.95093393325805664j), + (0.30898112058639526 - 0.95094609260559082j), + (0.80893135070800781 - 0.58772283792495728j), + (0.99990922212600708 - 8.7766354184282136e-09j), + (0.80894720554351807 + 0.58773452043533325j), + (0.30899339914321899 + 0.95098406076431274j), + (-0.30899572372436523 + 0.95099133253097534j), + (-0.80896598100662231 + 0.58774799108505249j), + (-0.99994778633117676 + 1.4628290578855285e-08j), + (-0.80897533893585205 - 0.58775502443313599j), + (-0.30900305509567261 - 0.95101380348205566j), + (0.30900448560714722 - 0.95101797580718994j), + (0.80898630619049072 - 0.58776277303695679j), + (0.99997037649154663 - 1.7554345532744264e-08j), + (0.80899184942245483 + 0.58776694536209106j), + (0.30900871753692627 + 0.95103120803833008j), + (-0.30900952219963074 + 0.95103377103805542j), + (-0.8089984655380249 + 0.58777159452438354j), + (-0.99998390674591064 + 2.3406109050938539e-08j), + (-0.809001624584198 - 0.58777409791946411j), + (-0.30901208519935608 - 0.95104163885116577j), + (0.30901262164115906 - 0.95104306936264038j), + (0.80900543928146362 - 0.587776780128479j), + (0.99999171495437622 - 2.6332081404234486e-08j), + (0.80900734663009644 + 0.58777821063995361j), + (0.30901408195495605 + 0.95104765892028809j), + (-0.30901429057121277 + 0.95104855298995972j), + (-0.80900967121124268 + 0.58777981996536255j), + (-0.99999648332595825 + 3.2183805842578295e-08j), + (-0.80901080369949341 - 0.58778077363967896j), + (-0.30901527404785156 - 0.95105135440826416j), + (0.30901545286178589 - 0.95105189085006714j), + (0.80901217460632324 - 0.58778166770935059j), + (0.99999916553497314 - 3.5109700036173308e-08j), + (0.809012770652771 + 0.58778214454650879j), + (0.30901595950126648 + 0.9510534405708313j), + (-0.30901598930358887 + 0.95105385780334473j), + (-0.80901366472244263 + 0.58778274059295654j), + (-1.0000008344650269 + 4.0961388947380328e-08j), + (-0.8090139627456665 - 0.58778303861618042j), + (-0.30901634693145752 - 0.95105475187301636j), + (0.30901640653610229 - 0.95105493068695068j), + (0.80901449918746948 - 0.5877833366394043j)) sampling_freq = 100 src1 = analog.sig_source_c(sampling_freq, analog.GR_SIN_WAVE, sampling_freq * 0.10, 100) dst1 = blocks.vector_sink_c() - head = blocks.head(gr.sizeof_gr_complex, int(5*sampling_freq * 0.10)) + head = blocks.head(gr.sizeof_gr_complex, int(5 * sampling_freq * 0.10)) agc = analog.agc2_cc(1e-2, 1e-3, 1, 1) @@ -454,7 +454,7 @@ class test_agc(gr_unittest.TestCase): tb = self.tb sampling_freq = 100 - N = int(5*sampling_freq) + N = int(5 * sampling_freq) src1 = analog.sig_source_c(sampling_freq, analog.GR_SIN_WAVE, sampling_freq * 0.10, 100) dst1 = blocks.vector_sink_c() @@ -470,8 +470,8 @@ class test_agc(gr_unittest.TestCase): tb.run() dst_data = dst1.data() M = 100 - result = [abs(x) for x in dst_data[N-M:]] - self.assertFloatTuplesAlmostEqual(result, M*[ref,], 4) + result = [abs(x) for x in dst_data[N - M:]] + self.assertFloatTuplesAlmostEqual(result, M * [ref, ], 4) def test_100(self): ''' Test complex feedforward agc with constant input ''' @@ -479,8 +479,8 @@ class test_agc(gr_unittest.TestCase): length = 8 gain = 2 - input_data = 8*(0.0,) + 24*(1.0,) + 24*(0.0,) - expected_result = (8+length-1)*(0.0,) + 24*(gain*1.0,) + (0,) + input_data = 8 * (0.0,) + 24 * (1.0,) + 24 * (0.0,) + expected_result = (8 + length - 1) * (0.0,) + 24 * (gain * 1.0,) + (0,) src = blocks.vector_source_c(input_data) agc = analog.feedforward_agc_cc(8, 2.0) diff --git a/gr-analog/python/analog/qa_cpfsk.py b/gr-analog/python/analog/qa_cpfsk.py index 7e866c1856..f6fa00a26f 100644 --- a/gr-analog/python/analog/qa_cpfsk.py +++ b/gr-analog/python/analog/qa_cpfsk.py @@ -13,6 +13,7 @@ import math from gnuradio import gr, gr_unittest, analog, blocks + class test_cpfsk_bc(gr_unittest.TestCase): def setUp(self): @@ -30,7 +31,7 @@ class test_cpfsk_bc(gr_unittest.TestCase): a = op.amplitude() self.assertEqual(2, a) - freq = 2*math.pi/2.0 + freq = 2 * math.pi / 2.0 f = op.freq() self.assertAlmostEqual(freq, f, 5) @@ -38,8 +39,8 @@ class test_cpfsk_bc(gr_unittest.TestCase): self.assertEqual(0, p) def test_cpfsk_bc_002(self): - src_data = 10*[0, 1] - expected_result = [complex(2*x-1,0) for x in src_data] + src_data = 10 * [0, 1] + expected_result = [complex(2 * x - 1, 0) for x in src_data] src = blocks.vector_source_b(src_data) op = analog.cpfsk_bc(2, 1, 2) @@ -52,6 +53,6 @@ class test_cpfsk_bc(gr_unittest.TestCase): result_data = dst.data()[0:len(expected_result)] self.assertComplexTuplesAlmostEqual(expected_result, result_data, 4) + if __name__ == '__main__': gr_unittest.run(test_cpfsk_bc) - diff --git a/gr-analog/python/analog/qa_ctcss_squelch.py b/gr-analog/python/analog/qa_ctcss_squelch.py index 8a7e5353da..6151641aa3 100644 --- a/gr-analog/python/analog/qa_ctcss_squelch.py +++ b/gr-analog/python/analog/qa_ctcss_squelch.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, analog, blocks + class test_ctcss_squelch(gr_unittest.TestCase): def setUp(self): @@ -93,6 +94,6 @@ class test_ctcss_squelch(gr_unittest.TestCase): result_data = dst.data() self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4) + if __name__ == '__main__': gr_unittest.run(test_ctcss_squelch) - diff --git a/gr-analog/python/analog/qa_dpll.py b/gr-analog/python/analog/qa_dpll.py index 90b060bd20..627db53f58 100644 --- a/gr-analog/python/analog/qa_dpll.py +++ b/gr-analog/python/analog/qa_dpll.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, analog, blocks + class test_dpll_bb(gr_unittest.TestCase): def setUp(self): @@ -33,7 +34,7 @@ class test_dpll_bb(gr_unittest.TestCase): f = op.freq() self.assertEqual(1 / period, f) - d0 = 1.0 - 0.5*f; + d0 = 1.0 - 0.5 * f d1 = op.decision_threshold() self.assertAlmostEqual(d0, d1) @@ -44,7 +45,7 @@ class test_dpll_bb(gr_unittest.TestCase): period = 4 gain = 0.1 - src_data = 10*((period-1)*[0,] + [1,]) + src_data = 10 * ((period - 1) * [0, ] + [1, ]) expected_result = src_data src = blocks.vector_source_b(src_data) @@ -58,6 +59,6 @@ class test_dpll_bb(gr_unittest.TestCase): result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_result, result_data, 4) + if __name__ == '__main__': gr_unittest.run(test_dpll_bb) - diff --git a/gr-analog/python/analog/qa_fastnoise.py b/gr-analog/python/analog/qa_fastnoise.py index b80d2e04d6..3e5e0c3001 100644 --- a/gr-analog/python/analog/qa_fastnoise.py +++ b/gr-analog/python/analog/qa_fastnoise.py @@ -14,13 +14,13 @@ import numpy class test_fastnoise_source(gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.num = 2**22 self.num_items = 10**6 self.default_args = {"samples": self.num, "seed": 43, "ampl": 1} - def tearDown (self): + def tearDown(self): pass def run_test_real(self, form): @@ -28,7 +28,9 @@ class test_fastnoise_source(gr_unittest.TestCase): """ tb = gr.top_block() src = analog.fastnoise_source_f(type=form, **self.default_args) - head = blocks.head(nitems=self.num_items, sizeof_stream_item=gr.sizeof_float) + head = blocks.head( + nitems=self.num_items, + sizeof_stream_item=gr.sizeof_float) sink = blocks.vector_sink_f() tb.connect(src, head, sink) tb.run() @@ -39,7 +41,9 @@ class test_fastnoise_source(gr_unittest.TestCase): """ tb = gr.top_block() src = analog.fastnoise_source_c(type=form, **self.default_args) - head = blocks.head(nitems=self.num_items, sizeof_stream_item=gr.sizeof_gr_complex) + head = blocks.head( + nitems=self.num_items, + sizeof_stream_item=gr.sizeof_gr_complex) sink = blocks.vector_sink_c() tb.connect(src, head, sink) tb.run() @@ -54,7 +58,7 @@ class test_fastnoise_source(gr_unittest.TestCase): # mean, variance self.assertAlmostEqual(data.mean(), 0, places=2) - self.assertAlmostEqual(data.var(), (1-(-1))**2./12, places=3) + self.assertAlmostEqual(data.var(), (1 - (-1))**2. / 12, places=3) def test_001_real_gaussian_moments(self): data = self.run_test_real(analog.GR_GAUSSIAN) @@ -75,10 +79,12 @@ class test_fastnoise_source(gr_unittest.TestCase): # mean, variance self.assertAlmostEqual(data.real.mean(), 0, places=2) - self.assertAlmostEqual(data.real.var(), 0.5*(1-(-1))**2./12, places=3) + self.assertAlmostEqual(data.real.var(), 0.5 * + (1 - (-1))**2. / 12, places=3) self.assertAlmostEqual(data.imag.mean(), 0, places=2) - self.assertAlmostEqual(data.imag.var(), 0.5*(1-(-1))**2./12, places=3) + self.assertAlmostEqual(data.imag.var(), 0.5 * + (1 - (-1))**2. / 12, places=3) def test_001_complex_gaussian_moments(self): data = self.run_test_complex(analog.GR_GAUSSIAN) @@ -104,24 +110,60 @@ class test_fastnoise_source(gr_unittest.TestCase): self.assertTrue(numpy.array_equal(data1, data2)) def test_003_real_uniform_pool(self): - src = analog.fastnoise_source_f(type=analog.GR_UNIFORM, **self.default_args) - src2 = analog.fastnoise_source_f(type=analog.GR_UNIFORM, **self.default_args) - self.assertTrue(numpy.array_equal(numpy.array(src.samples()), numpy.array(src2.samples()))) + src = analog.fastnoise_source_f( + type=analog.GR_UNIFORM, **self.default_args) + src2 = analog.fastnoise_source_f( + type=analog.GR_UNIFORM, **self.default_args) + self.assertTrue( + numpy.array_equal( + numpy.array( + src.samples()), numpy.array( + src2.samples()))) + def test_003_real_gaussian_pool(self): - src = analog.fastnoise_source_f(type=analog.GR_GAUSSIAN, **self.default_args) - src2 = analog.fastnoise_source_f(type=analog.GR_GAUSSIAN, **self.default_args) - self.assertTrue(numpy.array_equal(numpy.array(src.samples()), numpy.array(src2.samples()))) + src = analog.fastnoise_source_f( + type=analog.GR_GAUSSIAN, **self.default_args) + src2 = analog.fastnoise_source_f( + type=analog.GR_GAUSSIAN, **self.default_args) + self.assertTrue( + numpy.array_equal( + numpy.array( + src.samples()), numpy.array( + src2.samples()))) + def test_003_cmplx_gaussian_pool(self): - src = analog.fastnoise_source_c(type=analog.GR_GAUSSIAN, **self.default_args) - src2 = analog.fastnoise_source_c(type=analog.GR_GAUSSIAN, **self.default_args) - self.assertTrue(numpy.array_equal(numpy.array(src.samples()), numpy.array(src2.samples()))) + src = analog.fastnoise_source_c( + type=analog.GR_GAUSSIAN, **self.default_args) + src2 = analog.fastnoise_source_c( + type=analog.GR_GAUSSIAN, **self.default_args) + self.assertTrue( + numpy.array_equal( + numpy.array( + src.samples()), numpy.array( + src2.samples()))) + def test_003_cmplx_uniform_pool(self): - src = analog.fastnoise_source_c(type=analog.GR_UNIFORM, **self.default_args) - src2 = analog.fastnoise_source_c(type=analog.GR_UNIFORM, **self.default_args) - self.assertTrue(numpy.array_equal(numpy.array(src.samples()), numpy.array(src2.samples()))) + src = analog.fastnoise_source_c( + type=analog.GR_UNIFORM, **self.default_args) + src2 = analog.fastnoise_source_c( + type=analog.GR_UNIFORM, **self.default_args) + self.assertTrue( + numpy.array_equal( + numpy.array( + src.samples()), numpy.array( + src2.samples()))) + def test_003_real_laplacian_pool(self): - src = analog.fastnoise_source_f(type=analog.GR_LAPLACIAN, **self.default_args) - src2 = analog.fastnoise_source_f(type=analog.GR_LAPLACIAN, **self.default_args) - self.assertTrue(numpy.array_equal(numpy.array(src.samples()), numpy.array(src2.samples()))) + src = analog.fastnoise_source_f( + type=analog.GR_LAPLACIAN, **self.default_args) + src2 = analog.fastnoise_source_f( + type=analog.GR_LAPLACIAN, **self.default_args) + self.assertTrue( + numpy.array_equal( + numpy.array( + src.samples()), numpy.array( + src2.samples()))) + + if __name__ == '__main__': gr_unittest.run(test_fastnoise_source) diff --git a/gr-analog/python/analog/qa_fmdet.py b/gr-analog/python/analog/qa_fmdet.py index 84ba1b8b04..9480f2a4d4 100644 --- a/gr-analog/python/analog/qa_fmdet.py +++ b/gr-analog/python/analog/qa_fmdet.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, analog, blocks + class test_fmdet_cf(gr_unittest.TestCase): def setUp(self): @@ -33,7 +34,7 @@ class test_fmdet_cf(gr_unittest.TestCase): op.set_freq_range(fl2, fh2) lo = op.freq_low() hi = op.freq_high() - f = op.freq() + f = op.freq() self.assertEqual(fl2, lo) self.assertEqual(fh2, hi) self.assertEqual(0, f) @@ -41,7 +42,7 @@ class test_fmdet_cf(gr_unittest.TestCase): op.set_scale(scale2) s = op.scale() b = op.bias() - eb = 0.5*scale2*(hi + lo) / (hi - lo); + eb = 0.5 * scale2 * (hi + lo) / (hi - lo) self.assertEqual(scale2, s) self.assertAlmostEqual(eb, b) @@ -59,9 +60,9 @@ class test_fmdet_cf(gr_unittest.TestCase): self.tb.run() result_data = dst.data()[4:N] - expected_result = (100-4)*[-0.21755,] + expected_result = (100 - 4) * [-0.21755, ] self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4) + if __name__ == '__main__': gr_unittest.run(test_fmdet_cf) - diff --git a/gr-analog/python/analog/qa_frequency_modulator.py b/gr-analog/python/analog/qa_frequency_modulator.py index 8e99b29c1d..c967aaee28 100644 --- a/gr-analog/python/analog/qa_frequency_modulator.py +++ b/gr-analog/python/analog/qa_frequency_modulator.py @@ -13,8 +13,9 @@ import math from gnuradio import gr, gr_unittest, analog, blocks + def sincos(x): - return math.cos(x) + math.sin(x) * 1j + return math.cos(x) + math.sin(x) * 1j class test_frequency_modulator(gr_unittest.TestCase): @@ -29,7 +30,7 @@ class test_frequency_modulator(gr_unittest.TestCase): pi = math.pi sensitivity = pi / 4 src_data = (1.0 / 4, 1.0 / 2, 1.0 / 4, -1.0 / 4, -1.0 / 2, -1 / 4.0) - running_sum = (pi / 16, 3*pi/16, pi / 4, 3*pi/16, pi / 16, 0) + running_sum = (pi / 16, 3 * pi / 16, pi / 4, 3 * pi / 16, pi / 16, 0) expected_result = tuple([sincos(x) for x in running_sum]) src = blocks.vector_source_f(src_data) op = analog.frequency_modulator_fc(sensitivity) @@ -40,6 +41,6 @@ class test_frequency_modulator(gr_unittest.TestCase): result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5) + if __name__ == '__main__': gr_unittest.run(test_frequency_modulator) - diff --git a/gr-analog/python/analog/qa_noise.py b/gr-analog/python/analog/qa_noise.py index dbdce9b350..97a5c5cc44 100644 --- a/gr-analog/python/analog/qa_noise.py +++ b/gr-analog/python/analog/qa_noise.py @@ -11,12 +11,13 @@ from gnuradio import gr, gr_unittest, analog + class test_noise_source(gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_001(self): @@ -37,4 +38,3 @@ class test_noise_source(gr_unittest.TestCase): if __name__ == '__main__': gr_unittest.run(test_noise_source) - diff --git a/gr-analog/python/analog/qa_phase_modulator.py b/gr-analog/python/analog/qa_phase_modulator.py index 305b6ee665..abf079d9fd 100644 --- a/gr-analog/python/analog/qa_phase_modulator.py +++ b/gr-analog/python/analog/qa_phase_modulator.py @@ -13,8 +13,9 @@ import math from gnuradio import gr, gr_unittest, analog, blocks + def sincos(x): - return math.cos(x) + math.sin(x) * 1j + return math.cos(x) + math.sin(x) * 1j class test_phase_modulator(gr_unittest.TestCase): @@ -29,7 +30,7 @@ class test_phase_modulator(gr_unittest.TestCase): pi = math.pi sensitivity = pi / 4 src_data = (1.0 / 4, 1.0 / 2, 1.0 / 4, -1.0 / 4, -1.0 / 2, -1 / 4.0) - expected_result = tuple([sincos(sensitivity*x) for x in src_data]) + expected_result = tuple([sincos(sensitivity * x) for x in src_data]) src = blocks.vector_source_f(src_data) op = analog.phase_modulator_fc(sensitivity) @@ -42,6 +43,6 @@ class test_phase_modulator(gr_unittest.TestCase): result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5) + if __name__ == '__main__': gr_unittest.run(test_phase_modulator) - diff --git a/gr-analog/python/analog/qa_pll_carriertracking.py b/gr-analog/python/analog/qa_pll_carriertracking.py index 5406e34709..b835100884 100644 --- a/gr-analog/python/analog/qa_pll_carriertracking.py +++ b/gr-analog/python/analog/qa_pll_carriertracking.py @@ -13,115 +13,116 @@ import math from gnuradio import gr, gr_unittest, analog, blocks + class test_pll_carriertracking(gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_pll_carriertracking(self): - expected_result = ((1.000002384185791+7.219194575469601e-09j), - (0.9980257153511047+0.06279045343399048j), - (0.992796003818512+0.11979719996452332j), - (0.9852395057678223+0.17117266356945038j), - (0.9761406779289246+0.2171468883752823j), - (0.9661445617675781+0.25799843668937683j), - (0.9557913541793823+0.29403796792030334j), - (0.9455097317695618+0.3255884349346161j), - (0.935634434223175+0.35297322273254395j), - (0.9264140129089355+0.37650591135025024j), - (0.918036699295044+0.3964899182319641j), - (0.9106329679489136+0.4132115840911865j), - (0.9042812585830688+0.42693787813186646j), - (0.899017333984375+0.4379141628742218j), - (0.89484703540802+0.4463684558868408j), - (0.891755223274231+0.45251286029815674j), - (0.8897027969360352+0.4565400779247284j), - (0.8886303901672363+0.45862627029418945j), - (0.8884686827659607+0.4589335024356842j), - (0.8891477584838867+0.4576151967048645j), - (0.8905870318412781+0.4548112750053406j), - (0.8927018642425537+0.4506511092185974j), - (0.8954030275344849+0.4452534019947052j), - (0.898613452911377+0.43873584270477295j), - (0.9022520780563354+0.4312065541744232j), - (0.9062415361404419+0.42276597023010254j), - (0.9104995131492615+0.4135076403617859j), - (0.9149653315544128+0.4035266935825348j), - (0.9195748567581177+0.3929111361503601j), - (0.9242699146270752+0.3817441761493683j), - (0.9289909601211548+0.37010061740875244j), - (0.9336962103843689+0.3580598831176758j), - (0.9383456707000732+0.3456934690475464j), - (0.9429033994674683+0.3330692648887634j), - (0.9473329186439514+0.3202497363090515j), - (0.9516113996505737+0.3072968125343323j), - (0.9557210206985474+0.2942683696746826j), - (0.9596443772315979+0.2812172472476959j), - (0.963365912437439+0.2681918740272522j), - (0.9668760299682617+0.2552390694618225j), - (0.9701738357543945+0.24240154027938843j), - (0.9732568264007568+0.22971850633621216j), - (0.9761228561401367+0.21722495555877686j), - (0.9787704944610596+0.20495179295539856j), - (0.9812103509902954+0.1929289996623993j), - (0.98344886302948+0.18118229508399963j), - (0.9854917526245117+0.1697331666946411j), - (0.9873413443565369+0.1586003601551056j), - (0.989014744758606+0.147801473736763j), - (0.9905213713645935+0.1373506784439087j), - (0.9918720126152039+0.12725868821144104j), - (0.9930678606033325+0.1175333634018898j), - (0.9941287040710449+0.10818269848823547j), - (0.9950648546218872+0.0992119163274765j), - (0.995887041091919+0.09062285721302032j), - (0.9965973496437073+0.08241605758666992j), - (0.9972119927406311+0.07459107041358948j), - (0.997741162776947+0.06714606285095215j), - (0.9981945753097534+0.06007742881774902j), - (0.9985741376876831+0.05337977409362793j), - (0.9988903999328613+0.04704824090003967j), - (0.9991542100906372+0.04107558727264404j), - (0.9993717074394226+0.03545379638671875j), - (0.9995449185371399+0.03017553687095642j), - (0.9996798634529114+0.025230854749679565j), - (0.999785304069519+0.02061113715171814j), - (0.9998669624328613+0.01630493998527527j), - (0.9999253749847412+0.012303531169891357j), - (0.999961256980896+0.008596181869506836j), - (0.9999842047691345+0.005170613527297974j), - (0.9999972581863403+0.0020167529582977295j), - (1.0000011920928955-0.0008766651153564453j), - (0.9999923706054688-0.0035211145877838135j), - (0.999980092048645-0.00592736154794693j), - (0.9999660849571228-0.008106544613838196j), - (0.9999516606330872-0.010069712996482849j), - (0.9999289512634277-0.011828280985355377j), - (0.9999079704284668-0.013392657041549683j), - (0.9998894333839417-0.01477348804473877j), - (0.9998739957809448-0.015980780124664307j), - (0.9998545050621033-0.017024904489517212j), - (0.9998371601104736-0.017916440963745117j), - (0.9998237490653992-0.01866436004638672j), - (0.999815046787262-0.01927858591079712j), - (0.9998044967651367-0.019767403602600098j), - (0.9997949600219727-0.020140081644058228j), - (0.9997900128364563-0.020405471324920654j), - (0.9997888207435608-0.020570307970046997j), - (0.9997872114181519-0.020643681287765503j), - (0.9997851848602295-0.020633310079574585j), - (0.9997866153717041-0.020545780658721924j), - (0.9997920989990234-0.020388543605804443j), - (0.9997975826263428-0.02016708254814148j), - (0.9998003840446472-0.019888341426849365j), - (0.99980628490448-0.019558459520339966j), - (0.9998152256011963-0.019182950258255005j), - (0.9998254179954529-0.01876668632030487j), - (0.9998309016227722-0.01831553876399994j), - (0.999838650226593-0.017833217978477478j), - (0.9998488426208496-0.017324130982160568j)) + expected_result = ((1.000002384185791 + 7.219194575469601e-09j), + (0.9980257153511047 + 0.06279045343399048j), + (0.992796003818512 + 0.11979719996452332j), + (0.9852395057678223 + 0.17117266356945038j), + (0.9761406779289246 + 0.2171468883752823j), + (0.9661445617675781 + 0.25799843668937683j), + (0.9557913541793823 + 0.29403796792030334j), + (0.9455097317695618 + 0.3255884349346161j), + (0.935634434223175 + 0.35297322273254395j), + (0.9264140129089355 + 0.37650591135025024j), + (0.918036699295044 + 0.3964899182319641j), + (0.9106329679489136 + 0.4132115840911865j), + (0.9042812585830688 + 0.42693787813186646j), + (0.899017333984375 + 0.4379141628742218j), + (0.89484703540802 + 0.4463684558868408j), + (0.891755223274231 + 0.45251286029815674j), + (0.8897027969360352 + 0.4565400779247284j), + (0.8886303901672363 + 0.45862627029418945j), + (0.8884686827659607 + 0.4589335024356842j), + (0.8891477584838867 + 0.4576151967048645j), + (0.8905870318412781 + 0.4548112750053406j), + (0.8927018642425537 + 0.4506511092185974j), + (0.8954030275344849 + 0.4452534019947052j), + (0.898613452911377 + 0.43873584270477295j), + (0.9022520780563354 + 0.4312065541744232j), + (0.9062415361404419 + 0.42276597023010254j), + (0.9104995131492615 + 0.4135076403617859j), + (0.9149653315544128 + 0.4035266935825348j), + (0.9195748567581177 + 0.3929111361503601j), + (0.9242699146270752 + 0.3817441761493683j), + (0.9289909601211548 + 0.37010061740875244j), + (0.9336962103843689 + 0.3580598831176758j), + (0.9383456707000732 + 0.3456934690475464j), + (0.9429033994674683 + 0.3330692648887634j), + (0.9473329186439514 + 0.3202497363090515j), + (0.9516113996505737 + 0.3072968125343323j), + (0.9557210206985474 + 0.2942683696746826j), + (0.9596443772315979 + 0.2812172472476959j), + (0.963365912437439 + 0.2681918740272522j), + (0.9668760299682617 + 0.2552390694618225j), + (0.9701738357543945 + 0.24240154027938843j), + (0.9732568264007568 + 0.22971850633621216j), + (0.9761228561401367 + 0.21722495555877686j), + (0.9787704944610596 + 0.20495179295539856j), + (0.9812103509902954 + 0.1929289996623993j), + (0.98344886302948 + 0.18118229508399963j), + (0.9854917526245117 + 0.1697331666946411j), + (0.9873413443565369 + 0.1586003601551056j), + (0.989014744758606 + 0.147801473736763j), + (0.9905213713645935 + 0.1373506784439087j), + (0.9918720126152039 + 0.12725868821144104j), + (0.9930678606033325 + 0.1175333634018898j), + (0.9941287040710449 + 0.10818269848823547j), + (0.9950648546218872 + 0.0992119163274765j), + (0.995887041091919 + 0.09062285721302032j), + (0.9965973496437073 + 0.08241605758666992j), + (0.9972119927406311 + 0.07459107041358948j), + (0.997741162776947 + 0.06714606285095215j), + (0.9981945753097534 + 0.06007742881774902j), + (0.9985741376876831 + 0.05337977409362793j), + (0.9988903999328613 + 0.04704824090003967j), + (0.9991542100906372 + 0.04107558727264404j), + (0.9993717074394226 + 0.03545379638671875j), + (0.9995449185371399 + 0.03017553687095642j), + (0.9996798634529114 + 0.025230854749679565j), + (0.999785304069519 + 0.02061113715171814j), + (0.9998669624328613 + 0.01630493998527527j), + (0.9999253749847412 + 0.012303531169891357j), + (0.999961256980896 + 0.008596181869506836j), + (0.9999842047691345 + 0.005170613527297974j), + (0.9999972581863403 + 0.0020167529582977295j), + (1.0000011920928955 - 0.0008766651153564453j), + (0.9999923706054688 - 0.0035211145877838135j), + (0.999980092048645 - 0.00592736154794693j), + (0.9999660849571228 - 0.008106544613838196j), + (0.9999516606330872 - 0.010069712996482849j), + (0.9999289512634277 - 0.011828280985355377j), + (0.9999079704284668 - 0.013392657041549683j), + (0.9998894333839417 - 0.01477348804473877j), + (0.9998739957809448 - 0.015980780124664307j), + (0.9998545050621033 - 0.017024904489517212j), + (0.9998371601104736 - 0.017916440963745117j), + (0.9998237490653992 - 0.01866436004638672j), + (0.999815046787262 - 0.01927858591079712j), + (0.9998044967651367 - 0.019767403602600098j), + (0.9997949600219727 - 0.020140081644058228j), + (0.9997900128364563 - 0.020405471324920654j), + (0.9997888207435608 - 0.020570307970046997j), + (0.9997872114181519 - 0.020643681287765503j), + (0.9997851848602295 - 0.020633310079574585j), + (0.9997866153717041 - 0.020545780658721924j), + (0.9997920989990234 - 0.020388543605804443j), + (0.9997975826263428 - 0.02016708254814148j), + (0.9998003840446472 - 0.019888341426849365j), + (0.99980628490448 - 0.019558459520339966j), + (0.9998152256011963 - 0.019182950258255005j), + (0.9998254179954529 - 0.01876668632030487j), + (0.9998309016227722 - 0.01831553876399994j), + (0.999838650226593 - 0.017833217978477478j), + (0.9998488426208496 - 0.017324130982160568j)) sampling_freq = 10e3 freq = sampling_freq / 100 @@ -132,7 +133,7 @@ class test_pll_carriertracking(gr_unittest.TestCase): src = analog.sig_source_c(sampling_freq, analog.GR_COS_WAVE, freq, 1.0) pll = analog.pll_carriertracking_cc(loop_bw, maxf, minf) - head = blocks.head(gr.sizeof_gr_complex, int (freq)) + head = blocks.head(gr.sizeof_gr_complex, int(freq)) dst = blocks.vector_sink_c() self.tb.connect(src, pll, head) @@ -142,5 +143,6 @@ class test_pll_carriertracking(gr_unittest.TestCase): dst_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 5) + if __name__ == '__main__': gr_unittest.run(test_pll_carriertracking) diff --git a/gr-analog/python/analog/qa_pll_freqdet.py b/gr-analog/python/analog/qa_pll_freqdet.py index 12909e7715..e77f856565 100644 --- a/gr-analog/python/analog/qa_pll_freqdet.py +++ b/gr-analog/python/analog/qa_pll_freqdet.py @@ -13,115 +13,116 @@ import math from gnuradio import gr, gr_unittest, analog, blocks + class test_pll_freqdet(gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_pll_freqdet(self): expected_result = (0.0, - 4.338889228818161e-08, - 0.3776331578612825, - 1.0993741049896133, - 2.1332509128284287, - 3.448827166947317, - 5.017193050406445, - 6.810936277840595, - 8.804128662605573, - 10.972292025122194, - 13.292363360097312, - 15.742678902380248, - 18.302902979158944, - 20.954030233328815, - 23.678333003762834, - 26.459293141999492, - 29.2815901542755, - 32.13105969864019, - 34.99462836613535, - 37.860284035876894, - 40.71702547869386, - 43.5548208542428, - 46.364569172614004, - 49.138038040003174, - 51.86783994277676, - 54.547378886619114, - 57.17080592915505, - 59.73298657053974, - 62.229444428114014, - 64.65634937843706, - 67.01044048049889, - 69.28902004673668, - 71.48990028218192, - 73.61137363954212, - 75.65217724529884, - 77.61146325478951, - 79.48876920728905, - 81.28396466515709, - 82.9972452848542, - 84.62912095897468, - 86.18033873945902, - 87.65188876657749, - 89.0449983399466, - 90.36106669970881, - 91.6016768844999, - 92.76854829957963, - 93.86354857479924, - 94.88865206171563, - 95.84592204664062, - 96.73751075064077, - 97.56564154258655, - 98.33257336525031, - 99.04061259327368, - 99.69208931723288, - 100.28935141465512, - 100.83475862103487, - 101.33065881389933, - 101.77937615484109, - 102.18323480545271, - 102.54452335342484, - 102.8654948125462, - 103.14836662270359, - 103.39530879191456, - 103.6084320383601, - 103.78982336428665, - 103.94148676616939, - 104.06536695064705, - 104.16337305045634, - 104.23733119256288, - 104.28900821409572, - 104.32008794641274, - 104.33220678900258, - 104.32694185151738, - 104.30578723783803, - 104.27016590404165, - 104.22144151636876, - 104.16091845122337, - 104.08982993720561, - 104.00932619714447, - 103.9205337379343, - 103.82447234476369, - 103.72213808688659, - 103.6144440277858, - 103.50225579907487, - 103.38636788456353, - 103.26755105212685, - 103.14649306386876, - 103.02383425002395, - 102.90019122489248, - 102.7761213129379, - 102.65211069081985, - 102.5286218192634, - 102.40608158509168, - 102.28486944325857, - 102.16532927481605, - 102.04778124488143, - 101.93248622873554, - 101.81969324369186, - 101.70961573316195, - 101.60243156665544) + 4.338889228818161e-08, + 0.3776331578612825, + 1.0993741049896133, + 2.1332509128284287, + 3.448827166947317, + 5.017193050406445, + 6.810936277840595, + 8.804128662605573, + 10.972292025122194, + 13.292363360097312, + 15.742678902380248, + 18.302902979158944, + 20.954030233328815, + 23.678333003762834, + 26.459293141999492, + 29.2815901542755, + 32.13105969864019, + 34.99462836613535, + 37.860284035876894, + 40.71702547869386, + 43.5548208542428, + 46.364569172614004, + 49.138038040003174, + 51.86783994277676, + 54.547378886619114, + 57.17080592915505, + 59.73298657053974, + 62.229444428114014, + 64.65634937843706, + 67.01044048049889, + 69.28902004673668, + 71.48990028218192, + 73.61137363954212, + 75.65217724529884, + 77.61146325478951, + 79.48876920728905, + 81.28396466515709, + 82.9972452848542, + 84.62912095897468, + 86.18033873945902, + 87.65188876657749, + 89.0449983399466, + 90.36106669970881, + 91.6016768844999, + 92.76854829957963, + 93.86354857479924, + 94.88865206171563, + 95.84592204664062, + 96.73751075064077, + 97.56564154258655, + 98.33257336525031, + 99.04061259327368, + 99.69208931723288, + 100.28935141465512, + 100.83475862103487, + 101.33065881389933, + 101.77937615484109, + 102.18323480545271, + 102.54452335342484, + 102.8654948125462, + 103.14836662270359, + 103.39530879191456, + 103.6084320383601, + 103.78982336428665, + 103.94148676616939, + 104.06536695064705, + 104.16337305045634, + 104.23733119256288, + 104.28900821409572, + 104.32008794641274, + 104.33220678900258, + 104.32694185151738, + 104.30578723783803, + 104.27016590404165, + 104.22144151636876, + 104.16091845122337, + 104.08982993720561, + 104.00932619714447, + 103.9205337379343, + 103.82447234476369, + 103.72213808688659, + 103.6144440277858, + 103.50225579907487, + 103.38636788456353, + 103.26755105212685, + 103.14649306386876, + 103.02383425002395, + 102.90019122489248, + 102.7761213129379, + 102.65211069081985, + 102.5286218192634, + 102.40608158509168, + 102.28486944325857, + 102.16532927481605, + 102.04778124488143, + 101.93248622873554, + 101.81969324369186, + 101.70961573316195, + 101.60243156665544) sampling_freq = 10e3 freq = sampling_freq / 100 @@ -132,7 +133,7 @@ class test_pll_freqdet(gr_unittest.TestCase): src = analog.sig_source_c(sampling_freq, analog.GR_COS_WAVE, freq, 1.0) pll = analog.pll_freqdet_cf(loop_bw, maxf, minf) - head = blocks.head(gr.sizeof_float, int (freq)) + head = blocks.head(gr.sizeof_float, int(freq)) dst = blocks.vector_sink_f() self.tb.connect(src, pll, head) @@ -142,9 +143,10 @@ class test_pll_freqdet(gr_unittest.TestCase): dst_data = dst.data() # convert it from normalized frequency to absolute frequency (Hz) - dst_data = [i*(sampling_freq / (2*math.pi)) for i in dst_data] + dst_data = [i * (sampling_freq / (2 * math.pi)) for i in dst_data] self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 3) + if __name__ == '__main__': gr_unittest.run(test_pll_freqdet) diff --git a/gr-analog/python/analog/qa_pll_refout.py b/gr-analog/python/analog/qa_pll_refout.py index 8720432610..0a2ec724c8 100644 --- a/gr-analog/python/analog/qa_pll_refout.py +++ b/gr-analog/python/analog/qa_pll_refout.py @@ -13,6 +13,7 @@ import math from gnuradio import gr, gr_unittest, analog, blocks + class test_pll_refout(gr_unittest.TestCase): def setUp(self): @@ -22,106 +23,106 @@ class test_pll_refout(gr_unittest.TestCase): self.tb = None def test_pll_refout(self): - expected_result = ((1+0j), - (1+6.408735764296125e-10j), - (0.9999844431877136+0.005577784031629562j), - (0.9998642802238464+0.016474783420562744j), - (0.9994739890098572+0.032431427389383316j), - (0.9985847473144531+0.05318402871489525j), - (0.996917188167572+0.07846084982156754j), - (0.9941533207893372+0.10797744989395142j), - (0.9899479150772095+0.14143235981464386j), - (0.9839394092559814+0.1785029172897339j), - (0.9757603406906128+0.2188417762517929j), - (0.9650475978851318+0.26207470893859863j), - (0.9514514803886414+0.30779871344566345j), - (0.9346449971199036+0.35558223724365234j), - (0.9143316149711609+0.40496626496315j), - (0.8902531862258911+0.4554659426212311j), - (0.8621962666511536+0.5065743923187256j), - (0.8299974799156189+0.5577671527862549j), - (0.7935484647750854+0.6085070967674255j), - (0.7527987360954285+0.6582507491111755j), - (0.7077582478523254+0.7064547538757324j), - (0.6584978699684143+0.7525825500488281j), - (0.6051493883132935+0.7961119413375854j), - (0.547903835773468+0.8365413546562195j), - (0.48700881004333496+0.8733970522880554j), - (0.42276495695114136+0.90623939037323j), - (0.35552138090133667+0.9346681237220764j), - (0.2856702208518982+0.9583280086517334j), - (0.21364101767539978+0.976912260055542j), - (0.13989387452602386+0.9901664853096008j), - (0.06491273641586304+0.9978909492492676j), - (-0.01080091018229723+0.9999416470527649j), - (-0.08673560619354248+0.9962313771247864j), - (-0.16237612068653107+0.9867289662361145j), - (-0.23721040785312653+0.9714583158493042j), - (-0.3107353150844574+0.95049649477005j), - (-0.3824624717235565+0.9239710569381714j), - (-0.45192304253578186+0.892056941986084j), - (-0.5186731219291687+0.8549726009368896j), - (-0.5822963714599609+0.812976598739624j), - (-0.6424083709716797+0.7663624882698059j), - (-0.6986585855484009+0.7154552340507507j), - (-0.7507330775260925+0.6606056690216064j), - (-0.7983550429344177+0.6021870970726013j), - (-0.841286301612854+0.5405898094177246j), - (-0.879327654838562+0.47621726989746094j), - (-0.912318229675293+0.4094819128513336j), - (-0.9401354789733887+0.340800940990448j), - (-0.9626938104629517+0.27059316635131836j), - (-0.979943573474884+0.1992751508951187j), - (-0.9918696284294128+0.12725839018821716j), - (-0.9984893202781677+0.054946307092905045j), - (-0.9998509287834167-0.017267409712076187j), - (-0.9960314631462097-0.08900183439254761j), - (-0.9871346950531006-0.1598907858133316j), - (-0.9732890129089355-0.2295832633972168j), - (-0.9546451568603516-0.29774588346481323j), - (-0.9313743710517883-0.3640628457069397j), - (-0.9036663174629211-0.42823725938796997j), - (-0.8717266321182251-0.48999255895614624j), - (-0.8357754945755005-0.5490713119506836j), - (-0.7960456013679504-0.6052366495132446j), - (-0.7527803182601929-0.658271849155426j), - (-0.706232488155365-0.7079799771308899j), - (-0.6566619873046875-0.7541850209236145j), - (-0.6043350696563721-0.7967302799224854j), - (-0.5495226979255676-0.8354787826538086j), - (-0.4924990236759186-0.8703129887580872j), - (-0.4335414469242096-0.9011335968971252j), - (-0.3729270100593567-0.927860677242279j), - (-0.3109343349933624-0.9504314064979553j), - (-0.2478405237197876-0.9688008427619934j), - (-0.18392162024974823-0.9829409122467041j), - (-0.11945075541734695-0.9928401112556458j), - (-0.05469784513115883-0.9985029697418213j), - (0.010069688782095909-0.9999492764472961j), - (0.07459097355604172-0.9972141981124878j), - (0.13860897719860077-0.9903472065925598j), - (0.2018725872039795-0.979411780834198j), - (0.2641367018222809-0.964485228061676j), - (0.32516375184059143-0.9456577301025391j), - (0.3847236633300781-0.9230318069458008j), - (0.44259318709373474-0.8967224955558777j), - (0.49855801463127136-0.8668563365936279j), - (0.5524120926856995-0.8335711359977722j), - (0.6039596796035767-0.7970148921012878j), - (0.6530137062072754-0.7573460936546326j), - (0.6993972063064575-0.7147331833839417j), - (0.7429447770118713-0.6693527102470398j), - (0.7835012078285217-0.6213902235031128j), - (0.8209227919578552-0.5710391998291016j), - (0.8550769090652466-0.5185011625289917j), - (0.8858439326286316-0.46398329734802246j), - (0.9131162166595459-0.4076994061470032j), - (0.936798632144928-0.3498689830303192j), - (0.956809401512146-0.2907160222530365j), - (0.9730796813964844-0.23046888411045074j), - (0.9855544567108154-0.16935895383358002j), - (0.9941920042037964-0.10762103646993637j), - (0.9989647269248962-0.045491550117731094j)) + expected_result = ((1 + 0j), + (1 + 6.408735764296125e-10j), + (0.9999844431877136 + 0.005577784031629562j), + (0.9998642802238464 + 0.016474783420562744j), + (0.9994739890098572 + 0.032431427389383316j), + (0.9985847473144531 + 0.05318402871489525j), + (0.996917188167572 + 0.07846084982156754j), + (0.9941533207893372 + 0.10797744989395142j), + (0.9899479150772095 + 0.14143235981464386j), + (0.9839394092559814 + 0.1785029172897339j), + (0.9757603406906128 + 0.2188417762517929j), + (0.9650475978851318 + 0.26207470893859863j), + (0.9514514803886414 + 0.30779871344566345j), + (0.9346449971199036 + 0.35558223724365234j), + (0.9143316149711609 + 0.40496626496315j), + (0.8902531862258911 + 0.4554659426212311j), + (0.8621962666511536 + 0.5065743923187256j), + (0.8299974799156189 + 0.5577671527862549j), + (0.7935484647750854 + 0.6085070967674255j), + (0.7527987360954285 + 0.6582507491111755j), + (0.7077582478523254 + 0.7064547538757324j), + (0.6584978699684143 + 0.7525825500488281j), + (0.6051493883132935 + 0.7961119413375854j), + (0.547903835773468 + 0.8365413546562195j), + (0.48700881004333496 + 0.8733970522880554j), + (0.42276495695114136 + 0.90623939037323j), + (0.35552138090133667 + 0.9346681237220764j), + (0.2856702208518982 + 0.9583280086517334j), + (0.21364101767539978 + 0.976912260055542j), + (0.13989387452602386 + 0.9901664853096008j), + (0.06491273641586304 + 0.9978909492492676j), + (-0.01080091018229723 + 0.9999416470527649j), + (-0.08673560619354248 + 0.9962313771247864j), + (-0.16237612068653107 + 0.9867289662361145j), + (-0.23721040785312653 + 0.9714583158493042j), + (-0.3107353150844574 + 0.95049649477005j), + (-0.3824624717235565 + 0.9239710569381714j), + (-0.45192304253578186 + 0.892056941986084j), + (-0.5186731219291687 + 0.8549726009368896j), + (-0.5822963714599609 + 0.812976598739624j), + (-0.6424083709716797 + 0.7663624882698059j), + (-0.6986585855484009 + 0.7154552340507507j), + (-0.7507330775260925 + 0.6606056690216064j), + (-0.7983550429344177 + 0.6021870970726013j), + (-0.841286301612854 + 0.5405898094177246j), + (-0.879327654838562 + 0.47621726989746094j), + (-0.912318229675293 + 0.4094819128513336j), + (-0.9401354789733887 + 0.340800940990448j), + (-0.9626938104629517 + 0.27059316635131836j), + (-0.979943573474884 + 0.1992751508951187j), + (-0.9918696284294128 + 0.12725839018821716j), + (-0.9984893202781677 + 0.054946307092905045j), + (-0.9998509287834167 - 0.017267409712076187j), + (-0.9960314631462097 - 0.08900183439254761j), + (-0.9871346950531006 - 0.1598907858133316j), + (-0.9732890129089355 - 0.2295832633972168j), + (-0.9546451568603516 - 0.29774588346481323j), + (-0.9313743710517883 - 0.3640628457069397j), + (-0.9036663174629211 - 0.42823725938796997j), + (-0.8717266321182251 - 0.48999255895614624j), + (-0.8357754945755005 - 0.5490713119506836j), + (-0.7960456013679504 - 0.6052366495132446j), + (-0.7527803182601929 - 0.658271849155426j), + (-0.706232488155365 - 0.7079799771308899j), + (-0.6566619873046875 - 0.7541850209236145j), + (-0.6043350696563721 - 0.7967302799224854j), + (-0.5495226979255676 - 0.8354787826538086j), + (-0.4924990236759186 - 0.8703129887580872j), + (-0.4335414469242096 - 0.9011335968971252j), + (-0.3729270100593567 - 0.927860677242279j), + (-0.3109343349933624 - 0.9504314064979553j), + (-0.2478405237197876 - 0.9688008427619934j), + (-0.18392162024974823 - 0.9829409122467041j), + (-0.11945075541734695 - 0.9928401112556458j), + (-0.05469784513115883 - 0.9985029697418213j), + (0.010069688782095909 - 0.9999492764472961j), + (0.07459097355604172 - 0.9972141981124878j), + (0.13860897719860077 - 0.9903472065925598j), + (0.2018725872039795 - 0.979411780834198j), + (0.2641367018222809 - 0.964485228061676j), + (0.32516375184059143 - 0.9456577301025391j), + (0.3847236633300781 - 0.9230318069458008j), + (0.44259318709373474 - 0.8967224955558777j), + (0.49855801463127136 - 0.8668563365936279j), + (0.5524120926856995 - 0.8335711359977722j), + (0.6039596796035767 - 0.7970148921012878j), + (0.6530137062072754 - 0.7573460936546326j), + (0.6993972063064575 - 0.7147331833839417j), + (0.7429447770118713 - 0.6693527102470398j), + (0.7835012078285217 - 0.6213902235031128j), + (0.8209227919578552 - 0.5710391998291016j), + (0.8550769090652466 - 0.5185011625289917j), + (0.8858439326286316 - 0.46398329734802246j), + (0.9131162166595459 - 0.4076994061470032j), + (0.936798632144928 - 0.3498689830303192j), + (0.956809401512146 - 0.2907160222530365j), + (0.9730796813964844 - 0.23046888411045074j), + (0.9855544567108154 - 0.16935895383358002j), + (0.9941920042037964 - 0.10762103646993637j), + (0.9989647269248962 - 0.045491550117731094j)) sampling_freq = 10e3 freq = sampling_freq / 100 @@ -132,7 +133,7 @@ class test_pll_refout(gr_unittest.TestCase): src = analog.sig_source_c(sampling_freq, analog.GR_COS_WAVE, freq, 1.0) pll = analog.pll_refout_cc(loop_bw, maxf, minf) - head = blocks.head(gr.sizeof_gr_complex, int (freq)) + head = blocks.head(gr.sizeof_gr_complex, int(freq)) dst = blocks.vector_sink_c() self.tb.connect(src, pll, head) @@ -142,5 +143,6 @@ class test_pll_refout(gr_unittest.TestCase): dst_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4) + if __name__ == '__main__': gr_unittest.run(test_pll_refout) diff --git a/gr-analog/python/analog/qa_probe_avg_mag_sqrd.py b/gr-analog/python/analog/qa_probe_avg_mag_sqrd.py index cc2bc49099..721b9a6f6b 100644 --- a/gr-analog/python/analog/qa_probe_avg_mag_sqrd.py +++ b/gr-analog/python/analog/qa_probe_avg_mag_sqrd.py @@ -13,20 +13,24 @@ import math from gnuradio import gr, gr_unittest, analog, blocks + def avg_mag_sqrd_c(x, alpha): - y = [0,] + y = [0, ] for xi in x: - tmp = alpha*(xi.real*xi.real + xi.imag*xi.imag) + (1-alpha)*y[-1] + tmp = alpha * (xi.real * xi.real + xi.imag * + xi.imag) + (1 - alpha) * y[-1] y.append(tmp) return y + def avg_mag_sqrd_f(x, alpha): - y = [0,] + y = [0, ] for xi in x: - tmp = alpha*(xi*xi) + (1-alpha)*y[-1] + tmp = alpha * (xi * xi) + (1 - alpha) * y[-1] y.append(tmp) return y + class test_probe_avg_mag_sqrd(gr_unittest.TestCase): def setUp(self): @@ -37,8 +41,17 @@ class test_probe_avg_mag_sqrd(gr_unittest.TestCase): def test_c_001(self): alpha = 0.0001 - src_data = [1.0+1.0j, 2.0+2.0j, 3.0+3.0j, 4.0+4.0j, 5.0+5.0j, - 6.0+6.0j, 7.0+7.0j, 8.0+8.0j, 9.0+9.0j, 10.0+10.0j] + src_data = [ + 1.0 + 1.0j, + 2.0 + 2.0j, + 3.0 + 3.0j, + 4.0 + 4.0j, + 5.0 + 5.0j, + 6.0 + 6.0j, + 7.0 + 7.0j, + 8.0 + 8.0j, + 9.0 + 9.0j, + 10.0 + 10.0j] expected_result = avg_mag_sqrd_c(src_data, alpha)[-1] src = blocks.vector_source_c(src_data) @@ -52,8 +65,17 @@ class test_probe_avg_mag_sqrd(gr_unittest.TestCase): def test_cf_002(self): alpha = 0.0001 - src_data = [1.0+1.0j, 2.0+2.0j, 3.0+3.0j, 4.0+4.0j, 5.0+5.0j, - 6.0+6.0j, 7.0+7.0j, 8.0+8.0j, 9.0+9.0j, 10.0+10.0j] + src_data = [ + 1.0 + 1.0j, + 2.0 + 2.0j, + 3.0 + 3.0j, + 4.0 + 4.0j, + 5.0 + 5.0j, + 6.0 + 6.0j, + 7.0 + 7.0j, + 8.0 + 8.0j, + 9.0 + 9.0j, + 10.0 + 10.0j] expected_result = avg_mag_sqrd_c(src_data, alpha)[0:-1] src = blocks.vector_source_c(src_data) @@ -82,6 +104,6 @@ class test_probe_avg_mag_sqrd(gr_unittest.TestCase): result_data = op.level() self.assertAlmostEqual(expected_result, result_data, 5) + if __name__ == '__main__': gr_unittest.run(test_probe_avg_mag_sqrd) - diff --git a/gr-analog/python/analog/qa_pwr_squelch.py b/gr-analog/python/analog/qa_pwr_squelch.py index 2ef4e9938f..81ecd7edd4 100644 --- a/gr-analog/python/analog/qa_pwr_squelch.py +++ b/gr-analog/python/analog/qa_pwr_squelch.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, analog, blocks + class test_pwr_squelch(gr_unittest.TestCase): def setUp(self): @@ -60,7 +61,7 @@ class test_pwr_squelch(gr_unittest.TestCase): self.tb.run() expected_result = src_data - expected_result[0:20] = 20*[0,] + expected_result[0:20] = 20 * [0, ] result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_result, result_data, 4) @@ -91,7 +92,6 @@ class test_pwr_squelch(gr_unittest.TestCase): g = op.gate() self.assertEqual(gate2, g) - def test_pwr_squelch_004(self): alpha = 0.0001 thr = -25 @@ -106,11 +106,11 @@ class test_pwr_squelch(gr_unittest.TestCase): self.tb.run() expected_result = src_data - expected_result[0:20] = 20*[0,] + expected_result[0:20] = 20 * [0, ] result_data = dst.data() self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4) + if __name__ == '__main__': gr_unittest.run(test_pwr_squelch) - diff --git a/gr-analog/python/analog/qa_quadrature_demod.py b/gr-analog/python/analog/qa_quadrature_demod.py index b44f700490..a3ca92cd17 100644 --- a/gr-analog/python/analog/qa_quadrature_demod.py +++ b/gr-analog/python/analog/qa_quadrature_demod.py @@ -13,6 +13,7 @@ import cmath from gnuradio import gr, gr_unittest, analog, blocks + class test_quadrature_demod(gr_unittest.TestCase): def setUp(self): @@ -28,13 +29,13 @@ class test_quadrature_demod(gr_unittest.TestCase): src_data = [] for i in range(200): ti = i / fs - src_data.append(cmath.exp(2j*cmath.pi*f*ti)) + 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] + expected_result = [0, ] + 199 * [1.0] src = blocks.vector_source_c(src_data) op = analog.quadrature_demod_cf(gain) @@ -47,6 +48,6 @@ class test_quadrature_demod(gr_unittest.TestCase): result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5) + if __name__ == '__main__': gr_unittest.run(test_quadrature_demod) - diff --git a/gr-analog/python/analog/qa_rail_ff.py b/gr-analog/python/analog/qa_rail_ff.py index e7556188e0..43c2d46d75 100644 --- a/gr-analog/python/analog/qa_rail_ff.py +++ b/gr-analog/python/analog/qa_rail_ff.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, analog, blocks + def clip(x, lo, hi): if(x < lo): return lo @@ -19,6 +20,7 @@ def clip(x, lo, hi): else: return x + class test_rail(gr_unittest.TestCase): def setUp(self): @@ -62,6 +64,6 @@ class test_rail(gr_unittest.TestCase): result_data = dst.data() self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4) + if __name__ == '__main__': gr_unittest.run(test_rail) - diff --git a/gr-analog/python/analog/qa_sig_source.py b/gr-analog/python/analog/qa_sig_source.py index aafcc28483..977a17d372 100644 --- a/gr-analog/python/analog/qa_sig_source.py +++ b/gr-analog/python/analog/qa_sig_source.py @@ -1,10 +1,10 @@ #!/usr/bin/env python # -#Copyright 2004, 2007, 2010, 2012, 2013, 2020 Free Software Foundation, Inc. +# Copyright 2004, 2007, 2010, 2012, 2013, 2020 Free Software Foundation, Inc. # -#This file is part of GNU Radio +# This file is part of GNU Radio # -#SPDX-License-Identifier: GPL-3.0-or-later +# SPDX-License-Identifier: GPL-3.0-or-later # # @@ -83,7 +83,7 @@ class test_sig_source(gr_unittest.TestCase): tb.connect(op, dst1) tb.run() dst_data = dst1.data() - #Let the python know we are dealing with signed int behind scenes + # Let the python know we are dealing with signed int behind scenes dst_data_signed = [b if b < 127 else (256 - b) * -1 for b in dst_data] self.assertFloatTuplesAlmostEqual(expected_result, dst_data_signed) @@ -118,7 +118,7 @@ class test_sig_source(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5) def test_sqr_c(self): - tb = self.tb #arg6 is a bit before -PI/2 + tb = self.tb # arg6 is a bit before -PI/2 expected_result = [1j, 1j, 0, 0, 1, 1, 1 + 0j, 1 + 1j, 1j] src1 = analog.sig_source_c(8, analog.GR_SQR_WAVE, 1.0, 1.0) op = blocks.head(gr.sizeof_gr_complex, 9) diff --git a/gr-analog/python/analog/qa_simple_squelch.py b/gr-analog/python/analog/qa_simple_squelch.py index a5635eca04..7fa9b70770 100644 --- a/gr-analog/python/analog/qa_simple_squelch.py +++ b/gr-analog/python/analog/qa_simple_squelch.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, analog, blocks + class test_simple_squelch(gr_unittest.TestCase): def setUp(self): @@ -47,11 +48,11 @@ class test_simple_squelch(gr_unittest.TestCase): self.tb.run() expected_result = src_data - expected_result[0:20] = 20*[0,] + expected_result[0:20] = 20 * [0, ] result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_result, result_data, 4) + if __name__ == '__main__': gr_unittest.run(test_simple_squelch) - diff --git a/gr-blocks/python/blocks/qa_add_mult_div_sub.py b/gr-blocks/python/blocks/qa_add_mult_div_sub.py index 0e516da0c8..ffcf2f4a52 100644 --- a/gr-blocks/python/blocks/qa_add_mult_div_sub.py +++ b/gr-blocks/python/blocks/qa_add_mult_div_sub.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_add_mult_div_sub(gr_unittest.TestCase): def setUp(self): @@ -62,30 +63,30 @@ class test_add_mult_div_sub(gr_unittest.TestCase): # add_XX def test_add_ss(self): - src1_data = [1, 2, 3, 4, 5] + src1_data = [1, 2, 3, 4, 5] src2_data = [8, -3, 4, 8, 2] expected_result = [9, -1, 7, 12, 7] op = blocks.add_ss() self.help_ss((src1_data, src2_data), expected_result, op) def test_add_ii(self): - src1_data = [1, 2, 3, 4, 5] + src1_data = [1, 2, 3, 4, 5] src2_data = [8, -3, 4, 8, 2] expected_result = [9, -1, 7, 12, 7] op = blocks.add_ii() self.help_ii((src1_data, src2_data), expected_result, op) def test_add_ff(self): - src1_data = [1.0, 2.0, 3.0, 4.0, 5.0] + src1_data = [1.0, 2.0, 3.0, 4.0, 5.0] src2_data = [8.0, -3.0, 4.0, 8.0, 2.0] expected_result = [9.0, -1.0, 7.0, 12.0, 7.0] op = blocks.add_ff() self.help_ff((src1_data, src2_data), expected_result, op) def test_add_cc(self): - src1_data = [1+1j, 2+2j, 3+3j, 4+4j, 5+5j] - src2_data = [8+8j, -3-3j, 4+4j, 8+8j, 2+2j] - expected_result = [9+9j, -1-1j, 7+7j, 12+12j, 7+7j] + src1_data = [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j, 5 + 5j] + src2_data = [8 + 8j, -3 - 3j, 4 + 4j, 8 + 8j, 2 + 2j] + expected_result = [9 + 9j, -1 - 1j, 7 + 7j, 12 + 12j, 7 + 7j] op = blocks.add_cc() self.help_cc((src1_data, src2_data), expected_result, op) @@ -111,43 +112,43 @@ class test_add_mult_div_sub(gr_unittest.TestCase): def test_add_const_cc(self): src_data = [1, 2, 3, 4, 5] - expected_result = [1+5j, 2+5j, 3+5j, 4+5j, 5+5j] + expected_result = [1 + 5j, 2 + 5j, 3 + 5j, 4 + 5j, 5 + 5j] op = blocks.add_const_cc(5j) self.help_cc((src_data,), expected_result, op) # multiply_XX def test_multiply_ss(self): - src1_data = [1, 2, 3, 4, 5] + src1_data = [1, 2, 3, 4, 5] src2_data = [8, -3, 4, 8, 2] expected_result = [8, -6, 12, 32, 10] op = blocks.multiply_ss() self.help_ss((src1_data, src2_data), - expected_result, op) + expected_result, op) def test_multiply_ii(self): - src1_data = [1, 2, 3, 4, 5] + src1_data = [1, 2, 3, 4, 5] src2_data = [8, -3, 4, 8, 2] expected_result = [8, -6, 12, 32, 10] op = blocks.multiply_ii() self.help_ii((src1_data, src2_data), - expected_result, op) + expected_result, op) def test_multiply_ff(self): - src1_data = [1, 2, 3, 4, 5] + src1_data = [1, 2, 3, 4, 5] src2_data = [8, -3, 4, 8, 2] expected_result = [8, -6, 12, 32, 10] op = blocks.multiply_ff() self.help_ff((src1_data, src2_data), - expected_result, op) + expected_result, op) def test_multiply_cc(self): - src1_data = [1+1j, 2+2j, 3+3j, 4+4j, 5+5j] + src1_data = [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j, 5 + 5j] src2_data = [8, -3, 4, 8, 2] - expected_result = [8+8j, -6-6j, 12+12j, 32+32j, 10+10j] + expected_result = [8 + 8j, -6 - 6j, 12 + 12j, 32 + 32j, 10 + 10j] op = blocks.multiply_cc() self.help_cc((src1_data, src2_data), - expected_result, op) + expected_result, op) # multiply_const_XX @@ -170,24 +171,24 @@ class test_add_mult_div_sub(gr_unittest.TestCase): self.help_ff((src_data,), expected_result, op) def test_multiply_const_cc(self): - src_data = [-1-1j, 0+0j, 1+1j, 2+2j, 3+3j] - expected_result = [-5-5j, 0+0j, 5+5j, 10+10j, 15+15j] + src_data = [-1 - 1j, 0 + 0j, 1 + 1j, 2 + 2j, 3 + 3j] + expected_result = [-5 - 5j, 0 + 0j, 5 + 5j, 10 + 10j, 15 + 15j] op = blocks.multiply_const_cc(5) self.help_cc((src_data,), expected_result, op) def test_multiply_const_cc2(self): - src_data = [-1-1j, 0+0j, 1+1j, 2+2j, 3+3j] - expected_result = [-3-7j, 0+0j, 3+7j, 6+14j, 9+21j] - op = blocks.multiply_const_cc(5+2j) + src_data = [-1 - 1j, 0 + 0j, 1 + 1j, 2 + 2j, 3 + 3j] + expected_result = [-3 - 7j, 0 + 0j, 3 + 7j, 6 + 14j, 9 + 21j] + op = blocks.multiply_const_cc(5 + 2j) self.help_cc((src_data,), expected_result, op) def test_sub_ii(self): - src1_data = [1, 2, 3, 4, 5] + src1_data = [1, 2, 3, 4, 5] src2_data = [8, -3, 4, 8, 2] expected_result = [-7, 5, -1, -4, 3] op = blocks.sub_ii() self.help_ii((src1_data, src2_data), - expected_result, op) + expected_result, op) def test_sub_ii1(self): src1_data = [1, 2, 3, 4, 5] @@ -202,12 +203,12 @@ class test_add_mult_div_sub(gr_unittest.TestCase): self.assertEqual(expected_result, result_data) def test_sub_ss(self): - src1_data = [1, 2, 3, 4, 5] + src1_data = [1, 2, 3, 4, 5] src2_data = [8, -3, 4, 8, 2] expected_result = [-7, 5, -1, -4, 3] op = blocks.sub_ss() self.help_ss((src1_data, src2_data), - expected_result, op) + expected_result, op) def test_sub_ss1(self): src1_data = [1, 2, 3, 4, 5] @@ -222,12 +223,12 @@ class test_add_mult_div_sub(gr_unittest.TestCase): self.assertEqual(expected_result, result_data) def test_sub_ff(self): - src1_data = [1, 2, 3, 4, 5] + src1_data = [1, 2, 3, 4, 5] src2_data = [8, -3, 4, 8, 2] expected_result = [-7, 5, -1, -4, 3] op = blocks.sub_ff() self.help_ff((src1_data, src2_data), - expected_result, op) + expected_result, op) def test_sub_ff1(self): src1_data = [1, 2, 3, 4, 5] @@ -242,12 +243,12 @@ class test_add_mult_div_sub(gr_unittest.TestCase): self.assertEqual(expected_result, result_data) def test_sub_cc(self): - src1_data = [1, 2, 3, 4, 5] + src1_data = [1, 2, 3, 4, 5] src2_data = [8, -3, 4, 8, 2] expected_result = [-7, 5, -1, -4, 3] op = blocks.sub_cc() self.help_cc((src1_data, src2_data), - expected_result, op) + expected_result, op) def test_sub_cc1(self): src1_data = [1, 2, 3, 4, 5] @@ -262,11 +263,12 @@ class test_add_mult_div_sub(gr_unittest.TestCase): self.assertEqual(expected_result, result_data) def test_div_ff(self): - src1_data = [ 5, 9, -15, 1024] - src2_data = [10, 3, -5, 64] - expected_result = [0.5, 3, 3, 16] + src1_data = [5, 9, -15, 1024] + src2_data = [10, 3, -5, 64] + expected_result = [0.5, 3, 3, 16] op = blocks.divide_ff() self.help_ff((src1_data, src2_data), expected_result, op) + if __name__ == '__main__': gr_unittest.run(test_add_mult_div_sub) diff --git a/gr-blocks/python/blocks/qa_add_mult_v.py b/gr-blocks/python/blocks/qa_add_mult_v.py index dd872ee8ce..39f11bc4be 100644 --- a/gr-blocks/python/blocks/qa_add_mult_v.py +++ b/gr-blocks/python/blocks/qa_add_mult_v.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_add_mult_v(gr_unittest.TestCase): def setUp(self): @@ -20,7 +21,7 @@ class test_add_mult_v(gr_unittest.TestCase): self.tb = None def help_ss(self, size, src_data, exp_data, op): - for s in zip(list(range(len (src_data))), src_data): + for s in zip(list(range(len(src_data))), src_data): src = blocks.vector_source_s(s[1]) srcv = blocks.stream_to_vector(gr.sizeof_short, size) self.tb.connect(src, srcv) @@ -34,7 +35,7 @@ class test_add_mult_v(gr_unittest.TestCase): self.assertEqual(exp_data, result_data) def help_ii(self, size, src_data, exp_data, op): - for s in zip(list(range(len (src_data))), src_data): + for s in zip(list(range(len(src_data))), src_data): src = blocks.vector_source_i(s[1]) srcv = blocks.stream_to_vector(gr.sizeof_int, size) self.tb.connect(src, srcv) @@ -48,7 +49,7 @@ class test_add_mult_v(gr_unittest.TestCase): self.assertEqual(exp_data, result_data) def help_ff(self, size, src_data, exp_data, op): - for s in zip(list(range(len (src_data))), src_data): + for s in zip(list(range(len(src_data))), src_data): src = blocks.vector_source_f(s[1]) srcv = blocks.stream_to_vector(gr.sizeof_float, size) self.tb.connect(src, srcv) @@ -62,7 +63,7 @@ class test_add_mult_v(gr_unittest.TestCase): self.assertEqual(exp_data, result_data) def help_cc(self, size, src_data, exp_data, op): - for s in zip(list(range(len (src_data))), src_data): + for s in zip(list(range(len(src_data))), src_data): src = blocks.vector_source_c(s[1]) srcv = blocks.stream_to_vector(gr.sizeof_gr_complex, size) self.tb.connect(src, srcv) @@ -118,10 +119,10 @@ class test_add_mult_v(gr_unittest.TestCase): # add_vXX def test_add_vss_one(self): - src1_data = [1,] - src2_data = [2,] - src3_data = [3,] - expected_result = [6,] + src1_data = [1, ] + src2_data = [2, ] + src3_data = [3, ] + expected_result = [6, ] op = blocks.add_ss(1) self.help_ss(1, (src1_data, src2_data, src3_data), expected_result, op) @@ -134,10 +135,10 @@ class test_add_mult_v(gr_unittest.TestCase): self.help_ss(5, (src1_data, src2_data, src3_data), expected_result, op) def test_add_vii_one(self): - src1_data = [1,] - src2_data = [2,] - src3_data = [3,] - expected_result = [6,] + src1_data = [1, ] + src2_data = [2, ] + src3_data = [3, ] + expected_result = [6, ] op = blocks.add_ii(1) self.help_ii(1, (src1_data, src2_data, src3_data), expected_result, op) @@ -150,10 +151,10 @@ class test_add_mult_v(gr_unittest.TestCase): self.help_ii(5, (src1_data, src2_data, src3_data), expected_result, op) def test_add_vff_one(self): - src1_data = [1.0,] - src2_data = [2.0,] - src3_data = [3.0,] - expected_result = [6.0,] + src1_data = [1.0, ] + src2_data = [2.0, ] + src3_data = [3.0, ] + expected_result = [6.0, ] op = blocks.add_ff(1) self.help_ff(1, (src1_data, src2_data, src3_data), expected_result, op) @@ -166,27 +167,47 @@ class test_add_mult_v(gr_unittest.TestCase): self.help_ff(5, (src1_data, src2_data, src3_data), expected_result, op) def test_add_vcc_one(self): - src1_data = [1.0+2.0j,] - src2_data = [3.0+4.0j,] - src3_data = [5.0+6.0j,] - expected_result = [9.0+12j,] + src1_data = [1.0 + 2.0j, ] + src2_data = [3.0 + 4.0j, ] + src3_data = [5.0 + 6.0j, ] + expected_result = [9.0 + 12j, ] op = blocks.add_cc(1) self.help_cc(1, (src1_data, src2_data, src3_data), expected_result, op) def test_add_vcc_five(self): - src1_data = [1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j] - src2_data = [11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j] - src3_data = [21.0+22.0j, 23.0+24.0j, 25.0+26.0j, 27.0+28.0j, 29.0+30.0j] - expected_result = [33.0+36.0j, 39.0+42.0j, 45.0+48.0j, 51.0+54.0j, 57.0+60.0j] + src1_data = [ + 1.0 + 2.0j, + 3.0 + 4.0j, + 5.0 + 6.0j, + 7.0 + 8.0j, + 9.0 + 10.0j] + src2_data = [ + 11.0 + 12.0j, + 13.0 + 14.0j, + 15.0 + 16.0j, + 17.0 + 18.0j, + 19.0 + 20.0j] + src3_data = [ + 21.0 + 22.0j, + 23.0 + 24.0j, + 25.0 + 26.0j, + 27.0 + 28.0j, + 29.0 + 30.0j] + expected_result = [ + 33.0 + 36.0j, + 39.0 + 42.0j, + 45.0 + 48.0j, + 51.0 + 54.0j, + 57.0 + 60.0j] op = blocks.add_cc(5) self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op) # add_const_vXX def test_add_const_vss_one(self): - src_data = [1,] + src_data = [1, ] op = blocks.add_const_vss((2,)) - exp_data = [3,] + exp_data = [3, ] self.help_const_ss(src_data, exp_data, op) def test_add_const_vss_five(self): @@ -196,9 +217,9 @@ class test_add_mult_v(gr_unittest.TestCase): self.help_const_ss(src_data, exp_data, op) def test_add_const_vii_one(self): - src_data = [1,] + src_data = [1, ] op = blocks.add_const_vii((2,)) - exp_data = [3,] + exp_data = [3, ] self.help_const_ii(src_data, exp_data, op) def test_add_const_vii_five(self): @@ -208,9 +229,9 @@ class test_add_mult_v(gr_unittest.TestCase): self.help_const_ii(src_data, exp_data, op) def test_add_const_vff_one(self): - src_data = [1.0,] + src_data = [1.0, ] op = blocks.add_const_vff((2.0,)) - exp_data = [3.0,] + exp_data = [3.0, ] self.help_const_ff(src_data, exp_data, op) def test_add_const_vff_five(self): @@ -220,24 +241,39 @@ class test_add_mult_v(gr_unittest.TestCase): self.help_const_ff(src_data, exp_data, op) def test_add_const_vcc_one(self): - src_data = [1.0+2.0j,] - op = blocks.add_const_vcc((2.0+3.0j,)) - exp_data = [3.0+5.0j,] + src_data = [1.0 + 2.0j, ] + op = blocks.add_const_vcc((2.0 + 3.0j,)) + exp_data = [3.0 + 5.0j, ] self.help_const_cc(src_data, exp_data, op) def test_add_const_vcc_five(self): - src_data = [1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j] - op = blocks.add_const_vcc((11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j)) - exp_data = [12.0+14.0j, 16.0+18.0j, 20.0+22.0j, 24.0+26.0j, 28.0+30.0j] + src_data = [ + 1.0 + 2.0j, + 3.0 + 4.0j, + 5.0 + 6.0j, + 7.0 + 8.0j, + 9.0 + 10.0j] + op = blocks.add_const_vcc( + (11.0 + 12.0j, + 13.0 + 14.0j, + 15.0 + 16.0j, + 17.0 + 18.0j, + 19.0 + 20.0j)) + exp_data = [ + 12.0 + 14.0j, + 16.0 + 18.0j, + 20.0 + 22.0j, + 24.0 + 26.0j, + 28.0 + 30.0j] self.help_const_cc(src_data, exp_data, op) # multiply_vXX def test_multiply_vss_one(self): - src1_data = [1,] - src2_data = [2,] - src3_data = [3,] - expected_result = [6,] + src1_data = [1, ] + src2_data = [2, ] + src3_data = [3, ] + expected_result = [6, ] op = blocks.multiply_ss(1) self.help_ss(1, (src1_data, src2_data, src3_data), expected_result, op) @@ -250,10 +286,10 @@ class test_add_mult_v(gr_unittest.TestCase): self.help_ss(5, (src1_data, src2_data, src3_data), expected_result, op) def test_multiply_vii_one(self): - src1_data = [1,] - src2_data = [2,] - src3_data = [3,] - expected_result = [6,] + src1_data = [1, ] + src2_data = [2, ] + src3_data = [3, ] + expected_result = [6, ] op = blocks.multiply_ii(1) self.help_ii(1, (src1_data, src2_data, src3_data), expected_result, op) @@ -266,10 +302,10 @@ class test_add_mult_v(gr_unittest.TestCase): self.help_ii(5, (src1_data, src2_data, src3_data), expected_result, op) def test_multiply_vff_one(self): - src1_data = [1.0,] - src2_data = [2.0,] - src3_data = [3.0,] - expected_result = [6.0,] + src1_data = [1.0, ] + src2_data = [2.0, ] + src3_data = [3.0, ] + expected_result = [6.0, ] op = blocks.multiply_ff(1) self.help_ff(1, (src1_data, src2_data, src3_data), expected_result, op) @@ -282,27 +318,43 @@ class test_add_mult_v(gr_unittest.TestCase): self.help_ff(5, (src1_data, src2_data, src3_data), expected_result, op) def test_multiply_vcc_one(self): - src1_data = [1.0+2.0j,] - src2_data = [3.0+4.0j,] - src3_data = [5.0+6.0j,] - expected_result = [-85+20j,] + src1_data = [1.0 + 2.0j, ] + src2_data = [3.0 + 4.0j, ] + src3_data = [5.0 + 6.0j, ] + expected_result = [-85 + 20j, ] op = blocks.multiply_cc(1) self.help_cc(1, (src1_data, src2_data, src3_data), expected_result, op) def test_multiply_vcc_five(self): - src1_data = [1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j] - src2_data = [11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j] - src3_data = [21.0+22.0j, 23.0+24.0j, 25.0+26.0j, 27.0+28.0j, 29.0+30.0j] - expected_result = [-1021.0+428.0j, -2647.0+1754.0j, -4945.0+3704.0j, -8011.0+6374.0j, -11941.0+9860.0j] + src1_data = [ + 1.0 + 2.0j, + 3.0 + 4.0j, + 5.0 + 6.0j, + 7.0 + 8.0j, + 9.0 + 10.0j] + src2_data = [ + 11.0 + 12.0j, + 13.0 + 14.0j, + 15.0 + 16.0j, + 17.0 + 18.0j, + 19.0 + 20.0j] + src3_data = [ + 21.0 + 22.0j, + 23.0 + 24.0j, + 25.0 + 26.0j, + 27.0 + 28.0j, + 29.0 + 30.0j] + expected_result = [-1021.0 + 428.0j, -2647.0 + 1754.0j, - \ + 4945.0 + 3704.0j, -8011.0 + 6374.0j, -11941.0 + 9860.0j] op = blocks.multiply_cc(5) self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op) # multiply_const_vXX def test_multiply_const_vss_one(self): - src_data = [2,] + src_data = [2, ] op = blocks.multiply_const_vss((3,)) - exp_data = [6,] + exp_data = [6, ] self.help_const_ss(src_data, exp_data, op) def test_multiply_const_vss_five(self): @@ -312,9 +364,9 @@ class test_add_mult_v(gr_unittest.TestCase): self.help_const_ss(src_data, exp_data, op) def test_multiply_const_vii_one(self): - src_data = [2,] + src_data = [2, ] op = blocks.multiply_const_vii((3,)) - exp_data = [6,] + exp_data = [6, ] self.help_const_ii(src_data, exp_data, op) def test_multiply_const_vii_five(self): @@ -324,9 +376,9 @@ class test_add_mult_v(gr_unittest.TestCase): self.help_const_ii(src_data, exp_data, op) def test_multiply_const_vff_one(self): - src_data = [2.0,] + src_data = [2.0, ] op = blocks.multiply_const_vff((3.0,)) - exp_data = [6.0,] + exp_data = [6.0, ] self.help_const_ff(src_data, exp_data, op) def test_multiply_const_vff_five(self): @@ -336,15 +388,22 @@ class test_add_mult_v(gr_unittest.TestCase): self.help_const_ff(src_data, exp_data, op) def test_multiply_const_vcc_one(self): - src_data = [1.0+2.0j,] - op = blocks.multiply_const_vcc((2.0+3.0j,)) - exp_data = [-4.0+7.0j,] + src_data = [1.0 + 2.0j, ] + op = blocks.multiply_const_vcc((2.0 + 3.0j,)) + exp_data = [-4.0 + 7.0j, ] self.help_const_cc(src_data, exp_data, op) def test_multiply_const_vcc_five(self): - src_data = [1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j] - op = blocks.multiply_const_vcc((11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j)) - exp_data = [-13.0+34.0j, -17.0+94.0j, -21.0+170.0j, -25.0+262.0j, -29.0+370.0j] + src_data = [ + 1.0 + 2.0j, + 3.0 + 4.0j, + 5.0 + 6.0j, + 7.0 + 8.0j, + 9.0 + 10.0j] + op = blocks.multiply_const_vcc( + (11.0 + 12.0j, 13.0 + 14.0j, 15.0 + 16.0j, 17.0 + 18.0j, 19.0 + 20.0j)) + exp_data = [-13.0 + 34.0j, -17.0 + 94.0j, - + 21.0 + 170.0j, -25.0 + 262.0j, -29.0 + 370.0j] self.help_const_cc(src_data, exp_data, op) diff --git a/gr-blocks/python/blocks/qa_affinity.py b/gr-blocks/python/blocks/qa_affinity.py index 35eb6c0ed8..8399df53e9 100644 --- a/gr-blocks/python/blocks/qa_affinity.py +++ b/gr-blocks/python/blocks/qa_affinity.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_affinity(gr_unittest.TestCase): def setUp(self): @@ -26,13 +27,14 @@ class test_affinity(gr_unittest.TestCase): src = blocks.vector_source_f(src_data) snk = blocks.vector_sink_f() - src.set_processor_affinity([0,]) + src.set_processor_affinity([0, ]) self.tb.connect(src, snk) self.tb.run() a = src.processor_affinity() - self.assertEqual([0,], a) + self.assertEqual([0, ], a) + if __name__ == '__main__': gr_unittest.run(test_affinity) diff --git a/gr-blocks/python/blocks/qa_argmax.py b/gr-blocks/python/blocks/qa_argmax.py index 3aac837c62..70797b330b 100644 --- a/gr-blocks/python/blocks/qa_argmax.py +++ b/gr-blocks/python/blocks/qa_argmax.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest, blocks import math + class test_arg_max(gr_unittest.TestCase): def setUp(self): @@ -24,9 +25,9 @@ class test_arg_max(gr_unittest.TestCase): def test_001(self): tb = self.tb - src1_data = [0,0.2,-0.3,0,12,0] - src2_data = [0,0.0,3.0,0,10,0] - src3_data = [0,0.0,3.0,0,1,0] + src1_data = [0, 0.2, -0.3, 0, 12, 0] + src2_data = [0, 0.0, 3.0, 0, 10, 0] + src3_data = [0, 0.0, 3.0, 0, 1, 0] src1 = blocks.vector_source_f(src1_data) s2v1 = blocks.stream_to_vector(gr.sizeof_float, len(src1_data)) @@ -48,15 +49,15 @@ class test_arg_max(gr_unittest.TestCase): tb.connect(s2v2, (argmax, 1)) tb.connect(s2v3, (argmax, 2)) - tb.connect((argmax,0), dst1) - tb.connect((argmax,1), dst2) + tb.connect((argmax, 0), dst1) + tb.connect((argmax, 1), dst2) tb.run() index = dst1.data() source = dst2.data() - self.assertEqual(index, [4,]) - self.assertEqual(source, [0,]) + self.assertEqual(index, [4, ]) + self.assertEqual(source, [0, ]) + if __name__ == '__main__': gr_unittest.run(test_arg_max) - diff --git a/gr-blocks/python/blocks/qa_block_behavior.py b/gr-blocks/python/blocks/qa_block_behavior.py index a4bec822b0..b1c7f5a0c4 100644 --- a/gr-blocks/python/blocks/qa_block_behavior.py +++ b/gr-blocks/python/blocks/qa_block_behavior.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_block_behavior(gr_unittest.TestCase): def setUp(self): @@ -30,7 +31,7 @@ class test_block_behavior(gr_unittest.TestCase): ''' src = blocks.null_source(gr.sizeof_float) - op = blocks.head(gr.sizeof_float, 100) + op = blocks.head(gr.sizeof_float, 100) snk = blocks.null_sink(gr.sizeof_float) maxn_pre = op.max_noutput_items() @@ -49,7 +50,7 @@ class test_block_behavior(gr_unittest.TestCase): ''' src = blocks.null_source(gr.sizeof_float) - op = blocks.head(gr.sizeof_float, 100) + op = blocks.head(gr.sizeof_float, 100) snk = blocks.null_sink(gr.sizeof_float) op.set_max_noutput_items(1024) @@ -64,5 +65,6 @@ class test_block_behavior(gr_unittest.TestCase): self.assertEqual(maxn_pre, 1024) self.assertEqual(maxn_post, 1024) + if __name__ == '__main__': gr_unittest.run(test_block_behavior) diff --git a/gr-blocks/python/blocks/qa_block_gateway.py b/gr-blocks/python/blocks/qa_block_gateway.py index f78ea27076..2f8071dfdd 100644 --- a/gr-blocks/python/blocks/qa_block_gateway.py +++ b/gr-blocks/python/blocks/qa_block_gateway.py @@ -18,81 +18,89 @@ from gnuradio import gr, gr_unittest, blocks class non_sync_block(gr.basic_block): def __init__(self): gr.basic_block.__init__(self, - name="non_sync_block", - in_sig=[numpy.float32], - out_sig=[numpy.float32, numpy.float32]) + name="non_sync_block", + in_sig=[numpy.float32], + out_sig=[numpy.float32, numpy.float32]) + def general_work(self, input_items, output_items): self.consume(0, len(input_items[0])) - self.produce(0,2) - self.produce(1,1) + self.produce(0, 2) + self.produce(1, 1) return gr.WORK_CALLED_PRODUCE + class add_2_f32_1_f32(gr.sync_block): def __init__(self): gr.sync_block.__init__( self, - name = "add 2 f32", - in_sig = [numpy.float32, numpy.float32], - out_sig = [numpy.float32], + name="add 2 f32", + in_sig=[numpy.float32, numpy.float32], + out_sig=[numpy.float32], ) def work(self, input_items, output_items): output_items[0][:] = input_items[0] + input_items[1] return len(output_items[0]) + class add_2_fc32_1_fc32(gr.sync_block): def __init__(self): gr.sync_block.__init__( self, - name = "add 2 fc32", - in_sig = [numpy.complex64, numpy.complex64], - out_sig = [numpy.complex64], + name="add 2 fc32", + in_sig=[numpy.complex64, numpy.complex64], + out_sig=[numpy.complex64], ) def work(self, input_items, output_items): output_items[0][:] = input_items[0] + input_items[1] return len(output_items[0]) + class convolve(gr.sync_block): """ A demonstration using block history to properly perform a convolution. """ + def __init__(self): gr.sync_block.__init__( self, - name = "convolve", - in_sig = [numpy.float32], - out_sig = [numpy.float32] + name="convolve", + in_sig=[numpy.float32], + out_sig=[numpy.float32] ) self._taps = [1, 0, 0, 0] self.set_history(len(self._taps)) def work(self, input_items, output_items): - output_items[0][:] = numpy.convolve(input_items[0], self._taps, mode='valid') + output_items[0][:] = numpy.convolve( + input_items[0], self._taps, mode='valid') return len(output_items[0]) + class decim2x(gr.decim_block): def __init__(self): gr.decim_block.__init__( self, - name = "decim2x", - in_sig = [numpy.float32], - out_sig = [numpy.float32], - decim = 2 + name="decim2x", + in_sig=[numpy.float32], + out_sig=[numpy.float32], + decim=2 ) def work(self, input_items, output_items): output_items[0][:] = input_items[0][::2] return len(output_items[0]) + class interp2x(gr.interp_block): def __init__(self): gr.interp_block.__init__( self, - name = "interp2x", - in_sig = [numpy.float32], - out_sig = [numpy.float32], - interp = 2 + name="interp2x", + in_sig=[numpy.float32], + out_sig=[numpy.float32], + interp=2 ) def work(self, input_items, output_items): @@ -100,21 +108,22 @@ class interp2x(gr.interp_block): output_items[0][::2] = input_items[0] return len(output_items[0]) + class tag_source(gr.sync_block): def __init__(self): gr.sync_block.__init__( self, - name = "tag source", - in_sig = None, - out_sig = [numpy.float32], + name="tag source", + in_sig=None, + out_sig=[numpy.float32], ) def work(self, input_items, output_items): num_output_items = len(output_items[0]) - #put code here to fill the output items... + # put code here to fill the output items... - #make a new tag on the middle element every time work is called + # make a new tag on the middle element every time work is called count = self.nitems_written(0) + num_output_items // 2 key = pmt.string_to_symbol("example_key") value = pmt.string_to_symbol("example_value") @@ -122,37 +131,39 @@ class tag_source(gr.sync_block): return num_output_items + class tag_sink(gr.sync_block): def __init__(self): gr.sync_block.__init__( self, - name = "tag sink", - in_sig = [numpy.float32], - out_sig = None, + name="tag sink", + in_sig=[numpy.float32], + out_sig=None, ) self.key = None def work(self, input_items, output_items): num_input_items = len(input_items[0]) - #put code here to process the input items... + # put code here to process the input items... - #print all the tags received in this work call + # print all the tags received in this work call nread = self.nitems_read(0) - tags = self.get_tags_in_range(0, nread, nread+num_input_items) + tags = self.get_tags_in_range(0, nread, nread + num_input_items) for tag in tags: - #print tag.offset - #print pmt.symbol_to_string(tag.key) - #print pmt.symbol_to_string(tag.value) + # print tag.offset + # print pmt.symbol_to_string(tag.key) + # print pmt.symbol_to_string(tag.value) self.key = pmt.symbol_to_string(tag.key) return num_input_items + class tag_sink_win(gr.sync_block): def __init__(self): - gr.sync_block.__init__(self, name = "tag sink", - in_sig = [numpy.float32], - out_sig = None) + gr.sync_block.__init__(self, name="tag sink", + in_sig=[numpy.float32], + out_sig=None) self.key = None def work(self, input_items, output_items): @@ -162,28 +173,30 @@ class tag_sink_win(gr.sync_block): self.key = pmt.symbol_to_string(tag.key) return num_input_items + class fc32_to_f32_2(gr.sync_block): def __init__(self): gr.sync_block.__init__( self, - name = "fc32_to_f32_2", - in_sig = [numpy.complex64], - out_sig = [(numpy.float32, 2)], + name="fc32_to_f32_2", + in_sig=[numpy.complex64], + out_sig=[(numpy.float32, 2)], ) def work(self, input_items, output_items): - output_items[0][::,0] = numpy.real(input_items[0]) - output_items[0][::,1] = numpy.imag(input_items[0]) + output_items[0][::, 0] = numpy.real(input_items[0]) + output_items[0][::, 1] = numpy.imag(input_items[0]) return len(output_items[0]) + class vector_to_stream(gr.interp_block): def __init__(self, itemsize, nitems_per_block): gr.interp_block.__init__( self, - name = "vector_to_stream", - in_sig = [(itemsize, nitems_per_block)], - out_sig = [itemsize], - interp = nitems_per_block + name="vector_to_stream", + in_sig=[(itemsize, nitems_per_block)], + out_sig=[itemsize], + interp=nitems_per_block ) self.block_size = nitems_per_block @@ -196,6 +209,7 @@ class vector_to_stream(gr.interp_block): return len(output_items[0]) + class test_block_gateway(gr_unittest.TestCase): def test_add_f32(self): @@ -253,7 +267,8 @@ class test_block_gateway(gr_unittest.TestCase): def test_tags(self): src = tag_source() sink = tag_sink() - head = blocks.head(gr.sizeof_float, 50000) #should be enough items to get a tag through + # should be enough items to get a tag through + head = blocks.head(gr.sizeof_float, 50000) tb = gr.top_block() tb.connect(src, head, sink) tb.run() @@ -262,7 +277,8 @@ class test_block_gateway(gr_unittest.TestCase): def test_tags_win(self): src = tag_source() sink = tag_sink_win() - head = blocks.head(gr.sizeof_float, 50000) #should be enough items to get a tag through + # should be enough items to get a tag through + head = blocks.head(gr.sizeof_float, 50000) tb = gr.top_block() tb.connect(src, head, sink) tb.run() @@ -270,7 +286,8 @@ class test_block_gateway(gr_unittest.TestCase): def test_fc32_to_f32_2(self): tb = gr.top_block() - src = blocks.vector_source_c([1+2j, 3+4j, 5+6j, 7+8j, 9+10j], False) + src = blocks.vector_source_c( + [1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j], False) convert = fc32_to_f32_2() v2s = vector_to_stream(numpy.float32, 2) sink = blocks.vector_sink_f() @@ -279,15 +296,15 @@ class test_block_gateway(gr_unittest.TestCase): self.assertEqual(sink.data(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) def test_non_sync_block(self): - tb = gr.top_block () + tb = gr.top_block() src = blocks.vector_source_f(range(1000000)) sinks = [blocks.vector_sink_f(), blocks.vector_sink_f()] dut = non_sync_block() tb.connect(src, dut) - tb.connect((dut,0), sinks[0]) - tb.connect((dut,1), sinks[1]) - tb.run () - self.assertEqual(len(sinks[0].data()), 2*len(sinks[1].data())) + tb.connect((dut, 0), sinks[0]) + tb.connect((dut, 1), sinks[1]) + tb.run() + self.assertEqual(len(sinks[0].data()), 2 * len(sinks[1].data())) if __name__ == '__main__': diff --git a/gr-blocks/python/blocks/qa_boolean_operators.py b/gr-blocks/python/blocks/qa_boolean_operators.py index e5c199d283..384924d398 100644 --- a/gr-blocks/python/blocks/qa_boolean_operators.py +++ b/gr-blocks/python/blocks/qa_boolean_operators.py @@ -11,172 +11,169 @@ from gnuradio import gr, gr_unittest, blocks + class test_boolean_operators (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def help_ss (self, src_data, exp_data, op): - for s in zip (list(range(len (src_data))), src_data): - src = blocks.vector_source_s (s[1]) - self.tb.connect (src, (op, s[0])) - dst = blocks.vector_sink_s () - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (exp_data, result_data) - - def help_bb (self, src_data, exp_data, op): - for s in zip (list(range(len (src_data))), src_data): - src = blocks.vector_source_b (s[1]) - self.tb.connect (src, (op, s[0])) - dst = blocks.vector_sink_b () - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (exp_data, result_data) - - def help_ii (self, src_data, exp_data, op): - for s in zip (list(range(len (src_data))), src_data): - src = blocks.vector_source_i (s[1]) - self.tb.connect (src, (op, s[0])) - dst = blocks.vector_sink_i () - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (exp_data, result_data) - - def test_xor_ss (self): - src1_data = [1, 2, 3, 0x5004, 0x1150] - src2_data = [8, 2, 1 , 0x0508, 0x1105] - expected_result = [9, 0, 2, 0x550C, 0x0055] - op = blocks.xor_ss () - self.help_ss ((src1_data, src2_data), - expected_result, op) - - def test_xor_bb (self): - src1_data = [1, 2, 3, 4, 0x50] - src2_data = [8, 2, 1 , 8, 0x05] - expected_result = [9, 0, 2, 0xC, 0x55] - op = blocks.xor_bb () - self.help_bb ((src1_data, src2_data), - expected_result, op) - - - def test_xor_ii (self): - src1_data = [1, 2, 3, 0x5000004, 0x11000050] - src2_data = [8, 2, 1 , 0x0500008, 0x11000005] - expected_result = [9, 0, 2, 0x550000C, 0x00000055] - op = blocks.xor_ii () - self.help_ii ((src1_data, src2_data), - expected_result, op) - - - def test_and_ss (self): - src1_data = [1, 2, 3, 0x5004, 0x1150] - src2_data = [8, 2, 1 , 0x0508, 0x1105] - expected_result = [0, 2, 1, 0x0000, 0x1100] - op = blocks.and_ss () - self.help_ss ((src1_data, src2_data), - expected_result, op) - - def test_and_bb (self): - src1_data = [1, 2, 2, 3, 0x04, 0x50] - src2_data = [8, 2, 2, 1, 0x08, 0x05] - src3_data = [8, 2, 1, 1, 0x08, 0x05] - expected_result = [0, 2, 0, 1, 0x00, 0x00] - op = blocks.and_bb () - self.help_bb ((src1_data, src2_data, src3_data), - expected_result, op) - - def test_and_ii (self): - src1_data = [1, 2, 3, 0x50005004, 0x11001150] - src2_data = [8, 2, 1 , 0x05000508, 0x11001105] - expected_result = [0, 2, 1, 0x00000000, 0x11001100] - op = blocks.and_ii () - self.help_ii ((src1_data, src2_data), - expected_result, op) - - def test_and_const_ss (self): - src_data = [1, 2, 3, 0x5004, 0x1150] - expected_result = [0, 2, 2, 0x5000, 0x1100] + def help_ss(self, src_data, exp_data, op): + for s in zip(list(range(len(src_data))), src_data): + src = blocks.vector_source_s(s[1]) + self.tb.connect(src, (op, s[0])) + dst = blocks.vector_sink_s() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_bb(self, src_data, exp_data, op): + for s in zip(list(range(len(src_data))), src_data): + src = blocks.vector_source_b(s[1]) + self.tb.connect(src, (op, s[0])) + dst = blocks.vector_sink_b() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def help_ii(self, src_data, exp_data, op): + for s in zip(list(range(len(src_data))), src_data): + src = blocks.vector_source_i(s[1]) + self.tb.connect(src, (op, s[0])) + dst = blocks.vector_sink_i() + self.tb.connect(op, dst) + self.tb.run() + result_data = dst.data() + self.assertEqual(exp_data, result_data) + + def test_xor_ss(self): + src1_data = [1, 2, 3, 0x5004, 0x1150] + src2_data = [8, 2, 1, 0x0508, 0x1105] + expected_result = [9, 0, 2, 0x550C, 0x0055] + op = blocks.xor_ss() + self.help_ss((src1_data, src2_data), + expected_result, op) + + def test_xor_bb(self): + src1_data = [1, 2, 3, 4, 0x50] + src2_data = [8, 2, 1, 8, 0x05] + expected_result = [9, 0, 2, 0xC, 0x55] + op = blocks.xor_bb() + self.help_bb((src1_data, src2_data), + expected_result, op) + + def test_xor_ii(self): + src1_data = [1, 2, 3, 0x5000004, 0x11000050] + src2_data = [8, 2, 1, 0x0500008, 0x11000005] + expected_result = [9, 0, 2, 0x550000C, 0x00000055] + op = blocks.xor_ii() + self.help_ii((src1_data, src2_data), + expected_result, op) + + def test_and_ss(self): + src1_data = [1, 2, 3, 0x5004, 0x1150] + src2_data = [8, 2, 1, 0x0508, 0x1105] + expected_result = [0, 2, 1, 0x0000, 0x1100] + op = blocks.and_ss() + self.help_ss((src1_data, src2_data), + expected_result, op) + + def test_and_bb(self): + src1_data = [1, 2, 2, 3, 0x04, 0x50] + src2_data = [8, 2, 2, 1, 0x08, 0x05] + src3_data = [8, 2, 1, 1, 0x08, 0x05] + expected_result = [0, 2, 0, 1, 0x00, 0x00] + op = blocks.and_bb() + self.help_bb((src1_data, src2_data, src3_data), + expected_result, op) + + def test_and_ii(self): + src1_data = [1, 2, 3, 0x50005004, 0x11001150] + src2_data = [8, 2, 1, 0x05000508, 0x11001105] + expected_result = [0, 2, 1, 0x00000000, 0x11001100] + op = blocks.and_ii() + self.help_ii((src1_data, src2_data), + expected_result, op) + + def test_and_const_ss(self): + src_data = [1, 2, 3, 0x5004, 0x1150] + expected_result = [0, 2, 2, 0x5000, 0x1100] src = blocks.vector_source_s(src_data) - op = blocks.and_const_ss (0x55AA) + op = blocks.and_const_ss(0x55AA) dst = blocks.vector_sink_s() self.tb.connect(src, op, dst) self.tb.run() self.assertEqual(dst.data(), expected_result) - def test_and_const_bb (self): - src_data = [1, 2, 3, 0x50, 0x11] - expected_result = [0, 2, 2, 0x00, 0x00] + def test_and_const_bb(self): + src_data = [1, 2, 3, 0x50, 0x11] + expected_result = [0, 2, 2, 0x00, 0x00] src = blocks.vector_source_b(src_data) - op = blocks.and_const_bb (0xAA) + op = blocks.and_const_bb(0xAA) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() self.assertEqual(dst.data(), expected_result) - - def test_and_const_ii (self): - src_data = [1, 2, 3, 0x5004, 0x1150] - expected_result = [0, 2, 2, 0x5000, 0x1100] + def test_and_const_ii(self): + src_data = [1, 2, 3, 0x5004, 0x1150] + expected_result = [0, 2, 2, 0x5000, 0x1100] src = blocks.vector_source_i(src_data) - op = blocks.and_const_ii (0x55AA) + op = blocks.and_const_ii(0x55AA) dst = blocks.vector_sink_i() self.tb.connect(src, op, dst) self.tb.run() self.assertEqual(dst.data(), expected_result) - - def test_or_ss (self): - src1_data = [1, 2, 3, 0x5004, 0x1150] - src2_data = [8, 2, 1 , 0x0508, 0x1105] - expected_result = [9, 2, 3, 0x550C, 0x1155] - op = blocks.or_ss () - self.help_ss ((src1_data, src2_data), - expected_result, op) - - def test_or_bb (self): - src1_data = [1, 2, 2, 3, 0x04, 0x50] - src2_data = [8, 2, 2, 1 , 0x08, 0x05] - src3_data = [8, 2, 1, 1 , 0x08, 0x05] - expected_result = [9, 2, 3, 3, 0x0C, 0x55] - op = blocks.or_bb () - self.help_bb ((src1_data, src2_data, src3_data), - expected_result, op) - - def test_or_ii (self): - src1_data = [1, 2, 3, 0x50005004, 0x11001150] - src2_data = [8, 2, 1 , 0x05000508, 0x11001105] - expected_result = [9, 2, 3, 0x5500550C, 0x11001155] - op = blocks.or_ii () - self.help_ii ((src1_data, src2_data), - expected_result, op) - - def test_not_ss (self): - src1_data = [1, 2, 3, 0x5004, 0x1150] - expected_result = [~1, ~2, ~3, ~0x5004, ~0x1150] - op = blocks.not_ss () - self.help_ss ((((src1_data),)), - expected_result, op) - - def test_not_bb (self): - src1_data = [1, 2, 2, 3, 0x04, 0x50] - expected_result = [0xFE, 0xFD, 0xFD, 0xFC, 0xFB, 0xAF] - op = blocks.not_bb () - self.help_bb (((src1_data), ), - expected_result, op) - - def test_not_ii (self): - src1_data = [1, 2, 3, 0x50005004, 0x11001150] - expected_result = [~1 , ~2, ~3, ~0x50005004, ~0x11001150] - op = blocks.not_ii () - self.help_ii (((src1_data),), - expected_result, op) + def test_or_ss(self): + src1_data = [1, 2, 3, 0x5004, 0x1150] + src2_data = [8, 2, 1, 0x0508, 0x1105] + expected_result = [9, 2, 3, 0x550C, 0x1155] + op = blocks.or_ss() + self.help_ss((src1_data, src2_data), + expected_result, op) + + def test_or_bb(self): + src1_data = [1, 2, 2, 3, 0x04, 0x50] + src2_data = [8, 2, 2, 1, 0x08, 0x05] + src3_data = [8, 2, 1, 1, 0x08, 0x05] + expected_result = [9, 2, 3, 3, 0x0C, 0x55] + op = blocks.or_bb() + self.help_bb((src1_data, src2_data, src3_data), + expected_result, op) + + def test_or_ii(self): + src1_data = [1, 2, 3, 0x50005004, 0x11001150] + src2_data = [8, 2, 1, 0x05000508, 0x11001105] + expected_result = [9, 2, 3, 0x5500550C, 0x11001155] + op = blocks.or_ii() + self.help_ii((src1_data, src2_data), + expected_result, op) + + def test_not_ss(self): + src1_data = [1, 2, 3, 0x5004, 0x1150] + expected_result = [~1, ~2, ~3, ~0x5004, ~0x1150] + op = blocks.not_ss() + self.help_ss((((src1_data),)), + expected_result, op) + + def test_not_bb(self): + src1_data = [1, 2, 2, 3, 0x04, 0x50] + expected_result = [0xFE, 0xFD, 0xFD, 0xFC, 0xFB, 0xAF] + op = blocks.not_bb() + self.help_bb(((src1_data), ), + expected_result, op) + + def test_not_ii(self): + src1_data = [1, 2, 3, 0x50005004, 0x11001150] + expected_result = [~1, ~2, ~3, ~0x50005004, ~0x11001150] + op = blocks.not_ii() + self.help_ii(((src1_data),), + expected_result, op) if __name__ == '__main__': diff --git a/gr-blocks/python/blocks/qa_burst_tagger.py b/gr-blocks/python/blocks/qa_burst_tagger.py index 707e0d7a8c..c70fb283f0 100644 --- a/gr-blocks/python/blocks/qa_burst_tagger.py +++ b/gr-blocks/python/blocks/qa_burst_tagger.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest, blocks import pmt + class test_burst_tagger(gr_unittest.TestCase): def setUp(self): @@ -22,14 +23,14 @@ class test_burst_tagger(gr_unittest.TestCase): self.tb = None def test_001(self): - src_data = ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - trg_data = (-1, -1, 1, 1, -1, -1, 1, 1, -1, -1) + src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + trg_data = (-1, -1, 1, 1, -1, -1, 1, 1, -1, -1) src = blocks.vector_source_i(src_data) trg = blocks.vector_source_s(trg_data) - op = blocks.burst_tagger(gr.sizeof_int) + op = blocks.burst_tagger(gr.sizeof_int) snk = blocks.tag_debug(gr.sizeof_int, "burst tagger QA") - self.tb.connect(src, (op,0)) - self.tb.connect(trg, (op,1)) + self.tb.connect(src, (op, 0)) + self.tb.connect(trg, (op, 1)) self.tb.connect(op, snk) self.tb.run() @@ -39,10 +40,11 @@ class test_burst_tagger(gr_unittest.TestCase): self.assertEqual(6, x[2].offset) self.assertEqual(8, x[3].offset) - self.assertEqual(True, pmt.to_bool(x[0].value)) + self.assertEqual(True, pmt.to_bool(x[0].value)) self.assertEqual(False, pmt.to_bool(x[1].value)) - self.assertEqual(True, pmt.to_bool(x[2].value)) + self.assertEqual(True, pmt.to_bool(x[2].value)) self.assertEqual(False, pmt.to_bool(x[3].value)) + if __name__ == '__main__': gr_unittest.run(test_burst_tagger) diff --git a/gr-blocks/python/blocks/qa_conjugate.py b/gr-blocks/python/blocks/qa_conjugate.py index ad7b76b8f0..a67db1da58 100644 --- a/gr-blocks/python/blocks/qa_conjugate.py +++ b/gr-blocks/python/blocks/qa_conjugate.py @@ -11,32 +11,34 @@ from gnuradio import gr, gr_unittest, blocks + class test_conjugate (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_000 (self): - src_data = [-2-2j, -1-1j, -2+2j, -1+1j, - 2-2j, 1-1j, 2+2j, 1+1j, - 0+0j] + def test_000(self): + src_data = [-2 - 2j, -1 - 1j, -2 + 2j, -1 + 1j, + 2 - 2j, 1 - 1j, 2 + 2j, 1 + 1j, + 0 + 0j] - exp_data = [-2+2j, -1+1j, -2-2j, -1-1j, - 2+2j, 1+1j, 2-2j, 1-1j, - 0-0j] + exp_data = [-2 + 2j, -1 + 1j, -2 - 2j, -1 - 1j, + 2 + 2j, 1 + 1j, 2 - 2j, 1 - 1j, + 0 - 0j] src = blocks.vector_source_c(src_data) - op = blocks.conjugate_cc () - dst = blocks.vector_sink_c () + op = blocks.conjugate_cc() + dst = blocks.vector_sink_c() self.tb.connect(src, op) self.tb.connect(op, dst) self.tb.run() - result_data = dst.data () - self.assertEqual (exp_data, result_data) + result_data = dst.data() + self.assertEqual(exp_data, result_data) + if __name__ == '__main__': gr_unittest.run(test_conjugate) diff --git a/gr-blocks/python/blocks/qa_copy.py b/gr-blocks/python/blocks/qa_copy.py index 7bbbba9f7c..9ae4624699 100644 --- a/gr-blocks/python/blocks/qa_copy.py +++ b/gr-blocks/python/blocks/qa_copy.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_copy(gr_unittest.TestCase): def setUp(self): @@ -30,7 +31,7 @@ class test_copy(gr_unittest.TestCase): dst_data = dst.data() self.assertEqual(expected_result, dst_data) - def test_copy_drop (self): + def test_copy_drop(self): src_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] expected_result = [] src = blocks.vector_source_b(src_data) @@ -42,5 +43,6 @@ class test_copy(gr_unittest.TestCase): dst_data = dst.data() self.assertEqual(expected_result, dst_data) + if __name__ == '__main__': gr_unittest.run(test_copy) diff --git a/gr-blocks/python/blocks/qa_cpp_py_binding.py b/gr-blocks/python/blocks/qa_cpp_py_binding.py index 42c4f3995e..8352f67379 100644 --- a/gr-blocks/python/blocks/qa_cpp_py_binding.py +++ b/gr-blocks/python/blocks/qa_cpp_py_binding.py @@ -13,46 +13,59 @@ # -import sys, time, random, numpy, re +import sys +import time +import random +import numpy +import re from gnuradio import gr, gr_unittest, blocks from gnuradio.ctrlport import GNURadio from gnuradio import ctrlport import os + def get1(): return "success" + def get2(): return "failure" + class inc_class(object): def __init__(self): self.val = 1 + def pp(self): - self.val = self.val+1 + self.val = self.val + 1 return self.val + get3 = inc_class() + def get4(): random.seed(0) rv = random.random() return rv + def get5(): numpy.random.seed(0) - samp_t = numpy.random.randn(24)+1j*numpy.random.randn(24); - samp_f = numpy.fft.fft(samp_t); - log_pow_f = 20*numpy.log10(numpy.abs(samp_f)) + samp_t = numpy.random.randn(24) + 1j * numpy.random.randn(24) + samp_f = numpy.fft.fft(samp_t) + log_pow_f = 20 * numpy.log10(numpy.abs(samp_f)) rv = list(log_pow_f) - return rv; + return rv + def get6(): numpy.random.seed(0) - samp_t = numpy.random.randn(1024)+1j*numpy.random.randn(1024); + samp_t = numpy.random.randn(1024) + 1j * numpy.random.randn(1024) rv = list(samp_t) - return rv; + return rv + class test_cpp_py_binding(gr_unittest.TestCase): @@ -84,14 +97,26 @@ class test_cpp_py_binding(gr_unittest.TestCase): gr.DISPNULL) v4.activate(get4) - v5 = gr.RPC_get_vector_float("pyland", "fvec", "unit_5_float_vector", - "Python Exported Float Vector", [], [], [], - gr.DISPTIME | gr.DISPOPTCPLX) + v5 = gr.RPC_get_vector_float( + "pyland", + "fvec", + "unit_5_float_vector", + "Python Exported Float Vector", + [], + [], + [], + gr.DISPTIME | gr.DISPOPTCPLX) v5.activate(get5) - v6 = gr.RPC_get_vector_gr_complex("pyland", "cvec", "unit_6_gr_complex_vector", - "Python Exported Complex Vector", [], [], [], - gr.DISPXY | gr.DISPOPTSCATTER) + v6 = gr.RPC_get_vector_gr_complex( + "pyland", + "cvec", + "unit_6_gr_complex_vector", + "Python Exported Complex Vector", + [], + [], + [], + gr.DISPXY | gr.DISPOPTSCATTER) v6.activate(get6) # print some variables locally @@ -105,7 +130,7 @@ class test_cpp_py_binding(gr_unittest.TestCase): val = get3.pp() rval = v3.get() - self.assertEqual(val+1, rval) + self.assertEqual(val + 1, rval) val = get4() rval = v4.get() @@ -120,11 +145,11 @@ class test_cpp_py_binding(gr_unittest.TestCase): self.assertComplexTuplesAlmostEqual(val, rval, 5) def test_002(self): - data = list(range(1,9)) + data = list(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") + 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) @@ -146,7 +171,8 @@ class test_cpp_py_binding(gr_unittest.TestCase): # Initialize a simple ControlPort client from endpoint from gnuradio.ctrlport.GNURadioControlPortClient import GNURadioControlPortClient - radiosys = GNURadioControlPortClient(hostname, portnum, rpcmethod='thrift') + radiosys = GNURadioControlPortClient( + hostname, portnum, rpcmethod='thrift') radio = radiosys.client # Get all exported knobs @@ -157,5 +183,6 @@ class test_cpp_py_binding(gr_unittest.TestCase): self.tb.stop() + if __name__ == '__main__': gr_unittest.run(test_cpp_py_binding) diff --git a/gr-blocks/python/blocks/qa_cpp_py_binding_set.py b/gr-blocks/python/blocks/qa_cpp_py_binding_set.py index 6377d05b95..c404669cc3 100644 --- a/gr-blocks/python/blocks/qa_cpp_py_binding_set.py +++ b/gr-blocks/python/blocks/qa_cpp_py_binding_set.py @@ -13,29 +13,36 @@ # -import sys, time, random, numpy, re +import sys +import time +import random +import numpy +import re from gnuradio import gr, gr_unittest, blocks from gnuradio.ctrlport import GNURadio from gnuradio import ctrlport import os + class inc_class(object): - def __init__(self,val): - self.val = val; + def __init__(self, val): + self.val = val def _get(self): - #print "returning get (val = %s)"%(str(self.val)); - return self.val; + # print "returning get (val = %s)"%(str(self.val)); + return self.val + + def _set(self, val): + # print "updating val to %s"%(str(val)); + self.val = val + return + - def _set(self,val): - #print "updating val to %s"%(str(val)); - self.val = val; - return; +getset1 = inc_class(10) +getset2 = inc_class(100.0) +getset3 = inc_class("test") -getset1 = inc_class(10); -getset2 = inc_class(100.0); -getset3 = inc_class("test"); class test_cpp_py_binding_set(gr_unittest.TestCase): def setUp(self): @@ -48,12 +55,12 @@ class test_cpp_py_binding_set(gr_unittest.TestCase): def test_001(self): g1 = gr.RPC_get_int("pyland", "v1", "unit_1_int", - "Python Exported Int", 0, 100, 10, - gr.DISPNULL) + "Python Exported Int", 0, 100, 10, + gr.DISPNULL) g1.activate(getset1._get) s1 = gr.RPC_get_int("pyland", "v1", "unit_1_int", - "Python Exported Int", 0, 100, 10, - gr.DISPNULL) + "Python Exported Int", 0, 100, 10, + gr.DISPNULL) s1.activate(getset1._set) time.sleep(0.01) @@ -95,13 +102,12 @@ class test_cpp_py_binding_set(gr_unittest.TestCase): rval = g3.get() self.assertEqual(val, rval) - def test_002(self): data = list(range(1, 10)) self.src = blocks.vector_source_c(data, True) self.p = blocks.nop(gr.sizeof_gr_complex) - self.p.set_ctrlport_test(0); + self.p.set_ctrlport_test(0) probe_info = self.p.alias() self.tb.connect(self.src, self.p) @@ -113,7 +119,8 @@ class test_cpp_py_binding_set(gr_unittest.TestCase): # Initialize a simple ControlPort client from endpoint from gnuradio.ctrlport.GNURadioControlPortClient import GNURadioControlPortClient - radiosys = GNURadioControlPortClient(hostname, portnum, rpcmethod='thrift') + radiosys = GNURadioControlPortClient( + hostname, portnum, rpcmethod='thrift') radio = radiosys.client self.tb.start() @@ -122,8 +129,8 @@ class test_cpp_py_binding_set(gr_unittest.TestCase): time.sleep(0.1) # Get all exported knobs - key_name_test = probe_info+"::test" - ret = radio.getKnobs([key_name_test,]) + key_name_test = probe_info + "::test" + ret = radio.getKnobs([key_name_test, ]) ret[key_name_test].value = 10 radio.setKnobs({key_name_test: ret[key_name_test]}) @@ -135,5 +142,6 @@ class test_cpp_py_binding_set(gr_unittest.TestCase): self.tb.stop() self.tb.wait() + if __name__ == '__main__': gr_unittest.run(test_cpp_py_binding_set) diff --git a/gr-blocks/python/blocks/qa_ctrlport_probes.py b/gr-blocks/python/blocks/qa_ctrlport_probes.py index edaabcfc34..33b5a02e9b 100644 --- a/gr-blocks/python/blocks/qa_ctrlport_probes.py +++ b/gr-blocks/python/blocks/qa_ctrlport_probes.py @@ -9,12 +9,18 @@ # -import sys, time, random, numpy +import sys +import time +import random +import numpy from gnuradio import gr, gr_unittest, blocks -import os, struct, re +import os +import struct +import re from gnuradio.ctrlport.GNURadioControlPortClient import GNURadioControlPortClient + class test_ctrlport_probes(gr_unittest.TestCase): def setUp(self): @@ -25,17 +31,16 @@ class test_ctrlport_probes(gr_unittest.TestCase): self.tb = None def test_001(self): - data = list(range(1,9)) + data = list(range(1, 9)) self.src = blocks.vector_source_c(data, True) - self.probe = blocks.ctrlport_probe2_c("samples","Complex", + self.probe = blocks.ctrlport_probe2_c("samples", "Complex", len(data), gr.DISPNULL) probe_name = self.probe.alias() self.tb.connect(self.src, self.probe) 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, 2, 3, 4, @@ -51,7 +56,8 @@ class test_ctrlport_probes(gr_unittest.TestCase): # Initialize a simple ControlPort client from endpoint from gnuradio.ctrlport.GNURadioControlPortClient import GNURadioControlPortClient - radiosys = GNURadioControlPortClient(hostname, portnum, rpcmethod='thrift') + radiosys = GNURadioControlPortClient( + hostname, portnum, rpcmethod='thrift') radio = radiosys.client # Get all exported knobs @@ -67,19 +73,18 @@ class test_ctrlport_probes(gr_unittest.TestCase): self.tb.stop() self.tb.wait() - def test_002(self): - data = list(range(1,9)) + data = list(range(1, 9)) self.src = blocks.vector_source_f(data, True) - self.probe = blocks.ctrlport_probe2_f("samples","Floats", + self.probe = blocks.ctrlport_probe2_f("samples", "Floats", len(data), gr.DISPNULL) probe_name = self.probe.alias() self.tb.connect(self.src, self.probe) self.tb.start() - expected_result = [1, 2, 3, 4, 5, 6, 7, 8,] + expected_result = [1, 2, 3, 4, 5, 6, 7, 8, ] # Make sure we have time for flowgraph to run time.sleep(0.1) @@ -91,7 +96,8 @@ class test_ctrlport_probes(gr_unittest.TestCase): # Initialize a simple ControlPort client from endpoint from gnuradio.ctrlport.GNURadioControlPortClient import GNURadioControlPortClient - radiosys = GNURadioControlPortClient(hostname, portnum, rpcmethod='thrift') + radiosys = GNURadioControlPortClient( + hostname, portnum, rpcmethod='thrift') radio = radiosys.client # Get all exported knobs @@ -108,17 +114,17 @@ class test_ctrlport_probes(gr_unittest.TestCase): self.tb.wait() def test_003(self): - data = list(range(1,9)) + data = list(range(1, 9)) self.src = blocks.vector_source_i(data, True) - self.probe = blocks.ctrlport_probe2_i("samples","Integers", + self.probe = blocks.ctrlport_probe2_i("samples", "Integers", len(data), gr.DISPNULL) probe_name = self.probe.alias() self.tb.connect(self.src, self.probe) self.tb.start() - expected_result = [1, 2, 3, 4, 5, 6, 7, 8,] + expected_result = [1, 2, 3, 4, 5, 6, 7, 8, ] # Make sure we have time for flowgraph to run time.sleep(0.1) @@ -130,7 +136,8 @@ class test_ctrlport_probes(gr_unittest.TestCase): # Initialize a simple ControlPort client from endpoint from gnuradio.ctrlport.GNURadioControlPortClient import GNURadioControlPortClient - radiosys = GNURadioControlPortClient(hostname, portnum, rpcmethod='thrift') + radiosys = GNURadioControlPortClient( + hostname, portnum, rpcmethod='thrift') radio = radiosys.client # Get all exported knobs @@ -146,19 +153,18 @@ class test_ctrlport_probes(gr_unittest.TestCase): self.tb.stop() self.tb.wait() - def test_004(self): - data = list(range(1,9)) + data = list(range(1, 9)) self.src = blocks.vector_source_s(data, True) - self.probe = blocks.ctrlport_probe2_s("samples","Shorts", + self.probe = blocks.ctrlport_probe2_s("samples", "Shorts", len(data), gr.DISPNULL) probe_name = self.probe.alias() self.tb.connect(self.src, self.probe) self.tb.start() - expected_result = [1, 2, 3, 4, 5, 6, 7, 8,] + expected_result = [1, 2, 3, 4, 5, 6, 7, 8, ] # Make sure we have time for flowgraph to run time.sleep(0.1) @@ -170,7 +176,8 @@ class test_ctrlport_probes(gr_unittest.TestCase): # Initialize a simple ControlPort client from endpoint from gnuradio.ctrlport.GNURadioControlPortClient import GNURadioControlPortClient - radiosys = GNURadioControlPortClient(hostname, portnum, rpcmethod='thrift') + radiosys = GNURadioControlPortClient( + hostname, portnum, rpcmethod='thrift') radio = radiosys.client # Get all exported knobs @@ -187,17 +194,17 @@ class test_ctrlport_probes(gr_unittest.TestCase): self.tb.wait() def test_005(self): - data = list(range(1,9)) + data = list(range(1, 9)) self.src = blocks.vector_source_b(data, True) - self.probe = blocks.ctrlport_probe2_b("samples","Bytes", + self.probe = blocks.ctrlport_probe2_b("samples", "Bytes", len(data), gr.DISPNULL) probe_name = self.probe.alias() self.tb.connect(self.src, self.probe) self.tb.start() - expected_result = [1, 2, 3, 4, 5, 6, 7, 8,] + expected_result = [1, 2, 3, 4, 5, 6, 7, 8, ] # Make sure we have time for flowgraph to run time.sleep(0.1) @@ -209,7 +216,8 @@ class test_ctrlport_probes(gr_unittest.TestCase): # Initialize a simple ControlPort client from endpoint from gnuradio.ctrlport.GNURadioControlPortClient import GNURadioControlPortClient - radiosys = GNURadioControlPortClient(hostname, portnum, rpcmethod='thrift') + radiosys = GNURadioControlPortClient( + hostname, portnum, rpcmethod='thrift') radio = radiosys.client # Get all exported knobs @@ -218,7 +226,7 @@ class test_ctrlport_probes(gr_unittest.TestCase): # Get data in probe, which might be offset; find the # beginning and unwrap. result = ret[name].value - result = list(struct.unpack(len(result)*'b', result)) + result = list(struct.unpack(len(result) * 'b', result)) i = result.index(1) result = result[i:] + result[0:i] self.assertEqual(expected_result, result) @@ -226,5 +234,6 @@ class test_ctrlport_probes(gr_unittest.TestCase): self.tb.stop() self.tb.wait() + if __name__ == '__main__': gr_unittest.run(test_ctrlport_probes) diff --git a/gr-blocks/python/blocks/qa_delay.py b/gr-blocks/python/blocks/qa_delay.py index dfef2fcbec..08b3289ec5 100644 --- a/gr-blocks/python/blocks/qa_delay.py +++ b/gr-blocks/python/blocks/qa_delay.py @@ -12,6 +12,7 @@ from gnuradio import gr, gr_unittest, blocks import pmt + class test_delay(gr_unittest.TestCase): def setUp(self): @@ -24,7 +25,7 @@ class test_delay(gr_unittest.TestCase): delta_t = 0 tb = self.tb src_data = [float(x) for x in range(0, 100)] - expected_result = list(delta_t*[0.0] + src_data) + expected_result = list(delta_t * [0.0] + src_data) src = blocks.vector_source_f(src_data) op = blocks.delay(gr.sizeof_float, delta_t) @@ -39,7 +40,7 @@ class test_delay(gr_unittest.TestCase): delta_t = 10 tb = self.tb src_data = [float(x) for x in range(0, 100)] - expected_result = list(delta_t*[0.0] + src_data) + expected_result = list(delta_t * [0.0] + src_data) src = blocks.vector_source_f(src_data) op = blocks.delay(gr.sizeof_float, delta_t) @@ -54,9 +55,13 @@ class test_delay(gr_unittest.TestCase): tb = self.tb vector_sink = blocks.vector_sink_f(1) ref_sink = blocks.vector_sink_f(1) - tags_strobe = blocks.tags_strobe(gr.sizeof_float*1, pmt.intern("TEST"), 100, pmt.intern("strobe")) - head = blocks.head(gr.sizeof_float*1, 10**5) - delay = blocks.delay(gr.sizeof_float*1, 100) + tags_strobe = blocks.tags_strobe( + gr.sizeof_float * 1, + pmt.intern("TEST"), + 100, + pmt.intern("strobe")) + head = blocks.head(gr.sizeof_float * 1, 10**5) + delay = blocks.delay(gr.sizeof_float * 1, 100) tb.connect((delay, 0), (head, 0)) tb.connect((head, 0), (vector_sink, 0)) tb.connect((tags_strobe, 0), (delay, 0)) diff --git a/gr-blocks/python/blocks/qa_endian_swap.py b/gr-blocks/python/blocks/qa_endian_swap.py index 52d13c0bad..949183fd35 100644 --- a/gr-blocks/python/blocks/qa_endian_swap.py +++ b/gr-blocks/python/blocks/qa_endian_swap.py @@ -12,6 +12,7 @@ from gnuradio import gr, gr_unittest, blocks import ctypes + class test_endian_swap(gr_unittest.TestCase): def setUp(self): @@ -21,8 +22,8 @@ class test_endian_swap(gr_unittest.TestCase): self.tb = None def test_001(self): - src_data = [1,2,3,4] - expected_result = [256, 512, 768, 1024]; + src_data = [1, 2, 3, 4] + expected_result = [256, 512, 768, 1024] src = blocks.vector_source_s(src_data) op = blocks.endian_swap(2) @@ -36,8 +37,8 @@ class test_endian_swap(gr_unittest.TestCase): def test_002(self): - src_data = [1,2,3,4] - expected_result = [16777216, 33554432, 50331648, 67108864]; + src_data = [1, 2, 3, 4] + expected_result = [16777216, 33554432, 50331648, 67108864] src = blocks.vector_source_i(src_data) op = blocks.endian_swap(4) @@ -49,6 +50,6 @@ class test_endian_swap(gr_unittest.TestCase): self.assertEqual(expected_result, result_data) + if __name__ == '__main__': gr_unittest.run(test_endian_swap) - diff --git a/gr-blocks/python/blocks/qa_exponentiate_const_cci.py b/gr-blocks/python/blocks/qa_exponentiate_const_cci.py index d37e076975..0c1412949c 100644 --- a/gr-blocks/python/blocks/qa_exponentiate_const_cci.py +++ b/gr-blocks/python/blocks/qa_exponentiate_const_cci.py @@ -1,18 +1,19 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# +# # Copyright 2017 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# from gnuradio import gr, gr_unittest from gnuradio import blocks import pmt + class qa_exponentiate_const_cci(gr_unittest.TestCase): def setUp(self): @@ -22,9 +23,13 @@ class qa_exponentiate_const_cci(gr_unittest.TestCase): self.tb = None def test_001_t(self): - for exponent in range(1,10): - in_data = [1+1j, -1, 4-1j, -3-7j] - out_data = [in_data[0]**exponent, in_data[1]**exponent, in_data[2]**exponent, in_data[3]**exponent] + for exponent in range(1, 10): + in_data = [1 + 1j, -1, 4 - 1j, -3 - 7j] + out_data = [ + in_data[0]**exponent, + in_data[1]**exponent, + in_data[2]**exponent, + in_data[3]**exponent] # Test streaming input source = blocks.vector_source_c(in_data, False, 1) @@ -40,7 +45,8 @@ class qa_exponentiate_const_cci(gr_unittest.TestCase): for vlen in [2, 4]: source = blocks.vector_source_c(in_data, False, 1) s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, vlen) - exponentiate_const_cci = blocks.exponentiate_const_cci(exponent, vlen) + exponentiate_const_cci = blocks.exponentiate_const_cci( + exponent, vlen) v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, vlen) sink = blocks.vector_sink_c(1) diff --git a/gr-blocks/python/blocks/qa_file_descriptor_source_sink.py b/gr-blocks/python/blocks/qa_file_descriptor_source_sink.py index 230737802f..bd45b2b2e4 100644 --- a/gr-blocks/python/blocks/qa_file_descriptor_source_sink.py +++ b/gr-blocks/python/blocks/qa_file_descriptor_source_sink.py @@ -13,13 +13,14 @@ import os import tempfile import pmt + class test_file_descriptor_source_sink(gr_unittest.TestCase): - def setUp (self): + def setUp(self): os.environ['GR_CONF_CONTROLPORT_ON'] = 'False' - self.tb = gr.top_block () + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_file_descriptor(self): @@ -54,5 +55,6 @@ class test_file_descriptor_source_sink(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(expected_result, result_data) self.assertEqual(len(snk2.tags()), 0) + if __name__ == '__main__': gr_unittest.run(test_file_descriptor_source_sink) diff --git a/gr-blocks/python/blocks/qa_file_metadata.py b/gr-blocks/python/blocks/qa_file_metadata.py index 671966b493..aff8aabaa7 100644 --- a/gr-blocks/python/blocks/qa_file_metadata.py +++ b/gr-blocks/python/blocks/qa_file_metadata.py @@ -9,19 +9,22 @@ # -import os, math +import os +import math from gnuradio import gr, gr_unittest, blocks import pmt import parse_file_metadata + def sig_source_c(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [amp*math.cos(2.*math.pi*freq*x) + \ - 1j*amp*math.sin(2.*math.pi*freq*x) for x in t] + y = [amp * math.cos(2. * math.pi * freq * x) + + 1j * amp * math.sin(2. * math.pi * freq * x) for x in t] return y + class test_file_metadata(gr_unittest.TestCase): def setUp(self): @@ -43,7 +46,7 @@ class test_file_metadata(gr_unittest.TestCase): extras = pmt.dict_add(extras, key, val) data = sig_source_c(samp_rate, 1000, 1, N) - src = blocks.vector_source_c(data) + src = blocks.vector_source_c(data) fsnk = blocks.file_meta_sink(gr.sizeof_gr_complex, outfile, samp_rate, 1, blocks.GR_FILE_FLOAT, True, @@ -81,7 +84,6 @@ class test_file_metadata(gr_unittest.TestCase): self.assertEqual(info['rx_rate'], samp_rate) self.assertEqual(pmt.to_double(extra_info['samp_rate']), samp_rate) - # Test file metadata source src.rewind() fsrc = blocks.file_meta_source(outfile, False) @@ -94,7 +96,7 @@ class test_file_metadata(gr_unittest.TestCase): self.tb.connect(src, ssnk) self.tb.run() - fsrc.close() + fsrc.close() # Test to make sure tags with 'samp_rate' and 'rx_rate' keys # were generated and received correctly. tags = tsnk.current_tags() @@ -122,7 +124,7 @@ class test_file_metadata(gr_unittest.TestCase): extras = pmt.dict_add(extras, key, val) data = sig_source_c(samp_rate, 1000, 1, N) - src = blocks.vector_source_c(data) + src = blocks.vector_source_c(data) fsnk = blocks.file_meta_sink(gr.sizeof_gr_complex, outfile, samp_rate, 1, blocks.GR_FILE_FLOAT, True, @@ -162,7 +164,6 @@ class test_file_metadata(gr_unittest.TestCase): self.assertEqual(info['rx_rate'], samp_rate) self.assertEqual(pmt.to_double(extra_info['samp_rate']), samp_rate) - # Test file metadata source src.rewind() fsrc = blocks.file_meta_source(outfile, False, detached, outfile_hdr) @@ -191,5 +192,6 @@ class test_file_metadata(gr_unittest.TestCase): os.remove(outfile) os.remove(outfile_hdr) + if __name__ == '__main__': gr_unittest.run(test_file_metadata) diff --git a/gr-blocks/python/blocks/qa_file_sink.py b/gr-blocks/python/blocks/qa_file_sink.py index 7a0ad4f90a..ac169dbb6a 100644 --- a/gr-blocks/python/blocks/qa_file_sink.py +++ b/gr-blocks/python/blocks/qa_file_sink.py @@ -13,13 +13,14 @@ import tempfile import array from gnuradio import gr, gr_unittest, blocks + class test_file_sink(gr_unittest.TestCase): - def setUp (self): + def setUp(self): os.environ['GR_CONF_CONTROLPORT_ON'] = 'False' - self.tb = gr.top_block () + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_file_sink(self): @@ -43,5 +44,6 @@ class test_file_sink(gr_unittest.TestCase): result_data.fromfile(datafile, len(data)) self.assertFloatTuplesAlmostEqual(expected_result, result_data) + if __name__ == '__main__': gr_unittest.run(test_file_sink) diff --git a/gr-blocks/python/blocks/qa_file_source.py b/gr-blocks/python/blocks/qa_file_source.py index 9b282f3111..38de4f458e 100644 --- a/gr-blocks/python/blocks/qa_file_source.py +++ b/gr-blocks/python/blocks/qa_file_source.py @@ -14,6 +14,7 @@ import array import pmt from gnuradio import gr, gr_unittest, blocks + class test_file_source(gr_unittest.TestCase): @classmethod @@ -31,10 +32,10 @@ class test_file_source(gr_unittest.TestCase): del cls._datafilename del cls._datafile - def setUp (self): + def setUp(self): self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_file_source(self): @@ -60,7 +61,10 @@ class test_file_source(gr_unittest.TestCase): def test_file_source_with_offset(self): expected_result = self._vector[100:] - src = blocks.file_source(gr.sizeof_float, self._datafilename, offset=100) + src = blocks.file_source( + gr.sizeof_float, + self._datafilename, + offset=100) snk = blocks.vector_sink_f() self.tb.connect(src, snk) @@ -71,9 +75,13 @@ class test_file_source(gr_unittest.TestCase): self.assertEqual(len(snk.tags()), 0) def test_source_with_offset_and_len(self): - expected_result = self._vector[100:100+600] + expected_result = self._vector[100:100 + 600] - src = blocks.file_source(gr.sizeof_float, self._datafilename, offset=100, len=600) + src = blocks.file_source( + gr.sizeof_float, + self._datafilename, + offset=100, + len=600) snk = blocks.vector_sink_f() self.tb.connect(src, snk) self.tb.run() @@ -86,7 +94,7 @@ class test_file_source(gr_unittest.TestCase): src = blocks.file_source(gr.sizeof_float, self._datafilename) self.assertTrue(src.seek(0, os.SEEK_SET)) - self.assertTrue(src.seek(len(self._vector)-1, os.SEEK_SET)) + self.assertTrue(src.seek(len(self._vector) - 1, os.SEEK_SET)) # Seek past end of file - this will also log a warning self.assertFalse(src.seek(len(self._vector), os.SEEK_SET)) # Negative seek - this will also log a warning @@ -102,7 +110,6 @@ class test_file_source(gr_unittest.TestCase): # Seek past end of file - this will also log a warning self.assertFalse(src.seek(len(self._vector), os.SEEK_CUR)) - def test_begin_tag(self): expected_result = self._vector @@ -137,5 +144,6 @@ class test_file_source(gr_unittest.TestCase): self.assertEqual(str(tags[1].value), "1") self.assertEqual(tags[1].offset, 1000) + if __name__ == '__main__': gr_unittest.run(test_file_source) diff --git a/gr-blocks/python/blocks/qa_head.py b/gr-blocks/python/blocks/qa_head.py index c2868758e6..2999745721 100644 --- a/gr-blocks/python/blocks/qa_head.py +++ b/gr-blocks/python/blocks/qa_head.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_head(gr_unittest.TestCase): def setUp(self): @@ -31,5 +32,6 @@ class test_head(gr_unittest.TestCase): dst_data = dst1.data() self.assertEqual(expected_result, dst_data) + if __name__ == '__main__': gr_unittest.run(test_head) diff --git a/gr-blocks/python/blocks/qa_hier_block2.py b/gr-blocks/python/blocks/qa_hier_block2.py index 141561e2ce..418fb85810 100644 --- a/gr-blocks/python/blocks/qa_hier_block2.py +++ b/gr-blocks/python/blocks/qa_hier_block2.py @@ -12,104 +12,108 @@ class add_ff(gr.sync_block): def __init__(self): gr.sync_block.__init__( self, - name = "add_ff", - in_sig = [numpy.float32, numpy.float32], - out_sig = [numpy.float32], + name="add_ff", + in_sig=[numpy.float32, numpy.float32], + out_sig=[numpy.float32], ) def work(self, input_items, output_items): output_items[0][:] = input_items[0] + input_items[1] return len(output_items[0]) + class multiply_const_ff(gr.sync_block): def __init__(self, k): gr.sync_block.__init__( self, - name = "multiply_ff", - in_sig = [numpy.float32], - out_sig = [numpy.float32], + name="multiply_ff", + in_sig=[numpy.float32], + out_sig=[numpy.float32], ) self.k = k def work(self, input_items, output_items): - output_items[0][:] = [self.k*x for x in input_items[0]] + output_items[0][:] = [self.k * x for x in input_items[0]] return len(output_items[0]) + class test_hier_block2(gr_unittest.TestCase): def setUp(self): pass def tearDown(self): - pass + pass def test_001_make(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) self.assertEqual("test_block", hblock.name()) self.assertEqual(1, hblock.input_signature().max_streams()) self.assertEqual(1, hblock.output_signature().min_streams()) self.assertEqual(1, hblock.output_signature().max_streams()) - self.assertEqual(gr.sizeof_int, hblock.output_signature().sizeof_stream_item(0)) + self.assertEqual( + gr.sizeof_int, + hblock.output_signature().sizeof_stream_item(0)) def test_002_connect_input(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(hblock, nop1) def test_004_connect_output(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(nop1, hblock) def test_005_connect_output_in_use(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) nop2 = blocks.nop(gr.sizeof_int) hblock.connect(nop1, hblock) self.assertRaises(ValueError, - lambda: hblock.connect(nop2, hblock)) + lambda: hblock.connect(nop2, hblock)) def test_006_connect_invalid_src_port_neg(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) self.assertRaises(ValueError, - lambda: hblock.connect((hblock, -1), nop1)) + lambda: hblock.connect((hblock, -1), nop1)) def test_005_connect_invalid_src_port_exceeds(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) self.assertRaises(ValueError, - lambda: hblock.connect((hblock, 1), nop1)) + lambda: hblock.connect((hblock, 1), nop1)) def test_007_connect_invalid_dst_port_neg(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) nop2 = blocks.nop(gr.sizeof_int) self.assertRaises(ValueError, - lambda: hblock.connect(nop1, (nop2, -1))) + lambda: hblock.connect(nop1, (nop2, -1))) def test_008_connect_invalid_dst_port_exceeds(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.null_sink(gr.sizeof_int) nop2 = blocks.null_sink(gr.sizeof_int) self.assertRaises(ValueError, - lambda: hblock.connect(nop1, (nop2, 1))) + lambda: hblock.connect(nop1, (nop2, 1))) def test_009_check_topology(self): hblock = gr.top_block("test_block") @@ -131,75 +135,75 @@ class test_hier_block2(gr_unittest.TestCase): def test_012_disconnect_input(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(hblock, nop1) hblock.disconnect(hblock, nop1) def test_013_disconnect_input_not_connected(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) nop2 = blocks.nop(gr.sizeof_int) hblock.connect(hblock, nop1) self.assertRaises(ValueError, - lambda: hblock.disconnect(hblock, nop2)) + lambda: hblock.disconnect(hblock, nop2)) def test_014_disconnect_input_neg(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(hblock, nop1) self.assertRaises(ValueError, - lambda: hblock.disconnect((hblock, -1), nop1)) + lambda: hblock.disconnect((hblock, -1), nop1)) def test_015_disconnect_input_exceeds(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(hblock, nop1) self.assertRaises(ValueError, - lambda: hblock.disconnect((hblock, 1), nop1)) + lambda: hblock.disconnect((hblock, 1), nop1)) def test_016_disconnect_output(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(nop1, hblock) hblock.disconnect(nop1, hblock) def test_017_disconnect_output_not_connected(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) nop2 = blocks.nop(gr.sizeof_int) hblock.connect(nop1, hblock) self.assertRaises(ValueError, - lambda: hblock.disconnect(nop2, hblock)) + lambda: hblock.disconnect(nop2, hblock)) def test_018_disconnect_output_neg(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(hblock, nop1) self.assertRaises(ValueError, - lambda: hblock.disconnect(nop1, (hblock, -1))) + lambda: hblock.disconnect(nop1, (hblock, -1))) def test_019_disconnect_output_exceeds(self): hblock = gr.hier_block2("test_block", - gr.io_signature(1,1,gr.sizeof_int), - gr.io_signature(1,1,gr.sizeof_int)) + gr.io_signature(1, 1, gr.sizeof_int), + gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(nop1, hblock) self.assertRaises(ValueError, - lambda: hblock.disconnect(nop1, (hblock, 1))) + lambda: hblock.disconnect(nop1, (hblock, 1))) def test_020_run(self): hblock = gr.top_block("test_block") @@ -251,7 +255,7 @@ class test_hier_block2(gr_unittest.TestCase): lambda: hblock.disconnect(blk)) def test_026_run_single(self): - expected_data = [1.0,] + expected_data = [1.0, ] tb = gr.top_block("top_block") hb = gr.hier_block2("block", gr.io_signature(0, 0, 0), @@ -268,11 +272,11 @@ class test_hier_block2(gr_unittest.TestCase): hb = gr.hier_block2("block", gr.io_signature(1, 1, 1), gr.io_signature(1, 1, 1)) - hsrc = blocks.vector_source_b([1,]) - hb.connect(hsrc, hb) # wire output internally + hsrc = blocks.vector_source_b([1, ]) + hb.connect(hsrc, hb) # wire output internally src = blocks.vector_source_b([1, ]) dst = blocks.vector_sink_b() - tb.connect(src, hb, dst) # hb's input is not connected internally + tb.connect(src, hb, dst) # hb's input is not connected internally self.assertRaises(RuntimeError, lambda: tb.run()) @@ -283,10 +287,10 @@ class test_hier_block2(gr_unittest.TestCase): gr.io_signature(1, 1, 1), gr.io_signature(1, 1, 1)) hdst = blocks.vector_sink_b() - hb.connect(hb, hdst) # wire input internally + hb.connect(hb, hdst) # wire input internally src = blocks.vector_source_b([1, ]) dst = blocks.vector_sink_b() - tb.connect(src, hb, dst) # hb's output is not connected internally + tb.connect(src, hb, dst) # hb's output is not connected internally self.assertRaises(RuntimeError, lambda: tb.run()) @@ -296,10 +300,11 @@ class test_hier_block2(gr_unittest.TestCase): gr.io_signature(1, 1, 1), gr.io_signature(1, 1, 1)) hsrc = blocks.vector_sink_b() - hb.connect(hb, hsrc) # wire input internally + hb.connect(hb, hsrc) # wire input internally src = blocks.vector_source_b([1, ]) dst = blocks.vector_sink_b() - tb.connect(src, hb) # hb's output is not connected internally or externally + # hb's output is not connected internally or externally + tb.connect(src, hb) self.assertRaises(RuntimeError, lambda: tb.run()) @@ -308,10 +313,11 @@ class test_hier_block2(gr_unittest.TestCase): hb = gr.hier_block2("block", gr.io_signature(1, 1, 1), gr.io_signature(1, 1, 1)) - hdst = blocks.vector_source_b([1,]) - hb.connect(hdst, hb) # wire output internally + hdst = blocks.vector_source_b([1, ]) + hb.connect(hdst, hb) # wire output internally dst = blocks.vector_sink_b() - tb.connect(hb, dst) # hb's input is not connected internally or externally + # hb's input is not connected internally or externally + tb.connect(hb, dst) self.assertRaises(RuntimeError, lambda: tb.run()) @@ -322,7 +328,7 @@ class test_hier_block2(gr_unittest.TestCase): src = blocks.vector_source_b([1, ]) dst = blocks.vector_sink_b() hb.connect(src, dst) - tb.connect(hb) # Singleton connect + tb.connect(hb) # Singleton connect tb.lock() tb.disconnect_all() tb.connect(src, dst) @@ -336,11 +342,11 @@ class test_hier_block2(gr_unittest.TestCase): tb.disconnect(src) # Singleton disconnect tb.connect(src, dst) tb.run() - self.assertEqual(dst.data(), [1,]) + self.assertEqual(dst.data(), [1, ]) def test_030_nested_input(self): tb = gr.top_block() - src = blocks.vector_source_b([1,]) + src = blocks.vector_source_b([1, ]) hb1 = gr.hier_block2("hb1", gr.io_signature(1, 1, gr.sizeof_char), gr.io_signature(0, 0, 0)) @@ -352,11 +358,11 @@ class test_hier_block2(gr_unittest.TestCase): hb1.connect(hb1, hb2) hb2.connect(hb2, blocks.copy(gr.sizeof_char), dst) tb.run() - self.assertEqual(dst.data(), [1,]) + self.assertEqual(dst.data(), [1, ]) def test_031_multiple_internal_inputs(self): tb = gr.top_block() - src = blocks.vector_source_f([1.0,]) + src = blocks.vector_source_f([1.0, ]) hb = gr.hier_block2("hb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) @@ -371,23 +377,24 @@ class test_hier_block2(gr_unittest.TestCase): dst = blocks.vector_sink_f() tb.connect(src, hb, dst) tb.run() - self.assertEqual(dst.data(), [3.0,]) + self.assertEqual(dst.data(), [3.0, ]) def test_032_nested_multiple_internal_inputs(self): tb = gr.top_block() - src = blocks.vector_source_f([1.0,]) + src = blocks.vector_source_f([1.0, ]) hb = gr.hier_block2("hb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) hb2 = gr.hier_block2("hb", - gr.io_signature(1, 1, gr.sizeof_float), - gr.io_signature(1, 1, gr.sizeof_float)) + gr.io_signature(1, 1, gr.sizeof_float), + gr.io_signature(1, 1, gr.sizeof_float)) m1 = multiply_const_ff(1.0) m2 = multiply_const_ff(2.0) add = add_ff() hb2.connect(hb2, m1) # m1 is connected to hb2 external input #0 - hb2.connect(hb2, m2) # m2 is also connected to hb2 external input #0 + # m2 is also connected to hb2 external input #0 + hb2.connect(hb2, m2) hb2.connect(m1, (add, 0)) hb2.connect(m2, (add, 1)) hb2.connect(add, hb2) # add is connected to hb2 external output #0 @@ -395,8 +402,7 @@ class test_hier_block2(gr_unittest.TestCase): dst = blocks.vector_sink_f() tb.connect(src, hb, dst) tb.run() - self.assertEqual(dst.data(), [3.0,]) - + self.assertEqual(dst.data(), [3.0, ]) def test_033a_set_affinity(self): expected = [1.0, 2.0, 3.0, 4.0] @@ -404,7 +410,7 @@ class test_hier_block2(gr_unittest.TestCase): src = blocks.vector_source_f(expected, False) snk = blocks.vector_sink_f() hblock.connect(src, snk) - hblock.set_processor_affinity([0,]) + hblock.set_processor_affinity([0, ]) hblock.run() actual = snk.data() self.assertEqual(expected, actual) @@ -415,7 +421,7 @@ class test_hier_block2(gr_unittest.TestCase): src = blocks.vector_source_f(expected, False) snk = blocks.vector_sink_f() hblock.connect(src, snk) - hblock.set_processor_affinity([0,]) + hblock.set_processor_affinity([0, ]) hblock.unset_processor_affinity() hblock.run() actual = snk.data() @@ -427,9 +433,9 @@ class test_hier_block2(gr_unittest.TestCase): src = blocks.vector_source_f(expected, False) snk = blocks.vector_sink_f() hblock.connect(src, snk) - hblock.set_processor_affinity([0,]) + hblock.set_processor_affinity([0, ]) procs = hblock.processor_affinity() - self.assertEqual([0,], procs) + self.assertEqual([0, ], procs) def test_34a_lock_unlock(self): hblock = gr.top_block("test_block") @@ -438,7 +444,7 @@ class test_hier_block2(gr_unittest.TestCase): hier = multiply_const_ff(0.5) sink = blocks.null_sink(gr.sizeof_float) hblock.connect(src, throttle, hier, sink) - hblock.set_processor_affinity([0,]) + hblock.set_processor_affinity([0, ]) hblock.start() time.sleep(1) hblock.lock() @@ -452,7 +458,8 @@ class test_hier_block2(gr_unittest.TestCase): throttle = blocks.throttle(gr.sizeof_float, 32000) sink = blocks.null_sink(gr.sizeof_float) hblock.connect(src, throttle, sink) - hblock.set_processor_affinity([0,]) + hblock.set_processor_affinity([0, ]) + def thread_01(hblock, cls): cls.test_34b_val = 10 hblock.lock() @@ -469,5 +476,6 @@ class test_hier_block2(gr_unittest.TestCase): hblock.wait() self.assertEqual(40, self.test_34b_val) + if __name__ == "__main__": gr_unittest.run(test_hier_block2) diff --git a/gr-blocks/python/blocks/qa_hier_block2_message_connections.py b/gr-blocks/python/blocks/qa_hier_block2_message_connections.py index ee9745c69a..9029866f8d 100644 --- a/gr-blocks/python/blocks/qa_hier_block2_message_connections.py +++ b/gr-blocks/python/blocks/qa_hier_block2_message_connections.py @@ -19,9 +19,9 @@ class block_with_message_output(gr.basic_block): def __init__(self): gr.basic_block.__init__(self, - "block_with_message_output", - in_sig=None, - out_sig=None) + "block_with_message_output", + in_sig=None, + out_sig=None) self.message_port_register_out(pmt.intern("test")) @@ -29,9 +29,9 @@ class block_with_message_input(gr.basic_block): def __init__(self): gr.basic_block.__init__(self, - "block_with_message_input", - in_sig=None, - out_sig=None) + "block_with_message_input", + in_sig=None, + out_sig=None) self.message_port_register_in(pmt.intern("test")) @@ -39,9 +39,9 @@ class hier_block_with_message_output(gr.hier_block2): def __init__(self): gr.hier_block2.__init__(self, - "hier_block_with_message_output", - gr.io_signature(0, 0, 0), # Input signature - gr.io_signature(0, 0, 0)) # Output signature + "hier_block_with_message_output", + gr.io_signature(0, 0, 0), # Input signature + gr.io_signature(0, 0, 0)) # Output signature self.message_port_register_hier_out("test") self.block = block_with_message_output() self.msg_connect(self.block, "test", self, "test") @@ -51,9 +51,9 @@ class hier_block_with_message_input(gr.hier_block2): def __init__(self): gr.hier_block2.__init__(self, - "hier_block_with_message_output", - gr.io_signature(0, 0, 0), # Input signature - gr.io_signature(0, 0, 0)) # Output signature + "hier_block_with_message_output", + gr.io_signature(0, 0, 0), # Input signature + gr.io_signature(0, 0, 0)) # Output signature self.message_port_register_hier_in("test") self.block = block_with_message_input() self.msg_connect(self, "test", self.block, "test") @@ -63,9 +63,9 @@ class hier_block_with_message_inout(gr.hier_block2): def __init__(self): gr.hier_block2.__init__(self, - "hier_block_with_message_inout", - gr.io_signature(0, 0, 0), # Input signature - gr.io_signature(0, 0, 0)) # Output signature + "hier_block_with_message_inout", + gr.io_signature(0, 0, 0), # Input signature + gr.io_signature(0, 0, 0)) # Output signature self.message_port_register_hier_in("test") self.message_port_register_hier_out("test") self.input = block_with_message_input() @@ -88,7 +88,7 @@ class test_hier_block2_message_connections(gr_unittest.TestCase): self.tb.wait() def assert_has_subscription(self, sender, send_port, receiver, - receive_port): + receive_port): """assert that the given sender block has a subscription for the given receiver block on the appropriate send and receive ports @@ -188,5 +188,6 @@ class test_hier_block2_message_connections(gr_unittest.TestCase): self.tb.msg_disconnect(hier, "test", x, "test") self.assert_has_num_subscriptions(hier.block, "test", 0) + if __name__ == '__main__': gr_unittest.run(test_hier_block2_message_connections) diff --git a/gr-blocks/python/blocks/qa_integrate.py b/gr-blocks/python/blocks/qa_integrate.py index 34ac12ee9a..27311ba14f 100644 --- a/gr-blocks/python/blocks/qa_integrate.py +++ b/gr-blocks/python/blocks/qa_integrate.py @@ -11,12 +11,13 @@ from gnuradio import gr, gr_unittest, blocks + class test_integrate (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_000_ss(self): @@ -50,8 +51,14 @@ class test_integrate (gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(dst_data, dst.data(), 6) def test_003_cc(self): - src_data = [1.0+1.0j, 2.0+2.0j, 3.0+3.0j, 4.0+4.0j, 5.0+5.0j, 6.0+6.0j] - dst_data = [6.0+6.0j, 15.0+15.0j] + src_data = [ + 1.0 + 1.0j, + 2.0 + 2.0j, + 3.0 + 3.0j, + 4.0 + 4.0j, + 5.0 + 5.0j, + 6.0 + 6.0j] + dst_data = [6.0 + 6.0j, 15.0 + 15.0j] src = blocks.vector_source_c(src_data) itg = blocks.integrate_cc(3) dst = blocks.vector_sink_c() @@ -71,8 +78,14 @@ class test_integrate (gr_unittest.TestCase): self.assertEqual(dst_data, dst.data()) def test_003_cc_vec(self): - src_data = [1.0+1.0j, 2.0+2.0j, 3.0+3.0j, 4.0+4.0j, 5.0+5.0j, 6.0+6.0j] - dst_data = [9.0+9.0j, 12.0+12.0j] + src_data = [ + 1.0 + 1.0j, + 2.0 + 2.0j, + 3.0 + 3.0j, + 4.0 + 4.0j, + 5.0 + 5.0j, + 6.0 + 6.0j] + dst_data = [9.0 + 9.0j, 12.0 + 12.0j] vlen = 2 src = blocks.vector_source_c(src_data, False, vlen) itg = blocks.integrate_cc(3, vlen) @@ -81,5 +94,6 @@ class test_integrate (gr_unittest.TestCase): self.tb.run() self.assertComplexTuplesAlmostEqual(dst_data, dst.data(), 6) + if __name__ == '__main__': gr_unittest.run(test_integrate) diff --git a/gr-blocks/python/blocks/qa_interleave.py b/gr-blocks/python/blocks/qa_interleave.py index 939fa65876..028c9dc8e4 100644 --- a/gr-blocks/python/blocks/qa_interleave.py +++ b/gr-blocks/python/blocks/qa_interleave.py @@ -11,126 +11,128 @@ from gnuradio import gr, gr_unittest, blocks + class test_interleave (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_int_001 (self): + def test_int_001(self): lenx = 64 - src0 = blocks.vector_source_f (list(range(0, lenx, 4))) - src1 = blocks.vector_source_f (list(range(1, lenx, 4))) - src2 = blocks.vector_source_f (list(range(2, lenx, 4))) - src3 = blocks.vector_source_f (list(range(3, lenx, 4))) - op = blocks.interleave (gr.sizeof_float) - dst = blocks.vector_sink_f () - - self.tb.connect (src0, (op, 0)) - self.tb.connect (src1, (op, 1)) - self.tb.connect (src2, (op, 2)) - self.tb.connect (src3, (op, 3)) - self.tb.connect (op, dst) - self.tb.run () - expected_result = tuple (range (lenx)) - result_data = dst.data () - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - def test_int_002 (self): + src0 = blocks.vector_source_f(list(range(0, lenx, 4))) + src1 = blocks.vector_source_f(list(range(1, lenx, 4))) + src2 = blocks.vector_source_f(list(range(2, lenx, 4))) + src3 = blocks.vector_source_f(list(range(3, lenx, 4))) + op = blocks.interleave(gr.sizeof_float) + dst = blocks.vector_sink_f() + + self.tb.connect(src0, (op, 0)) + self.tb.connect(src1, (op, 1)) + self.tb.connect(src2, (op, 2)) + self.tb.connect(src3, (op, 3)) + self.tb.connect(op, dst) + self.tb.run() + expected_result = tuple(range(lenx)) + result_data = dst.data() + self.assertFloatTuplesAlmostEqual(expected_result, result_data) + + def test_int_002(self): blksize = 4 lenx = 64 - plusup_big = lambda a: a + (blksize * 4) - plusup_little = lambda a: a + blksize - a_vec = list(range(0,blksize)) - for i in range(0,(lenx // (4 * blksize)) - 1): + def plusup_big(a): return a + (blksize * 4) + def plusup_little(a): return a + blksize + a_vec = list(range(0, blksize)) + for i in range(0, (lenx // (4 * blksize)) - 1): a_vec += list(map(plusup_big, a_vec[len(a_vec) - blksize:])) b_vec = list(map(plusup_little, a_vec)) c_vec = list(map(plusup_little, b_vec)) d_vec = list(map(plusup_little, c_vec)) - src0 = blocks.vector_source_f (a_vec) - src1 = blocks.vector_source_f (b_vec) - src2 = blocks.vector_source_f (c_vec) - src3 = blocks.vector_source_f (d_vec) - op = blocks.interleave (gr.sizeof_float, blksize) - dst = blocks.vector_sink_f () - - self.tb.connect (src0, (op, 0)) - self.tb.connect (src1, (op, 1)) - self.tb.connect (src2, (op, 2)) - self.tb.connect (src3, (op, 3)) - self.tb.connect (op, dst) - self.tb.run () - expected_result = tuple (range (lenx)) - result_data = dst.data () - - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - def test_deint_001 (self): + src0 = blocks.vector_source_f(a_vec) + src1 = blocks.vector_source_f(b_vec) + src2 = blocks.vector_source_f(c_vec) + src3 = blocks.vector_source_f(d_vec) + op = blocks.interleave(gr.sizeof_float, blksize) + dst = blocks.vector_sink_f() + + self.tb.connect(src0, (op, 0)) + self.tb.connect(src1, (op, 1)) + self.tb.connect(src2, (op, 2)) + self.tb.connect(src3, (op, 3)) + self.tb.connect(op, dst) + self.tb.run() + expected_result = tuple(range(lenx)) + result_data = dst.data() + + self.assertFloatTuplesAlmostEqual(expected_result, result_data) + + def test_deint_001(self): lenx = 64 - src = blocks.vector_source_f (list(range(lenx))) - op = blocks.deinterleave (gr.sizeof_float) - dst0 = blocks.vector_sink_f () - dst1 = blocks.vector_sink_f () - dst2 = blocks.vector_sink_f () - dst3 = blocks.vector_sink_f () - - self.tb.connect (src, op) - self.tb.connect ((op, 0), dst0) - self.tb.connect ((op, 1), dst1) - self.tb.connect ((op, 2), dst2) - self.tb.connect ((op, 3), dst3) - self.tb.run () - - expected_result0 = tuple (range (0, lenx, 4)) - expected_result1 = tuple (range (1, lenx, 4)) - expected_result2 = tuple (range (2, lenx, 4)) - expected_result3 = tuple (range (3, lenx, 4)) - - self.assertFloatTuplesAlmostEqual (expected_result0, dst0.data ()) - self.assertFloatTuplesAlmostEqual (expected_result1, dst1.data ()) - self.assertFloatTuplesAlmostEqual (expected_result2, dst2.data ()) - self.assertFloatTuplesAlmostEqual (expected_result3, dst3.data ()) - - def test_deint_002 (self): + src = blocks.vector_source_f(list(range(lenx))) + op = blocks.deinterleave(gr.sizeof_float) + dst0 = blocks.vector_sink_f() + dst1 = blocks.vector_sink_f() + dst2 = blocks.vector_sink_f() + dst3 = blocks.vector_sink_f() + + self.tb.connect(src, op) + self.tb.connect((op, 0), dst0) + self.tb.connect((op, 1), dst1) + self.tb.connect((op, 2), dst2) + self.tb.connect((op, 3), dst3) + self.tb.run() + + expected_result0 = tuple(range(0, lenx, 4)) + expected_result1 = tuple(range(1, lenx, 4)) + expected_result2 = tuple(range(2, lenx, 4)) + expected_result3 = tuple(range(3, lenx, 4)) + + self.assertFloatTuplesAlmostEqual(expected_result0, dst0.data()) + self.assertFloatTuplesAlmostEqual(expected_result1, dst1.data()) + self.assertFloatTuplesAlmostEqual(expected_result2, dst2.data()) + self.assertFloatTuplesAlmostEqual(expected_result3, dst3.data()) + + def test_deint_002(self): blksize = 4 lenx = 64 - src = blocks.vector_source_f (list(range(lenx))) - op = blocks.deinterleave (gr.sizeof_float, blksize) - dst0 = blocks.vector_sink_f () - dst1 = blocks.vector_sink_f () - dst2 = blocks.vector_sink_f () - dst3 = blocks.vector_sink_f () - - self.tb.connect (src, op) - self.tb.connect ((op, 0), dst0) - self.tb.connect ((op, 1), dst1) - self.tb.connect ((op, 2), dst2) - self.tb.connect ((op, 3), dst3) - self.tb.run () - - plusup_big = lambda a: a + (blksize * 4) - plusup_little = lambda a: a + blksize - a_vec = list(range(0,blksize)) - for i in range(0,(lenx // (4 * blksize)) - 1): + src = blocks.vector_source_f(list(range(lenx))) + op = blocks.deinterleave(gr.sizeof_float, blksize) + dst0 = blocks.vector_sink_f() + dst1 = blocks.vector_sink_f() + dst2 = blocks.vector_sink_f() + dst3 = blocks.vector_sink_f() + + self.tb.connect(src, op) + self.tb.connect((op, 0), dst0) + self.tb.connect((op, 1), dst1) + self.tb.connect((op, 2), dst2) + self.tb.connect((op, 3), dst3) + self.tb.run() + + def plusup_big(a): return a + (blksize * 4) + def plusup_little(a): return a + blksize + a_vec = list(range(0, blksize)) + for i in range(0, (lenx // (4 * blksize)) - 1): a_vec += list(map(plusup_big, a_vec[len(a_vec) - blksize:])) b_vec = list(map(plusup_little, a_vec)) c_vec = list(map(plusup_little, b_vec)) d_vec = list(map(plusup_little, c_vec)) - expected_result0 = tuple (a_vec) - expected_result1 = tuple (b_vec) - expected_result2 = tuple (c_vec) - expected_result3 = tuple (d_vec) + expected_result0 = tuple(a_vec) + expected_result1 = tuple(b_vec) + expected_result2 = tuple(c_vec) + expected_result3 = tuple(d_vec) + + self.assertFloatTuplesAlmostEqual(expected_result0, dst0.data()) + self.assertFloatTuplesAlmostEqual(expected_result1, dst1.data()) + self.assertFloatTuplesAlmostEqual(expected_result2, dst2.data()) + self.assertFloatTuplesAlmostEqual(expected_result3, dst3.data()) - self.assertFloatTuplesAlmostEqual (expected_result0, dst0.data ()) - self.assertFloatTuplesAlmostEqual (expected_result1, dst1.data ()) - self.assertFloatTuplesAlmostEqual (expected_result2, dst2.data ()) - self.assertFloatTuplesAlmostEqual (expected_result3, dst3.data ()) if __name__ == '__main__': gr_unittest.run(test_interleave) diff --git a/gr-blocks/python/blocks/qa_keep_m_in_n.py b/gr-blocks/python/blocks/qa_keep_m_in_n.py index 17298cd1fa..b055303e5c 100644 --- a/gr-blocks/python/blocks/qa_keep_m_in_n.py +++ b/gr-blocks/python/blocks/qa_keep_m_in_n.py @@ -61,8 +61,8 @@ class test_keep_m_in_n(gr_unittest.TestCase): self.assertEqual( sorted( list(range(i, 100, 5)) + - list(range((i+1) % 5, 100, 5)) + - list(range((i+2) % 5, 100, 5)) + list(range((i + 1) % 5, 100, 5)) + + list(range((i + 2) % 5, 100, 5)) ), list(snk[i].data()) ) @@ -82,7 +82,8 @@ class test_keep_m_in_n(gr_unittest.TestCase): with self.assertRaises(RuntimeError) as cm: blocks.keep_m_in_n(8, 2, 5, -1) - self.assertEqual(str(cm.exception), 'keep_m_in_n: offset (-1) must be >= 0') + self.assertEqual(str(cm.exception), + 'keep_m_in_n: offset (-1) must be >= 0') with self.assertRaises(RuntimeError) as cm: blocks.keep_m_in_n(8, 2, 5, 5) diff --git a/gr-blocks/python/blocks/qa_keep_one_in_n.py b/gr-blocks/python/blocks/qa_keep_one_in_n.py index d37195963f..613fc8ed14 100644 --- a/gr-blocks/python/blocks/qa_keep_one_in_n.py +++ b/gr-blocks/python/blocks/qa_keep_one_in_n.py @@ -11,12 +11,13 @@ from gnuradio import gr, gr_unittest, blocks + class test_keep_one_in_n(gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_001(self): diff --git a/gr-blocks/python/blocks/qa_logger.py b/gr-blocks/python/blocks/qa_logger.py index 697d657c79..f3714afbb3 100644 --- a/gr-blocks/python/blocks/qa_logger.py +++ b/gr-blocks/python/blocks/qa_logger.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_logger (gr_unittest.TestCase): def setUp(self): @@ -45,9 +46,9 @@ class test_logger (gr_unittest.TestCase): # Make sure exception is throw on bogus data self.assertRaises(RuntimeError, ns.set_log_level, "11") - def test_log_level_for_tb(self): - # Test the python API for getting and setting log levels for a top_block + # Test the python API for getting and setting log levels for a + # top_block nsrc = blocks.null_source(4) nsnk = blocks.null_sink(4) # Set all log levels to a known state @@ -64,10 +65,12 @@ class test_logger (gr_unittest.TestCase): self.assertEqual(nsnk.log_level(), "alert") def test_log_level_for_hier_block(self): - # Test the python API for getting and setting log levels for hier blocks + # Test the python API for getting and setting log levels for hier + # blocks nsrc = blocks.null_source(4) nsnk = blocks.null_sink(4) - b = blocks.stream_to_vector_decimator(4, 1, 1, 1) # just a random hier block that exists + b = blocks.stream_to_vector_decimator( + 4, 1, 1, 1) # just a random hier block that exists tb = gr.top_block() tb.connect(nsrc, b, nsnk) tb.set_log_level("debug") @@ -81,5 +84,6 @@ class test_logger (gr_unittest.TestCase): self.assertEqual(nsnk.log_level(), "alert") self.assertEqual(b.one_in_n.log_level(), "alert") + if __name__ == '__main__': gr_unittest.run(test_logger) diff --git a/gr-blocks/python/blocks/qa_max.py b/gr-blocks/python/blocks/qa_max.py index 31c949853c..86250b7d4f 100644 --- a/gr-blocks/python/blocks/qa_max.py +++ b/gr-blocks/python/blocks/qa_max.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest, blocks import math + class test_max(gr_unittest.TestCase): def setUp(self): @@ -22,8 +23,8 @@ class test_max(gr_unittest.TestCase): self.tb = None def test_001(self): - src_data = [0,0.2,-0.3,0,12,0] - expected_result = [float(max(src_data)),] + src_data = [0, 0.2, -0.3, 0, 12, 0] + expected_result = [float(max(src_data)), ] src = blocks.vector_source_f(src_data) s2v = blocks.stream_to_vector(gr.sizeof_float, len(src_data)) @@ -36,8 +37,8 @@ class test_max(gr_unittest.TestCase): self.assertEqual(expected_result, result_data) def stest_002(self): - src_data=[-100,-99,-98,-97,-96,-1] - expected_result = [float(max(src_data)),] + src_data = [-100, -99, -98, -97, -96, -1] + expected_result = [float(max(src_data)), ] src = blocks.vector_source_f(src_data) s2v = blocks.stream_to_vector(gr.sizeof_float, len(src_data)) @@ -51,9 +52,10 @@ class test_max(gr_unittest.TestCase): def stest_003(self): src_data0 = [0, 2, -3, 0, 12, 0] - src_data1 = [1, 1, 1, 1, 1, 1] + src_data1 = [1, 1, 1, 1, 1, 1] - expected_result = [float(max(x,y)) for x,y in zip(src_data0, src_data1)] + expected_result = [float(max(x, y)) + for x, y in zip(src_data0, src_data1)] src0 = blocks.vector_source_f(src_data0) src1 = blocks.vector_source_f(src_data1) @@ -70,17 +72,17 @@ class test_max(gr_unittest.TestCase): def stest_004(self): dim = 2 src_data0 = [0, 2, -3, 0, 12, 0] - src_data1 = [1, 1, 1, 1, 1, 1] + src_data1 = [1, 1, 1, 1, 1, 1] expected_data = [] - tmp = [float(max(x,y)) for x,y in zip(src_data0, src_data1)] + tmp = [float(max(x, y)) for x, y in zip(src_data0, src_data1)] for i in range(len(tmp) / dim): - expected_data.append(float(max(tmp[i*dim:(i+1)*dim]))) + expected_data.append(float(max(tmp[i * dim:(i + 1) * dim]))) src0 = blocks.vector_source_f(src_data0) - s2v0 = blocks.stream_to_vector(gr.sizeof_float,dim) + s2v0 = blocks.stream_to_vector(gr.sizeof_float, dim) src1 = blocks.vector_source_f(src_data1) - s2v1 = blocks.stream_to_vector(gr.sizeof_float,dim) + s2v1 = blocks.stream_to_vector(gr.sizeof_float, dim) op = blocks.max_ff(dim) dst = blocks.vector_sink_f() @@ -91,13 +93,12 @@ class test_max(gr_unittest.TestCase): result_data = dst.data() self.assertEqual(expected_result, result_data) - def stest_s001(self): src_data = [0, 2, -3, 0, 12, 0] - expected_result = [max(src_data),] + expected_result = [max(src_data), ] src = blocks.vector_source_s(src_data) - s2v = blocks.stream_to_vector(gr.sizeof_short,len(src_data)) + s2v = blocks.stream_to_vector(gr.sizeof_short, len(src_data)) op = blocks.max_ss(len(src_data)) dst = blocks.vector_sink_s() @@ -107,8 +108,8 @@ class test_max(gr_unittest.TestCase): self.assertEqual(expected_result, result_data) def stest_s002(self): - src_data=[-100,-99,-98,-97,-96,-1] - expected_result = [max(src_data),] + src_data = [-100, -99, -98, -97, -96, -1] + expected_result = [max(src_data), ] src = blocks.vector_source_s(src_data) s2v = blocks.stream_to_vector(gr.sizeof_short, len(src_data)) @@ -120,12 +121,11 @@ class test_max(gr_unittest.TestCase): result_data = dst.data() self.assertEqual(expected_result, result_data) - def stest_s003(self): src_data0 = [0, 2, -3, 0, 12, 0] - src_data1 = [1, 1, 1, 1, 1, 1] + src_data1 = [1, 1, 1, 1, 1, 1] - expected_result = [max(x,y) for x,y in zip(src_data0, src_data1)] + expected_result = [max(x, y) for x, y in zip(src_data0, src_data1)] src0 = blocks.vector_source_s(src_data0) src1 = blocks.vector_source_s(src_data1) @@ -142,17 +142,17 @@ class test_max(gr_unittest.TestCase): def stest_s004(self): dim = 2 src_data0 = [0, 2, -3, 0, 12, 0] - src_data1 = [1, 1, 1, 1, 1, 1] + src_data1 = [1, 1, 1, 1, 1, 1] expected_data = [] - tmp = [max(x,y) for x,y in zip(src_data0, src_data1)] + tmp = [max(x, y) for x, y in zip(src_data0, src_data1)] for i in range(len(tmp) / dim): - expected_data.append(max(tmp[i*dim:(i+1)*dim])) + expected_data.append(max(tmp[i * dim:(i + 1) * dim])) src0 = blocks.vector_source_s(src_data0) - s2v0 = blocks.stream_to_vector(gr.sizeof_short,dim) + s2v0 = blocks.stream_to_vector(gr.sizeof_short, dim) src1 = blocks.vector_source_s(src_data1) - s2v1 = blocks.stream_to_vector(gr.sizeof_short,dim) + s2v1 = blocks.stream_to_vector(gr.sizeof_short, dim) op = blocks.max_ss(dim) dst = blocks.vector_sink_s() diff --git a/gr-blocks/python/blocks/qa_message.py b/gr-blocks/python/blocks/qa_message.py index af31d7256c..1df6857490 100644 --- a/gr-blocks/python/blocks/qa_message.py +++ b/gr-blocks/python/blocks/qa_message.py @@ -56,7 +56,7 @@ class test_message(gr_unittest.TestCase): msg = gr.message_from_string(s) self.assertEquals(s.encode('utf8'), msg.to_string()) - ## msg_queue was removed from API in 3.8 + # msg_queue was removed from API in 3.8 # def test_200(self): # self.leak_check(self.body_200) @@ -88,7 +88,7 @@ class test_message(gr_unittest.TestCase): msg = gr.message(666) def test_300(self): - input_data = [0,1,2,3,4,5,6,7,8,9] + input_data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] src = blocks.vector_source_b(input_data) dst = blocks.vector_sink_b() tb = gr.top_block() diff --git a/gr-blocks/python/blocks/qa_min.py b/gr-blocks/python/blocks/qa_min.py index 1cd8f31e82..3ae46257a3 100644 --- a/gr-blocks/python/blocks/qa_min.py +++ b/gr-blocks/python/blocks/qa_min.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest, blocks import math + class test_min(gr_unittest.TestCase): def setUp(self): @@ -23,7 +24,7 @@ class test_min(gr_unittest.TestCase): def test_001(self): src_data = [0, 0.2, -0.25, 0, 12, 0] - expected_result = [float(min(src_data)),] + expected_result = [float(min(src_data)), ] src = blocks.vector_source_f(src_data) s2v = blocks.stream_to_vector(gr.sizeof_float, len(src_data)) @@ -36,8 +37,8 @@ class test_min(gr_unittest.TestCase): self.assertEqual(expected_result, result_data) def stest_002(self): - src_data=[-100,-99,-98,-97,-96,-1] - expected_result = [float(min(src_data)),] + src_data = [-100, -99, -98, -97, -96, -1] + expected_result = [float(min(src_data)), ] src = blocks.vector_source_f(src_data) s2v = blocks.stream_to_vector(gr.sizeof_float, len(src_data)) @@ -51,9 +52,10 @@ class test_min(gr_unittest.TestCase): def stest_003(self): src_data0 = [0, 2, -3, 0, 12, 0] - src_data1 = [1, 1, 1, 1, 1, 1] + src_data1 = [1, 1, 1, 1, 1, 1] - expected_result = [float(min(x,y)) for x,y in zip(src_data0, src_data1)] + expected_result = [float(min(x, y)) + for x, y in zip(src_data0, src_data1)] src0 = blocks.vector_source_f(src_data0) src1 = blocks.vector_source_f(src_data1) @@ -70,17 +72,17 @@ class test_min(gr_unittest.TestCase): def stest_004(self): dim = 2 src_data0 = [0, 2, -3, 0, 12, 0] - src_data1 = [1, 1, 1, 1, 1, 1] + src_data1 = [1, 1, 1, 1, 1, 1] expected_data = [] - tmp = [float(min(x,y)) for x,y in zip(src_data0, src_data1)] + tmp = [float(min(x, y)) for x, y in zip(src_data0, src_data1)] for i in range(len(tmp) / dim): - expected_data.append(float(min(tmp[i*dim:(i+1)*dim]))) + expected_data.append(float(min(tmp[i * dim:(i + 1) * dim]))) src0 = blocks.vector_source_f(src_data0) - s2v0 = blocks.stream_to_vector(gr.sizeof_float,dim) + s2v0 = blocks.stream_to_vector(gr.sizeof_float, dim) src1 = blocks.vector_source_f(src_data1) - s2v1 = blocks.stream_to_vector(gr.sizeof_float,dim) + s2v1 = blocks.stream_to_vector(gr.sizeof_float, dim) op = blocks.min_ff(dim) dst = blocks.vector_sink_f() @@ -91,13 +93,12 @@ class test_min(gr_unittest.TestCase): result_data = dst.data() self.assertEqual(expected_result, result_data) - def stest_s001(self): src_data = [0, 2, -3, 0, 12, 0] - expected_result = [min(src_data),] + expected_result = [min(src_data), ] src = blocks.vector_source_s(src_data) - s2v = blocks.stream_to_vector(gr.sizeof_short,len(src_data)) + s2v = blocks.stream_to_vector(gr.sizeof_short, len(src_data)) op = blocks.min_ss(len(src_data)) dst = blocks.vector_sink_s() @@ -107,8 +108,8 @@ class test_min(gr_unittest.TestCase): self.assertEqual(expected_result, result_data) def stest_s002(self): - src_data=[-100,-99,-98,-97,-96,-1] - expected_result = [min(src_data),] + src_data = [-100, -99, -98, -97, -96, -1] + expected_result = [min(src_data), ] src = blocks.vector_source_s(src_data) s2v = blocks.stream_to_vector(gr.sizeof_short, len(src_data)) @@ -120,12 +121,11 @@ class test_min(gr_unittest.TestCase): result_data = dst.data() self.assertEqual(expected_result, result_data) - def stest_s003(self): src_data0 = [0, 2, -3, 0, 12, 0] - src_data1 = [1, 1, 1, 1, 1, 1] + src_data1 = [1, 1, 1, 1, 1, 1] - expected_result = [min(x,y) for x,y in zip(src_data0, src_data1)] + expected_result = [min(x, y) for x, y in zip(src_data0, src_data1)] src0 = blocks.vector_source_s(src_data0) src1 = blocks.vector_source_s(src_data1) @@ -142,17 +142,17 @@ class test_min(gr_unittest.TestCase): def stest_s004(self): dim = 2 src_data0 = [0, 2, -3, 0, 12, 0] - src_data1 = [1, 1, 1, 1, 1, 1] + src_data1 = [1, 1, 1, 1, 1, 1] expected_data = [] - tmp = [min(x,y) for x,y in zip(src_data0, src_data1)] + tmp = [min(x, y) for x, y in zip(src_data0, src_data1)] for i in range(len(tmp) / dim): - expected_data.append(min(tmp[i*dim:(i+1)*dim])) + expected_data.append(min(tmp[i * dim:(i + 1) * dim])) src0 = blocks.vector_source_s(src_data0) - s2v0 = blocks.stream_to_vector(gr.sizeof_short,dim) + s2v0 = blocks.stream_to_vector(gr.sizeof_short, dim) src1 = blocks.vector_source_s(src_data1) - s2v1 = blocks.stream_to_vector(gr.sizeof_short,dim) + s2v1 = blocks.stream_to_vector(gr.sizeof_short, dim) op = blocks.min_ss(dim) dst = blocks.vector_sink_s() @@ -163,5 +163,6 @@ class test_min(gr_unittest.TestCase): result_data = dst.data() self.assertEqual(expected_result, result_data) + if __name__ == '__main__': gr_unittest.run(test_min) diff --git a/gr-blocks/python/blocks/qa_moving_average.py b/gr-blocks/python/blocks/qa_moving_average.py index 1691eac71e..8f4169d05c 100644 --- a/gr-blocks/python/blocks/qa_moving_average.py +++ b/gr-blocks/python/blocks/qa_moving_average.py @@ -11,27 +11,31 @@ from gnuradio import gr, gr_unittest, blocks -import math, random +import math +import random + def make_random_complex_tuple(L, scale=1): result = [] for x in range(L): - result.append(scale*complex(2*random.random()-1, - 2*random.random()-1)) + result.append(scale * complex(2 * random.random() - 1, + 2 * random.random() - 1)) return tuple(result) + def make_random_float_tuple(L, scale=1): result = [] for x in range(L): - result.append(scale*(2*random.random()-1)) + result.append(scale * (2 * random.random() - 1)) return tuple(result) + class test_moving_average(gr_unittest.TestCase): def assertListAlmostEqual(self, list1, list2, tol): self.assertEqual(len(list1), len(list2)) for a, b in zip(list1, list2): self.assertAlmostEqual(a, b, tol) - + def setUp(self): random.seed(0) self.tb = gr.top_block() @@ -48,10 +52,10 @@ class test_moving_average(gr_unittest.TestCase): N = 10000 data = make_random_float_tuple(N, 1) - expected_result = N*[0,] + expected_result = N * [0, ] src = blocks.vector_source_f(data, False) - op = blocks.moving_average_ff(100, 0.001) + op = blocks.moving_average_ff(100, 0.001) dst = blocks.vector_sink_f() tb.connect(src, op) @@ -68,10 +72,10 @@ class test_moving_average(gr_unittest.TestCase): N = 10000 data = make_random_complex_tuple(N, 1) - expected_result = N*[0,] + expected_result = N * [0, ] src = blocks.vector_source_c(data, False) - op = blocks.moving_average_cc(100, 0.001) + op = blocks.moving_average_cc(100, 0.001) dst = blocks.vector_sink_c() tb.connect(src, op) @@ -83,20 +87,21 @@ class test_moving_average(gr_unittest.TestCase): # make sure result is close to zero self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 1) - # This tests implement own moving average to verify correct behaviour of the block + # This tests implement own moving average to verify correct behaviour of + # the block def test_vector_int(self): tb = self.tb vlen = 5 - N = 10*vlen + N = 10 * vlen data = make_random_float_tuple(N, 2**10) - data = [int(d*1000) for d in data] + data = [int(d * 1000) for d in data] src = blocks.vector_source_i(data, False) one_to_many = blocks.stream_to_streams(gr.sizeof_int, vlen) one_to_vector = blocks.stream_to_vector(gr.sizeof_int, vlen) many_to_vector = blocks.streams_to_vector(gr.sizeof_int, vlen) - isolated = [ blocks.moving_average_ii(100, 1) for i in range(vlen)] + isolated = [blocks.moving_average_ii(100, 1) for i in range(vlen)] dut = blocks.moving_average_ii(100, 1, vlen=vlen) dut_dst = blocks.vector_sink_i(vlen=vlen) ref_dst = blocks.vector_sink_i(vlen=vlen) @@ -105,7 +110,7 @@ class test_moving_average(gr_unittest.TestCase): tb.connect(src, one_to_vector, dut, dut_dst) tb.connect(many_to_vector, ref_dst) for idx, single in enumerate(isolated): - tb.connect((one_to_many,idx), single, (many_to_vector,idx)) + tb.connect((one_to_many, idx), single, (many_to_vector, idx)) tb.run() @@ -119,13 +124,13 @@ class test_moving_average(gr_unittest.TestCase): tb = self.tb vlen = 5 - N = 10*vlen + N = 10 * vlen data = make_random_complex_tuple(N, 2**10) src = blocks.vector_source_c(data, False) one_to_many = blocks.stream_to_streams(gr.sizeof_gr_complex, vlen) one_to_vector = blocks.stream_to_vector(gr.sizeof_gr_complex, vlen) many_to_vector = blocks.streams_to_vector(gr.sizeof_gr_complex, vlen) - isolated = [ blocks.moving_average_cc(100, 1) for i in range(vlen)] + isolated = [blocks.moving_average_cc(100, 1) for i in range(vlen)] dut = blocks.moving_average_cc(100, 1, vlen=vlen) dut_dst = blocks.vector_sink_c(vlen=vlen) ref_dst = blocks.vector_sink_c(vlen=vlen) @@ -134,7 +139,7 @@ class test_moving_average(gr_unittest.TestCase): tb.connect(src, one_to_vector, dut, dut_dst) tb.connect(many_to_vector, ref_dst) for idx, single in enumerate(isolated): - tb.connect((one_to_many,idx), single, (many_to_vector,idx)) + tb.connect((one_to_many, idx), single, (many_to_vector, idx)) tb.run() @@ -152,26 +157,28 @@ class test_moving_average(gr_unittest.TestCase): data = make_random_complex_tuple(N, 1) # generate random data # pythonic MA filter - data_padded = (history-1)*[complex(0.0, 0.0)]+list(data) # history + data_padded = (history - 1) * \ + [complex(0.0, 0.0)] + list(data) # history expected_result = [] - moving_sum = sum(data_padded[:history-1]) + moving_sum = sum(data_padded[:history - 1]) for i in range(N): - moving_sum += data_padded[i+history-1] + moving_sum += data_padded[i + history - 1] expected_result.append(moving_sum) moving_sum -= data_padded[i] src = blocks.vector_source_c(data, False) - op = blocks.moving_average_cc(history, 1) + op = blocks.moving_average_cc(history, 1) dst = blocks.vector_sink_c() - + tb.connect(src, op) tb.connect(op, dst) tb.run() - + dst_data = dst.data() # make sure result is close to zero self.assertListAlmostEqual(expected_result, dst_data, 4) + if __name__ == '__main__': gr_unittest.run(test_moving_average) diff --git a/gr-blocks/python/blocks/qa_multiply_conjugate.py b/gr-blocks/python/blocks/qa_multiply_conjugate.py index 3590a703ae..50d48ec672 100644 --- a/gr-blocks/python/blocks/qa_multiply_conjugate.py +++ b/gr-blocks/python/blocks/qa_multiply_conjugate.py @@ -11,36 +11,38 @@ from gnuradio import gr, gr_unittest, blocks + class test_multiply_conjugate (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_000 (self): - src_data0 = [-2-2j, -1-1j, -2+2j, -1+1j, - 2-2j, 1-1j, 2+2j, 1+1j, - 0+0j] - src_data1 = [-3-3j, -4-4j, -3+3j, -4+4j, - 3-3j, 4-4j, 3+3j, 4+4j, - 0+0j] - - exp_data = [12+0j, 8+0j, 12+0j, 8+0j, - 12+0j, 8+0j, 12+0j, 8+0j, - 0+0j] + def test_000(self): + src_data0 = [-2 - 2j, -1 - 1j, -2 + 2j, -1 + 1j, + 2 - 2j, 1 - 1j, 2 + 2j, 1 + 1j, + 0 + 0j] + src_data1 = [-3 - 3j, -4 - 4j, -3 + 3j, -4 + 4j, + 3 - 3j, 4 - 4j, 3 + 3j, 4 + 4j, + 0 + 0j] + + exp_data = [12 + 0j, 8 + 0j, 12 + 0j, 8 + 0j, + 12 + 0j, 8 + 0j, 12 + 0j, 8 + 0j, + 0 + 0j] src0 = blocks.vector_source_c(src_data0) src1 = blocks.vector_source_c(src_data1) - op = blocks.multiply_conjugate_cc () - dst = blocks.vector_sink_c () + op = blocks.multiply_conjugate_cc() + dst = blocks.vector_sink_c() - self.tb.connect(src0, (op,0)) - self.tb.connect(src1, (op,1)) + self.tb.connect(src0, (op, 0)) + self.tb.connect(src1, (op, 1)) self.tb.connect(op, dst) self.tb.run() - result_data = dst.data () - self.assertEqual (exp_data, result_data) + result_data = dst.data() + self.assertEqual(exp_data, result_data) + if __name__ == '__main__': gr_unittest.run(test_multiply_conjugate) diff --git a/gr-blocks/python/blocks/qa_multiply_matrix_xx.py b/gr-blocks/python/blocks/qa_multiply_matrix_xx.py index 3b877d9d27..c908bf52e9 100644 --- a/gr-blocks/python/blocks/qa_multiply_matrix_xx.py +++ b/gr-blocks/python/blocks/qa_multiply_matrix_xx.py @@ -1,13 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# +# # Copyright 2014 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# import time @@ -19,36 +19,37 @@ from gnuradio import blocks BLOCK_LOOKUP = { 'float': { - 'src': blocks.vector_source_f, + 'src': blocks.vector_source_f, 'sink': blocks.vector_sink_f, 'mult': blocks.multiply_matrix_ff, }, 'complex': { - 'src': blocks.vector_source_c, + 'src': blocks.vector_source_c, 'sink': blocks.vector_sink_c, 'mult': blocks.multiply_matrix_cc, }, } + class test_multiply_matrix_xx (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() self.multiplier = None - def tearDown (self): + def tearDown(self): self.tb = None self.multiplier = None def run_once(self, - X_in, - A, - tpp=gr.TPP_DONT, - A2=None, - tags=None, - msg_A=None, - datatype='float', - ): + X_in, + A, + tpp=gr.TPP_DONT, + A2=None, + tags=None, + msg_A=None, + datatype='float', + ): """ Run the test for given input-, output- and matrix values. Every row from X_in is considered an input signal on a port. """ X_in = numpy.matrix(X_in) @@ -68,9 +69,11 @@ class test_multiply_matrix_xx (gr_unittest.TestCase): else: these_tags = (tags[i],) self.tb.connect( - BLOCK_LOOKUP[datatype]['src'](X_in[i].tolist()[0], tags=these_tags), - (self.multiplier, i) - ) + BLOCK_LOOKUP[datatype]['src']( + X_in[i].tolist()[0], + tags=these_tags), + (self.multiplier, + i)) sinks = [] for i in range(M): sinks.append(BLOCK_LOOKUP[datatype]['sink']()) @@ -78,7 +81,7 @@ class test_multiply_matrix_xx (gr_unittest.TestCase): # Run and check self.tb.run() for i in range(X_in.shape[1]): - Y_out_exp[:,i] = A_matrix * X_in[:,i] + Y_out_exp[:, i] = A_matrix * X_in[:, i] Y_out = [list(x.data()) for x in sinks] if tags is not None: self.the_tags = [] @@ -86,8 +89,7 @@ class test_multiply_matrix_xx (gr_unittest.TestCase): self.the_tags.append(sinks[i].tags()) self.assertEqual(list(Y_out), Y_out_exp.tolist()) - - def test_001_t (self): + def test_001_t(self): """ Simplest possible check: N==M, unit matrix """ X_in = ( (1, 2, 3, 4), @@ -99,7 +101,7 @@ class test_multiply_matrix_xx (gr_unittest.TestCase): ) self.run_once(X_in, A) - def test_001_t_complex (self): + def test_001_t_complex(self): """ Simplest possible check: N==M, unit matrix """ X_in = ( (1, 2, 3, 4), @@ -111,7 +113,7 @@ class test_multiply_matrix_xx (gr_unittest.TestCase): ) self.run_once(X_in, A, datatype='complex') - def test_002_t (self): + def test_002_t(self): """ Switch check: N==M, flipped unit matrix """ X_in = ( (1, 2, 3, 4), @@ -123,7 +125,7 @@ class test_multiply_matrix_xx (gr_unittest.TestCase): ) self.run_once(X_in, A) - def test_003_t (self): + def test_003_t(self): """ Average """ X_in = ( (1, 1, 1, 1), @@ -135,7 +137,7 @@ class test_multiply_matrix_xx (gr_unittest.TestCase): ) self.run_once(X_in, A) - def test_004_t (self): + def test_004_t(self): """ Set """ X_in = ( (1, 2, 3, 4), @@ -151,14 +153,14 @@ class test_multiply_matrix_xx (gr_unittest.TestCase): ) self.run_once(X_in, A1, A2=A2) - def test_005_t (self): + def test_005_t(self): """ Tags """ X_in = ( (1, 2, 3, 4), (5, 6, 7, 8), ) A = ( - (0, 1), # Flip them round + (0, 1), # Flip them round (1, 0), ) tag1 = gr.tag_t() @@ -173,24 +175,22 @@ class test_multiply_matrix_xx (gr_unittest.TestCase): self.assertTrue(pmt.equal(tag1.key, self.the_tags[0][0].key)) self.assertTrue(pmt.equal(tag2.key, self.the_tags[1][0].key)) - #def test_006_t (self): + # def test_006_t (self): #""" Message passing """ - #X_in = ( - #(1, 2, 3, 4), - #(5, 6, 7, 8), - #) - #A1 = ( - #(1, 0), - #(0, 1), - #) - #msg_A = ( - #(0, 1), - #(1, 0), - #) + # X_in = ( + #(1, 2, 3, 4), + #(5, 6, 7, 8), + # ) + # A1 = ( + #(1, 0), + #(0, 1), + # ) + # msg_A = ( + #(0, 1), + #(1, 0), + # ) #self.run_once(X_in, A1, msg_A=msg_A) - if __name__ == '__main__': gr_unittest.run(test_multiply_matrix_xx) - diff --git a/gr-blocks/python/blocks/qa_mute.py b/gr-blocks/python/blocks/qa_mute.py index ae789f1a13..e5aaf76798 100644 --- a/gr-blocks/python/blocks/qa_mute.py +++ b/gr-blocks/python/blocks/qa_mute.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_mute(gr_unittest.TestCase): def setUp(self): @@ -62,16 +63,17 @@ class test_mute(gr_unittest.TestCase): self.help_ii((src_data,), expected_result, op) def test_unmute_cc(self): - src_data = [1+5j, 2+5j, 3+5j, 4+5j, 5+5j] - expected_result = [1+5j, 2+5j, 3+5j, 4+5j, 5+5j] + src_data = [1 + 5j, 2 + 5j, 3 + 5j, 4 + 5j, 5 + 5j] + expected_result = [1 + 5j, 2 + 5j, 3 + 5j, 4 + 5j, 5 + 5j] op = blocks.mute_cc(False) self.help_cc((src_data,), expected_result, op) def test_unmute_cc(self): - src_data = [1+5j, 2+5j, 3+5j, 4+5j, 5+5j] - expected_result =[0+0j, 0+0j, 0+0j, 0+0j, 0+0j] + src_data = [1 + 5j, 2 + 5j, 3 + 5j, 4 + 5j, 5 + 5j] + expected_result = [0 + 0j, 0 + 0j, 0 + 0j, 0 + 0j, 0 + 0j] op = blocks.mute_cc(True) self.help_cc((src_data,), expected_result, op) + if __name__ == '__main__': gr_unittest.run(test_mute) diff --git a/gr-blocks/python/blocks/qa_nlog10.py b/gr-blocks/python/blocks/qa_nlog10.py index 92a5e22ee7..e6fb3b942b 100644 --- a/gr-blocks/python/blocks/qa_nlog10.py +++ b/gr-blocks/python/blocks/qa_nlog10.py @@ -11,12 +11,13 @@ from gnuradio import gr, gr_unittest, blocks + class test_nlog10(gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_001(self): @@ -25,12 +26,11 @@ class test_nlog10(gr_unittest.TestCase): src = blocks.vector_source_f(src_data) op = blocks.nlog10_ff(10) dst = blocks.vector_sink_f() - self.tb.connect (src, op, dst) + self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data, 5) + self.assertFloatTuplesAlmostEqual(expected_result, result_data, 5) if __name__ == '__main__': gr_unittest.run(test_nlog10) - diff --git a/gr-blocks/python/blocks/qa_null_sink_source.py b/gr-blocks/python/blocks/qa_null_sink_source.py index d903eb9c0c..b8acdfc027 100644 --- a/gr-blocks/python/blocks/qa_null_sink_source.py +++ b/gr-blocks/python/blocks/qa_null_sink_source.py @@ -12,6 +12,7 @@ from gnuradio import gr, gr_unittest, blocks import math + class test_null_sink_source(gr_unittest.TestCase): def setUp(self): @@ -29,6 +30,6 @@ class test_null_sink_source(gr_unittest.TestCase): self.tb.connect(src, hed, dst) self.tb.run() + if __name__ == '__main__': gr_unittest.run(test_null_sink_source) - diff --git a/gr-blocks/python/blocks/qa_pack_k_bits.py b/gr-blocks/python/blocks/qa_pack_k_bits.py index 435325cd40..b38f9c519d 100644 --- a/gr-blocks/python/blocks/qa_pack_k_bits.py +++ b/gr-blocks/python/blocks/qa_pack_k_bits.py @@ -13,6 +13,7 @@ import random from gnuradio import gr, gr_unittest, blocks + class test_pack(gr_unittest.TestCase): def setUp(self): @@ -23,9 +24,9 @@ class test_pack(gr_unittest.TestCase): self.tb = None def test_001(self): - src_data = [1,0,1,1,0,1,1,0] - expected_results = [1,0,1,1,0,1,1,0] - src = blocks.vector_source_b(src_data,False) + src_data = [1, 0, 1, 1, 0, 1, 1, 0] + expected_results = [1, 0, 1, 1, 0, 1, 1, 0] + src = blocks.vector_source_b(src_data, False) op = blocks.pack_k_bits_bb(1) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) @@ -33,9 +34,9 @@ class test_pack(gr_unittest.TestCase): self.assertEqual(expected_results, dst.data()) def test_002(self): - src_data = [1,0,1,1,0,0,0,1] - expected_results = [ 2, 3, 0, 1] - src = blocks.vector_source_b(src_data,False) + src_data = [1, 0, 1, 1, 0, 0, 0, 1] + expected_results = [2, 3, 0, 1] + src = blocks.vector_source_b(src_data, False) op = blocks.pack_k_bits_bb(2) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) @@ -44,15 +45,15 @@ class test_pack(gr_unittest.TestCase): self.assertEqual(expected_results, dst.data()) def test_003(self): - src_data = expected_results = [random.randint(0,3) for x in range(10)]; - src = blocks.vector_source_b( src_data ) + src_data = expected_results = [random.randint(0, 3) for x in range(10)] + src = blocks.vector_source_b(src_data) pack = blocks.pack_k_bits_bb(2) unpack = blocks.unpack_k_bits_bb(2) snk = blocks.vector_sink_b() - self.tb.connect(src,unpack,pack,snk) + self.tb.connect(src, unpack, pack, snk) self.tb.run() self.assertEqual(list(expected_results), list(snk.data())) -if __name__ == '__main__': - gr_unittest.run(test_pack) +if __name__ == '__main__': + gr_unittest.run(test_pack) diff --git a/gr-blocks/python/blocks/qa_packed_to_unpacked.py b/gr-blocks/python/blocks/qa_packed_to_unpacked.py index 5965b6c067..b3bc0d93e4 100644 --- a/gr-blocks/python/blocks/qa_packed_to_unpacked.py +++ b/gr-blocks/python/blocks/qa_packed_to_unpacked.py @@ -13,18 +13,19 @@ from gnuradio import gr, gr_unittest, blocks import random + class test_packing(gr_unittest.TestCase): def setUp(self): random.seed(0) - self.tb = gr.top_block () + self.tb = gr.top_block() def tearDown(self): self.tb = None def test_001(self): - src_data = [0x80,] - expected_results = [1,0,0,0,0,0,0,0] + src_data = [0x80, ] + expected_results = [1, 0, 0, 0, 0, 0, 0, 0] src = blocks.vector_source_b(src_data, False) op = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) dst = blocks.vector_sink_b() @@ -36,8 +37,8 @@ class test_packing(gr_unittest.TestCase): self.assertEqual(expected_results, dst.data()) def test_002(self): - src_data = [0x80,] - expected_results = [0,0,0,0,0,0,0,1] + src_data = [0x80, ] + expected_results = [0, 0, 0, 0, 0, 0, 0, 1] src = blocks.vector_source_b(src_data, False) op = blocks.packed_to_unpacked_bb(1, gr.GR_LSB_FIRST) dst = blocks.vector_sink_b() @@ -49,7 +50,7 @@ class test_packing(gr_unittest.TestCase): self.assertEqual(expected_results, dst.data()) def test_003(self): - src_data = [0x11,] + src_data = [0x11, ] expected_results = [4, 2] src = blocks.vector_source_b(src_data, False) op = blocks.packed_to_unpacked_bb(3, gr.GR_LSB_FIRST) @@ -62,7 +63,7 @@ class test_packing(gr_unittest.TestCase): self.assertEqual(expected_results, dst.data()) def test_004(self): - src_data = [0x11,] + src_data = [0x11, ] expected_results = [0, 4] src = blocks.vector_source_b(src_data, False) op = blocks.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST) @@ -75,7 +76,7 @@ class test_packing(gr_unittest.TestCase): self.assertEqual(expected_results, dst.data()) def test_005(self): - src_data = [1,0,0,0,0,0,1,0,0,1,0,1,1,0,1,0] + src_data = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0] expected_results = [0x82, 0x5a] src = blocks.vector_source_b(src_data, False) op = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) @@ -88,7 +89,7 @@ class test_packing(gr_unittest.TestCase): self.assertEqual(expected_results, dst.data()) def test_006(self): - src_data = [0,1,0,0,0,0,0,1,0,1,0,1,1,0,1,0] + src_data = [0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0] expected_results = [0x82, 0x5a] src = blocks.vector_source_b(src_data, False) op = blocks.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST) @@ -101,8 +102,8 @@ class test_packing(gr_unittest.TestCase): self.assertEqual(expected_results, dst.data()) def test_007(self): - src_data = [4, 2, 0,0,0] - expected_results = [0x11,] + src_data = [4, 2, 0, 0, 0] + expected_results = [0x11, ] src = blocks.vector_source_b(src_data, False) op = blocks.unpacked_to_packed_bb(3, gr.GR_LSB_FIRST) dst = blocks.vector_sink_b() @@ -114,9 +115,9 @@ class test_packing(gr_unittest.TestCase): self.assertEqual(expected_results, dst.data()) def test_008(self): - src_data = [0, 4, 2,0,0] - expected_results = [0x11,] - src = blocks.vector_source_b(src_data,False) + src_data = [0, 4, 2, 0, 0] + expected_results = [0x11, ] + src = blocks.vector_source_b(src_data, False) op = blocks.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST) dst = blocks.vector_sink_b() @@ -130,7 +131,7 @@ class test_packing(gr_unittest.TestCase): random.seed(0) src_data = [] for i in range(202): - src_data.append((random.randint(0,255))) + src_data.append((random.randint(0, 255))) src_data = src_data expected_results = src_data @@ -149,7 +150,7 @@ class test_packing(gr_unittest.TestCase): random.seed(0) src_data = [] for i in range(56): - src_data.append((random.randint(0,255))) + src_data.append((random.randint(0, 255))) src_data = src_data expected_results = src_data src = blocks.vector_source_b(tuple(src_data), False) @@ -167,10 +168,10 @@ class test_packing(gr_unittest.TestCase): random.seed(0) src_data = [] for i in range(56): - src_data.append((random.randint(0,255))) + src_data.append((random.randint(0, 255))) src_data = src_data expected_results = src_data - src = blocks.vector_source_b(tuple(src_data),False) + src = blocks.vector_source_b(tuple(src_data), False) op1 = blocks.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST) op2 = blocks.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST) dst = blocks.vector_sink_b() @@ -181,13 +182,13 @@ class test_packing(gr_unittest.TestCase): self.assertEqual(expected_results[0:201], dst.data()) - # tests on shorts + def test_100a(self): random.seed(0) src_data = [] for i in range(100): - src_data.append((random.randint(-2**15,2**15-1))) + src_data.append((random.randint(-2**15, 2**15 - 1))) src_data = src_data expected_results = src_data src = blocks.vector_source_s(tuple(src_data), False) @@ -205,7 +206,7 @@ class test_packing(gr_unittest.TestCase): random.seed(0) src_data = [] for i in range(100): - src_data.append((random.randint(-2**15,2**15-1))) + src_data.append((random.randint(-2**15, 2**15 - 1))) src_data = src_data expected_results = src_data src = blocks.vector_source_s(tuple(src_data), False) @@ -223,7 +224,7 @@ class test_packing(gr_unittest.TestCase): random.seed(0) src_data = [] for i in range(100): - src_data.append((random.randint(-2**15,2**15-1))) + src_data.append((random.randint(-2**15, 2**15 - 1))) src_data = src_data expected_results = src_data src = blocks.vector_source_s(tuple(src_data), False) @@ -241,7 +242,7 @@ class test_packing(gr_unittest.TestCase): random.seed(0) src_data = [] for i in range(100): - src_data.append((random.randint(-2**15,2**15-1))) + src_data.append((random.randint(-2**15, 2**15 - 1))) src_data = src_data expected_results = src_data src = blocks.vector_source_s(tuple(src_data), False) @@ -255,13 +256,13 @@ class test_packing(gr_unittest.TestCase): self.assertEqual(expected_results, dst.data()) - # tests on ints + def test_200a(self): random.seed(0) src_data = [] for i in range(100): - src_data.append((random.randint(-2**31,2**31-1))) + src_data.append((random.randint(-2**31, 2**31 - 1))) src_data = src_data expected_results = src_data src = blocks.vector_source_i(tuple(src_data), False) @@ -279,7 +280,7 @@ class test_packing(gr_unittest.TestCase): random.seed(0) src_data = [] for i in range(100): - src_data.append((random.randint(-2**31,2**31-1))) + src_data.append((random.randint(-2**31, 2**31 - 1))) src_data = src_data expected_results = src_data src = blocks.vector_source_i(tuple(src_data), False) @@ -297,7 +298,7 @@ class test_packing(gr_unittest.TestCase): random.seed(0) src_data = [] for i in range(100): - src_data.append((random.randint(-2**31,2**31-1))) + src_data.append((random.randint(-2**31, 2**31 - 1))) src_data = src_data expected_results = src_data src = blocks.vector_source_i(tuple(src_data), False) @@ -315,7 +316,7 @@ class test_packing(gr_unittest.TestCase): random.seed(0) src_data = [] for i in range(100): - src_data.append((random.randint(-2**31,2**31-1))) + src_data.append((random.randint(-2**31, 2**31 - 1))) src_data = src_data expected_results = src_data src = blocks.vector_source_i(tuple(src_data), False) @@ -329,6 +330,6 @@ class test_packing(gr_unittest.TestCase): self.assertEqual(expected_results, dst.data()) -if __name__ == '__main__': - gr_unittest.run(test_packing) +if __name__ == '__main__': + gr_unittest.run(test_packing) diff --git a/gr-blocks/python/blocks/qa_patterned_interleaver.py b/gr-blocks/python/blocks/qa_patterned_interleaver.py index 02790eaafc..bc032c5203 100644 --- a/gr-blocks/python/blocks/qa_patterned_interleaver.py +++ b/gr-blocks/python/blocks/qa_patterned_interleaver.py @@ -13,30 +13,32 @@ from gnuradio import gr, gr_unittest, blocks import math + class test_patterned_interleaver (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_000(self): - dst_data = [0,0,1,2,0,2,1,0]; - src0 = blocks.vector_source_f(200*[0]) - src1 = blocks.vector_source_f(200*[1]) - src2 = blocks.vector_source_f(200*[2]) + dst_data = [0, 0, 1, 2, 0, 2, 1, 0] + src0 = blocks.vector_source_f(200 * [0]) + src1 = blocks.vector_source_f(200 * [1]) + src2 = blocks.vector_source_f(200 * [2]) itg = blocks.patterned_interleaver(gr.sizeof_float, dst_data) dst = blocks.vector_sink_f() - head = blocks.head(gr.sizeof_float, 8); + head = blocks.head(gr.sizeof_float, 8) - self.tb.connect( src0, (itg,0) ); - self.tb.connect( src1, (itg,1) ); - self.tb.connect( src2, (itg,2) ); - self.tb.connect( itg, head, dst ); + self.tb.connect(src0, (itg, 0)) + self.tb.connect(src1, (itg, 1)) + self.tb.connect(src2, (itg, 2)) + self.tb.connect(itg, head, dst) self.tb.run() self.assertEqual(list(dst_data), list(dst.data())) + if __name__ == '__main__': gr_unittest.run(test_patterned_interleaver) diff --git a/gr-blocks/python/blocks/qa_pdu.py b/gr-blocks/python/blocks/qa_pdu.py index 97d9854c55..e3d0aad8e2 100644 --- a/gr-blocks/python/blocks/qa_pdu.py +++ b/gr-blocks/python/blocks/qa_pdu.py @@ -14,6 +14,7 @@ import time from gnuradio import gr, gr_unittest, blocks import pmt + class test_pdu(gr_unittest.TestCase): def setUp(self): @@ -37,7 +38,8 @@ class test_pdu(gr_unittest.TestCase): # Test that the right number of ports exist. pi = snk3.message_ports_in() po = snk3.message_ports_out() - self.assertEqual(pmt.length(pi), 1) #system port is defined automatically + # system port is defined automatically + self.assertEqual(pmt.length(pi), 1) self.assertEqual(pmt.length(po), 1) self.tb.connect(src, snk) @@ -47,12 +49,13 @@ class test_pdu(gr_unittest.TestCase): # make our reference and message pmts port = pmt.intern("pdus") - msg = pmt.cons( pmt.PMT_NIL, pmt.make_u8vector(16, 0xFF)) + msg = pmt.cons(pmt.PMT_NIL, pmt.make_u8vector(16, 0xFF)) # post the message src.to_basic_block()._post(port, msg) - src.to_basic_block()._post(pmt.intern("system"), - pmt.cons(pmt.intern("done"), pmt.from_long(1))) + src.to_basic_block()._post( + pmt.intern("system"), pmt.cons( + pmt.intern("done"), pmt.from_long(1))) self.tb.start() self.tb.wait() @@ -64,19 +67,19 @@ class test_pdu(gr_unittest.TestCase): # Convert the message PMT as a pair into its vector result_msg = dbg.get_message(0) msg_vec = pmt.cdr(result_msg) - #pmt.print(msg_vec) + # pmt.print(msg_vec) # Convert the PMT vector into a Python list msg_data = [] for i in range(16): msg_data.append(pmt.u8vector_ref(msg_vec, i)) - actual_data = 16*[0xFF,] + actual_data = 16 * [0xFF, ] self.assertEqual(actual_data, list(result_data)) self.assertEqual(actual_data, msg_data) def test_001(self): - #Test the overflow buffer in pdu_to_tagged_stream + # Test the overflow buffer in pdu_to_tagged_stream src_data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0] src = blocks.pdu_to_tagged_stream(blocks.float_t) snk = blocks.vector_sink_f() @@ -84,16 +87,16 @@ class test_pdu(gr_unittest.TestCase): self.tb.connect(src, snk) port = pmt.intern("pdus") - msg = pmt.cons( pmt.PMT_NIL, pmt.init_f32vector(10, src_data)) + msg = pmt.cons(pmt.PMT_NIL, pmt.init_f32vector(10, src_data)) src.to_basic_block()._post(port, msg) - src.to_basic_block()._post(pmt.intern("system"), - pmt.cons(pmt.intern("done"), pmt.from_long(1))) + src.to_basic_block()._post( + pmt.intern("system"), pmt.cons( + pmt.intern("done"), pmt.from_long(1))) self.tb.start() self.tb.wait() - self.assertEqual(src_data, list(snk.data()) ) - + self.assertEqual(src_data, list(snk.data())) def test_002_tags_plus_data(self): packet_len = 16 @@ -103,11 +106,15 @@ class test_pdu(gr_unittest.TestCase): tag1.key = pmt.string_to_symbol('spam') tag1.value = pmt.from_long(23) tag2 = gr.tag_t() - tag2.offset = 10 # Must be < packet_len + tag2.offset = 10 # Must be < packet_len tag2.key = pmt.string_to_symbol('eggs') tag2.value = pmt.from_long(42) src = blocks.vector_source_f(src_data, tags=(tag1, tag2)) - s2ts = blocks.stream_to_tagged_stream(gr.sizeof_float, vlen=1, packet_len=packet_len, len_tag_key="packet_len") + s2ts = blocks.stream_to_tagged_stream( + gr.sizeof_float, + vlen=1, + packet_len=packet_len, + len_tag_key="packet_len") ts2pdu = blocks.tagged_stream_to_pdu(blocks.float_t, "packet_len") dbg = blocks.message_debug() self.tb.connect(src, s2ts, ts2pdu) @@ -116,7 +123,7 @@ class test_pdu(gr_unittest.TestCase): self.tb.wait() result_msg = dbg.get_message(0) metadata = pmt.to_python(pmt.car(result_msg)) - vector = pmt.f32vector_elements(pmt.cdr(result_msg)) + vector = pmt.f32vector_elements(pmt.cdr(result_msg)) self.assertEqual(metadata, {'eggs': 42, 'spam': 23}) self.assertFloatTuplesAlmostEqual(tuple(vector), src_data) diff --git a/gr-blocks/python/blocks/qa_peak_detector.py b/gr-blocks/python/blocks/qa_peak_detector.py index 297e6cc040..1fe4663e6b 100644 --- a/gr-blocks/python/blocks/qa_peak_detector.py +++ b/gr-blocks/python/blocks/qa_peak_detector.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_peak_detector(gr_unittest.TestCase): def setUp(self): @@ -82,5 +83,6 @@ class test_peak_detector(gr_unittest.TestCase): self.assertEqual(expected_result, dst_data) + if __name__ == '__main__': gr_unittest.run(test_peak_detector) diff --git a/gr-blocks/python/blocks/qa_peak_detector2.py b/gr-blocks/python/blocks/qa_peak_detector2.py index fbbca1d56d..ff6323bb0e 100644 --- a/gr-blocks/python/blocks/qa_peak_detector2.py +++ b/gr-blocks/python/blocks/qa_peak_detector2.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_peak_detector2(gr_unittest.TestCase): def setUp(self): @@ -20,16 +21,15 @@ class test_peak_detector2(gr_unittest.TestCase): self.tb = None def test_peak1(self): - #print "\n\nTEST 1" + # print "\n\nTEST 1" tb = self.tb - n=10 + n = 10 data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,]+n*[0,] + 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, ] + n * [0, ] expected_result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]+n*[0,] - + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + n * [0, ] src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb(7.0, 25, 0.001) @@ -44,19 +44,19 @@ class test_peak_detector2(gr_unittest.TestCase): self.assertEqual(expected_result, dst_data) def test_peak2(self): - #print "\n\nTEST 2" + # print "\n\nTEST 2" tb = self.tb - n=10 + n = 10 data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,]+n*[0,] + 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, ] + n * [0, ] expected_result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]+n*[0,] - + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + n * [0, ] src = blocks.vector_source_f(data, False) - regen = blocks.peak_detector2_fb(7.0, 1000, 0.001) # called with a LONG window + regen = blocks.peak_detector2_fb( + 7.0, 1000, 0.001) # called with a LONG window dst = blocks.vector_sink_b() tb.connect(src, regen) @@ -65,20 +65,19 @@ class test_peak_detector2(gr_unittest.TestCase): dst_data = dst.data() - # here we know that the block will terminate prematurely, so we compare only part of the expected_result + # here we know that the block will terminate prematurely, so we compare + # only part of the expected_result self.assertEqual(expected_result[0:len(dst_data)], dst_data) - def test_peak3(self): - #print "\n\nTEST 3" + # print "\n\nTEST 3" tb = self.tb l = 8100 m = 100 n = 10 - data = l*[0,]+ [10,]+ m*[0,]+[100,]+ n*[0,] - expected_result = l*[0,]+ [0,]+ m*[0,]+[1,]+ n*[0,] - + data = l * [0, ] + [10, ] + m * [0, ] + [100, ] + n * [0, ] + expected_result = l * [0, ] + [0, ] + m * [0, ] + [1, ] + n * [0, ] src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb(7.0, 105, 0.001) @@ -92,17 +91,15 @@ class test_peak_detector2(gr_unittest.TestCase): self.assertEqual(expected_result, dst_data) - def test_peak4(self): - #print "\n\nTEST 4" + # print "\n\nTEST 4" tb = self.tb l = 8100 m = 100 n = 10 - data = l*[0,]+ [10,]+ m*[0,]+[100,]+ n*[0,] - expected_result = l*[0,]+ [0,]+ m*[0,]+[1,]+ n*[0,] - + data = l * [0, ] + [10, ] + m * [0, ] + [100, ] + n * [0, ] + expected_result = l * [0, ] + [0, ] + m * [0, ] + [1, ] + n * [0, ] src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb(7.0, 150, 0.001) @@ -114,7 +111,8 @@ class test_peak_detector2(gr_unittest.TestCase): dst_data = dst.data() - # here we know that the block will terminate prematurely, so we compare only part of the expected_result + # here we know that the block will terminate prematurely, so we compare + # only part of the expected_result self.assertEqual(expected_result[0:len(dst_data)], dst_data) diff --git a/gr-blocks/python/blocks/qa_pipe_fittings.py b/gr-blocks/python/blocks/qa_pipe_fittings.py index 6c0d799f40..db91b45a7e 100644 --- a/gr-blocks/python/blocks/qa_pipe_fittings.py +++ b/gr-blocks/python/blocks/qa_pipe_fittings.py @@ -11,10 +11,11 @@ from gnuradio import gr, gr_unittest, blocks + def calc_expected_result(src_data, n): assert (len(src_data) % n) == 0 result = [list() for x in range(n)] - #print "len(result) =", len(result) + # print "len(result) =", len(result) for i in range(len(src_data)): (result[i % n]).append(src_data[i]) return result @@ -23,7 +24,7 @@ def calc_expected_result(src_data, n): class test_pipe_fittings(gr_unittest.TestCase): def setUp(self): - self.tb = gr.top_block () + self.tb = gr.top_block() def tearDown(self): self.tb = None @@ -37,7 +38,7 @@ class test_pipe_fittings(gr_unittest.TestCase): src_data = list(range(src_len)) expected_results = calc_expected_result(src_data, n) - #print "expected results: ", expected_results + # print "expected results: ", expected_results src = blocks.vector_source_i(src_data) op = blocks.stream_to_streams(gr.sizeof_int, n) self.tb.connect(src, op) @@ -77,7 +78,7 @@ class test_pipe_fittings(gr_unittest.TestCase): def test_003(self): - #Test streams_to_vector (using stream_to_streams & vector_to_stream). + # Test streams_to_vector (using stream_to_streams & vector_to_stream). n = 8 src_len = n * 8 @@ -100,7 +101,7 @@ class test_pipe_fittings(gr_unittest.TestCase): def test_004(self): - #Test vector_to_streams. + # Test vector_to_streams. n = 8 src_len = n * 8 diff --git a/gr-blocks/python/blocks/qa_plateau_detector_fb.py b/gr-blocks/python/blocks/qa_plateau_detector_fb.py index 6fcabdb8b2..c14022caf8 100644 --- a/gr-blocks/python/blocks/qa_plateau_detector_fb.py +++ b/gr-blocks/python/blocks/qa_plateau_detector_fb.py @@ -11,22 +11,24 @@ from gnuradio import gr, gr_unittest, blocks + class qa_plateau_detector_fb (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_001_t (self): + def test_001_t(self): # | Spur spike 1 | Plateau | Spur spike 2 - test_signal = [0, 1, .2, .4, .6, .8, 1, 1, 1, 1, 1, .8, .6, .4, 1, 0] - expected_sig = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0] + test_signal = [0, 1, .2, .4, .6, .8, 1, 1, 1, 1, 1, .8, .6, .4, 1, 0] + expected_sig = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0] # | Center of Plateau sink = blocks.vector_sink_b() - self.tb.connect(blocks.vector_source_f(test_signal), blocks.plateau_detector_fb(5), sink) - self.tb.run () + self.tb.connect(blocks.vector_source_f(test_signal), + blocks.plateau_detector_fb(5), sink) + self.tb.run() self.assertEqual(expected_sig, sink.data()) diff --git a/gr-blocks/python/blocks/qa_probe_signal.py b/gr-blocks/python/blocks/qa_probe_signal.py index 64df060441..712a3519fe 100644 --- a/gr-blocks/python/blocks/qa_probe_signal.py +++ b/gr-blocks/python/blocks/qa_probe_signal.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_probe_signal(gr_unittest.TestCase): def setUp(self): @@ -35,7 +36,7 @@ class test_probe_signal(gr_unittest.TestCase): def test_002(self): vector_length = 10 repeats = 10 - value = [0.5+i for i in range(0, vector_length)] + value = [0.5 + i for i in range(0, vector_length)] src_data = value * repeats src = blocks.vector_source_f(src_data) @@ -48,5 +49,6 @@ class test_probe_signal(gr_unittest.TestCase): self.assertEqual(len(output), vector_length) self.assertAlmostEqual(value[3], output[3], places=6) + if __name__ == '__main__': gr_unittest.run(test_probe_signal) diff --git a/gr-blocks/python/blocks/qa_python_message_passing.py b/gr-blocks/python/blocks/qa_python_message_passing.py index e5b0bc6d9f..d36145793a 100644 --- a/gr-blocks/python/blocks/qa_python_message_passing.py +++ b/gr-blocks/python/blocks/qa_python_message_passing.py @@ -15,20 +15,21 @@ import numpy import time # Simple block to generate messages + + class message_generator(gr.sync_block): def __init__(self, msg_list, msg_interval): gr.sync_block.__init__( self, - name = "message generator", - in_sig = [numpy.float32], - out_sig = None + name="message generator", + in_sig=[numpy.float32], + out_sig=None ) self.msg_list = msg_list self.msg_interval = msg_interval self.msg_ctr = 0 self.message_port_register_out(pmt.intern('out_port')) - def work(self, input_items, output_items): inLen = len(input_items[0]) while self.msg_ctr < len(self.msg_list) and \ @@ -40,13 +41,15 @@ class message_generator(gr.sync_block): return inLen # Simple block to consume messages + + class message_consumer(gr.sync_block): def __init__(self): gr.sync_block.__init__( self, - name = "message consumer", - in_sig = None, - out_sig = None + name="message consumer", + in_sig=None, + out_sig=None ) self.msg_list = [] self.message_port_register_in(pmt.intern('in_port')) @@ -57,6 +60,7 @@ class message_consumer(gr.sync_block): # Create a new PMT from long value and put in list self.msg_list.append(pmt.from_long(pmt.to_long(msg))) + class test_python_message_passing(gr_unittest.TestCase): def setUp(self): @@ -74,7 +78,7 @@ class test_python_message_passing(gr_unittest.TestCase): # Create vector source with dummy data to trigger messages src_data = [] - for i in range(num_msgs*msg_interval): + for i in range(num_msgs * msg_interval): src_data.append(float(i)) src = blocks.vector_source_f(src_data, False) msg_gen = message_generator(msg_list, msg_interval) @@ -87,8 +91,13 @@ class test_python_message_passing(gr_unittest.TestCase): self.tb.msg_connect(msg_gen, 'out_port', msg_cons, 'in_port') # Verify that the messgae port query functions work - self.assertEqual(pmt.to_python(msg_gen.message_ports_out())[0], 'out_port') - self.assertEqual('in_port' in pmt.to_python(msg_cons.message_ports_in()), True) + self.assertEqual( + pmt.to_python( + msg_gen.message_ports_out())[0], + 'out_port') + self.assertEqual( + 'in_port' in pmt.to_python( + msg_cons.message_ports_in()), True) # Run to verify message passing self.tb.run() @@ -98,5 +107,6 @@ class test_python_message_passing(gr_unittest.TestCase): for i in range(num_msgs): self.assertTrue(pmt.equal(msg_list[i], msg_cons.msg_list[i])) + if __name__ == '__main__': gr_unittest.run(test_python_message_passing) diff --git a/gr-blocks/python/blocks/qa_regenerate.py b/gr-blocks/python/blocks/qa_regenerate.py index f5e92c2dc1..d8146abd71 100644 --- a/gr-blocks/python/blocks/qa_regenerate.py +++ b/gr-blocks/python/blocks/qa_regenerate.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_regenerate(gr_unittest.TestCase): def setUp(self): @@ -26,10 +27,50 @@ class test_regenerate(gr_unittest.TestCase): 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] - expected_result = [0, 0, 0, - 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] - + expected_result = [ + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0] src = blocks.vector_source_b(data, False) regen = blocks.regenerate_bb(5, 2) @@ -46,20 +87,20 @@ class test_regenerate(gr_unittest.TestCase): def test_regen2(self): tb = self.tb - data = 200*[0,] + data = 200 * [0, ] data[9] = 1 data[99] = 1 - expected_result = 200*[0,] - expected_result[9] = 1 - expected_result[19] = 1 - expected_result[29] = 1 - expected_result[39] = 1 + expected_result = 200 * [0, ] + expected_result[9] = 1 + expected_result[19] = 1 + expected_result[29] = 1 + expected_result[39] = 1 - expected_result[99] = 1 - expected_result[109] = 1 - expected_result[119] = 1 - expected_result[129] = 1 + expected_result[99] = 1 + expected_result[109] = 1 + expected_result[119] = 1 + expected_result[129] = 1 src = blocks.vector_source_b(data, False) regen = blocks.regenerate_bb(10, 3) @@ -67,7 +108,7 @@ class test_regenerate(gr_unittest.TestCase): tb.connect(src, regen) tb.connect(regen, dst) - tb.run () + tb.run() dst_data = dst.data() diff --git a/gr-blocks/python/blocks/qa_repack_bits_bb.py b/gr-blocks/python/blocks/qa_repack_bits_bb.py index 129a6795fd..8f41116a2a 100644 --- a/gr-blocks/python/blocks/qa_repack_bits_bb.py +++ b/gr-blocks/python/blocks/qa_repack_bits_bb.py @@ -13,17 +13,18 @@ import random from gnuradio import gr, gr_unittest, blocks import pmt + class qa_repack_bits_bb (gr_unittest.TestCase): - def setUp (self): + def setUp(self): random.seed(0) - self.tb = gr.top_block () + self.tb = gr.top_block() self.tsb_key = "length" - def tearDown (self): + def tearDown(self): self.tb = None - def test_001_simple (self): + def test_001_simple(self): """ Very simple test, 2 bits -> 1 """ src_data = [0b11, 0b01, 0b10] expected_data = [0b1, 0b1, 0b1, 0b0, 0b0, 0b1] @@ -33,10 +34,10 @@ class qa_repack_bits_bb (gr_unittest.TestCase): repack = blocks.repack_bits_bb(k, l) sink = blocks.vector_sink_b() self.tb.connect(src, repack, sink) - self.tb.run () + self.tb.run() self.assertEqual(sink.data(), expected_data) - def test_001_simple_msb (self): + def test_001_simple_msb(self): """ Very simple test, 2 bits -> 1 with MSB set """ src_data = [0b11, 0b01, 0b10] expected_data = [0b1, 0b1, 0b0, 0b1, 0b1, 0b0] @@ -46,51 +47,51 @@ class qa_repack_bits_bb (gr_unittest.TestCase): repack = blocks.repack_bits_bb(k, l, "", False, gr.GR_MSB_FIRST) sink = blocks.vector_sink_b() self.tb.connect(src, repack, sink) - self.tb.run () + self.tb.run() self.assertEqual(sink.data(), expected_data) - def test_002_three (self): + def test_002_three(self): """ 8 -> 3 """ src_data = [0b11111101, 0b11111111, 0b11111111] - expected_data = [0b101,] + [0b111,] * 7 + expected_data = [0b101, ] + [0b111, ] * 7 k = 8 l = 3 src = blocks.vector_source_b(src_data, False, 1) repack = blocks.repack_bits_bb(k, l) sink = blocks.vector_sink_b() self.tb.connect(src, repack, sink) - self.tb.run () + self.tb.run() self.assertEqual(sink.data(), expected_data) - def test_002_three (self): + def test_002_three(self): """ 8 -> 3 """ src_data = [0b11111101, 0b11111111, 0b11111111] - expected_data = [0b101,] + [0b111,] * 7 + expected_data = [0b101, ] + [0b111, ] * 7 k = 8 l = 3 src = blocks.vector_source_b(src_data, False, 1) repack = blocks.repack_bits_bb(k, l) sink = blocks.vector_sink_b() self.tb.connect(src, repack, sink) - self.tb.run () + self.tb.run() self.assertEqual(sink.data(), expected_data) - def test_002_three_msb (self): + def test_002_three_msb(self): """ 8 -> 3 """ src_data = [0b11111101, 0b11111111, 0b11111111] - expected_data = [0b111,] + [0b111,] + [0b011,] + [0b111,] * 5 + expected_data = [0b111, ] + [0b111, ] + [0b011, ] + [0b111, ] * 5 k = 8 l = 3 src = blocks.vector_source_b(src_data, False, 1) repack = blocks.repack_bits_bb(k, l, "", False, gr.GR_MSB_FIRST) sink = blocks.vector_sink_b() self.tb.connect(src, repack, sink) - self.tb.run () + self.tb.run() self.assertEqual(sink.data(), expected_data) - def test_003_lots_of_bytes (self): + def test_003_lots_of_bytes(self): """ Lots and lots of bytes, multiple packer stages """ - src_data = [random.randint(0, 255) for x in range(3*5*7*8 * 10)] + src_data = [random.randint(0, 255) for x in range(3 * 5 * 7 * 8 * 10)] src = blocks.vector_source_b(src_data, False, 1) repack1 = blocks.repack_bits_bb(8, 3) repack2 = blocks.repack_bits_bb(3, 5) @@ -98,12 +99,12 @@ class qa_repack_bits_bb (gr_unittest.TestCase): repack4 = blocks.repack_bits_bb(7, 8) sink = blocks.vector_sink_b() self.tb.connect(src, repack1, repack2, repack3, repack4, sink) - self.tb.run () + self.tb.run() self.assertEqual(sink.data(), src_data) - def test_003_lots_of_bytes_msb (self): + def test_003_lots_of_bytes_msb(self): """ Lots and lots of bytes, multiple packer stages """ - src_data = [random.randint(0, 255) for x in range(3*5*7*8 * 10)] + src_data = [random.randint(0, 255) for x in range(3 * 5 * 7 * 8 * 10)] src = blocks.vector_source_b(src_data, False, 1) repack1 = blocks.repack_bits_bb(8, 3, "", False, gr.GR_MSB_FIRST) repack2 = blocks.repack_bits_bb(3, 5, "", False, gr.GR_MSB_FIRST) @@ -111,13 +112,13 @@ class qa_repack_bits_bb (gr_unittest.TestCase): repack4 = blocks.repack_bits_bb(7, 8, "", False, gr.GR_MSB_FIRST) sink = blocks.vector_sink_b() self.tb.connect(src, repack1, repack2, repack3, repack4, sink) - self.tb.run () + self.tb.run() self.assertEqual(sink.data(), src_data) - def test_004_three_with_tags (self): + def test_004_three_with_tags(self): """ 8 -> 3 """ src_data = [0b11111101, 0b11111111] - expected_data = [0b101,] + [0b111,] * 4 + [0b001,] + expected_data = [0b101, ] + [0b111, ] * 4 + [0b001, ] k = 8 l = 3 src = blocks.vector_source_b(src_data, False, 1) @@ -125,17 +126,20 @@ class qa_repack_bits_bb (gr_unittest.TestCase): sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key) self.tb.connect( src, - blocks.stream_to_tagged_stream(gr.sizeof_char, 1, len(src_data), self.tsb_key), + blocks.stream_to_tagged_stream( + gr.sizeof_char, + 1, + len(src_data), + self.tsb_key), repack, - sink - ) - self.tb.run () + sink) + self.tb.run() self.assertEqual(len(sink.data()), 1) self.assertEqual(sink.data()[0], expected_data) - def test_005_three_with_tags_trailing (self): + def test_005_three_with_tags_trailing(self): """ 3 -> 8, trailing bits """ - src_data = [0b101,] + [0b111,] * 4 + [0b001,] + src_data = [0b101, ] + [0b111, ] * 4 + [0b001, ] expected_data = [0b11111101, 0b11111111] k = 3 l = 8 @@ -144,13 +148,17 @@ class qa_repack_bits_bb (gr_unittest.TestCase): sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key) self.tb.connect( src, - blocks.stream_to_tagged_stream(gr.sizeof_char, 1, len(src_data), self.tsb_key), + blocks.stream_to_tagged_stream( + gr.sizeof_char, + 1, + len(src_data), + self.tsb_key), repack, - sink - ) - self.tb.run () + sink) + self.tb.run() self.assertEqual(len(sink.data()), 1) self.assertEqual(sink.data()[0], expected_data) + if __name__ == '__main__': gr_unittest.run(qa_repack_bits_bb) diff --git a/gr-blocks/python/blocks/qa_repeat.py b/gr-blocks/python/blocks/qa_repeat.py index 1cdd788392..e54aba1037 100644 --- a/gr-blocks/python/blocks/qa_repeat.py +++ b/gr-blocks/python/blocks/qa_repeat.py @@ -11,19 +11,20 @@ from gnuradio import gr, gr_unittest, blocks + class test_repeat (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_001_float(self): - src_data = [n*1.0 for n in range(100)]; + src_data = [n * 1.0 for n in range(100)] dst_data = [] for n in range(100): - dst_data += [1.0*n, 1.0*n, 1.0*n] + dst_data += [1.0 * n, 1.0 * n, 1.0 * n] src = blocks.vector_source_f(src_data) rpt = blocks.repeat(gr.sizeof_float, 3) @@ -32,5 +33,6 @@ class test_repeat (gr_unittest.TestCase): self.tb.run() self.assertFloatTuplesAlmostEqual(dst_data, dst.data(), 6) + if __name__ == '__main__': gr_unittest.run(test_repeat) diff --git a/gr-blocks/python/blocks/qa_rms.py b/gr-blocks/python/blocks/qa_rms.py index 378bedd300..174fdaa153 100644 --- a/gr-blocks/python/blocks/qa_rms.py +++ b/gr-blocks/python/blocks/qa_rms.py @@ -13,17 +13,20 @@ from gnuradio import gr, gr_unittest, blocks import math + def sig_source_f(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [amp*math.cos(2.*math.pi*freq*x) for x in t] + y = [amp * math.cos(2. * math.pi * freq * x) for x in t] return y + def sig_source_c(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [amp*math.cos(2.*math.pi*freq*x) + \ - 1j*amp*math.sin(2.*math.pi*freq*x) for x in t] + y = [amp * math.cos(2. * math.pi * freq * x) + + 1j * amp * math.sin(2. * math.pi * freq * x) for x in t] return y + class test_rms(gr_unittest.TestCase): def setUp(self): @@ -68,5 +71,6 @@ class test_rms(gr_unittest.TestCase): dst_data = dst.data() self.assertAlmostEqual(dst_data[-1], expected_data, 4) + if __name__ == '__main__': gr_unittest.run(test_rms) diff --git a/gr-blocks/python/blocks/qa_sample_and_hold.py b/gr-blocks/python/blocks/qa_sample_and_hold.py index c44915c3bf..59d43ccbf2 100644 --- a/gr-blocks/python/blocks/qa_sample_and_hold.py +++ b/gr-blocks/python/blocks/qa_sample_and_hold.py @@ -12,6 +12,7 @@ import time from gnuradio import gr, gr_unittest, blocks + class test_sample_and_hold(gr_unittest.TestCase): def setUp(self): @@ -21,22 +22,24 @@ class test_sample_and_hold(gr_unittest.TestCase): self.tb = None def test_001(self): - src_data = 10*[0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1] - ctrl_data = 10*[1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0] - expected_result = 10*(0,0,0,0,4,5,6,7,8,9,9,9,9,9,9,9,9,9) + src_data = 10 * [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1] + ctrl_data = 10 * [1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0] + expected_result = 10 * (0, 0, 0, 0, 4, 5, 6, 7, + 8, 9, 9, 9, 9, 9, 9, 9, 9, 9) - src = blocks.vector_source_f(src_data) + src = blocks.vector_source_f(src_data) ctrl = blocks.vector_source_b(ctrl_data) op = blocks.sample_and_hold_ff() dst = blocks.vector_sink_f() - self.tb.connect(src, (op,0)) - self.tb.connect(ctrl, (op,1)) + self.tb.connect(src, (op, 0)) + self.tb.connect(ctrl, (op, 1)) self.tb.connect(op, dst) self.tb.run() result = dst.data() self.assertFloatTuplesAlmostEqual(expected_result, result, places=6) + if __name__ == '__main__': gr_unittest.run(test_sample_and_hold) diff --git a/gr-blocks/python/blocks/qa_selector.py b/gr-blocks/python/blocks/qa_selector.py index c36cfefad5..e19ed22fb1 100644 --- a/gr-blocks/python/blocks/qa_selector.py +++ b/gr-blocks/python/blocks/qa_selector.py @@ -25,57 +25,60 @@ class test_selector(gr_unittest.TestCase): expected_result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] expected_drop = () - num_inputs = 4; num_outputs = 4 - input_index = 1; output_index = 2 + num_inputs = 4 + num_outputs = 4 + input_index = 1 + output_index = 2 op = blocks.selector(gr.sizeof_char, input_index, output_index) src = [] dst = [] for ii in range(num_inputs): - src.append( blocks.vector_source_b(src_data)) - self.tb.connect(src[ii], (op,ii)) + src.append(blocks.vector_source_b(src_data)) + self.tb.connect(src[ii], (op, ii)) for jj in range(num_outputs): dst.append(blocks.vector_sink_b()) - self.tb.connect((op,jj),dst[jj]) + self.tb.connect((op, jj), dst[jj]) - self.tb.run() dst_data = dst[output_index].data() self.assertEqual(expected_result, dst_data) - def test_select_input(self): - num_inputs = 4; num_outputs = 4 - input_index = 1; output_index = 2 + num_inputs = 4 + num_outputs = 4 + input_index = 1 + output_index = 2 op = blocks.selector(gr.sizeof_char, input_index, output_index) src = [] dst = [] for ii in range(num_inputs): - src_data = [ii+1]*10 - src.append( blocks.vector_source_b(src_data)) - self.tb.connect(src[ii], (op,ii)) + src_data = [ii + 1] * 10 + src.append(blocks.vector_source_b(src_data)) + self.tb.connect(src[ii], (op, ii)) for jj in range(num_outputs): dst.append(blocks.vector_sink_b()) - self.tb.connect((op,jj),dst[jj]) + self.tb.connect((op, jj), dst[jj]) - self.tb.run() - expected_result = [input_index+1]*10 + expected_result = [input_index + 1] * 10 dst_data = list(dst[output_index].data()) self.assertEqual(expected_result, dst_data) - + def test_dump(self): - num_inputs = 4; num_outputs = 4 - input_index = 1; output_index = 2 + num_inputs = 4 + num_outputs = 4 + input_index = 1 + output_index = 2 output_not_selected = 3 op = blocks.selector(gr.sizeof_char, input_index, output_index) @@ -83,14 +86,13 @@ class test_selector(gr_unittest.TestCase): src = [] dst = [] for ii in range(num_inputs): - src_data = [ii+1]*10 - src.append( blocks.vector_source_b(src_data)) - self.tb.connect(src[ii], (op,ii)) + src_data = [ii + 1] * 10 + src.append(blocks.vector_source_b(src_data)) + self.tb.connect(src[ii], (op, ii)) for jj in range(num_outputs): dst.append(blocks.vector_sink_b()) - self.tb.connect((op,jj),dst[jj]) + self.tb.connect((op, jj), dst[jj]) - self.tb.run() expected_result = [] @@ -98,12 +100,14 @@ class test_selector(gr_unittest.TestCase): self.assertEqual(expected_result, dst_data) - def test_not_enabled (self): + def test_not_enabled(self): src_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] expected_result = [] - num_inputs = 4; num_outputs = 4 - input_index = 1; output_index = 2 + num_inputs = 4 + num_outputs = 4 + input_index = 1 + output_index = 2 op = blocks.selector(gr.sizeof_char, input_index, output_index) op.set_enabled(False) @@ -111,19 +115,17 @@ class test_selector(gr_unittest.TestCase): src = [] dst = [] for ii in range(num_inputs): - src.append( blocks.vector_source_b(src_data)) - self.tb.connect(src[ii], (op,ii)) + src.append(blocks.vector_source_b(src_data)) + self.tb.connect(src[ii], (op, ii)) for jj in range(num_outputs): dst.append(blocks.vector_sink_b()) - self.tb.connect((op,jj),dst[jj]) + self.tb.connect((op, jj), dst[jj]) - self.tb.run() dst_data = dst[output_index].data() self.assertEqual(expected_result, dst_data) - # These tests cannot be run as set_index can only be called after check_topology is called # def test_set_indices(self): @@ -132,7 +134,6 @@ class test_selector(gr_unittest.TestCase): # op = blocks.selector(gr.sizeof_char, 0, 0) - # src = [] # dst = [] # for ii in range(num_inputs): @@ -145,7 +146,7 @@ class test_selector(gr_unittest.TestCase): # op.set_input_index(input_index) # op.set_output_index(output_index) - + # self.tb.run() # expected_result = [input_index+1]*10 @@ -172,7 +173,6 @@ class test_selector(gr_unittest.TestCase): # dst.append(blocks.vector_sink_b()) # self.tb.connect((op,jj),dst[jj]) - # self.tb.run() # expected_result = [input_index+1]*10 @@ -182,30 +182,39 @@ class test_selector(gr_unittest.TestCase): def test_float_vector(self): - num_inputs = 4; num_outputs = 4 - input_index = 1; output_index = 2 + num_inputs = 4 + num_outputs = 4 + input_index = 1 + output_index = 2 veclen = 3 - op = blocks.selector(gr.sizeof_float*veclen, input_index, output_index) + op = blocks.selector( + gr.sizeof_float * veclen, + input_index, + output_index) src = [] dst = [] for ii in range(num_inputs): - src_data = [float(ii)+1]*10*veclen - src.append( blocks.vector_source_f(src_data, repeat=False, vlen=veclen)) - self.tb.connect(src[ii], (op,ii)) + src_data = [float(ii) + 1] * 10 * veclen + src.append( + blocks.vector_source_f( + src_data, + repeat=False, + vlen=veclen)) + self.tb.connect(src[ii], (op, ii)) for jj in range(num_outputs): dst.append(blocks.vector_sink_f(vlen=veclen)) - self.tb.connect((op,jj),dst[jj]) + self.tb.connect((op, jj), dst[jj]) - self.tb.run() - expected_result = [float(input_index)+1]*10*veclen + expected_result = [float(input_index) + 1] * 10 * veclen dst_data = list(dst[output_index].data()) self.assertEqual(expected_result, dst_data) + if __name__ == '__main__': gr_unittest.run(test_selector) diff --git a/gr-blocks/python/blocks/qa_skiphead.py b/gr-blocks/python/blocks/qa_skiphead.py index 842a36ca0e..1c643cfbd7 100644 --- a/gr-blocks/python/blocks/qa_skiphead.py +++ b/gr-blocks/python/blocks/qa_skiphead.py @@ -120,5 +120,6 @@ class test_skiphead(gr_unittest.TestCase): self.assertEqual(pmt.to_python( dst_tags[0].value), "qux", "Tag value is incorrect") + if __name__ == '__main__': gr_unittest.run(test_skiphead) diff --git a/gr-blocks/python/blocks/qa_socket_pdu.py b/gr-blocks/python/blocks/qa_socket_pdu.py index b591716d7e..16e118dafb 100644 --- a/gr-blocks/python/blocks/qa_socket_pdu.py +++ b/gr-blocks/python/blocks/qa_socket_pdu.py @@ -14,16 +14,17 @@ import random import pmt import time + class qa_socket_pdu (gr_unittest.TestCase): - def setUp (self): + def setUp(self): random.seed(0) - self.tb = gr.top_block () + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_001 (self): + def test_001(self): # Test that blocks can be created and destroyed without hanging port = str(random.Random().randint(0, 30000) + 10000) self.pdu_send = blocks.socket_pdu("UDP_CLIENT", "localhost", port) @@ -31,7 +32,7 @@ class qa_socket_pdu (gr_unittest.TestCase): self.pdu_send = None self.pdu_recv = None - def test_002 (self): + def test_002(self): # Send a PDU through a pair of UDP sockets port = str(random.Random().randint(0, 30000) + 10000) srcdata = (0x64, 0x6f, 0x67, 0x65) @@ -47,7 +48,7 @@ class qa_socket_pdu (gr_unittest.TestCase): self.tb.msg_connect(self.pdu_source, "strobe", self.pdu_send, "pdus") self.tb.msg_connect(self.pdu_recv, "pdus", self.dbg, "store") - self.tb.start () + self.tb.start() time.sleep(1) self.tb.stop() self.tb.wait() @@ -61,10 +62,26 @@ class qa_socket_pdu (gr_unittest.TestCase): msg_data.append(pmt.u8vector_ref(received_data, i)) self.assertEqual(srcdata, tuple(msg_data)) - def test_003 (self): + def test_003(self): # Test that block stops when interacting with streaming interface port = str(random.Random().randint(0, 30000) + 10000) - srcdata = (0x73, 0x75, 0x63, 0x68, 0x74, 0x65, 0x73, 0x74, 0x76, 0x65, 0x72, 0x79, 0x70, 0x61, 0x73, 0x73) + srcdata = ( + 0x73, + 0x75, + 0x63, + 0x68, + 0x74, + 0x65, + 0x73, + 0x74, + 0x76, + 0x65, + 0x72, + 0x79, + 0x70, + 0x61, + 0x73, + 0x73) tag_dict = {"offset": 0} tag_dict["key"] = pmt.intern("len") tag_dict["value"] = pmt.from_long(8) @@ -90,7 +107,7 @@ class qa_socket_pdu (gr_unittest.TestCase): #self.tb.connect(pdu_to_ts, head, sink) self.tb.run() - def test_004 (self): + def test_004(self): # Test that the TCP server can stream PDUs <= the MTU size. port = str(random.Random().randint(0, 30000) + 10000) mtu = 10000 @@ -118,6 +135,6 @@ class qa_socket_pdu (gr_unittest.TestCase): msg_data.append(pmt.u8vector_ref(received_data, i)) self.assertEqual(srcdata, tuple(msg_data)) + if __name__ == '__main__': gr_unittest.run(qa_socket_pdu) - diff --git a/gr-blocks/python/blocks/qa_stream_demux.py b/gr-blocks/python/blocks/qa_stream_demux.py index da9aa46be0..629c35283c 100755 --- a/gr-blocks/python/blocks/qa_stream_demux.py +++ b/gr-blocks/python/blocks/qa_stream_demux.py @@ -26,17 +26,18 @@ from gnuradio import gr, gr_unittest, blocks import pmt import os + class qa_stream_demux(gr_unittest.TestCase): - def setUp (self): + def setUp(self): os.environ['GR_CONF_CONTROLPORT_ON'] = 'False' - self.tb = gr.top_block () + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def help_stream_2ff(self, N, stream_sizes): - v = blocks.vector_source_f(N*[1,] + N*[2,], False) + v = blocks.vector_source_f(N * [1, ] + N * [2, ], False) demux = blocks.stream_demux(gr.sizeof_float, stream_sizes) @@ -44,8 +45,8 @@ class qa_stream_demux(gr_unittest.TestCase): dst1 = blocks.vector_sink_f() self.tb.connect(v, demux) - self.tb.connect((demux,0), dst0) - self.tb.connect((demux,1), dst1) + self.tb.connect((demux, 0), dst0) + self.tb.connect((demux, 1), dst1) self.tb.run() return (dst0.data(), dst1.data()) @@ -61,14 +62,15 @@ class qa_stream_demux(gr_unittest.TestCase): dst1 = blocks.vector_sink_f() self.tb.connect(v, demux) - self.tb.connect((demux,0), dst0) - self.tb.connect((demux,1), dst1) + self.tb.connect((demux, 0), dst0) + self.tb.connect((demux, 1), dst1) self.tb.run() return (dst0.data(), dst1.data()) def help_stream_tag_propagation(self, N, stream_sizes): - src_data = (stream_sizes[0]*[1,] + stream_sizes[1]*[2,] + stream_sizes[2]*[3,]) * N + src_data = (stream_sizes[0] * [1, ] + stream_sizes[1] + * [2, ] + stream_sizes[2] * [3, ]) * N src = blocks.vector_source_f(src_data, False) @@ -88,9 +90,9 @@ class qa_stream_demux(gr_unittest.TestCase): self.tb.connect(tag_stream1, tag_stream2) self.tb.connect(tag_stream2, tag_stream3) self.tb.connect(tag_stream3, demux) - self.tb.connect((demux,0), dst0) - self.tb.connect((demux,1), dst1) - self.tb.connect((demux,2), dst2) + self.tb.connect((demux, 0), dst0) + self.tb.connect((demux, 1), dst1) + self.tb.connect((demux, 2), dst2) self.tb.run() return (dst0, dst1, dst2) @@ -109,25 +111,99 @@ class qa_stream_demux(gr_unittest.TestCase): 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] - self.assertEqual (exp_data0, result_data[0]) - self.assertEqual (exp_data1, result_data[1]) + self.assertEqual(exp_data0, result_data[0]) + self.assertEqual(exp_data1, result_data[1]) def test_stream_ramp_2NN_ff(self): N = 40 stream_sizes = [10, 10] result_data = self.help_stream_ramp_2ff(N, stream_sizes) - exp_data0 = [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, - 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, - 39.0, 38.0, 37.0, 36.0, 35.0, 34.0, 33.0, 32.0, 31.0, 30.0, - 19.0, 18.0, 17.0, 16.0, 15.0, 14.0, 13.0, 12.0, 11.0, 10.0] - exp_data1 = [10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, - 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, - 29.0, 28.0, 27.0, 26.0, 25.0, 24.0, 23.0, 22.0, 21.0, 20.0, - 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0] - - self.assertEqual (exp_data0, result_data[0]) - self.assertEqual (exp_data1, result_data[1]) + exp_data0 = [ + 0.0, + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0, + 9.0, + 20.0, + 21.0, + 22.0, + 23.0, + 24.0, + 25.0, + 26.0, + 27.0, + 28.0, + 29.0, + 39.0, + 38.0, + 37.0, + 36.0, + 35.0, + 34.0, + 33.0, + 32.0, + 31.0, + 30.0, + 19.0, + 18.0, + 17.0, + 16.0, + 15.0, + 14.0, + 13.0, + 12.0, + 11.0, + 10.0] + exp_data1 = [ + 10.0, + 11.0, + 12.0, + 13.0, + 14.0, + 15.0, + 16.0, + 17.0, + 18.0, + 19.0, + 30.0, + 31.0, + 32.0, + 33.0, + 34.0, + 35.0, + 36.0, + 37.0, + 38.0, + 39.0, + 29.0, + 28.0, + 27.0, + 26.0, + 25.0, + 24.0, + 23.0, + 22.0, + 21.0, + 20.0, + 9.0, + 8.0, + 7.0, + 6.0, + 5.0, + 4.0, + 3.0, + 2.0, + 1.0, + 0.0] + + self.assertEqual(exp_data0, result_data[0]) + self.assertEqual(exp_data1, result_data[1]) def test_stream_2NM_ff(self): N = 40 @@ -148,9 +224,8 @@ class qa_stream_demux(gr_unittest.TestCase): 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] - self.assertEqual (exp_data0, result_data[0]) - self.assertEqual (exp_data1, result_data[1]) - + self.assertEqual(exp_data0, result_data[0]) + self.assertEqual(exp_data1, result_data[1]) def test_stream_2MN_ff(self): N = 37 @@ -171,8 +246,8 @@ class qa_stream_demux(gr_unittest.TestCase): 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] - self.assertEqual (exp_data0, result_data[0]) - self.assertEqual (exp_data1, result_data[1]) + self.assertEqual(exp_data0, result_data[0]) + self.assertEqual(exp_data1, result_data[1]) def test_stream_2N0_ff(self): N = 30 @@ -192,8 +267,8 @@ class qa_stream_demux(gr_unittest.TestCase): 2.0, 2.0, 2.0, 2.0] exp_data1 = [] - self.assertEqual (exp_data0, result_data[0]) - self.assertEqual (exp_data1, result_data[1]) + self.assertEqual(exp_data0, result_data[0]) + self.assertEqual(exp_data1, result_data[1]) def test_stream_20N_ff(self): N = 30 @@ -211,82 +286,121 @@ class qa_stream_demux(gr_unittest.TestCase): 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] - self.assertEqual (exp_data0, result_data[0]) - self.assertEqual (exp_data1, result_data[1]) + self.assertEqual(exp_data0, result_data[0]) + self.assertEqual(exp_data1, result_data[1]) def test_largeN_ff(self): stream_sizes = [3, 8191] - r0 = [1.0,] * stream_sizes[0] - r1 = [2.0,] * stream_sizes[1] + r0 = [1.0, ] * stream_sizes[0] + r1 = [2.0, ] * stream_sizes[1] v = blocks.vector_source_f(r0 + r1, repeat=False) demux = blocks.stream_demux(gr.sizeof_float, stream_sizes) dst0 = blocks.vector_sink_f() dst1 = blocks.vector_sink_f() - self.tb.connect (v, demux) - self.tb.connect ((demux,0), dst0) - self.tb.connect ((demux,1), dst1) - self.tb.run () - self.assertEqual (r0, dst0.data()) - self.assertEqual (r1, dst1.data()) + self.tb.connect(v, demux) + self.tb.connect((demux, 0), dst0) + self.tb.connect((demux, 1), dst1) + self.tb.run() + self.assertEqual(r0, dst0.data()) + self.assertEqual(r1, dst1.data()) def test_tag_propagation(self): - N = 10 # Block length - stream_sizes = [1,2,3] + N = 10 # Block length + stream_sizes = [1, 2, 3] - expected_result0 = N*(stream_sizes[0]*[1,]) - expected_result1 = N*(stream_sizes[1]*[2,]) - expected_result2 = N*(stream_sizes[2]*[3,]) + expected_result0 = N * (stream_sizes[0] * [1, ]) + expected_result1 = N * (stream_sizes[1] * [2, ]) + expected_result2 = N * (stream_sizes[2] * [3, ]) # check the data (result0, result1, result2) = self.help_stream_tag_propagation(N, stream_sizes) - self.assertFloatTuplesAlmostEqual(expected_result0, result0.data(), places=6) - self.assertFloatTuplesAlmostEqual(expected_result1, result1.data(), places=6) - self.assertFloatTuplesAlmostEqual(expected_result2, result2.data(), places=6) + self.assertFloatTuplesAlmostEqual( + expected_result0, result0.data(), places=6) + self.assertFloatTuplesAlmostEqual( + expected_result1, result1.data(), places=6) + self.assertFloatTuplesAlmostEqual( + expected_result2, result2.data(), places=6) # check the tags - result0 tags = result0.tags() - expected_tag_offsets_src1 = list(range(0,stream_sizes[0]*N,stream_sizes[0])) - expected_tag_offsets_src2 = list(range(0,stream_sizes[0]*N,stream_sizes[0])) - expected_tag_offsets_src3 = list(range(0,stream_sizes[0]*N,stream_sizes[0])) - tags_src1 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src1'))] - tags_src2 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src2'))] - tags_src3 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src3'))] + expected_tag_offsets_src1 = list( + range(0, stream_sizes[0] * N, stream_sizes[0])) + expected_tag_offsets_src2 = list( + range(0, stream_sizes[0] * N, stream_sizes[0])) + expected_tag_offsets_src3 = list( + range(0, stream_sizes[0] * N, stream_sizes[0])) + tags_src1 = [ + tag for tag in tags if pmt.eq( + tag.key, pmt.intern('src1'))] + tags_src2 = [ + tag for tag in tags if pmt.eq( + tag.key, pmt.intern('src2'))] + tags_src3 = [ + tag for tag in tags if pmt.eq( + tag.key, pmt.intern('src3'))] for i in range(len(expected_tag_offsets_src1)): - self.assertTrue(expected_tag_offsets_src1[i] == tags_src1[i].offset) + self.assertTrue( + expected_tag_offsets_src1[i] == tags_src1[i].offset) for i in range(len(expected_tag_offsets_src2)): - self.assertTrue(expected_tag_offsets_src2[i] == tags_src2[i].offset) + self.assertTrue( + expected_tag_offsets_src2[i] == tags_src2[i].offset) for i in range(len(expected_tag_offsets_src3)): - self.assertTrue(expected_tag_offsets_src3[i] == tags_src3[i].offset) + self.assertTrue( + expected_tag_offsets_src3[i] == tags_src3[i].offset) # check the tags - result1 tags = result1.tags() - expected_tag_offsets_src1 = list(range(0,stream_sizes[1]*N,stream_sizes[0])) - expected_tag_offsets_src2 = list(range(1,stream_sizes[1]*N,stream_sizes[1])) + expected_tag_offsets_src1 = list( + range(0, stream_sizes[1] * N, stream_sizes[0])) + expected_tag_offsets_src2 = list( + range(1, stream_sizes[1] * N, stream_sizes[1])) expected_tag_offsets_src3 = list() - tags_src1 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src1'))] - tags_src2 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src2'))] - tags_src3 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src3'))] + tags_src1 = [ + tag for tag in tags if pmt.eq( + tag.key, pmt.intern('src1'))] + tags_src2 = [ + tag for tag in tags if pmt.eq( + tag.key, pmt.intern('src2'))] + tags_src3 = [ + tag for tag in tags if pmt.eq( + tag.key, pmt.intern('src3'))] for i in range(len(expected_tag_offsets_src1)): - self.assertTrue(expected_tag_offsets_src1[i] == tags_src1[i].offset) + self.assertTrue( + expected_tag_offsets_src1[i] == tags_src1[i].offset) for i in range(len(expected_tag_offsets_src2)): - self.assertTrue(expected_tag_offsets_src2[i] == tags_src2[i].offset) + self.assertTrue( + expected_tag_offsets_src2[i] == tags_src2[i].offset) for i in range(len(expected_tag_offsets_src3)): - self.assertTrue(expected_tag_offsets_src3[i] == tags_src3[i].offset) + self.assertTrue( + expected_tag_offsets_src3[i] == tags_src3[i].offset) # check the tags - result2 tags = result2.tags() - expected_tag_offsets_src1 = list(range(0,stream_sizes[2]*N,stream_sizes[0])) - expected_tag_offsets_src2 = list(range(1,stream_sizes[2]*N,stream_sizes[2])) - expected_tag_offsets_src3 = list(range(0,stream_sizes[2]*N,stream_sizes[2])) - tags_src1 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src1'))] - tags_src2 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src2'))] - tags_src3 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src3'))] + expected_tag_offsets_src1 = list( + range(0, stream_sizes[2] * N, stream_sizes[0])) + expected_tag_offsets_src2 = list( + range(1, stream_sizes[2] * N, stream_sizes[2])) + expected_tag_offsets_src3 = list( + range(0, stream_sizes[2] * N, stream_sizes[2])) + tags_src1 = [ + tag for tag in tags if pmt.eq( + tag.key, pmt.intern('src1'))] + tags_src2 = [ + tag for tag in tags if pmt.eq( + tag.key, pmt.intern('src2'))] + tags_src3 = [ + tag for tag in tags if pmt.eq( + tag.key, pmt.intern('src3'))] for i in range(len(expected_tag_offsets_src1)): - self.assertTrue(expected_tag_offsets_src1[i] == tags_src1[i].offset) + self.assertTrue( + expected_tag_offsets_src1[i] == tags_src1[i].offset) for i in range(len(expected_tag_offsets_src2)): - self.assertTrue(expected_tag_offsets_src2[i] == tags_src2[i].offset) + self.assertTrue( + expected_tag_offsets_src2[i] == tags_src2[i].offset) for i in range(len(expected_tag_offsets_src3)): - self.assertTrue(expected_tag_offsets_src3[i] == tags_src3[i].offset) + self.assertTrue( + expected_tag_offsets_src3[i] == tags_src3[i].offset) + if __name__ == '__main__': gr_unittest.run(qa_stream_demux) diff --git a/gr-blocks/python/blocks/qa_stream_mux.py b/gr-blocks/python/blocks/qa_stream_mux.py index 20d1376eac..4c935245db 100644 --- a/gr-blocks/python/blocks/qa_stream_mux.py +++ b/gr-blocks/python/blocks/qa_stream_mux.py @@ -13,29 +13,30 @@ from gnuradio import gr, gr_unittest, blocks import pmt import os + class test_stream_mux (gr_unittest.TestCase): - def setUp (self): + def setUp(self): os.environ['GR_CONF_CONTROLPORT_ON'] = 'False' - self.tb = gr.top_block () + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def help_stream_2ff(self, N, stream_sizes): - v0 = blocks.vector_source_f(N*[1,], False) - v1 = blocks.vector_source_f(N*[2,], False) + v0 = blocks.vector_source_f(N * [1, ], False) + v1 = blocks.vector_source_f(N * [2, ], False) mux = blocks.stream_mux(gr.sizeof_float, stream_sizes) - dst = blocks.vector_sink_f () + dst = blocks.vector_sink_f() - self.tb.connect (v0, (mux,0)) - self.tb.connect (v1, (mux,1)) - self.tb.connect (mux, dst) - self.tb.run () + self.tb.connect(v0, (mux, 0)) + self.tb.connect(v1, (mux, 1)) + self.tb.connect(mux, dst) + self.tb.run() - return dst.data () + return dst.data() def help_stream_ramp_2ff(self, N, stream_sizes): r1 = list(range(N)) @@ -47,19 +48,19 @@ class test_stream_mux (gr_unittest.TestCase): mux = blocks.stream_mux(gr.sizeof_float, stream_sizes) - dst = blocks.vector_sink_f () + dst = blocks.vector_sink_f() - self.tb.connect (v0, (mux,0)) - self.tb.connect (v1, (mux,1)) - self.tb.connect (mux, dst) - self.tb.run () + self.tb.connect(v0, (mux, 0)) + self.tb.connect(v1, (mux, 1)) + self.tb.connect(mux, dst) + self.tb.run() - return dst.data () + return dst.data() def help_stream_tag_propagation(self, N, stream_sizes): - src_data1 = stream_sizes[0]*N*[1,] - src_data2 = stream_sizes[1]*N*[2,] - src_data3 = stream_sizes[2]*N*[3,] + src_data1 = stream_sizes[0] * N * [1, ] + src_data2 = stream_sizes[1] * N * [2, ] + src_data3 = stream_sizes[2] * N * [3, ] # stream_mux scheme (3,2,4) src1 = blocks.vector_source_f(src_data1) src2 = blocks.vector_source_f(src_data2) @@ -77,14 +78,13 @@ class test_stream_mux (gr_unittest.TestCase): self.tb.connect(src1, tag_stream1) self.tb.connect(src2, tag_stream2) self.tb.connect(src3, tag_stream3) - self.tb.connect(tag_stream1, (mux,0)) - self.tb.connect(tag_stream2, (mux,1)) - self.tb.connect(tag_stream3, (mux,2)) + self.tb.connect(tag_stream1, (mux, 0)) + self.tb.connect(tag_stream2, (mux, 1)) + self.tb.connect(tag_stream3, (mux, 2)) self.tb.connect(mux, dst) self.tb.run() - return (dst.data (), dst.tags ()) - + return (dst.data(), dst.tags()) def test_stream_2NN_ff(self): N = 40 @@ -99,22 +99,22 @@ class test_stream_mux (gr_unittest.TestCase): 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] - self.assertEqual (exp_data, result_data) + self.assertEqual(exp_data, result_data) def test_stream_ramp_2NN_ff(self): N = 40 stream_sizes = [10, 10] result_data = self.help_stream_ramp_2ff(N, stream_sizes) - exp_data = [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, + exp_data = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 39.0, 38.0, 37.0, 36.0, 35.0, 34.0, 33.0, 32.0, 31.0, 30.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 29.0, 28.0, 27.0, 26.0, 25.0, 24.0, 23.0, 22.0, 21.0, 20.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 19.0, 18.0, 17.0, 16.0, 15.0, 14.0, 13.0, 12.0, 11.0, 10.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, - 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0] - self.assertEqual (exp_data, result_data) + 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0] + self.assertEqual(exp_data, result_data) def test_stream_2NM_ff(self): N = 40 @@ -134,8 +134,7 @@ class test_stream_mux (gr_unittest.TestCase): 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0] - self.assertEqual (exp_data, result_data) - + self.assertEqual(exp_data, result_data) def test_stream_2MN_ff(self): N = 37 @@ -155,7 +154,7 @@ class test_stream_mux (gr_unittest.TestCase): 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0] - self.assertEqual (exp_data, result_data) + self.assertEqual(exp_data, result_data) def test_stream_2N0_ff(self): N = 30 @@ -170,7 +169,7 @@ class test_stream_mux (gr_unittest.TestCase): 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] - self.assertEqual (exp_data, result_data) + self.assertEqual(exp_data, result_data) def test_stream_20N_ff(self): N = 30 @@ -184,49 +183,59 @@ class test_stream_mux (gr_unittest.TestCase): 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] - self.assertEqual (exp_data, result_data) + self.assertEqual(exp_data, result_data) def test_largeN_ff(self): stream_sizes = [3, 8191] - r1 = [1,] * stream_sizes[0] - r2 = [2,] * stream_sizes[1] + r1 = [1, ] * stream_sizes[0] + r2 = [2, ] * stream_sizes[1] v0 = blocks.vector_source_f(r1, repeat=False) v1 = blocks.vector_source_f(r2, repeat=False) mux = blocks.stream_mux(gr.sizeof_float, stream_sizes) - dst = blocks.vector_sink_f () - self.tb.connect (v0, (mux,0)) - self.tb.connect (v1, (mux,1)) - self.tb.connect (mux, dst) - self.tb.run () - self.assertEqual (r1 + r2, dst.data()) + dst = blocks.vector_sink_f() + self.tb.connect(v0, (mux, 0)) + self.tb.connect(v1, (mux, 1)) + self.tb.connect(mux, dst) + self.tb.run() + self.assertEqual(r1 + r2, dst.data()) def test_tag_propagation(self): - N = 10 # Block length - stream_sizes = [1,2,3] + N = 10 # Block length + stream_sizes = [1, 2, 3] - expected_result = N*(stream_sizes[0]*[1,] - +stream_sizes[1]*[2,] - +stream_sizes[2]*[3,]) + expected_result = N * (stream_sizes[0] * [1, ] + + stream_sizes[1] * [2, ] + + stream_sizes[2] * [3, ]) # check the data (result, tags) = self.help_stream_tag_propagation(N, stream_sizes) self.assertFloatTuplesAlmostEqual(expected_result, result, places=6) # check the tags - expected_tag_offsets_src1 = [sum(stream_sizes)*i for i in range(N)] + expected_tag_offsets_src1 = [sum(stream_sizes) * i for i in range(N)] expected_tag_offsets_src2 = [stream_sizes[0] - +sum(stream_sizes)*i for i in range(N)] - expected_tag_offsets_src3 = [stream_sizes[0]+stream_sizes[1] - +sum(stream_sizes)*i for i in range(N)] - tags_src1 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src1'))] - tags_src2 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src2'))] - tags_src3 = [tag for tag in tags if pmt.eq(tag.key, pmt.intern('src3'))] + + sum(stream_sizes) * i for i in range(N)] + expected_tag_offsets_src3 = [stream_sizes[0] + stream_sizes[1] + + sum(stream_sizes) * i for i in range(N)] + tags_src1 = [ + tag for tag in tags if pmt.eq( + tag.key, pmt.intern('src1'))] + tags_src2 = [ + tag for tag in tags if pmt.eq( + tag.key, pmt.intern('src2'))] + tags_src3 = [ + tag for tag in tags if pmt.eq( + tag.key, pmt.intern('src3'))] for i in range(len(expected_tag_offsets_src1)): - self.assertTrue(expected_tag_offsets_src1[i] == tags_src1[i].offset) + self.assertTrue( + expected_tag_offsets_src1[i] == tags_src1[i].offset) for i in range(len(expected_tag_offsets_src2)): - self.assertTrue(expected_tag_offsets_src2[i] == tags_src2[i].offset) + self.assertTrue( + expected_tag_offsets_src2[i] == tags_src2[i].offset) for i in range(len(expected_tag_offsets_src3)): - self.assertTrue(expected_tag_offsets_src3[i] == tags_src3[i].offset) + self.assertTrue( + expected_tag_offsets_src3[i] == tags_src3[i].offset) + if __name__ == '__main__': gr_unittest.run(test_stream_mux) diff --git a/gr-blocks/python/blocks/qa_stream_to_tagged_stream.py b/gr-blocks/python/blocks/qa_stream_to_tagged_stream.py index 6059c00114..4c8170a202 100644 --- a/gr-blocks/python/blocks/qa_stream_to_tagged_stream.py +++ b/gr-blocks/python/blocks/qa_stream_to_tagged_stream.py @@ -13,30 +13,32 @@ from gnuradio import gr, gr_unittest from gnuradio import blocks + class qa_stream_to_tagged_stream (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_001_t (self): + def test_001_t(self): src_data = [1, ] * 50 packet_len = 10 len_tag_key = 'packet_len' src = blocks.vector_source_f(src_data, False, 1) - tagger = blocks.stream_to_tagged_stream(gr.sizeof_float, 1, packet_len, len_tag_key) + tagger = blocks.stream_to_tagged_stream( + gr.sizeof_float, 1, packet_len, len_tag_key) sink = blocks.vector_sink_f() self.tb.connect(src, tagger, sink) - self.tb.run () + self.tb.run() self.assertEqual(sink.data(), src_data) 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 = [(int(pos), 'packet_len', packet_len) for pos in range(0, 50, 10) ] + expected_tags = [(int(pos), 'packet_len', packet_len) + for pos in range(0, 50, 10)] self.assertEqual(tags, expected_tags) if __name__ == '__main__': gr_unittest.run(qa_stream_to_tagged_stream) - diff --git a/gr-blocks/python/blocks/qa_stretch.py b/gr-blocks/python/blocks/qa_stretch.py index 0a3ca0a105..e48a47901b 100644 --- a/gr-blocks/python/blocks/qa_stretch.py +++ b/gr-blocks/python/blocks/qa_stretch.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_stretch(gr_unittest.TestCase): def setUp(self): @@ -22,12 +23,12 @@ class test_stretch(gr_unittest.TestCase): def test_stretch_01(self): tb = self.tb - data = 10*[1,] + data = 10 * [1, ] data0 = [x / 20.0 for x in data] data1 = [x / 10.0 for x in data] - expected_result0 = 10*[0.05,] - expected_result1 = 10*[0.1,] + expected_result0 = 10 * [0.05, ] + expected_result1 = 10 * [0.1, ] src0 = blocks.vector_source_f(data0, False) src1 = blocks.vector_source_f(data1, False) @@ -37,12 +38,12 @@ class test_stretch(gr_unittest.TestCase): dst0 = blocks.vector_sink_f() dst1 = blocks.vector_sink_f() - tb.connect(src0, (inter,0)) - tb.connect(src1, (inter,1)) + tb.connect(src0, (inter, 0)) + tb.connect(src1, (inter, 1)) tb.connect(inter, op) tb.connect(op, deinter) - tb.connect((deinter,0), dst0) - tb.connect((deinter,1), dst1) + tb.connect((deinter, 0), dst0) + tb.connect((deinter, 1), dst1) tb.run() dst0_data = dst0.data() @@ -51,5 +52,6 @@ class test_stretch(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(expected_result0, dst0_data, 4) self.assertFloatTuplesAlmostEqual(expected_result1, dst1_data, 4) + if __name__ == '__main__': gr_unittest.run(test_stretch) diff --git a/gr-blocks/python/blocks/qa_tag_debug.py b/gr-blocks/python/blocks/qa_tag_debug.py index 960d005644..e6b1146bc6 100644 --- a/gr-blocks/python/blocks/qa_tag_debug.py +++ b/gr-blocks/python/blocks/qa_tag_debug.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_tag_debug(gr_unittest.TestCase): def setUp(self): @@ -28,5 +29,6 @@ class test_tag_debug(gr_unittest.TestCase): self.tb.run() x = op.current_tags() + if __name__ == '__main__': gr_unittest.run(test_tag_debug) diff --git a/gr-blocks/python/blocks/qa_tag_file_sink.py b/gr-blocks/python/blocks/qa_tag_file_sink.py index 2edcbb75c7..255672a40b 100644 --- a/gr-blocks/python/blocks/qa_tag_file_sink.py +++ b/gr-blocks/python/blocks/qa_tag_file_sink.py @@ -10,7 +10,9 @@ from gnuradio import gr, gr_unittest, blocks -import os, struct +import os +import struct + class test_tag_file_sink(gr_unittest.TestCase): @@ -21,14 +23,14 @@ class test_tag_file_sink(gr_unittest.TestCase): self.tb = None def test_001(self): - src_data = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - trg_data = [-1, -1, 1, 1, -1, -1, 1, 1, -1, -1] + src_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + trg_data = [-1, -1, 1, 1, -1, -1, 1, 1, -1, -1] src = blocks.vector_source_i(src_data) trg = blocks.vector_source_s(trg_data) - op = blocks.burst_tagger(gr.sizeof_int) + op = blocks.burst_tagger(gr.sizeof_int) snk = blocks.tagged_file_sink(gr.sizeof_int, 1) - self.tb.connect(src, (op,0)) - self.tb.connect(trg, (op,1)) + self.tb.connect(src, (op, 0)) + self.tb.connect(trg, (op, 1)) self.tb.connect(op, snk) self.tb.run() @@ -56,5 +58,6 @@ class test_tag_file_sink(gr_unittest.TestCase): self.assertEqual(idata0, (3, 4)) self.assertEqual(idata1, (7, 8)) + if __name__ == '__main__': gr_unittest.run(test_tag_file_sink) diff --git a/gr-blocks/python/blocks/qa_tag_gate.py b/gr-blocks/python/blocks/qa_tag_gate.py index 0597ca32f9..179d27cb68 100644 --- a/gr-blocks/python/blocks/qa_tag_gate.py +++ b/gr-blocks/python/blocks/qa_tag_gate.py @@ -15,13 +15,13 @@ import pmt class qa_tag_gate (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_001_t (self): + def test_001_t(self): tag = gr.tag_t() tag.key = pmt.string_to_symbol('key') tag.value = pmt.from_long(42) @@ -30,10 +30,10 @@ class qa_tag_gate (gr_unittest.TestCase): gate = blocks.tag_gate(gr.sizeof_float, False) sink = blocks.vector_sink_f() self.tb.connect(src, gate, sink) - self.tb.run () + self.tb.run() self.assertEqual(len(sink.tags()), 0) - def test_002_t (self): + def test_002_t(self): tags = [] tags.append(gr.tag_t()) tags[0].key = pmt.string_to_symbol('key') @@ -50,13 +50,13 @@ class qa_tag_gate (gr_unittest.TestCase): src = blocks.vector_source_f(range(20), False, 1, tags) gate = blocks.tag_gate(gr.sizeof_float, False) gate.set_single_key("key") - self.assertEqual(gate.single_key(),"key") + self.assertEqual(gate.single_key(), "key") sink = blocks.vector_sink_f() self.tb.connect(src, gate, sink) - self.tb.run () + self.tb.run() self.assertEqual(len(sink.tags()), 1) - def test_003_t (self): + def test_003_t(self): tags = [] tags.append(gr.tag_t()) tags[0].key = pmt.string_to_symbol('key') @@ -75,10 +75,10 @@ class qa_tag_gate (gr_unittest.TestCase): gate.set_single_key("key") sink = blocks.vector_sink_f() self.tb.connect(src, gate, sink) - self.tb.run () + self.tb.run() self.assertEqual(len(sink.tags()), 3) - def test_004_t (self): + def test_004_t(self): tags = [] tags.append(gr.tag_t()) tags[0].key = pmt.string_to_symbol('key') @@ -96,10 +96,10 @@ class qa_tag_gate (gr_unittest.TestCase): gate = blocks.tag_gate(gr.sizeof_float, True) sink = blocks.vector_sink_f() self.tb.connect(src, gate, sink) - self.tb.run () + self.tb.run() self.assertEqual(len(sink.tags()), 3) - def test_005_t (self): + def test_005_t(self): gate = blocks.tag_gate(gr.sizeof_float, True) self.assertEqual(gate.single_key(), "") gate.set_single_key("the_key") @@ -107,6 +107,6 @@ class qa_tag_gate (gr_unittest.TestCase): gate.set_single_key("") self.assertEqual(gate.single_key(), "") + if __name__ == '__main__': gr_unittest.run(qa_tag_gate) - diff --git a/gr-blocks/python/blocks/qa_tag_share.py b/gr-blocks/python/blocks/qa_tag_share.py index 077fa8dee3..3fdb2651c2 100755 --- a/gr-blocks/python/blocks/qa_tag_share.py +++ b/gr-blocks/python/blocks/qa_tag_share.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest from gnuradio import blocks import pmt + class qa_tag_share(gr_unittest.TestCase): def setUp(self): @@ -26,10 +27,10 @@ class qa_tag_share(gr_unittest.TestCase): tag_key = 'in1_tag' tag_value = 0 tag_offset = 0 - in0_value = 1.0+1.0j + in0_value = 1.0 + 1.0j in1_value = 2.717 - in0_data = [in0_value,]*10 - in1_data = [in1_value,]*10 + in0_data = [in0_value, ] * 10 + in1_data = [in1_value, ] * 10 sink_data = in0_data tag = gr.tag_t() @@ -45,8 +46,8 @@ class qa_tag_share(gr_unittest.TestCase): tag_share = blocks.tag_share(gr.sizeof_gr_complex, gr.sizeof_float) sink = blocks.vector_sink_c(1) - self.tb.connect(in0, (tag_share,0)) - self.tb.connect(in1, (tag_share,1)) + self.tb.connect(in0, (tag_share, 0)) + self.tb.connect(in1, (tag_share, 1)) self.tb.connect(tag_share, sink) self.tb.run() diff --git a/gr-blocks/python/blocks/qa_tagged_stream_mux.py b/gr-blocks/python/blocks/qa_tagged_stream_mux.py index 739ffd7bcb..ff95069ab7 100644 --- a/gr-blocks/python/blocks/qa_tagged_stream_mux.py +++ b/gr-blocks/python/blocks/qa_tagged_stream_mux.py @@ -14,6 +14,7 @@ import pmt from gnuradio import gr, gr_unittest, blocks from gnuradio.gr import packet_utils + def make_tag(key, value, offset, srcid=None): tag = gr.tag_t() tag.key = pmt.string_to_symbol(key) @@ -23,6 +24,7 @@ def make_tag(key, value, offset, srcid=None): tag.srcid = pmt.to_pmt(srcid) return tag + class qa_tagged_stream_mux (gr_unittest.TestCase): def setUp(self): @@ -34,25 +36,27 @@ class qa_tagged_stream_mux (gr_unittest.TestCase): def setup_data_tags(self, data): return packet_utils.packets_to_vectors( - data, - self.tsb_key + data, + self.tsb_key ) def test_1(self): packets0 = ( - (0, 1, 2), (5, 6), (10,), (14, 15, 16,) + (0, 1, 2), (5, 6), (10,), (14, 15, 16,) ) packets1 = ( - (3, 4), (7, 8, 9), (11, 12, 13), (17,) + (3, 4), (7, 8, 9), (11, 12, 13), (17,) ) - expected = [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13], [14, 15, 16, 17]] + expected = [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], + [10, 11, 12, 13], [14, 15, 16, 17]] data0, tags0 = self.setup_data_tags(packets0) data1, tags1 = self.setup_data_tags(packets1) tags0.append(make_tag('spam', 42, 4)) tags1.append(make_tag('eggs', 23, 3)) src0 = blocks.vector_source_b(data0, tags=tags0) src1 = blocks.vector_source_b(data1, tags=tags1) - tagged_stream_mux = blocks.tagged_stream_mux(gr.sizeof_char, self.tsb_key) + tagged_stream_mux = blocks.tagged_stream_mux( + gr.sizeof_char, self.tsb_key) snk = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key) self.tb.connect(src0, (tagged_stream_mux, 0)) self.tb.connect(src1, (tagged_stream_mux, 1)) @@ -63,8 +67,8 @@ class qa_tagged_stream_mux (gr_unittest.TestCase): tags = [gr.tag_to_python(x) for x in snk.tags()] tags = sorted([(x.offset, x.key, x.value) for x in tags]) tags_expected = [ - (6, 'spam', 42), - (8, 'eggs', 23), + (6, 'spam', 42), + (8, 'eggs', 23), ] self.assertEqual(tags, tags_expected) @@ -77,21 +81,20 @@ class qa_tagged_stream_mux (gr_unittest.TestCase): packet_len_1 = 3 data1 = list(range(packet_len_1)) mux = blocks.tagged_stream_mux( - gr.sizeof_float, - self.tsb_key, - 1 # Mark port 1 as carrying special tags on the head position + gr.sizeof_float, + self.tsb_key, + 1 # Mark port 1 as carrying special tags on the head position ) sink = blocks.tsb_vector_sink_f(tsb_key=self.tsb_key) + self.tb.connect(blocks.vector_source_f(data0), blocks.stream_to_tagged_stream( + gr.sizeof_float, 1, packet_len_0, self.tsb_key), (mux, 0)) self.tb.connect( - blocks.vector_source_f(data0), - blocks.stream_to_tagged_stream(gr.sizeof_float, 1, packet_len_0, self.tsb_key), - (mux, 0) - ) - self.tb.connect( - blocks.vector_source_f(list(range(packet_len_1)), tags=(make_tag('spam', 'eggs', 0),)), - blocks.stream_to_tagged_stream(gr.sizeof_float, 1, packet_len_1, self.tsb_key), - (mux, 1) - ) + blocks.vector_source_f( + list( + range(packet_len_1)), tags=( + make_tag( + 'spam', 'eggs', 0),)), blocks.stream_to_tagged_stream( + gr.sizeof_float, 1, packet_len_1, self.tsb_key), (mux, 1)) self.tb.connect(mux, sink) self.tb.run() self.assertEqual(len(sink.data()), 1) @@ -105,4 +108,3 @@ class qa_tagged_stream_mux (gr_unittest.TestCase): if __name__ == '__main__': gr_unittest.run(qa_tagged_stream_mux) - diff --git a/gr-blocks/python/blocks/qa_tags_strobe.py b/gr-blocks/python/blocks/qa_tags_strobe.py index a31a97bc5c..fa6285427a 100644 --- a/gr-blocks/python/blocks/qa_tags_strobe.py +++ b/gr-blocks/python/blocks/qa_tags_strobe.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest, blocks import pmt import math + class test_tags_strobe(gr_unittest.TestCase): def setUp(self): @@ -81,5 +82,6 @@ class test_tags_strobe(gr_unittest.TestCase): self.assertEqual(tag.offset, n_expected) n_expected += nsamps + if __name__ == '__main__': gr_unittest.run(test_tags_strobe) diff --git a/gr-blocks/python/blocks/qa_tcp_server_sink.py b/gr-blocks/python/blocks/qa_tcp_server_sink.py index 00593f5574..64bcbf0c2e 100644 --- a/gr-blocks/python/blocks/qa_tcp_server_sink.py +++ b/gr-blocks/python/blocks/qa_tcp_server_sink.py @@ -17,6 +17,7 @@ from time import sleep from threading import Timer from multiprocessing import Process + class test_tcp_sink(gr_unittest.TestCase): def setUp(self): @@ -32,7 +33,7 @@ class test_tcp_sink(gr_unittest.TestCase): dst = blocks.vector_sink_s() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) for t in (0, 0.2): -# wait until server listens + # wait until server listens sleep(t) try: sock.connect((self.addr, self.port)) @@ -42,7 +43,9 @@ class test_tcp_sink(gr_unittest.TestCase): continue break fd = os.dup(sock.fileno()) - self.tb_rcv.connect(blocks.file_descriptor_source(self.itemsize, fd), dst) + self.tb_rcv.connect( + blocks.file_descriptor_source( + self.itemsize, fd), dst) self.tb_rcv.run() self.assertEqual(self.data, dst.data()) @@ -53,12 +56,14 @@ class test_tcp_sink(gr_unittest.TestCase): n_data = 16 self.data = tuple([x for x in range(n_data)]) -# tcp_server_sink blocks until client does not connect, start client process first +# tcp_server_sink blocks until client does not connect, start client +# process first p = Process(target=self._tcp_client) p.start() src = blocks.vector_source_s(self.data, False) - tcp_snd = blocks.tcp_server_sink(self.itemsize, self.addr, self.port, False) + tcp_snd = blocks.tcp_server_sink( + self.itemsize, self.addr, self.port, False) self.tb_snd.connect(src, tcp_snd) self.tb_snd.run() @@ -69,8 +74,8 @@ class test_tcp_sink(gr_unittest.TestCase): def stop_rcv(self): self.timeout = True self.tb_rcv.stop() - #print "tb_rcv stopped by Timer" + # print "tb_rcv stopped by Timer" + if __name__ == '__main__': gr_unittest.run(test_tcp_sink) - diff --git a/gr-blocks/python/blocks/qa_threshold.py b/gr-blocks/python/blocks/qa_threshold.py index 8b9eb7b071..e3064b1ad3 100644 --- a/gr-blocks/python/blocks/qa_threshold.py +++ b/gr-blocks/python/blocks/qa_threshold.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks + class test_threshold(gr_unittest.TestCase): def setUp(self): @@ -38,5 +39,6 @@ class test_threshold(gr_unittest.TestCase): self.assertEqual(expected_result, dst_data) + if __name__ == '__main__': gr_unittest.run(test_threshold) diff --git a/gr-blocks/python/blocks/qa_transcendental.py b/gr-blocks/python/blocks/qa_transcendental.py index deb0d56cc2..95649d0388 100644 --- a/gr-blocks/python/blocks/qa_transcendental.py +++ b/gr-blocks/python/blocks/qa_transcendental.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest, blocks import math + class test_transcendental(gr_unittest.TestCase): def setUp(self): @@ -24,8 +25,8 @@ class test_transcendental(gr_unittest.TestCase): def test_01(self): tb = self.tb - data = 100*[0,] - expected_result = 100*[1,] + data = 100 * [0, ] + expected_result = 100 * [1, ] src = blocks.vector_source_f(data, False) op = blocks.transcendental("cos", "float") @@ -42,8 +43,8 @@ class test_transcendental(gr_unittest.TestCase): def test_02(self): tb = self.tb - data = 100*[3,] - expected_result = 100*[math.log10(3),] + data = 100 * [3, ] + expected_result = 100 * [math.log10(3), ] src = blocks.vector_source_f(data, False) op = blocks.transcendental("log10", "float") @@ -60,8 +61,8 @@ class test_transcendental(gr_unittest.TestCase): def test_03(self): tb = self.tb - data = 100*[3,] - expected_result = 100*[math.tanh(3),] + data = 100 * [3, ] + expected_result = 100 * [math.tanh(3), ] src = blocks.vector_source_f(data, False) op = blocks.transcendental("tanh", "float") @@ -75,5 +76,6 @@ class test_transcendental(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5) + if __name__ == '__main__': gr_unittest.run(test_transcendental) diff --git a/gr-blocks/python/blocks/qa_tsb_vector_sink_X.py b/gr-blocks/python/blocks/qa_tsb_vector_sink_X.py index 291a5054b4..fd382c134c 100644 --- a/gr-blocks/python/blocks/qa_tsb_vector_sink_X.py +++ b/gr-blocks/python/blocks/qa_tsb_vector_sink_X.py @@ -14,16 +14,17 @@ import pmt from gnuradio import gr, gr_unittest from gnuradio import blocks + class qa_tsb_vector_sink (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() self.tsb_key = "tsb" - def tearDown (self): + def tearDown(self): self.tb = None - def test_001_t (self): + def test_001_t(self): packet_len = 4 data = list(range(2 * packet_len)) tag = gr.tag_t() @@ -33,10 +34,13 @@ class qa_tsb_vector_sink (gr_unittest.TestCase): src = blocks.vector_source_f(data, tags=(tag,)) sink = blocks.tsb_vector_sink_f(tsb_key=self.tsb_key) self.tb.connect( - src, - blocks.stream_to_tagged_stream(gr.sizeof_float, 1, packet_len, self.tsb_key), - sink - ) + src, + blocks.stream_to_tagged_stream( + gr.sizeof_float, + 1, + packet_len, + self.tsb_key), + sink) self.tb.run() self.assertEqual([data[0:packet_len], data[packet_len:]], sink.data()) self.assertEqual(len(sink.tags()), 1) diff --git a/gr-blocks/python/blocks/qa_type_conversions.py b/gr-blocks/python/blocks/qa_type_conversions.py index 7f56bdc177..38e1c6c064 100644 --- a/gr-blocks/python/blocks/qa_type_conversions.py +++ b/gr-blocks/python/blocks/qa_type_conversions.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest, blocks from math import sqrt, atan2 + class test_type_conversions(gr_unittest.TestCase): def setUp(self): @@ -52,7 +53,7 @@ class test_type_conversions(gr_unittest.TestCase): self.assertEqual(expected_data, dst.data()) def test_complex_to_interleaved_char(self): - src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + 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_char() @@ -62,7 +63,7 @@ class test_type_conversions(gr_unittest.TestCase): self.assertEqual(expected_data, dst.data()) def test_complex_to_interleaved_short(self): - src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + 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() @@ -72,7 +73,7 @@ class test_type_conversions(gr_unittest.TestCase): self.assertEqual(expected_data, dst.data()) def test_complex_to_float_1(self): - src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + 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_float() @@ -82,7 +83,7 @@ class test_type_conversions(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) def test_complex_to_float_2(self): - src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + src_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j) expected_data1 = [1.0, 3.0, 5.0, 7.0, 9.0] expected_data2 = [2.0, 4.0, 6.0, 8.0, 10.0] src = blocks.vector_source_c(src_data) @@ -97,7 +98,7 @@ class test_type_conversions(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(expected_data2, dst2.data()) def test_complex_to_real(self): - src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + 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() @@ -107,7 +108,7 @@ class test_type_conversions(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) def test_complex_to_imag(self): - src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + src_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j) expected_data = [2.0, 4.0, 6.0, 8.0, 10.0] src = blocks.vector_source_c(src_data) op = blocks.complex_to_imag() @@ -117,7 +118,7 @@ class test_type_conversions(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) def test_complex_to_mag(self): - src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j) + 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() @@ -127,7 +128,7 @@ class test_type_conversions(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 5) def test_complex_to_mag_squared(self): - src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j) + 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() @@ -137,8 +138,9 @@ class test_type_conversions(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(expected_data, dst.data()) def test_complex_to_arg(self): - src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j) - expected_data = [atan2(2, 1), atan2(-4,3), atan2(6, 5), atan2(-8, 7), atan2(10,-9)] + src_data = (1 + 2j, 3 - 4j, 5 + 6j, 7 - 8j, -9 + 10j) + expected_data = [atan2(2, 1), atan2(-4, 3), + atan2(6, 5), atan2(-8, 7), atan2(10, -9)] src = blocks.vector_source_c(src_data) op = blocks.complex_to_arg() dst = blocks.vector_sink_f() @@ -168,7 +170,7 @@ class test_type_conversions(gr_unittest.TestCase): def test_float_to_complex_1(self): src_data = (1.0, 3.0, 5.0, 7.0, 9.0) - expected_data = [1+0j, 3+0j, 5+0j, 7+0j, 9+0j] + expected_data = [1 + 0j, 3 + 0j, 5 + 0j, 7 + 0j, 9 + 0j] src = blocks.vector_source_f(src_data) op = blocks.float_to_complex() dst = blocks.vector_sink_c() @@ -179,7 +181,7 @@ class test_type_conversions(gr_unittest.TestCase): def test_float_to_complex_2(self): src1_data = (1.0, 3.0, 5.0, 7.0, 9.0) src2_data = (2.0, 4.0, 6.0, 8.0, 10.0) - expected_data = [1+2j, 3+4j, 5+6j, 7+8j, 9+10j] + expected_data = [1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j] src1 = blocks.vector_source_f(src1_data) src2 = blocks.vector_source_f(src2_data) op = blocks.float_to_complex() @@ -262,7 +264,7 @@ class test_type_conversions(gr_unittest.TestCase): def test_interleaved_short_to_complex(self): src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - expected_data = [1+2j, 3+4j, 5+6j, 7+8j, 9+10j] + expected_data = [1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j] src = blocks.vector_source_s(src_data) op = blocks.interleaved_short_to_complex() dst = blocks.vector_sink_c() diff --git a/gr-blocks/python/blocks/qa_udp_source_sink.py b/gr-blocks/python/blocks/qa_udp_source_sink.py index 45e53991d1..2e48d0bfae 100644 --- a/gr-blocks/python/blocks/qa_udp_source_sink.py +++ b/gr-blocks/python/blocks/qa_udp_source_sink.py @@ -20,7 +20,7 @@ from threading import Timer, Thread def recv_data(sock, result): while True: - data = sock.recv(4*1000) + data = sock.recv(4 * 1000) if len(data) == 0: break real_data = numpy.frombuffer(data, dtype=numpy.float32) @@ -53,12 +53,10 @@ class test_udp_sink_source(gr_unittest.TestCase): self.tb_snd.run() udp_snd.disconnect() - - udp_snd.connect('localhost', port+1) + udp_snd.connect('localhost', port + 1) src.rewind() self.tb_snd.run() - def test_sink_001(self): port = 65520 @@ -78,7 +76,6 @@ class test_udp_sink_source(gr_unittest.TestCase): udp_snd = blocks.udp_sink(gr.sizeof_float, '127.0.0.1', port) self.tb_snd.connect(src, udp_snd) - self.tb_snd.run() udp_snd.disconnect() t.join() @@ -112,8 +109,6 @@ class test_udp_sink_source(gr_unittest.TestCase): self.assertEqual(expected_result, recv_data) - - def test_003(self): port = 65530 @@ -137,7 +132,7 @@ class test_udp_sink_source(gr_unittest.TestCase): self.tb_snd.run() udp_snd.disconnect() self.timeout = False - q = Timer(2.0,self.stop_rcv) + q = Timer(2.0, self.stop_rcv) q.start() self.tb_rcv.wait() q.cancel() @@ -149,8 +144,8 @@ class test_udp_sink_source(gr_unittest.TestCase): def stop_rcv(self): self.timeout = True self.tb_rcv.stop() - #print "tb_rcv stopped by Timer" + # print "tb_rcv stopped by Timer" + if __name__ == '__main__': gr_unittest.run(test_udp_sink_source) - diff --git a/gr-blocks/python/blocks/qa_unpack_k_bits.py b/gr-blocks/python/blocks/qa_unpack_k_bits.py index aea57a65f6..6f41240830 100644 --- a/gr-blocks/python/blocks/qa_unpack_k_bits.py +++ b/gr-blocks/python/blocks/qa_unpack_k_bits.py @@ -13,19 +13,20 @@ from gnuradio import gr, gr_unittest, blocks import random + class test_unpack(gr_unittest.TestCase): def setUp(self): random.seed(0) - self.tb = gr.top_block () + self.tb = gr.top_block() def tearDown(self): self.tb = None def test_001(self): - src_data = [1,0,1,1,0,1,1,0] - expected_results = [1,0,1,1,0,1,1,0] - src = blocks.vector_source_b(src_data,False) + src_data = [1, 0, 1, 1, 0, 1, 1, 0] + expected_results = [1, 0, 1, 1, 0, 1, 1, 0] + src = blocks.vector_source_b(src_data, False) op = blocks.unpack_k_bits_bb(1) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) @@ -33,15 +34,15 @@ class test_unpack(gr_unittest.TestCase): self.assertEqual(expected_results, dst.data()) def test_002(self): - src_data = [ 2, 3, 0, 1] - expected_results = [1,0,1,1,0,0,0,1] - src = blocks.vector_source_b(src_data,False) + src_data = [2, 3, 0, 1] + expected_results = [1, 0, 1, 1, 0, 0, 0, 1] + src = blocks.vector_source_b(src_data, False) op = blocks.unpack_k_bits_bb(2) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() self.assertEqual(expected_results, dst.data()) -if __name__ == '__main__': - gr_unittest.run(test_unpack) +if __name__ == '__main__': + gr_unittest.run(test_unpack) diff --git a/gr-blocks/python/blocks/qa_vco.py b/gr-blocks/python/blocks/qa_vco.py index 354eb7b42c..7ebdedc8e2 100644 --- a/gr-blocks/python/blocks/qa_vco.py +++ b/gr-blocks/python/blocks/qa_vco.py @@ -12,28 +12,31 @@ from gnuradio import gr, gr_unittest, blocks import math + def sig_source_f(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [amp*math.cos(2.*math.pi*freq*x) for x in t] + y = [amp * math.cos(2. * math.pi * freq * x) for x in t] return y + def sig_source_c(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x) for x in t] + y = [math.cos(2. * math.pi * freq * x) + + 1j * math.sin(2. * math.pi * freq * x) for x in t] return y + class test_vco(gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_001(self): - src_data = 200*[0,] + 200*[0.5,] + 200*[1,] - expected_result = 200*[1,] + \ + src_data = 200 * [0, ] + 200 * [0.5, ] + 200 * [1, ] + expected_result = 200 * [1, ] + \ sig_source_f(1, 0.125, 1, 200) + \ sig_source_f(1, 0.25, 1, 200) @@ -47,10 +50,9 @@ class test_vco(gr_unittest.TestCase): result_data = dst.data() self.assertFloatTuplesAlmostEqual(expected_result, result_data, 5) - def test_002(self): - src_data = 200*[0,] + 200*[0.5,] + 200*[1,] - expected_result = 200*[1,] + \ + src_data = 200 * [0, ] + 200 * [0.5, ] + 200 * [1, ] + expected_result = 200 * [1, ] + \ sig_source_c(1, 0.125, 1, 200) + \ sig_source_c(1, 0.25, 1, 200) @@ -67,4 +69,3 @@ class test_vco(gr_unittest.TestCase): if __name__ == '__main__': gr_unittest.run(test_vco) - diff --git a/gr-blocks/python/blocks/qa_vector_insert.py b/gr-blocks/python/blocks/qa_vector_insert.py index 4c25c1538a..d0be59a81e 100644 --- a/gr-blocks/python/blocks/qa_vector_insert.py +++ b/gr-blocks/python/blocks/qa_vector_insert.py @@ -12,6 +12,7 @@ from gnuradio import gr, gr_unittest, blocks import math + class test_vector_insert(gr_unittest.TestCase): def setUp(self): @@ -24,12 +25,12 @@ class test_vector_insert(gr_unittest.TestCase): src_data = [float(x) for x in range(16)] expected_result = tuple(src_data) - period = 9177; - offset = 0; + period = 9177 + offset = 0 src = blocks.null_source(1) - head = blocks.head(1, 10000000); - ins = blocks.vector_insert_b([1], period, offset); + head = blocks.head(1, 10000000) + ins = blocks.vector_insert_b([1], period, offset) dst = blocks.vector_sink_b() self.tb.connect(src, head, ins, dst) @@ -37,7 +38,7 @@ class test_vector_insert(gr_unittest.TestCase): result_data = dst.data() for i in range(10000): - if(i%period == offset): + if(i % period == offset): self.assertEqual(1, result_data[i]) else: self.assertEqual(0, result_data[i]) @@ -45,10 +46,11 @@ class test_vector_insert(gr_unittest.TestCase): def test_002(self): # insert tags and check their propagation, zero offset period = 11000 offset = 0 - insert = [1.0,] * 1000 + insert = [1.0, ] * 1000 src = blocks.null_source(gr.sizeof_float) - s2ts = blocks.stream_to_tagged_stream(gr.sizeof_float, 1, period-len(insert), "packet") + s2ts = blocks.stream_to_tagged_stream( + gr.sizeof_float, 1, period - len(insert), "packet") head = blocks.head(gr.sizeof_float, 1000000) ins = blocks.vector_insert_f(insert, period, offset) dst = blocks.vector_sink_f() @@ -65,10 +67,11 @@ class test_vector_insert(gr_unittest.TestCase): def test_003(self): # insert tags and check their propagation, non-zero offset period = 11000 offset = 1000 - insert = [1.0,] * 1000 + insert = [1.0, ] * 1000 src = blocks.null_source(gr.sizeof_float) - s2ts = blocks.stream_to_tagged_stream(gr.sizeof_float, 1, period-len(insert), "packet") + s2ts = blocks.stream_to_tagged_stream( + gr.sizeof_float, 1, period - len(insert), "packet") head = blocks.head(gr.sizeof_float, 1000000) ins = blocks.vector_insert_f(insert, period, offset) dst = blocks.vector_sink_f() @@ -86,10 +89,11 @@ class test_vector_insert(gr_unittest.TestCase): period = 11000 offset = 1000 packetlen = 2000 - insert = [1.0,] * 1000 + insert = [1.0, ] * 1000 src = blocks.null_source(gr.sizeof_float) - s2ts = blocks.stream_to_tagged_stream(gr.sizeof_float, 1, packetlen, "packet") + s2ts = blocks.stream_to_tagged_stream( + gr.sizeof_float, 1, packetlen, "packet") head = blocks.head(gr.sizeof_float, 1000000) ins = blocks.vector_insert_f(insert, period, offset) dst = blocks.vector_sink_f() @@ -97,12 +101,25 @@ class test_vector_insert(gr_unittest.TestCase): self.tb.connect(src, s2ts, head, ins, dst) self.tb.run() - expected_result = (0, 2000, 4000, 6000, 8000, 11000, 13000, 15000, 17000, 19000, 22000, 24000, 26000) + expected_result = ( + 0, + 2000, + 4000, + 6000, + 8000, + 11000, + 13000, + 15000, + 17000, + 19000, + 22000, + 24000, + 26000) tags = dst.tags() offsets = [tag.offset for tag in tags] for i in range(len(expected_result)): self.assertTrue(expected_result[i] == offsets[i]) + if __name__ == '__main__': gr_unittest.run(test_vector_insert) - diff --git a/gr-blocks/python/blocks/qa_vector_map.py b/gr-blocks/python/blocks/qa_vector_map.py index e2001537eb..a0c9b6dc3e 100644 --- a/gr-blocks/python/blocks/qa_vector_map.py +++ b/gr-blocks/python/blocks/qa_vector_map.py @@ -12,6 +12,7 @@ from gnuradio import gr, gr_unittest, blocks import math + class test_vector_map(gr_unittest.TestCase): def setUp(self): @@ -25,9 +26,9 @@ class test_vector_map(gr_unittest.TestCase): N = 5 src_data = list(range(0, 20)) expected_result = [] - for i in range(N-1, len(src_data), N): + for i in range(N - 1, len(src_data), N): for j in range(0, N): - expected_result.append(1.0*(i-j)) + expected_result.append(1.0 * (i - j)) mapping = [list(reversed([(0, i) for i in range(0, N)]))] src = blocks.vector_source_f(src_data, False, N) vmap = blocks.vector_map(gr.sizeof_float, (N, ), mapping) @@ -69,13 +70,13 @@ class test_vector_map(gr_unittest.TestCase): expected_D = [1, 11, 2, 12, 3, 13, 4, 14, 5, 15] expected_E = [1, 11, 98, 99, 2, 12, 96, 97, 3, 13, 94, 95, 4, 14, 92, 93, 5, 15, 90, 91] - mapping = [[(0, 0), (1, 0)], # mapping to produce D - [(0, 0), (1, 0), (2, 1), (2, 0)], # mapping to produce E + mapping = [[(0, 0), (1, 0)], # mapping to produce D + [(0, 0), (1, 0), (2, 1), (2, 0)], # mapping to produce E ] srcA = blocks.vector_source_f(A, False, 1) srcB = blocks.vector_source_f(B, False, 1) srcC = blocks.vector_source_f(C, False, 2) - vmap = blocks.vector_map(gr.sizeof_int, (1, 1, 2), mapping) + vmap = blocks.vector_map(gr.sizeof_int, (1, 1, 2), mapping) dstD = blocks.vector_sink_f(2) dstE = blocks.vector_sink_f(4) self.tb.connect(srcA, (vmap, 0)) @@ -87,6 +88,6 @@ class test_vector_map(gr_unittest.TestCase): self.assertEqual(expected_D, dstD.data()) self.assertEqual(expected_E, dstE.data()) + if __name__ == '__main__': gr_unittest.run(test_vector_map) - diff --git a/gr-blocks/python/blocks/qa_vector_sink_source.py b/gr-blocks/python/blocks/qa_vector_sink_source.py index 6a4806e660..9fe604c066 100644 --- a/gr-blocks/python/blocks/qa_vector_sink_source.py +++ b/gr-blocks/python/blocks/qa_vector_sink_source.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest, blocks import pmt import math + def make_tag(key, value, offset, srcid=None): tag = gr.tag_t() tag.key = pmt.string_to_symbol(key) @@ -22,9 +23,11 @@ def make_tag(key, value, offset, srcid=None): tag.srcid = pmt.to_pmt(srcid) return tag + def compare_tags(a, b): return a.offset == b.offset and pmt.equal(a.key, b.key) and \ - pmt.equal(a.value, b.value) and pmt.equal(a.srcid, b.srcid) + pmt.equal(a.value, b.value) and pmt.equal(a.srcid, b.srcid) + class test_vector_sink_source(gr_unittest.TestCase): @@ -64,7 +67,9 @@ class test_vector_sink_source(gr_unittest.TestCase): # Test that we can only make vectors (the I/O type) if the input # vector has sufficient size src_data = [float(x) for x in range(16)] - self.assertRaises(ValueError, lambda : blocks.vector_source_f(src_data, False, 3)) + self.assertRaises( + ValueError, lambda: blocks.vector_source_f( + src_data, False, 3)) def test_004(self): # Test sending and receiving tagged streams @@ -91,10 +96,10 @@ class test_vector_sink_source(gr_unittest.TestCase): expected_result = src_data + src_data src_tags = [make_tag('key', 'val', 0, 'src')] expected_tags = [make_tag('key', 'val', 0, 'src'), - make_tag('key', 'val', length, 'src')] + make_tag('key', 'val', length, 'src')] src = blocks.vector_source_f(src_data, repeat=True, tags=src_tags) - head = blocks.head(gr.sizeof_float, 2*length) + head = blocks.head(gr.sizeof_float, 2 * length) dst = blocks.vector_sink_f() self.tb.connect(src, head, dst) @@ -111,7 +116,7 @@ class test_vector_sink_source(gr_unittest.TestCase): src_data = [float(x) for x in range(16)] expected_result = src_data - src = blocks.vector_source_f((3,1,4)) + src = blocks.vector_source_f((3, 1, 4)) dst = blocks.vector_sink_f() src.set_data(src_data) @@ -138,4 +143,3 @@ class test_vector_sink_source(gr_unittest.TestCase): if __name__ == '__main__': gr_unittest.run(test_vector_sink_source) - diff --git a/gr-blocks/python/blocks/qa_wavfile.py b/gr-blocks/python/blocks/qa_wavfile.py index 0b08ce3290..c62cd703c4 100644 --- a/gr-blocks/python/blocks/qa_wavfile.py +++ b/gr-blocks/python/blocks/qa_wavfile.py @@ -15,10 +15,13 @@ import os from os.path import getsize g_in_file = os.path.join(os.getenv("srcdir"), "test_16bit_1chunk.wav") -g_in_file_normal = os.path.join(os.getenv("srcdir"), "test_16bit_1chunk_normal.wav") +g_in_file_normal = os.path.join( + os.getenv("srcdir"), + "test_16bit_1chunk_normal.wav") g_extra_header_offset = 36 g_extra_header_len = 22 + class test_wavefile(gr_unittest.TestCase): def setUp(self): @@ -32,10 +35,10 @@ class test_wavefile(gr_unittest.TestCase): self.assertEqual(wf.sample_rate(), 8000) def test_002_checkwavcopy(self): - infile = g_in_file + infile = g_in_file outfile = "test_out.wav" - wf_in = blocks.wavfile_source(infile) + wf_in = blocks.wavfile_source(infile) wf_out = blocks.wavfile_sink(outfile, wf_in.channels(), wf_in.sample_rate(), @@ -52,11 +55,14 @@ class test_wavefile(gr_unittest.TestCase): pass with wave.open(outfile, 'rb') as f: pass - except: + except BaseException: raise AssertionError('Invalid WAV file') # we're losing all extra header chunks - self.assertEqual(getsize(infile) - g_extra_header_len, getsize(outfile)) + self.assertEqual( + getsize(infile) - + g_extra_header_len, + getsize(outfile)) with open(infile, 'rb') as f: in_data = bytearray(f.read()) @@ -70,11 +76,12 @@ class test_wavefile(gr_unittest.TestCase): out_data[4:8] = b'\x00\x00\x00\x00' # cut extra header chunks from input file - self.assertEqual(in_data[:g_extra_header_offset] + \ - in_data[g_extra_header_offset + g_extra_header_len:], out_data) + self.assertEqual(in_data[:g_extra_header_offset] + + in_data[g_extra_header_offset + + g_extra_header_len:], out_data) def test_003_checkwav_append_copy(self): - infile = g_in_file_normal + infile = g_in_file_normal outfile = "test_out_append.wav" # 1. Copy input to output @@ -82,7 +89,7 @@ class test_wavefile(gr_unittest.TestCase): copyfile(infile, outfile) # 2. append copy - wf_in = blocks.wavfile_source(infile) + wf_in = blocks.wavfile_source(infile) wf_out = blocks.wavfile_sink(outfile, wf_in.channels(), wf_in.sample_rate(), @@ -94,7 +101,7 @@ class test_wavefile(gr_unittest.TestCase): wf_out.close() # 3. append halved copy - wf_in = blocks.wavfile_source(infile) + wf_in = blocks.wavfile_source(infile) halver = blocks.multiply_const_ff(0.5) wf_out = blocks.wavfile_sink(outfile, wf_in.channels(), @@ -117,22 +124,22 @@ class test_wavefile(gr_unittest.TestCase): with wave.open(outfile, 'rb') as w_out: out_params = w_out.getparams() data_out = wav_read_frames(w_out) - except: + except BaseException: raise AssertionError('Invalid WAV file') # Params must be equal except in size: - expected_params = in_params._replace(nframes=3*in_params.nframes) + expected_params = in_params._replace(nframes=3 * in_params.nframes) self.assertEqual(out_params, expected_params) # Part 1 self.assertEqual(data_in, data_out[:len(data_in)]) # Part 2 - self.assertEqual(data_in, data_out[len(data_in):2*len(data_in)]) + self.assertEqual(data_in, data_out[len(data_in):2 * len(data_in)]) # Part 3 - data_in_halved = [int(round(d/2)) for d in data_in] - self.assertEqual(data_in_halved, data_out[2*len(data_in):]) + data_in_halved = [int(round(d / 2)) for d in data_in] + self.assertEqual(data_in_halved, data_out[2 * len(data_in):]) os.remove(outfile) @@ -140,14 +147,21 @@ class test_wavefile(gr_unittest.TestCase): outfile = "no_file.wav" with self.assertRaisesRegex(RuntimeError, "Can't open WAV file."): - blocks.wavfile_sink(outfile, 1, 44100, blocks.FORMAT_WAV, blocks.FORMAT_PCM_16, True) + blocks.wavfile_sink( + outfile, + 1, + 44100, + blocks.FORMAT_WAV, + blocks.FORMAT_PCM_16, + True) os.remove(outfile) + def wav_read_frames(w): import struct # grouper from itertools recipes. - grouper = lambda iterable, n: list(zip(* ([iter(iterable)] * n) )) + def grouper(iterable, n): return list(zip(* ([iter(iterable)] * n))) assert w.getsampwidth() == 2 # Assume 16 bits return [ struct.unpack('<h', bytes(frame_g))[0] diff --git a/gr-channels/python/channels/qa_channel_model.py b/gr-channels/python/channels/qa_channel_model.py index 6e2434d7e4..88fa5d4a21 100644 --- a/gr-channels/python/channels/qa_channel_model.py +++ b/gr-channels/python/channels/qa_channel_model.py @@ -12,6 +12,7 @@ from gnuradio import gr, gr_unittest, analog, blocks, channels import math + class test_channel_model(gr_unittest.TestCase): def setUp(self): @@ -27,13 +28,13 @@ class test_channel_model(gr_unittest.TestCase): signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1) head = blocks.head(gr.sizeof_gr_complex, N) - op = channels.channel_model(0.0, 0.0, 1.0, [1,], 0) + op = channels.channel_model(0.0, 0.0, 1.0, [1, ], 0) snk = blocks.vector_sink_c() snk1 = blocks.vector_sink_c() op.set_noise_voltage(0.0) op.set_frequency_offset(0.0) - op.set_taps([1,]) + op.set_taps([1, ]) op.set_timing_offset(1.0) self.tb.connect(signal, head, op, snk) @@ -44,5 +45,6 @@ class test_channel_model(gr_unittest.TestCase): exp_data = snk1.data() self.assertComplexTuplesAlmostEqual(exp_data, dst_data, 5) + if __name__ == '__main__': gr_unittest.run(test_channel_model) diff --git a/gr-channels/python/channels/qa_fading_model.py b/gr-channels/python/channels/qa_fading_model.py index 910104c6dd..fcbfcce8e6 100644 --- a/gr-channels/python/channels/qa_fading_model.py +++ b/gr-channels/python/channels/qa_fading_model.py @@ -12,6 +12,7 @@ from gnuradio import gr, gr_unittest, analog, blocks, channels import math + class test_fading_model(gr_unittest.TestCase): def setUp(self): @@ -39,11 +40,12 @@ class test_fading_model(gr_unittest.TestCase): #self.tb.connect(signal, head, op, snk) #self.tb.connect(op, snk1) - #self.tb.run() + # self.tb.run() #dst_data = snk.data() #exp_data = snk1.data() #self.assertComplexTuplesAlmostEqual(exp_data, dst_data, 5) + if __name__ == '__main__': gr_unittest.run(test_fading_model) diff --git a/gr-digital/python/digital/qa_binary_slicer_fb.py b/gr-digital/python/digital/qa_binary_slicer_fb.py index eccaeab6f5..2ad40d1e02 100644 --- a/gr-digital/python/digital/qa_binary_slicer_fb.py +++ b/gr-digital/python/digital/qa_binary_slicer_fb.py @@ -13,6 +13,7 @@ import random from gnuradio import gr, gr_unittest, digital, blocks + class test_binary_slicer_fb(gr_unittest.TestCase): def setUp(self): @@ -23,9 +24,10 @@ class test_binary_slicer_fb(gr_unittest.TestCase): self.tb = None def test_binary_slicer_fb(self): - expected_result = ( 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1) - src_data = (-1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1) - src_data = [s + (1 - random.random()) for s in src_data] # add some noise + expected_result = (0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1) + src_data = (-1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1) + src_data = [s + (1 - random.random()) + for s in src_data] # add some noise src = blocks.vector_source_f(src_data) op = digital.binary_slicer_fb() dst = blocks.vector_sink_b() @@ -35,8 +37,8 @@ class test_binary_slicer_fb(gr_unittest.TestCase): self.tb.run() # run the graph and wait for it to finish actual_result = dst.data() # fetch the contents of the sink - #print "actual result", actual_result - #print "expected result", expected_result + # print "actual result", actual_result + # print "expected result", expected_result self.assertFloatTuplesAlmostEqual(expected_result, actual_result) diff --git a/gr-digital/python/digital/qa_burst_shaper.py b/gr-digital/python/digital/qa_burst_shaper.py index 3fd47195fa..2846617fd7 100644 --- a/gr-digital/python/digital/qa_burst_shaper.py +++ b/gr-digital/python/digital/qa_burst_shaper.py @@ -1,13 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# +# # Copyright 2015 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# from gnuradio import gr, gr_unittest @@ -16,31 +16,35 @@ import pmt import numpy as np import sys + def make_length_tag(offset, length): - return gr.python_to_tag({'offset' : offset, - 'key' : pmt.intern('packet_len'), - 'value' : pmt.from_long(length), - 'srcid' : pmt.intern('qa_burst_shaper')}) + return gr.python_to_tag({'offset': offset, + 'key': pmt.intern('packet_len'), + 'value': pmt.from_long(length), + 'srcid': pmt.intern('qa_burst_shaper')}) + def make_tag(offset, key, value): - return gr.python_to_tag({'offset' : offset, - 'key' : pmt.intern(key), - 'value' : value, - 'srcid' : pmt.intern('qa_burst_shaper')}) + return gr.python_to_tag({'offset': offset, + 'key': pmt.intern(key), + 'value': value, + 'srcid': pmt.intern('qa_burst_shaper')}) + def compare_tags(a, b): return a.offset == b.offset and pmt.equal(a.key, b.key) and \ - pmt.equal(a.value, b.value) + pmt.equal(a.value, b.value) + class qa_burst_shaper (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_ff (self): + def test_ff(self): ''' test_ff: test with float values, even length window, zero padding, and no phasing @@ -49,7 +53,7 @@ class qa_burst_shaper (gr_unittest.TestCase): postpad = 10 length = 20 data = np.ones(length) - window = np.concatenate((-2.0*np.ones(5), -4.0*np.ones(5))) + window = np.concatenate((-2.0 * np.ones(5), -4.0 * np.ones(5))) tags = (make_length_tag(0, length),) expected = np.concatenate((np.zeros(prepad), window[0:5], np.ones(length - len(window)), window[5:10], @@ -62,13 +66,13 @@ class qa_burst_shaper (gr_unittest.TestCase): post_padding=postpad) sink = blocks.vector_sink_f() self.tb.connect(source, shaper, sink) - self.tb.run () + self.tb.run() # checks self.assertFloatTuplesAlmostEqual(sink.data(), expected, 6) self.assertTrue(compare_tags(sink.tags()[0], etag)) - def test_cc (self): + def test_cc(self): ''' test_cc: test with complex values, even length window, zero padding, and no phasing @@ -77,13 +81,13 @@ class qa_burst_shaper (gr_unittest.TestCase): postpad = 10 length = 20 data = np.ones(length, dtype=complex) - window = np.concatenate((-2.0*np.ones(5, dtype=complex), - -4.0*np.ones(5, dtype=complex))) + window = np.concatenate((-2.0 * np.ones(5, dtype=complex), + -4.0 * np.ones(5, dtype=complex))) tags = (make_length_tag(0, length),) expected = np.concatenate((np.zeros(prepad, dtype=complex), window[0:5], np.ones(length - len(window), dtype=complex), window[5:10], np.zeros(postpad, - dtype=complex))) + dtype=complex))) etag = make_length_tag(0, length + prepad + postpad) # flowgraph @@ -92,13 +96,13 @@ class qa_burst_shaper (gr_unittest.TestCase): post_padding=postpad) sink = blocks.vector_sink_c() self.tb.connect(source, shaper, sink) - self.tb.run () + self.tb.run() # checks self.assertComplexTuplesAlmostEqual(sink.data(), expected, 6) self.assertTrue(compare_tags(sink.tags()[0], etag)) - def test_ff_with_phasing (self): + def test_ff_with_phasing(self): ''' test_ff_with_phasing: test with float values, even length window, zero padding, and phasing @@ -107,13 +111,13 @@ class qa_burst_shaper (gr_unittest.TestCase): postpad = 10 length = 20 data = np.ones(length) - window = np.concatenate((-2.0*np.ones(5), -4.0*np.ones(5))) + window = np.concatenate((-2.0 * np.ones(5), -4.0 * np.ones(5))) tags = (make_length_tag(0, length),) phasing = np.zeros(5) for i in range(5): phasing[i] = ((-1.0)**i) - expected = np.concatenate((np.zeros(prepad), phasing*window[0:5], - np.ones(length), phasing*window[5:10], + expected = np.concatenate((np.zeros(prepad), phasing * window[0:5], + np.ones(length), phasing * window[5:10], np.zeros(postpad))) etag = make_length_tag(0, length + prepad + postpad + len(window)) @@ -124,13 +128,13 @@ class qa_burst_shaper (gr_unittest.TestCase): insert_phasing=True) sink = blocks.vector_sink_f() self.tb.connect(source, shaper, sink) - self.tb.run () + self.tb.run() # checks self.assertFloatTuplesAlmostEqual(sink.data(), expected, 6) self.assertTrue(compare_tags(sink.tags()[0], etag)) - def test_cc_with_phasing (self): + def test_cc_with_phasing(self): ''' test_cc_with_phasing: test with complex values, even length window, zero padding, and phasing @@ -139,16 +143,16 @@ class qa_burst_shaper (gr_unittest.TestCase): postpad = 10 length = 20 data = np.ones(length, dtype=complex) - window = np.concatenate((-2.0*np.ones(5, dtype=complex), - -4.0*np.ones(5, dtype=complex))) + window = np.concatenate((-2.0 * np.ones(5, dtype=complex), + -4.0 * np.ones(5, dtype=complex))) tags = (make_length_tag(0, length),) phasing = np.zeros(5, dtype=complex) for i in range(5): phasing[i] = complex((-1.0)**i) expected = np.concatenate((np.zeros(prepad, dtype=complex), - phasing*window[0:5], + phasing * window[0:5], np.ones(length, dtype=complex), - phasing*window[5:10], + phasing * window[5:10], np.zeros(postpad, dtype=complex))) etag = make_length_tag(0, length + prepad + postpad + len(window)) @@ -159,13 +163,13 @@ class qa_burst_shaper (gr_unittest.TestCase): insert_phasing=True) sink = blocks.vector_sink_c() self.tb.connect(source, shaper, sink) - self.tb.run () + self.tb.run() # checks self.assertComplexTuplesAlmostEqual(sink.data(), expected, 6) self.assertTrue(compare_tags(sink.tags()[0], etag)) - def test_odd_window (self): + def test_odd_window(self): ''' test_odd_window: test with odd length window; center sample should be applied at end of up flank and beginning of down flank @@ -174,8 +178,8 @@ class qa_burst_shaper (gr_unittest.TestCase): postpad = 10 length = 20 data = np.ones(length) - window = np.concatenate((-2.0*np.ones(5), -3.0*np.ones(1), - -4.0*np.ones(5))) + window = np.concatenate((-2.0 * np.ones(5), -3.0 * np.ones(1), + -4.0 * np.ones(5))) tags = (make_length_tag(0, length),) expected = np.concatenate((np.zeros(prepad), window[0:6], np.ones(length - len(window) - 1), @@ -188,13 +192,13 @@ class qa_burst_shaper (gr_unittest.TestCase): post_padding=postpad) sink = blocks.vector_sink_f() self.tb.connect(source, shaper, sink) - self.tb.run () + self.tb.run() # checks self.assertFloatTuplesAlmostEqual(sink.data(), expected, 6) self.assertTrue(compare_tags(sink.tags()[0], etag)) - def test_short_burst (self): + def test_short_burst(self): ''' test_short_burst: test with burst length shorter than window length; clips the window up and down flanks to FLOOR(length/2) samples @@ -216,13 +220,13 @@ class qa_burst_shaper (gr_unittest.TestCase): post_padding=postpad) sink = blocks.vector_sink_f() self.tb.connect(source, shaper, sink) - self.tb.run () + self.tb.run() # checks self.assertFloatTuplesAlmostEqual(sink.data(), expected, 6) self.assertTrue(compare_tags(sink.tags()[0], etag)) - def test_consecutive_bursts (self): + def test_consecutive_bursts(self): ''' test_consecutive_bursts: test with consecutive bursts of different lengths @@ -231,14 +235,14 @@ class qa_burst_shaper (gr_unittest.TestCase): postpad = 10 length1 = 15 length2 = 25 - data = np.concatenate((np.ones(length1), -1.0*np.ones(length2))) - window = np.concatenate((-2.0*np.ones(5), -4.0*np.ones(5))) + data = np.concatenate((np.ones(length1), -1.0 * np.ones(length2))) + window = np.concatenate((-2.0 * np.ones(5), -4.0 * np.ones(5))) tags = (make_length_tag(0, length1), make_length_tag(length1, length2)) expected = np.concatenate((np.zeros(prepad), window[0:5], np.ones(length1 - len(window)), window[5:10], - np.zeros(postpad + prepad), -1.0*window[0:5], - -1.0*np.ones(length2 - len(window)), - -1.0*window[5:10], np.zeros(postpad))) + np.zeros(postpad + prepad), -1.0 * window[0:5], + -1.0 * np.ones(length2 - len(window)), + -1.0 * window[5:10], np.zeros(postpad))) etags = (make_length_tag(0, length1 + prepad + postpad), make_length_tag(length1 + prepad + postpad, length2 + prepad + postpad)) @@ -249,14 +253,14 @@ class qa_burst_shaper (gr_unittest.TestCase): post_padding=postpad) sink = blocks.vector_sink_f() self.tb.connect(source, shaper, sink) - self.tb.run () + self.tb.run() # checks self.assertFloatTuplesAlmostEqual(sink.data(), expected, 6) for i in range(len(etags)): self.assertTrue(compare_tags(sink.tags()[i], etags[i])) - def test_tag_gap (self): + def test_tag_gap(self): ''' test_tag_gap: test with gap between tags; should drop samples that are between proper tagged streams @@ -265,18 +269,26 @@ class qa_burst_shaper (gr_unittest.TestCase): postpad = 10 length = 20 gap_len = 5 - data = np.arange(2*length + gap_len, dtype=float) - window = np.concatenate((-2.0*np.ones(5), -4.0*np.ones(5))) - ewindow = window * np.array([1,-1,1,-1,1,1,-1,1,-1,1],dtype=float) + data = np.arange(2 * length + gap_len, dtype=float) + window = np.concatenate((-2.0 * np.ones(5), -4.0 * np.ones(5))) + ewindow = window * \ + np.array([1, -1, 1, -1, 1, 1, -1, 1, -1, 1], dtype=float) tags = (make_length_tag(0, length), make_length_tag(length + gap_len, length)) - expected = np.concatenate((np.zeros(prepad), ewindow[0:5], - np.arange(0, length, dtype=float), - ewindow[5:10], np.zeros(postpad), - np.zeros(prepad), ewindow[0:5], + expected = np.concatenate((np.zeros(prepad), + ewindow[0:5], + np.arange(0, + length, + dtype=float), + ewindow[5:10], + np.zeros(postpad), + np.zeros(prepad), + ewindow[0:5], np.arange(length + gap_len, - 2*length + gap_len, dtype=float), - ewindow[5:10], np.zeros(postpad))) + 2 * length + gap_len, + dtype=float), + ewindow[5:10], + np.zeros(postpad))) burst_len = length + len(window) + prepad + postpad etags = (make_length_tag(0, burst_len), make_length_tag(burst_len, burst_len)) @@ -288,14 +300,14 @@ class qa_burst_shaper (gr_unittest.TestCase): insert_phasing=True) sink = blocks.vector_sink_f() self.tb.connect(source, shaper, sink) - self.tb.run () + self.tb.run() # checks self.assertFloatTuplesAlmostEqual(sink.data(), expected, 6) for i in range(len(etags)): self.assertTrue(compare_tags(sink.tags()[i], etags[i])) - def test_tag_propagation (self): + def test_tag_propagation(self): ''' test_tag_propagation: test that non length tags are handled correctly ''' @@ -310,11 +322,11 @@ class qa_burst_shaper (gr_unittest.TestCase): tag2_offset = length1 + gap_len # accompanies second length tag tag3_offset = 2 # in ramp-up state tag4_offset = length1 + 2 # in gap; tag will be dropped - tag5_offset = length1 + gap_len + 7 # in copy state + tag5_offset = length1 + gap_len + 7 # in copy state data = np.concatenate((np.ones(length1), np.zeros(gap_len), - -1.0*np.ones(length2))) - window = np.concatenate((-2.0*np.ones(5), -4.0*np.ones(5))) + -1.0 * np.ones(length2))) + window = np.concatenate((-2.0 * np.ones(5), -4.0 * np.ones(5))) tags = (make_length_tag(lentag1_offset, length1), make_length_tag(lentag2_offset, length2), make_tag(tag1_offset, 'head', pmt.intern('tag1')), @@ -324,15 +336,15 @@ class qa_burst_shaper (gr_unittest.TestCase): make_tag(tag5_offset, 'body', pmt.intern('tag5'))) expected = np.concatenate((np.zeros(prepad), window[0:5], np.ones(length1 - len(window)), window[5:10], - np.zeros(postpad + prepad), -1.0*window[0:5], - -1.0*np.ones(length2 - len(window)), - -1.0*window[5:10], np.zeros(postpad))) + np.zeros(postpad + prepad), -1.0 * window[0:5], + -1.0 * np.ones(length2 - len(window)), + -1.0 * window[5:10], np.zeros(postpad))) elentag1_offset = 0 elentag2_offset = length1 + prepad + postpad etag1_offset = 0 etag2_offset = elentag2_offset etag3_offset = prepad + tag3_offset - etag5_offset = 2*prepad + postpad + tag5_offset - gap_len + etag5_offset = 2 * prepad + postpad + tag5_offset - gap_len etags = (make_length_tag(elentag1_offset, length1 + prepad + postpad), make_length_tag(elentag2_offset, length2 + prepad + postpad), make_tag(etag1_offset, 'head', pmt.intern('tag1')), @@ -346,7 +358,7 @@ class qa_burst_shaper (gr_unittest.TestCase): post_padding=postpad) sink = blocks.vector_sink_f() self.tb.connect(source, shaper, sink) - self.tb.run () + self.tb.run() # checks self.assertFloatTuplesAlmostEqual(sink.data(), expected, 6) diff --git a/gr-digital/python/digital/qa_chunks_to_symbols.py b/gr-digital/python/digital/qa_chunks_to_symbols.py index e2d8801571..1616f29e08 100644 --- a/gr-digital/python/digital/qa_chunks_to_symbols.py +++ b/gr-digital/python/digital/qa_chunks_to_symbols.py @@ -12,6 +12,7 @@ import pmt from gnuradio import gr, gr_unittest, digital, blocks + class test_chunks_to_symbols(gr_unittest.TestCase): def setUp(self): @@ -21,11 +22,11 @@ class test_chunks_to_symbols(gr_unittest.TestCase): self.tb = None def test_bc_001(self): - const = [ 1+0j, 0+1j, - -1+0j, 0-1j] + const = [1 + 0j, 0 + 1j, + -1 + 0j, 0 - 1j] src_data = (0, 1, 2, 3, 3, 2, 1, 0) - expected_result = [1+0j, 0+1j, -1+0j, 0-1j, - 0-1j, -1+0j, 0+1j, 1+0j] + expected_result = [1 + 0j, 0 + 1j, -1 + 0j, 0 - 1j, + 0 - 1j, -1 + 0j, 0 + 1j, 1 + 0j] src = blocks.vector_source_b(src_data) op = digital.chunks_to_symbols_bc(const) @@ -42,7 +43,7 @@ class test_chunks_to_symbols(gr_unittest.TestCase): const = [-3, -1, 1, 3] src_data = (0, 1, 2, 3, 3, 2, 1, 0) expected_result = [-3, -1, 1, 3, - 3, 1, -1, -3] + 3, 1, -1, -3] src = blocks.vector_source_b(src_data) op = digital.chunks_to_symbols_bf(const) @@ -56,11 +57,11 @@ class test_chunks_to_symbols(gr_unittest.TestCase): self.assertEqual(expected_result, actual_result) def test_ic_003(self): - const = [ 1+0j, 0+1j, - -1+0j, 0-1j] + const = [1 + 0j, 0 + 1j, + -1 + 0j, 0 - 1j] src_data = (0, 1, 2, 3, 3, 2, 1, 0) - expected_result = [1+0j, 0+1j, -1+0j, 0-1j, - 0-1j, -1+0j, 0+1j, 1+0j] + expected_result = [1 + 0j, 0 + 1j, -1 + 0j, 0 - 1j, + 0 - 1j, -1 + 0j, 0 + 1j, 1 + 0j] src = blocks.vector_source_i(src_data) op = digital.chunks_to_symbols_ic(const) @@ -77,7 +78,7 @@ class test_chunks_to_symbols(gr_unittest.TestCase): const = [-3, -1, 1, 3] src_data = (0, 1, 2, 3, 3, 2, 1, 0) expected_result = [-3, -1, 1, 3, - 3, 1, -1, -3] + 3, 1, -1, -3] src = blocks.vector_source_i(src_data) op = digital.chunks_to_symbols_if(const) @@ -91,11 +92,11 @@ class test_chunks_to_symbols(gr_unittest.TestCase): self.assertEqual(expected_result, actual_result) def test_sc_005(self): - const = [ 1+0j, 0+1j, - -1+0j, 0-1j] + const = [1 + 0j, 0 + 1j, + -1 + 0j, 0 - 1j] src_data = (0, 1, 2, 3, 3, 2, 1, 0) - expected_result = [1+0j, 0+1j, -1+0j, 0-1j, - 0-1j, -1+0j, 0+1j, 1+0j] + expected_result = [1 + 0j, 0 + 1j, -1 + 0j, 0 - 1j, + 0 - 1j, -1 + 0j, 0 + 1j, 1 + 0j] src = blocks.vector_source_s(src_data) op = digital.chunks_to_symbols_sc(const) @@ -112,7 +113,7 @@ class test_chunks_to_symbols(gr_unittest.TestCase): const = [-3, -1, 1, 3] src_data = (0, 1, 2, 3, 3, 2, 1, 0) expected_result = [-3, -1, 1, 3, - 3, 1, -1, -3] + 3, 1, -1, -3] src = blocks.vector_source_s(src_data) op = digital.chunks_to_symbols_sf(const) @@ -125,12 +126,11 @@ class test_chunks_to_symbols(gr_unittest.TestCase): actual_result = dst.data() self.assertEqual(expected_result, actual_result) - def test_sf_callback(self): constA = [-3, -1, 1, 3] constB = [12, -12, 6, -6] src_data = [0, 1, 2, 3, 3, 2, 1, 0] - expected_result=[12, -12, 6, -6, -6, 6, -12, 12] + expected_result = [12, -12, 6, -6, -6, 6, -12, 12] src = blocks.vector_source_s(src_data, False, 1, []) op = digital.chunks_to_symbols_sf(constA) @@ -143,10 +143,11 @@ class test_chunks_to_symbols(gr_unittest.TestCase): self.assertEqual(expected_result, actual_result) def test_sc_callback(self): - constA = [-3.0+1j, -1.0-1j, 1.0+1j, 3-1j] - constB = [12.0+1j, -12.0-1j, 6.0+1j, -6-1j] + constA = [-3.0 + 1j, -1.0 - 1j, 1.0 + 1j, 3 - 1j] + constB = [12.0 + 1j, -12.0 - 1j, 6.0 + 1j, -6 - 1j] src_data = [0, 1, 2, 3, 3, 2, 1, 0] - expected_result=[12.0+1j, -12.0-1j, 6.0+1j, -6-1j, -6-1j, 6+1j, -12-1j, 12+1j] + expected_result = [12.0 + 1j, -12.0 - 1j, 6.0 + + 1j, -6 - 1j, -6 - 1j, 6 + 1j, -12 - 1j, 12 + 1j] src = blocks.vector_source_s(src_data, False, 1, []) op = digital.chunks_to_symbols_sc(constA) @@ -163,7 +164,7 @@ class test_chunks_to_symbols(gr_unittest.TestCase): constB = [12.0, -12.0, 6.0, -6] src_data = (0, 1, 2, 3, 3, 2, 1, 0) expected_result = [-3, -1, 1, 3, - -6, 6, -12, 12] + -6, 6, -12, 12] first_tag = gr.tag_t() first_tag.key = pmt.intern("set_symbol_table") first_tag.value = pmt.init_f32vector(len(constA), constA) @@ -173,7 +174,9 @@ class test_chunks_to_symbols(gr_unittest.TestCase): second_tag.value = pmt.init_f32vector(len(constB), constB) second_tag.offset = 4 - src = blocks.vector_source_s(src_data, False, 1, [first_tag, second_tag]) + src = blocks.vector_source_s( + src_data, False, 1, [ + first_tag, second_tag]) op = digital.chunks_to_symbols_sf(constB) dst = blocks.vector_sink_f() @@ -185,11 +188,11 @@ class test_chunks_to_symbols(gr_unittest.TestCase): self.assertEqual(expected_result, actual_result) def test_sc_tag(self): - constA = [-3.0+1j, -1.0-1j, 1.0+1j, 3-1j] - constB = [12.0+1j, -12.0-1j, 6.0+1j, -6-1j] + constA = [-3.0 + 1j, -1.0 - 1j, 1.0 + 1j, 3 - 1j] + constB = [12.0 + 1j, -12.0 - 1j, 6.0 + 1j, -6 - 1j] src_data = (0, 1, 2, 3, 3, 2, 1, 0) - expected_result = [-3+1j, -1-1j, 1+1j, 3-1j, - -6-1j, 6+1j, -12-1j, 12+1j] + expected_result = [-3 + 1j, -1 - 1j, 1 + 1j, 3 - 1j, + -6 - 1j, 6 + 1j, -12 - 1j, 12 + 1j] first_tag = gr.tag_t() first_tag.key = pmt.intern("set_symbol_table") first_tag.value = pmt.init_c32vector(len(constA), constA) @@ -199,7 +202,9 @@ class test_chunks_to_symbols(gr_unittest.TestCase): second_tag.value = pmt.init_c32vector(len(constB), constB) second_tag.offset = 4 - src = blocks.vector_source_s(src_data, False, 1, [first_tag, second_tag]) + src = blocks.vector_source_s( + src_data, False, 1, [ + first_tag, second_tag]) op = digital.chunks_to_symbols_sc(constB) dst = blocks.vector_sink_c() @@ -210,5 +215,6 @@ class test_chunks_to_symbols(gr_unittest.TestCase): actual_result = dst.data() self.assertEqual(expected_result, actual_result) + if __name__ == '__main__': gr_unittest.run(test_chunks_to_symbols) diff --git a/gr-digital/python/digital/qa_clock_recovery_mm.py b/gr-digital/python/digital/qa_clock_recovery_mm.py index 782d9e6bae..1475eacf15 100644 --- a/gr-digital/python/digital/qa_clock_recovery_mm.py +++ b/gr-digital/python/digital/qa_clock_recovery_mm.py @@ -14,6 +14,7 @@ import cmath from gnuradio import gr, gr_unittest, digital, blocks + class test_clock_recovery_mm(gr_unittest.TestCase): def setUp(self): @@ -35,14 +36,15 @@ class test_clock_recovery_mm(gr_unittest.TestCase): mu, gain_mu, omega_rel_lim) - data = 100*[complex(1, 1),] + 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 + # doesn't quite get to 1.0 + expected_result = 100 * [complex(0.99972, 0.99972)] dst_data = self.snk.data() # Only compare last Ncmp samples @@ -52,12 +54,11 @@ class test_clock_recovery_mm(gr_unittest.TestCase): expected_result = expected_result[len_e - Ncmp:] dst_data = dst_data[len_d - Ncmp:] - #print expected_result - #print dst_data + # print expected_result + # print dst_data self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 5) - def test02(self): # Test float/float version omega = 2 @@ -70,14 +71,14 @@ class test_clock_recovery_mm(gr_unittest.TestCase): mu, gain_mu, omega_rel_lim) - data = 100*[1,] + data = 100 * [1, ] self.src = blocks.vector_source_f(data, False) self.snk = blocks.vector_sink_f() self.tb.connect(self.src, self.test, self.snk) self.tb.run() - expected_result = 100*[0.9997, ] # doesn't quite get to 1.0 + expected_result = 100 * [0.9997, ] # doesn't quite get to 1.0 dst_data = self.snk.data() # Only compare last Ncmp samples @@ -87,12 +88,11 @@ class test_clock_recovery_mm(gr_unittest.TestCase): expected_result = expected_result[len_e - Ncmp:] dst_data = dst_data[len_d - Ncmp:] - #print expected_result - #print dst_data + # print expected_result + # print dst_data self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 4) - def test03(self): # Test complex/complex version with varying input omega = 2 @@ -105,14 +105,15 @@ class test_clock_recovery_mm(gr_unittest.TestCase): mu, gain_mu, omega_rel_lim) - data = 1000*[complex(1, 1), complex(1, 1), complex(-1, -1), complex(-1, -1)] + 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)] + expected_result = 1000 * [complex(-1.2, -1.2), complex(1.2, 1.2)] dst_data = self.snk.data() # Only compare last Ncmp samples @@ -122,12 +123,11 @@ class test_clock_recovery_mm(gr_unittest.TestCase): expected_result = expected_result[len_e - Ncmp:] dst_data = dst_data[len_d - Ncmp:] - #print expected_result - #print dst_data + # print expected_result + # print dst_data self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 1) - def test04(self): # Test float/float version omega = 2 @@ -140,14 +140,14 @@ class test_clock_recovery_mm(gr_unittest.TestCase): mu, gain_mu, omega_rel_lim) - data = 1000*[1, 1, -1, -1] + data = 1000 * [1, 1, -1, -1] self.src = blocks.vector_source_f(data, False) self.snk = blocks.vector_sink_f() self.tb.connect(self.src, self.test, self.snk) self.tb.run() - expected_result = 1000*[-1.2, 1.2] + expected_result = 1000 * [-1.2, 1.2] dst_data = self.snk.data() # Only compare last Ncmp samples @@ -157,8 +157,8 @@ class test_clock_recovery_mm(gr_unittest.TestCase): expected_result = expected_result[len_e - Ncmp:] dst_data = dst_data[len_d - Ncmp:] - #print expected_result - #print dst_data + # print expected_result + # print dst_data self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 1) diff --git a/gr-digital/python/digital/qa_cma_equalizer.py b/gr-digital/python/digital/qa_cma_equalizer.py index 39b868f8d1..f6da3d1b70 100644 --- a/gr-digital/python/digital/qa_cma_equalizer.py +++ b/gr-digital/python/digital/qa_cma_equalizer.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, digital, blocks + class test_cma_equalizer_fir(gr_unittest.TestCase): def setUp(self): @@ -29,12 +30,13 @@ class test_cma_equalizer_fir(gr_unittest.TestCase): def test_001_identity(self): # Constant modulus signal so no adjustments - src_data = (1+0j, 0+1j, -1+0j, 0-1j)*1000 + src_data = (1 + 0j, 0 + 1j, -1 + 0j, 0 - 1j) * 1000 expected_data = src_data result = self.transform(src_data) N = -500 self.assertComplexTuplesAlmostEqual(expected_data[N:], result[N:]) + if __name__ == "__main__": gr_unittest.run(test_cma_equalizer_fir) diff --git a/gr-digital/python/digital/qa_constellation.py b/gr-digital/python/digital/qa_constellation.py index 050b507a2b..0e3460a142 100644 --- a/gr-digital/python/digital/qa_constellation.py +++ b/gr-digital/python/digital/qa_constellation.py @@ -9,7 +9,8 @@ # -import random, math +import random +import math from cmath import exp, pi, log, sqrt from gnuradio import gr, gr_unittest, digital, blocks @@ -27,18 +28,20 @@ tested_mod_codes = (mod_codes.NO_CODE, mod_codes.GRAY_CODE) # Fourth item is the name of the argument to constructor that specifies # whether differential encoding is used. + def twod_constell(): """ """ - points = ((1+0j), (0+1j), - (-1+0j), (0-1j)) + points = ((1 + 0j), (0 + 1j), + (-1 + 0j), (0 - 1j)) rot_sym = 2 dim = 2 return digital.constellation_calcdist(points, [], rot_sym, dim) + def threed_constell(): - oned_points = ((1+0j), (0+1j), (-1+0j), (0-1j)) + oned_points = ((1 + 0j), (0 + 1j), (-1 + 0j), (0 - 1j)) points = [] r4 = list(range(0, 4)) for ia in r4: @@ -52,6 +55,7 @@ def threed_constell(): # A list of tuples for constellation testing. The contents of the # tuples are (constructor, poss_args, differential, diff_argname). + # These constellations should lock on well. easy_constellation_info = ( (psk.psk_constellation, @@ -66,7 +70,7 @@ easy_constellation_info = ( (qam.qam_constellation, {'constellation_points': (4,), 'mod_code': tested_mod_codes, - 'large_ampls_to_corners': [False],}, + 'large_ampls_to_corners': [False], }, True, None), (qam.qam_constellation, {'constellation_points': (4, 16, 64), @@ -79,7 +83,7 @@ easy_constellation_info = ( (digital.constellation_8psk, {}, False, None), (twod_constell, {}, True, None), (threed_constell, {}, True, None), - ) +) # These constellations don't work nicely. # We have a lower required error rate. @@ -89,9 +93,9 @@ medium_constellation_info = ( 'mod_code': tested_mod_codes, }, True, None), (qam.qam_constellation, - {'constellation_points': (16 ,), + {'constellation_points': (16,), 'mod_code': tested_mod_codes, - 'large_ampls_to_corners': [False, True],}, + 'large_ampls_to_corners': [False, True], }, True, None), (qamlike.qam32_holeinside_constellation, {'large_ampls_to_corners': [True]}, @@ -103,10 +107,11 @@ difficult_constellation_info = ( (qam.qam_constellation, {'constellation_points': (64,), 'mod_code': tested_mod_codes, - 'large_ampls_to_corners': [False, True],}, + 'large_ampls_to_corners': [False, True], }, True, None), ) + def slicer(x): ret = [] for xi in x: @@ -116,6 +121,7 @@ def slicer(x): ret.append(1.0) return ret + def tested_constellations(easy=True, medium=True, difficult=True): """ Generator to produce (constellation, differential) tuples for testing purposes. @@ -132,9 +138,11 @@ def tested_constellations(easy=True, medium=True, difficult=True): diff_poss = (True, False) else: diff_poss = (False,) - poss_args = [[argname, argvalues, 0] for argname, argvalues in list(poss_args.items())] + poss_args = [[argname, argvalues, 0] + for argname, argvalues in list(poss_args.items())] for current_diff in diff_poss: - # Add an index into args to keep track of current position in argvalues + # Add an index into args to keep track of current position in + # argvalues while True: current_args = dict([(argname, argvalues[argindex]) for argname, argvalues, argindex in poss_args]) @@ -149,7 +157,8 @@ def tested_constellations(easy=True, medium=True, difficult=True): break else: this_poss_arg[2] = 0 - if sum([argindex for argname, argvalues, argindex in poss_args]) == 0: + if sum([argindex for argname, argvalues, + argindex in poss_args]) == 0: break @@ -160,7 +169,10 @@ class test_constellation(gr_unittest.TestCase): def setUp(self): random.seed(0) # Generate a list of random bits. - self.src_data = [random.randint(0,1) for i in range(0, self.src_length)] + self.src_data = [ + random.randint( + 0, 1) for i in range( + 0, self.src_length)] def tearDown(self): pass @@ -169,7 +181,8 @@ class test_constellation(gr_unittest.TestCase): for constellation, differential in tested_constellations(): if differential: rs = constellation.rotational_symmetry() - rotations = [exp(i*2*pi*(0+1j)/rs) for i in range(0, rs)] + rotations = [exp(i * 2 * pi * (0 + 1j) / rs) + for i in range(0, rs)] else: rotations = [None] for rotation in rotations: @@ -202,12 +215,17 @@ class test_constellation(gr_unittest.TestCase): c.set_soft_dec_lut(table, prec) x = sqrt(2.0) / 2.0 - step = (x.real+x.real) / (2**prec - 1) - samples = [ -x-x*1j, -x+x*1j, - x+x*1j, x-x*1j, - (-x+128*step)+(-x+128*step)*1j, - (-x+64*step) +(-x+64*step)*1j, (-x+64*step) +(-x+192*step)*1j, - (-x+192*step)+(-x+192*step)*1j, (-x+192*step)+(-x+64*step)*1j,] + step = (x.real + x.real) / (2**prec - 1) + samples = [-x - x * 1j, + -x + x * 1j, + x + x * 1j, + x - x * 1j, + (-x + 128 * step) + (-x + 128 * step) * 1j, + (-x + 64 * step) + (-x + 64 * step) * 1j, + (-x + 64 * step) + (-x + 192 * step) * 1j, + (-x + 192 * step) + (-x + 192 * step) * 1j, + (-x + 192 * step) + (-x + 64 * step) * 1j, + ] y_python_raw_calc = [] y_python_gen_calc = [] @@ -215,14 +233,19 @@ class test_constellation(gr_unittest.TestCase): y_cpp_raw_calc = [] y_cpp_table = [] for sample in samples: - y_python_raw_calc += slicer(digital.calc_soft_dec(sample, constel, code)) + y_python_raw_calc += slicer( + digital.calc_soft_dec( + sample, constel, code)) y_python_gen_calc += slicer(digital.sd_psk_4_0(sample, Es)) - y_python_table += slicer(digital.calc_soft_dec_from_table(sample, table, prec, Es)) + y_python_table += slicer( + digital.calc_soft_dec_from_table( + sample, table, prec, Es)) y_cpp_raw_calc += c.calc_soft_dec(sample) y_cpp_table += c.soft_decision_maker(sample) - self.assertFloatTuplesAlmostEqual(y_python_raw_calc, y_python_gen_calc, 0) + self.assertFloatTuplesAlmostEqual( + y_python_raw_calc, y_python_gen_calc, 0) self.assertFloatTuplesAlmostEqual(y_python_gen_calc, y_python_table, 0) self.assertFloatTuplesAlmostEqual(y_cpp_raw_calc, y_cpp_table, 0) @@ -244,20 +267,29 @@ class test_constellation(gr_unittest.TestCase): c.gen_soft_dec_lut(prec) x = sqrt(2.0) / 2.0 - step = (x.real+x.real) / (2**prec - 1) - samples = [ -x-x*1j, -x+x*1j, - x+x*1j, x-x*1j, - (-x+128*step)+(-x+128*step)*1j, - (-x+64*step) +(-x+64*step)*1j, (-x+64*step) +(-x+192*step)*1j, - (-x+192*step)+(-x+192*step)*1j, (-x+192*step)+(-x+64*step)*1j,] + step = (x.real + x.real) / (2**prec - 1) + samples = [-x - x * 1j, + -x + x * 1j, + x + x * 1j, + x - x * 1j, + (-x + 128 * step) + (-x + 128 * step) * 1j, + (-x + 64 * step) + (-x + 64 * step) * 1j, + (-x + 64 * step) + (-x + 192 * step) * 1j, + (-x + 192 * step) + (-x + 192 * step) * 1j, + (-x + 192 * step) + (-x + 64 * step) * 1j, + ] y_python_raw_calc = [] y_python_table = [] y_cpp_raw_calc = [] y_cpp_table = [] for sample in samples: - y_python_raw_calc += slicer(digital.calc_soft_dec(sample, constel, code)) - y_python_table += slicer(digital.calc_soft_dec_from_table(sample, table, prec, Es)) + y_python_raw_calc += slicer( + digital.calc_soft_dec( + sample, constel, code)) + y_python_table += slicer( + digital.calc_soft_dec_from_table( + sample, table, prec, Es)) y_cpp_raw_calc += slicer(c.calc_soft_dec(sample)) y_cpp_table += slicer(c.soft_decision_maker(sample)) @@ -265,7 +297,6 @@ class test_constellation(gr_unittest.TestCase): self.assertEqual(y_python_raw_calc, y_python_table) self.assertEqual(y_cpp_raw_calc, y_cpp_table) - def test_soft_qam16_calc(self): prec = 8 constel, code = digital.qam_16_0() @@ -284,20 +315,29 @@ class test_constellation(gr_unittest.TestCase): c.gen_soft_dec_lut(prec) x = sqrt(2.0) / 2.0 - step = (x.real+x.real) / (2**prec - 1) - samples = [ -x-x*1j, -x+x*1j, - x+x*1j, x-x*1j, - (-x+128*step)+(-x+128*step)*1j, - (-x+64*step) +(-x+64*step)*1j, (-x+64*step) +(-x+192*step)*1j, - (-x+192*step)+(-x+192*step)*1j, (-x+192*step)+(-x+64*step)*1j,] + step = (x.real + x.real) / (2**prec - 1) + samples = [-x - x * 1j, + -x + x * 1j, + x + x * 1j, + x - x * 1j, + (-x + 128 * step) + (-x + 128 * step) * 1j, + (-x + 64 * step) + (-x + 64 * step) * 1j, + (-x + 64 * step) + (-x + 192 * step) * 1j, + (-x + 192 * step) + (-x + 192 * step) * 1j, + (-x + 192 * step) + (-x + 64 * step) * 1j, + ] y_python_raw_calc = [] y_python_table = [] y_cpp_raw_calc = [] y_cpp_table = [] for sample in samples: - y_python_raw_calc += slicer(digital.calc_soft_dec(sample, constel, code)) - y_python_table += slicer(digital.calc_soft_dec_from_table(sample, table, prec, Es)) + y_python_raw_calc += slicer( + digital.calc_soft_dec( + sample, constel, code)) + y_python_table += slicer( + digital.calc_soft_dec_from_table( + sample, table, prec, Es)) y_cpp_raw_calc += slicer(c.calc_soft_dec(sample)) y_cpp_table += slicer(c.soft_decision_maker(sample)) @@ -305,15 +345,18 @@ class test_constellation(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(y_python_raw_calc, y_python_table, 0) self.assertFloatTuplesAlmostEqual(y_cpp_raw_calc, y_cpp_table, 0) + class mod_demod(gr.hier_block2): def __init__(self, constellation, differential, rotation): if constellation.arity() > 256: # If this becomes limiting some of the blocks should be generalised so # that they can work with shorts and ints as well as chars. - raise ValueError("Constellation cannot contain more than 256 points.") + raise ValueError( + "Constellation cannot contain more than 256 points.") gr.hier_block2.__init__(self, "mod_demod", - gr.io_signature(1, 1, gr.sizeof_char), # Input signature + gr.io_signature( + 1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_char)) # Output signature arity = constellation.arity() @@ -334,13 +377,17 @@ class mod_demod(gr.hier_block2): # Apply any pre-differential coding # Gray-coding is done here if we're also using differential coding. if self.constellation.apply_pre_diff_code(): - self.blocks.append(digital.map_bb(self.constellation.pre_diff_code())) + self.blocks.append( + digital.map_bb( + self.constellation.pre_diff_code())) # Differential encoding. if self.differential: self.blocks.append(digital.diff_encoder_bb(arity)) # Convert to constellation symbols. - self.blocks.append(digital.chunks_to_symbols_bc(self.constellation.points(), - self.constellation.dimensionality())) + self.blocks.append( + digital.chunks_to_symbols_bc( + self.constellation.points(), + self.constellation.dimensionality())) # CHANNEL # Channel just consists of a rotation to check differential coding. if rotation is not None: @@ -348,7 +395,9 @@ class mod_demod(gr.hier_block2): # RX # Convert the constellation symbols back to binary values. - self.blocks.append(digital.constellation_decoder_cb(self.constellation.base())) + self.blocks.append( + digital.constellation_decoder_cb( + self.constellation.base())) # Differential decoding. if self.differential: self.blocks.append(digital.diff_decoder_bb(arity)) @@ -358,7 +407,7 @@ class mod_demod(gr.hier_block2): mod_codes.invert_code(self.constellation.pre_diff_code()))) # unpack the k bit vector into a stream of bits self.blocks.append(blocks.unpack_k_bits_bb( - self.constellation.bits_per_symbol())) + self.constellation.bits_per_symbol())) # connect to block output check_index = len(self.blocks) self.blocks = self.blocks[:check_index] @@ -366,5 +415,6 @@ class mod_demod(gr.hier_block2): self.connect(*self.blocks) + if __name__ == '__main__': gr_unittest.run(test_constellation) diff --git a/gr-digital/python/digital/qa_constellation_decoder_cb.py b/gr-digital/python/digital/qa_constellation_decoder_cb.py index 8e67531cd8..288c8fe5d7 100644 --- a/gr-digital/python/digital/qa_constellation_decoder_cb.py +++ b/gr-digital/python/digital/qa_constellation_decoder_cb.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, digital, blocks + class test_constellation_decoder(gr_unittest.TestCase): def setUp(self): @@ -21,10 +22,10 @@ class test_constellation_decoder(gr_unittest.TestCase): def test_constellation_decoder_cb_bpsk(self): cnst = digital.constellation_bpsk() - src_data = (0.5 + 0.5j, 0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j, - 0.8 + 1.0j, -0.5 + 0.1j, 0.1 - 1.2j) - expected_result = ( 1, 1, 0, 0, - 1, 0, 1) + src_data = (0.5 + 0.5j, 0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j, + 0.8 + 1.0j, -0.5 + 0.1j, 0.1 - 1.2j) + expected_result = (1, 1, 0, 0, + 1, 0, 1) src = blocks.vector_source_c(src_data) op = digital.constellation_decoder_cb(cnst.base()) dst = blocks.vector_sink_b() @@ -34,16 +35,16 @@ class test_constellation_decoder(gr_unittest.TestCase): self.tb.run() # run the graph and wait for it to finish actual_result = dst.data() # fetch the contents of the sink - #print "actual result", actual_result - #print "expected result", expected_result + # print "actual result", actual_result + # print "expected result", expected_result self.assertFloatTuplesAlmostEqual(expected_result, actual_result) def _test_constellation_decoder_cb_qpsk(self): cnst = digital.constellation_qpsk() - src_data = (0.5 + 0.5j, 0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j, - 0.8 + 1.0j, -0.5 + 0.1j, 0.1 - 1.2j) - expected_result = ( 3, 1, 0, 2, - 3, 2, 1) + src_data = (0.5 + 0.5j, 0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j, + 0.8 + 1.0j, -0.5 + 0.1j, 0.1 - 1.2j) + expected_result = (3, 1, 0, 2, + 3, 2, 1) src = blocks.vector_source_c(src_data) op = digital.constellation_decoder_cb(cnst.base()) dst = blocks.vector_sink_b() @@ -53,8 +54,8 @@ class test_constellation_decoder(gr_unittest.TestCase): self.tb.run() # run the graph and wait for it to finish actual_result = dst.data() # fetch the contents of the sink - #print "actual result", actual_result - #print "expected result", expected_result + # print "actual result", actual_result + # print "expected result", expected_result self.assertFloatTuplesAlmostEqual(expected_result, actual_result) diff --git a/gr-digital/python/digital/qa_constellation_receiver.py b/gr-digital/python/digital/qa_constellation_receiver.py index 8c22ebc68e..507fdd45b5 100644 --- a/gr-digital/python/digital/qa_constellation_receiver.py +++ b/gr-digital/python/digital/qa_constellation_receiver.py @@ -9,7 +9,6 @@ # - import random import math @@ -40,8 +39,8 @@ FREQUENCY_OFFSET = 0.01 TIMING_OFFSET = 1.0 # RECEIVER PARAMETERS -FREQ_BW = 2*math.pi/100.0 -PHASE_BW = 2*math.pi/100.0 +FREQ_BW = 2 * math.pi / 100.0 +PHASE_BW = 2 * math.pi / 100.0 class channel_model(gr.hier_block2): @@ -50,20 +49,19 @@ class channel_model(gr.hier_block2): gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) - timing_offset = filter.mmse_resampler_cc(0, timing) noise_adder = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_voltage, 0) freq_offset = analog.sig_source_c(1, analog.GR_SIN_WAVE, freq, 1.0, 0.0) - mixer_offset = blocks.multiply_cc(); + mixer_offset = blocks.multiply_cc() self.connect(self, timing_offset) - self.connect(timing_offset, (mixer_offset,0)) - self.connect(freq_offset, (mixer_offset,1)) - self.connect(mixer_offset, (noise_adder,1)) - self.connect(noise, (noise_adder,0)) + self.connect(timing_offset, (mixer_offset, 0)) + self.connect(freq_offset, (mixer_offset, 1)) + self.connect(mixer_offset, (noise_adder, 1)) + self.connect(noise, (noise_adder, 0)) self.connect(noise_adder, self) @@ -91,16 +89,24 @@ class test_constellation_receiver(gr_unittest.TestCase): # Assumes not more than 64 points in a constellation # Generates some random input data to use. self.src_data = tuple( - [rndm.randint(0,1) for i in range(0, self.max_data_length)]) + [rndm.randint(0, 1) for i in range(0, self.max_data_length)]) # Generates some random indices to use for comparing input and # output data (a full comparison is too slow in python). self.indices = alignment.random_sample( self.max_data_length, self.max_num_samples, SEED) requirements = ( - (EASY_REQ_CORRECT, tested_constellations(easy=True, medium=False, difficult=False)), - (MEDIUM_REQ_CORRECT, tested_constellations(easy=False, medium=True, difficult=False)), - ) + (EASY_REQ_CORRECT, + tested_constellations( + easy=True, + medium=False, + difficult=False)), + (MEDIUM_REQ_CORRECT, + tested_constellations( + easy=False, + medium=True, + difficult=False)), + ) for req_correct, tcs in requirements: for constellation, differential in tcs: # The constellation_receiver doesn't work for constellations @@ -116,19 +122,20 @@ class test_constellation_receiver(gr_unittest.TestCase): src_data=self.src_data[:data_length]) tb.run() data = tb.dst.data() - d1 = tb.src_data[:int(len(tb.src_data)*self.ignore_fraction)] - d2 = data[:int(len(data)*self.ignore_fraction)] + d1 = tb.src_data[:int(len(tb.src_data) * self.ignore_fraction)] + d2 = data[:int(len(data) * self.ignore_fraction)] correct, overlap, offset, indices = alignment.align_sequences( d1, d2, indices=self.indices) if correct <= req_correct: - print("Constellation is {0}. Differential is {1}. Required correct is {2}. Correct is {3}. FAIL.". - format(constellation, differential, req_correct, correct)) + print( + "Constellation is {0}. Differential is {1}. Required correct is {2}. Correct is {3}. FAIL.". format( + constellation, differential, req_correct, correct)) self.assertTrue(correct > req_correct) def test_tag(self): # Send data through bpsk receiver # followed by qpsk receiver - data = [0.9+0j, 0.1+0.9j, -1-0.1j, -0.1-0.6j]*2 + data = [0.9 + 0j, 0.1 + 0.9j, -1 - 0.1j, -0.1 - 0.6j] * 2 bpsk_data = [1, 1, 0, 0] qpsk_data = [1, 3, 0, 0] first_tag = gr.tag_t() @@ -146,13 +153,15 @@ class test_constellation_receiver(gr_unittest.TestCase): tb = gr.top_block() tb.connect(src, decoder, snk) tb.run() - self.assertEqual(list(snk.data()), bpsk_data+qpsk_data) + self.assertEqual(list(snk.data()), bpsk_data + qpsk_data) + class rec_test_tb(gr.top_block): """ Takes a constellation an runs a generic modulation, channel, and generic demodulation. """ + def __init__(self, constellation, differential, data_length=None, src_data=None, freq_offset=True): """ @@ -166,7 +175,8 @@ class rec_test_tb(gr.top_block): super(rec_test_tb, self).__init__() # Transmission Blocks if src_data is None: - self.src_data = tuple([random.randint(0,1) for i in range(0, data_length)]) + self.src_data = tuple([random.randint(0, 1) + for i in range(0, data_length)]) else: self.src_data = src_data packer = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) @@ -174,7 +184,8 @@ class rec_test_tb(gr.top_block): mod = generic_mod(constellation, differential=differential) # Channel if freq_offset: - channel = channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET, TIMING_OFFSET) + channel = channel_model( + NOISE_VOLTAGE, FREQUENCY_OFFSET, TIMING_OFFSET) else: channel = channel_model(NOISE_VOLTAGE, 0, TIMING_OFFSET) # Receiver Blocks @@ -188,5 +199,6 @@ class rec_test_tb(gr.top_block): self.dst = blocks.vector_sink_b() self.connect(src, packer, mod, channel, demod, self.dst) + if __name__ == '__main__': gr_unittest.run(test_constellation_receiver) diff --git a/gr-digital/python/digital/qa_constellation_soft_decoder_cf.py b/gr-digital/python/digital/qa_constellation_soft_decoder_cf.py index 034c455081..ca162f4ade 100644 --- a/gr-digital/python/digital/qa_constellation_soft_decoder_cf.py +++ b/gr-digital/python/digital/qa_constellation_soft_decoder_cf.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest, digital, blocks from math import sqrt from numpy import random, vectorize + class test_constellation_soft_decoder(gr_unittest.TestCase): def setUp(self): @@ -42,8 +43,8 @@ class test_constellation_soft_decoder(gr_unittest.TestCase): self.tb.run() actual_result = dst.data() # fetch the contents of the sink - #print "actual result", actual_result - #print "expected result", expected_result + # print "actual result", actual_result + # print "expected result", expected_result self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 5) def helper_no_lut(self, prec, src_data, const_gen, const_sd_gen): @@ -63,8 +64,8 @@ class test_constellation_soft_decoder(gr_unittest.TestCase): self.tb.run() actual_result = dst.data() # fetch the contents of the sink - #print "actual result", actual_result - #print "expected result", expected_result + # print "actual result", actual_result + # print "expected result", expected_result # Double vs. float precision issues between Python and C++, so # use only 4 decimals in comparisons. @@ -72,88 +73,141 @@ class test_constellation_soft_decoder(gr_unittest.TestCase): def test_constellation_soft_decoder_cf_bpsk_3(self): prec = 3 - src_data = (-1.0 - 1.0j, 1.0 - 1.0j, -1.0 + 1.0j, 1.0 + 1.0j, - -2.0 - 2.0j, 2.0 - 2.0j, -2.0 + 2.0j, 2.0 + 2.0j, - -0.2 - 0.2j, 0.2 - 0.2j, -0.2 + 0.2j, 0.2 + 0.2j, - 0.3 + 0.4j, 0.1 - 1.2j, -0.8 - 0.1j, -0.4 + 0.8j, - 0.8 + 1.0j, -0.5 + 0.1j, 0.1 + 1.2j, -1.7 - 0.9j) - self.helper_with_lut(prec, src_data, digital.psk_2_0x0, digital.sd_psk_2_0x0) + src_data = (-1.0 - 1.0j, 1.0 - 1.0j, -1.0 + 1.0j, 1.0 + 1.0j, + -2.0 - 2.0j, 2.0 - 2.0j, -2.0 + 2.0j, 2.0 + 2.0j, + -0.2 - 0.2j, 0.2 - 0.2j, -0.2 + 0.2j, 0.2 + 0.2j, + 0.3 + 0.4j, 0.1 - 1.2j, -0.8 - 0.1j, -0.4 + 0.8j, + 0.8 + 1.0j, -0.5 + 0.1j, 0.1 + 1.2j, -1.7 - 0.9j) + self.helper_with_lut( + prec, + src_data, + digital.psk_2_0x0, + digital.sd_psk_2_0x0) def test_constellation_soft_decoder_cf_bpsk_8(self): prec = 8 - src_data = (-1.0 - 1.0j, 1.0 - 1.0j, -1.0 + 1.0j, 1.0 + 1.0j, - -2.0 - 2.0j, 2.0 - 2.0j, -2.0 + 2.0j, 2.0 + 2.0j, - -0.2 - 0.2j, 0.2 - 0.2j, -0.2 + 0.2j, 0.2 + 0.2j, - 0.3 + 0.4j, 0.1 - 1.2j, -0.8 - 0.1j, -0.4 + 0.8j, - 0.8 + 1.0j, -0.5 + 0.1j, 0.1 + 1.2j, -1.7 - 0.9j) - self.helper_with_lut(prec, src_data, digital.psk_2_0x0, digital.sd_psk_2_0x0) + src_data = (-1.0 - 1.0j, 1.0 - 1.0j, -1.0 + 1.0j, 1.0 + 1.0j, + -2.0 - 2.0j, 2.0 - 2.0j, -2.0 + 2.0j, 2.0 + 2.0j, + -0.2 - 0.2j, 0.2 - 0.2j, -0.2 + 0.2j, 0.2 + 0.2j, + 0.3 + 0.4j, 0.1 - 1.2j, -0.8 - 0.1j, -0.4 + 0.8j, + 0.8 + 1.0j, -0.5 + 0.1j, 0.1 + 1.2j, -1.7 - 0.9j) + self.helper_with_lut( + prec, + src_data, + digital.psk_2_0x0, + digital.sd_psk_2_0x0) def test_constellation_soft_decoder_cf_bpsk_8_rand(self): prec = 8 - src_data = vectorize(complex)(2*random.randn(100), 2*random.randn(100)) - self.helper_with_lut(prec, src_data, digital.psk_2_0x0, digital.sd_psk_2_0x0) + src_data = vectorize(complex)( + 2 * random.randn(100), 2 * random.randn(100)) + self.helper_with_lut( + prec, + src_data, + digital.psk_2_0x0, + digital.sd_psk_2_0x0) def test_constellation_soft_decoder_cf_bpsk_8_rand2(self): prec = 8 - src_data = vectorize(complex)(2*random.randn(100), 2*random.randn(100)) - self.helper_no_lut(prec, src_data, digital.psk_2_0x0, digital.sd_psk_2_0x0) + src_data = vectorize(complex)( + 2 * random.randn(100), 2 * random.randn(100)) + self.helper_no_lut( + prec, + src_data, + digital.psk_2_0x0, + digital.sd_psk_2_0x0) def test_constellation_soft_decoder_cf_qpsk_3(self): prec = 3 - src_data = (-1.0 - 1.0j, 1.0 - 1.0j, -1.0 + 1.0j, 1.0 + 1.0j, - -2.0 - 2.0j, 2.0 - 2.0j, -2.0 + 2.0j, 2.0 + 2.0j, - -0.2 - 0.2j, 0.2 - 0.2j, -0.2 + 0.2j, 0.2 + 0.2j, - 0.3 + 0.4j, 0.1 - 1.2j, -0.8 - 0.1j, -0.4 + 0.8j, - 0.8 + 1.0j, -0.5 + 0.1j, 0.1 + 1.2j, -1.7 - 0.9j) - self.helper_with_lut(prec, src_data, digital.psk_4_0x0_0_1, digital.sd_psk_4_0x0_0_1) + src_data = (-1.0 - 1.0j, 1.0 - 1.0j, -1.0 + 1.0j, 1.0 + 1.0j, + -2.0 - 2.0j, 2.0 - 2.0j, -2.0 + 2.0j, 2.0 + 2.0j, + -0.2 - 0.2j, 0.2 - 0.2j, -0.2 + 0.2j, 0.2 + 0.2j, + 0.3 + 0.4j, 0.1 - 1.2j, -0.8 - 0.1j, -0.4 + 0.8j, + 0.8 + 1.0j, -0.5 + 0.1j, 0.1 + 1.2j, -1.7 - 0.9j) + self.helper_with_lut( + prec, + src_data, + digital.psk_4_0x0_0_1, + digital.sd_psk_4_0x0_0_1) def test_constellation_soft_decoder_cf_qpsk_8(self): prec = 8 - src_data = (-1.0 - 1.0j, 1.0 - 1.0j, -1.0 + 1.0j, 1.0 + 1.0j, - -2.0 - 2.0j, 2.0 - 2.0j, -2.0 + 2.0j, 2.0 + 2.0j, - -0.2 - 0.2j, 0.2 - 0.2j, -0.2 + 0.2j, 0.2 + 0.2j, - 0.3 + 0.4j, 0.1 - 1.2j, -0.8 - 0.1j, -0.4 + 0.8j, - 0.8 + 1.0j, -0.5 + 0.1j, 0.1 + 1.2j, -1.7 - 0.9j) - self.helper_with_lut(prec, src_data, digital.psk_4_0x0_0_1, digital.sd_psk_4_0x0_0_1) + src_data = (-1.0 - 1.0j, 1.0 - 1.0j, -1.0 + 1.0j, 1.0 + 1.0j, + -2.0 - 2.0j, 2.0 - 2.0j, -2.0 + 2.0j, 2.0 + 2.0j, + -0.2 - 0.2j, 0.2 - 0.2j, -0.2 + 0.2j, 0.2 + 0.2j, + 0.3 + 0.4j, 0.1 - 1.2j, -0.8 - 0.1j, -0.4 + 0.8j, + 0.8 + 1.0j, -0.5 + 0.1j, 0.1 + 1.2j, -1.7 - 0.9j) + self.helper_with_lut( + prec, + src_data, + digital.psk_4_0x0_0_1, + digital.sd_psk_4_0x0_0_1) def test_constellation_soft_decoder_cf_qpsk_8_rand(self): prec = 8 - src_data = vectorize(complex)(2*random.randn(100), 2*random.randn(100)) - self.helper_with_lut(prec, src_data, digital.psk_4_0x0_0_1, digital.sd_psk_4_0x0_0_1) + src_data = vectorize(complex)( + 2 * random.randn(100), 2 * random.randn(100)) + self.helper_with_lut( + prec, + src_data, + digital.psk_4_0x0_0_1, + digital.sd_psk_4_0x0_0_1) def test_constellation_soft_decoder_cf_qpsk_8_rand2(self): prec = 8 - src_data = vectorize(complex)(2*random.randn(100), 2*random.randn(100)) - self.helper_no_lut(prec, src_data, digital.psk_4_0x0_0_1, digital.sd_psk_4_0x0_0_1) + src_data = vectorize(complex)( + 2 * random.randn(100), 2 * random.randn(100)) + self.helper_no_lut( + prec, + src_data, + digital.psk_4_0x0_0_1, + digital.sd_psk_4_0x0_0_1) def test_constellation_soft_decoder_cf_qam16_3(self): prec = 3 - src_data = (-1.0 - 1.0j, 1.0 - 1.0j, -1.0 + 1.0j, 1.0 + 1.0j, - -2.0 - 2.0j, 2.0 - 2.0j, -2.0 + 2.0j, 2.0 + 2.0j, - -0.2 - 0.2j, 0.2 - 0.2j, -0.2 + 0.2j, 0.2 + 0.2j, - 0.3 + 0.4j, 0.1 - 1.2j, -0.8 - 0.1j, -0.4 + 0.8j, - 0.8 + 1.0j, -0.5 + 0.1j, 0.1 + 1.2j, -1.7 - 0.9j) - self.helper_with_lut(prec, src_data, digital.qam_16_0x0_0_1_2_3, digital.sd_qam_16_0x0_0_1_2_3) + src_data = (-1.0 - 1.0j, 1.0 - 1.0j, -1.0 + 1.0j, 1.0 + 1.0j, + -2.0 - 2.0j, 2.0 - 2.0j, -2.0 + 2.0j, 2.0 + 2.0j, + -0.2 - 0.2j, 0.2 - 0.2j, -0.2 + 0.2j, 0.2 + 0.2j, + 0.3 + 0.4j, 0.1 - 1.2j, -0.8 - 0.1j, -0.4 + 0.8j, + 0.8 + 1.0j, -0.5 + 0.1j, 0.1 + 1.2j, -1.7 - 0.9j) + self.helper_with_lut( + prec, + src_data, + digital.qam_16_0x0_0_1_2_3, + digital.sd_qam_16_0x0_0_1_2_3) def test_constellation_soft_decoder_cf_qam16_8(self): prec = 8 - src_data = (-1.0 - 1.0j, 1.0 - 1.0j, -1.0 + 1.0j, 1.0 + 1.0j, - -2.0 - 2.0j, 2.0 - 2.0j, -2.0 + 2.0j, 2.0 + 2.0j, - -0.2 - 0.2j, 0.2 - 0.2j, -0.2 + 0.2j, 0.2 + 0.2j, - 0.3 + 0.4j, 0.1 - 1.2j, -0.8 - 0.1j, -0.4 + 0.8j, - 0.8 + 1.0j, -0.5 + 0.1j, 0.1 + 1.2j, -1.7 - 0.9j) - self.helper_with_lut(prec, src_data, digital.qam_16_0x0_0_1_2_3, digital.sd_qam_16_0x0_0_1_2_3) + src_data = (-1.0 - 1.0j, 1.0 - 1.0j, -1.0 + 1.0j, 1.0 + 1.0j, + -2.0 - 2.0j, 2.0 - 2.0j, -2.0 + 2.0j, 2.0 + 2.0j, + -0.2 - 0.2j, 0.2 - 0.2j, -0.2 + 0.2j, 0.2 + 0.2j, + 0.3 + 0.4j, 0.1 - 1.2j, -0.8 - 0.1j, -0.4 + 0.8j, + 0.8 + 1.0j, -0.5 + 0.1j, 0.1 + 1.2j, -1.7 - 0.9j) + self.helper_with_lut( + prec, + src_data, + digital.qam_16_0x0_0_1_2_3, + digital.sd_qam_16_0x0_0_1_2_3) def test_constellation_soft_decoder_cf_qam16_8_rand(self): prec = 8 - src_data = vectorize(complex)(2*random.randn(100), 2*random.randn(100)) - self.helper_with_lut(prec, src_data, digital.qam_16_0x0_0_1_2_3, digital.sd_qam_16_0x0_0_1_2_3) + src_data = vectorize(complex)( + 2 * random.randn(100), 2 * random.randn(100)) + self.helper_with_lut( + prec, + src_data, + digital.qam_16_0x0_0_1_2_3, + digital.sd_qam_16_0x0_0_1_2_3) def test_constellation_soft_decoder_cf_qam16_8_rand2(self): prec = 8 #src_data = vectorize(complex)(2*random.randn(100), 2*random.randn(100)) - src_data = vectorize(complex)(2*random.randn(2), 2*random.randn(2)) - self.helper_no_lut(prec, src_data, digital.qam_16_0x0_0_1_2_3, digital.sd_qam_16_0x0_0_1_2_3) + src_data = vectorize(complex)(2 * random.randn(2), 2 * random.randn(2)) + self.helper_no_lut( + prec, + src_data, + digital.qam_16_0x0_0_1_2_3, + digital.sd_qam_16_0x0_0_1_2_3) if __name__ == '__main__': diff --git a/gr-digital/python/digital/qa_correlate_access_code.py b/gr-digital/python/digital/qa_correlate_access_code.py index 0fb7f64d61..51b7c4dd4f 100644 --- a/gr-digital/python/digital/qa_correlate_access_code.py +++ b/gr-digital/python/digital/qa_correlate_access_code.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest, digital, blocks default_access_code = '\xAC\xDD\xA4\xE2\xF2\x8C\x20\xFC' + def string_to_1_0_list(s): r = [] for ch in s: @@ -23,9 +24,11 @@ def string_to_1_0_list(s): return r + def to_1_0_string(L): return ''.join([chr(x + ord('0')) for x in L]) + class test_correlate_access_code(gr_unittest.TestCase): def setUp(self): @@ -35,10 +38,10 @@ class test_correlate_access_code(gr_unittest.TestCase): self.tb = None def test_001(self): - pad = [0,] * 64 + pad = [0, ] * 64 # 0 0 0 1 0 0 0 1 - src_data = [1, 0, 1, 1, 1, 1, 0, 1, 1] + pad + [0,] * 7 - expected_result = pad + [1, 0, 1, 1, 3, 1, 0, 1, 1, 2] + [0,] * 6 + src_data = [1, 0, 1, 1, 1, 1, 0, 1, 1] + pad + [0, ] * 7 + expected_result = pad + [1, 0, 1, 1, 3, 1, 0, 1, 1, 2] + [0, ] * 6 src = blocks.vector_source_b(src_data) op = digital.correlate_access_code_bb("1011", 0) dst = blocks.vector_sink_b() @@ -47,13 +50,12 @@ class test_correlate_access_code(gr_unittest.TestCase): result_data = dst.data() self.assertEqual(expected_result, result_data) - def test_002(self): code = list(string_to_1_0_list(default_access_code)) access_code = to_1_0_string(code) - pad = [0,] * 64 - #print code - #print access_code + pad = [0, ] * 64 + # print code + # print access_code src_data = code + [1, 0, 1, 1] + pad expected_result = pad + code + [3, 0, 1, 1] src = blocks.vector_source_b(src_data) @@ -67,9 +69,9 @@ class test_correlate_access_code(gr_unittest.TestCase): def test_003(self): code = list(string_to_1_0_list(default_access_code)) access_code = to_1_0_string(code) - pad = [0,] * 64 - #print code - #print access_code + pad = [0, ] * 64 + # print code + # print access_code src_data = code + [1, 0, 1, 1] + pad expected_result = code + [1, 0, 1, 1] + pad src = blocks.vector_source_b(src_data) @@ -83,13 +85,13 @@ class test_correlate_access_code(gr_unittest.TestCase): def test_004(self): code = list(string_to_1_0_list(default_access_code)) access_code = to_1_0_string(code) - pad = [0,] * 64 - #print code - #print access_code + pad = [0, ] * 64 + # print code + # print access_code src_bits = code + [1, 0, 1, 1] + pad - src_data = [2.0*x - 1.0 for x in src_bits] + src_data = [2.0 * x - 1.0 for x in src_bits] expected_result_bits = code + [1, 0, 1, 1] + pad - expected_result = [2.0*x - 1.0 for x in expected_result_bits] + expected_result = [2.0 * x - 1.0 for x in expected_result_bits] src = blocks.vector_source_f(src_data) op = digital.correlate_access_code_tag_ff(access_code, 0, "test") dst = blocks.vector_sink_f() @@ -98,6 +100,6 @@ class test_correlate_access_code(gr_unittest.TestCase): result_data = dst.data() self.assertFloatTuplesAlmostEqual(expected_result, result_data, 5) + if __name__ == '__main__': gr_unittest.run(test_correlate_access_code) - diff --git a/gr-digital/python/digital/qa_correlate_access_code_XX_ts.py b/gr-digital/python/digital/qa_correlate_access_code_XX_ts.py index f3780d36ec..5681d6bbef 100644 --- a/gr-digital/python/digital/qa_correlate_access_code_XX_ts.py +++ b/gr-digital/python/digital/qa_correlate_access_code_XX_ts.py @@ -14,6 +14,7 @@ import pmt default_access_code = '\xAC\xDD\xA4\xE2\xF2\x8C\x20\xFC' + def string_to_1_0_list(s): r = [] for ch in s: @@ -23,9 +24,11 @@ def string_to_1_0_list(s): r.append(t) return r + def to_1_0_string(L): return ''.join([chr(x + ord('0')) for x in L]) + class test_correlate_access_code_XX_ts(gr_unittest.TestCase): def setUp(self): @@ -36,11 +39,13 @@ class test_correlate_access_code_XX_ts(gr_unittest.TestCase): def test_001(self): payload = "test packet" # payload length is 11 bytes - header = "\x00\xd0\x00\xd0" # header contains packet length, twice (bit-swapped) + # header contains packet length, twice (bit-swapped) + header = "\x00\xd0\x00\xd0" packet = header + payload pad = (0,) * 64 - src_data = (0, 0, 1, 1, 1, 1, 0, 1, 1) + tuple(string_to_1_0_list(packet)) + pad - expected = list(map(int, src_data[9+32:-len(pad)])) + src_data = (0, 0, 1, 1, 1, 1, 0, 1, 1) + \ + tuple(string_to_1_0_list(packet)) + pad + expected = list(map(int, src_data[9 + 32:-len(pad)])) src = blocks.vector_source_b(src_data) op = digital.correlate_access_code_bb_ts("1011", 0, "sync") dst = blocks.vector_sink_b() @@ -48,18 +53,20 @@ class test_correlate_access_code_XX_ts(gr_unittest.TestCase): self.tb.run() result_data = dst.data() result_tags = dst.tags() - self.assertEqual(len(result_data), len(payload)*8) + self.assertEqual(len(result_data), len(payload) * 8) self.assertEqual(result_tags[0].offset, 0) - self.assertEqual(pmt.to_long(result_tags[0].value), len(payload)*8) + self.assertEqual(pmt.to_long(result_tags[0].value), len(payload) * 8) self.assertEqual(result_data, expected) def test_bb_prefix(self): payload = "test packet" # payload length is 11 bytes - header = "\x00\xd0\x00\xd0" # header contains packet length, twice (bit-swapped) + # header contains packet length, twice (bit-swapped) + header = "\x00\xd0\x00\xd0" packet = header + payload pad = (0,) * 64 - src_data = (0, 1, 1, 1, 0, 0, 0, 1, 1) + tuple(string_to_1_0_list(packet)) + pad - expected = list(map(int, src_data[9+32:-len(pad)])) + src_data = (0, 1, 1, 1, 0, 0, 0, 1, 1) + \ + tuple(string_to_1_0_list(packet)) + pad + expected = list(map(int, src_data[9 + 32:-len(pad)])) src = blocks.vector_source_b(src_data) op = digital.correlate_access_code_bb_ts("0011", 0, "sync") dst = blocks.vector_sink_b() @@ -67,19 +74,20 @@ class test_correlate_access_code_XX_ts(gr_unittest.TestCase): self.tb.run() result_data = dst.data() result_tags = dst.tags() - self.assertEqual(len(result_data), len(payload)*8) + self.assertEqual(len(result_data), len(payload) * 8) self.assertEqual(result_tags[0].offset, 0) - self.assertEqual(pmt.to_long(result_tags[0].value), len(payload)*8) + self.assertEqual(pmt.to_long(result_tags[0].value), len(payload) * 8) self.assertEqual(result_data, expected) def test_bb_immediate(self): """Test that packets at start of stream match""" payload = "test packet" # payload length is 11 bytes - header = "\x00\xd0\x00\xd0" # header contains packet length, twice (bit-swapped) + # header contains packet length, twice (bit-swapped) + header = "\x00\xd0\x00\xd0" packet = header + payload pad = (0,) * 64 src_data = (0, 0, 1, 1) + tuple(string_to_1_0_list(packet)) + pad - expected = list(map(int, src_data[4+32:-len(pad)])) + expected = list(map(int, src_data[4 + 32:-len(pad)])) src = blocks.vector_source_b(src_data) op = digital.correlate_access_code_bb_ts("0011", 0, "sync") dst = blocks.vector_sink_b() @@ -94,12 +102,15 @@ class test_correlate_access_code_XX_ts(gr_unittest.TestCase): def test_002(self): payload = "test packet" # payload length is 11 bytes - header = "\x00\xd0\x00\xd0" # header contains packet length, twice (bit-swapped) + # header contains packet length, twice (bit-swapped) + header = "\x00\xd0\x00\xd0" packet = header + payload pad = (0,) * 64 - src_data = (0, 0, 1, 1, 1, 1, 0, 1, 1) + tuple(string_to_1_0_list(packet)) + pad - src_floats = tuple(2*b-1 for b in src_data) # convert to binary antipodal symbols (-1,1) - expected = src_floats[9+32:-len(pad)] + src_data = (0, 0, 1, 1, 1, 1, 0, 1, 1) + \ + tuple(string_to_1_0_list(packet)) + pad + # convert to binary antipodal symbols (-1,1) + src_floats = tuple(2 * b - 1 for b in src_data) + expected = src_floats[9 + 32:-len(pad)] src = blocks.vector_source_f(src_floats) op = digital.correlate_access_code_ff_ts("1011", 0, "sync") dst = blocks.vector_sink_f() @@ -107,19 +118,22 @@ class test_correlate_access_code_XX_ts(gr_unittest.TestCase): self.tb.run() result_data = dst.data() result_tags = dst.tags() - self.assertEqual(len(result_data), len(payload)*8) + self.assertEqual(len(result_data), len(payload) * 8) self.assertEqual(result_tags[0].offset, 0) - self.assertEqual(pmt.to_long(result_tags[0].value), len(payload)*8) + self.assertEqual(pmt.to_long(result_tags[0].value), len(payload) * 8) self.assertFloatTuplesAlmostEqual(result_data, expected, 5) def test_ff_prefix(self): payload = "test packet" # payload length is 11 bytes - header = "\x00\xd0\x00\xd0" # header contains packet length, twice (bit-swapped) + # header contains packet length, twice (bit-swapped) + header = "\x00\xd0\x00\xd0" packet = header + payload pad = (0,) * 64 - src_data = (0, 1, 1, 1, 1, 0, 0, 1, 1) + tuple(string_to_1_0_list(packet)) + pad - src_floats = tuple(2*b-1 for b in src_data) # convert to binary antipodal symbols (-1,1) - expected = src_floats[9+32:-len(pad)] + src_data = (0, 1, 1, 1, 1, 0, 0, 1, 1) + \ + tuple(string_to_1_0_list(packet)) + pad + # convert to binary antipodal symbols (-1,1) + src_floats = tuple(2 * b - 1 for b in src_data) + expected = src_floats[9 + 32:-len(pad)] src = blocks.vector_source_f(src_floats) op = digital.correlate_access_code_ff_ts("0011", 0, "sync") dst = blocks.vector_sink_f() @@ -127,20 +141,22 @@ class test_correlate_access_code_XX_ts(gr_unittest.TestCase): self.tb.run() result_data = dst.data() result_tags = dst.tags() - self.assertEqual(len(result_data), len(payload)*8) + self.assertEqual(len(result_data), len(payload) * 8) self.assertEqual(result_tags[0].offset, 0) - self.assertEqual(pmt.to_long(result_tags[0].value), len(payload)*8) + self.assertEqual(pmt.to_long(result_tags[0].value), len(payload) * 8) self.assertFloatTuplesAlmostEqual(result_data, expected, 5) def test_ff_immediate(self): """Test that packets at start of stream match""" payload = "test packet" # payload length is 11 bytes - header = "\x00\xd0\x00\xd0" # header contains packet length, twice (bit-swapped) + # header contains packet length, twice (bit-swapped) + header = "\x00\xd0\x00\xd0" packet = header + payload pad = (0,) * 64 src_data = (0, 0, 1, 1) + tuple(string_to_1_0_list(packet)) + pad - src_floats = tuple(2*b-1 for b in src_data) # convert to binary antipodal symbols (-1,1) - expected = src_floats[4+32:-len(pad)] + # convert to binary antipodal symbols (-1,1) + src_floats = tuple(2 * b - 1 for b in src_data) + expected = src_floats[4 + 32:-len(pad)] src = blocks.vector_source_f(src_floats) op = digital.correlate_access_code_ff_ts("0011", 0, "sync") dst = blocks.vector_sink_f() @@ -148,9 +164,9 @@ class test_correlate_access_code_XX_ts(gr_unittest.TestCase): self.tb.run() result_data = dst.data() result_tags = dst.tags() - self.assertEqual(len(result_data), len(payload)*8) + self.assertEqual(len(result_data), len(payload) * 8) self.assertEqual(result_tags[0].offset, 0) - self.assertEqual(pmt.to_long(result_tags[0].value), len(payload)*8) + self.assertEqual(pmt.to_long(result_tags[0].value), len(payload) * 8) self.assertFloatTuplesAlmostEqual(result_data, expected, 5) diff --git a/gr-digital/python/digital/qa_correlate_access_code_tag.py b/gr-digital/python/digital/qa_correlate_access_code_tag.py index e35205a8b0..31b18c71a7 100644 --- a/gr-digital/python/digital/qa_correlate_access_code_tag.py +++ b/gr-digital/python/digital/qa_correlate_access_code_tag.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest, digital, blocks default_access_code = '\xAC\xDD\xA4\xE2\xF2\x8C\x20\xFC' + def string_to_1_0_list(s): r = [] for ch in s: @@ -23,9 +24,11 @@ def string_to_1_0_list(s): return r + def to_1_0_string(L): return ''.join([chr(x + ord('0')) for x in L]) + class test_correlate_access_code(gr_unittest.TestCase): def setUp(self): @@ -76,8 +79,8 @@ class test_correlate_access_code(gr_unittest.TestCase): code = tuple(string_to_1_0_list(default_access_code)) access_code = to_1_0_string(code) pad = (0,) * 64 - #print code - #print access_code + # print code + # print access_code src_data = code + (1, 0, 1, 1) + pad src = blocks.vector_source_b(src_data) op = digital.correlate_access_code_tag_bb(access_code, 0, "sync") @@ -91,7 +94,7 @@ class test_correlate_access_code(gr_unittest.TestCase): def test_ff(self): pad = (0,) * 64 src_bits = (1, 0, 1, 1, 1, 1, 0, 1, 1) + pad + (0,) * 7 - src_data = [2.0*x - 1.0 for x in src_bits] + src_data = [2.0 * x - 1.0 for x in src_bits] src = blocks.vector_source_f(src_data) op = digital.correlate_access_code_tag_ff("1011", 0, "sync") dst = blocks.tag_debug(gr.sizeof_float, "sync") @@ -105,7 +108,7 @@ class test_correlate_access_code(gr_unittest.TestCase): def test_ff_skip_prefix(self): pad = (0,) * 64 src_bits = (0, 1, 1, 1, 1, 0, 0, 1, 1) + pad + (0,) * 7 - src_data = [2.0*x - 1.0 for x in src_bits] + src_data = [2.0 * x - 1.0 for x in src_bits] src = blocks.vector_source_f(src_data) op = digital.correlate_access_code_tag_ff("0011", 0, "sync") dst = blocks.tag_debug(gr.sizeof_float, "sync") @@ -119,7 +122,7 @@ class test_correlate_access_code(gr_unittest.TestCase): """Test that packets at start of stream match""" pad = (0,) * 64 src_bits = (0, 0, 1, 1) + pad + (0,) * 7 - src_data = [2.0*x - 1.0 for x in src_bits] + src_data = [2.0 * x - 1.0 for x in src_bits] src = blocks.vector_source_f(src_data) op = digital.correlate_access_code_tag_ff("0011", 0, "sync") dst = blocks.tag_debug(gr.sizeof_float, "sync") @@ -133,10 +136,10 @@ class test_correlate_access_code(gr_unittest.TestCase): code = tuple(string_to_1_0_list(default_access_code)) access_code = to_1_0_string(code) pad = (0,) * 64 - #print code - #print access_code + # print code + # print access_code src_bits = code + (1, 0, 1, 1) + pad - src_data = [2.0*x - 1.0 for x in src_bits] + src_data = [2.0 * x - 1.0 for x in src_bits] src = blocks.vector_source_f(src_data) op = digital.correlate_access_code_tag_ff(access_code, 0, "sync") dst = blocks.tag_debug(gr.sizeof_float, "sync") @@ -146,5 +149,6 @@ class test_correlate_access_code(gr_unittest.TestCase): self.assertEqual(len(result_data), 1) self.assertEqual(result_data[0].offset, len(code)) + if __name__ == '__main__': gr_unittest.run(test_correlate_access_code) diff --git a/gr-digital/python/digital/qa_costas_loop_cc.py b/gr-digital/python/digital/qa_costas_loop_cc.py index a71e3f4596..6c82992917 100644 --- a/gr-digital/python/digital/qa_costas_loop_cc.py +++ b/gr-digital/python/digital/qa_costas_loop_cc.py @@ -15,6 +15,7 @@ import cmath from gnuradio import gr, gr_unittest, digital, blocks from gnuradio.digital import psk + class test_costas_loop_cc(gr_unittest.TestCase): def setUp(self): @@ -30,7 +31,7 @@ class test_costas_loop_cc(gr_unittest.TestCase): order = 2 self.test = digital.costas_loop_cc(natfreq, order) - data = 100*[complex(1,0),] + data = 100 * [complex(1, 0), ] self.src = blocks.vector_source_c(data, False) self.snk = blocks.vector_sink_c() @@ -47,7 +48,7 @@ class test_costas_loop_cc(gr_unittest.TestCase): order = 2 self.test = digital.costas_loop_cc(natfreq, order) - data = [complex(2*random.randint(0,1)-1, 0) for i in range(100)] + data = [complex(2 * random.randint(0, 1) - 1, 0) for i in range(100)] self.src = blocks.vector_source_c(data, False) self.snk = blocks.vector_sink_c() @@ -65,12 +66,12 @@ class test_costas_loop_cc(gr_unittest.TestCase): order = 2 self.test = digital.costas_loop_cc(natfreq, order) - rot = cmath.exp(0.2j) # some small rotation - data = [complex(2*random.randint(0,1)-1, 0) for i in range(100)] + rot = cmath.exp(0.2j) # some small rotation + data = [complex(2 * random.randint(0, 1) - 1, 0) for i in range(100)] - N = 40 # settling time + N = 40 # settling time expected_result = data[N:] - data = [rot*d for d in data] + data = [rot * d for d in data] self.src = blocks.vector_source_c(data, False) self.snk = blocks.vector_sink_c() @@ -90,13 +91,23 @@ class test_costas_loop_cc(gr_unittest.TestCase): 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 range(100)] - - N = 40 # settling time + 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 range(100)] + + N = 40 # settling time expected_result = data[N:] - data = [rot*d for d in data] + data = [rot * d for d in data] self.src = blocks.vector_source_c(data, False) self.snk = blocks.vector_sink_c() @@ -116,16 +127,16 @@ class test_costas_loop_cc(gr_unittest.TestCase): order = 8 self.test = digital.costas_loop_cc(natfreq, order) - rot = cmath.exp(-cmath.pi / 8.0j) # rotate to match Costas rotation + 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 range(100)] - data = [2*rot*const.points()[d] for d in data] + data = [random.randint(0, 7) for i in range(100)] + data = [2 * rot * const.points()[d] for d in data] - N = 40 # settling time + N = 40 # settling time expected_result = data[N:] - rot = cmath.exp(0.1j) # some small rotation - data = [rot*d for d in data] + 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() @@ -135,9 +146,10 @@ class test_costas_loop_cc(gr_unittest.TestCase): dst_data = self.snk.data()[N:] - # generously compare results; the loop will converge near to, but + # generously compare results; the loop will converge near to, but # not exactly on, the target data self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 2) + if __name__ == '__main__': gr_unittest.run(test_costas_loop_cc) diff --git a/gr-digital/python/digital/qa_cpm.py b/gr-digital/python/digital/qa_cpm.py index 420b78d10b..e41e7e8f35 100644 --- a/gr-digital/python/digital/qa_cpm.py +++ b/gr-digital/python/digital/qa_cpm.py @@ -1,18 +1,19 @@ #!/usr/bin/env python # # Copyright 2010,2013 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# import numpy from gnuradio import gr, gr_unittest, digital, analog, blocks + class test_cpm(gr_unittest.TestCase): def setUp(self): @@ -33,11 +34,18 @@ class test_cpm(gr_unittest.TestCase): self.tb.connect(src, cpm, arg, sink) self.tb.run() - symbol_phases = numpy.array(sink.data()[sps*L-1::sps]) + symbol_phases = numpy.array(sink.data()[sps * L - 1::sps]) phase_diff = numpy.mod(numpy.subtract(symbol_phases[1:], symbol_phases[:-1]), - (2*numpy.pi,) * (len(symbol_phases)-1)) - self.assertFloatTuplesAlmostEqual(tuple(phase_diff), (0.5 * numpy.pi,) * len(phase_diff), 5, - msg="Phase shift was not correct for CPM method " + name) + (2 * numpy.pi,) * (len(symbol_phases) - 1)) + self.assertFloatTuplesAlmostEqual( + tuple(phase_diff), + (0.5 * + numpy.pi, + ) * + len(phase_diff), + 5, + msg="Phase shift was not correct for CPM method " + + name) def test_001_lrec(self): self.do_check_phase_shift(analog.cpm.LRC, 'LREC') @@ -64,11 +72,15 @@ class test_cpm(gr_unittest.TestCase): self.tb.connect(src, gmsk, arg, sink) self.tb.run() - symbol_phases = numpy.array(sink.data()[sps*L-1::sps]) + symbol_phases = numpy.array(sink.data()[sps * L - 1::sps]) phase_diff = numpy.mod(numpy.subtract(symbol_phases[1:], symbol_phases[:-1]), - (2*numpy.pi,) * (len(symbol_phases)-1)) - self.assertFloatTuplesAlmostEqual(tuple(phase_diff), (0.5 * numpy.pi,) * len(phase_diff), 5, - msg="Phase shift was not correct for GMSK") + (2 * numpy.pi,) * (len(symbol_phases) - 1)) + self.assertFloatTuplesAlmostEqual( + tuple(phase_diff), + (0.5 * numpy.pi, + ) * len(phase_diff), + 5, + msg="Phase shift was not correct for GMSK") def test_phase_response(self): phase_response = analog.cpm.phase_response(analog.cpm.LREC, 2, 4) @@ -77,4 +89,3 @@ class test_cpm(gr_unittest.TestCase): if __name__ == '__main__': gr_unittest.run(test_cpm) - diff --git a/gr-digital/python/digital/qa_crc32.py b/gr-digital/python/digital/qa_crc32.py index f5340082be..8207a34e73 100644 --- a/gr-digital/python/digital/qa_crc32.py +++ b/gr-digital/python/digital/qa_crc32.py @@ -1,18 +1,19 @@ #!/usr/bin/env python # # Copyright 2011 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# import cmath from gnuradio import gr, gr_unittest, digital + class test_crc32(gr_unittest.TestCase): def setUp(self): @@ -22,28 +23,29 @@ class test_crc32(gr_unittest.TestCase): self.tb = None def test01(self): - data = 100*"0" + data = 100 * "0" expected_result = 2943744955 result = digital.crc32(data) - #print hex(result) - + # print hex(result) + self.assertEqual(expected_result, result) def test02(self): - data = 100*"1" + data = 100 * "1" expected_result = 2326594156 result = digital.crc32(data) - #print hex(result) - + # print hex(result) + self.assertEqual(expected_result, result) def test03(self): - data = 10*"0123456789" + data = 10 * "0123456789" expected_result = 3774345973 result = digital.crc32(data) - #print hex(result) + # print hex(result) self.assertEqual(expected_result, result) + if __name__ == '__main__': gr_unittest.run(test_crc32) diff --git a/gr-digital/python/digital/qa_crc32_bb.py b/gr-digital/python/digital/qa_crc32_bb.py index ba498aeec1..b83372ebdc 100644 --- a/gr-digital/python/digital/qa_crc32_bb.py +++ b/gr-digital/python/digital/qa_crc32_bb.py @@ -31,7 +31,8 @@ class qa_crc32_bb(gr_unittest.TestCase): blocks.stream_to_tagged_stream(gr.sizeof_char, 1, len(data), self.tsb_key), crc, sink) self.tb.run() - # Check that the packets before crc_check are 4 bytes longer that the input. + # Check that the packets before crc_check are 4 bytes longer that the + # input. self.assertEqual(len(data) + 4, len(sink.data()[0])) def test_002_crc_equal(self): @@ -53,7 +54,7 @@ class qa_crc32_bb(gr_unittest.TestCase): def test_003_crc_correct_lentag(self): tag_name = "length" pack_len = 8 - packets = list(range(pack_len*2)) + packets = list(range(pack_len * 2)) tag1 = gr.tag_t() tag1.offset = 0 tag1.key = pmt.string_to_symbol(tag_name) @@ -132,7 +133,8 @@ class qa_crc32_bb(gr_unittest.TestCase): if pmt.symbol_to_string(tag.key) == 'tag1' ]) - # NOTE: What follows are the same tests as before but with the packed flag set to False + # NOTE: What follows are the same tests as before but with the packed flag + # set to False def test_006_crc_len(self): """ Make sure the output of a CRC set is 32 (unpacked) bytes longer than the input. """ @@ -145,7 +147,8 @@ class qa_crc32_bb(gr_unittest.TestCase): blocks.stream_to_tagged_stream(gr.sizeof_char, 1, len(data), self.tsb_key), crc, sink) self.tb.run() - # Check that the packets before crc_check are 4 bytes longer that the input. + # Check that the packets before crc_check are 4 bytes longer that the + # input. self.assertEqual(len(data) + 32, len(sink.data()[0])) def test_007_crc_equal(self): @@ -164,13 +167,15 @@ class qa_crc32_bb(gr_unittest.TestCase): # Check that the packets after crc_check are the same as input. self.assertEqual(data, sink.data()[0]) - def test_002_crc_equal_unpacked (self): + def test_002_crc_equal_unpacked(self): """ Test unpacked operation with packed operation """ data = [0, 1, 2, 3, 4, 5, 6, 7, 8] src = blocks.vector_source_b(data) - unpack1 = blocks.repack_bits_bb(8, 1, self.tsb_key, False, gr.GR_LSB_FIRST) - unpack2 = blocks.repack_bits_bb(8, 1, self.tsb_key, False, gr.GR_LSB_FIRST) + unpack1 = blocks.repack_bits_bb( + 8, 1, self.tsb_key, False, gr.GR_LSB_FIRST) + unpack2 = blocks.repack_bits_bb( + 8, 1, self.tsb_key, False, gr.GR_LSB_FIRST) crc_unpacked = digital.crc32_bb(False, self.tsb_key, False) crc_packed = digital.crc32_bb(False, self.tsb_key, True) sink1 = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key) @@ -212,10 +217,10 @@ class qa_crc32_bb(gr_unittest.TestCase): self.tb.run() self.assertEqual(sink1.data(), sink2.data()) - def test_008_crc_correct_lentag (self): + def test_008_crc_correct_lentag(self): tag_name = "length" pack_len = 8 - packets = list(range(pack_len*2)) + packets = list(range(pack_len * 2)) tag1 = gr.tag_t() tag1.offset = 0 tag1.key = pmt.string_to_symbol(tag_name) diff --git a/gr-digital/python/digital/qa_decision_feedback_equalizer.py b/gr-digital/python/digital/qa_decision_feedback_equalizer.py index 1a9d3abe79..1249df46a1 100755 --- a/gr-digital/python/digital/qa_decision_feedback_equalizer.py +++ b/gr-digital/python/digital/qa_decision_feedback_equalizer.py @@ -1,76 +1,113 @@ #!/usr/bin/env python # # Copyright 2020 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# from gnuradio import gr, gr_unittest -import random, numpy +import random +import numpy from gnuradio import digital, blocks, channels + class qa_linear_equalizer(gr_unittest.TestCase): - def unpack_values(self, values_in, bits_per_value, bits_per_symbol): - # verify that 8 is divisible by bits_per_symbol + def unpack_values(self, values_in, bits_per_value, bits_per_symbol): + # verify that 8 is divisible by bits_per_symbol m = bits_per_value / bits_per_symbol # print(m) - mask = 2**(bits_per_symbol)-1 - - if bits_per_value != m*bits_per_symbol: - print("error - bits per symbols must fit nicely into bits_per_value bit values") + mask = 2**(bits_per_symbol) - 1 + + if bits_per_value != m * bits_per_symbol: + print( + "error - bits per symbols must fit nicely into bits_per_value bit values") return [] - + num_values = len(values_in) - num_symbols = int(num_values*( m) ) - + num_symbols = int(num_values * (m)) + cur_byte = 0 cur_bit = 0 out = [] for i in range(num_symbols): - s = (values_in[cur_byte] >> (bits_per_value-bits_per_symbol-cur_bit)) & mask + s = ( + values_in[cur_byte] >> ( + bits_per_value - + bits_per_symbol - + cur_bit)) & mask out.append(s) cur_bit += bits_per_symbol - + if cur_bit >= bits_per_value: cur_bit = 0 cur_byte += 1 - + return out def map_symbols_to_constellation(self, symbols, cons): l = list(map(lambda x: cons.points()[x], symbols)) return l - def setUp(self): random.seed(987654) self.tb = gr.top_block() self.num_data = num_data = 10000 self.snr = snr = 10 - self.noise_voltage = pow(10.0,(-snr/20.0)) - + self.noise_voltage = pow(10.0, (-snr / 20.0)) + self.sps = sps = 4 self.eb = eb = 0.35 - self.preamble = preamble = [0x27,0x2F,0x18,0x5D,0x5B,0x2A,0x3F,0x71,0x63,0x3C,0x17,0x0C,0x0A,0x41,0xD6,0x1F,0x4C,0x23,0x65,0x68,0xED,0x1C,0x77,0xA7,0x0E,0x0A,0x9E,0x47,0x82,0xA4,0x57,0x24,] - - self.payload_size = payload_size = 300 # bytes - self.data = data = [0]*4+[random.getrandbits(8) for i in range(payload_size)] + self.preamble = preamble = [ + 0x27, + 0x2F, + 0x18, + 0x5D, + 0x5B, + 0x2A, + 0x3F, + 0x71, + 0x63, + 0x3C, + 0x17, + 0x0C, + 0x0A, + 0x41, + 0xD6, + 0x1F, + 0x4C, + 0x23, + 0x65, + 0x68, + 0xED, + 0x1C, + 0x77, + 0xA7, + 0x0E, + 0x0A, + 0x9E, + 0x47, + 0x82, + 0xA4, + 0x57, + 0x24, + ] + + self.payload_size = payload_size = 300 # bytes + self.data = data = [0] * 4 + \ + [random.getrandbits(8) for i in range(payload_size)] self.gain = gain = .001 # LMS gain self.corr_thresh = corr_thresh = 3e6 - self.num_taps = num_taps = 16 - - + self.num_taps = num_taps = 16 def tearDown(self): self.tb = None - 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()) @@ -82,9 +119,9 @@ class qa_linear_equalizer(gr_unittest.TestCase): def test_001_identity(self): # Constant modulus signal so no adjustments const = digital.constellation_qpsk() - src_data = const.points()*1000 + src_data = const.points() * 1000 - N = 100 # settling time + N = 100 # settling time expected_data = src_data[N:] result = self.transform(src_data, 0.1, const)[N:] @@ -97,18 +134,37 @@ class qa_linear_equalizer(gr_unittest.TestCase): num_taps_fwd = 13 num_taps_rev = 3 num_test = 1000 - cons = digital.constellation_qpsk().base() - rxmod = digital.generic_mod(cons, False, self.sps, True, self.eb, False, False) - modulated_sync_word_pre = digital.modulate_vector_bc(rxmod.to_basic_block(), self.preamble+self.preamble, [1]) - modulated_sync_word = modulated_sync_word_pre[86:(512+86)] # compensate for the RRC filter delay - corr_max = numpy.abs(numpy.dot(modulated_sync_word,numpy.conj(modulated_sync_word))) - corr_calc = self.corr_thresh/(corr_max*corr_max) - preamble_symbols = self.map_symbols_to_constellation(self.unpack_values(self.preamble, 8, 2), cons) + cons = digital.constellation_qpsk().base() + rxmod = digital.generic_mod( + cons, False, self.sps, True, self.eb, False, False) + modulated_sync_word_pre = digital.modulate_vector_bc( + rxmod.to_basic_block(), self.preamble + self.preamble, [1]) + # compensate for the RRC filter delay + modulated_sync_word = modulated_sync_word_pre[86:(512 + 86)] + corr_max = numpy.abs( + numpy.dot( + modulated_sync_word, + numpy.conj(modulated_sync_word))) + corr_calc = self.corr_thresh / (corr_max * corr_max) + preamble_symbols = self.map_symbols_to_constellation( + self.unpack_values(self.preamble, 8, 2), cons) alg = digital.adaptive_algorithm_lms(cons, gain).base() evm = digital.meas_evm_cc(cons, digital.evm_measurement_t.EVM_PERCENT) - dfe = digital.decision_feedback_equalizer(num_taps_fwd, num_taps_rev, self.sps, alg, True, preamble_symbols, 'corr_est') - correst = digital.corr_est_cc(modulated_sync_word, self.sps, 12, corr_calc, digital.THRESHOLD_ABSOLUTE) + dfe = digital.decision_feedback_equalizer( + num_taps_fwd, + num_taps_rev, + self.sps, + alg, + True, + preamble_symbols, + 'corr_est') + correst = digital.corr_est_cc( + modulated_sync_word, + self.sps, + 12, + corr_calc, + digital.THRESHOLD_ABSOLUTE) constmod = digital.generic_mod( constellation=cons, differential=False, @@ -121,21 +177,45 @@ class qa_linear_equalizer(gr_unittest.TestCase): noise_voltage=self.noise_voltage, frequency_offset=0.0, epsilon=1.0, - taps=(2.0,-0.459489+-0.156287j,0.185799+0.022878j,0.060229+0.002171j,-0.023041+-0.016539j,-0.004507+0.011984j,-0.002597+0.002675j,0.002320+0.000621j,-0.001420+-0.000126j,-0.000118+-0.000520j,-0.000029+-0.000201j,0.000060+-0.000002j,0.169089+-0.500778j,0.419112+0.042402j,-0.139208+0.030027j,-0.080077+0.036473j,0.026689+0.000837j,-0.002449+0.002320j,-0.000567+-0.002068j,0.001528+0.002867j,0.000944+-0.000166j,0.000218+0.000007j,0.000214+-0.000150j,0.000004+0.000008j), + taps=( + 2.0, + -0.459489 + -0.156287j, + 0.185799 + 0.022878j, + 0.060229 + 0.002171j, + -0.023041 + -0.016539j, + -0.004507 + 0.011984j, + -0.002597 + 0.002675j, + 0.002320 + 0.000621j, + -0.001420 + -0.000126j, + -0.000118 + -0.000520j, + -0.000029 + -0.000201j, + 0.000060 + -0.000002j, + 0.169089 + -0.500778j, + 0.419112 + 0.042402j, + -0.139208 + 0.030027j, + -0.080077 + 0.036473j, + 0.026689 + 0.000837j, + -0.002449 + 0.002320j, + -0.000567 + -0.002068j, + 0.001528 + 0.002867j, + 0.000944 + -0.000166j, + 0.000218 + 0.000007j, + 0.000214 + -0.000150j, + 0.000004 + 0.000008j), noise_seed=-44982235, block_tags=False) - - repeating_data = self.preamble+self.data * 200 + + repeating_data = self.preamble + self.data * 200 vso = blocks.vector_source_b(repeating_data, False, 1, []) - head = blocks.head(gr.sizeof_char*1, 500) + head = blocks.head(gr.sizeof_char * 1, 500) vsi = blocks.vector_sink_f() self.tb.connect(vso, head, constmod, chan, correst, dfe, evm, vsi) self.tb.run() # look at the last 1000 samples, should converge quickly, below 5% EVM - upper_bound = list(20.0*numpy.ones((num_test,))) - lower_bound = list(0.0*numpy.zeros((num_test,))) + upper_bound = list(20.0 * numpy.ones((num_test,))) + lower_bound = list(0.0 * numpy.zeros((num_test,))) output_data = vsi.data() output_data = output_data[-num_test:] self.assertLess(output_data, upper_bound) diff --git a/gr-digital/python/digital/qa_diff_encoder.py b/gr-digital/python/digital/qa_diff_encoder.py index 15d80e5281..7ffc331b47 100644 --- a/gr-digital/python/digital/qa_diff_encoder.py +++ b/gr-digital/python/digital/qa_diff_encoder.py @@ -13,6 +13,7 @@ import random from gnuradio import gr, gr_unittest, digital, blocks + def make_random_int_list(L, min, max): result = [] for x in range(L): @@ -32,7 +33,7 @@ class test_diff_encoder(gr_unittest.TestCase): def test_diff_encdec_000(self): random.seed(0) modulus = 2 - src_data = make_random_int_list(1000, 0, modulus-1) + src_data = make_random_int_list(1000, 0, modulus - 1) expected_result = src_data src = blocks.vector_source_b(src_data) enc = digital.diff_encoder_bb(modulus) @@ -46,7 +47,7 @@ class test_diff_encoder(gr_unittest.TestCase): def test_diff_encdec_001(self): random.seed(0) modulus = 4 - src_data = make_random_int_list(1000, 0, modulus-1) + src_data = make_random_int_list(1000, 0, modulus - 1) expected_result = src_data src = blocks.vector_source_b(src_data) enc = digital.diff_encoder_bb(modulus) @@ -60,7 +61,7 @@ class test_diff_encoder(gr_unittest.TestCase): def test_diff_encdec_002(self): random.seed(0) modulus = 8 - src_data = make_random_int_list(40000, 0, modulus-1) + src_data = make_random_int_list(40000, 0, modulus - 1) expected_result = src_data src = blocks.vector_source_b(src_data) enc = digital.diff_encoder_bb(modulus) @@ -71,6 +72,6 @@ class test_diff_encoder(gr_unittest.TestCase): actual_result = dst.data() # fetch the contents of the sink self.assertEqual(expected_result, actual_result) + if __name__ == '__main__': gr_unittest.run(test_diff_encoder) - diff --git a/gr-digital/python/digital/qa_diff_phasor_cc.py b/gr-digital/python/digital/qa_diff_phasor_cc.py index 4c018087e3..7a6ff569f8 100644 --- a/gr-digital/python/digital/qa_diff_phasor_cc.py +++ b/gr-digital/python/digital/qa_diff_phasor_cc.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, digital, blocks + class test_diff_phasor(gr_unittest.TestCase): def setUp(self): @@ -20,8 +21,9 @@ class test_diff_phasor(gr_unittest.TestCase): self.tb = None def test_diff_phasor_cc(self): - src_data = (0+0j, 1+0j, -1+0j, 3+4j, -3-4j, -3+4j) - expected_result = (0+0j, 0+0j, -1+0j, -3-4j, -25+0j, -7-24j) + src_data = (0 + 0j, 1 + 0j, -1 + 0j, 3 + 4j, -3 - 4j, -3 + 4j) + expected_result = (0 + 0j, 0 + 0j, -1 + 0j, - + 3 - 4j, -25 + 0j, -7 - 24j) src = blocks.vector_source_c(src_data) op = digital.diff_phasor_cc() dst = blocks.vector_sink_c() @@ -31,6 +33,6 @@ class test_diff_phasor(gr_unittest.TestCase): actual_result = dst.data() # fetch the contents of the sink self.assertComplexTuplesAlmostEqual(expected_result, actual_result) + if __name__ == '__main__': gr_unittest.run(test_diff_phasor) - diff --git a/gr-digital/python/digital/qa_digital.py b/gr-digital/python/digital/qa_digital.py index 2c4a7594e9..7acfdd518a 100644 --- a/gr-digital/python/digital/qa_digital.py +++ b/gr-digital/python/digital/qa_digital.py @@ -1,16 +1,17 @@ #!/usr/bin/env python # # Copyright 2011 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# from gnuradio import gr, gr_unittest, digital + class test_digital(gr_unittest.TestCase): def setUp(self): @@ -19,5 +20,6 @@ class test_digital(gr_unittest.TestCase): def tearDown(self): self.tb = None + if __name__ == '__main__': gr_unittest.run(test_digital) diff --git a/gr-digital/python/digital/qa_fll_band_edge.py b/gr-digital/python/digital/qa_fll_band_edge.py index 6d35d132b6..0d8d159ecb 100644 --- a/gr-digital/python/digital/qa_fll_band_edge.py +++ b/gr-digital/python/digital/qa_fll_band_edge.py @@ -1,12 +1,12 @@ #!/usr/bin/env python # # Copyright 2011-2013 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# import random @@ -14,6 +14,7 @@ import math from gnuradio import gr, gr_unittest, digital, filter, blocks, analog + class test_fll_band_edge_cc(gr_unittest.TestCase): def setUp(self): @@ -26,19 +27,19 @@ class test_fll_band_edge_cc(gr_unittest.TestCase): def test01(self): sps = 4 rolloff = 0.35 - bw = 2*math.pi/100.0 + bw = 2 * math.pi / 100.0 ntaps = 45 - + # Create pulse shape filter rrc_taps = filter.firdes.root_raised_cosine( sps, sps, 1.0, rolloff, ntaps) # The frequency offset to correct - foffset = 0.2 / (2.0*math.pi) + foffset = 0.2 / (2.0 * math.pi) # Create a set of 1's and -1's, pulse shape and interpolate to sps random.seed(0) - data = [2.0*random.randint(0, 2) - 1.0 for i in range(200)] + data = [2.0 * random.randint(0, 2) - 1.0 for i in range(200)] self.src = blocks.vector_source_c(data, False) self.rrc = filter.interp_fir_filter_ccf(sps, rrc_taps) @@ -55,21 +56,22 @@ class test_fll_band_edge_cc(gr_unittest.TestCase): self.nsnk_fll = blocks.null_sink(gr.sizeof_gr_complex) self.nsnk_phs = blocks.null_sink(gr.sizeof_float) self.nsnk_err = blocks.null_sink(gr.sizeof_float) - + # Connect the blocks - self.tb.connect(self.nco, (self.mix,1)) - self.tb.connect(self.src, self.rrc, (self.mix,0)) + self.tb.connect(self.nco, (self.mix, 1)) + self.tb.connect(self.src, self.rrc, (self.mix, 0)) self.tb.connect(self.mix, self.fll, self.nsnk_fll) - self.tb.connect((self.fll,1), self.vsnk_frq) - self.tb.connect((self.fll,2), self.nsnk_phs) - self.tb.connect((self.fll,3), self.nsnk_err) + self.tb.connect((self.fll, 1), self.vsnk_frq) + self.tb.connect((self.fll, 2), self.nsnk_phs) + self.tb.connect((self.fll, 3), self.nsnk_err) self.tb.run() - + N = 700 dst_data = self.vsnk_frq.data()[N:] - expected_result = len(dst_data)* [-0.20,] + expected_result = len(dst_data) * [-0.20, ] self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 4) + if __name__ == '__main__': gr_unittest.run(test_fll_band_edge_cc) diff --git a/gr-digital/python/digital/qa_framer_sink.py b/gr-digital/python/digital/qa_framer_sink.py index 365829a9a1..e5bda1e63f 100644 --- a/gr-digital/python/digital/qa_framer_sink.py +++ b/gr-digital/python/digital/qa_framer_sink.py @@ -1,18 +1,19 @@ #!/usr/bin/env python # # Copyright 2012,2013 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# from gnuradio import gr, gr_unittest, digital, blocks default_access_code = '\xAC\xDD\xA4\xE2\xF2\x8C\x20\xFC' + def string_to_1_0_list(s): r = [] for ch in s: @@ -22,9 +23,11 @@ def string_to_1_0_list(s): r.append(t) return r + def to_1_0_string(L): return ''.join([chr(x + ord('0')) for x in L]) + class test_framker_sink(gr_unittest.TestCase): def setUp(self): @@ -37,9 +40,10 @@ class test_framker_sink(gr_unittest.TestCase): code = (1, 1, 0, 1) access_code = to_1_0_string(code) - header = tuple(2*[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]) # len=1 + header = tuple(2 * [0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1]) # len=1 pad = (0,) * 100 - src_data = code + header + (0,1,0,0,0,0,0,1) + pad + src_data = code + header + (0, 1, 0, 0, 0, 0, 0, 1) + pad expected_data = b'A' rcvd_pktq = gr.msg_queue() @@ -61,9 +65,11 @@ class test_framker_sink(gr_unittest.TestCase): code = tuple(string_to_1_0_list(default_access_code)) access_code = to_1_0_string(code) - header = tuple(2*[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0]) # len=2 + header = tuple(2 * [0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0]) # len=2 pad = (0,) * 100 - src_data = code + header + (0,1,0,0,1,0,0,0) + (0,1,0,0,1,0,0,1) + pad + src_data = code + header + \ + (0, 1, 0, 0, 1, 0, 0, 0) + (0, 1, 0, 0, 1, 0, 0, 1) + pad expected_data = b'HI' rcvd_pktq = gr.msg_queue() @@ -81,6 +87,6 @@ class test_framker_sink(gr_unittest.TestCase): result_data = result_data.to_string() self.assertEqual(expected_data, result_data) + if __name__ == '__main__': gr_unittest.run(test_framker_sink) - diff --git a/gr-digital/python/digital/qa_glfsr_source.py b/gr-digital/python/digital/qa_glfsr_source.py index 7505f5bdaa..dbe488399b 100644 --- a/gr-digital/python/digital/qa_glfsr_source.py +++ b/gr-digital/python/digital/qa_glfsr_source.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, digital, blocks + class test_glfsr_source(gr_unittest.TestCase): def setUp(self): @@ -22,7 +23,7 @@ class test_glfsr_source(gr_unittest.TestCase): def test_000_make_b(self): src = digital.glfsr_source_b(16) self.assertEqual(src.mask(), 0x8016) - self.assertEqual(src.period(), 2**16-1) + self.assertEqual(src.period(), 2**16 - 1) def test_001_degree_b(self): self.assertRaises(RuntimeError, @@ -31,53 +32,62 @@ class test_glfsr_source(gr_unittest.TestCase): lambda: digital.glfsr_source_b(33)) def test_002_correlation_b(self): - for degree in range(1,11): # Higher degrees take too long to correlate + for degree in range( + 1, 11): # Higher degrees take too long to correlate src = digital.glfsr_source_b(degree, False) - b2f = digital.chunks_to_symbols_bf((-1.0,1.0), 1) + b2f = digital.chunks_to_symbols_bf((-1.0, 1.0), 1) dst = blocks.vector_sink_f() - del self.tb # Discard existing top block + del self.tb # Discard existing top block self.tb = gr.top_block() self.tb.connect(src, b2f, dst) self.tb.run() self.tb.disconnect_all() actual_result = dst.data() R = auto_correlate(actual_result) - self.assertEqual(R[0], float(len(R))) # Auto-correlation peak at origin - for i in range(len(R)-1): - self.assertEqual(R[i+1], -1.0) # Auto-correlation minimum everywhere else + # Auto-correlation peak at origin + self.assertEqual(R[0], float(len(R))) + for i in range(len(R) - 1): + # Auto-correlation minimum everywhere else + self.assertEqual(R[i + 1], -1.0) def test_003_make_f(self): src = digital.glfsr_source_f(16) self.assertEqual(src.mask(), 0x8016) - self.assertEqual(src.period(), 2**16-1) + self.assertEqual(src.period(), 2**16 - 1) def test_004_degree_f(self): self.assertRaises(RuntimeError, lambda: digital.glfsr_source_f(0)) self.assertRaises(RuntimeError, lambda: digital.glfsr_source_f(33)) + def test_005_correlation_f(self): - for degree in range(1,11): # Higher degrees take too long to correlate + for degree in range( + 1, 11): # Higher degrees take too long to correlate src = digital.glfsr_source_f(degree, False) dst = blocks.vector_sink_f() - del self.tb # Discard existing top block + del self.tb # Discard existing top block self.tb = gr.top_block() self.tb.connect(src, dst) self.tb.run() actual_result = dst.data() R = auto_correlate(actual_result) - self.assertEqual(R[0], float(len(R))) # Auto-correlation peak at origin - for i in range(len(R)-1): - self.assertEqual(R[i+1], -1.0) # Auto-correlation minimum everywhere else + # Auto-correlation peak at origin + self.assertEqual(R[0], float(len(R))) + for i in range(len(R) - 1): + # Auto-correlation minimum everywhere else + self.assertEqual(R[i + 1], -1.0) + def auto_correlate(data): l = len(data) - R = [0,]*l + R = [0, ] * l for lag in range(l): for i in range(l): - R[lag] += data[i]*data[i-lag] + R[lag] += data[i] * data[i - lag] return R + if __name__ == '__main__': gr_unittest.run(test_glfsr_source) diff --git a/gr-digital/python/digital/qa_hdlc_framer.py b/gr-digital/python/digital/qa_hdlc_framer.py index a13f364eeb..b4d63b3d07 100644 --- a/gr-digital/python/digital/qa_hdlc_framer.py +++ b/gr-digital/python/digital/qa_hdlc_framer.py @@ -1,12 +1,12 @@ #!/usr/bin/env python # # Copyright 2006,2007,2010,2011,2013 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# from gnuradio import gr, gr_unittest, digital, blocks @@ -14,6 +14,7 @@ import pmt import numpy from time import sleep + class test_hdlc_framer(gr_unittest.TestCase): def setUp(self): self.tb = gr.top_block() @@ -22,18 +23,18 @@ class test_hdlc_framer(gr_unittest.TestCase): self.tb = None def test_001(self): - #test complementary operation of framer & deframer - #want to frame some random data that has enough consecutive bits to - #stuff at least a few bits + # test complementary operation of framer & deframer + # want to frame some random data that has enough consecutive bits to + # stuff at least a few bits npkts = 20 src_data = [0xFE, 0xDA, 0xAC, 0x29, 0x7F, 0xA2, 0x90, 0x0F, 0xF8] - frame = digital.hdlc_framer_pb("wat") + frame = digital.hdlc_framer_pb("wat") deframe = digital.hdlc_deframer_bp(8, 500) - debug = blocks.message_debug() + debug = blocks.message_debug() self.tb.connect(frame, deframe) self.tb.msg_connect(deframe, "out", debug, "store") self.tb.start() - msg = pmt.cons(pmt.PMT_NIL, pmt.init_u8vector(len(src_data),src_data)) + msg = pmt.cons(pmt.PMT_NIL, pmt.init_u8vector(len(src_data), src_data)) for i in range(npkts): frame.to_basic_block()._post(pmt.intern("in"), msg) sleep(0.2) @@ -49,4 +50,3 @@ class test_hdlc_framer(gr_unittest.TestCase): if __name__ == '__main__': gr_unittest.run(test_hdlc_framer) - diff --git a/gr-digital/python/digital/qa_header_payload_demux.py b/gr-digital/python/digital/qa_header_payload_demux.py index edee14c0c1..76be0905f0 100644 --- a/gr-digital/python/digital/qa_header_payload_demux.py +++ b/gr-digital/python/digital/qa_header_payload_demux.py @@ -33,6 +33,7 @@ class HeaderToMessageBlock(gr.sync_block): Helps with testing the HPD. Receives a header, stores it, posts a predetermined message. """ + def __init__(self, itemsize, header_len, messages): gr.sync_block.__init__( self, @@ -57,12 +58,12 @@ class HeaderToMessageBlock(gr.sync_block): class qa_header_payload_demux (gr_unittest.TestCase): - def setUp (self): + def setUp(self): """Runs before every test.""" - self.tb = gr.top_block () + self.tb = gr.top_block() random.seed(0) - def tearDown (self): + def tearDown(self): """Runs after every test.""" self.tb = None @@ -85,11 +86,17 @@ class qa_header_payload_demux (gr_unittest.TestCase): ) self.tb.connect((hpd, 1), payload_sink) - def run_tb(self, payload_sink, payload_len, header_sink, header_len, timeout=30): + def run_tb( + self, + payload_sink, + payload_len, + header_sink, + header_len, + timeout=30): """Execute self.tb""" stop_time = time.time() + timeout self.tb.start() - while (len(payload_sink.data()) < payload_len or \ + while (len(payload_sink.data()) < payload_len or len(header_sink.data()) < header_len) and \ time.time() < stop_time: time.sleep(.2) @@ -106,7 +113,7 @@ class qa_header_payload_demux (gr_unittest.TestCase): header = (1, 2, 3) payload = tuple(range(5, 20)) data_signal = (0,) * n_zeros + header + payload - trigger_signal = [0,] * len(data_signal) + trigger_signal = [0, ] * len(data_signal) trigger_signal[n_zeros] = 1 # This is dropped: testtag1 = make_tag('tag1', 0, 0) @@ -130,7 +137,8 @@ class qa_header_payload_demux (gr_unittest.TestCase): len(header), [len(payload)] ) - self.assertEqual(pmt.length(hpd.message_ports_in()), 2) #extra system port defined for you + # extra system port defined for you + self.assertEqual(pmt.length(hpd.message_ports_in()), 2) payload_sink = blocks.vector_sink_f() header_sink = blocks.vector_sink_f() self.connect_all_blocks( @@ -188,7 +196,8 @@ class qa_header_payload_demux (gr_unittest.TestCase): hpd = digital.header_payload_demux( len(header), 1, 0, "frame_len", "detect", False, gr.sizeof_float ) - self.assertEqual(pmt.length(hpd.message_ports_in()), 2) #extra system port defined for you + # extra system port defined for you + self.assertEqual(pmt.length(hpd.message_ports_in()), 2) header_sink = blocks.vector_sink_f() payload_sink = blocks.vector_sink_f() mock_header_demod = HeaderToMessageBlock( @@ -196,7 +205,13 @@ class qa_header_payload_demux (gr_unittest.TestCase): len(header), [len(payload)] ) - self.connect_all_blocks(data_src, None, hpd, mock_header_demod, payload_sink, header_sink) + self.connect_all_blocks( + data_src, + None, + hpd, + mock_header_demod, + payload_sink, + header_sink) self.run_tb(payload_sink, len(payload), header_sink, len(header)) # Check results self.assertEqual(header_sink.data(), list(header)) @@ -220,13 +235,13 @@ class qa_header_payload_demux (gr_unittest.TestCase): ] self.assertEqual(expected_tags_payload, ptags_payload) - def test_001_headerpadding (self): + def test_001_headerpadding(self): """ Like test 1, but with header padding. """ n_zeros = 3 header = [1, 2, 3] header_padding = 1 payload = list(range(5, 20)) - data_signal = [0,] * n_zeros + header + payload + data_signal = [0, ] * n_zeros + header + payload trigger_signal = [0] * len(data_signal) trigger_signal[n_zeros] = 1 # This is dropped: @@ -245,15 +260,15 @@ class qa_header_payload_demux (gr_unittest.TestCase): trigger_src = blocks.vector_source_b(trigger_signal, False) hpd = digital.header_payload_demux( len(header), - 1, # Items per symbol - 0, # Guard interval - "frame_len", # TSB tag key - "detect", # Trigger tag key - False, # No symbols please - gr.sizeof_float, # Item size - "", # Timing tag key - 1.0, # Samp rate - (), # No special tags + 1, # Items per symbol + 0, # Guard interval + "frame_len", # TSB tag key + "detect", # Trigger tag key + False, # No symbols please + gr.sizeof_float, # Item size + "", # Timing tag key + 1.0, # Samp rate + (), # No special tags header_padding ) mock_header_demod = HeaderToMessageBlock( @@ -263,11 +278,17 @@ class qa_header_payload_demux (gr_unittest.TestCase): ) header_sink = blocks.vector_sink_f() payload_sink = blocks.vector_sink_f() - self.connect_all_blocks(data_src, trigger_src, hpd, mock_header_demod, payload_sink, header_sink) - self.run_tb(payload_sink, len(payload), header_sink, len(header)+2) + self.connect_all_blocks( + data_src, + trigger_src, + hpd, + mock_header_demod, + payload_sink, + header_sink) + self.run_tb(payload_sink, len(payload), header_sink, len(header) + 2) # Check values # Header now is padded: - self.assertEqual(header_sink.data(), [0,] + header + [payload[0],]) + self.assertEqual(header_sink.data(), [0, ] + header + [payload[0], ]) self.assertEqual(payload_sink.data(), payload) ptags_header = [] for tag in header_sink.tags(): @@ -288,14 +309,14 @@ class qa_header_payload_demux (gr_unittest.TestCase): ] self.assertEqual(expected_tags_payload, ptags_payload) - def test_001_headerpadding_payload_offset (self): + def test_001_headerpadding_payload_offset(self): """ Like test 1, but with header padding + payload offset. """ n_zeros = 3 header = [1, 2, 3] header_padding = 1 payload_offset = -1 payload = list(range(5, 20)) - data_signal = [0,] * n_zeros + header + payload + [0,] * 100 + data_signal = [0, ] * n_zeros + header + payload + [0, ] * 100 trigger_signal = [0] * len(data_signal) trigger_signal[n_zeros] = 1 # This goes on output 1, item 3 + 1 (for payload offset) @@ -308,41 +329,38 @@ class qa_header_payload_demux (gr_unittest.TestCase): trigger_src = blocks.vector_source_b(trigger_signal, False) hpd = digital.header_payload_demux( len(header), - 1, # Items per symbol - 0, # Guard interval - "frame_len", # TSB tag key - "detect", # Trigger tag key - False, # No symbols please - gr.sizeof_float, # Item size - "", # Timing tag key - 1.0, # Samp rate - (), # No special tags + 1, # Items per symbol + 0, # Guard interval + "frame_len", # TSB tag key + "detect", # Trigger tag key + False, # No symbols please + gr.sizeof_float, # Item size + "", # Timing tag key + 1.0, # Samp rate + (), # No special tags header_padding ) - self.assertEqual(pmt.length(hpd.message_ports_in()), 2) #extra system port defined for you + # extra system port defined for you + self.assertEqual(pmt.length(hpd.message_ports_in()), 2) header_sink = blocks.vector_sink_f() payload_sink = blocks.vector_sink_f() - self.tb.connect(data_src, (hpd, 0)) + self.tb.connect(data_src, (hpd, 0)) self.tb.connect(trigger_src, (hpd, 1)) self.tb.connect((hpd, 0), header_sink) self.tb.connect((hpd, 1), payload_sink) self.tb.start() - time.sleep(.2) # Need this, otherwise, the next message is ignored - hpd.to_basic_block()._post( - pmt.intern('header_data'), - pmt.to_pmt({'frame_len': len(payload), 'payload_offset': payload_offset}) - ) + time.sleep(.2) # Need this, otherwise, the next message is ignored + hpd.to_basic_block()._post(pmt.intern('header_data'), pmt.to_pmt( + {'frame_len': len(payload), 'payload_offset': payload_offset})) while len(payload_sink.data()) < len(payload): time.sleep(.2) self.tb.stop() self.tb.wait() # Header is now padded: - self.assertEqual(header_sink.data(), [0,] + header + [payload[0],]) + self.assertEqual(header_sink.data(), [0, ] + header + [payload[0], ]) # Payload is now offset: - self.assertEqual( - payload_sink.data(), - data_signal[n_zeros + len(header) + payload_offset:n_zeros + len(header) + payload_offset + len(payload)] - ) + self.assertEqual(payload_sink.data(), data_signal[n_zeros + len( + header) + payload_offset:n_zeros + len(header) + payload_offset + len(payload)]) ptags_payload = {} for tag in payload_sink.tags(): ptag = gr.tag_to_python(tag) @@ -354,7 +372,6 @@ class qa_header_payload_demux (gr_unittest.TestCase): } self.assertEqual(expected_tags_payload, ptags_payload) - def test_002_symbols(self): """ Same as before, but operate on symbols @@ -365,8 +382,9 @@ class qa_header_payload_demux (gr_unittest.TestCase): n_symbols = 4 header = (1, 2, 3) payload = (1, 2, 3) - data_signal = (0,) * n_zeros + (0,) + header + ((0,) + payload) * n_symbols - trigger_signal = [0,] * len(data_signal) + data_signal = (0,) * n_zeros + (0,) + header + \ + ((0,) + payload) * n_symbols + trigger_signal = [0, ] * len(data_signal) trigger_signal[n_zeros] = 1 # This is dropped: testtag1 = make_tag('tag1', 0, 0) @@ -375,11 +393,14 @@ class qa_header_payload_demux (gr_unittest.TestCase): # This goes on output 0, item 0 (middle of the header symbol) testtag3 = make_tag('tag3', 42, n_zeros + gi + 1) # This goes on output 1, item 1 (middle of the first payload symbol) - testtag4 = make_tag('tag4', 314, n_zeros + (gi + items_per_symbol) * 2 + 1) - data_src = blocks.vector_source_f(data_signal, False, tags=(testtag1, testtag2, testtag3, testtag4)) + testtag4 = make_tag('tag4', 314, n_zeros + + (gi + items_per_symbol) * 2 + 1) + data_src = blocks.vector_source_f( + data_signal, False, tags=( + testtag1, testtag2, testtag3, testtag4)) trigger_src = blocks.vector_source_b(trigger_signal, False) hpd = digital.header_payload_demux( - len(header) // items_per_symbol, # Header length (in symbols) + len(header) // items_per_symbol, # Header length (in symbols) items_per_symbol, # Items per symbols gi, # Items per guard time "frame_len", # Frame length tag key @@ -387,15 +408,16 @@ class qa_header_payload_demux (gr_unittest.TestCase): True, # Output symbols (not items) gr.sizeof_float # Bytes per item ) - self.assertEqual(pmt.length(hpd.message_ports_in()), 2) #extra system port defined for you + # extra system port defined for you + self.assertEqual(pmt.length(hpd.message_ports_in()), 2) header_sink = blocks.vector_sink_f(items_per_symbol) payload_sink = blocks.vector_sink_f(items_per_symbol) - self.tb.connect(data_src, (hpd, 0)) + self.tb.connect(data_src, (hpd, 0)) self.tb.connect(trigger_src, (hpd, 1)) self.tb.connect((hpd, 0), header_sink) self.tb.connect((hpd, 1), payload_sink) self.tb.start() - time.sleep(.2) # Need this, otherwise, the next message is ignored + time.sleep(.2) # Need this, otherwise, the next message is ignored hpd.to_basic_block()._post( pmt.intern('header_data'), pmt.from_long(n_symbols) @@ -404,7 +426,7 @@ class qa_header_payload_demux (gr_unittest.TestCase): time.sleep(.2) self.tb.stop() self.tb.wait() - self.assertEqual(header_sink.data(), header) + self.assertEqual(header_sink.data(), header) self.assertEqual(payload_sink.data(), payload * n_symbols) ptags_header = [] for tag in header_sink.tags(): @@ -429,32 +451,32 @@ class qa_header_payload_demux (gr_unittest.TestCase): """ Like test 1, but twice, plus one fail """ - ### Tx Data + # Tx Data n_zeros = 5 header = [1, 2, 3] - header_fail = [-1, -2, -4] # Contents don't really matter + header_fail = [-1, -2, -4] # Contents don't really matter payload1 = list(range(5, 20)) - payload2 = [42,] + payload2 = [42, ] sampling_rate = 2 - data_signal = [0,] * n_zeros + header + payload1 - trigger_signal = [0,] * len(data_signal) * 2 + data_signal = [0, ] * n_zeros + header + payload1 + trigger_signal = [0, ] * len(data_signal) * 2 trigger_signal[n_zeros] = 1 trigger_signal[len(data_signal)] = 1 - trigger_signal[len(data_signal)+len(header_fail)+n_zeros] = 1 + trigger_signal[len(data_signal) + len(header_fail) + n_zeros] = 1 print("Triggers at: {0} {1} {2}".format( n_zeros, len(data_signal), - len(data_signal)+len(header_fail)+n_zeros)) + len(data_signal) + len(header_fail) + n_zeros)) tx_signal = data_signal + \ - header_fail + [0,] * n_zeros + \ - header + payload2 + [0,] * 1000 + header_fail + [0, ] * n_zeros + \ + header + payload2 + [0, ] * 1000 # Timing tag: This is preserved and updated: timing_tag = make_tag('rx_time', (0, 0), 0) # Rx freq tags: rx_freq_tag1 = make_tag('rx_freq', 1.0, 0) rx_freq_tag2 = make_tag('rx_freq', 1.5, 29) rx_freq_tag3 = make_tag('rx_freq', 2.0, 30) - ### Flow graph + # Flow graph data_src = blocks.vector_source_f( tx_signal, False, tags=(timing_tag, rx_freq_tag1, rx_freq_tag2, rx_freq_tag3) @@ -472,15 +494,16 @@ class qa_header_payload_demux (gr_unittest.TestCase): samp_rate=sampling_rate, special_tags=('rx_freq',), ) - self.assertEqual(pmt.length(hpd.message_ports_in()), 2) #extra system port defined for you + # extra system port defined for you + self.assertEqual(pmt.length(hpd.message_ports_in()), 2) header_sink = blocks.vector_sink_f() payload_sink = blocks.vector_sink_f() - self.tb.connect(data_src, (hpd, 0)) + self.tb.connect(data_src, (hpd, 0)) self.tb.connect(trigger_src, (hpd, 1)) self.tb.connect((hpd, 0), header_sink) self.tb.connect((hpd, 1), payload_sink) self.tb.start() - time.sleep(.2) # Need this, otherwise, the next message is ignored + time.sleep(.2) # Need this, otherwise, the next message is ignored hpd.to_basic_block()._post( pmt.intern('header_data'), pmt.from_long(len(payload1)) @@ -511,23 +534,29 @@ class qa_header_payload_demux (gr_unittest.TestCase): # 31: header 3 # 34: payload 2 (length 1) # 35: 1000 zeros - self.assertEqual(header_sink.data(), list(header + header_fail + header)) + self.assertEqual( + header_sink.data(), list( + header + header_fail + header)) self.assertEqual(payload_sink.data(), payload1 + payload2) tags_payload = [gr.tag_to_python(x) for x in payload_sink.tags()] - tags_payload = sorted([(x.offset, x.key, x.value) for x in tags_payload]) + tags_payload = sorted([(x.offset, x.key, x.value) + for x in tags_payload]) tags_expected_payload = [ - (0, 'frame_len', len(payload1)), + (0, 'frame_len', len(payload1)), (len(payload1), 'frame_len', len(payload2)), ] tags_header = [gr.tag_to_python(x) for x in header_sink.tags()] tags_header = sorted([(x.offset, x.key, x.value) for x in tags_header]) tags_expected_header = [ - (0, 'rx_freq', 1.0), - (0, 'rx_time', (2, 0.5)), # Hard coded time value :( Is n_zeros/sampling_rate - (len(header), 'rx_freq', 1.0), - (len(header), 'rx_time', (11, .5)), # Hard coded time value :(. See above. - (2*len(header), 'rx_freq', 2.0), - (2*len(header), 'rx_time', (15, .5)), # Hard coded time value :(. See above. + (0, 'rx_freq', 1.0), + # Hard coded time value :( Is n_zeros/sampling_rate + (0, 'rx_time', (2, 0.5)), + (len(header), 'rx_freq', 1.0), + # Hard coded time value :(. See above. + (len(header), 'rx_time', (11, .5)), + (2 * len(header), 'rx_freq', 2.0), + # Hard coded time value :(. See above. + (2 * len(header), 'rx_time', (15, .5)), ] self.assertEqual(tags_header, tags_expected_header) self.assertEqual(tags_payload, tags_expected_payload) @@ -561,6 +590,7 @@ class qa_header_payload_demux (gr_unittest.TestCase): signal += [2] * burst_size burst_sizes += [burst_size] return (signal, indexes, total_payload_len, burst_sizes) + def indexes_to_triggers(indexes, signal_len): """ Convert indexes to a mix of trigger signals and tags @@ -588,7 +618,8 @@ class qa_header_payload_demux (gr_unittest.TestCase): signal, indexes, total_payload_len, burst_sizes = create_signal( n_bursts, header_len, max_gap, max_burstsize, fail_rate ) - trigger_signal, trigger_tags = indexes_to_triggers(indexes, len(signal)) + trigger_signal, trigger_tags = indexes_to_triggers( + indexes, len(signal)) # Flow graph data_src = blocks.vector_source_f( signal, False, @@ -614,10 +645,22 @@ class qa_header_payload_demux (gr_unittest.TestCase): ) header_sink = blocks.vector_sink_f() payload_sink = blocks.vector_sink_f() - self.connect_all_blocks(data_src, trigger_src, hpd, mock_header_demod, payload_sink, header_sink) - self.run_tb(payload_sink, total_payload_len, header_sink, header_len*n_bursts) - self.assertEqual(header_sink.data(), list([1]*header_len*n_bursts)) - self.assertEqual(payload_sink.data(), list([2]*total_payload_len)) + self.connect_all_blocks( + data_src, + trigger_src, + hpd, + mock_header_demod, + payload_sink, + header_sink) + self.run_tb( + payload_sink, + total_payload_len, + header_sink, + header_len * + n_bursts) + self.assertEqual(header_sink.data(), list([1] * header_len * n_bursts)) + self.assertEqual(payload_sink.data(), list([2] * total_payload_len)) + if __name__ == '__main__': gr_unittest.run(qa_header_payload_demux) diff --git a/gr-digital/python/digital/qa_lfsr.py b/gr-digital/python/digital/qa_lfsr.py index ba03689634..0d7a2ccb94 100644 --- a/gr-digital/python/digital/qa_lfsr.py +++ b/gr-digital/python/digital/qa_lfsr.py @@ -13,6 +13,7 @@ import math from gnuradio import gr, gr_unittest, digital + class test_lfsr(gr_unittest.TestCase): def setUp(self): @@ -26,12 +27,12 @@ class test_lfsr(gr_unittest.TestCase): l = digital.lfsr(1, 1, reglen) result_data = [] - for i in range(4*(reglen+1)): + for i in range(4 * (reglen + 1)): result_data.append(l.next_bit()) - expected_result = 4*([1,] + reglen*[0,]) + expected_result = 4 * ([1, ] + reglen * [0, ]) self.assertFloatTuplesAlmostEqual(expected_result, result_data, 5) + if __name__ == '__main__': gr_unittest.run(test_lfsr) - diff --git a/gr-digital/python/digital/qa_linear_equalizer.py b/gr-digital/python/digital/qa_linear_equalizer.py index 522575db54..1ad3c3bece 100755 --- a/gr-digital/python/digital/qa_linear_equalizer.py +++ b/gr-digital/python/digital/qa_linear_equalizer.py @@ -1,74 +1,110 @@ #!/usr/bin/env python # # Copyright 2020 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# from gnuradio import gr, gr_unittest -import random, numpy +import random +import numpy from gnuradio import digital, blocks, channels + class qa_linear_equalizer(gr_unittest.TestCase): - def unpack_values(self, values_in, bits_per_value, bits_per_symbol): - # verify that 8 is divisible by bits_per_symbol + def unpack_values(self, values_in, bits_per_value, bits_per_symbol): + # verify that 8 is divisible by bits_per_symbol m = bits_per_value / bits_per_symbol # print(m) - mask = 2**(bits_per_symbol)-1 - - if bits_per_value != m*bits_per_symbol: - print("error - bits per symbols must fit nicely into bits_per_value bit values") + mask = 2**(bits_per_symbol) - 1 + + if bits_per_value != m * bits_per_symbol: + print( + "error - bits per symbols must fit nicely into bits_per_value bit values") return [] - + num_values = len(values_in) - num_symbols = int(num_values*( m) ) - + num_symbols = int(num_values * (m)) + cur_byte = 0 cur_bit = 0 out = [] for i in range(num_symbols): - s = (values_in[cur_byte] >> (bits_per_value-bits_per_symbol-cur_bit)) & mask + s = ( + values_in[cur_byte] >> ( + bits_per_value - + bits_per_symbol - + cur_bit)) & mask out.append(s) cur_bit += bits_per_symbol - + if cur_bit >= bits_per_value: cur_bit = 0 cur_byte += 1 - + return out def map_symbols_to_constellation(self, symbols, cons): l = list(map(lambda x: cons.points()[x], symbols)) return l - def setUp(self): random.seed(987654) self.tb = gr.top_block() self.num_data = num_data = 10000 - self.sps = sps = 4 self.eb = eb = 0.35 - self.preamble = preamble = [0x27,0x2F,0x18,0x5D,0x5B,0x2A,0x3F,0x71,0x63,0x3C,0x17,0x0C,0x0A,0x41,0xD6,0x1F,0x4C,0x23,0x65,0x68,0xED,0x1C,0x77,0xA7,0x0E,0x0A,0x9E,0x47,0x82,0xA4,0x57,0x24,] - - self.payload_size = payload_size = 300 # bytes - self.data = data = [0]*4+[random.getrandbits(8) for i in range(payload_size)] + self.preamble = preamble = [ + 0x27, + 0x2F, + 0x18, + 0x5D, + 0x5B, + 0x2A, + 0x3F, + 0x71, + 0x63, + 0x3C, + 0x17, + 0x0C, + 0x0A, + 0x41, + 0xD6, + 0x1F, + 0x4C, + 0x23, + 0x65, + 0x68, + 0xED, + 0x1C, + 0x77, + 0xA7, + 0x0E, + 0x0A, + 0x9E, + 0x47, + 0x82, + 0xA4, + 0x57, + 0x24, + ] + + self.payload_size = payload_size = 300 # bytes + self.data = data = [0] * 4 + \ + [random.getrandbits(8) for i in range(payload_size)] self.gain = gain = .001 # LMS gain self.corr_thresh = corr_thresh = 3e6 - self.num_taps = num_taps = 16 - - + self.num_taps = num_taps = 16 def tearDown(self): self.tb = None - 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()) @@ -80,9 +116,9 @@ class qa_linear_equalizer(gr_unittest.TestCase): def test_001_identity(self): # Constant modulus signal so no adjustments const = digital.constellation_qpsk() - src_data = const.points()*1000 + src_data = const.points() * 1000 - N = 100 # settling time + N = 100 # settling time expected_data = src_data[N:] result = self.transform(src_data, 0.1, const)[N:] @@ -95,18 +131,36 @@ class qa_linear_equalizer(gr_unittest.TestCase): num_taps = 16 num_samp = 2000 num_test = 500 - cons = digital.constellation_qpsk().base() - rxmod = digital.generic_mod(cons, False, self.sps, True, self.eb, False, False) - modulated_sync_word_pre = digital.modulate_vector_bc(rxmod.to_basic_block(), self.preamble+self.preamble, [1]) - modulated_sync_word = modulated_sync_word_pre[86:(512+86)] # compensate for the RRC filter delay - corr_max = numpy.abs(numpy.dot(modulated_sync_word,numpy.conj(modulated_sync_word))) - corr_calc = self.corr_thresh/(corr_max*corr_max) - preamble_symbols = self.map_symbols_to_constellation(self.unpack_values(self.preamble, 8, 2), cons) + cons = digital.constellation_qpsk().base() + rxmod = digital.generic_mod( + cons, False, self.sps, True, self.eb, False, False) + modulated_sync_word_pre = digital.modulate_vector_bc( + rxmod.to_basic_block(), self.preamble + self.preamble, [1]) + # compensate for the RRC filter delay + modulated_sync_word = modulated_sync_word_pre[86:(512 + 86)] + corr_max = numpy.abs( + numpy.dot( + modulated_sync_word, + numpy.conj(modulated_sync_word))) + corr_calc = self.corr_thresh / (corr_max * corr_max) + preamble_symbols = self.map_symbols_to_constellation( + self.unpack_values(self.preamble, 8, 2), cons) alg = digital.adaptive_algorithm_lms(cons, gain).base() evm = digital.meas_evm_cc(cons, digital.evm_measurement_t.EVM_PERCENT) - leq = digital.linear_equalizer(num_taps, self.sps, alg, False, preamble_symbols, 'corr_est') - correst = digital.corr_est_cc(modulated_sync_word, self.sps, 12, corr_calc, digital.THRESHOLD_ABSOLUTE) + leq = digital.linear_equalizer( + num_taps, + self.sps, + alg, + False, + preamble_symbols, + 'corr_est') + correst = digital.corr_est_cc( + modulated_sync_word, + self.sps, + 12, + corr_calc, + digital.THRESHOLD_ABSOLUTE) constmod = digital.generic_mod( constellation=cons, differential=False, @@ -119,19 +173,19 @@ class qa_linear_equalizer(gr_unittest.TestCase): noise_voltage=0.0, frequency_offset=0.0, epsilon=1.0, - taps=(1.0 + 1.0j, 0.63-.22j, -.1+.07j), + taps=(1.0 + 1.0j, 0.63 - .22j, -.1 + .07j), noise_seed=0, block_tags=False) - vso = blocks.vector_source_b(self.preamble+self.data, True, 1, []) - head = blocks.head(gr.sizeof_float*1, num_samp) + vso = blocks.vector_source_b(self.preamble + self.data, True, 1, []) + head = blocks.head(gr.sizeof_float * 1, num_samp) vsi = blocks.vector_sink_f() self.tb.connect(vso, constmod, chan, correst, leq, evm, head, vsi) self.tb.run() # look at the last 1000 samples, should converge quickly, below 5% EVM - upper_bound = list(20.0*numpy.ones((num_test,))) - lower_bound = list(0.0*numpy.zeros((num_test,))) + upper_bound = list(20.0 * numpy.ones((num_test,))) + lower_bound = list(0.0 * numpy.zeros((num_test,))) output_data = vsi.data() output_data = output_data[-num_test:] self.assertLess(output_data, upper_bound) diff --git a/gr-digital/python/digital/qa_lms_equalizer.py b/gr-digital/python/digital/qa_lms_equalizer.py index 12f6b26bcc..23e3c6f28f 100644 --- a/gr-digital/python/digital/qa_lms_equalizer.py +++ b/gr-digital/python/digital/qa_lms_equalizer.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, digital, blocks + class test_lms_dd_equalizer(gr_unittest.TestCase): def setUp(self): @@ -30,14 +31,15 @@ class test_lms_dd_equalizer(gr_unittest.TestCase): def test_001_identity(self): # Constant modulus signal so no adjustments const = digital.constellation_qpsk() - src_data = const.points()*1000 + src_data = const.points() * 1000 - N = 100 # settling time + N = 100 # settling time expected_data = src_data[N:] result = self.transform(src_data, 0.1, const)[N:] N = -500 self.assertComplexTuplesAlmostEqual(expected_data[N:], result[N:], 5) + if __name__ == "__main__": gr_unittest.run(test_lms_dd_equalizer) diff --git a/gr-digital/python/digital/qa_map.py b/gr-digital/python/digital/qa_map.py index 59d0ed1ee5..384636e595 100644 --- a/gr-digital/python/digital/qa_map.py +++ b/gr-digital/python/digital/qa_map.py @@ -1,16 +1,17 @@ #!/usr/bin/env python # # Copyright 2012,2013 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# from gnuradio import gr, gr_unittest, digital, blocks + class test_map(gr_unittest.TestCase): def setUp(self): @@ -34,15 +35,15 @@ class test_map(gr_unittest.TestCase): def test_001(self): symbols = [0, 0, 0, 0] self.helper(symbols) - + def test_002(self): symbols = [3, 2, 1, 0] self.helper(symbols) def test_003(self): - symbols = [8-1, 32-1, 128, 256-1] + symbols = [8 - 1, 32 - 1, 128, 256 - 1] self.helper(symbols) + if __name__ == '__main__': gr_unittest.run(test_map) - diff --git a/gr-digital/python/digital/qa_meas_evm_cc.py b/gr-digital/python/digital/qa_meas_evm_cc.py index 580d2acce5..3c0196b9d6 100755 --- a/gr-digital/python/digital/qa_meas_evm_cc.py +++ b/gr-digital/python/digital/qa_meas_evm_cc.py @@ -1,20 +1,22 @@ #!/usr/bin/env python # # Copyright 2020 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# from gnuradio import gr, gr_unittest from gnuradio import blocks -import random, numpy +import random +import numpy from gnuradio import digital from gnuradio import channels + class qa_meas_evm_cc(gr_unittest.TestCase): def setUp(self): @@ -30,8 +32,10 @@ class qa_meas_evm_cc(gr_unittest.TestCase): expected_result = list(numpy.zeros((self.num_data,))) self.cons = cons = digital.constellation_qpsk().base() - self.data = data = [random.randrange(len(cons.points())) for x in range(self.num_data)] - self.symbols = symbols = numpy.squeeze([cons.map_to_points_v(i) for i in data]) + self.data = data = [random.randrange( + len(cons.points())) for x in range(self.num_data)] + self.symbols = symbols = numpy.squeeze( + [cons.map_to_points_v(i) for i in data]) evm = digital.meas_evm_cc(cons, digital.evm_measurement_t.EVM_PERCENT) vso = blocks.vector_source_c(symbols, False, 1, []) @@ -50,12 +54,14 @@ class qa_meas_evm_cc(gr_unittest.TestCase): expected_result = list(numpy.zeros((self.num_data,))) self.cons = cons = digital.constellation_qpsk().base() - self.data = data = [random.randrange(len(cons.points())) for x in range(self.num_data)] - self.symbols = symbols = numpy.squeeze([cons.map_to_points_v(i) for i in data]) + self.data = data = [random.randrange( + len(cons.points())) for x in range(self.num_data)] + self.symbols = symbols = numpy.squeeze( + [cons.map_to_points_v(i) for i in data]) evm = digital.meas_evm_cc(cons, digital.evm_measurement_t.EVM_PERCENT) vso = blocks.vector_source_c(symbols, False, 1, []) - mc = blocks.multiply_const_cc(3.0+2.0j) + mc = blocks.multiply_const_cc(3.0 + 2.0j) vsi = blocks.vector_sink_f() self.tb.connect(vso, mc, evm, vsi) @@ -66,12 +72,14 @@ class qa_meas_evm_cc(gr_unittest.TestCase): self.assertNotEqual(expected_result, output_data) def test_qpsk_channel(self): - upper_bound = list(50.0*numpy.ones((self.num_data,))) - lower_bound = list(0.0*numpy.zeros((self.num_data,))) + upper_bound = list(50.0 * numpy.ones((self.num_data,))) + lower_bound = list(0.0 * numpy.zeros((self.num_data,))) self.cons = cons = digital.constellation_qpsk().base() - self.data = data = [random.randrange(len(cons.points())) for x in range(self.num_data)] - self.symbols = symbols = numpy.squeeze([cons.map_to_points_v(i) for i in data]) + self.data = data = [random.randrange( + len(cons.points())) for x in range(self.num_data)] + self.symbols = symbols = numpy.squeeze( + [cons.map_to_points_v(i) for i in data]) chan = channels.channel_model( noise_voltage=0.1, @@ -83,7 +91,7 @@ class qa_meas_evm_cc(gr_unittest.TestCase): evm = digital.meas_evm_cc(cons, digital.evm_measurement_t.EVM_PERCENT) vso = blocks.vector_source_c(symbols, False, 1, []) - mc = blocks.multiply_const_cc(3.0+2.0j) + mc = blocks.multiply_const_cc(3.0 + 2.0j) vsi = blocks.vector_sink_f() self.tb.connect(vso, chan, evm, vsi) @@ -95,12 +103,14 @@ class qa_meas_evm_cc(gr_unittest.TestCase): self.assertGreater(output_data, lower_bound) def test_qam16_channel(self): - upper_bound = list(50.0*numpy.ones((self.num_data,))) - lower_bound = list(0.0*numpy.zeros((self.num_data,))) + upper_bound = list(50.0 * numpy.ones((self.num_data,))) + lower_bound = list(0.0 * numpy.zeros((self.num_data,))) self.cons = cons = digital.constellation_16qam().base() - self.data = data = [random.randrange(len(cons.points())) for x in range(self.num_data)] - self.symbols = symbols = numpy.squeeze([cons.map_to_points_v(i) for i in data]) + self.data = data = [random.randrange( + len(cons.points())) for x in range(self.num_data)] + self.symbols = symbols = numpy.squeeze( + [cons.map_to_points_v(i) for i in data]) chan = channels.channel_model( noise_voltage=0.1, @@ -112,7 +122,7 @@ class qa_meas_evm_cc(gr_unittest.TestCase): evm = digital.meas_evm_cc(cons, digital.evm_measurement_t.EVM_PERCENT) vso = blocks.vector_source_c(symbols, False, 1, []) - mc = blocks.multiply_const_cc(3.0+2.0j) + mc = blocks.multiply_const_cc(3.0 + 2.0j) vsi = blocks.vector_sink_f() self.tb.connect(vso, chan, evm, vsi) @@ -123,5 +133,6 @@ class qa_meas_evm_cc(gr_unittest.TestCase): self.assertLess(output_data, upper_bound) self.assertGreater(output_data, lower_bound) + if __name__ == '__main__': gr_unittest.run(qa_meas_evm_cc) diff --git a/gr-digital/python/digital/qa_mpsk_snr_est.py b/gr-digital/python/digital/qa_mpsk_snr_est.py index 3834aecaf0..50d60103ef 100644 --- a/gr-digital/python/digital/qa_mpsk_snr_est.py +++ b/gr-digital/python/digital/qa_mpsk_snr_est.py @@ -13,21 +13,27 @@ import random from gnuradio import gr, gr_unittest, digital, blocks + def random_bit(): """Create random bits using random() rather than randint(). The latter changed for Python 3.2.""" return random.random() > .5 + + def get_cplx(): "Return a BPSK symbol (complex)" - return complex(2*random_bit() - 1, 0) + return complex(2 * random_bit() - 1, 0) + + def get_n_cplx(): "Return random, normal-distributed complex number" - return complex(random.random()-0.5, random.random()-0.5) + return complex(random.random() - 0.5, random.random() - 0.5) + class test_mpsk_snr_est(gr_unittest.TestCase): def setUp(self): self.tb = gr.top_block() - random.seed(0) # make repeatable + random.seed(0) # make repeatable N = 10000 self._noise = [get_n_cplx() for _ in range(N)] self._bits = [get_cplx() for _ in range(N)] @@ -38,13 +44,13 @@ class test_mpsk_snr_est(gr_unittest.TestCase): def mpsk_snr_est_setup(self, op): result = [] for i in range(1, 6): - src_data = [b+(i*n) for b,n in zip(self._bits, self._noise)] + src_data = [b + (i * n) for b, n in zip(self._bits, self._noise)] src = blocks.vector_source_c(src_data) dst = blocks.null_sink(gr.sizeof_gr_complex) tb = gr.top_block() tb.connect(src, op) tb.connect(op, dst) - tb.run() # run the graph and wait for it to finish + tb.run() # run the graph and wait for it to finish result.append(op.snr()) return result @@ -93,8 +99,8 @@ class test_mpsk_snr_est(gr_unittest.TestCase): expected_result = [8.01, 3.19, 1.97, 2.15, 2.65] actual_result = [] - for i in range(1,6): - src_data = [b+(i*n) for b,n in zip(self._bits, self._noise)] + for i in range(1, 6): + src_data = [b + (i * n) for b, n in zip(self._bits, self._noise)] src = blocks.vector_source_c(src_data) @@ -109,6 +115,7 @@ class test_mpsk_snr_est(gr_unittest.TestCase): actual_result.append(op.snr()) self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 2) + if __name__ == '__main__': # Test various SNR estimators; we're not using a Gaussian # noise source, so these estimates have no real meaning; diff --git a/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py b/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py index ae06f8eaf2..0b1cddbaa6 100644 --- a/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py +++ b/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py @@ -10,16 +10,17 @@ from gnuradio import gr, gr_unittest, digital, blocks import pmt + class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() self.tsb_key = "ts_last" - def tearDown (self): + def tearDown(self): self.tb = None - def test_001_t (self): + def test_001_t(self): """ pretty simple (the carrier allocation here is not a practical OFDM configuration!) """ @@ -34,21 +35,24 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): # ^ DC carrier src = blocks.vector_source_c(tx_symbols, False, 1) alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - occupied_carriers, - pilot_carriers, - pilot_symbols, sync_word, - self.tsb_key) + occupied_carriers, + pilot_carriers, + pilot_symbols, sync_word, + self.tsb_key) sink = blocks.tsb_vector_sink_c(vlen=fft_len, tsb_key=self.tsb_key) self.tb.connect( - src, - blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_symbols), self.tsb_key), - alloc, - sink - ) + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + 1, + len(tx_symbols), + self.tsb_key), + alloc, + sink) self.tb.run() self.assertEqual(sink.data()[0], expected_result) - def test_001_t2 (self): + def test_001_t2(self): """ pretty simple (same as before, but odd fft len) """ @@ -62,18 +66,26 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): # ^ DC carrier src = blocks.vector_source_c(tx_symbols, False, 1) alloc = digital.ofdm_carrier_allocator_cvc( - fft_len, - occupied_carriers, - pilot_carriers, - pilot_symbols, (), - self.tsb_key + fft_len, + occupied_carriers, + pilot_carriers, + pilot_symbols, (), + self.tsb_key ) sink = blocks.tsb_vector_sink_c(vlen=fft_len, tsb_key=self.tsb_key) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_symbols), self.tsb_key), alloc, sink) - self.tb.run () + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + 1, + len(tx_symbols), + self.tsb_key), + alloc, + sink) + self.tb.run() self.assertEqual(sink.data()[0], expected_result) - def test_002_t (self): + def test_002_t(self): """ same, but using negative carrier indices """ @@ -85,21 +97,24 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): expected_result = [1j, 0, 1, 0, 2, 3] src = blocks.vector_source_c(tx_symbols, False, 1) alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - occupied_carriers, - pilot_carriers, - pilot_symbols, (), - self.tsb_key) + occupied_carriers, + pilot_carriers, + pilot_symbols, (), + self.tsb_key) sink = blocks.tsb_vector_sink_c(fft_len) self.tb.connect( - src, - blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_symbols), self.tsb_key), - alloc, - sink - ) - self.tb.run () + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + 1, + len(tx_symbols), + self.tsb_key), + alloc, + sink) + self.tb.run() self.assertEqual(sink.data()[0], expected_result) - def test_002_tb (self): + def test_002_tb(self): """ once again, but this time add a sync word """ @@ -109,7 +124,8 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): pilot_symbols = ((1j,),) occupied_carriers = ((-1, 1, 2),) pilot_carriers = ((3,),) - expected_result = list(sync_word + (1j, 0, 1, 0, 2, 3) + (1j, 0, 4, 0, 5, 6)) + expected_result = list( + sync_word + (1j, 0, 1, 0, 2, 3) + (1j, 0, 4, 0, 5, 6)) special_tag1 = gr.tag_t() special_tag1.offset = 0 special_tag1.key = pmt.string_to_symbol("spam") @@ -131,18 +147,26 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): len_tag_key=self.tsb_key ) sink = blocks.tsb_vector_sink_c(fft_len) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_symbols), self.tsb_key), alloc, sink) - self.tb.run () + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + 1, + len(tx_symbols), + self.tsb_key), + alloc, + sink) + self.tb.run() self.assertEqual(sink.data()[0], 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]) tags_expected = [ - (0, 'spam', 23), - (2, 'eggs', 42), + (0, 'spam', 23), + (2, 'eggs', 42), ] self.assertEqual(tags, tags_expected) - def test_003_t (self): + def test_003_t(self): """ more advanced: - 6 symbols per carrier @@ -152,42 +176,102 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): - add some random tags - don't shift """ - tx_symbols = list(range(1, 16)); # 15 symbols + tx_symbols = list(range(1, 16)) # 15 symbols pilot_symbols = ((1j, 2j), (3j, 4j)) occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),) pilot_carriers = ((2, 13), (3, 12)) - expected_result = list((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 = list( + (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)) fft_len = 16 testtag1 = gr.tag_t() testtag1.offset = 0 testtag1.key = pmt.string_to_symbol('tag1') testtag1.value = pmt.from_long(0) testtag2 = gr.tag_t() - testtag2.offset = 7 # On the 2nd OFDM symbol + testtag2.offset = 7 # On the 2nd OFDM symbol testtag2.key = pmt.string_to_symbol('tag2') testtag2.value = pmt.from_long(0) testtag3 = gr.tag_t() - testtag3.offset = len(tx_symbols)+1 # First OFDM symbol of packet 2 + testtag3.offset = len(tx_symbols) + 1 # First OFDM symbol of packet 2 testtag3.key = pmt.string_to_symbol('tag3') testtag3.value = pmt.from_long(0) testtag4 = gr.tag_t() - testtag4.offset = 2*len(tx_symbols)-1 # Last OFDM symbol of packet 2 + # Last OFDM symbol of packet 2 + testtag4.offset = 2 * len(tx_symbols) - 1 testtag4.key = pmt.string_to_symbol('tag4') testtag4.value = pmt.from_long(0) - src = blocks.vector_source_c(tx_symbols * 2, False, 1, (testtag1, testtag2, testtag3, testtag4)) + src = blocks.vector_source_c( + tx_symbols * 2, False, 1, (testtag1, testtag2, testtag3, testtag4)) alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - occupied_carriers, - pilot_carriers, - pilot_symbols, (), - self.tsb_key, - False) + occupied_carriers, + pilot_carriers, + pilot_symbols, (), + self.tsb_key, + False) sink = blocks.tsb_vector_sink_c(fft_len) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_symbols), self.tsb_key), alloc, sink) - self.tb.run () + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + 1, + len(tx_symbols), + self.tsb_key), + alloc, + sink) + self.tb.run() self.assertEqual(sink.data()[0], expected_result) - tags_found = {'tag1': False, 'tag2': False, 'tag3': False, 'tag4': False} + tags_found = { + 'tag1': False, + 'tag2': False, + 'tag3': False, + 'tag4': False} correct_offsets = {'tag1': 0, 'tag2': 1, 'tag3': 3, 'tag4': 5} for tag in sink.tags(): key = pmt.symbol_to_string(tag.key) @@ -196,49 +280,50 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): self.assertEqual(correct_offsets[key], tag.offset) self.assertTrue(all(tags_found.values())) - def test_004_t (self): + def test_004_t(self): """ Provoking TypeError exceptions providing wrong user input (earlier invisible SIGFPE). """ fft_len = 6 # Occupied carriers - #with self.assertRaises(TypeError) as oc: - #Pybind11 raises this as a ValueError + # with self.assertRaises(TypeError) as oc: + # Pybind11 raises this as a ValueError with self.assertRaises(ValueError) as oc: - alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - [], - [[],], - [[],], - [], - self.tsb_key) + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + [], + [[], ], + [[], ], + [], + self.tsb_key) # Pilot carriers - #Pybind11 raises this as a ValueError + # Pybind11 raises this as a ValueError with self.assertRaises(ValueError) as pc: - alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - [[],], - [], - [[],], - [], - self.tsb_key) + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + [[], ], + [], + [[], ], + [], + self.tsb_key) # Pilot carrier symbols - #Pybind11 raises this as a ValueError + # Pybind11 raises this as a ValueError with self.assertRaises(ValueError) as ps: - alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - [[],], - [[],], - [], - [], - self.tsb_key) + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + [[], ], + [[], ], + [], + [], + self.tsb_key) - - self.assertEqual(str(oc.exception), "Occupied carriers must be of type vector of vector i.e. ((),).") - self.assertEqual(str(pc.exception), "Pilot carriers must be of type vector of vector i.e. ((),).") - self.assertEqual(str(ps.exception), "Pilot symbols must be of type vector of vector i.e. ((),).") + self.assertEqual(str( + oc.exception), "Occupied carriers must be of type vector of vector i.e. ((),).") + self.assertEqual(str(pc.exception), + "Pilot carriers must be of type vector of vector i.e. ((),).") + self.assertEqual(str(ps.exception), + "Pilot symbols must be of type vector of vector i.e. ((),).") if __name__ == '__main__': gr_unittest.run(qa_digital_carrier_allocator_cvc) - diff --git a/gr-digital/python/digital/qa_ofdm_chanest_vcvc.py b/gr-digital/python/digital/qa_ofdm_chanest_vcvc.py index c9222ec0dc..c69d2af984 100644 --- a/gr-digital/python/digital/qa_ofdm_chanest_vcvc.py +++ b/gr-digital/python/digital/qa_ofdm_chanest_vcvc.py @@ -1,11 +1,11 @@ #!/usr/bin/env python # Copyright 2012-2014 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# import sys @@ -16,6 +16,7 @@ import numpy from gnuradio import gr, gr_unittest, blocks, analog, digital import pmt + def shift_tuple(vec, N): """ Shifts a vector by N elements. Fills up with zeros. """ if N > 0: @@ -24,6 +25,7 @@ def shift_tuple(vec, N): N = -N return tuple(vec[N:]) + (0,) * N + def rand_range(min_val, max_val): """ Returns a random value (uniform) from the interval min_val, max_val """ return random.random() * (max_val - min_val) + min_val @@ -31,25 +33,25 @@ def rand_range(min_val, max_val): class qa_ofdm_chanest_vcvc (gr_unittest.TestCase): - def setUp (self): + def setUp(self): random.seed(0) - self.tb = gr.top_block () + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_001_offset_2sym (self): + def test_001_offset_2sym(self): """ Add a frequency offset, check if it's correctly detected. Also add some random tags and see if they come out at the correct position. """ fft_len = 16 carr_offset = -2 - sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0) - sync_symbol2 = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0) - data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0) + sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0) + sync_symbol2 = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0) + data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0) tx_data = shift_tuple(sync_symbol1, carr_offset) + \ - shift_tuple(sync_symbol2, carr_offset) + \ - shift_tuple(data_symbol, carr_offset) + shift_tuple(sync_symbol2, carr_offset) + \ + shift_tuple(data_symbol, carr_offset) tag1 = gr.tag_t() tag1.offset = 0 tag1.key = pmt.string_to_symbol("test_tag_1") @@ -72,25 +74,24 @@ class qa_ofdm_chanest_vcvc (gr_unittest.TestCase): if ptag.key == 'ofdm_sync_chan_taps': ptags[ptag.key] = (None, ptag.offset) expected_tags = { - 'ofdm_sync_carr_offset': (-2, 0), - 'ofdm_sync_chan_taps': (None, 0), - 'test_tag_1': (23, 0), - 'test_tag_2': (42, 0), + 'ofdm_sync_carr_offset': (-2, 0), + 'ofdm_sync_chan_taps': (None, 0), + 'test_tag_1': (23, 0), + 'test_tag_2': (42, 0), } self.assertEqual(ptags, expected_tags) - - def test_002_offset_1sym (self): + def test_002_offset_1sym(self): """ Add a frequency offset, check if it's correctly detected. Difference to previous test is, it only uses one synchronisation symbol. """ fft_len = 16 carr_offset = -2 # This will not correct for +2 because it thinks carrier 14 is used # (because of interpolation) - 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) + 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 = shift_tuple(sync_symbol, carr_offset) + \ - shift_tuple(data_symbol, carr_offset) + shift_tuple(data_symbol, carr_offset) src = blocks.vector_source_c(tx_data, False, fft_len) # 17 is out of bounds! chanest = digital.ofdm_chanest_vcvc(sync_symbol, (), 1, 0, 17) @@ -104,13 +105,14 @@ class qa_ofdm_chanest_vcvc (gr_unittest.TestCase): carr_offset_hat = pmt.to_long(tag.value) self.assertEqual(pmt.to_long(tag.value), carr_offset) - def test_003_channel_no_carroffset (self): + 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) + 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) @@ -122,7 +124,8 @@ class qa_ofdm_chanest_vcvc (gr_unittest.TestCase): 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))) + 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) @@ -130,13 +133,13 @@ class qa_ofdm_chanest_vcvc (gr_unittest.TestCase): self.assertEqual(pmt.c32vector_elements(tag.value), channel) self.assertEqual(sink_chanest.data(), channel) - def test_004_channel_no_carroffset_1sym (self): + 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) + 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) @@ -156,14 +159,14 @@ class qa_ofdm_chanest_vcvc (gr_unittest.TestCase): if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': self.assertEqual(pmt.c32vector_elements(tag.value), channel) - def test_005_both_1sym_force (self): + def test_005_both_1sym_force(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) - ref_symbol = (0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0) - data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0) + sync_symbol = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0) + ref_symbol = (0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 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.5, 3, 2.5, 2, 2.5, 3, 2, 1, 1, 0] src = blocks.vector_source_c(tx_data, False, fft_len) @@ -179,20 +182,22 @@ class qa_ofdm_chanest_vcvc (gr_unittest.TestCase): if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps': self.assertEqual(pmt.c32vector_elements(tag.value), channel) - def test_006_channel_and_carroffset (self): + 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) + # 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] + 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) + shift_tuple(sync_symbol2, carr_offset) + \ + shift_tuple(data_symbol, carr_offset) channel = list(range(fft_len)) src = blocks.vector_source_c(tx_data, False, fft_len) chan = blocks.multiply_const_vcc(channel) @@ -208,27 +213,108 @@ class qa_ofdm_chanest_vcvc (gr_unittest.TestCase): 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(), list(numpy.multiply(shift_tuple(data_symbol, carr_offset), channel))) - + self.assertEqual( + sink.data(), + list( + numpy.multiply( + shift_tuple( + data_symbol, + carr_offset), + channel))) def test_999_all_at_once(self): """docstring for test_999_all_at_once""" fft_len = 32 - # 6 carriers empty, 10 carriers full, 1 DC carrier, 10 carriers full, 5 carriers empty - syncsym_mask = (0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0) - carrier_mask = (0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0) + # 6 carriers empty, 10 carriers full, 1 DC carrier, 10 carriers full, 5 + # carriers empty + syncsym_mask = ( + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0) + carrier_mask = ( + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 0) max_offset = 4 wgn_amplitude = 0.05 min_chan_ampl = 0.1 max_chan_ampl = 5 - n_iter = 20 # The more the accurater + n_iter = 20 # The more the accurater + 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)] + 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) @@ -236,32 +322,43 @@ class qa_ofdm_chanest_vcvc (gr_unittest.TestCase): 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.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 + 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) + 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) + 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))) + return ( + carr_offset, list( + shift_tuple( + rx_sym_est, -carr_offset_hat))) bit_errors = 0 for k in range(n_iter): - sync_sym = [(random.randint(0, 1) * 2 - 1) * syncsym_mask[i] for i in range(fft_len)] - ref_sym = [(random.randint(0, 1) * 2 - 1) * carrier_mask[i] for i in range(fft_len)] - data_sym = [(random.randint(0, 1) * 2 - 1) * carrier_mask[i] for i in range(fft_len)] + sync_sym = [(random.randint(0, 1) * 2 - 1) * syncsym_mask[i] + for i in range(fft_len)] + ref_sym = [(random.randint(0, 1) * 2 - 1) * carrier_mask[i] + for i in range(fft_len)] + data_sym = [(random.randint(0, 1) * 2 - 1) * carrier_mask[i] + for i in range(fft_len)] data_sym[26] = 1 (carr_offset, rx_sym) = run_flow_graph(sync_sym, ref_sym, data_sym) - rx_sym_est = [0,] * fft_len + rx_sym_est = [0, ] * fft_len for i in range(fft_len): if carrier_mask[i] == 0: continue @@ -274,4 +371,3 @@ class qa_ofdm_chanest_vcvc (gr_unittest.TestCase): if __name__ == '__main__': gr_unittest.run(qa_ofdm_chanest_vcvc) - diff --git a/gr-digital/python/digital/qa_ofdm_cyclic_prefixer.py b/gr-digital/python/digital/qa_ofdm_cyclic_prefixer.py index 0d4d4f0fbe..f5eefd60f4 100644 --- a/gr-digital/python/digital/qa_ofdm_cyclic_prefixer.py +++ b/gr-digital/python/digital/qa_ofdm_cyclic_prefixer.py @@ -14,12 +14,13 @@ Unit tests for OFDM cyclic prefixer. from gnuradio import gr, gr_unittest, digital, blocks import pmt + class test_ofdm_cyclic_prefixer (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_wo_tags_no_rolloff(self): @@ -40,9 +41,17 @@ class test_ofdm_cyclic_prefixer (gr_unittest.TestCase): 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(list(range(1, fft_len+1)) * 2, False, fft_len) + 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( + list( + 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) @@ -54,22 +63,32 @@ class test_ofdm_cyclic_prefixer (gr_unittest.TestCase): fft_len = 8 cp_len = 2 tag_name = "ts_last" - 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] + 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] 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(list(range(1, fft_len+1)) * 2, False, fft_len, (tag2,)) - cp = digital.ofdm_cyclic_prefixer(fft_len, fft_len + cp_len, 2, tag_name) + src = blocks.vector_source_c( + list(range(1, fft_len + 1)) * 2, False, fft_len, (tag2,)) + cp = digital.ofdm_cyclic_prefixer( + fft_len, fft_len + cp_len, 2, tag_name) sink = blocks.tsb_vector_sink_c(tsb_key=tag_name) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, 2, tag_name), cp, sink) + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + fft_len, + 2, + tag_name), + cp, + sink) self.tb.run() self.assertEqual(sink.data()[0], 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 = [ - (fft_len+cp_len, "random_tag", 42) + (fft_len + cp_len, "random_tag", 42) ] self.assertEqual(tags, expected_tags) @@ -77,13 +96,13 @@ class test_ofdm_cyclic_prefixer (gr_unittest.TestCase): "Two CP lengths, no rolloff and no tags." fft_len = 8 cp_lengths = (3, 2, 2) - expected_result = [5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, # 1 + expected_result = [5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, # 1 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, # 2 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, # 3 - 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, # 4 + 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, # 4 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, # 5 - ] - src = blocks.vector_source_c(list(range(fft_len))*5, False, fft_len) + ] + src = blocks.vector_source_c(list(range(fft_len)) * 5, False, fft_len) cp = digital.ofdm_cyclic_prefixer(fft_len, cp_lengths) sink = blocks.vector_sink_c() self.tb.connect(src, cp, sink) @@ -95,13 +114,21 @@ class test_ofdm_cyclic_prefixer (gr_unittest.TestCase): fft_len = 8 cp_lengths = (3, 2, 2) rolloff = 2 - expected_result = [6.0/2,7,8,1,2,3,4,5,6,7,8, #1 - 7.0/2 + 1.0/2,8,1,2,3,4,5,6,7,8, #2 - 7.0/2 + 1.0/2,8,1,2,3,4,5,6,7,8, #3 - 6.0/2 + 1.0/2,7,8,1,2,3,4,5,6,7,8,#4 - 7.0/2 + 1.0/2,8,1,2,3,4,5,6,7,8 #5 - ] - src = blocks.vector_source_c(list(range(1, fft_len+1))*5, False, fft_len) + expected_result = [6.0 / 2, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, # 1 + 7.0 / 2 + 1.0 / 2, 8, 1, 2, 3, 4, 5, 6, 7, 8, # 2 + 7.0 / 2 + 1.0 / 2, 8, 1, 2, 3, 4, 5, 6, 7, 8, # 3 + 6.0 / 2 + 1.0 / 2, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, # 4 + 7.0 / 2 + 1.0 / 2, 8, 1, 2, 3, 4, 5, 6, 7, 8 # 5 + ] + src = blocks.vector_source_c( + list( + range( + 1, + fft_len + + 1)) * + 5, + False, + fft_len) cp = digital.ofdm_cyclic_prefixer(fft_len, cp_lengths, rolloff) sink = blocks.vector_sink_c() self.tb.connect(src, cp, sink) @@ -115,8 +142,8 @@ class test_ofdm_cyclic_prefixer (gr_unittest.TestCase): rolloff = 2 tag_name = "ts_last" expected_result = [ - 6.0/2, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, #1 - 7.0/2+1.0/2, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1.0/2 #Last tail + 6.0 / 2, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, # 1 + 7.0 / 2 + 1.0 / 2, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1.0 / 2 # Last tail ] # First test tag tag0 = gr.tag_t() @@ -128,10 +155,20 @@ class test_ofdm_cyclic_prefixer (gr_unittest.TestCase): tag1.offset = 1 tag1.key = pmt.string_to_symbol("second_tag") tag1.value = pmt.from_long(42) - src = blocks.vector_source_c(list(range(1, fft_len+1)) * 2, False, fft_len, (tag0, tag1)) - cp = digital.ofdm_cyclic_prefixer(fft_len, cp_lengths, rolloff, tag_name) + src = blocks.vector_source_c( + list(range(1, fft_len + 1)) * 2, False, fft_len, (tag0, tag1)) + cp = digital.ofdm_cyclic_prefixer( + fft_len, cp_lengths, rolloff, tag_name) sink = blocks.tsb_vector_sink_c(tsb_key=tag_name) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, 2, tag_name), cp, sink) + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + fft_len, + 2, + tag_name), + cp, + sink) self.tb.run() self.assertEqual(sink.data()[0], expected_result) tags = [gr.tag_to_python(x) for x in sink.tags()] diff --git a/gr-digital/python/digital/qa_ofdm_frame_equalizer_vcvc.py b/gr-digital/python/digital/qa_ofdm_frame_equalizer_vcvc.py index a1b2a2e070..730769e839 100755 --- a/gr-digital/python/digital/qa_ofdm_frame_equalizer_vcvc.py +++ b/gr-digital/python/digital/qa_ofdm_frame_equalizer_vcvc.py @@ -13,16 +13,17 @@ import numpy from gnuradio import gr, gr_unittest, digital, blocks import pmt + class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() self.tsb_key = "tsb_key" - def tearDown (self): + def tearDown(self): self.tb = None - def test_001_simple (self): + def test_001_simple(self): """ Very simple functionality testing: - static equalizer - init channel state with all ones @@ -34,7 +35,7 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase): fft_len = 8 equalizer = digital.ofdm_equalizer_static(fft_len) n_syms = 3 - tx_data = [1,] * fft_len * n_syms + tx_data = [1, ] * fft_len * n_syms chan_tag = gr.tag_t() chan_tag.offset = 0 chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps") @@ -43,16 +44,21 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase): random_tag.offset = 1 random_tag.key = pmt.string_to_symbol("foo") random_tag.value = pmt.from_long(42) - src = blocks.vector_source_c(tx_data, False, fft_len, (chan_tag, random_tag)) - eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, self.tsb_key) + src = blocks.vector_source_c( + tx_data, False, fft_len, (chan_tag, random_tag)) + eq = digital.ofdm_frame_equalizer_vcvc( + equalizer.base(), 0, self.tsb_key) sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key) self.tb.connect( src, - blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key), + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + fft_len, + n_syms, + self.tsb_key), eq, - sink - ) - self.tb.run () + sink) + self.tb.run() # Check data self.assertEqual(tx_data, sink.data()[0]) # Check tags @@ -65,32 +71,36 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase): } self.assertEqual(tag_dict, expected_dict) - def test_001b_simple_skip_nothing (self): + def test_001b_simple_skip_nothing(self): """ Same as before, but put a skip-header in there """ fft_len = 8 equalizer = digital.ofdm_equalizer_static(fft_len, symbols_skipped=1) n_syms = 3 - tx_data = [1,] * fft_len * n_syms + tx_data = [1, ] * fft_len * n_syms chan_tag = gr.tag_t() chan_tag.offset = 0 chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps") chan_tag.value = pmt.init_c32vector(fft_len, (1,) * fft_len) src = blocks.vector_source_c(tx_data, False, fft_len, (chan_tag,)) - eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, self.tsb_key) + eq = digital.ofdm_frame_equalizer_vcvc( + equalizer.base(), 0, self.tsb_key) sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key) self.tb.connect( src, - blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key), + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + fft_len, + n_syms, + self.tsb_key), eq, - sink - ) - self.tb.run () + sink) + self.tb.run() # Check data self.assertEqual(tx_data, sink.data()[0]) - def test_001c_carrier_offset_no_cp (self): + def test_001c_carrier_offset_no_cp(self): """ Same as before, but put a carrier offset in there """ @@ -100,7 +110,7 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase): carr_offset = 1 occupied_carriers = ((-2, -1, 1, 2),) tx_data = ( - 0, 0, 0, -1j, -1j, 0, -1j, -1j, + 0, 0, 0, -1j, -1j, 0, -1j, -1j, ) # The rx'd signal is shifted rx_expected = (0, 0, 1, 1, 0, 1, 1, 0) * n_syms @@ -109,25 +119,32 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase): chan_tag.offset = 0 chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps") # Note: this is shifted to the correct position! - chan_tag.value = pmt.init_c32vector(fft_len, (0, 0, -1j, -1j, 0, -1j, -1j, 0)) + chan_tag.value = pmt.init_c32vector( + fft_len, (0, 0, -1j, -1j, 0, -1j, -1j, 0)) offset_tag = gr.tag_t() offset_tag.offset = 0 offset_tag.key = pmt.string_to_symbol("ofdm_sync_carr_offset") offset_tag.value = pmt.from_long(carr_offset) - src = blocks.vector_source_c(tx_data, False, fft_len, (chan_tag, offset_tag)) - eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), cp_len, self.tsb_key) + src = blocks.vector_source_c( + tx_data, False, fft_len, (chan_tag, offset_tag)) + eq = digital.ofdm_frame_equalizer_vcvc( + equalizer.base(), cp_len, self.tsb_key) sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key) self.tb.connect( src, - blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key), + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + fft_len, + n_syms, + self.tsb_key), eq, - sink - ) - self.tb.run () + sink) + self.tb.run() # Check data - self.assertComplexTuplesAlmostEqual(rx_expected, sink.data()[0], places=4) + self.assertComplexTuplesAlmostEqual( + rx_expected, sink.data()[0], places=4) - def test_001c_carrier_offset_cp (self): + def test_001c_carrier_offset_cp(self): """ Same as before, but put a carrier offset in there and a CP """ @@ -139,9 +156,9 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase): occupied_carriers = ((-2, -1, 1, 2),) carr_offset = -1 tx_data = ( - 0,-1j,-1j, 0,-1j,-1j, 0, 0, - 0, -1, -1, 0, -1, -1, 0, 0, - 0, 1j, 1j, 0, 1j, 1j, 0, 0, + 0, -1j, -1j, 0, -1j, -1j, 0, 0, + 0, -1, -1, 0, -1, -1, 0, 0, + 0, 1j, 1j, 0, 1j, 1j, 0, 0, ) # Rx'd signal is corrected rx_expected = (0, 0, 1, 1, 0, 1, 1, 0) * n_syms @@ -154,68 +171,87 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase): offset_tag.offset = 0 offset_tag.key = pmt.string_to_symbol("ofdm_sync_carr_offset") offset_tag.value = pmt.from_long(carr_offset) - src = blocks.vector_source_c(tx_data, False, fft_len, (chan_tag, offset_tag)) - eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), cp_len, self.tsb_key) + src = blocks.vector_source_c( + tx_data, False, fft_len, (chan_tag, offset_tag)) + eq = digital.ofdm_frame_equalizer_vcvc( + equalizer.base(), cp_len, self.tsb_key) sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key) self.tb.connect( src, - blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key), + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + fft_len, + n_syms, + self.tsb_key), eq, - sink - ) - self.tb.run () + sink) + self.tb.run() # Check data - self.assertComplexTuplesAlmostEqual(rx_expected, sink.data()[0], places=4) + self.assertComplexTuplesAlmostEqual( + rx_expected, sink.data()[0], places=4) - - def test_002_static (self): + def test_002_static(self): """ - Add a simple channel - Make symbols QPSK """ 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 + 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] + 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)], [] + [], [], [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) + 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 (but less than \pi/2) - 0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here! + 0, 0, 1, 1, 0, 1, 1, 0, + # These coefficients will be rotated slightly (but less than \pi/2) + 0, 0, 1, 1, 0, 1, 1, 0, + 0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here! 0, 0, 1j, 1j, 0, 1j, 1j, 0 ] channel = [ - 0, 0, 1, 1, 0, 1, 1, 0, - 0, 0, 1, 1, 0, 1, 1, 0, # These coefficients will be rotated slightly (but less than \pi/2) - 0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here! + 0, 0, 1, 1, 0, 1, 1, 0, + # These coefficients will be rotated slightly (but less than \pi/2) + 0, 0, 1, 1, 0, 1, 1, 0, + 0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here! 0, 0, 1j, 1j, 0, 1j, 1j, 0 ] - 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)) + 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)) chan_tag = gr.tag_t() chan_tag.offset = 0 chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps") chan_tag.value = pmt.init_c32vector(fft_len, channel[:fft_len]) - src = blocks.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len, (chan_tag,)) + src = blocks.vector_source_c(numpy.multiply( + tx_signal, channel), False, fft_len, (chan_tag,)) sink = blocks.tsb_vector_sink_c(vlen=fft_len, tsb_key=self.tsb_key) - eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, self.tsb_key, True) + eq = digital.ofdm_frame_equalizer_vcvc( + equalizer.base(), 0, self.tsb_key, True) self.tb.connect( - src, - blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, len(tx_data) // fft_len, self.tsb_key), - eq, - sink - ) - self.tb.run () - rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()[0]] + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + fft_len, + len(tx_data) // + fft_len, + self.tsb_key), + eq, + sink) + self.tb.run() + rx_data = [ + cnst.decision_maker_v( + (x,)) if x != 0 else -1 for x in sink.data()[0]] # Check data self.assertEqual(tx_data, rx_data) # Check tags @@ -228,14 +264,17 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase): else: tag_dict[ptag.key] = pmt.to_python(tag.value) expected_dict = { - 'ofdm_sync_chan_taps': channel[-fft_len:] + 'ofdm_sync_chan_taps': channel[-fft_len:] } # Won't be exactly the same when compiled with -fcx-limited-range - self.assertTrue(numpy.allclose(tag_dict['ofdm_sync_chan_taps'], expected_dict['ofdm_sync_chan_taps'])) + self.assertTrue( + numpy.allclose( + tag_dict['ofdm_sync_chan_taps'], + expected_dict['ofdm_sync_chan_taps'])) expected_dict['ofdm_sync_chan_taps'] = tag_dict['ofdm_sync_chan_taps'] self.assertEqual(tag_dict, expected_dict) - def test_002_static_wo_tags (self): + def test_002_static_wo_tags(self): """ Same as before, but the input stream has no tag. We specify the frame size in the constructor. We also specify a tag key, so the output stream *should* have @@ -244,145 +283,200 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase): fft_len = 8 n_syms = 4 # 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 + 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] + 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)], [] + [], [], [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) + 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 (below)... - 0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here! + 0, 0, 1, 1, 0, 1, 1, 0, + # These coefficients will be rotated slightly (below)... + 0, 0, 1, 1, 0, 1, 1, 0, + 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) - eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, self.tsb_key, False, n_syms) + 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) + eq = digital.ofdm_frame_equalizer_vcvc( + equalizer.base(), 0, self.tsb_key, False, n_syms) sink = blocks.tsb_vector_sink_c(vlen=fft_len, tsb_key=self.tsb_key) self.tb.connect( - src, - blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, len(tx_data) // fft_len, self.tsb_key), - eq, - sink - ) - self.tb.run () - rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()[0]] + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + fft_len, + len(tx_data) // + fft_len, + self.tsb_key), + eq, + sink) + self.tb.run() + rx_data = [ + cnst.decision_maker_v( + (x,)) if x != 0 else -1 for x in sink.data()[0]] self.assertEqual(tx_data, rx_data) # Check TSB Functionality packets = sink.data() self.assertEqual(len(packets), 1) self.assertEqual(len(packets[0]), len(tx_data)) - def test_002_static_wo_tags (self): + 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 + 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] + 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)], [] + [], [], [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) + 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, 1, 1, 0, 1, 1, 0, + # These coefficients will be rotated slightly... + 0, 0, 1, 1, 0, 1, 1, 0, + 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) + 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) + 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.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_002_simpledfe (self): + def test_002_simpledfe(self): """ Use the simple DFE equalizer. """ 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 + 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] + 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)], [] + [], [], [cnst.map_to_points_v(x)[0] for x in (1, 0, 3, 0)], [] ) equalizer = digital.ofdm_equalizer_simpledfe( - fft_len, cnst.base(), occupied_carriers, pilot_carriers, pilot_symbols, 0, 0.01 - ) + fft_len, + cnst.base(), + occupied_carriers, + pilot_carriers, + pilot_symbols, + 0, + 0.01) equalizer_soft = digital.ofdm_equalizer_simpledfe( - fft_len, cnst.base(), occupied_carriers, pilot_carriers, pilot_symbols, 0, 0.01, enable_soft_output=True - ) + fft_len, + cnst.base(), + occupied_carriers, + pilot_carriers, + pilot_symbols, + 0, + 0.01, + enable_soft_output=True) 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, 1, 1, 0, 1, 1, 0, + # These coefficients will be rotated slightly... + 0, 0, 1, 1, 0, 1, 1, 0, + 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)) + 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)) chan_tag = gr.tag_t() chan_tag.offset = 0 chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps") chan_tag.value = pmt.init_c32vector(fft_len, channel[:fft_len]) - src = blocks.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len, (chan_tag,)) - eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, self.tsb_key, True) - eq_soft = digital.ofdm_frame_equalizer_vcvc(equalizer_soft.base(), 0, self.tsb_key, True) + src = blocks.vector_source_c(numpy.multiply( + tx_signal, channel), False, fft_len, (chan_tag,)) + eq = digital.ofdm_frame_equalizer_vcvc( + equalizer.base(), 0, self.tsb_key, True) + eq_soft = digital.ofdm_frame_equalizer_vcvc( + equalizer_soft.base(), 0, self.tsb_key, True) sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key) sink_soft = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key) - stream_to_tagged = blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, len(tx_data) // fft_len, self.tsb_key) + stream_to_tagged = blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, fft_len, len(tx_data) // fft_len, self.tsb_key) self.tb.connect( - src, - stream_to_tagged, - eq, - sink + src, + stream_to_tagged, + eq, + sink ) self.tb.connect( - stream_to_tagged, - eq_soft, - sink_soft + stream_to_tagged, + eq_soft, + sink_soft ) - self.tb.run () + self.tb.run() out_syms = numpy.array(sink.data()[0]) out_syms_soft = numpy.array(sink_soft.data()[0]) - demod = lambda syms: [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in syms] + + def demod(syms): return [ + cnst.decision_maker_v( + (x,)) if x != 0 else -1 for x in syms] rx_data = demod(out_syms) rx_data_soft = demod(out_syms_soft) - ## Uncomment to plot symbols + # Uncomment to plot symbols #import matplotlib.pyplot as plt #def plot_syms(d): plt.figure(); plt.plot(d.real, d.imag, 'b.') # - #plot_syms(out_syms) - #plot_syms(out_syms_soft) - #plt.show() + # plot_syms(out_syms) + # plot_syms(out_syms_soft) + # plt.show() self.assertEqual(tx_data, rx_data) self.assertEqual(rx_data, rx_data_soft) @@ -390,9 +484,9 @@ class qa_ofdm_frame_equalizer_vcvc (gr_unittest.TestCase): self.assertEqual(len(sink.tags()), 1) tag = sink.tags()[0] self.assertEqual(pmt.symbol_to_string(tag.key), "ofdm_sync_chan_taps") - self.assertComplexTuplesAlmostEqual(list(pmt.c32vector_elements(tag.value)), channel[-fft_len:], places=1) + self.assertComplexTuplesAlmostEqual( + list(pmt.c32vector_elements(tag.value)), channel[-fft_len:], places=1) if __name__ == '__main__': gr_unittest.run(qa_ofdm_frame_equalizer_vcvc) - diff --git a/gr-digital/python/digital/qa_ofdm_serializer_vcc.py b/gr-digital/python/digital/qa_ofdm_serializer_vcc.py index 049900a44e..07e801f72a 100644 --- a/gr-digital/python/digital/qa_ofdm_serializer_vcc.py +++ b/gr-digital/python/digital/qa_ofdm_serializer_vcc.py @@ -14,57 +14,76 @@ import numpy from gnuradio import gr, gr_unittest, blocks, fft, analog, digital import pmt + class qa_ofdm_serializer_vcc (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() self.tsb_key = "ts_last" - def tearDown (self): + def tearDown(self): self.tb = None - def test_001_simple (self): + def test_001_simple(self): """ Standard test """ fft_len = 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) + 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 = list(range(1, 16)) + [0, 0, 0] occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),) n_syms = len(tx_symbols) // fft_len src = blocks.vector_source_c(tx_symbols, False, fft_len) - serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, self.tsb_key, "", 0, "", False) + serializer = digital.ofdm_serializer_vcc( + fft_len, occupied_carriers, self.tsb_key, "", 0, "", False) sink = blocks.tsb_vector_sink_c(tsb_key=self.tsb_key) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key), serializer, sink) - self.tb.run () + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + fft_len, + n_syms, + self.tsb_key), + serializer, + sink) + self.tb.run() self.assertEqual(sink.data()[0], expected_result) - def test_001b_shifted (self): + 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, + 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 = list(range(18)) occupied_carriers = ((13, 14, 15, 1, 2, 3), (-4, -2, -1, 1, 2, 4),) n_syms = len(tx_symbols) // fft_len src = blocks.vector_source_c(tx_symbols, False, fft_len) - serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, self.tsb_key) + serializer = digital.ofdm_serializer_vcc( + fft_len, occupied_carriers, self.tsb_key) sink = blocks.tsb_vector_sink_c(tsb_key=self.tsb_key) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key), serializer, sink) - self.tb.run () + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + fft_len, + n_syms, + self.tsb_key), + serializer, + sink) + self.tb.run() self.assertEqual(sink.data()[0], expected_result) - def test_002_with_offset (self): + def test_002_with_offset(self): """ Standard test, carrier offset """ fft_len = 16 - tx_symbols = list(range(1, 16)); - tx_symbols = (0, 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) - carr_offset = 1 # Compare this with tx_symbols from the previous test + tx_symbols = list(range(1, 16)) + tx_symbols = (0, 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) + carr_offset = 1 # Compare this with tx_symbols from the previous test expected_result = list(range(1, 16)) + [0, 0, 0] occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),) n_syms = len(tx_symbols) // fft_len @@ -75,51 +94,68 @@ class qa_ofdm_serializer_vcc (gr_unittest.TestCase): src = blocks.vector_source_c(tx_symbols, False, fft_len, (offsettag,)) sink = blocks.tsb_vector_sink_c(tsb_key=self.tsb_key) serializer = digital.ofdm_serializer_vcc( - fft_len, - occupied_carriers, - self.tsb_key, - "", 0, - "ofdm_sync_carr_offset", - False + fft_len, + occupied_carriers, + self.tsb_key, + "", 0, + "ofdm_sync_carr_offset", + False ) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key), serializer, sink) - self.tb.run () + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + fft_len, + n_syms, + self.tsb_key), + serializer, + sink) + self.tb.run() self.assertEqual(sink.data()[0], expected_result) self.assertEqual(len(sink.tags()), 1) - def test_003_connect (self): + def test_003_connect(self): """ Connect carrier_allocator to ofdm_serializer, make sure output==input """ fft_len = 8 n_syms = 1 occupied_carriers = ((1, 2, 6, 7),) - pilot_carriers = ((3,),(5,)) - pilot_symbols = ((1j,),(-1j,)) + pilot_carriers = ((3,), (5,)) + pilot_symbols = ((1j,), (-1j,)) #tx_data = tuple([numpy.random.randint(0, 10) for x in range(4 * n_syms)]) tx_data = [1, 2, 3, 4] src = blocks.vector_source_c(tx_data, False, 1) alloc = digital.ofdm_carrier_allocator_cvc( - fft_len, - occupied_carriers, - pilot_carriers, - pilot_symbols, - (), # No sync word - self.tsb_key, - True # Output is shifted (default) + fft_len, + occupied_carriers, + pilot_carriers, + pilot_symbols, + (), # No sync word + self.tsb_key, + True # Output is shifted (default) ) serializer = digital.ofdm_serializer_vcc( - alloc, - "", # Len tag key - 0, # Symbols skipped - "", # Carrier offset key - True # Input is shifted (default) + alloc, + "", # Len tag key + 0, # Symbols skipped + "", # Carrier offset key + True # Input is shifted (default) ) sink = blocks.tsb_vector_sink_c(tsb_key=self.tsb_key) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_data), self.tsb_key), alloc, serializer, sink) - self.tb.run () + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + 1, + len(tx_data), + self.tsb_key), + alloc, + serializer, + sink) + self.tb.run() self.assertEqual(sink.data()[0], tx_data) - def test_004_connect (self): + def test_004_connect(self): """ Advanced test: - Allocator -> IFFT -> Frequency offset -> FFT -> Serializer @@ -130,10 +166,10 @@ class qa_ofdm_serializer_vcc (gr_unittest.TestCase): fft_len = 8 n_syms = 1 carr_offset = -2 - freq_offset = 1.0 / fft_len * carr_offset # Normalized frequency + freq_offset = 1.0 / fft_len * carr_offset # Normalized frequency occupied_carriers = ((-2, -1, 1, 2),) - pilot_carriers = ((-3,),(3,)) - pilot_symbols = ((1j,),(-1j,)) + pilot_carriers = ((-3,), (3,)) + pilot_symbols = ((1j,), (-1j,)) tx_data = [1, 2, 3, 4] offsettag = gr.tag_t() offsettag.offset = 0 @@ -141,40 +177,53 @@ class qa_ofdm_serializer_vcc (gr_unittest.TestCase): offsettag.value = pmt.from_long(carr_offset) src = blocks.vector_source_c(tx_data, False, 1, (offsettag,)) alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - occupied_carriers, - pilot_carriers, - pilot_symbols, (), - self.tsb_key) - tx_ifft = fft.fft_vcc(fft_len, False, (1.0 / fft_len,)*fft_len, True) - oscillator = analog.sig_source_c(1.0, analog.GR_COS_WAVE, freq_offset, 1.0) + occupied_carriers, + pilot_carriers, + pilot_symbols, (), + self.tsb_key) + tx_ifft = fft.fft_vcc(fft_len, False, (1.0 / fft_len,) * fft_len, True) + oscillator = analog.sig_source_c( + 1.0, analog.GR_COS_WAVE, freq_offset, 1.0) mixer = blocks.multiply_cc() - rx_fft = fft.fft_vcc(fft_len, True, (), True) + rx_fft = fft.fft_vcc(fft_len, True, (), True) sink2 = blocks.tsb_vector_sink_c(vlen=fft_len, tsb_key=self.tsb_key) self.tb.connect(rx_fft, sink2) serializer = digital.ofdm_serializer_vcc( - alloc, "", 0, "ofdm_sync_carr_offset", True + alloc, "", 0, "ofdm_sync_carr_offset", True ) sink = blocks.tsb_vector_sink_c(tsb_key=self.tsb_key) self.tb.connect( - src, - blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_data), self.tsb_key), - alloc, tx_ifft, - blocks.vector_to_stream(gr.sizeof_gr_complex, fft_len), - (mixer, 0), - blocks.stream_to_vector(gr.sizeof_gr_complex, fft_len), - rx_fft, serializer, sink - ) + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + 1, + len(tx_data), + self.tsb_key), + alloc, + tx_ifft, + blocks.vector_to_stream( + gr.sizeof_gr_complex, + fft_len), + (mixer, + 0), + blocks.stream_to_vector( + gr.sizeof_gr_complex, + fft_len), + rx_fft, + serializer, + sink) self.tb.connect(oscillator, (mixer, 1)) - self.tb.run () - self.assertComplexTuplesAlmostEqual(sink.data()[0][-len(occupied_carriers[0]):], tx_data, places=4) + self.tb.run() + self.assertComplexTuplesAlmostEqual( + sink.data()[0][-len(occupied_carriers[0]):], tx_data, places=4) - def test_005_packet_len_tag (self): + def test_005_packet_len_tag(self): """ Standard test """ fft_len = 16 tx_symbols = list(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) + 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 = list(range(1, 16)) occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),) n_syms = len(tx_symbols) // fft_len @@ -184,21 +233,34 @@ class qa_ofdm_serializer_vcc (gr_unittest.TestCase): 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, (tag2,)) - serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, self.tsb_key, packet_len_tsb_key , 0, "", False) + serializer = digital.ofdm_serializer_vcc( + fft_len, occupied_carriers, self.tsb_key, packet_len_tsb_key, 0, "", False) sink = blocks.tsb_vector_sink_c(tsb_key=packet_len_tsb_key) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key), serializer, sink) - self.tb.run () + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + fft_len, + n_syms, + self.tsb_key), + serializer, + sink) + self.tb.run() self.assertEqual(sink.data()[0], expected_result) - def test_099 (self): + def test_099(self): """ Make sure it fails if it should """ fft_len = 16 - occupied_carriers = ((1, 3, 4, 11, 12, 112),) # Something invalid + occupied_carriers = ((1, 3, 4, 11, 12, 112),) # Something invalid #self.assertRaises(TypeError, digital.ofdm_serializer_vcc, fft_len, occupied_carriers, self.tsb_key) - #pybind11 raises ValueError instead of TypeError - self.assertRaises(ValueError, digital.ofdm_serializer_vcc, fft_len, occupied_carriers, self.tsb_key) + # pybind11 raises ValueError instead of TypeError + self.assertRaises( + ValueError, + digital.ofdm_serializer_vcc, + fft_len, + occupied_carriers, + self.tsb_key) if __name__ == '__main__': gr_unittest.run(qa_ofdm_serializer_vcc) - diff --git a/gr-digital/python/digital/qa_ofdm_sync_sc_cfb.py b/gr-digital/python/digital/qa_ofdm_sync_sc_cfb.py index 5b84e89472..254479363e 100644 --- a/gr-digital/python/digital/qa_ofdm_sync_sc_cfb.py +++ b/gr-digital/python/digital/qa_ofdm_sync_sc_cfb.py @@ -17,24 +17,26 @@ from gnuradio import digital from gnuradio.digital.utils import tagged_streams from gnuradio.digital.ofdm_txrx import ofdm_tx + def make_bpsk_burst(fft_len, cp_len, num_bits): """ Create a burst of a sync symbol and some BPSK bits """ sync_symbol = [ - (random.randint(0, 1)*2)-1 + (random.randint(0, 1) * 2) - 1 for x in range(fft_len // 2) ] * 2 sync_symbols = sync_symbol[-cp_len:] + sync_symbol mod_symbols = [ - (random.randint(0, 1)*2)-1 + (random.randint(0, 1) * 2) - 1 for x in range(num_bits) ] return sync_symbols + mod_symbols + class qa_ofdm_sync_sc_cfb (gr_unittest.TestCase): def setUp(self): random.seed(0) - self.tb = gr.top_block () + self.tb = gr.top_block() def tearDown(self): self.tb = None @@ -47,22 +49,26 @@ class qa_ofdm_sync_sc_cfb (gr_unittest.TestCase): fft_len = 32 cp_len = 4 sig_len = (fft_len + cp_len) * 10 - tx_signal = [0,] * n_zeros + make_bpsk_burst(fft_len, cp_len, sig_len) + tx_signal = [0, ] * n_zeros + make_bpsk_burst(fft_len, cp_len, 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( + 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.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) @@ -71,7 +77,7 @@ class qa_ofdm_sync_sc_cfb (gr_unittest.TestCase): fft_len = 32 cp_len = 4 # This frequency offset is normalized to rads, i.e. \pi == f_s/2 - max_freq_offset = 2*numpy.pi/fft_len # Otherwise, it's coarse + max_freq_offset = 2 * numpy.pi / fft_len # Otherwise, it's coarse freq_offset = ((2 * random.random()) - 1) * max_freq_offset sig_len = (fft_len + cp_len) * 10 tx_signal = make_bpsk_burst(fft_len, cp_len, sig_len) @@ -98,18 +104,17 @@ class qa_ofdm_sync_sc_cfb (gr_unittest.TestCase): cp_len = 4 tx_signal = [] for _ in range(n_bursts): - gap = [0,] * random.randint(0, 2*fft_len) - tx_signal += \ - gap + \ + gap = [0, ] * random.randint(0, 2 * fft_len) + tx_signal += gap + \ make_bpsk_burst(fft_len, cp_len, fft_len * random.randint(5, 23)) # Very loose definition of SNR here - snr = 20 # dB - sigma = 10**(-snr/10) + snr = 20 # dB + sigma = 10**(-snr / 10) # Add noise -- we don't use the channel model blocks, we want to keep # this test as self-contained as possible, and all randomness should # derive from random.seed() above - complex_randn = \ - lambda N: (numpy.random.randn(N) + 1j * numpy.random.randn(N)) * sigma / numpy.sqrt(2) + def complex_randn(N): return (numpy.random.randn( + N) + 1j * numpy.random.randn(N)) * sigma / numpy.sqrt(2) tx_signal += complex_randn(len(tx_signal)) sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = blocks.vector_sink_f() @@ -134,7 +139,7 @@ class qa_ofdm_sync_sc_cfb (gr_unittest.TestCase): fft_len = 64 cp_len = 16 # Here, coarse freq offset is allowed - max_freq_offset = 2*numpy.pi/fft_len * 4 + max_freq_offset = 2 * numpy.pi / fft_len * 4 freq_offset = ((2 * random.random()) - 1) * max_freq_offset packets = [] tagname = "packet_length" @@ -142,17 +147,19 @@ class qa_ofdm_sync_sc_cfb (gr_unittest.TestCase): max_packet_length = 50 for _ in range(n_bursts): packet_length = random.randint(min_packet_length, - max_packet_length+1) + max_packet_length + 1) packet = [random.randint(0, 255) for i in range(packet_length)] packets.append(packet) - data, tags = tagged_streams.packets_to_vectors(packets, tagname, vlen=1) + data, tags = tagged_streams.packets_to_vectors( + packets, tagname, vlen=1) src = blocks.vector_source_b(data, False, 1, tags) mod = ofdm_tx(packet_length_tag_key=tagname) sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len) sink_freq = blocks.vector_sink_f() sink_detect = blocks.vector_sink_b() noise_level = 0.005 - channel = channels.channel_model(noise_level, freq_offset / 2 / numpy.pi) + channel = channels.channel_model( + noise_level, freq_offset / 2 / numpy.pi) self.tb.connect(src, mod, channel, sync, sink_freq) self.tb.connect((sync, 1), sink_detect) self.tb.run() diff --git a/gr-digital/python/digital/qa_ofdm_txrx.py b/gr-digital/python/digital/qa_ofdm_txrx.py index a531080bc2..8bf107ebc0 100644 --- a/gr-digital/python/digital/qa_ofdm_txrx.py +++ b/gr-digital/python/digital/qa_ofdm_txrx.py @@ -1,12 +1,12 @@ #!/usr/bin/env python # # Copyright 2013 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# import random @@ -21,27 +21,46 @@ from gnuradio.digital.ofdm_txrx import ofdm_tx, ofdm_rx from gnuradio.digital.utils import tagged_streams # Set this to true if you need to write out data -LOG_DEBUG_INFO=False +LOG_DEBUG_INFO = False + class ofdm_tx_fg (gr.top_block): - def __init__(self, data, len_tag_key, scramble_bits=False, additional_tags=[]): + def __init__( + self, + data, + len_tag_key, + scramble_bits=False, + additional_tags=[]): gr.top_block.__init__(self, "ofdm_tx") tx_data, tags = tagged_streams.packets_to_vectors((data,), len_tag_key) src = blocks.vector_source_b(data, False, 1, tags + additional_tags) - self.tx = ofdm_tx(packet_length_tag_key=len_tag_key, debug_log=LOG_DEBUG_INFO, scramble_bits=scramble_bits) + self.tx = ofdm_tx( + packet_length_tag_key=len_tag_key, + debug_log=LOG_DEBUG_INFO, + scramble_bits=scramble_bits) self.sink = blocks.vector_sink_c() self.connect(src, self.tx, self.sink) def get_tx_samples(self): return self.sink.data() + class ofdm_rx_fg (gr.top_block): - def __init__(self, samples, len_tag_key, channel=None, prepend_zeros=100, scramble_bits=False): + def __init__( + self, + samples, + len_tag_key, + channel=None, + prepend_zeros=100, + scramble_bits=False): gr.top_block.__init__(self, "ofdm_rx") if prepend_zeros: samples = (0,) * prepend_zeros + tuple(samples) - src = blocks.vector_source_c(list(samples) + [0,] * 1000) - self.rx = ofdm_rx(frame_length_tag_key=len_tag_key, debug_log=LOG_DEBUG_INFO, scramble_bits=scramble_bits) + src = blocks.vector_source_c(list(samples) + [0, ] * 1000) + self.rx = ofdm_rx( + frame_length_tag_key=len_tag_key, + debug_log=LOG_DEBUG_INFO, + scramble_bits=scramble_bits) if channel is not None: self.connect(src, channel, self.rx) else: @@ -52,16 +71,17 @@ class ofdm_rx_fg (gr.top_block): def get_rx_bytes(self): return self.sink.data() + class test_ofdm_txrx (gr_unittest.TestCase): - def setUp (self): + def setUp(self): random.seed(0) - self.tb = gr.top_block () + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_001_tx (self): + def test_001_tx(self): """ Just make sure the Tx works in general """ # This tag gets put onto the first item of the transmit data, # it should be transmitted first, too @@ -73,14 +93,19 @@ class test_ofdm_txrx (gr_unittest.TestCase): n_bytes = 52 n_samples_expected = (numpy.ceil(1.0 * (n_bytes + 4) / 6) + 3) * 80 test_data = [random.randint(0, 255) for x in range(n_bytes)] - tx_fg = ofdm_tx_fg(test_data, len_tag_key, additional_tags=[timing_tag,]) + tx_fg = ofdm_tx_fg( + test_data, + len_tag_key, + additional_tags=[ + timing_tag, + ]) tx_fg.run() self.assertEqual(len(tx_fg.get_tx_samples()), n_samples_expected) tags_rx = [gr.tag_to_python(x) for x in tx_fg.sink.tags()] tags_rx = sorted([(x.offset, x.key, x.value) for x in tags_rx]) tags_expected = [ - (0, 'frame_len', n_samples_expected), - (0, 'tx_timing', 'now'), + (0, 'frame_len', n_samples_expected), + (0, 'tx_timing', 'now'), ] self.assertEqual(tags_rx, tags_expected) @@ -132,7 +157,12 @@ class test_ofdm_txrx (gr_unittest.TestCase): tx_fg.run() tx_samples = tx_fg.get_tx_samples() # Rx - rx_fg = ofdm_rx_fg(tx_samples, len_tag_key, channel, prepend_zeros=100, scramble_bits=True) + rx_fg = ofdm_rx_fg( + tx_samples, + len_tag_key, + channel, + prepend_zeros=100, + scramble_bits=True) rx_fg.run() rx_data = rx_fg.get_rx_bytes() self.assertEqual(list(tx_fg.tx.sync_word1), list(rx_fg.rx.sync_word1)) @@ -160,6 +190,6 @@ class test_ofdm_txrx (gr_unittest.TestCase): rx_data = rx_fg.get_rx_bytes() self.assertEqual(test_data, rx_data) + if __name__ == '__main__': gr_unittest.run(test_ofdm_txrx) - diff --git a/gr-digital/python/digital/qa_packet_format.py b/gr-digital/python/digital/qa_packet_format.py index fe2c82a798..0a6564ca8d 100644 --- a/gr-digital/python/digital/qa_packet_format.py +++ b/gr-digital/python/digital/qa_packet_format.py @@ -8,12 +8,14 @@ # # -import time, struct +import time +import struct import pmt from gnuradio import gr, gr_unittest, digital, blocks from gnuradio.digital import packet_utils + class test_packet_format_fb(gr_unittest.TestCase): def setUp(self): @@ -33,7 +35,6 @@ class test_packet_format_fb(gr_unittest.TestCase): self.tb.msg_connect(formatter, 'header', snk_hdr, 'store') self.tb.msg_connect(formatter, 'payload', snk_pld, 'store') - send_str = b"Hello World" send_pmt = pmt.make_u8vector(len(send_str), 0) for i in range(len(send_str)): @@ -58,7 +59,8 @@ class test_packet_format_fb(gr_unittest.TestCase): header = bytes(result_hdr) payload = bytes(result_pld) - access_code = packet_utils.conv_1_0_string_to_packed_binary_string(packet_utils.default_access_code)[0] + access_code = packet_utils.conv_1_0_string_to_packed_binary_string( + packet_utils.default_access_code)[0] rx_access_code = header[0:len(access_code)] length = len(send_str) @@ -69,7 +71,6 @@ class test_packet_format_fb(gr_unittest.TestCase): self.assertEqual(length, len(payload)) self.assertEqual(send_str, payload[0:length]) - def test_packet_parse_default(self): ac = packet_utils.default_access_code length = '0000000000000001' @@ -96,7 +97,9 @@ class test_packet_format_fb(gr_unittest.TestCase): self.tb.msg_connect(parser_4bps, 'info', snk_hdr_4bps, 'store') self.tb.start() - while (snk_hdr_1bps.num_messages() < 1) or (snk_hdr_4bps.num_messages() < 1): + while ( + snk_hdr_1bps.num_messages() < 1) or ( + snk_hdr_4bps.num_messages() < 1): time.sleep(0.1) self.tb.stop() self.tb.wait() @@ -114,7 +117,6 @@ class test_packet_format_fb(gr_unittest.TestCase): self.assertEqual(pmt.to_long(pmt.dict_ref( result_4bps, pmt.intern('payload symbols'), pmt.PMT_F)), 2) - def test_packet_format_async_counter(self): bps = 2 ac = packet_utils.default_access_code @@ -127,8 +129,7 @@ class test_packet_format_fb(gr_unittest.TestCase): self.tb.msg_connect(formatter, 'header', snk_hdr, 'store') self.tb.msg_connect(formatter, 'payload', snk_pld, 'store') - - send_str = b"Hello World" + 1000*b"xxx" + send_str = b"Hello World" + 1000 * b"xxx" send_pmt = pmt.make_u8vector(len(send_str), 0) for i in range(len(send_str)): pmt.u8vector_set(send_pmt, i, send_str[i]) @@ -151,13 +152,14 @@ class test_packet_format_fb(gr_unittest.TestCase): header = bytes(result_hdr) payload = bytes(result_pld) - access_code = packet_utils.conv_1_0_string_to_packed_binary_string(packet_utils.default_access_code)[0] + access_code = packet_utils.conv_1_0_string_to_packed_binary_string( + packet_utils.default_access_code)[0] rx_access_code = header[0:len(access_code)] length = len(send_str) rx_length = struct.unpack_from(b"!H", header, len(access_code))[0] - rx_bps = struct.unpack_from(b"!H", header, len(access_code)+4)[0] - rx_counter = struct.unpack_from(b"!H", header, len(access_code)+6)[0] + rx_bps = struct.unpack_from(b"!H", header, len(access_code) + 4)[0] + rx_counter = struct.unpack_from(b"!H", header, len(access_code) + 6)[0] self.assertEqual(access_code, rx_access_code) self.assertEqual(length, rx_length) @@ -166,5 +168,6 @@ class test_packet_format_fb(gr_unittest.TestCase): self.assertEqual(length, len(payload)) self.assertEqual(send_str, payload[0:length]) + if __name__ == '__main__': gr_unittest.run(test_packet_format_fb) diff --git a/gr-digital/python/digital/qa_packet_headergenerator_bb.py b/gr-digital/python/digital/qa_packet_headergenerator_bb.py index 59b565cf0a..994ae3cafb 100644 --- a/gr-digital/python/digital/qa_packet_headergenerator_bb.py +++ b/gr-digital/python/digital/qa_packet_headergenerator_bb.py @@ -1,9 +1,9 @@ #!/usr/bin/env python # -#Copyright 2012-2014 Free Software Foundation, Inc. -# +# Copyright 2012-2014 Free Software Foundation, Inc. +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # @@ -12,37 +12,39 @@ from gnuradio import gr, gr_unittest, digital, blocks from gnuradio.gr import packet_utils import pmt + class qa_packet_headergenerator_bb (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() self.tsb_key = "tsb_key" - def tearDown (self): + def tearDown(self): self.tb = None def setup_data_tags(self, data): return packet_utils.packets_to_vectors( - data, - self.tsb_key + data, + self.tsb_key ) - def test_001_12bits (self): + def test_001_12bits(self): # 3 packets: | | | - data, tags = self.setup_data_tags(((1, 2, 3, 4), (1, 2), tuple(range(25)))) + data, tags = self.setup_data_tags( + ((1, 2, 3, 4), (1, 2), tuple(range(25)))) src = blocks.vector_source_b(data, tags=tags) header = digital.packet_headergenerator_bb(12, self.tsb_key) sink = blocks.vector_sink_b() self.tb.connect(src, header, sink) self.tb.run() expected_data = [ - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 ] self.assertEqual(sink.data(), expected_data) - def test_002_32bits (self): + def test_002_32bits(self): # 3 packets: | | | | data, tags = self.setup_data_tags(((1, 2, 3, 4), (1, 2), (1, 2, 3, 4))) src = blocks.vector_source_b(data, tags=tags) @@ -52,18 +54,19 @@ class qa_packet_headergenerator_bb (gr_unittest.TestCase): self.tb.run() expected_data = [ # | Number of symbols | Packet number | CRC - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, - 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1 + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1 ] self.assertEqual(sink.data(), expected_data) - def test_003_12bits_formatter_object (self): + def test_003_12bits_formatter_object(self): # 3 packets: | | | | data, tags = self.setup_data_tags(((1, 2, 3, 4), (1, 2), (1, 2, 3, 4))) src = blocks.vector_source_b(data, tags=tags) formatter_object = digital.packet_header_default(12, self.tsb_key) - header = digital.packet_headergenerator_bb(formatter_object.formatter(), self.tsb_key) + header = digital.packet_headergenerator_bb( + formatter_object.formatter(), self.tsb_key) sink = blocks.vector_sink_b() self.tb.connect(src, header, sink) self.tb.run() @@ -74,15 +77,20 @@ class qa_packet_headergenerator_bb (gr_unittest.TestCase): ] self.assertEqual(sink.data(), expected_data) - def test_004_8bits_formatter_ofdm (self): + def test_004_8bits_formatter_ofdm(self): occupied_carriers = ((1, 2, 3, 5, 6, 7),) # 3 packets: | | | | data, tags = self.setup_data_tags(((1, 2, 3, 4), (1, 2), (1, 2, 3, 4))) src = blocks.vector_source_b(data, tags=tags) - formatter_object = digital.packet_header_ofdm(occupied_carriers, 1, self.tsb_key) + formatter_object = digital.packet_header_ofdm( + occupied_carriers, 1, self.tsb_key) self.assertEqual(formatter_object.header_len(), 6) - self.assertEqual(pmt.symbol_to_string(formatter_object.len_tag_key()), self.tsb_key) - header = digital.packet_headergenerator_bb(formatter_object.formatter(), self.tsb_key) + self.assertEqual( + pmt.symbol_to_string( + formatter_object.len_tag_key()), + self.tsb_key) + header = digital.packet_headergenerator_bb( + formatter_object.formatter(), self.tsb_key) sink = blocks.vector_sink_b() self.tb.connect(src, header, sink) self.tb.run() @@ -93,6 +101,6 @@ class qa_packet_headergenerator_bb (gr_unittest.TestCase): ] self.assertEqual(sink.data(), expected_data) + if __name__ == '__main__': gr_unittest.run(qa_packet_headergenerator_bb) - diff --git a/gr-digital/python/digital/qa_packet_headerparser_b.py b/gr-digital/python/digital/qa_packet_headerparser_b.py index 13840c7cad..897220a59d 100644 --- a/gr-digital/python/digital/qa_packet_headerparser_b.py +++ b/gr-digital/python/digital/qa_packet_headerparser_b.py @@ -1,11 +1,11 @@ #!/usr/bin/env python # Copyright 2012 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# import time @@ -15,16 +15,17 @@ from gnuradio import gr, gr_unittest, blocks, digital from gnuradio.digital.utils import tagged_streams import pmt + class qa_packet_headerparser_b (gr_unittest.TestCase): - def setUp (self): + def setUp(self): random.seed(0) - self.tb = gr.top_block () + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_001_t (self): + def test_001_t(self): """ First header: Packet length 4, packet num 0 Second header: Packet 2, packet num 1 @@ -32,9 +33,9 @@ class qa_packet_headerparser_b (gr_unittest.TestCase): """ encoded_headers = ( # | Number of bytes | Packet number | CRC - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, - 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 ) packet_len_tagname = "packet_len" random_tag = gr.tag_t() @@ -67,10 +68,13 @@ class qa_packet_headerparser_b (gr_unittest.TestCase): header_len = 32 packet_len_tagname = "packet_len" packet_lengths = [random.randint(1, 100) for x in range(N)] - data, tags = tagged_streams.packets_to_vectors([list(range(packet_lengths[i])) for i in range(N)], packet_len_tagname) + data, tags = tagged_streams.packets_to_vectors( + [list(range(packet_lengths[i])) for i in range(N)], packet_len_tagname) src = blocks.vector_source_b(data, False, 1, tags) - header_gen = digital.packet_headergenerator_bb(header_len, packet_len_tagname) - header_parser = digital.packet_headerparser_b(header_len, packet_len_tagname) + header_gen = digital.packet_headergenerator_bb( + header_len, packet_len_tagname) + header_parser = digital.packet_headerparser_b( + header_len, packet_len_tagname) sink = blocks.message_debug() self.tb.connect(src, header_gen, header_parser) self.tb.msg_connect(header_parser, "header_data", sink, "store") @@ -81,9 +85,11 @@ class qa_packet_headerparser_b (gr_unittest.TestCase): self.assertEqual(sink.num_messages(), N) for i in range(N): msg = pmt.to_python(sink.get_message(i)) - self.assertEqual(msg, {'packet_len': packet_lengths[i], 'packet_num': i}) + self.assertEqual( + msg, { + 'packet_len': packet_lengths[i], 'packet_num': i}) - def test_003_ofdm (self): + def test_003_ofdm(self): """ Header 1: 193 bytes Header 2: 8 bytes 2 bits per complex symbol, 32 carriers => 64 bits = 8 bytes per OFDM symbol @@ -93,20 +99,21 @@ class qa_packet_headerparser_b (gr_unittest.TestCase): """ encoded_headers = ( # | Number of bytes | Packet number | CRC - 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, + 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, ) packet_len_tagname = "packet_len" frame_len_tagname = "frame_len" src = blocks.vector_source_b(encoded_headers) header_formatter = digital.packet_header_ofdm( - (list(range(32)),list(range(4)),list(range(8))), # 32/4/8 carriers are occupied (which doesn't matter here) - 1, # 1 OFDM symbol per header (= 32 bits) - packet_len_tagname, - frame_len_tagname, - "packet_num", - 1, # 1 bit per header symbols (BPSK) - 2 # 2 bits per payload symbol (QPSK) + # 32/4/8 carriers are occupied (which doesn't matter here) + (list(range(32)), list(range(4)), list(range(8))), + 1, # 1 OFDM symbol per header (= 32 bits) + packet_len_tagname, + frame_len_tagname, + "packet_num", + 1, # 1 bit per header symbols (BPSK) + 2 # 2 bits per payload symbol (QPSK) ) parser = digital.packet_headerparser_b(header_formatter.base()) sink = blocks.message_debug() @@ -120,8 +127,11 @@ class qa_packet_headerparser_b (gr_unittest.TestCase): msg1 = pmt.to_python(sink.get_message(0)) msg2 = pmt.to_python(sink.get_message(1)) # Multiply with 4 because unpacked bytes have only two bits - self.assertEqual(msg1, {'packet_len': 193*4, 'frame_len': 52, 'packet_num': 0}) - self.assertEqual(msg2, {'packet_len': 8*4, 'frame_len': 1, 'packet_num': 1}) + self.assertEqual(msg1, {'packet_len': 193 * 4, + 'frame_len': 52, 'packet_num': 0}) + self.assertEqual( + msg2, { + 'packet_len': 8 * 4, 'frame_len': 1, 'packet_num': 1}) def test_004_ofdm_scramble(self): """ @@ -131,17 +141,19 @@ class qa_packet_headerparser_b (gr_unittest.TestCase): packet_length = 23 packet_len_tagname = "packet_len" frame_len_tagname = "frame_len" - data, tags = tagged_streams.packets_to_vectors([list(range(packet_length)),list(range(packet_length)),], packet_len_tagname) + data, tags = tagged_streams.packets_to_vectors( + [list(range(packet_length)), list(range(packet_length)), ], packet_len_tagname) src = blocks.vector_source_b(data, False, 1, tags) header_formatter = digital.packet_header_ofdm( - (list(range(32)),), # 32 carriers are occupied (which doesn't matter here) - 1, # 1 OFDM symbol per header (= 32 bits) - packet_len_tagname, - frame_len_tagname, - "packet_num", - 1, # 1 bit per header symbols (BPSK) - 2, # 2 bits per payload symbol (QPSK) - scramble_header=True + # 32 carriers are occupied (which doesn't matter here) + (list(range(32)),), + 1, # 1 OFDM symbol per header (= 32 bits) + packet_len_tagname, + frame_len_tagname, + "packet_num", + 1, # 1 bit per header symbols (BPSK) + 2, # 2 bits per payload symbol (QPSK) + scramble_header=True ) header_gen = digital.packet_headergenerator_bb(header_formatter.base()) header_parser = digital.packet_headerparser_b(header_formatter.base()) @@ -153,11 +165,14 @@ class qa_packet_headerparser_b (gr_unittest.TestCase): self.tb.stop() self.tb.wait() msg = pmt.to_python(sink.get_message(0)) - self.assertEqual(msg, {'packet_len': packet_length, 'packet_num': 0, 'frame_len': 4}) + self.assertEqual( + msg, { + 'packet_len': packet_length, 'packet_num': 0, 'frame_len': 4}) msg = pmt.to_python(sink.get_message(1)) - self.assertEqual(msg, {'packet_len': packet_length, 'packet_num': 1, 'frame_len': 4}) + self.assertEqual( + msg, { + 'packet_len': packet_length, 'packet_num': 1, 'frame_len': 4}) + if __name__ == '__main__': gr_unittest.run(qa_packet_headerparser_b) - - diff --git a/gr-digital/python/digital/qa_pfb_clock_sync.py b/gr-digital/python/digital/qa_pfb_clock_sync.py index f9dfd6d66d..6be41324bc 100644 --- a/gr-digital/python/digital/qa_pfb_clock_sync.py +++ b/gr-digital/python/digital/qa_pfb_clock_sync.py @@ -15,6 +15,7 @@ import time from gnuradio import gr, gr_unittest, filter, digital, blocks + class test_pfb_clock_sync(gr_unittest.TestCase): def setUp(self): @@ -35,8 +36,8 @@ class test_pfb_clock_sync(gr_unittest.TestCase): max_rate_deviation = 0.5 osps = 1 - ntaps = 11 * int(sps*nfilts) - taps = filter.firdes.root_raised_cosine(nfilts, nfilts*sps, + ntaps = 11 * int(sps * nfilts) + taps = filter.firdes.root_raised_cosine(nfilts, nfilts * sps, 1.0, excess_bw, ntaps) self.test = digital.pfb_clock_sync_ccf(sps, loop_bw, taps, @@ -44,7 +45,7 @@ class test_pfb_clock_sync(gr_unittest.TestCase): max_rate_deviation, osps) - data = 10000*[complex(1,0), complex(-1,0)] + data = 10000 * [complex(1, 0), complex(-1, 0)] self.src = blocks.vector_source_c(data, False) # pulse shaping interpolation filter @@ -61,7 +62,7 @@ class test_pfb_clock_sync(gr_unittest.TestCase): self.tb.connect(self.src, self.rrc_filter, self.test, self.snk) self.tb.run() - expected_result = 10000*[complex(1,0), complex(-1,0)] + expected_result = 10000 * [complex(1, 0), complex(-1, 0)] dst_data = self.snk.data() # Only compare last Ncmp samples @@ -71,12 +72,11 @@ class test_pfb_clock_sync(gr_unittest.TestCase): expected_result = expected_result[len_e - Ncmp:] dst_data = dst_data[len_d - Ncmp:] - #for e,d in zip(expected_result, dst_data): + # for e,d in zip(expected_result, dst_data): # print e, d self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 1) - def test02(self): # Test real BPSK sync excess_bw = 0.35 @@ -88,8 +88,8 @@ class test_pfb_clock_sync(gr_unittest.TestCase): max_rate_deviation = 0.5 osps = 1 - ntaps = 11 * int(sps*nfilts) - taps = filter.firdes.root_raised_cosine(nfilts, nfilts*sps, + ntaps = 11 * int(sps * nfilts) + taps = filter.firdes.root_raised_cosine(nfilts, nfilts * sps, 1.0, excess_bw, ntaps) self.test = digital.pfb_clock_sync_fff(sps, loop_bw, taps, @@ -97,7 +97,7 @@ class test_pfb_clock_sync(gr_unittest.TestCase): max_rate_deviation, osps) - data = 10000*[1, -1] + data = 10000 * [1, -1] self.src = blocks.vector_source_f(data, False) # pulse shaping interpolation filter @@ -114,7 +114,7 @@ class test_pfb_clock_sync(gr_unittest.TestCase): self.tb.connect(self.src, self.rrc_filter, self.test, self.snk) self.tb.run() - expected_result = 10000*[1, -1] + expected_result = 10000 * [1, -1] dst_data = self.snk.data() # Only compare last Ncmp samples @@ -124,12 +124,11 @@ class test_pfb_clock_sync(gr_unittest.TestCase): expected_result = expected_result[len_e - Ncmp:] dst_data = dst_data[len_d - Ncmp:] - #for e,d in zip(expected_result, dst_data): + # for e,d in zip(expected_result, dst_data): # print e, d self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 1) - def test03(self): # Test resting of taps excess_bw0 = 0.35 @@ -142,8 +141,8 @@ class test_pfb_clock_sync(gr_unittest.TestCase): max_rate_deviation = 0.5 osps = 1 - ntaps = 11 * int(sps*nfilts) - taps = filter.firdes.root_raised_cosine(nfilts, nfilts*sps, + ntaps = 11 * int(sps * nfilts) + taps = filter.firdes.root_raised_cosine(nfilts, nfilts * sps, 1.0, excess_bw0, ntaps) self.test = digital.pfb_clock_sync_ccf(sps, loop_bw, taps, @@ -158,7 +157,7 @@ class test_pfb_clock_sync(gr_unittest.TestCase): self.tb.start() time.sleep(0.1) - taps = filter.firdes.root_raised_cosine(nfilts, nfilts*sps, + taps = filter.firdes.root_raised_cosine(nfilts, nfilts * sps, 1.0, excess_bw1, ntaps) self.test.update_taps(taps) @@ -180,8 +179,8 @@ class test_pfb_clock_sync(gr_unittest.TestCase): max_rate_deviation = 0.5 osps = 1 - ntaps = 11 * int(sps*nfilts) - taps = filter.firdes.root_raised_cosine(nfilts, nfilts*sps, + ntaps = 11 * int(sps * nfilts) + taps = filter.firdes.root_raised_cosine(nfilts, nfilts * sps, 1.0, excess_bw0, ntaps) self.test = digital.pfb_clock_sync_fff(sps, loop_bw, taps, @@ -196,7 +195,7 @@ class test_pfb_clock_sync(gr_unittest.TestCase): self.tb.start() time.sleep(0.1) - taps = filter.firdes.root_raised_cosine(nfilts, nfilts*sps, + taps = filter.firdes.root_raised_cosine(nfilts, nfilts * sps, 1.0, excess_bw1, ntaps) self.test.update_taps(taps) diff --git a/gr-digital/python/digital/qa_pn_correlator_cc.py b/gr-digital/python/digital/qa_pn_correlator_cc.py index c82229bd95..3f81295bdf 100644 --- a/gr-digital/python/digital/qa_pn_correlator_cc.py +++ b/gr-digital/python/digital/qa_pn_correlator_cc.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, digital, blocks + class test_pn_correlator_cc(gr_unittest.TestCase): def setUp(self): @@ -24,16 +25,17 @@ class test_pn_correlator_cc(gr_unittest.TestCase): def test_001_correlate(self): degree = 10 - length = 2**degree-1 + length = 2**degree - 1 src = digital.glfsr_source_f(degree) - head = blocks.head(gr.sizeof_float, length*length) + head = blocks.head(gr.sizeof_float, length * length) f2c = blocks.float_to_complex() corr = digital.pn_correlator_cc(degree) dst = blocks.vector_sink_c() self.tb.connect(src, head, f2c, corr, dst) self.tb.run() data = dst.data() - self.assertEqual(data[-1], (1.0+0j)) + self.assertEqual(data[-1], (1.0 + 0j)) + if __name__ == '__main__': gr_unittest.run(test_pn_correlator_cc) diff --git a/gr-digital/python/digital/qa_probe_density.py b/gr-digital/python/digital/qa_probe_density.py index 30e24e9522..c2249c1b51 100644 --- a/gr-digital/python/digital/qa_probe_density.py +++ b/gr-digital/python/digital/qa_probe_density.py @@ -1,16 +1,17 @@ #!/usr/bin/env python # # Copyright 2012,2013 Free Software Foundation, Inc. -# +# # This file is part of GNU Radio -# +# # SPDX-License-Identifier: GPL-3.0-or-later # -# +# from gnuradio import gr, gr_unittest, digital, blocks + class test_probe_density(gr_unittest.TestCase): def setUp(self): @@ -30,7 +31,6 @@ class test_probe_density(gr_unittest.TestCase): result_data = op.density() self.assertEqual(expected_data, result_data) - def test_002(self): src_data = [1, 1, 1, 1] expected_data = 1 @@ -54,6 +54,6 @@ class test_probe_density(gr_unittest.TestCase): print(result_data) self.assertAlmostEqual(expected_data, result_data, 5) + if __name__ == '__main__': gr_unittest.run(test_probe_density) - diff --git a/gr-digital/python/digital/qa_scrambler.py b/gr-digital/python/digital/qa_scrambler.py index c6e357bbef..6f6c35134a 100644 --- a/gr-digital/python/digital/qa_scrambler.py +++ b/gr-digital/python/digital/qa_scrambler.py @@ -13,16 +13,19 @@ from gnuradio import gr, gr_unittest, digital, blocks import pmt # See gr-digital/lib/additive_scrambler_bb_impl.cc for reference. + + def additive_scramble_lfsr(mask, seed, reglen, bpb, data): l = digital.lfsr(mask, seed, reglen) out = [] for d in data: scramble_word = 0 - for i in range(0,bpb): + for i in range(0, bpb): scramble_word ^= l.next_bit() << i out.append(d ^ scramble_word) return out + class test_scrambler(gr_unittest.TestCase): def setUp(self): @@ -32,17 +35,19 @@ class test_scrambler(gr_unittest.TestCase): self.tb = None def test_scrambler_descrambler(self): - src_data = [1,]*1000 + src_data = [1, ] * 1000 src = blocks.vector_source_b(src_data, False) - scrambler = digital.scrambler_bb(0x8a, 0x7F, 7) # CCSDS 7-bit scrambler + scrambler = digital.scrambler_bb( + 0x8a, 0x7F, 7) # CCSDS 7-bit scrambler descrambler = digital.descrambler_bb(0x8a, 0x7F, 7) dst = blocks.vector_sink_b() self.tb.connect(src, scrambler, descrambler, dst) self.tb.run() - self.assertEqual(src_data[:-8], dst.data()[8:]) # skip garbage during synchronization + # skip garbage during synchronization + self.assertEqual(src_data[:-8], dst.data()[8:]) def test_additive_scrambler(self): - src_data = [1,]*1000 + src_data = [1, ] * 1000 src = blocks.vector_source_b(src_data, False) scrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7) descrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7) @@ -52,7 +57,7 @@ class test_scrambler(gr_unittest.TestCase): self.assertEqual(src_data, dst.data()) def test_additive_scrambler_reset(self): - src_data = [1,]*200 + src_data = [1, ] * 200 src = blocks.vector_source_b(src_data, False) scrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7, 50) dst = blocks.vector_sink_b() @@ -62,7 +67,7 @@ class test_scrambler(gr_unittest.TestCase): self.assertEqual(output[:50] * 4, output) def test_additive_scrambler_reset_3bpb(self): - src_data = [5,]*200 + src_data = [5, ] * 200 src = blocks.vector_source_b(src_data, False) scrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7, 50, 3) dst = blocks.vector_sink_b() @@ -72,7 +77,7 @@ class test_scrambler(gr_unittest.TestCase): self.assertEqual(output[:50] * 4, output) def test_additive_scrambler_tags(self): - src_data = [1,]*1000 + src_data = [1, ] * 1000 src = blocks.vector_source_b(src_data, False) scrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7, 100) descrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7, 100) @@ -86,9 +91,12 @@ class test_scrambler(gr_unittest.TestCase): reset_tag3 = gr.tag_t() reset_tag3.key = pmt.string_to_symbol(reset_tag_key) reset_tag3.offset = 523 - src = blocks.vector_source_b(src_data, False, 1, (reset_tag1, reset_tag2, reset_tag3)) - scrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7, 100, 1, reset_tag_key) - descrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7, 100, 1, reset_tag_key) + src = blocks.vector_source_b( + src_data, False, 1, (reset_tag1, reset_tag2, reset_tag3)) + scrambler = digital.additive_scrambler_bb( + 0x8a, 0x7f, 7, 100, 1, reset_tag_key) + descrambler = digital.additive_scrambler_bb( + 0x8a, 0x7f, 7, 100, 1, reset_tag_key) dst = blocks.vector_sink_b() self.tb.connect(src, scrambler, descrambler, dst) self.tb.run() @@ -106,13 +114,16 @@ class test_scrambler(gr_unittest.TestCase): reset_tag3 = gr.tag_t() reset_tag3.key = pmt.string_to_symbol(reset_tag_key) reset_tag3.offset = 20 - src = blocks.vector_source_b(src_data * 3, False, 1, (reset_tag1, reset_tag2, reset_tag3)) - scrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7, 0, 8, reset_tag_key) + src = blocks.vector_source_b( + src_data * 3, False, 1, (reset_tag1, reset_tag2, reset_tag3)) + scrambler = digital.additive_scrambler_bb( + 0x8a, 0x7f, 7, 0, 8, reset_tag_key) dst = blocks.vector_sink_b() self.tb.connect(src, scrambler, dst) self.tb.run() expected_data = additive_scramble_lfsr(0x8a, 0x7f, 7, 8, src_data) self.assertEqual(expected_data * 3, dst.data()) + if __name__ == '__main__': gr_unittest.run(test_scrambler) diff --git a/gr-digital/python/digital/qa_simple_correlator.py b/gr-digital/python/digital/qa_simple_correlator.py index 1f5bf5bd72..9b7690c883 100644 --- a/gr-digital/python/digital/qa_simple_correlator.py +++ b/gr-digital/python/digital/qa_simple_correlator.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, blocks, filter, digital + class test_simple_correlator(gr_unittest.TestCase): def setUp(self): @@ -30,7 +31,7 @@ class test_simple_correlator(gr_unittest.TestCase): # Filter taps to expand the data to oversample by 8 # Just using a RRC for some basic filter shape taps = filter.firdes.root_raised_cosine(8, 8, 1.0, 0.5, 21) - + src = blocks.vector_source_b(expected_result) frame = digital.simple_framer(4) unpack = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) @@ -47,5 +48,6 @@ class test_simple_correlator(gr_unittest.TestCase): self.assertEqual(expected_result, result_data) + if __name__ == '__main__': gr_unittest.run(test_simple_correlator) diff --git a/gr-digital/python/digital/qa_simple_framer.py b/gr-digital/python/digital/qa_simple_framer.py index 5c8c65ee86..7acfc82977 100644 --- a/gr-digital/python/digital/qa_simple_framer.py +++ b/gr-digital/python/digital/qa_simple_framer.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, digital, blocks + class test_simple_framer(gr_unittest.TestCase): def setUp(self): @@ -26,11 +27,62 @@ class test_simple_framer(gr_unittest.TestCase): 0xcc, 0xdd, 0xee, 0xff) expected_result = [ - 0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc, 0x00, 0x00, 0x11, 0x22, 0x33, 0x55, - 0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc, 0x01, 0x44, 0x55, 0x66, 0x77, 0x55, - 0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc, 0x02, 0x88, 0x99, 0xaa, 0xbb, 0x55, - 0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc, 0x03, 0xcc, 0xdd, 0xee, 0xff, 0x55 - ] + 0xac, + 0xdd, + 0xa4, + 0xe2, + 0xf2, + 0x8c, + 0x20, + 0xfc, + 0x00, + 0x00, + 0x11, + 0x22, + 0x33, + 0x55, + 0xac, + 0xdd, + 0xa4, + 0xe2, + 0xf2, + 0x8c, + 0x20, + 0xfc, + 0x01, + 0x44, + 0x55, + 0x66, + 0x77, + 0x55, + 0xac, + 0xdd, + 0xa4, + 0xe2, + 0xf2, + 0x8c, + 0x20, + 0xfc, + 0x02, + 0x88, + 0x99, + 0xaa, + 0xbb, + 0x55, + 0xac, + 0xdd, + 0xa4, + 0xe2, + 0xf2, + 0x8c, + 0x20, + 0xfc, + 0x03, + 0xcc, + 0xdd, + 0xee, + 0xff, + 0x55] src = blocks.vector_source_b(src_data) op = digital.simple_framer(4) @@ -41,6 +93,6 @@ class test_simple_framer(gr_unittest.TestCase): result_data = dst.data() self.assertEqual(expected_result, result_data) + if __name__ == '__main__': gr_unittest.run(test_simple_framer) - diff --git a/gr-digital/python/digital/qam.py b/gr-digital/python/digital/qam.py index 29e88ee236..d74866b946 100644 --- a/gr-digital/python/digital/qam.py +++ b/gr-digital/python/digital/qam.py @@ -29,13 +29,16 @@ _def_differential = True # coding is used within but not between each quadrant. _def_mod_code = mod_codes.NO_CODE + def is_power_of_four(x): v = log(x) / log(4) return int(v) == v + def get_bit(x, n): """ Get the n'th bit of integer x (from little end).""" - return (x&(0x01 << n)) >> n + return (x & (0x01 << n)) >> n + def get_bits(x, n, k): """ Get the k bits of integer x starting at bit n(from little end).""" @@ -44,6 +47,7 @@ def get_bits(x, n, k): # Remove all bits bigger than n+k-1 return v % pow(2, k) + def make_differential_constellation(m, gray_coded): """ Create a constellation with m possible symbols where m must be @@ -71,9 +75,9 @@ def make_differential_constellation(m, gray_coded): else: i_gcs = dict([(i, i) for i in range(0, side)]) # The distance between points is found. - step = 1 / (side-0.5) + step = 1 / (side - 0.5) - gc_to_x = [(i_gcs[gc]+0.5)*step for gc in range(0, side)] + gc_to_x = [(i_gcs[gc] + 0.5) * step for gc in range(0, side)] # Takes the (x, y) location of the point with the quadrant along # with the quadrant number. (x, y) are integers referring to which @@ -93,16 +97,18 @@ def make_differential_constellation(m, gray_coded): # First two bits determine quadrant. # Next (k-2)/2 bits determine x position. # Following (k-2)/2 bits determine y position. - # How x and y relate to real and imag depends on quadrant (see get_c function). + # How x and y relate to real and imag depends on quadrant (see get_c + # function). const_map = [] for i in range(m): - y = get_bits(i, 0, (k-2) // 2) - x = get_bits(i, (k-2) // 2, (k-2) // 2) - quad = get_bits(i, k-2, 2) + y = get_bits(i, 0, (k - 2) // 2) + x = get_bits(i, (k - 2) // 2, (k - 2) // 2) + quad = get_bits(i, k - 2, 2) const_map.append(get_c(x, y, quad)) return const_map + def make_non_differential_constellation(m, gray_coded): side = int(pow(m, 0.5)) if (not isinstance(m, int) or m < 4 or not is_power_of_four(m)): @@ -117,22 +123,23 @@ def make_non_differential_constellation(m, gray_coded): else: i_gcs = list(range(0, side)) # The distance between points is found. - step = 2.0 / (side-1) + step = 2.0 / (side - 1) - gc_to_x = [-1 + i_gcs[gc]*step for gc in range(0, side)] + gc_to_x = [-1 + i_gcs[gc] * step for gc in range(0, side)] # First k/2 bits determine x position. # Following k/2 bits determine y position. const_map = [] for i in range(m): y = gc_to_x[get_bits(i, 0, k // 2)] x = gc_to_x[get_bits(i, k // 2, k // 2)] - const_map.append(complex(x,y)) + const_map.append(complex(x, y)) return const_map # ///////////////////////////////////////////////////////////////////////////// # QAM constellation # ///////////////////////////////////////////////////////////////////////////// + def qam_constellation(constellation_points=_def_constellation_points, differential=_def_differential, mod_code=_def_mod_code, @@ -154,18 +161,20 @@ def qam_constellation(constellation_points=_def_constellation_points, else: raise ValueError("Mod code is not implemented for QAM") if differential: - points = make_differential_constellation(constellation_points, gray_coded=False) + points = make_differential_constellation( + constellation_points, gray_coded=False) else: - points = make_non_differential_constellation(constellation_points, gray_coded) + points = make_non_differential_constellation( + constellation_points, gray_coded) side = int(sqrt(constellation_points)) - width = 2.0 / (side-1) + width = 2.0 / (side - 1) # No pre-diff code # Should add one so that we can gray-code the quadrant bits too. pre_diff_code = [] if not large_ampls_to_corners: constellation = digital.constellation_rect(points, pre_diff_code, 4, - side, side, width, width) + side, side, width, width) else: sector_values = large_ampls_to_corners_mapping(side, points, width) constellation = digital.constellation_expl_rect( @@ -173,6 +182,7 @@ def qam_constellation(constellation_points=_def_constellation_points, return constellation + def find_closest_point(p, qs): """ Return in index of the closest point in 'qs' to 'p'. @@ -180,12 +190,13 @@ def find_closest_point(p, qs): min_dist = None min_i = None for i, q in enumerate(qs): - dist = abs(q-p) + dist = abs(q - p) if min_dist is None or dist < min_dist: min_dist = dist min_i = i return min_i + def large_ampls_to_corners_mapping(side, points, width): """ We have a grid that we use for decision making. One additional row/column @@ -222,7 +233,7 @@ def large_ampls_to_corners_mapping(side, points, width): # Value in this extra layer will be mapped to the closest corner rather # than the closest constellation point. extra_layers = 1 - side = side + extra_layers*2 + side = side + extra_layers * 2 # Calculate sector values sector_values = [] for real_x in range(side): @@ -230,10 +241,10 @@ def large_ampls_to_corners_mapping(side, points, width): sector = real_x * side + imag_x # If this sector is a normal constellation sector then # use the center point. - c = ((real_x-side / 2.0+0.5)*width + - (imag_x-side / 2.0+0.5)*width*1j) - if (real_x >= extra_layers and real_x < side-extra_layers - and imag_x >= extra_layers and imag_x < side-extra_layers): + c = ((real_x - side / 2.0 + 0.5) * width + + (imag_x - side / 2.0 + 0.5) * width * 1j) + if (real_x >= extra_layers and real_x < side - extra_layers + and imag_x >= extra_layers and imag_x < side - extra_layers): # This is not an edge row/column. Find closest point. index = find_closest_point(c, points) else: @@ -242,4 +253,5 @@ def large_ampls_to_corners_mapping(side, points, width): sector_values.append(index) return sector_values + modulation_utils.add_type_1_constellation('qam', qam_constellation) diff --git a/gr-digital/python/digital/qam_constellations.py b/gr-digital/python/digital/qam_constellations.py index 2ddaa92d15..42aa31611f 100644 --- a/gr-digital/python/digital/qam_constellations.py +++ b/gr-digital/python/digital/qam_constellations.py @@ -85,6 +85,7 @@ For 16QAM: 3, 2, 1, 0 ''' + def qam_16_0x0_0_1_2_3(): ''' | 0010 0110 | 1110 1010 @@ -95,18 +96,21 @@ def qam_16_0x0_0_1_2_3(): | | 0000 0100 | 1100 1000 ''' - const_points = [-3-3j, -1-3j, 1-3j, 3-3j, - -3-1j, -1-1j, 1-1j, 3-1j, - -3+1j, -1+1j, 1+1j, 3+1j, - -3+3j, -1+3j, 1+3j, 3+3j] + const_points = [-3 - 3j, -1 - 3j, 1 - 3j, 3 - 3j, + -3 - 1j, -1 - 1j, 1 - 1j, 3 - 1j, + -3 + 1j, -1 + 1j, 1 + 1j, 3 + 1j, + -3 + 3j, -1 + 3j, 1 + 3j, 3 + 3j] symbols = [0x0, 0x4, 0xC, 0x8, 0x1, 0x5, 0xD, 0x9, 0x3, 0x7, 0xF, 0xB, 0x2, 0x6, 0xE, 0xA] return (const_points, symbols) + + qam_16 = qam_16_0x0_0_1_2_3 qam_16_0 = qam_16 + def qam_16_0x1_0_1_2_3(): ''' | 0011 0111 | 1111 1011 @@ -120,8 +124,11 @@ def qam_16_0x1_0_1_2_3(): k = 0x1 pi = [0, 1, 2, 3] return constellation_map_generator(qam_16()[0], qam_16()[1], k, pi) + + qam_16_1 = qam_16_0x1_0_1_2_3 + def qam_16_0x2_0_1_2_3(): ''' | 0000 0100 | 1100 1000 @@ -135,8 +142,11 @@ def qam_16_0x2_0_1_2_3(): k = 0x2 pi = [0, 1, 2, 3] return constellation_map_generator(qam_16()[0], qam_16()[1], k, pi) + + qam_16_2 = qam_16_0x2_0_1_2_3 + def qam_16_0x3_0_1_2_3(): ''' | 0001 0101 | 1101 1001 @@ -150,6 +160,8 @@ def qam_16_0x3_0_1_2_3(): k = 0x3 pi = [0, 1, 2, 3] return constellation_map_generator(qam_16()[0], qam_16()[1], k, pi) + + qam_16_3 = qam_16_0x3_0_1_2_3 @@ -166,8 +178,11 @@ def qam_16_0x0_1_0_2_3(): k = 0x0 pi = [1, 0, 2, 3] return constellation_map_generator(qam_16()[0], qam_16()[1], k, pi) + + qam_16_4 = qam_16_0x0_1_0_2_3 + def qam_16_0x1_1_0_2_3(): ''' | 0000 0100 | 1100 1000 @@ -181,8 +196,11 @@ def qam_16_0x1_1_0_2_3(): k = 0x1 pi = [1, 0, 2, 3] return constellation_map_generator(qam_16()[0], qam_16()[1], k, pi) + + qam_16_5 = qam_16_0x1_1_0_2_3 + def qam_16_0x2_1_0_2_3(): ''' | 0011 0111 | 1111 1011 @@ -196,8 +214,11 @@ def qam_16_0x2_1_0_2_3(): k = 0x2 pi = [1, 0, 2, 3] return constellation_map_generator(qam_16()[0], qam_16()[1], k, pi) + + qam_16_6 = qam_16_0x2_1_0_2_3 + def qam_16_0x3_1_0_2_3(): ''' | 0010 0110 | 1110 1010 @@ -211,6 +232,8 @@ def qam_16_0x3_1_0_2_3(): k = 0x3 pi = [1, 0, 2, 3] return constellation_map_generator(qam_16()[0], qam_16()[1], k, pi) + + qam_16_7 = qam_16_0x3_1_0_2_3 @@ -229,7 +252,7 @@ def sd_qam_16_0x0_0_1_2_3(x, Es=1): | 0000 0100 | 1100 1000 ''' - dist = Es*numpy.sqrt(2) + dist = Es * numpy.sqrt(2) boundary = dist / 3.0 dist0 = dist / 6.0 # print "Sample: ", x @@ -242,26 +265,29 @@ def sd_qam_16_0x0_0_1_2_3(x, Es=1): x_im = x.imag if x_re < -boundary: - b3 = boundary*(x_re + dist0) + b3 = boundary * (x_re + dist0) elif x_re < boundary: b3 = x_re else: - b3 = boundary*(x_re - dist0) + b3 = boundary * (x_re - dist0) if x_im < -boundary: - b1 = boundary*(x_im + dist0) + b1 = boundary * (x_im + dist0) elif x_im < boundary: b1 = x_im else: - b1 = boundary*(x_im - dist0) + b1 = boundary * (x_im - dist0) b2 = -abs(x_re) + boundary b0 = -abs(x_im) + boundary - return [(Es / 2.0)*b3, (Es / 2.0)*b2, (Es / 2.0)*b1, (Es / 2.0)*b0] + return [(Es / 2.0) * b3, (Es / 2.0) * b2, (Es / 2.0) * b1, (Es / 2.0) * b0] + + sd_qam_16 = sd_qam_16_0x0_0_1_2_3 sd_qam_16_0 = sd_qam_16 + def sd_qam_16_0x1_0_1_2_3(x, Es=1): ''' | Soft bit LUT generator for constellation: @@ -274,29 +300,32 @@ def sd_qam_16_0x1_0_1_2_3(x, Es=1): | | 0001 0101 | 1101 1001 ''' - x_re = 3*x.real - x_im = 3*x.imag + x_re = 3 * x.real + x_im = 3 * x.imag if x_re < -2: - b3 = 2*(x_re + 1) + b3 = 2 * (x_re + 1) elif x_re < 2: b3 = x_re else: - b3 = 2*(x_re - 1) + b3 = 2 * (x_re - 1) if x_im < -2: - b1 = 2*(x_im + 1) + b1 = 2 * (x_im + 1) elif x_im < 2: b1 = x_im else: - b1 = 2*(x_im - 1) + b1 = 2 * (x_im - 1) b2 = -abs(x_re) + 2 b0 = +abs(x_im) - 2 return [b3, b2, b1, b0] + + sd_qam_16_1 = sd_qam_16_0x1_0_1_2_3 + def sd_qam_16_0x2_0_1_2_3(x, Es=1): ''' | Soft bit LUT generator for constellation: @@ -310,29 +339,32 @@ def sd_qam_16_0x2_0_1_2_3(x, Es=1): | 0010 0110 | 1110 1010 ''' - x_re = 3*x.real - x_im = 3*x.imag + x_re = 3 * x.real + x_im = 3 * x.imag if x_re < -2: - b3 = 2*(x_re + 1) + b3 = 2 * (x_re + 1) elif x_re < 2: b3 = x_re else: - b3 = 2*(x_re - 1) + b3 = 2 * (x_re - 1) if x_im < -2: - b1 = -2*(x_im + 1) + b1 = -2 * (x_im + 1) elif x_im < 2: b1 = -x_im else: - b1 = -2*(x_im - 1) + b1 = -2 * (x_im - 1) b2 = -abs(x_re) + 2 b0 = -abs(x_im) + 2 return [b3, b2, b1, b0] + + sd_qam_16_2 = sd_qam_16_0x2_0_1_2_3 + def sd_qam_16_0x3_0_1_2_3(x, Es=1): ''' | Soft bit LUT generator for constellation: @@ -345,29 +377,32 @@ def sd_qam_16_0x3_0_1_2_3(x, Es=1): | | 0011 0111 | 1111 1011 ''' - x_re = 3*x.real - x_im = 3*x.imag + x_re = 3 * x.real + x_im = 3 * x.imag if x_re < -2: - b3 = 2*(x_re + 1) + b3 = 2 * (x_re + 1) elif x_re < 2: b3 = x_re else: - b3 = 2*(x_re - 1) + b3 = 2 * (x_re - 1) if x_im < -2: - b1 = -2*(x_im + 1) + b1 = -2 * (x_im + 1) elif x_im < 2: b1 = -x_im else: - b1 = -2*(x_im - 1) + b1 = -2 * (x_im - 1) b2 = -abs(x_re) + 2 b0 = +abs(x_im) - 2 return [b3, b2, b1, b0] + + sd_qam_16_3 = sd_qam_16_0x3_0_1_2_3 + def sd_qam_16_0x0_1_0_2_3(x, Es=1): ''' | Soft bit LUT generator for constellation: @@ -380,29 +415,32 @@ def sd_qam_16_0x0_1_0_2_3(x, Es=1): | | 0000 0100 | 1100 1000 ''' - x_re = 3*x.real - x_im = 3*x.imag + x_re = 3 * x.real + x_im = 3 * x.imag if x_re < -2: - b3 = 2*(x_re + 1) + b3 = 2 * (x_re + 1) elif x_re < 2: b3 = x_re else: - b3 = 2*(x_re - 1) + b3 = 2 * (x_re - 1) if x_im < -2: - b0 = 2*(x_im + 1) + b0 = 2 * (x_im + 1) elif x_im < 2: b0 = x_im else: - b0 = 2*(x_im - 1) + b0 = 2 * (x_im - 1) b2 = -abs(x_re) + 2 b1 = -abs(x_im) + 2 return [b3, b2, b1, b0] + + sd_qam_16_4 = sd_qam_16_0x0_1_0_2_3 + def sd_qam_16_0x1_1_0_2_3(x, Es=1): ''' | Soft bit LUT generator for constellation: @@ -415,29 +453,32 @@ def sd_qam_16_0x1_1_0_2_3(x, Es=1): | | 0001 0101 | 1101 1001 ''' - x_re = 3*x.real - x_im = 3*x.imag + x_re = 3 * x.real + x_im = 3 * x.imag if x_re < -2: - b3 = 2*(x_re + 1) + b3 = 2 * (x_re + 1) elif x_re < 2: b3 = x_re else: - b3 = 2*(x_re - 1) + b3 = 2 * (x_re - 1) if x_im < -2: - b0 = -2*(x_im + 1) + b0 = -2 * (x_im + 1) elif x_im < 2: b0 = -x_im else: - b0 = -2*(x_im - 1) + b0 = -2 * (x_im - 1) b2 = -abs(x_re) + 2 b1 = -abs(x_im) + 2 return [b3, b2, b1, b0] + + sd_qam_16_5 = sd_qam_16_0x1_1_0_2_3 + def sd_qam_16_0x2_1_0_2_3(x, Es=1): ''' | Soft bit LUT generator for constellation: @@ -450,29 +491,32 @@ def sd_qam_16_0x2_1_0_2_3(x, Es=1): | | 0010 0110 | 1110 1010 ''' - x_re = 3*x.real - x_im = 3*x.imag + x_re = 3 * x.real + x_im = 3 * x.imag if x_re < -2: - b3 = 2*(x_re + 1) + b3 = 2 * (x_re + 1) elif x_re < 2: b3 = x_re else: - b3 = 2*(x_re - 1) + b3 = 2 * (x_re - 1) if x_im < -2: - b0 = 2*(x_im + 1) + b0 = 2 * (x_im + 1) elif x_im < 2: b0 = x_im else: - b0 = 2*(x_im - 1) + b0 = 2 * (x_im - 1) b2 = -abs(x_re) + 2 b1 = +abs(x_im) - 2 return [b3, b2, b1, b0] + + sd_qam_16_6 = sd_qam_16_0x2_1_0_2_3 + def sd_qam_16_0x3_1_0_2_3(x, Es=1): ''' | Soft bit LUT generator for constellation: @@ -485,25 +529,27 @@ def sd_qam_16_0x3_1_0_2_3(x, Es=1): | | 0011 0111 | 1111 1011 ''' - x_re = 3*x.real - x_im = 3*x.imag + x_re = 3 * x.real + x_im = 3 * x.imag if x_re < -2: - b3 = 2*(x_re + 1) + b3 = 2 * (x_re + 1) elif x_re < 2: b3 = x_re else: - b3 = 2*(x_re - 1) + b3 = 2 * (x_re - 1) if x_im < -2: - b0 = -2*(x_im + 1) + b0 = -2 * (x_im + 1) elif x_im < 2: b0 = -x_im else: - b0 = -2*(x_im - 1) + b0 = -2 * (x_im - 1) b2 = -abs(x_re) + 2 b1 = +abs(x_im) - 2 return [b3, b2, b1, b0] + + sd_qam_16_7 = sd_qam_16_0x3_1_0_2_3 diff --git a/gr-digital/python/digital/qamlike.py b/gr-digital/python/digital/qamlike.py index 88ff423e15..4939f20437 100644 --- a/gr-digital/python/digital/qamlike.py +++ b/gr-digital/python/digital/qamlike.py @@ -13,6 +13,7 @@ This file contains constellations that are similar to QAM, but are not perfect s from . import digital_python from .qam import large_ampls_to_corners_mapping + def qam32_holeinside_constellation(large_ampls_to_corners=False): # First make constellation for one quadrant. # 0 1 2 @@ -36,10 +37,10 @@ def qam32_holeinside_constellation(large_ampls_to_corners=False): ((1, 2), 0b111), ((2, 1), 0b100), ((2, 2), 0b110), - ) - points = [None]*32 + ) + points = [None] * 32 for indices, number in indices_and_numbers: - p_in_quadrant = 0.5+indices[0] + 1j*(0.5+indices[1]) + p_in_quadrant = 0.5 + indices[0] + 1j * (0.5 + indices[1]) for quadrant in range(4): index = number + 8 * quadrant rotation = pow(1j, quadrant) @@ -53,8 +54,8 @@ def qam32_holeinside_constellation(large_ampls_to_corners=False): width = 0.5 pre_diff_code = [] if not large_ampls_to_corners: - constellation = digital_python.constellation_rect(points, pre_diff_code, 4, - side, side, width, width) + constellation = digital_python.constellation_rect( + points, pre_diff_code, 4, side, side, width, width) else: sector_values = large_ampls_to_corners_mapping(side, points, width) constellation = digital_python.constellation_expl_rect( diff --git a/gr-dtv/python/dtv/qa_dtv.py b/gr-dtv/python/dtv/qa_dtv.py index df70ef0445..3e6553e0a9 100644 --- a/gr-dtv/python/dtv/qa_dtv.py +++ b/gr-dtv/python/dtv/qa_dtv.py @@ -11,13 +11,15 @@ from gnuradio import gr, gr_unittest, blocks, digital, dtv -import os, pmt +import os +import pmt from os.path import getsize import numpy as np ts_in_file = os.path.join(os.getenv("srcdir"), "vv009-4kfft.ts") complex_out_file = os.path.join(os.getenv("srcdir"), "vv009-4kfft.cfile") + class test_dtv(gr_unittest.TestCase): def setUp(self): @@ -27,10 +29,11 @@ class test_dtv(gr_unittest.TestCase): self.tb = None def test_000(self): - infile = ts_in_file + infile = ts_in_file outfile = "vv.cfile" testfile = complex_out_file - file_source = blocks.file_source(gr.sizeof_char*1, infile, False, 0, 0) + file_source = blocks.file_source( + gr.sizeof_char * 1, infile, False, 0, 0) file_source.set_begin_tag(pmt.PMT_NIL) bbheader = dtv.dvb_bbheader_bb( dtv.STANDARD_DVBT2, @@ -97,7 +100,7 @@ class test_dtv(gr_unittest.TestCase): dtv.PAPR_TR, dtv.VERSION_111, dtv.PREAMBLE_T2_SISO - ) + ) pilotgenerator = dtv.dvbt2_pilotgenerator_cc( dtv.CARRIERS_NORMAL, dtv.FFTSIZE_4K, @@ -111,7 +114,7 @@ class test_dtv(gr_unittest.TestCase): dtv.EQUALIZATION_OFF, dtv.BANDWIDTH_8_0_MHZ, 4096 - ) + ) paprtr = dtv.dvbt2_paprtr_cc( dtv.CARRIERS_NORMAL, dtv.FFTSIZE_4K, @@ -123,7 +126,7 @@ class test_dtv(gr_unittest.TestCase): 3.0, 10, 4096 - ) + ) ofdm_cyclic_prefixer = digital.ofdm_cyclic_prefixer( 4096, 4096 + 4096 // 32, @@ -137,8 +140,8 @@ class test_dtv(gr_unittest.TestCase): dtv.PREAMBLE_T2_SISO, dtv.SHOWLEVELS_OFF, 3.01 - ) - file_sink = blocks.file_sink(gr.sizeof_gr_complex*1, outfile, False) + ) + file_sink = blocks.file_sink(gr.sizeof_gr_complex * 1, outfile, False) file_sink.set_unbuffered(True) self.tb.connect( file_source, @@ -161,12 +164,13 @@ class test_dtv(gr_unittest.TestCase): self.assertEqual(getsize(outfile), getsize(testfile)) - out_data = np.fromfile(outfile, dtype=np.float32) + out_data = np.fromfile(outfile, dtype=np.float32) expected_data = np.fromfile(testfile, dtype=np.float32) os.remove(outfile) self.assertFloatTuplesAlmostEqual(out_data, expected_data, 5) pass + if __name__ == '__main__': gr_unittest.run(test_dtv) diff --git a/gr-fec/python/fec/qa_ber_bf.py b/gr-fec/python/fec/qa_ber_bf.py index 5bac171573..3fc03c8ccd 100644 --- a/gr-fec/python/fec/qa_ber_bf.py +++ b/gr-fec/python/fec/qa_ber_bf.py @@ -9,7 +9,6 @@ # - import numpy import copy @@ -45,7 +44,8 @@ class test_ber_bf(gr_unittest.TestCase): self.tb.run() data = dst.data() - expected_result = self.log_ber(1., N) # [numpy.log10(1.0 / (8.0 * N)), ] + # [numpy.log10(1.0 / (8.0 * N)), ] + expected_result = self.log_ber(1., N) self.assertFloatTuplesAlmostEqual(expected_result, data, 5) diff --git a/gr-fec/python/fec/qa_depuncture.py b/gr-fec/python/fec/qa_depuncture.py index 88c2eee864..0fdd795c0c 100644 --- a/gr-fec/python/fec/qa_depuncture.py +++ b/gr-fec/python/fec/qa_depuncture.py @@ -30,14 +30,14 @@ class test_depuncture (gr_unittest.TestCase): for n in range(len(self.src_data) // (self.puncsize - self.puncholes)): for i in range(self.puncsize): if _puncpat[i] == 1: - self.expected.append(self.src_data[k]); - k+=1 + self.expected.append(self.src_data[k]) + k += 1 else: self.expected.append(self.sym) def setUp(self): - self.src_data = 2000*list(range(64)) - self.tb = gr.top_block () + self.src_data = 2000 * list(range(64)) + self.tb = gr.top_block() def tearDown(self): self.tb = None @@ -54,8 +54,8 @@ class test_depuncture (gr_unittest.TestCase): self.depuncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.depuncture_bb(self.puncsize, self.puncpat, - self.delay, self.sym) + op = fec.depuncture_bb(self.puncsize, self.puncpat, + self.delay, self.sym) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) @@ -79,8 +79,8 @@ class test_depuncture (gr_unittest.TestCase): self.depuncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.depuncture_bb(self.puncsize, self.puncpat, - self.delay, self.sym) + op = fec.depuncture_bb(self.puncsize, self.puncpat, + self.delay, self.sym) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) @@ -105,8 +105,8 @@ class test_depuncture (gr_unittest.TestCase): self.depuncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.depuncture_bb(self.puncsize, self.puncpat, - self.delay, self.sym) + op = fec.depuncture_bb(self.puncsize, self.puncpat, + self.delay, self.sym) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) @@ -125,16 +125,16 @@ class test_depuncture (gr_unittest.TestCase): # this should be equivalent to a puncpat of the correct size. self.puncsize = 4 - self.puncpat0 = 0x5555 # too many bits set + self.puncpat0 = 0x5555 # too many bits set self.puncpat1 = 0x55 # num bits = puncsize self.delay = 1 self.sym = 0 src = blocks.vector_source_b(self.src_data) - op0 = fec.depuncture_bb(self.puncsize, self.puncpat0, - self.delay, self.sym) - op1 = fec.depuncture_bb(self.puncsize, self.puncpat1, - self.delay, self.sym) + op0 = fec.depuncture_bb(self.puncsize, self.puncpat0, + self.delay, self.sym) + op1 = fec.depuncture_bb(self.puncsize, self.puncpat1, + self.delay, self.sym) dst0 = blocks.vector_sink_b() dst1 = blocks.vector_sink_b() @@ -165,8 +165,8 @@ class test_depuncture (gr_unittest.TestCase): self.depuncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.depuncture_bb(self.puncsize, self.puncpat, - self.delay) + op = fec.depuncture_bb(self.puncsize, self.puncpat, + self.delay) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) @@ -178,5 +178,6 @@ class test_depuncture (gr_unittest.TestCase): self.assertEqual(self.expected, dst_data) + if __name__ == '__main__': gr_unittest.run(test_depuncture) diff --git a/gr-fec/python/fec/qa_ecc_ccsds_27.py b/gr-fec/python/fec/qa_ecc_ccsds_27.py index 22d3c5f9b2..7439e208d0 100644 --- a/gr-fec/python/fec/qa_ecc_ccsds_27.py +++ b/gr-fec/python/fec/qa_ecc_ccsds_27.py @@ -15,13 +15,13 @@ from gnuradio import fec class test_ccsds_27 (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def xtest_ccsds_27 (self): + def xtest_ccsds_27(self): src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) expected = (0, 0, 0, 0, 1, 2, 3, 4, 5, 6) src = blocks.vector_source_b(src_data) diff --git a/gr-fec/python/fec/qa_fecapi_cc.py b/gr-fec/python/fec/qa_fecapi_cc.py index bef3948554..e965d46542 100644 --- a/gr-fec/python/fec/qa_fecapi_cc.py +++ b/gr-fec/python/fec/qa_fecapi_cc.py @@ -9,7 +9,6 @@ # - from gnuradio import gr, gr_unittest from gnuradio import fec @@ -28,16 +27,16 @@ class test_fecapi_cc(gr_unittest.TestCase): frame_size = 30 k = 7 rate = 2 - polys = [109,79] - enc = fec.cc_encoder_make(frame_size*8, k, rate, polys) - dec = fec.cc_decoder.make(frame_size*8, k, rate, polys) + polys = [109, 79] + enc = fec.cc_encoder_make(frame_size * 8, k, rate, polys) + dec = fec.cc_decoder.make(frame_size * 8, k, rate, polys) threading = None - self.test = _qa_helper(4*frame_size, enc, dec, threading) + self.test = _qa_helper(4 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_out = self.test.snk_output.data() - data_in = self.test.snk_input.data()[0:len(data_out)] + data_in = self.test.snk_input.data()[0:len(data_out)] self.assertEqual(data_in, data_out) @@ -45,16 +44,16 @@ class test_fecapi_cc(gr_unittest.TestCase): frame_size = 30 k = 7 rate = 2 - polys = [109,79] - enc = fec.cc_encoder_make(frame_size*8, k, rate, polys) - dec = fec.cc_decoder.make(frame_size*8, k, rate, polys) + polys = [109, 79] + enc = fec.cc_encoder_make(frame_size * 8, k, rate, polys) + dec = fec.cc_decoder.make(frame_size * 8, k, rate, polys) threading = 'ordinary' - self.test = _qa_helper(5*frame_size, enc, dec, threading) + self.test = _qa_helper(5 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_out = self.test.snk_output.data() - data_in = self.test.snk_input.data()[0:len(data_out)] + data_in = self.test.snk_input.data()[0:len(data_out)] self.assertEqual(data_in, data_out) @@ -62,16 +61,16 @@ class test_fecapi_cc(gr_unittest.TestCase): frame_size = 30 k = 7 rate = 2 - polys = [109,79] - enc = fec.cc_encoder_make(frame_size*8, k, rate, polys) - dec = fec.cc_decoder.make(frame_size*8, k, rate, polys) + polys = [109, 79] + enc = fec.cc_encoder_make(frame_size * 8, k, rate, polys) + dec = fec.cc_decoder.make(frame_size * 8, k, rate, polys) threading = 'capillary' - self.test = _qa_helper(5*frame_size, enc, dec, threading) + self.test = _qa_helper(5 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_out = self.test.snk_output.data() - data_in = self.test.snk_input.data()[0:len(data_out)] + data_in = self.test.snk_input.data()[0:len(data_out)] self.assertEqual(data_in, data_out) @@ -79,16 +78,18 @@ class test_fecapi_cc(gr_unittest.TestCase): frame_size = 30 k = 7 rate = 2 - polys = [109,79] - enc = list(map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys)), list(range(0,1)))) - dec = list(map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys)), list(range(0,1)))) + polys = [109, 79] + enc = list(map((lambda a: fec.cc_encoder_make( + frame_size * 8, k, rate, polys)), list(range(0, 1)))) + dec = list(map((lambda a: fec.cc_decoder.make( + frame_size * 8, k, rate, polys)), list(range(0, 1)))) threading = None - self.test = _qa_helper(5*frame_size, enc, dec, threading) + self.test = _qa_helper(5 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_out = self.test.snk_output.data() - data_in = self.test.snk_input.data()[0:len(data_out)] + data_in = self.test.snk_input.data()[0:len(data_out)] self.assertEqual(data_in, data_out) @@ -96,16 +97,18 @@ class test_fecapi_cc(gr_unittest.TestCase): frame_size = 30 k = 7 rate = 2 - polys = [109,79] - enc = list(map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys)), list(range(0,1)))) - dec = list(map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys)), list(range(0,1)))) + polys = [109, 79] + enc = list(map((lambda a: fec.cc_encoder_make( + frame_size * 8, k, rate, polys)), list(range(0, 1)))) + dec = list(map((lambda a: fec.cc_decoder.make( + frame_size * 8, k, rate, polys)), list(range(0, 1)))) threading = 'ordinary' - self.test = _qa_helper(5*frame_size, enc, dec, threading) + self.test = _qa_helper(5 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_out = self.test.snk_output.data() - data_in = self.test.snk_input.data()[0:len(data_out)] + data_in = self.test.snk_input.data()[0:len(data_out)] self.assertEqual(data_in, data_out) @@ -113,16 +116,18 @@ class test_fecapi_cc(gr_unittest.TestCase): frame_size = 30 k = 7 rate = 2 - polys = [109,79] - enc = list(map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys)), list(range(0,1)))) - dec = list(map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys)), list(range(0,1)))) + polys = [109, 79] + enc = list(map((lambda a: fec.cc_encoder_make( + frame_size * 8, k, rate, polys)), list(range(0, 1)))) + dec = list(map((lambda a: fec.cc_decoder.make( + frame_size * 8, k, rate, polys)), list(range(0, 1)))) threading = 'capillary' - self.test = _qa_helper(5*frame_size, enc, dec, threading) + self.test = _qa_helper(5 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_out = self.test.snk_output.data() - data_in = self.test.snk_input.data()[0:len(data_out)] + data_in = self.test.snk_input.data()[0:len(data_out)] self.assertEqual(data_in, data_out) @@ -130,17 +135,19 @@ class test_fecapi_cc(gr_unittest.TestCase): frame_size = 30 k = 7 rate = 2 - polys = [109,79] + polys = [109, 79] mode = fec.CC_TERMINATED - enc = list(map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys, mode=mode)), list(range(0,4)))) - dec = list(map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys, mode=mode)), list(range(0,4)))) + enc = list(map((lambda a: fec.cc_encoder_make( + frame_size * 8, k, rate, polys, mode=mode)), list(range(0, 4)))) + dec = list(map((lambda a: fec.cc_decoder.make( + frame_size * 8, k, rate, polys, mode=mode)), list(range(0, 4)))) threading = 'capillary' - self.test = _qa_helper(4*frame_size, enc, dec, threading) + self.test = _qa_helper(4 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_out = self.test.snk_output.data() - data_in = self.test.snk_input.data()[0:len(data_out)] + data_in = self.test.snk_input.data()[0:len(data_out)] self.assertEqual(data_in, data_out) @@ -148,17 +155,19 @@ class test_fecapi_cc(gr_unittest.TestCase): frame_size = 30 k = 7 rate = 2 - polys = [109,79] + polys = [109, 79] mode = fec.CC_TRUNCATED - enc = list(map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys, mode=mode)), list(range(0,4)))) - dec = list(map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys, mode=mode)), list(range(0,4)))) + enc = list(map((lambda a: fec.cc_encoder_make( + frame_size * 8, k, rate, polys, mode=mode)), list(range(0, 4)))) + dec = list(map((lambda a: fec.cc_decoder.make( + frame_size * 8, k, rate, polys, mode=mode)), list(range(0, 4)))) threading = 'capillary' - self.test = _qa_helper(4*frame_size, enc, dec, threading) + self.test = _qa_helper(4 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_out = self.test.snk_output.data() - data_in = self.test.snk_input.data()[0:len(data_out)] + data_in = self.test.snk_input.data()[0:len(data_out)] self.assertEqual(data_in, data_out) @@ -166,19 +175,22 @@ class test_fecapi_cc(gr_unittest.TestCase): frame_size = 30 k = 7 rate = 2 - polys = [109,79] + polys = [109, 79] mode = fec.CC_TAILBITING - enc = list(map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys, mode=mode)), list(range(0,4)))) - dec = list(map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys, mode=mode)), list(range(0,4)))) + enc = list(map((lambda a: fec.cc_encoder_make( + frame_size * 8, k, rate, polys, mode=mode)), list(range(0, 4)))) + dec = list(map((lambda a: fec.cc_decoder.make( + frame_size * 8, k, rate, polys, mode=mode)), list(range(0, 4)))) threading = 'capillary' - self.test = _qa_helper(4*frame_size, enc, dec, threading) + self.test = _qa_helper(4 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_out = self.test.snk_output.data() - data_in = self.test.snk_input.data()[0:len(data_out)] + data_in = self.test.snk_input.data()[0:len(data_out)] self.assertEqual(data_in, data_out) + if __name__ == '__main__': gr_unittest.run(test_fecapi_cc) diff --git a/gr-fec/python/fec/qa_fecapi_cc_buffer_overflow.py b/gr-fec/python/fec/qa_fecapi_cc_buffer_overflow.py index 938897ccb5..98344b5175 100644 --- a/gr-fec/python/fec/qa_fecapi_cc_buffer_overflow.py +++ b/gr-fec/python/fec/qa_fecapi_cc_buffer_overflow.py @@ -15,21 +15,24 @@ from gnuradio import blocks, analog # This test tries to checks for the kind of buffer overflows in the # FECAPI convolutional decoder that were fixed in #2965 + class test_fecapi_cc_buffer_overflow(gr_unittest.TestCase): def run_with_frame_len(self, frame_len): self.tb = gr.top_block() noise = analog.noise_source_f(analog.GR_GAUSSIAN, 1, 0) head = blocks.head(gr.sizeof_float, self.n_frames * frame_len) - tag = blocks.stream_to_tagged_stream(gr.sizeof_float, 1, frame_len, "packet_len") + tag = blocks.stream_to_tagged_stream( + gr.sizeof_float, 1, frame_len, "packet_len") stream2pdu = blocks.tagged_stream_to_pdu(blocks.float_t, 'packet_len') - - viterbi = fec.cc_decoder.make(frame_len//2, 7, 2, [79,-109], 0, -1, fec.CC_TERMINATED, False) + + viterbi = fec.cc_decoder.make( + frame_len // 2, 7, 2, [79, -109], 0, -1, fec.CC_TERMINATED, False) cc_decoder = fec.async_decoder(viterbi, False, False, frame_len) - + self.tb.connect(noise, head, tag, stream2pdu) self.tb.msg_connect((stream2pdu, 'pdus'), (cc_decoder, 'in')) - + self.tb.run() # the test is considered successful if it hasn't segfaulted or aborted @@ -39,8 +42,9 @@ class test_fecapi_cc_buffer_overflow(gr_unittest.TestCase): self.n_frames = 10 for frame_len in range(1000, 2000): - with self.subTest(frame_length = frame_len): + with self.subTest(frame_length=frame_len): self.run_with_frame_len(frame_len) - + + if __name__ == '__main__': gr_unittest.run(test_fecapi_cc_buffer_overflow) diff --git a/gr-fec/python/fec/qa_fecapi_dummy.py b/gr-fec/python/fec/qa_fecapi_dummy.py index 317a9e7d24..f1de85e526 100644 --- a/gr-fec/python/fec/qa_fecapi_dummy.py +++ b/gr-fec/python/fec/qa_fecapi_dummy.py @@ -29,157 +29,192 @@ class test_fecapi_dummy(gr_unittest.TestCase): def test_parallelism0_00(self): frame_size = 30 - enc = fec.dummy_encoder_make(frame_size*8) - dec = fec.dummy_decoder.make(frame_size*8) + enc = fec.dummy_encoder_make(frame_size * 8) + dec = fec.dummy_decoder.make(frame_size * 8) threading = None - self.test = _qa_helper(10*frame_size, enc, dec, threading) + self.test = _qa_helper(10 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism0_01(self): frame_size = 30 - enc = fec.dummy_encoder_make(frame_size*8) - dec = fec.dummy_decoder.make(frame_size*8) + enc = fec.dummy_encoder_make(frame_size * 8) + dec = fec.dummy_decoder.make(frame_size * 8) threading = 'ordinary' - self.test = _qa_helper(10*frame_size, enc, dec, threading) + self.test = _qa_helper(10 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism0_02(self): frame_size = 30 - enc = fec.dummy_encoder_make(frame_size*8) - dec = fec.dummy_decoder.make(frame_size*8) + enc = fec.dummy_encoder_make(frame_size * 8) + dec = fec.dummy_decoder.make(frame_size * 8) threading = 'capillary' - self.test = _qa_helper(10*frame_size, enc, dec, threading) + self.test = _qa_helper(10 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism1_00(self): frame_size = 30 - enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,1)))) - dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), list(range(0,1)))) + enc = list( + map((lambda a: fec.dummy_encoder_make(frame_size * 8)), list(range(0, 1)))) + dec = list( + map((lambda a: fec.dummy_decoder.make(frame_size * 8)), list(range(0, 1)))) threading = None - self.test = _qa_helper(10*frame_size, enc, dec, threading) + self.test = _qa_helper(10 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism1_01(self): frame_size = 30 - enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,1)))) - dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), list(range(0,1)))) + enc = list( + map((lambda a: fec.dummy_encoder_make(frame_size * 8)), list(range(0, 1)))) + dec = list( + map((lambda a: fec.dummy_decoder.make(frame_size * 8)), list(range(0, 1)))) threading = 'ordinary' - self.test = _qa_helper(10*frame_size, enc, dec, threading) + self.test = _qa_helper(10 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism1_02(self): frame_size = 300 - enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,1)))) - dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), list(range(0,1)))) + enc = list( + map((lambda a: fec.dummy_encoder_make(frame_size * 8)), list(range(0, 1)))) + dec = list( + map((lambda a: fec.dummy_decoder.make(frame_size * 8)), list(range(0, 1)))) threading = 'capillary' - self.test = _qa_helper(10*frame_size, enc, dec, threading) + self.test = _qa_helper(10 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism1_03(self): frame_size = 30 dims = 10 - enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,dims)))) - dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), list(range(0,dims)))) + enc = list(map((lambda a: fec.dummy_encoder_make( + frame_size * 8)), list(range(0, dims)))) + dec = list(map((lambda a: fec.dummy_decoder.make( + frame_size * 8)), list(range(0, dims)))) threading = 'ordinary' - self.test = _qa_helper(dims*frame_size, enc, dec, threading) + self.test = _qa_helper(dims * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism1_04(self): frame_size = 30 dims = 16 - enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,dims)))) - dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), list(range(0,dims)))) + enc = list(map((lambda a: fec.dummy_encoder_make( + frame_size * 8)), list(range(0, dims)))) + dec = list(map((lambda a: fec.dummy_decoder.make( + frame_size * 8)), list(range(0, dims)))) threading = 'capillary' - self.test = _qa_helper(dims*frame_size, enc, dec, threading) + self.test = _qa_helper(dims * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism1_05(self): frame_size = 30 dims = 5 - enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,dims)))) + enc = list(map((lambda a: fec.dummy_encoder_make( + frame_size * 8)), list(range(0, dims)))) #dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), range(0,dims))) threading = 'capillary' - self.assertRaises(AttributeError, lambda: extended_encoder(enc, threading=threading, puncpat="11")) + self.assertRaises( + AttributeError, + lambda: extended_encoder( + enc, + threading=threading, + puncpat="11")) def test_parallelism1_06(self): frame_size = 30 dims = 5 #enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), range(0,dims))) - dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), list(range(0,dims)))) + dec = list(map((lambda a: fec.dummy_decoder.make( + frame_size * 8)), list(range(0, dims)))) threading = 'capillary' - self.assertRaises(AttributeError, lambda: extended_decoder(dec, threading=threading, puncpat="11")) + self.assertRaises( + AttributeError, + lambda: extended_decoder( + dec, + threading=threading, + puncpat="11")) def test_parallelism2_00(self): frame_size = 30 dims1 = 16 dims2 = 16 - enc = list(map((lambda b: list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,dims1))))), list(range(0,dims2)))) + enc = list(map((lambda b: list(map((lambda a: fec.dummy_encoder_make( + frame_size * 8)), list(range(0, dims1))))), list(range(0, dims2)))) #dec = list(map((lambda b: map((lambda a: fec.dummy_decoder_make(frame_size*8)), range(0,dims1))), range(0,dims2))) threading = 'capillary' - self.assertRaises(AttributeError, lambda: extended_encoder(enc, threading=threading, puncpat="11")) + self.assertRaises( + AttributeError, + lambda: extended_encoder( + enc, + threading=threading, + puncpat="11")) def test_parallelism2_01(self): frame_size = 30 dims1 = 16 dims2 = 16 - dec = list(map((lambda b: list(map((lambda a: fec.dummy_decoder_make(frame_size*8)), list(range(0,dims1))))), list(range(0,dims2)))) + dec = list(map((lambda b: list(map((lambda a: fec.dummy_decoder_make( + frame_size * 8)), list(range(0, dims1))))), list(range(0, dims2)))) threading = 'capillary' - self.assertRaises(AttributeError, lambda: extended_decoder(dec, threading=threading, puncpat="11")) + self.assertRaises( + AttributeError, + lambda: extended_decoder( + dec, + threading=threading, + puncpat="11")) def test_extended_pack_data(self): - # test if extended encoder gets correct values for input and output conversion. + # test if extended encoder gets correct values for input and output + # conversion. n_frames = 10 frame_size = 32 @@ -199,15 +234,18 @@ class test_fecapi_dummy(gr_unittest.TestCase): tb.connect(src, packer, snk0) enc_unpacked = fec.dummy_encoder_make(frame_size, False, False) - ext_enc_unp = extended_encoder(enc_unpacked, threading='none', puncpat='11') + ext_enc_unp = extended_encoder( + enc_unpacked, threading='none', puncpat='11') tb.connect(src, ext_enc_unp, snk1) enc_pack = fec.dummy_encoder_make(frame_size // 8, True, False) - ext_enc_pack = extended_encoder(enc_pack, threading='none', puncpat='11') + ext_enc_pack = extended_encoder( + enc_pack, threading='none', puncpat='11') tb.connect(src, ext_enc_pack, snk2) enc_packed_bits = fec.dummy_encoder_make(frame_size // 8, False, True) - ext_enc_packed_bits = extended_encoder(enc_packed_bits, threading='none', puncpat='11') + ext_enc_packed_bits = extended_encoder( + enc_packed_bits, threading='none', puncpat='11') tb.connect(packer, ext_enc_packed_bits, snk3) tb.run() diff --git a/gr-fec/python/fec/qa_fecapi_ldpc.py b/gr-fec/python/fec/qa_fecapi_ldpc.py index 1f0771d570..f4e83bee42 100644 --- a/gr-fec/python/fec/qa_fecapi_ldpc.py +++ b/gr-fec/python/fec/qa_fecapi_ldpc.py @@ -9,7 +9,6 @@ # - import os from gnuradio import gr, gr_unittest @@ -25,6 +24,7 @@ from _qa_helper import _qa_helper # from the current directory and know where to go. LDPC_ALIST_DIR = os.getenv('srcdir', '.') + "/../../ldpc_alist/" + class test_fecapi_ldpc(gr_unittest.TestCase): def setUp(self): @@ -39,14 +39,15 @@ class test_fecapi_ldpc(gr_unittest.TestCase): LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap) k = LDPC_matrix_object.k() enc = fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object) - dec = fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr()) + dec = fec.ldpc_bit_flip_decoder.make( + LDPC_matrix_object.get_base_sptr()) threading = None - self.test = _qa_helper(10*k, enc, dec, threading) + self.test = _qa_helper(10 * k, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) @@ -56,14 +57,15 @@ class test_fecapi_ldpc(gr_unittest.TestCase): LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap) k = LDPC_matrix_object.k() enc = fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object) - dec = fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr()) + dec = fec.ldpc_bit_flip_decoder.make( + LDPC_matrix_object.get_base_sptr()) threading = 'ordinary' - self.test = _qa_helper(10*k, enc, dec, threading) + self.test = _qa_helper(10 * k, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) @@ -73,14 +75,15 @@ class test_fecapi_ldpc(gr_unittest.TestCase): LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap) k = LDPC_matrix_object.k() enc = fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object) - dec = fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr()) + dec = fec.ldpc_bit_flip_decoder.make( + LDPC_matrix_object.get_base_sptr()) threading = 'capillary' - self.test = _qa_helper(10*k, enc, dec, threading) + self.test = _qa_helper(10 * k, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) @@ -90,14 +93,15 @@ class test_fecapi_ldpc(gr_unittest.TestCase): LDPC_matrix_object = fec.ldpc_G_matrix(filename) k = LDPC_matrix_object.k() enc = fec.ldpc_gen_mtrx_encoder.make(LDPC_matrix_object) - dec = fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr()) + dec = fec.ldpc_bit_flip_decoder.make( + LDPC_matrix_object.get_base_sptr()) threading = 'capillary' - self.test = _qa_helper(10*k, enc, dec, threading) + self.test = _qa_helper(10 * k, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) @@ -108,12 +112,12 @@ class test_fecapi_ldpc(gr_unittest.TestCase): enc = fec.ldpc_par_mtrx_encoder.make(filename, gap) dec = fec.ldpc_decoder.make(filename) threading = 'capillary' - self.test = _qa_helper(10*k, enc, dec, threading) + self.test = _qa_helper(10 * k, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) @@ -122,15 +126,17 @@ class test_fecapi_ldpc(gr_unittest.TestCase): gap = 4 LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap) k = LDPC_matrix_object.k() - enc = list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), list(range(0,1)))) - dec = list(map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), list(range(0,1)))) + enc = list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H( + LDPC_matrix_object)), list(range(0, 1)))) + dec = list(map((lambda a: fec.ldpc_bit_flip_decoder.make( + LDPC_matrix_object.get_base_sptr())), list(range(0, 1)))) threading = None - self.test = _qa_helper(10*k, enc, dec, threading) + self.test = _qa_helper(10 * k, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) @@ -139,15 +145,17 @@ class test_fecapi_ldpc(gr_unittest.TestCase): gap = 4 LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap) k = LDPC_matrix_object.k() - enc = list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), list(range(0,1)))) - dec = list(map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), list(range(0,1)))) + enc = list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H( + LDPC_matrix_object)), list(range(0, 1)))) + dec = list(map((lambda a: fec.ldpc_bit_flip_decoder.make( + LDPC_matrix_object.get_base_sptr())), list(range(0, 1)))) threading = 'ordinary' - self.test = _qa_helper(10*k, enc, dec, threading) + self.test = _qa_helper(10 * k, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) @@ -156,15 +164,17 @@ class test_fecapi_ldpc(gr_unittest.TestCase): gap = 4 LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap) k = LDPC_matrix_object.k() - enc = list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), list(range(0,1)))) - dec = list(map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), list(range(0,1)))) + enc = list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H( + LDPC_matrix_object)), list(range(0, 1)))) + dec = list(map((lambda a: fec.ldpc_bit_flip_decoder.make( + LDPC_matrix_object.get_base_sptr())), list(range(0, 1)))) threading = 'capillary' - self.test = _qa_helper(10*k, enc, dec, threading) + self.test = _qa_helper(10 * k, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) @@ -174,23 +184,23 @@ class test_fecapi_ldpc(gr_unittest.TestCase): dims = 10 enc = [] - for n in range(0,dims): + for n in range(0, dims): H = fec.ldpc_H_matrix(filename, gap) enc.append(fec.ldpc_par_mtrx_encoder.make_H(H)) dec = [] - for n in range(0,dims): + for n in range(0, dims): H = fec.ldpc_H_matrix(filename, gap) dec.append(fec.ldpc_bit_flip_decoder.make(H.get_base_sptr())) k = 27 threading = 'ordinary' - self.test = _qa_helper(dims*k, enc, dec, threading) + self.test = _qa_helper(dims * k, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) @@ -200,24 +210,23 @@ class test_fecapi_ldpc(gr_unittest.TestCase): dims = 16 enc = [] - for n in range(0,dims): + for n in range(0, dims): H = fec.ldpc_H_matrix(filename, gap) enc.append(fec.ldpc_par_mtrx_encoder.make_H(H)) dec = [] - for n in range(0,dims): + for n in range(0, dims): H = fec.ldpc_H_matrix(filename, gap) dec.append(fec.ldpc_bit_flip_decoder.make(H.get_base_sptr())) - k = 27 threading = 'capillary' - self.test = _qa_helper(dims*k, enc, dec, threading) + self.test = _qa_helper(dims * k, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) @@ -227,18 +236,23 @@ class test_fecapi_ldpc(gr_unittest.TestCase): dims = 5 enc = [] - for n in range(0,dims): + for n in range(0, dims): H = fec.ldpc_H_matrix(filename, gap) enc.append(fec.ldpc_par_mtrx_encoder.make_H(H)) dec = [] - for n in range(0,dims): + for n in range(0, dims): H = fec.ldpc_H_matrix(filename, gap) dec.append(fec.ldpc_bit_flip_decoder.make(H.get_base_sptr())) k = H.k() threading = 'capillary' - self.assertRaises(AttributeError, lambda: extended_encoder(enc, threading=threading, puncpat="11")) + self.assertRaises( + AttributeError, + lambda: extended_encoder( + enc, + threading=threading, + puncpat="11")) def test_parallelism1_06(self): filename = LDPC_ALIST_DIR + "n_0100_k_0027_gap_04.alist" @@ -246,9 +260,15 @@ class test_fecapi_ldpc(gr_unittest.TestCase): dims = 5 LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap) k = LDPC_matrix_object.k() - dec = list(map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), list(range(0,dims)))) + dec = list(map((lambda a: fec.ldpc_bit_flip_decoder.make( + LDPC_matrix_object.get_base_sptr())), list(range(0, dims)))) threading = 'capillary' - self.assertRaises(AttributeError, lambda: extended_decoder(dec, threading=threading, puncpat="11")) + self.assertRaises( + AttributeError, + lambda: extended_decoder( + dec, + threading=threading, + puncpat="11")) def test_parallelism2_00(self): filename = LDPC_ALIST_DIR + "n_0100_k_0027_gap_04.alist" @@ -258,11 +278,16 @@ class test_fecapi_ldpc(gr_unittest.TestCase): k = LDPC_matrix_object.k() dims1 = 16 dims2 = 16 - enc = list(map((lambda b: list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), - list(range(0,dims1))))), list(range(0,dims2)))) + enc = list(map((lambda b: list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H( + LDPC_matrix_object)), list(range(0, dims1))))), list(range(0, dims2)))) threading = 'capillary' - self.assertRaises(AttributeError, lambda: extended_encoder(enc, threading=threading, puncpat="11")) + self.assertRaises( + AttributeError, + lambda: extended_encoder( + enc, + threading=threading, + puncpat="11")) def test_parallelism2_00(self): filename = LDPC_ALIST_DIR + "n_0100_k_0027_gap_04.alist" @@ -272,11 +297,16 @@ class test_fecapi_ldpc(gr_unittest.TestCase): k = LDPC_matrix_object.k() dims1 = 16 dims2 = 16 - enc = list(map((lambda b: list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), - list(range(0,dims1))))), list(range(0,dims2)))) + enc = list(map((lambda b: list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H( + LDPC_matrix_object)), list(range(0, dims1))))), list(range(0, dims2)))) threading = 'capillary' - self.assertRaises(AttributeError, lambda: extended_encoder(enc, threading=threading, puncpat="11")) + self.assertRaises( + AttributeError, + lambda: extended_encoder( + enc, + threading=threading, + puncpat="11")) def test_parallelism2_01(self): filename = LDPC_ALIST_DIR + "n_0100_k_0027_gap_04.alist" @@ -286,11 +316,17 @@ class test_fecapi_ldpc(gr_unittest.TestCase): k = LDPC_matrix_object.k() dims1 = 16 dims2 = 16 - dec = list(map((lambda b: list(map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), - list(range(0,dims1))))), list(range(0,dims2)))) + dec = list(map((lambda b: list(map((lambda a: fec.ldpc_bit_flip_decoder.make( + LDPC_matrix_object.get_base_sptr())), list(range(0, dims1))))), list(range(0, dims2)))) threading = 'capillary' - self.assertRaises(AttributeError, lambda: extended_decoder(dec, threading=threading, puncpat="11")) + self.assertRaises( + AttributeError, + lambda: extended_decoder( + dec, + threading=threading, + puncpat="11")) + if __name__ == '__main__': gr_unittest.run(test_fecapi_ldpc) diff --git a/gr-fec/python/fec/qa_fecapi_repetition.py b/gr-fec/python/fec/qa_fecapi_repetition.py index ab26de6476..9d560b32ef 100644 --- a/gr-fec/python/fec/qa_fecapi_repetition.py +++ b/gr-fec/python/fec/qa_fecapi_repetition.py @@ -9,8 +9,6 @@ # - - from gnuradio import gr, gr_unittest from gnuradio import fec @@ -28,90 +26,96 @@ class test_fecapi_repetition(gr_unittest.TestCase): def test_parallelism0_00(self): frame_size = 30 rep = 3 - enc = fec.repetition_encoder_make(frame_size*8, rep) - dec = fec.repetition_decoder.make(frame_size*8, rep) + enc = fec.repetition_encoder_make(frame_size * 8, rep) + dec = fec.repetition_decoder.make(frame_size * 8, rep) threading = None - self.test = _qa_helper(10*frame_size, enc, dec, threading) + self.test = _qa_helper(10 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism0_01(self): frame_size = 30 rep = 3 - enc = fec.repetition_encoder_make(frame_size*8, rep) - dec = fec.repetition_decoder.make(frame_size*8, rep) + enc = fec.repetition_encoder_make(frame_size * 8, rep) + dec = fec.repetition_decoder.make(frame_size * 8, rep) threading = 'ordinary' - self.test = _qa_helper(10*frame_size, enc, dec, threading) + self.test = _qa_helper(10 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism0_02(self): frame_size = 30 rep = 3 - enc = fec.repetition_encoder_make(frame_size*8, rep) - dec = fec.repetition_decoder.make(frame_size*8, rep) + enc = fec.repetition_encoder_make(frame_size * 8, rep) + dec = fec.repetition_decoder.make(frame_size * 8, rep) threading = 'capillary' - self.test = _qa_helper(10*frame_size, enc, dec, threading) + self.test = _qa_helper(10 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism1_00(self): frame_size = 30 rep = 3 - enc = list(map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), list(range(0,1)))) - dec = list(map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), list(range(0,1)))) + enc = list(map((lambda a: fec.repetition_encoder_make( + frame_size * 8, rep)), list(range(0, 1)))) + dec = list(map((lambda a: fec.repetition_decoder.make( + frame_size * 8, rep)), list(range(0, 1)))) threading = None - self.test = _qa_helper(10*frame_size, enc, dec, threading) + self.test = _qa_helper(10 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism1_01(self): frame_size = 30 rep = 3 - enc = list(map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), list(range(0,1)))) - dec = list(map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), list(range(0,1)))) + enc = list(map((lambda a: fec.repetition_encoder_make( + frame_size * 8, rep)), list(range(0, 1)))) + dec = list(map((lambda a: fec.repetition_decoder.make( + frame_size * 8, rep)), list(range(0, 1)))) threading = 'ordinary' - self.test = _qa_helper(10*frame_size, enc, dec, threading) + self.test = _qa_helper(10 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) def test_parallelism1_02(self): frame_size = 300 rep = 3 - enc = list(map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), list(range(0,1)))) - dec = list(map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), list(range(0,1)))) + enc = list(map((lambda a: fec.repetition_encoder_make( + frame_size * 8, rep)), list(range(0, 1)))) + dec = list(map((lambda a: fec.repetition_decoder.make( + frame_size * 8, rep)), list(range(0, 1)))) threading = 'capillary' - self.test = _qa_helper(10*frame_size, enc, dec, threading) + self.test = _qa_helper(10 * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) @@ -119,15 +123,17 @@ class test_fecapi_repetition(gr_unittest.TestCase): frame_size = 30 rep = 3 dims = 10 - enc = list(map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), list(range(0,dims)))) - dec = list(map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), list(range(0,dims)))) + enc = list(map((lambda a: fec.repetition_encoder_make( + frame_size * 8, rep)), list(range(0, dims)))) + dec = list(map((lambda a: fec.repetition_decoder.make( + frame_size * 8, rep)), list(range(0, dims)))) threading = 'ordinary' - self.test = _qa_helper(dims*frame_size, enc, dec, threading) + self.test = _qa_helper(dims * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) @@ -135,17 +141,20 @@ class test_fecapi_repetition(gr_unittest.TestCase): frame_size = 30 rep = 3 dims = 16 - enc = list(map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), list(range(0,dims)))) - dec = list(map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), list(range(0,dims)))) + enc = list(map((lambda a: fec.repetition_encoder_make( + frame_size * 8, rep)), list(range(0, dims)))) + dec = list(map((lambda a: fec.repetition_decoder.make( + frame_size * 8, rep)), list(range(0, dims)))) threading = 'capillary' - self.test = _qa_helper(dims*frame_size, enc, dec, threading) + self.test = _qa_helper(dims * frame_size, enc, dec, threading) self.tb.connect(self.test) self.tb.run() data_in = self.test.snk_input.data() - data_out =self.test.snk_output.data() + data_out = self.test.snk_output.data() self.assertEqual(data_in, data_out) + if __name__ == '__main__': gr_unittest.run(test_fecapi_repetition) diff --git a/gr-fec/python/fec/qa_polar_decoder_sc.py b/gr-fec/python/fec/qa_polar_decoder_sc.py index 8350738228..0cd84a3b4e 100644 --- a/gr-fec/python/fec/qa_polar_decoder_sc.py +++ b/gr-fec/python/fec/qa_polar_decoder_sc.py @@ -9,7 +9,6 @@ # - import numpy as np from gnuradio import gr, gr_unittest, blocks @@ -37,11 +36,13 @@ class test_polar_decoder_sc(gr_unittest.TestCase): frozen_bit_positions = np.arange(block_size - num_info_bits) frozen_bit_values = np.array([],) - polar_decoder = fec.polar_decoder_sc.make(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + polar_decoder = fec.polar_decoder_sc.make( + block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) self.assertEqual(num_info_bits, polar_decoder.get_output_size()) self.assertEqual(block_size, polar_decoder.get_input_size()) - self.assertFloatTuplesAlmostEqual((float(num_info_bits) / block_size, ), (polar_decoder.rate(), )) + self.assertFloatTuplesAlmostEqual( + (float(num_info_bits) / block_size, ), (polar_decoder.rate(), )) self.assertFalse(polar_decoder.set_frame_size(10)) def test_002_one_vector(self): @@ -49,12 +50,15 @@ class test_polar_decoder_sc(gr_unittest.TestCase): block_size = 2 ** block_power num_info_bits = 2 ** (block_power - 1) num_frozen_bits = block_size - num_info_bits - frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0) + frozen_bit_positions = cc.frozen_bit_positions( + block_size, num_info_bits, 0.0) frozen_bit_values = np.array([0] * num_frozen_bits,) - bits, gr_data = self.generate_test_data(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values, 1, True) + bits, gr_data = self.generate_test_data( + block_size, num_info_bits, frozen_bit_positions, frozen_bit_values, 1, True) - polar_decoder = fec.polar_decoder_sc.make(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + polar_decoder = fec.polar_decoder_sc.make( + block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) src = blocks.vector_source_f(gr_data, False) dec_block = extended_decoder(polar_decoder, None) snk = blocks.vector_sink_b(1) @@ -72,12 +76,15 @@ class test_polar_decoder_sc(gr_unittest.TestCase): block_size = 2 ** block_power num_info_bits = 2 ** (block_power - 1) num_frozen_bits = block_size - num_info_bits - frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0) + frozen_bit_positions = cc.frozen_bit_positions( + block_size, num_info_bits, 0.0) frozen_bit_values = np.array([0] * num_frozen_bits,) - bits, gr_data = self.generate_test_data(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values, nframes, False) + bits, gr_data = self.generate_test_data( + block_size, num_info_bits, frozen_bit_positions, frozen_bit_values, nframes, False) - polar_decoder = fec.polar_decoder_sc.make(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + polar_decoder = fec.polar_decoder_sc.make( + block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) src = blocks.vector_source_f(gr_data, False) dec_block = extended_decoder(polar_decoder, None) snk = blocks.vector_sink_b(1) @@ -89,8 +96,19 @@ class test_polar_decoder_sc(gr_unittest.TestCase): res = np.array(snk.data()).astype(dtype=int) self.assertTupleEqual(tuple(res), tuple(bits)) - def generate_test_data(self, block_size, num_info_bits, frozen_bit_positions, frozen_bit_values, nframes, onlyones): - encoder = PolarEncoder(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + def generate_test_data( + self, + block_size, + num_info_bits, + frozen_bit_positions, + frozen_bit_values, + nframes, + onlyones): + encoder = PolarEncoder( + block_size, + num_info_bits, + frozen_bit_positions, + frozen_bit_values) bits = np.array([], dtype=int) data = np.array([], dtype=int) for n in range(nframes): diff --git a/gr-fec/python/fec/qa_polar_decoder_sc_list.py b/gr-fec/python/fec/qa_polar_decoder_sc_list.py index 0dd5a0933f..c354445beb 100644 --- a/gr-fec/python/fec/qa_polar_decoder_sc_list.py +++ b/gr-fec/python/fec/qa_polar_decoder_sc_list.py @@ -9,7 +9,6 @@ # - import numpy as np from gnuradio import gr, gr_unittest, blocks, fec @@ -37,11 +36,17 @@ class test_polar_decoder_sc_list(gr_unittest.TestCase): frozen_bit_positions = np.arange(block_size - num_info_bits) frozen_bit_values = np.array([],) - polar_decoder = fec.polar_decoder_sc_list.make(max_list_size, block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + polar_decoder = fec.polar_decoder_sc_list.make( + max_list_size, + block_size, + num_info_bits, + frozen_bit_positions, + frozen_bit_values) self.assertEqual(num_info_bits, polar_decoder.get_output_size()) self.assertEqual(block_size, polar_decoder.get_input_size()) - self.assertFloatTuplesAlmostEqual((float(num_info_bits) / block_size, ), (polar_decoder.rate(), )) + self.assertFloatTuplesAlmostEqual( + (float(num_info_bits) / block_size, ), (polar_decoder.rate(), )) self.assertFalse(polar_decoder.set_frame_size(10)) def test_002_one_vector(self): @@ -51,15 +56,25 @@ class test_polar_decoder_sc_list(gr_unittest.TestCase): num_info_bits = 2 ** (expo - 1) max_list_size = 2 ** (expo - 2) num_frozen_bits = block_size - num_info_bits - frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0) + frozen_bit_positions = cc.frozen_bit_positions( + block_size, num_info_bits, 0.0) frozen_bit_values = np.array([0] * num_frozen_bits,) bits = np.random.randint(2, size=num_info_bits) - encoder = PolarEncoder(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + encoder = PolarEncoder( + block_size, + num_info_bits, + frozen_bit_positions, + frozen_bit_values) data = encoder.encode(bits) gr_data = 2.0 * data - 1.0 - polar_decoder = fec.polar_decoder_sc_list.make(max_list_size, block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + polar_decoder = fec.polar_decoder_sc_list.make( + max_list_size, + block_size, + num_info_bits, + frozen_bit_positions, + frozen_bit_values) src = blocks.vector_source_f(gr_data, False) dec_block = extended_decoder(polar_decoder, None) snk = blocks.vector_sink_b(1) @@ -85,10 +100,15 @@ class test_polar_decoder_sc_list(gr_unittest.TestCase): num_info_bits = 2 ** (expo - 1) max_list_size = 2 ** (expo - 2) num_frozen_bits = block_size - num_info_bits - frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0) + frozen_bit_positions = cc.frozen_bit_positions( + block_size, num_info_bits, 0.0) frozen_bit_values = np.array([0] * num_frozen_bits,) - encoder = PolarEncoder(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + encoder = PolarEncoder( + block_size, + num_info_bits, + frozen_bit_positions, + frozen_bit_values) ref = np.array([], dtype=int) data = np.array([], dtype=int) @@ -99,7 +119,12 @@ class test_polar_decoder_sc_list(gr_unittest.TestCase): ref = np.append(ref, b) gr_data = 2.0 * data - 1.0 - polar_decoder = fec.polar_decoder_sc_list.make(max_list_size, block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + polar_decoder = fec.polar_decoder_sc_list.make( + max_list_size, + block_size, + num_info_bits, + frozen_bit_positions, + frozen_bit_values) src = blocks.vector_source_f(gr_data, False) dec_block = extended_decoder(polar_decoder, None) snk = blocks.vector_sink_b(1) diff --git a/gr-fec/python/fec/qa_polar_decoder_sc_systematic.py b/gr-fec/python/fec/qa_polar_decoder_sc_systematic.py index 67bfba99b6..55c37064b1 100644 --- a/gr-fec/python/fec/qa_polar_decoder_sc_systematic.py +++ b/gr-fec/python/fec/qa_polar_decoder_sc_systematic.py @@ -35,22 +35,27 @@ class test_polar_decoder_sc_systematic(gr_unittest.TestCase): num_info_bits = 8 frozen_bit_positions = np.arange(block_size - num_info_bits) - polar_decoder = fec.polar_decoder_sc_systematic.make(block_size, num_info_bits, frozen_bit_positions) + polar_decoder = fec.polar_decoder_sc_systematic.make( + block_size, num_info_bits, frozen_bit_positions) self.assertEqual(num_info_bits, polar_decoder.get_output_size()) self.assertEqual(block_size, polar_decoder.get_input_size()) - self.assertFloatTuplesAlmostEqual((float(num_info_bits) / block_size, ), (polar_decoder.rate(), )) + self.assertFloatTuplesAlmostEqual( + (float(num_info_bits) / block_size, ), (polar_decoder.rate(), )) self.assertFalse(polar_decoder.set_frame_size(10)) def test_002_one_vector(self): block_power = 4 block_size = 2 ** block_power num_info_bits = block_size // 2 - frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0) + frozen_bit_positions = cc.frozen_bit_positions( + block_size, num_info_bits, 0.0) - bits, gr_data = self.generate_test_data(block_size, num_info_bits, frozen_bit_positions, 1, False) + bits, gr_data = self.generate_test_data( + block_size, num_info_bits, frozen_bit_positions, 1, False) - polar_decoder = fec.polar_decoder_sc_systematic.make(block_size, num_info_bits, frozen_bit_positions) + polar_decoder = fec.polar_decoder_sc_systematic.make( + block_size, num_info_bits, frozen_bit_positions) src = blocks.vector_source_f(gr_data, False) dec_block = extended_decoder(polar_decoder, None) snk = blocks.vector_sink_b(1) @@ -67,11 +72,14 @@ class test_polar_decoder_sc_systematic(gr_unittest.TestCase): block_power = 8 block_size = 2 ** block_power num_info_bits = block_size // 2 - frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0) + frozen_bit_positions = cc.frozen_bit_positions( + block_size, num_info_bits, 0.0) - bits, gr_data = self.generate_test_data(block_size, num_info_bits, frozen_bit_positions, nframes, False) + bits, gr_data = self.generate_test_data( + block_size, num_info_bits, frozen_bit_positions, nframes, False) - polar_decoder = fec.polar_decoder_sc_systematic.make(block_size, num_info_bits, frozen_bit_positions) + polar_decoder = fec.polar_decoder_sc_systematic.make( + block_size, num_info_bits, frozen_bit_positions) src = blocks.vector_source_f(gr_data, False) dec_block = extended_decoder(polar_decoder, None) snk = blocks.vector_sink_b(1) @@ -83,9 +91,19 @@ class test_polar_decoder_sc_systematic(gr_unittest.TestCase): res = np.array(snk.data()).astype(dtype=int) self.assertTupleEqual(tuple(res), tuple(bits)) - def generate_test_data(self, block_size, num_info_bits, frozen_bit_positions, nframes, onlyones): + def generate_test_data( + self, + block_size, + num_info_bits, + frozen_bit_positions, + nframes, + onlyones): frozen_bit_values = np.zeros(block_size - num_info_bits, dtype=int) - encoder = PolarEncoder(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + encoder = PolarEncoder( + block_size, + num_info_bits, + frozen_bit_positions, + frozen_bit_values) bits = np.array([], dtype=int) data = np.array([], dtype=int) for n in range(nframes): diff --git a/gr-fec/python/fec/qa_polar_encoder.py b/gr-fec/python/fec/qa_polar_encoder.py index f068aa582c..59ed0ff7a0 100644 --- a/gr-fec/python/fec/qa_polar_encoder.py +++ b/gr-fec/python/fec/qa_polar_encoder.py @@ -9,7 +9,6 @@ # - import numpy as np from gnuradio import gr, gr_unittest, blocks, fec @@ -33,14 +32,17 @@ class test_polar_encoder(gr_unittest.TestCase): def test_001_setup(self): block_size = 16 num_info_bits = 8 - frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0) + frozen_bit_positions = cc.frozen_bit_positions( + block_size, num_info_bits, 0.0) frozen_bit_values = np.array([],) - polar_encoder = fec.polar_encoder.make(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + polar_encoder = fec.polar_encoder.make( + block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) self.assertEqual(block_size, polar_encoder.get_output_size()) self.assertEqual(num_info_bits, polar_encoder.get_input_size()) - self.assertFloatTuplesAlmostEqual((float(num_info_bits) / block_size, ), (polar_encoder.rate(), )) + self.assertFloatTuplesAlmostEqual( + (float(num_info_bits) / block_size, ), (polar_encoder.rate(), )) self.assertFalse(polar_encoder.set_frame_size(10)) def test_002_work_function_packed(self): @@ -48,7 +50,8 @@ class test_polar_encoder(gr_unittest.TestCase): block_size = 256 num_info_bits = block_size // 2 - data, ref, polar_encoder = self.get_test_data(block_size, num_info_bits, 1, is_packed) + data, ref, polar_encoder = self.get_test_data( + block_size, num_info_bits, 1, is_packed) src = blocks.vector_source_b(data, False) enc_block = extended_encoder(polar_encoder, None, '11') snk = blocks.vector_sink_b(1) @@ -64,7 +67,8 @@ class test_polar_encoder(gr_unittest.TestCase): block_size = 256 num_info_bits = block_size // 2 - data, ref, polar_encoder = self.get_test_data(block_size, num_info_bits, 1, is_packed) + data, ref, polar_encoder = self.get_test_data( + block_size, num_info_bits, 1, is_packed) src = blocks.vector_source_b(data, False) enc_block = extended_encoder(polar_encoder, None, '11') snk = blocks.vector_sink_b(1) @@ -81,7 +85,8 @@ class test_polar_encoder(gr_unittest.TestCase): block_size = 1024 num_info_bits = block_size // 8 - data, ref, polar_encoder = self.get_test_data(block_size, num_info_bits, num_blocks, is_packed) + data, ref, polar_encoder = self.get_test_data( + block_size, num_info_bits, num_blocks, is_packed) src = blocks.vector_source_b(data, False) enc_block = extended_encoder(polar_encoder, None, '11') snk = blocks.vector_sink_b(1) @@ -95,9 +100,14 @@ class test_polar_encoder(gr_unittest.TestCase): def get_test_data(self, block_size, num_info_bits, num_blocks, is_packed): # helper function to set up test data and together with encoder object. num_frozen_bits = block_size - num_info_bits - frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0) + frozen_bit_positions = cc.frozen_bit_positions( + block_size, num_info_bits, 0.0) frozen_bit_values = np.array([0] * num_frozen_bits,) - python_encoder = PolarEncoder(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + python_encoder = PolarEncoder( + block_size, + num_info_bits, + frozen_bit_positions, + frozen_bit_values) data = np.array([], dtype=int) ref = np.array([], dtype=int) @@ -105,7 +115,12 @@ class test_polar_encoder(gr_unittest.TestCase): d = np.random.randint(2, size=num_info_bits) data = np.append(data, d) ref = np.append(ref, python_encoder.encode(d)) - polar_encoder = fec.polar_encoder.make(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values, is_packed) + polar_encoder = fec.polar_encoder.make( + block_size, + num_info_bits, + frozen_bit_positions, + frozen_bit_values, + is_packed) return data, ref, polar_encoder diff --git a/gr-fec/python/fec/qa_polar_encoder_systematic.py b/gr-fec/python/fec/qa_polar_encoder_systematic.py index 4118567216..25a8302b6b 100644 --- a/gr-fec/python/fec/qa_polar_encoder_systematic.py +++ b/gr-fec/python/fec/qa_polar_encoder_systematic.py @@ -32,20 +32,24 @@ class test_polar_encoder_systematic(gr_unittest.TestCase): def test_001_setup(self): block_size = 16 num_info_bits = 8 - frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0) + frozen_bit_positions = cc.frozen_bit_positions( + block_size, num_info_bits, 0.0) - polar_encoder = fec.polar_encoder_systematic.make(block_size, num_info_bits, frozen_bit_positions) + polar_encoder = fec.polar_encoder_systematic.make( + block_size, num_info_bits, frozen_bit_positions) self.assertEqual(block_size, polar_encoder.get_output_size()) self.assertEqual(num_info_bits, polar_encoder.get_input_size()) - self.assertFloatTuplesAlmostEqual((float(num_info_bits) / block_size, ), (polar_encoder.rate(), )) + self.assertFloatTuplesAlmostEqual( + (float(num_info_bits) / block_size, ), (polar_encoder.rate(), )) self.assertFalse(polar_encoder.set_frame_size(10)) def test_002_work_function_packed(self): block_size = 256 num_info_bits = block_size // 2 - data, ref, polar_encoder = self.get_test_data(block_size, num_info_bits, 1) + data, ref, polar_encoder = self.get_test_data( + block_size, num_info_bits, 1) src = blocks.vector_source_b(data, False) enc_block = extended_encoder(polar_encoder, None, '11') snk = blocks.vector_sink_b(1) @@ -61,7 +65,8 @@ class test_polar_encoder_systematic(gr_unittest.TestCase): block_size = 1024 num_info_bits = block_size // 8 - data, ref, polar_encoder = self.get_test_data(block_size, num_info_bits, num_blocks) + data, ref, polar_encoder = self.get_test_data( + block_size, num_info_bits, num_blocks) src = blocks.vector_source_b(data, False) enc_block = extended_encoder(polar_encoder, None, '11') snk = blocks.vector_sink_b(1) @@ -75,9 +80,14 @@ class test_polar_encoder_systematic(gr_unittest.TestCase): def get_test_data(self, block_size, num_info_bits, num_blocks): # helper function to set up test data and together with encoder object. num_frozen_bits = block_size - num_info_bits - frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0) + frozen_bit_positions = cc.frozen_bit_positions( + block_size, num_info_bits, 0.0) frozen_bit_values = np.array([0] * num_frozen_bits,) - python_encoder = PolarEncoder(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values) + python_encoder = PolarEncoder( + block_size, + num_info_bits, + frozen_bit_positions, + frozen_bit_values) data = np.array([], dtype=int) ref = np.array([], dtype=int) @@ -85,7 +95,8 @@ class test_polar_encoder_systematic(gr_unittest.TestCase): d = np.random.randint(2, size=num_info_bits) data = np.append(data, d) ref = np.append(ref, python_encoder.encode_systematic(d)) - polar_encoder = fec.polar_encoder_systematic.make(block_size, num_info_bits, frozen_bit_positions) + polar_encoder = fec.polar_encoder_systematic.make( + block_size, num_info_bits, frozen_bit_positions) return data, ref, polar_encoder diff --git a/gr-fec/python/fec/qa_puncture.py b/gr-fec/python/fec/qa_puncture.py index 15262925ae..2508814c45 100644 --- a/gr-fec/python/fec/qa_puncture.py +++ b/gr-fec/python/fec/qa_puncture.py @@ -28,10 +28,10 @@ class test_puncture (gr_unittest.TestCase): for n in range(len(self.src_data) // self.puncsize): for i in range(self.puncsize): if _puncpat[i] == 1: - self.expected.append(self.src_data[n*self.puncsize+i]); + self.expected.append(self.src_data[n * self.puncsize + i]) def setUp(self): - self.src_data = 10000*list(range(64)) + self.src_data = 10000 * list(range(64)) self.tb = gr.top_block() def tearDown(self): @@ -47,7 +47,7 @@ class test_puncture (gr_unittest.TestCase): self.puncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.puncture_bb(self.puncsize, self.puncpat, self.delay) + op = fec.puncture_bb(self.puncsize, self.puncpat, self.delay) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) @@ -59,7 +59,6 @@ class test_puncture (gr_unittest.TestCase): self.assertEqual(self.expected, dst_data) - def test_001(self): # Test normal operation of the puncture block with a delay @@ -72,7 +71,7 @@ class test_puncture (gr_unittest.TestCase): self.puncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.puncture_bb(self.puncsize, self.puncpat, self.delay) + op = fec.puncture_bb(self.puncsize, self.puncpat, self.delay) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) @@ -84,7 +83,6 @@ class test_puncture (gr_unittest.TestCase): self.assertEqual(self.expected, dst_data) - def test_002(self): # Test scenario where we have defined a puncture pattern with # more bits than the puncsize. @@ -96,7 +94,7 @@ class test_puncture (gr_unittest.TestCase): self.puncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.puncture_bb(self.puncsize, self.puncpat, self.delay) + op = fec.puncture_bb(self.puncsize, self.puncpat, self.delay) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) @@ -115,13 +113,13 @@ class test_puncture (gr_unittest.TestCase): # this should be equivalent to a puncpat of the correct size. self.puncsize = 4 - self.puncpat0 = 0x5555 # too many bits set + self.puncpat0 = 0x5555 # too many bits set self.puncpat1 = 0x55 # num bits = puncsize self.delay = 1 src = blocks.vector_source_b(self.src_data) - op0 = fec.puncture_bb(self.puncsize, self.puncpat0, self.delay) - op1 = fec.puncture_bb(self.puncsize, self.puncpat1, self.delay) + op0 = fec.puncture_bb(self.puncsize, self.puncpat0, self.delay) + op1 = fec.puncture_bb(self.puncsize, self.puncpat1, self.delay) dst0 = blocks.vector_sink_b() dst1 = blocks.vector_sink_b() @@ -139,8 +137,6 @@ class test_puncture (gr_unittest.TestCase): self.assertEqual(dst_data1, dst_data0) - - def test_f_000(self): # Test normal operation of the float puncture block @@ -151,7 +147,7 @@ class test_puncture (gr_unittest.TestCase): self.puncture_setup() src = blocks.vector_source_f(self.src_data) - op = fec.puncture_ff(self.puncsize, self.puncpat, self.delay) + op = fec.puncture_ff(self.puncsize, self.puncpat, self.delay) dst = blocks.vector_sink_f() self.tb.connect(src, op, dst) @@ -160,7 +156,6 @@ class test_puncture (gr_unittest.TestCase): dst_data = list(dst.data()) self.assertEqual(self.expected, dst_data) - def test_f_001(self): # Test normal operation of the puncture block with a delay @@ -173,7 +168,7 @@ class test_puncture (gr_unittest.TestCase): self.puncture_setup() src = blocks.vector_source_f(self.src_data) - op = fec.puncture_ff(self.puncsize, self.puncpat, self.delay) + op = fec.puncture_ff(self.puncsize, self.puncpat, self.delay) dst = blocks.vector_sink_f() self.tb.connect(src, op, dst) @@ -182,7 +177,6 @@ class test_puncture (gr_unittest.TestCase): dst_data = list(dst.data()) self.assertEqual(self.expected, dst_data) - def test_f_002(self): # Test scenariou where we have defined a puncture pattern with # more bits than the puncsize. @@ -194,7 +188,7 @@ class test_puncture (gr_unittest.TestCase): self.puncture_setup() src = blocks.vector_source_f(self.src_data) - op = fec.puncture_ff(self.puncsize, self.puncpat, self.delay) + op = fec.puncture_ff(self.puncsize, self.puncpat, self.delay) dst = blocks.vector_sink_f() self.tb.connect(src, op, dst) @@ -210,13 +204,13 @@ class test_puncture (gr_unittest.TestCase): # this should be equivalent to a puncpat of the correct size. self.puncsize = 4 - self.puncpat0 = 0x5555 # too many bits set + self.puncpat0 = 0x5555 # too many bits set self.puncpat1 = 0x55 # num bits = puncsize self.delay = 1 src = blocks.vector_source_f(self.src_data) - op0 = fec.puncture_ff(self.puncsize, self.puncpat0, self.delay) - op1 = fec.puncture_ff(self.puncsize, self.puncpat1, self.delay) + op0 = fec.puncture_ff(self.puncsize, self.puncpat0, self.delay) + op1 = fec.puncture_ff(self.puncsize, self.puncpat1, self.delay) dst0 = blocks.vector_sink_f() dst1 = blocks.vector_sink_f() @@ -229,5 +223,6 @@ class test_puncture (gr_unittest.TestCase): self.assertEqual(dst_data1, dst_data0) + if __name__ == '__main__': gr_unittest.run(test_puncture) diff --git a/gr-fft/python/fft/qa_fft.py b/gr-fft/python/fft/qa_fft.py index 36af441fd2..c1b8bbdf40 100644 --- a/gr-fft/python/fft/qa_fft.py +++ b/gr-fft/python/fft/qa_fft.py @@ -20,10 +20,71 @@ from gnuradio import gr, gr_unittest, fft, blocks # windowed = fft(src_data(:).*hamming(32)) # reverse_window_shift = ifft(fftshift(forward.*hamming(32))) -primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, - 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, - 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, - 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311) +primes = ( + 2, + 3, + 5, + 7, + 11, + 13, + 17, + 19, + 23, + 29, + 31, + 37, + 41, + 43, + 47, + 53, + 59, + 61, + 67, + 71, + 73, + 79, + 83, + 89, + 97, + 101, + 103, + 107, + 109, + 113, + 127, + 131, + 137, + 139, + 149, + 151, + 157, + 163, + 167, + 173, + 179, + 181, + 191, + 193, + 197, + 199, + 211, + 223, + 227, + 229, + 233, + 239, + 241, + 251, + 257, + 263, + 269, + 271, + 277, + 281, + 283, + 293, + 307, + 311) primes_transformed = ((4377 + 4516j), (-1706.1268310546875 + 1638.4256591796875j), @@ -73,7 +134,8 @@ class test_fft(gr_unittest.TestCase): abs_eps=1e-9, rel_eps=4e-4) def test_forward(self): - src_data = tuple([complex(primes[2 * i], primes[2 * i + 1]) for i in range(self.fft_size)]) + src_data = tuple([complex(primes[2 * i], primes[2 * i + 1]) + for i in range(self.fft_size)]) expected_result = primes_transformed src = blocks.vector_source_c(src_data) @@ -88,7 +150,8 @@ class test_fft(gr_unittest.TestCase): def test_reverse(self): src_data = tuple([x / self.fft_size for x in primes_transformed]) - expected_result = tuple([complex(primes[2 * i], primes[2 * i + 1]) for i in range(self.fft_size)]) + expected_result = tuple( + [complex(primes[2 * i], primes[2 * i + 1]) for i in range(self.fft_size)]) src = blocks.vector_source_c(src_data) s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) @@ -103,7 +166,8 @@ class test_fft(gr_unittest.TestCase): def test_multithreaded(self): # Same test as above, only use 2 threads src_data = tuple([x / self.fft_size for x in primes_transformed]) - expected_result = tuple([complex(primes[2 * i], primes[2 * i + 1]) for i in range(self.fft_size)]) + expected_result = tuple( + [complex(primes[2 * i], primes[2 * i + 1]) for i in range(self.fft_size)]) nthreads = 2 src = blocks.vector_source_c(src_data) @@ -117,7 +181,8 @@ class test_fft(gr_unittest.TestCase): self.assert_fft_ok2(expected_result, result_data) def test_window(self): - src_data = tuple([complex(primes[2 * i], primes[2 * i + 1]) for i in range(self.fft_size)]) + src_data = tuple([complex(primes[2 * i], primes[2 * i + 1]) + for i in range(self.fft_size)]) expected_result = ((2238.9174 + 2310.4750j), (-1603.7416 - 466.7420j), (116.7449 - 70.8553j), diff --git a/gr-fft/python/fft/qa_goertzel.py b/gr-fft/python/fft/qa_goertzel.py index ee4af1bb40..b7eb1f168a 100644 --- a/gr-fft/python/fft/qa_goertzel.py +++ b/gr-fft/python/fft/qa_goertzel.py @@ -13,6 +13,7 @@ from math import pi, cos from gnuradio import gr, gr_unittest, fft, blocks + class test_goertzel(gr_unittest.TestCase): def setUp(self): @@ -22,7 +23,7 @@ class test_goertzel(gr_unittest.TestCase): self.tb = None def make_tone_data(self, rate, freq): - return [cos(2*pi*x*freq/rate) for x in range(rate)] + return [cos(2 * pi * x * freq / rate) for x in range(rate)] def transform(self, src_data, rate, freq): src = blocks.vector_source_f(src_data, False) @@ -32,7 +33,7 @@ class test_goertzel(gr_unittest.TestCase): self.tb.run() return dst.data() - def test_001(self): # Measure single tone magnitude + def test_001(self): # Measure single tone magnitude rate = 8000 freq = 100 bin = freq @@ -41,7 +42,7 @@ class test_goertzel(gr_unittest.TestCase): actual_result = abs(self.transform(src_data, rate, bin)[0]) self.assertAlmostEqual(expected_result, actual_result, places=4) - def test_002(self): # Measure off frequency magnitude + def test_002(self): # Measure off frequency magnitude rate = 8000 freq = 100 bin = freq / 2 @@ -50,5 +51,6 @@ class test_goertzel(gr_unittest.TestCase): actual_result = abs(self.transform(src_data, rate, bin)[0]) self.assertAlmostEqual(expected_result, actual_result, places=4) + if __name__ == '__main__': gr_unittest.run(test_goertzel) diff --git a/gr-fft/python/fft/qa_window.py b/gr-fft/python/fft/qa_window.py index f5afd2640d..ba133f6cb4 100644 --- a/gr-fft/python/fft/qa_window.py +++ b/gr-fft/python/fft/qa_window.py @@ -14,6 +14,7 @@ import numpy from gnuradio import gr_unittest from gnuradio import fft + class test_window(gr_unittest.TestCase): """ Unit tests for fft.window @@ -29,9 +30,13 @@ class test_window(gr_unittest.TestCase): """ Verify window normalization """ - win = fft.window.build(fft.win_type.WIN_BLACKMAN_hARRIS, 21, normalize=True) - power = numpy.sum([x*x for x in win])/len(win) + win = fft.window.build( + fft.win_type.WIN_BLACKMAN_hARRIS, + 21, + normalize=True) + power = numpy.sum([x * x for x in win]) / len(win) self.assertAlmostEqual(power, 1.0) + if __name__ == '__main__': gr_unittest.run(test_window) diff --git a/gr-filter/python/filter/qa_dc_blocker.py b/gr-filter/python/filter/qa_dc_blocker.py index aaca17cf9b..59adde2666 100644 --- a/gr-filter/python/filter/qa_dc_blocker.py +++ b/gr-filter/python/filter/qa_dc_blocker.py @@ -11,54 +11,57 @@ from gnuradio import gr, gr_unittest, filter, blocks + class test_dc_blocker(gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_001(self): ''' Test impulse response - long form, cc ''' - src_data = [1,] + 100*[0,] - expected_result = ((-0.02072429656982422+0j), (-0.02081298828125+0j), - (0.979156494140625+0j), (-0.02081298828125+0j), - (-0.02072429656982422+0j)) + src_data = [1, ] + 100 * [0, ] + expected_result = ( + (-0.02072429656982422 + 0j), + (-0.02081298828125 + 0j), + (0.979156494140625 + 0j), + (-0.02081298828125 + 0j), + (-0.02072429656982422 + 0j)) src = blocks.vector_source_c(src_data) op = filter.dc_blocker_cc(32, True) dst = blocks.vector_sink_c() - self.tb.connect (src, op, dst) + self.tb.connect(src, op, dst) self.tb.run() # only test samples around 2D-2 result_data = dst.data()[60:65] - self.assertComplexTuplesAlmostEqual (expected_result, result_data) + self.assertComplexTuplesAlmostEqual(expected_result, result_data) def test_002(self): ''' Test impulse response - short form, cc ''' - src_data = [1,] + 100*[0,] - expected_result = ((-0.029296875+0j), (-0.0302734375+0j), - (0.96875+0j), (-0.0302734375+0j), - (-0.029296875+0j)) + src_data = [1, ] + 100 * [0, ] + expected_result = ((-0.029296875 + 0j), (-0.0302734375 + 0j), + (0.96875 + 0j), (-0.0302734375 + 0j), + (-0.029296875 + 0j)) src = blocks.vector_source_c(src_data) op = filter.dc_blocker_cc(32, False) dst = blocks.vector_sink_c() - self.tb.connect (src, op, dst) + self.tb.connect(src, op, dst) self.tb.run() # only test samples around D-1 result_data = dst.data()[29:34] - self.assertComplexTuplesAlmostEqual (expected_result, result_data) - + self.assertComplexTuplesAlmostEqual(expected_result, result_data) def test_003(self): ''' Test impulse response - long form, ff ''' - src_data = [1,] + 100*[0,] + src_data = [1, ] + 100 * [0, ] expected_result = ((-0.02072429656982422), (-0.02081298828125), (0.979156494140625), (-0.02081298828125), (-0.02072429656982422)) @@ -67,16 +70,16 @@ class test_dc_blocker(gr_unittest.TestCase): op = filter.dc_blocker_ff(32, True) dst = blocks.vector_sink_f() - self.tb.connect (src, op, dst) + self.tb.connect(src, op, dst) self.tb.run() # only test samples around 2D-2 result_data = dst.data()[60:65] - self.assertFloatTuplesAlmostEqual (expected_result, result_data) + self.assertFloatTuplesAlmostEqual(expected_result, result_data) def test_004(self): ''' Test impulse response - short form, ff ''' - src_data = [1,] + 100*[0,] + src_data = [1, ] + 100 * [0, ] expected_result = ((-0.029296875), (-0.0302734375), (0.96875), (-0.0302734375), (-0.029296875)) @@ -85,13 +88,13 @@ class test_dc_blocker(gr_unittest.TestCase): op = filter.dc_blocker_ff(32, False) dst = blocks.vector_sink_f() - self.tb.connect (src, op, dst) + self.tb.connect(src, op, dst) self.tb.run() # only test samples around D-1 result_data = dst.data()[29:34] - self.assertFloatTuplesAlmostEqual (expected_result, result_data) + self.assertFloatTuplesAlmostEqual(expected_result, result_data) + if __name__ == '__main__': gr_unittest.run(test_dc_blocker) - diff --git a/gr-filter/python/filter/qa_fft_filter.py b/gr-filter/python/filter/qa_fft_filter.py index 135618fdb4..453fb1bc60 100644 --- a/gr-filter/python/filter/qa_fft_filter.py +++ b/gr-filter/python/filter/qa_fft_filter.py @@ -14,17 +14,19 @@ from gnuradio import gr, gr_unittest, filter, blocks import sys import random + def make_random_complex_tuple(L): result = [] for x in range(L): - result.append(complex(2*random.random()-1, - 2*random.random()-1)) + result.append(complex(2 * random.random() - 1, + 2 * random.random() - 1)) return tuple(result) + def make_random_float_tuple(L): result = [] for x in range(L): - result.append(float(int(2*random.random()-1))) + result.append(float(int(2 * random.random() - 1))) return tuple(result) @@ -41,6 +43,7 @@ def reference_filter_ccc(dec, taps, input): tb.run() return dst.data() + def reference_filter_fff(dec, taps, input): """ compute result using conventional fir filter @@ -54,6 +57,7 @@ def reference_filter_fff(dec, taps, input): tb.run() return dst.data() + def reference_filter_ccf(dec, taps, input): """ compute result using conventional fir filter @@ -84,68 +88,73 @@ class test_fft_filter(gr_unittest.TestCase): def assert_fft_ok2(self, expected_result, result_data): expected_result = expected_result[:len(result_data)] - self.assertComplexTuplesAlmostEqual2 (expected_result, result_data, - abs_eps=1e-9, rel_eps=4e-4) - - def assert_fft_float_ok2(self, expected_result, result_data, abs_eps=1e-9, rel_eps=4e-4): + self.assertComplexTuplesAlmostEqual2(expected_result, result_data, + abs_eps=1e-9, rel_eps=4e-4) + + def assert_fft_float_ok2( + self, + expected_result, + result_data, + abs_eps=1e-9, + rel_eps=4e-4): expected_result = expected_result[:len(result_data)] - self.assertFloatTuplesAlmostEqual2 (expected_result, result_data, - abs_eps, rel_eps) + self.assertFloatTuplesAlmostEqual2(expected_result, result_data, + abs_eps, rel_eps) def test_ccc_001(self): tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) + src_data = (0, 1, 2, 3, 4, 5, 6, 7) taps = (1,) - expected_result = tuple([complex(x) for x in (0,1,2,3,4,5,6,7)]) + expected_result = tuple([complex(x) for x in (0, 1, 2, 3, 4, 5, 6, 7)]) src = blocks.vector_source_c(src_data) - op = filter.fft_filter_ccc(1, taps) + op = filter.fft_filter_ccc(1, taps) dst = blocks.vector_sink_c() tb.connect(src, op, dst) tb.run() result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - + # print 'expected:', expected_result + # print 'results: ', result_data + self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5) def test_ccc_002(self): # Test nthreads tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) + src_data = (0, 1, 2, 3, 4, 5, 6, 7) taps = (2,) nthreads = 2 - expected_result = tuple([2 * complex(x) for x in (0,1,2,3,4,5,6,7)]) + expected_result = tuple([2 * complex(x) + for x in (0, 1, 2, 3, 4, 5, 6, 7)]) src = blocks.vector_source_c(src_data) op = filter.fft_filter_ccc(1, taps, nthreads) dst = blocks.vector_sink_c() tb.connect(src, op, dst) tb.run() result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) + # print 'expected:', expected_result + # print 'results: ', result_data + self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5) def test_ccc_003(self): tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) + src_data = (0, 1, 2, 3, 4, 5, 6, 7) taps = (2,) - expected_result = tuple([2 * complex(x) for x in (0,1,2,3,4,5,6,7)]) + expected_result = tuple([2 * complex(x) + for x in (0, 1, 2, 3, 4, 5, 6, 7)]) src = blocks.vector_source_c(src_data) op = filter.fft_filter_ccc(1, taps) dst = blocks.vector_sink_c() tb.connect(src, op, dst) tb.run() result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - + # print 'expected:', expected_result + # print 'results: ', result_data + self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5) def test_ccc_004(self): random.seed(0) for i in range(25): # sys.stderr.write("\n>>> Loop = %d\n" % (i,)) - src_len = 4*1024 + src_len = 4 * 1024 src_data = make_random_complex_tuple(src_len) ntaps = int(random.uniform(2, 1000)) taps = make_random_complex_tuple(ntaps) @@ -166,7 +175,7 @@ class test_fft_filter(gr_unittest.TestCase): for i in range(25): # sys.stderr.write("\n>>> Loop = %d\n" % (i,)) dec = i + 1 - src_len = 4*1024 + src_len = 4 * 1024 src_data = make_random_complex_tuple(src_len) ntaps = int(random.uniform(2, 100)) taps = make_random_complex_tuple(ntaps) @@ -190,7 +199,7 @@ class test_fft_filter(gr_unittest.TestCase): for i in range(25): # sys.stderr.write("\n>>> Loop = %d\n" % (i,)) dec = i + 1 - src_len = 4*1024 + src_len = 4 * 1024 src_data = make_random_complex_tuple(src_len) ntaps = int(random.uniform(2, 100)) taps = make_random_complex_tuple(ntaps) @@ -213,58 +222,58 @@ class test_fft_filter(gr_unittest.TestCase): def test_ccf_001(self): tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) + src_data = (0, 1, 2, 3, 4, 5, 6, 7) taps = (1,) - expected_result = tuple([complex(x) for x in (0,1,2,3,4,5,6,7)]) + expected_result = tuple([complex(x) for x in (0, 1, 2, 3, 4, 5, 6, 7)]) src = blocks.vector_source_c(src_data) - op = filter.fft_filter_ccf(1, taps) + op = filter.fft_filter_ccf(1, taps) dst = blocks.vector_sink_c() tb.connect(src, op, dst) tb.run() result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - + # print 'expected:', expected_result + # print 'results: ', result_data + self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5) def test_ccf_002(self): # Test nthreads tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) + src_data = (0, 1, 2, 3, 4, 5, 6, 7) taps = (2,) nthreads = 2 - expected_result = tuple([2 * complex(x) for x in (0,1,2,3,4,5,6,7)]) + expected_result = tuple([2 * complex(x) + for x in (0, 1, 2, 3, 4, 5, 6, 7)]) src = blocks.vector_source_c(src_data) op = filter.fft_filter_ccf(1, taps, nthreads) dst = blocks.vector_sink_c() tb.connect(src, op, dst) tb.run() result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) + # print 'expected:', expected_result + # print 'results: ', result_data + self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5) def test_ccf_003(self): tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) + src_data = (0, 1, 2, 3, 4, 5, 6, 7) taps = (2,) - expected_result = tuple([2 * complex(x) for x in (0,1,2,3,4,5,6,7)]) + expected_result = tuple([2 * complex(x) + for x in (0, 1, 2, 3, 4, 5, 6, 7)]) src = blocks.vector_source_c(src_data) op = filter.fft_filter_ccf(1, taps) dst = blocks.vector_sink_c() tb.connect(src, op, dst) tb.run() result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - + # print 'expected:', expected_result + # print 'results: ', result_data + self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5) def test_ccf_004(self): random.seed(0) for i in range(25): # sys.stderr.write("\n>>> Loop = %d\n" % (i,)) - src_len = 4*1024 + src_len = 4 * 1024 src_data = make_random_complex_tuple(src_len) ntaps = int(random.uniform(2, 1000)) taps = make_random_float_tuple(ntaps) @@ -285,7 +294,7 @@ class test_fft_filter(gr_unittest.TestCase): for i in range(25): # sys.stderr.write("\n>>> Loop = %d\n" % (i,)) dec = i + 1 - src_len = 4*1024 + src_len = 4 * 1024 src_data = make_random_complex_tuple(src_len) ntaps = int(random.uniform(2, 100)) taps = make_random_float_tuple(ntaps) @@ -309,7 +318,7 @@ class test_fft_filter(gr_unittest.TestCase): for i in range(25): # sys.stderr.write("\n>>> Loop = %d\n" % (i,)) dec = i + 1 - src_len = 4*1024 + src_len = 4 * 1024 src_data = make_random_complex_tuple(src_len) ntaps = int(random.uniform(2, 100)) taps = make_random_float_tuple(ntaps) @@ -332,49 +341,50 @@ class test_fft_filter(gr_unittest.TestCase): def test_fff_001(self): tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) + src_data = (0, 1, 2, 3, 4, 5, 6, 7) taps = (1,) - expected_result = tuple([float(x) for x in (0,1,2,3,4,5,6,7)]) + expected_result = tuple([float(x) for x in (0, 1, 2, 3, 4, 5, 6, 7)]) src = blocks.vector_source_f(src_data) op = filter.fft_filter_fff(1, taps) dst = blocks.vector_sink_f() tb.connect(src, op, dst) tb.run() result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertFloatTuplesAlmostEqual (expected_result, result_data, 5) - + # print 'expected:', expected_result + # print 'results: ', result_data + self.assertFloatTuplesAlmostEqual(expected_result, result_data, 5) def test_fff_002(self): tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) + src_data = (0, 1, 2, 3, 4, 5, 6, 7) taps = (2,) - expected_result = tuple([2 * float(x) for x in (0,1,2,3,4,5,6,7)]) + expected_result = tuple([2 * float(x) + for x in (0, 1, 2, 3, 4, 5, 6, 7)]) src = blocks.vector_source_f(src_data) op = filter.fft_filter_fff(1, taps) dst = blocks.vector_sink_f() tb.connect(src, op, dst) tb.run() result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertFloatTuplesAlmostEqual (expected_result, result_data, 5) + # print 'expected:', expected_result + # print 'results: ', result_data + self.assertFloatTuplesAlmostEqual(expected_result, result_data, 5) def test_fff_003(self): # Test 02 with nthreads tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) + src_data = (0, 1, 2, 3, 4, 5, 6, 7) taps = (2,) nthreads = 2 - expected_result = tuple([2 * float(x) for x in (0,1,2,3,4,5,6,7)]) + expected_result = tuple([2 * float(x) + for x in (0, 1, 2, 3, 4, 5, 6, 7)]) src = blocks.vector_source_f(src_data) op = filter.fft_filter_fff(1, taps, nthreads) dst = blocks.vector_sink_f() tb.connect(src, op, dst) tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data, 5) + self.assertFloatTuplesAlmostEqual(expected_result, result_data, 5) def xtest_fff_004(self): random.seed(0) @@ -394,9 +404,10 @@ class test_fft_filter(gr_unittest.TestCase): tb.run() result_data = dst.data() - #print "src_len =", src_len, " ntaps =", ntaps + # print "src_len =", src_len, " ntaps =", ntaps try: - self.assert_fft_float_ok2(expected_result, result_data, abs_eps=1.0) + self.assert_fft_float_ok2( + expected_result, result_data, abs_eps=1.0) except AssertionError: expected = open('expected', 'w') for x in expected_result: @@ -410,7 +421,7 @@ class test_fft_filter(gr_unittest.TestCase): random.seed(0) for i in range(25): sys.stderr.write("\n>>> Loop = %d\n" % (i,)) - src_len = 4*1024 + src_len = 4 * 1024 src_data = make_random_float_tuple(src_len) ntaps = int(random.uniform(2, 1000)) taps = make_random_float_tuple(ntaps) @@ -424,14 +435,15 @@ class test_fft_filter(gr_unittest.TestCase): tb.run() result_data = dst.data() - self.assert_fft_float_ok2(expected_result, result_data, abs_eps=2.0) + self.assert_fft_float_ok2( + expected_result, result_data, abs_eps=2.0) def xtest_fff_006(self): random.seed(0) for i in range(25): sys.stderr.write("\n>>> Loop = %d\n" % (i,)) dec = i + 1 - src_len = 4*1024 + src_len = 4 * 1024 src_data = make_random_float_tuple(src_len) ntaps = int(random.uniform(2, 100)) taps = make_random_float_tuple(ntaps) @@ -454,7 +466,7 @@ class test_fft_filter(gr_unittest.TestCase): for i in range(25): sys.stderr.write("\n>>> Loop = %d\n" % (i,)) dec = i + 1 - src_len = 4*1024 + src_len = 4 * 1024 src_data = make_random_float_tuple(src_len) ntaps = int(random.uniform(2, 100)) taps = make_random_float_tuple(ntaps) @@ -478,7 +490,7 @@ class test_fft_filter(gr_unittest.TestCase): op = filter.fft_filter_fff(1, taps) result_data = op.taps() - #print result_data + # print result_data self.assertEqual(taps, result_data) @@ -490,7 +502,7 @@ class test_fft_filter(gr_unittest.TestCase): op = filter.fft_filter_ccc(1, taps) result_data = op.taps() - #print result_data + # print result_data self.assertComplexTuplesAlmostEqual(taps, result_data, 4) diff --git a/gr-filter/python/filter/qa_file_taps_loader.py b/gr-filter/python/filter/qa_file_taps_loader.py index ff0b2ecc3a..592e7a9844 100755 --- a/gr-filter/python/filter/qa_file_taps_loader.py +++ b/gr-filter/python/filter/qa_file_taps_loader.py @@ -15,12 +15,13 @@ import numpy as np from gnuradio import gr, gr_unittest, filter from file_taps_loader import file_taps_loader + class qa_file_taps_loader (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_float_taps(self): @@ -33,19 +34,20 @@ class qa_file_taps_loader (gr_unittest.TestCase): c_path = os.path.dirname( os.path.abspath( inspect.getfile(inspect.currentframe()))) + "/" + path - test_file_content = ("restype,fir\n" - "fs,320000.\n" - "pbend,50000.0\n" - "gain,2.0\n" - "sbstart,100000.0\n" - "filttype,lpf\n" - "atten,40.0\n" - "wintype,0\n" - "ntaps,11\n" - "taps,-0.010157553479075432,-0.01920645497739315,0.01674678549170494," - "0.20396660268306732,0.49091556668281555,0.6354700922966003," - "0.49091556668281555,0.20396660268306732,0.01674678549170494," - "-0.01920645497739315,-0.010157553479075432\n") + test_file_content = ( + "restype,fir\n" + "fs,320000.\n" + "pbend,50000.0\n" + "gain,2.0\n" + "sbstart,100000.0\n" + "filttype,lpf\n" + "atten,40.0\n" + "wintype,0\n" + "ntaps,11\n" + "taps,-0.010157553479075432,-0.01920645497739315,0.01674678549170494," + "0.20396660268306732,0.49091556668281555,0.6354700922966003," + "0.49091556668281555,0.20396660268306732,0.01674678549170494," + "-0.01920645497739315,-0.010157553479075432\n") test_file = open(c_path, 'w') test_file.write(test_file_content) test_file.close() @@ -69,46 +71,53 @@ class qa_file_taps_loader (gr_unittest.TestCase): # Parameters path = "test_taps_complex" # For sanity reasons work with absolute path here. - c_path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + "/" + path - test_file_content = ("restype,fir\n" - "fs,320000.0\n" - "pbend,100000.0\n" - "gain,2.0\n" - "filttype,cbpf\n" - "atten,10.0\n" - "ntaps,15\n" - "tb,10000.0\n" - "wintype,0\n" - "pbstart,50000.0\n" - "taps,(0.00151832250413-0.0018500800943j),(-0.00244879024103-0.00163623178378j)," - "(0.0109249493107-0.0204391144216j),(0.0673716515303+0.0279062893242j)," - "(-0.0446246191859+0.147107481956j),(-0.243210762739-0.0483776889741j)," - "(0.031814865768-0.323020994663j),(0.354127079248+8.44304750558e-08j)," - "(0.0318147130311+0.323020994663j),(-0.243210792542+0.0483775734901j)," - "(-0.0446245521307-0.147107496858j),(0.0673716664314-0.0279062557966j)," - "(0.0109249399975+0.0204391200095j),(-0.00244879163802+0.00163622945547j)," - "(0.0015183207579+0.0018500816077j)\n") + c_path = os.path.dirname( + os.path.abspath( + inspect.getfile( + inspect.currentframe()))) + "/" + path + test_file_content = ( + "restype,fir\n" + "fs,320000.0\n" + "pbend,100000.0\n" + "gain,2.0\n" + "filttype,cbpf\n" + "atten,10.0\n" + "ntaps,15\n" + "tb,10000.0\n" + "wintype,0\n" + "pbstart,50000.0\n" + "taps,(0.00151832250413-0.0018500800943j),(-0.00244879024103-0.00163623178378j)," + "(0.0109249493107-0.0204391144216j),(0.0673716515303+0.0279062893242j)," + "(-0.0446246191859+0.147107481956j),(-0.243210762739-0.0483776889741j)," + "(0.031814865768-0.323020994663j),(0.354127079248+8.44304750558e-08j)," + "(0.0318147130311+0.323020994663j),(-0.243210792542+0.0483775734901j)," + "(-0.0446245521307-0.147107496858j),(0.0673716664314-0.0279062557966j)," + "(0.0109249399975+0.0204391200095j),(-0.00244879163802+0.00163622945547j)," + "(0.0015183207579+0.0018500816077j)\n") test_file = open(c_path, 'w') test_file.write(test_file_content) test_file.close() verbose = False ftl = filter.file_taps_loader(c_path, verbose) os.remove(c_path) - expected_taps = tuple(np.array(((0.0015183225041255355-0.0018500800943002105j), - (-0.002448790241032839-0.0016362317837774754j), - (0.010924949310719967-0.020439114421606064j), - (0.06737165153026581+0.02790628932416439j), - (-0.04462461918592453+0.14710748195648193j), - (-0.24321076273918152-0.048377688974142075j), - (0.03181486576795578-0.3230209946632385j), - (0.35412707924842834+8.44304750557967e-08j), - (0.03181471303105354+0.3230209946632385j), - (-0.2432107925415039+0.04837757349014282j), - (-0.04462455213069916-0.14710749685764313j), - (0.067371666431427-0.027906255796551704j), - (0.01092493999749422+0.02043912000954151j), - (-0.0024487916380167007+0.0016362294554710388j), - (0.001518320757895708+0.0018500816076993942j)), dtype=complex)) + expected_taps = tuple( + np.array( + ((0.0015183225041255355 - 0.0018500800943002105j), + (-0.002448790241032839 - 0.0016362317837774754j), + (0.010924949310719967 - 0.020439114421606064j), + (0.06737165153026581 + 0.02790628932416439j), + (-0.04462461918592453 + 0.14710748195648193j), + (-0.24321076273918152 - 0.048377688974142075j), + (0.03181486576795578 - 0.3230209946632385j), + (0.35412707924842834 + 8.44304750557967e-08j), + (0.03181471303105354 + 0.3230209946632385j), + (-0.2432107925415039 + 0.04837757349014282j), + (-0.04462455213069916 - 0.14710749685764313j), + (0.067371666431427 - 0.027906255796551704j), + (0.01092493999749422 + 0.02043912000954151j), + (-0.0024487916380167007 + 0.0016362294554710388j), + (0.001518320757895708 + 0.0018500816076993942j)), + dtype=complex)) # Verify types self.assertEqual(type(ftl.get_taps()), type(expected_taps)) self.assertEqual(type(ftl.get_taps()[0]), type(expected_taps[0])) @@ -128,7 +137,9 @@ class qa_file_taps_loader (gr_unittest.TestCase): with self.assertRaises(RuntimeError) as re: _ = filter.file_taps_loader(path, verbose) # Is the correct exception raised? - self.assertEqual(str(re.exception), "file_taps_loader: Can not open " + "\"" + path + "\"" + ".") + self.assertEqual(str(re.exception), + "file_taps_loader: Can not open " + "\"" + path + "\"" + ".") + if __name__ == '__main__': gr_unittest.run(qa_file_taps_loader) diff --git a/gr-filter/python/filter/qa_filter_delay_fc.py b/gr-filter/python/filter/qa_filter_delay_fc.py index 9a806248ec..b6a21c1cc3 100644 --- a/gr-filter/python/filter/qa_filter_delay_fc.py +++ b/gr-filter/python/filter/qa_filter_delay_fc.py @@ -13,37 +13,42 @@ from gnuradio import gr, gr_unittest, filter, blocks import math + def sin_source_f(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.sin(2.*math.pi*freq*x) for x in t] + y = [math.sin(2. * math.pi * freq * x) for x in t] return y + def cos_source_f(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.cos(2.*math.pi*freq*x) for x in t] + y = [math.cos(2. * math.pi * freq * x) for x in t] return y + def fir_filter(x, taps, delay): y = [] - x2 = (len(taps)-1)*[0,] + x + x2 = (len(taps) - 1) * [0, ] + x for i in range(len(x)): yi = 0 for j in range(len(taps)): - yi += taps[len(taps)-1-j] * x2[i+j] - y.append(complex(x2[i+delay], yi)) + yi += taps[len(taps) - 1 - j] * x2[i + j] + y.append(complex(x2[i + delay], yi)) return y + def fir_filter2(x1, x2, taps, delay): y = [] - x1_2 = (len(taps)-1)*[0,] + x1 - x2_2 = (len(taps)-1)*[0,] + x2 + x1_2 = (len(taps) - 1) * [0, ] + x1 + x2_2 = (len(taps) - 1) * [0, ] + x2 for i in range(len(x2)): yi = 0 for j in range(len(taps)): - yi += taps[len(taps)-1-j] * x2_2[i+j] - y.append(complex(x1_2[i+delay], yi)) + yi += taps[len(taps) - 1 - j] * x2_2[i + j] + y.append(complex(x1_2[i + delay], yi)) return y + class test_filter_delay_fc(gr_unittest.TestCase): def setUp(self): @@ -67,7 +72,7 @@ class test_filter_delay_fc(gr_unittest.TestCase): taps = filter.firdes.hilbert(ntaps, filter.firdes.WIN_HAMMING) hd = filter.filter_delay_fc(taps) - expected_result = fir_filter(data, taps, (ntaps-1) // 2) + expected_result = fir_filter(data, taps, (ntaps - 1) // 2) tb.connect(src1, hd) tb.connect(hd, dst2) @@ -95,11 +100,11 @@ class test_filter_delay_fc(gr_unittest.TestCase): taps = filter.firdes.hilbert(ntaps, filter.firdes.WIN_HAMMING) hd = filter.filter_delay_fc(taps) - expected_result = fir_filter2(data, data, taps, (ntaps-1) // 2) + expected_result = fir_filter2(data, data, taps, (ntaps - 1) // 2) - tb.connect(src1, (hd,0)) - tb.connect(src1, (hd,1)) - tb.connect(hd,dst2) + tb.connect(src1, (hd, 0)) + tb.connect(src1, (hd, 1)) + tb.connect(hd, dst2) tb.run() # get output @@ -107,7 +112,6 @@ class test_filter_delay_fc(gr_unittest.TestCase): self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5) - def test_003_filter_delay_two_inputs(self): # give two different inputs tb = self.tb @@ -124,12 +128,12 @@ class test_filter_delay_fc(gr_unittest.TestCase): taps = filter.firdes.hilbert(ntaps, filter.firdes.WIN_HAMMING) hd = filter.filter_delay_fc(taps) - expected_result = fir_filter2(data1, data2, taps, (ntaps-1) // 2) + expected_result = fir_filter2(data1, data2, taps, (ntaps - 1) // 2) dst2 = blocks.vector_sink_c() - tb.connect(src1, (hd,0)) - tb.connect(src2, (hd,1)) + tb.connect(src1, (hd, 0)) + tb.connect(src2, (hd, 1)) tb.connect(hd, dst2) tb.run() diff --git a/gr-filter/python/filter/qa_filterbank.py b/gr-filter/python/filter/qa_filterbank.py index ae65ab54db..fd2daea7c8 100644 --- a/gr-filter/python/filter/qa_filterbank.py +++ b/gr-filter/python/filter/qa_filterbank.py @@ -15,19 +15,21 @@ import math from gnuradio import gr, gr_unittest, filter, blocks + def convolution(A, B): """ Returns a convolution of the A and B vectors of length len(A)-len(B). """ rs = [] - for i in range(len(B)-1, len(A)): + for i in range(len(B) - 1, len(A)): r = 0 for j, b in enumerate(B): - r += A[i-j] * b + r += A[i - j] * b rs.append(r) return rs + class test_filterbank_vcvcf(gr_unittest.TestCase): def setUp(self): @@ -56,7 +58,7 @@ class test_filterbank_vcvcf(gr_unittest.TestCase): # Generate some random sets of data data_sets = [] for i in range(0, nfilts): - data_sets.append([(myrand()-0.5) + (myrand()-0.5)*(0+1j) + data_sets.append([(myrand() - 0.5) + (myrand() - 0.5) * (0 + 1j) for k in range(0, ndatapoints)]) # Join them together to pass to vector_source block data = [] @@ -67,20 +69,20 @@ class test_filterbank_vcvcf(gr_unittest.TestCase): taps2 = [] for i in range(0, nfilts): if i in zero_filts1: - taps1.append([0]*ntaps) + taps1.append([0] * ntaps) else: - taps1.append([myrand()-0.5 for k in range(0, ntaps)]) + taps1.append([myrand() - 0.5 for k in range(0, ntaps)]) if i in zero_filts2: - taps2.append([0]*ntaps) + taps2.append([0] * ntaps) else: - taps2.append([myrand()-0.5 for k in range(0, ntaps)]) + taps2.append([myrand() - 0.5 for k in range(0, ntaps)]) # Calculate results with a python-implemented convolution. results = [] results2 = [] for ds, ts, ts2 in zip(data_sets, taps1, taps2): - results.append(convolution(ds[-len(ts):]+ds[:-1], ts)) - results2.append(convolution(ds[-len(ts):]+ds[:-1], ts2)) + results.append(convolution(ds[-len(ts):] + ds[:-1], ts)) + results2.append(convolution(ds[-len(ts):] + ds[:-1], ts2)) # Convert results from 2D arrays to 1D arrays for ease of comparison. comb_results = [] for rs in zip(*results): @@ -92,8 +94,9 @@ class test_filterbank_vcvcf(gr_unittest.TestCase): src = blocks.vector_source_c(data, True, nfilts) fb = filter.filterbank_vcvcf(taps1) v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, nfilts) - s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, nfilts*ndatapoints) - snk = blocks.probe_signal_vc(nfilts*ndatapoints) + s2v = blocks.stream_to_vector( + gr.sizeof_gr_complex, nfilts * ndatapoints) + snk = blocks.probe_signal_vc(nfilts * ndatapoints) self.tb.connect(src, fb, v2s, s2v, snk) # Run the signal-processing chain. self.tb.start() @@ -101,7 +104,7 @@ class test_filterbank_vcvcf(gr_unittest.TestCase): outdata = None waittime = 0.001 # Wait until we have some data. - while (not outdata) or outdata[0]==0: + while (not outdata) or outdata[0] == 0: time.sleep(waittime) outdata = snk.level() # Apply the second set of taps. @@ -116,5 +119,6 @@ class test_filterbank_vcvcf(gr_unittest.TestCase): self.assertComplexTuplesAlmostEqual(comb_results, outdata, 6) self.assertComplexTuplesAlmostEqual(comb_results2, outdata2, 6) + if __name__ == '__main__': gr_unittest.run(test_filterbank_vcvcf) diff --git a/gr-filter/python/filter/qa_fir_filter.py b/gr-filter/python/filter/qa_fir_filter.py index 8debbcdd43..ae3db3c263 100644 --- a/gr-filter/python/filter/qa_fir_filter.py +++ b/gr-filter/python/filter/qa_fir_filter.py @@ -11,32 +11,34 @@ from gnuradio import gr, gr_unittest, filter, blocks + def fir_filter(x, taps, decim=1): y = [] - x2 = (len(taps)-1)*[0,] + x + x2 = (len(taps) - 1) * [0, ] + x for i in range(0, len(x), decim): yi = 0 for j in range(len(taps)): - yi += taps[len(taps)-1-j] * x2[i+j] + yi += taps[len(taps) - 1 - j] * x2[i + j] y.append(yi) return y + class test_filter(gr_unittest.TestCase): def setUp(self): - self.tb = gr.top_block () + self.tb = gr.top_block() def tearDown(self): self.tb = None def test_fir_filter_fff_001(self): decim = 1 - taps = 20*[0.5, 0.5] - src_data = 40*[1, 2, 3, 4] + taps = 20 * [0.5, 0.5] + src_data = 40 * [1, 2, 3, 4] expected_data = fir_filter(src_data, taps, decim) src = blocks.vector_source_f(src_data) - op = filter.fir_filter_fff(decim, taps) + op = filter.fir_filter_fff(decim, taps) dst = blocks.vector_sink_f() self.tb.connect(src, op, dst) self.tb.run() @@ -45,12 +47,12 @@ class test_filter(gr_unittest.TestCase): def test_fir_filter_fff_002(self): decim = 4 - taps = 20*[0.5, 0.5] - src_data = 40*[1, 2, 3, 4] + taps = 20 * [0.5, 0.5] + src_data = 40 * [1, 2, 3, 4] expected_data = fir_filter(src_data, taps, decim) src = blocks.vector_source_f(src_data) - op = filter.fir_filter_fff(decim, taps) + op = filter.fir_filter_fff(decim, taps) dst = blocks.vector_sink_f() self.tb.connect(src, op, dst) self.tb.run() @@ -59,12 +61,12 @@ class test_filter(gr_unittest.TestCase): def test_fir_filter_ccf_001(self): decim = 1 - taps = 20*[0.5, 0.5] - src_data = 40*[1+1j, 2+2j, 3+3j, 4+4j] + taps = 20 * [0.5, 0.5] + src_data = 40 * [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j] expected_data = fir_filter(src_data, taps, decim) src = blocks.vector_source_c(src_data) - op = filter.fir_filter_ccf(decim, taps) + op = filter.fir_filter_ccf(decim, taps) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -73,12 +75,12 @@ class test_filter(gr_unittest.TestCase): def test_fir_filter_ccf_002(self): decim = 4 - taps = 20*[0.5, 0.5] - src_data = 40*[1+1j, 2+2j, 3+3j, 4+4j] + taps = 20 * [0.5, 0.5] + src_data = 40 * [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j] expected_data = fir_filter(src_data, taps, decim) src = blocks.vector_source_c(src_data) - op = filter.fir_filter_ccf(decim, taps) + op = filter.fir_filter_ccf(decim, taps) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -87,27 +89,26 @@ class test_filter(gr_unittest.TestCase): def test_fir_filter_ccc_001(self): decim = 1 - taps = 20*[0.5+1j, 0.5+1j] - src_data = 40*[1+1j, 2+2j, 3+3j, 4+4j] + taps = 20 * [0.5 + 1j, 0.5 + 1j] + src_data = 40 * [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j] expected_data = fir_filter(src_data, taps, decim) src = blocks.vector_source_c(src_data) - op = filter.fir_filter_ccc(decim, taps) + op = filter.fir_filter_ccc(decim, taps) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5) - def test_fir_filter_ccc_002(self): decim = 1 taps = filter.firdes.low_pass(1, 1, 0.1, 0.01) - src_data = 10*[1+1j, 2+2j, 3+3j, 4+4j] + src_data = 10 * [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j] expected_data = fir_filter(src_data, taps, decim) src = blocks.vector_source_c(src_data) - op = filter.fir_filter_ccc(decim, taps) + op = filter.fir_filter_ccc(decim, taps) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -116,42 +117,40 @@ class test_filter(gr_unittest.TestCase): def test_fir_filter_ccc_003(self): decim = 4 - taps = 20*[0.5+1j, 0.5+1j] - src_data = 40*[1+1j, 2+2j, 3+3j, 4+4j] + taps = 20 * [0.5 + 1j, 0.5 + 1j] + src_data = 40 * [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j] expected_data = fir_filter(src_data, taps, decim) src = blocks.vector_source_c(src_data) - op = filter.fir_filter_ccc(decim, taps) + op = filter.fir_filter_ccc(decim, taps) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5) - def test_fir_filter_scc_001(self): decim = 1 - taps = 20*[0.5+1j, 0.5+1j] - src_data = 40*[1, 2, 3, 4] + taps = 20 * [0.5 + 1j, 0.5 + 1j] + src_data = 40 * [1, 2, 3, 4] expected_data = fir_filter(src_data, taps, decim) src = blocks.vector_source_s(src_data) - op = filter.fir_filter_scc(decim, taps) + op = filter.fir_filter_scc(decim, taps) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5) - def test_fir_filter_scc_002(self): decim = 4 - taps = 20*[0.5+1j, 0.5+1j] - src_data = 40*[1, 2, 3, 4] + taps = 20 * [0.5 + 1j, 0.5 + 1j] + src_data = 40 * [1, 2, 3, 4] expected_data = fir_filter(src_data, taps, decim) src = blocks.vector_source_s(src_data) - op = filter.fir_filter_scc(decim, taps) + op = filter.fir_filter_scc(decim, taps) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -160,35 +159,34 @@ class test_filter(gr_unittest.TestCase): def test_fir_filter_fsf_001(self): decim = 1 - taps = 20*[0.5, 0.5] - src_data = 40*[1, 2, 3, 4] + taps = 20 * [0.5, 0.5] + src_data = 40 * [1, 2, 3, 4] expected_data = fir_filter(src_data, taps, decim) expected_data = [int(e) for e in expected_data] src = blocks.vector_source_f(src_data) - op = filter.fir_filter_fsf(decim, taps) + op = filter.fir_filter_fsf(decim, taps) dst = blocks.vector_sink_s() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5) - def test_fir_filter_fsf_002(self): decim = 4 - taps = 20*[0.5, 0.5] - src_data = 40*[1, 2, 3, 4] + taps = 20 * [0.5, 0.5] + src_data = 40 * [1, 2, 3, 4] expected_data = fir_filter(src_data, taps, decim) expected_data = [int(e) for e in expected_data] src = blocks.vector_source_f(src_data) - op = filter.fir_filter_fsf(decim, taps) + op = filter.fir_filter_fsf(decim, taps) dst = blocks.vector_sink_s() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_data, result_data, 5) + if __name__ == '__main__': gr_unittest.run(test_filter) - diff --git a/gr-filter/python/filter/qa_firdes.py b/gr-filter/python/filter/qa_firdes.py index 78a6ff5b6c..16a4054c2b 100644 --- a/gr-filter/python/filter/qa_firdes.py +++ b/gr-filter/python/filter/qa_firdes.py @@ -12,6 +12,7 @@ from gnuradio import gr, gr_unittest, filter import sys + class test_firdes(gr_unittest.TestCase): def setUp(self): @@ -45,79 +46,79 @@ class test_firdes(gr_unittest.TestCase): def test_high_pass(self): known_taps = (-0.0027197482995688915, 4.815287179370254e-18, - 0.01580853760242462, -0.05940871313214302, - 0.1270686239004135, -0.1914101094007492, - 0.21804752945899963, -0.1914101094007492, - 0.1270686239004135, -0.05940871313214302, - 0.01580853760242462, 4.815287179370254e-18, + 0.01580853760242462, -0.05940871313214302, + 0.1270686239004135, -0.1914101094007492, + 0.21804752945899963, -0.1914101094007492, + 0.1270686239004135, -0.05940871313214302, + 0.01580853760242462, 4.815287179370254e-18, -0.0027197482995688915) new_taps = filter.firdes.high_pass(1, 1, 0.4, 0.2) self.assertFloatTuplesAlmostEqual(known_taps, new_taps, 5) def test_high_pass_2(self): known_taps = (-0.0027197482995688915, 4.815287179370254e-18, - 0.01580853760242462, -0.05940871313214302, - 0.1270686239004135, -0.1914101094007492, - 0.21804752945899963, -0.1914101094007492, - 0.1270686239004135, -0.05940871313214302, - 0.01580853760242462, 4.815287179370254e-18, - -0.0027197482995688915) + 0.01580853760242462, -0.05940871313214302, + 0.1270686239004135, -0.1914101094007492, + 0.21804752945899963, -0.1914101094007492, + 0.1270686239004135, -0.05940871313214302, + 0.01580853760242462, 4.815287179370254e-18, + -0.0027197482995688915) new_taps = filter.firdes.high_pass_2(1, 1, 0.4, 0.2, 60) self.assertFloatTuplesAlmostEqual(known_taps, new_taps, 5) def test_band_pass(self): known_taps = (-0.001676854444667697, -2.4018533253972557e-18, - 0.009746716357767582, 0.09589414298534393, + 0.009746716357767582, 0.09589414298534393, -0.20510689914226532, -0.11801345646381378, - 0.4350462853908539, -0.11801345646381378, + 0.4350462853908539, -0.11801345646381378, -0.20510689914226532, 0.09589414298534393, - 0.009746716357767582, -2.4018533253972557e-18, + 0.009746716357767582, -2.4018533253972557e-18, -0.001676854444667697) new_taps = filter.firdes.band_pass(1, 1, 0.2, 0.4, 0.2) self.assertFloatTuplesAlmostEqual(known_taps, new_taps, 5) def test_band_pass_2(self): known_taps = (-0.001676854444667697, -2.4018533253972557e-18, - 0.009746716357767582, 0.09589414298534393, - -0.20510689914226532, -0.11801345646381378, - 0.4350462853908539, -0.11801345646381378, - -0.20510689914226532, 0.09589414298534393, - 0.009746716357767582, -2.4018533253972557e-18, - -0.001676854444667697) + 0.009746716357767582, 0.09589414298534393, + -0.20510689914226532, -0.11801345646381378, + 0.4350462853908539, -0.11801345646381378, + -0.20510689914226532, 0.09589414298534393, + 0.009746716357767582, -2.4018533253972557e-18, + -0.001676854444667697) new_taps = filter.firdes.band_pass_2(1, 1, 0.2, 0.4, 0.2, 60) self.assertFloatTuplesAlmostEqual(known_taps, new_taps, 5) def test_complex_band_pass(self): - known_taps = ((-0.0008404505206272006-0.0025866336654871702j), - (-1.2038217948425635e-18+1.1767648157397848e-24j), - (0.0048850891180336475-0.015034818090498447j), - (0.048062704503536224+0.03491950035095215j), - (-0.10280057787895203+0.07468919456005096j), - (-0.05914920195937157-0.18204176425933838j), - (0.21804752945899963-2.5993290364567656e-07j), - (-0.059148769825696945+0.18204189836978912j), - (-0.10280075669288635-0.07468894869089127j), - (0.04806262254714966-0.0349196158349514j), - (0.004885117989033461+0.015034808777272701j), - (-1.2038217948425635e-18+1.1193430388030685e-24j), - (-0.000840445572976023+0.002586635295301676j)) + known_taps = ((-0.0008404505206272006 - 0.0025866336654871702j), + (-1.2038217948425635e-18 + 1.1767648157397848e-24j), + (0.0048850891180336475 - 0.015034818090498447j), + (0.048062704503536224 + 0.03491950035095215j), + (-0.10280057787895203 + 0.07468919456005096j), + (-0.05914920195937157 - 0.18204176425933838j), + (0.21804752945899963 - 2.5993290364567656e-07j), + (-0.059148769825696945 + 0.18204189836978912j), + (-0.10280075669288635 - 0.07468894869089127j), + (0.04806262254714966 - 0.0349196158349514j), + (0.004885117989033461 + 0.015034808777272701j), + (-1.2038217948425635e-18 + 1.1193430388030685e-24j), + (-0.000840445572976023 + 0.002586635295301676j)) new_taps = filter.firdes.complex_band_pass(1, 1, 0.2, 0.4, 0.2) self.assertComplexTuplesAlmostEqual(known_taps, new_taps, 5) def test_complex_band_pass_2(self): - known_taps = ((-0.0008404505206272006-0.0025866336654871702j), - (-1.2038217948425635e-18+1.1767648157397848e-24j), - (0.0048850891180336475-0.015034818090498447j), - (0.048062704503536224+0.03491950035095215j), - (-0.10280057787895203+0.07468919456005096j), - (-0.05914920195937157-0.18204176425933838j), - (0.21804752945899963-2.5993290364567656e-07j), - (-0.059148769825696945+0.18204189836978912j), - (-0.10280075669288635-0.07468894869089127j), - (0.04806262254714966-0.0349196158349514j), - (0.004885117989033461+0.015034808777272701j), - (-1.2038217948425635e-18+1.1193430388030685e-24j), - (-0.000840445572976023+0.002586635295301676j)) + known_taps = ((-0.0008404505206272006 - 0.0025866336654871702j), + (-1.2038217948425635e-18 + 1.1767648157397848e-24j), + (0.0048850891180336475 - 0.015034818090498447j), + (0.048062704503536224 + 0.03491950035095215j), + (-0.10280057787895203 + 0.07468919456005096j), + (-0.05914920195937157 - 0.18204176425933838j), + (0.21804752945899963 - 2.5993290364567656e-07j), + (-0.059148769825696945 + 0.18204189836978912j), + (-0.10280075669288635 - 0.07468894869089127j), + (0.04806262254714966 - 0.0349196158349514j), + (0.004885117989033461 + 0.015034808777272701j), + (-1.2038217948425635e-18 + 1.1193430388030685e-24j), + (-0.000840445572976023 + 0.002586635295301676j)) new_taps = filter.firdes.complex_band_pass_2(1, 1, 0.2, 0.4, 0.2, 60) self.assertComplexTuplesAlmostEqual(known_taps, new_taps, 5) @@ -145,21 +146,21 @@ class test_firdes(gr_unittest.TestCase): def test_hilbert(self): known_taps = (-0.010056184604763985, 0.0, - -0.08335155993700027, 0.0, - -0.5732954144477844, 0.0, - 0.5732954144477844, 0.0, - 0.08335155993700027, 0.0, - 0.010056184604763985) + -0.08335155993700027, 0.0, + -0.5732954144477844, 0.0, + 0.5732954144477844, 0.0, + 0.08335155993700027, 0.0, + 0.010056184604763985) new_taps = filter.firdes.hilbert(11, filter.firdes.WIN_HAMMING) self.assertFloatTuplesAlmostEqual(known_taps, new_taps, 5) def test_root_raised_cosine(self): known_taps = (-0.04609205573797226, -0.02069387212395668, - 0.050548505038022995, 0.14850808680057526, - 0.23387153446674347, 0.2677156329154968, - 0.23387153446674347, 0.14850808680057526, - 0.050548505038022995, -0.02069387212395668, - -0.04609205573797226) + 0.050548505038022995, 0.14850808680057526, + 0.23387153446674347, 0.2677156329154968, + 0.23387153446674347, 0.14850808680057526, + 0.050548505038022995, -0.02069387212395668, + -0.04609205573797226) new_taps = filter.firdes.root_raised_cosine(1, 4, 1, 0.35, 11) self.assertFloatTuplesAlmostEqual(known_taps, new_taps, 5) @@ -181,5 +182,6 @@ class test_firdes(gr_unittest.TestCase): new_taps = filter.firdes.gaussian(1, 4, 0.35, 13) self.assertFloatTuplesAlmostEqual(known_taps, new_taps, 5) + if __name__ == '__main__': gr_unittest.run(test_firdes) diff --git a/gr-filter/python/filter/qa_fractional_interpolator.py b/gr-filter/python/filter/qa_fractional_interpolator.py index de1457a0e4..f8457a0e5d 100644 --- a/gr-filter/python/filter/qa_fractional_interpolator.py +++ b/gr-filter/python/filter/qa_fractional_interpolator.py @@ -13,17 +13,20 @@ from gnuradio import gr, gr_unittest, filter, blocks import math + def sig_source_f(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.sin(2.*math.pi*freq*x) for x in t] + y = [math.sin(2. * math.pi * freq * x) for x in t] return y + def sig_source_c(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x) for x in t] + y = [math.cos(2. * math.pi * freq * x) + + 1j * math.sin(2. * math.pi * freq * x) for x in t] return y + class test_mmse_resampler(gr_unittest.TestCase): def setUp(self): @@ -51,12 +54,12 @@ class test_mmse_resampler(gr_unittest.TestCase): t = [float(x) / (fs / rrate) for x in range(L)] phase = 0.1884 - expected_data = [math.sin(2.*math.pi*freq*x+phase) for x in t] + expected_data = [math.sin(2. * math.pi * freq * x + phase) for x in t] dst_data = snk.data() - self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3) - + self.assertFloatTuplesAlmostEqual( + expected_data[-Ntest:], dst_data[-Ntest:], 3) def test_002_cc(self): N = 10000 # number of samples to use @@ -77,12 +80,25 @@ class test_mmse_resampler(gr_unittest.TestCase): t = [float(x) / (fs / rrate) for x in range(L)] phase = 0.1884 - expected_data = [math.cos(2.*math.pi*freq*x+phase) + \ - 1j*math.sin(2.*math.pi*freq*x+phase) for x in t] + expected_data = [ + math.cos( + 2. * + math.pi * + freq * + x + + phase) + + 1j * + math.sin( + 2. * + math.pi * + freq * + x + + phase) for x in t] dst_data = snk.data() - self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3) + self.assertComplexTuplesAlmostEqual( + expected_data[-Ntest:], dst_data[-Ntest:], 3) if __name__ == '__main__': diff --git a/gr-filter/python/filter/qa_fractional_resampler.py b/gr-filter/python/filter/qa_fractional_resampler.py index 907563d303..68ab028048 100644 --- a/gr-filter/python/filter/qa_fractional_resampler.py +++ b/gr-filter/python/filter/qa_fractional_resampler.py @@ -13,21 +13,25 @@ import math from gnuradio import gr, gr_unittest, filter, blocks + def sig_source_f(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.sin(2.*math.pi*freq*x) for x in t] + y = [math.sin(2. * math.pi * freq * x) for x in t] return y + def sig_source_c(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x) for x in t] + y = [math.cos(2. * math.pi * freq * x) + + 1j * math.sin(2. * math.pi * freq * x) for x in t] return y + def const_source_f(amp, N): - y = N*[amp,] + y = N * [amp, ] return y + class test_mmse_resampler(gr_unittest.TestCase): def setUp(self): @@ -55,11 +59,12 @@ class test_mmse_resampler(gr_unittest.TestCase): t = [float(x) / (fs / rrate) for x in range(L)] phase = 0.1884 - expected_data = [math.sin(2.*math.pi*freq*x+phase) for x in t] + expected_data = [math.sin(2. * math.pi * freq * x + phase) for x in t] dst_data = snk.data() - self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3) + self.assertFloatTuplesAlmostEqual( + expected_data[-Ntest:], dst_data[-Ntest:], 3) def test_002_cc(self): N = 10000 # number of samples to use @@ -80,12 +85,25 @@ class test_mmse_resampler(gr_unittest.TestCase): t = [float(x) / (fs / rrate) for x in range(L)] phase = 0.1884 - expected_data = [math.cos(2.*math.pi*freq*x+phase) + \ - 1j*math.sin(2.*math.pi*freq*x+phase) for x in t] + expected_data = [ + math.cos( + 2. * + math.pi * + freq * + x + + phase) + + 1j * + math.sin( + 2. * + math.pi * + freq * + x + + phase) for x in t] dst_data = snk.data() - self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3) + self.assertComplexTuplesAlmostEqual( + expected_data[-Ntest:], dst_data[-Ntest:], 3) def test_003_ff(self): N = 10000 # number of samples to use @@ -101,7 +119,7 @@ class test_mmse_resampler(gr_unittest.TestCase): snk = blocks.vector_sink_f() self.tb.connect(signal, op, snk) - self.tb.connect(control, (op,1)) + self.tb.connect(control, (op, 1)) self.tb.run() Ntest = 5000 @@ -109,11 +127,12 @@ class test_mmse_resampler(gr_unittest.TestCase): t = [float(x) / (fs / rrate) for x in range(L)] phase = 0.1884 - expected_data = [math.sin(2.*math.pi*freq*x+phase) for x in t] + expected_data = [math.sin(2. * math.pi * freq * x + phase) for x in t] dst_data = snk.data() - self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3) + self.assertFloatTuplesAlmostEqual( + expected_data[-Ntest:], dst_data[-Ntest:], 3) def test_004_cc(self): N = 10000 # number of samples to use @@ -129,7 +148,7 @@ class test_mmse_resampler(gr_unittest.TestCase): snk = blocks.vector_sink_c() self.tb.connect(signal, op, snk) - self.tb.connect(control, (op,1)) + self.tb.connect(control, (op, 1)) self.tb.run() Ntest = 5000 @@ -137,12 +156,26 @@ class test_mmse_resampler(gr_unittest.TestCase): t = [float(x) / (fs / rrate) for x in range(L)] phase = 0.1884 - expected_data = [math.cos(2.*math.pi*freq*x+phase) + \ - 1j*math.sin(2.*math.pi*freq*x+phase) for x in t] + expected_data = [ + math.cos( + 2. * + math.pi * + freq * + x + + phase) + + 1j * + math.sin( + 2. * + math.pi * + freq * + x + + phase) for x in t] dst_data = snk.data() - self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3) + self.assertComplexTuplesAlmostEqual( + expected_data[-Ntest:], dst_data[-Ntest:], 3) + if __name__ == '__main__': gr_unittest.run(test_mmse_resampler) diff --git a/gr-filter/python/filter/qa_freq_xlating_fft_filter.py b/gr-filter/python/filter/qa_freq_xlating_fft_filter.py index 0ae30345d2..5f4ee5e2e6 100644 --- a/gr-filter/python/filter/qa_freq_xlating_fft_filter.py +++ b/gr-filter/python/filter/qa_freq_xlating_fft_filter.py @@ -10,37 +10,43 @@ from gnuradio import gr, gr_unittest, filter, blocks -import cmath, math +import cmath +import math + def fir_filter(x, taps, decim=1): y = [] - x2 = (len(taps)-1)*[0,] + x + x2 = (len(taps) - 1) * [0, ] + x for i in range(0, len(x), decim): yi = 0 for j in range(len(taps)): - yi += taps[len(taps)-1-j] * x2[i+j] + yi += taps[len(taps) - 1 - j] * x2[i + j] y.append(yi) return y + def sig_source_s(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [int(100*math.sin(2.*math.pi*freq*x)) for x in t] + y = [int(100 * math.sin(2. * math.pi * freq * x)) for x in t] return y + def sig_source_c(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x) for x in t] + y = [math.cos(2. * math.pi * freq * x) + + 1j * math.sin(2. * math.pi * freq * x) for x in t] return y + def mix(lo, data): - y = [lo_i*data_i for lo_i, data_i in zip(lo, data)] + y = [lo_i * data_i for lo_i, data_i in zip(lo, data)] return y + class test_freq_xlating_filter(gr_unittest.TestCase): def setUp(self): - self.tb = gr.top_block () + self.tb = gr.top_block() def tearDown(self): self.tb = None @@ -51,21 +57,23 @@ class test_freq_xlating_filter(gr_unittest.TestCase): self.bw = bw = 0.1 self.taps = filter.firdes.low_pass(1, fs, bw, bw / 4) times = list(range(1024)) - self.src_data = [cmath.exp(-2j*cmath.pi*fc/fs*(t / 100.0)) for t in times] + self.src_data = [ + cmath.exp(-2j * cmath.pi * fc / fs * (t / 100.0)) for t in times] def generate_ccc_source(self): self.fs = fs = 1 self.fc = fc = 0.3 self.bw = bw = 0.1 - self.taps = filter.firdes.complex_band_pass(1, fs, -bw / 2, bw / 2, bw / 4) + self.taps = filter.firdes.complex_band_pass( + 1, fs, -bw / 2, bw / 2, bw / 4) times = list(range(1024)) - self.src_data = [cmath.exp(-2j*cmath.pi*fc/fs*(t / 100.0)) for t in times] + self.src_data = [ + cmath.exp(-2j * cmath.pi * fc / fs * (t / 100.0)) for t in times] def assert_fft_ok(self, expected_result, result_data): expected_result = expected_result[:len(result_data)] - self.assertComplexTuplesAlmostEqual2 (expected_result, result_data, - abs_eps=1e-9, rel_eps=1.5e-3) - + self.assertComplexTuplesAlmostEqual2(expected_result, result_data, + abs_eps=1e-9, rel_eps=1.5e-3) def test_fft_filter_ccf_001(self): self.generate_ccf_source() @@ -76,7 +84,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_c(self.src_data) - op = filter.freq_xlating_fft_filter_ccc(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fft_filter_ccc( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -92,7 +101,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_c(self.src_data) - op = filter.freq_xlating_fft_filter_ccc(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fft_filter_ccc( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -108,7 +118,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_c(self.src_data) - op = filter.freq_xlating_fft_filter_ccc(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fft_filter_ccc( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -124,12 +135,14 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_c(self.src_data) - op = filter.freq_xlating_fft_filter_ccc(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fft_filter_ccc( + decim, 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.assert_fft_ok(expected_data, result_data) + if __name__ == '__main__': gr_unittest.run(test_freq_xlating_filter) diff --git a/gr-filter/python/filter/qa_freq_xlating_fir_filter.py b/gr-filter/python/filter/qa_freq_xlating_fir_filter.py index ba7d9215f3..4b73ad3646 100644 --- a/gr-filter/python/filter/qa_freq_xlating_fir_filter.py +++ b/gr-filter/python/filter/qa_freq_xlating_fir_filter.py @@ -11,37 +11,43 @@ from gnuradio import gr, gr_unittest, filter, blocks -import cmath, math +import cmath +import math + def fir_filter(x, taps, decim=1): y = [] - x2 = (len(taps)-1)*[0,] + x + x2 = (len(taps) - 1) * [0, ] + x for i in range(0, len(x), decim): yi = 0 for j in range(len(taps)): - yi += taps[len(taps)-1-j] * x2[i+j] + yi += taps[len(taps) - 1 - j] * x2[i + j] y.append(yi) return y + def sig_source_s(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [int(100*math.sin(2.*math.pi*freq*x)) for x in t] + y = [int(100 * math.sin(2. * math.pi * freq * x)) for x in t] return y + def sig_source_c(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x) for x in t] + y = [math.cos(2. * math.pi * freq * x) + + 1j * math.sin(2. * math.pi * freq * x) for x in t] return y + def mix(lo, data): - y = [lo_i*data_i for lo_i, data_i in zip(lo, data)] + y = [lo_i * data_i for lo_i, data_i in zip(lo, data)] return y + class test_freq_xlating_filter(gr_unittest.TestCase): def setUp(self): - self.tb = gr.top_block () + self.tb = gr.top_block() def tearDown(self): self.tb = None @@ -52,15 +58,18 @@ class test_freq_xlating_filter(gr_unittest.TestCase): self.bw = bw = 0.1 self.taps = filter.firdes.low_pass(1, fs, bw, bw / 4) times = list(range(100)) - self.src_data = [cmath.exp(-2j*cmath.pi*fc/fs*(t / 100.0)) for t in times] + self.src_data = [ + cmath.exp(-2j * cmath.pi * fc / fs * (t / 100.0)) for t in times] def generate_ccc_source(self): self.fs = fs = 1 self.fc = fc = 0.3 self.bw = bw = 0.1 - self.taps = filter.firdes.complex_band_pass(1, fs, -bw / 2, bw / 2, bw / 4) + self.taps = filter.firdes.complex_band_pass( + 1, fs, -bw / 2, bw / 2, bw / 4) times = list(range(100)) - self.src_data = [cmath.exp(-2j*cmath.pi*fc/fs*(t / 100.0)) for t in times] + self.src_data = [ + cmath.exp(-2j * cmath.pi * fc / fs * (t / 100.0)) for t in times] def generate_fcf_source(self): self.fs = fs = 1 @@ -68,15 +77,18 @@ class test_freq_xlating_filter(gr_unittest.TestCase): self.bw = bw = 0.1 self.taps = filter.firdes.low_pass(1, fs, bw, bw / 4) times = list(range(100)) - self.src_data = [math.sin(2*cmath.pi*fc/fs*(t / 100.0)) for t in times] + self.src_data = [ + math.sin(2 * cmath.pi * fc / fs * (t / 100.0)) for t in times] def generate_fcc_source(self): self.fs = fs = 1 self.fc = fc = 0.3 self.bw = bw = 0.1 - self.taps = filter.firdes.complex_band_pass(1, fs, -bw / 2, bw / 2, bw / 4) + self.taps = filter.firdes.complex_band_pass( + 1, fs, -bw / 2, bw / 2, bw / 4) times = list(range(100)) - self.src_data = [math.sin(2*cmath.pi*fc/fs*(t / 100.0)) for t in times] + self.src_data = [ + math.sin(2 * cmath.pi * fc / fs * (t / 100.0)) for t in times] def generate_scf_source(self): self.fs = fs = 1 @@ -84,16 +96,18 @@ class test_freq_xlating_filter(gr_unittest.TestCase): self.bw = bw = 0.12 self.taps = filter.firdes.low_pass(1, fs, bw, bw / 4) times = list(range(100)) - self.src_data = [int(100*math.sin(2*cmath.pi*fc/fs*(t / 100.0))) for t in times] + self.src_data = [ + int(100 * math.sin(2 * cmath.pi * fc / fs * (t / 100.0))) for t in times] def generate_scc_source(self): self.fs = fs = 1 self.fc = fc = 0.3 self.bw = bw = 0.12 - self.taps = filter.firdes.complex_band_pass(1, fs, -bw / 2, bw / 2, bw / 4) + self.taps = filter.firdes.complex_band_pass( + 1, fs, -bw / 2, bw / 2, bw / 4) times = list(range(100)) - self.src_data = [int(100*math.sin(2*cmath.pi*fc/fs*(t / 100.0))) for t in times] - + self.src_data = [ + int(100 * math.sin(2 * cmath.pi * fc / fs * (t / 100.0))) for t in times] def test_fir_filter_ccf_001(self): self.generate_ccf_source() @@ -104,7 +118,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_c(self.src_data) - op = filter.freq_xlating_fir_filter_ccf(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fir_filter_ccf( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -121,7 +136,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_c(self.src_data) - op = filter.freq_xlating_fir_filter_ccf(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fir_filter_ccf( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -137,7 +153,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_c(self.src_data) - op = filter.freq_xlating_fir_filter_ccc(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fir_filter_ccc( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -153,7 +170,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_c(self.src_data) - op = filter.freq_xlating_fir_filter_ccc(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fir_filter_ccc( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -169,7 +187,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_f(self.src_data) - op = filter.freq_xlating_fir_filter_fcf(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fir_filter_fcf( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -185,7 +204,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_f(self.src_data) - op = filter.freq_xlating_fir_filter_fcf(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fir_filter_fcf( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -201,7 +221,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_f(self.src_data) - op = filter.freq_xlating_fir_filter_fcc(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fir_filter_fcc( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -217,7 +238,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_f(self.src_data) - op = filter.freq_xlating_fir_filter_fcc(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fir_filter_fcc( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -233,7 +255,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_s(self.src_data) - op = filter.freq_xlating_fir_filter_scf(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fir_filter_scf( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -249,7 +272,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_s(self.src_data) - op = filter.freq_xlating_fir_filter_scf(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fir_filter_scf( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -265,7 +289,8 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_s(self.src_data) - op = filter.freq_xlating_fir_filter_scc(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fir_filter_scc( + decim, self.taps, self.fc, self.fs) dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() @@ -281,13 +306,14 @@ class test_freq_xlating_filter(gr_unittest.TestCase): expected_data = fir_filter(despun, self.taps, decim) src = blocks.vector_source_s(self.src_data) - op = filter.freq_xlating_fir_filter_scc(decim, self.taps, self.fc, self.fs) + op = filter.freq_xlating_fir_filter_scc( + decim, 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, 4) + if __name__ == '__main__': gr_unittest.run(test_freq_xlating_filter) - diff --git a/gr-filter/python/filter/qa_hilbert.py b/gr-filter/python/filter/qa_hilbert.py index 51fa4744d7..7363750d3f 100644 --- a/gr-filter/python/filter/qa_hilbert.py +++ b/gr-filter/python/filter/qa_hilbert.py @@ -12,26 +12,29 @@ from gnuradio import gr, gr_unittest, filter, blocks import math + def sig_source_f(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.sin(2.*math.pi*freq*x) for x in t] + y = [math.sin(2. * math.pi * freq * x) for x in t] return y + def fir_filter(x, taps): y = [] - x2 = (len(taps)-1)*[0,] + x - delay = (len(taps)-1) // 2 + x2 = (len(taps) - 1) * [0, ] + x + delay = (len(taps) - 1) // 2 for i in range(len(x)): yi = 0 for j in range(len(taps)): - yi += taps[len(taps)-1-j] * x2[i+j] - y.append(complex(x2[i+delay], yi)) + yi += taps[len(taps) - 1 - j] * x2[i + j] + y.append(complex(x2[i + delay], yi)) return y + class test_hilbert(gr_unittest.TestCase): def setUp(self): - self.tb = gr.top_block () + self.tb = gr.top_block() def tearDown(self): self.tb = None @@ -57,5 +60,6 @@ class test_hilbert(gr_unittest.TestCase): self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 5) + if __name__ == '__main__': gr_unittest.run(test_hilbert) diff --git a/gr-filter/python/filter/qa_iir_filter.py b/gr-filter/python/filter/qa_iir_filter.py index 0ddeb807ab..f017e7a169 100644 --- a/gr-filter/python/filter/qa_iir_filter.py +++ b/gr-filter/python/filter/qa_iir_filter.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, filter, blocks + class test_iir_filter(gr_unittest.TestCase): def setUp(self): @@ -50,7 +51,7 @@ class test_iir_filter(gr_unittest.TestCase): def test_iir_direct_003(self): src_data = (1, 2, 3, 4, 5, 6, 7, 8) fftaps = (2, 11) - fbtaps = (0, 0) + fbtaps = (0, 0) expected_result = (2, 15, 28, 41, 54, 67, 80, 93) src = blocks.vector_source_f(src_data) op = filter.iir_filter_ffd(fftaps, fbtaps) @@ -64,7 +65,7 @@ class test_iir_filter(gr_unittest.TestCase): def test_iir_direct_004(self): src_data = (1, 2, 3, 4, 5, 6, 7, 8) fftaps = (2, 11) - fbtaps = (0, -1) + fbtaps = (0, -1) expected_result = (2, 13, 15, 26, 28, 39, 41, 52) src = blocks.vector_source_f(src_data) op = filter.iir_filter_ffd(fftaps, fbtaps) @@ -77,8 +78,8 @@ class test_iir_filter(gr_unittest.TestCase): def test_iir_direct_005(self): src_data = (1, 2, 3, 4, 5, 6, 7, 8) - fftaps = (2, 11, 0) - fbtaps = (0, -1, 3) + fftaps = (2, 11, 0) + fbtaps = (0, -1, 3) expected_result = (2, 13, 21, 59, 58, 186, 68, 583) src = blocks.vector_source_f(src_data) op = filter.iir_filter_ffd(fftaps, fbtaps) @@ -96,8 +97,8 @@ class test_iir_filter(gr_unittest.TestCase): fbtaps = (0, -1) src = blocks.vector_source_f(src_data) op = filter.iir_filter_ffd(fftaps, fbtaps) - fftaps = (2, 11, 0) - fbtaps = (0, -1, 3) + fftaps = (2, 11, 0) + fbtaps = (0, -1, 3) op.set_taps(fftaps, fbtaps) dst = blocks.vector_sink_f() self.tb.connect(src, op) @@ -108,12 +109,12 @@ class test_iir_filter(gr_unittest.TestCase): def test_iir_direct_007(self): src_data = (1, 2, 3, 4, 5, 6, 7, 8) - expected_result = (2,2,5,5,8,8,11,11) + expected_result = (2, 2, 5, 5, 8, 8, 11, 11) fftaps = (2, 1) fbtaps = (0, -1) src = blocks.vector_source_f(src_data) op = filter.iir_filter_ffd(fftaps, fbtaps) - fftaps = (2,0,1) + fftaps = (2, 0, 1) fbtaps = (0, -1) op.set_taps(fftaps, fbtaps) dst = blocks.vector_sink_f() @@ -125,24 +126,40 @@ class test_iir_filter(gr_unittest.TestCase): def test_iir_direct_008(self): src_data = (1, 2, 3, 4, 5, 6, 7, 8) - expected_result = (2,4,4,10,18,14,26,56) + expected_result = (2, 4, 4, 10, 18, 14, 26, 56) fftaps = (2,) fbtaps = (0, 1) src = blocks.vector_source_f(src_data) op = filter.iir_filter_ffd(fftaps, fbtaps) fftaps_data = (1) - fbtaps = (0,0, -1,3) + fbtaps = (0, 0, -1, 3) op.set_taps(fftaps, fbtaps) dst = blocks.vector_sink_f() self.tb.connect(src, op) self.tb.connect(op, dst) self.tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data) + self.assertFloatTuplesAlmostEqual(expected_result, result_data) def test_iir_ccf_001(self): - src_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j, 6+6j, 7+7j, 8+8j) - expected_result = (2+2j, (6+6j), (12+12j), (20+20j), (30+30j), (42+42j), (56+56j), (72+72j)) + src_data = ( + 1 + 1j, + 2 + 2j, + 3 + 3j, + 4 + 4j, + 5 + 5j, + 6 + 6j, + 7 + 7j, + 8 + 8j) + expected_result = ( + 2 + 2j, + (6 + 6j), + (12 + 12j), + (20 + 20j), + (30 + 30j), + (42 + 42j), + (56 + 56j), + (72 + 72j)) fftaps = (2,) fbtaps = (0, 1) src = blocks.vector_source_c(src_data) @@ -154,11 +171,27 @@ class test_iir_filter(gr_unittest.TestCase): self.tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data) + self.assertFloatTuplesAlmostEqual(expected_result, result_data) def test_iir_ccf_002(self): - src_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j, 6+6j, 7+7j, 8+8j) - expected_result = (2+2j, (6+6j), (12+12j), (20+20j), (30+30j), (42+42j), (56+56j), (72+72j)) + src_data = ( + 1 + 1j, + 2 + 2j, + 3 + 3j, + 4 + 4j, + 5 + 5j, + 6 + 6j, + 7 + 7j, + 8 + 8j) + expected_result = ( + 2 + 2j, + (6 + 6j), + (12 + 12j), + (20 + 20j), + (30 + 30j), + (42 + 42j), + (56 + 56j), + (72 + 72j)) src = blocks.vector_source_c(src_data) op = filter.iir_filter_ccf([1], [1]) @@ -173,12 +206,27 @@ class test_iir_filter(gr_unittest.TestCase): self.tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - + self.assertFloatTuplesAlmostEqual(expected_result, result_data) def test_iir_ccd_001(self): - src_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j, 6+6j, 7+7j, 8+8j) - expected_result = (2+2j, (6+6j), (12+12j), (20+20j), (30+30j), (42+42j), (56+56j), (72+72j)) + src_data = ( + 1 + 1j, + 2 + 2j, + 3 + 3j, + 4 + 4j, + 5 + 5j, + 6 + 6j, + 7 + 7j, + 8 + 8j) + expected_result = ( + 2 + 2j, + (6 + 6j), + (12 + 12j), + (20 + 20j), + (30 + 30j), + (42 + 42j), + (56 + 56j), + (72 + 72j)) fftaps = (2,) fbtaps = (0, 1) src = blocks.vector_source_c(src_data) @@ -190,11 +238,27 @@ class test_iir_filter(gr_unittest.TestCase): self.tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data) + self.assertFloatTuplesAlmostEqual(expected_result, result_data) def test_iir_ccd_002(self): - src_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j, 6+6j, 7+7j, 8+8j) - expected_result = (2+2j, (6+6j), (12+12j), (20+20j), (30+30j), (42+42j), (56+56j), (72+72j)) + src_data = ( + 1 + 1j, + 2 + 2j, + 3 + 3j, + 4 + 4j, + 5 + 5j, + 6 + 6j, + 7 + 7j, + 8 + 8j) + expected_result = ( + 2 + 2j, + (6 + 6j), + (12 + 12j), + (20 + 20j), + (30 + 30j), + (42 + 42j), + (56 + 56j), + (72 + 72j)) src = blocks.vector_source_c(src_data) op = filter.iir_filter_ccd([1], [1]) @@ -209,13 +273,20 @@ class test_iir_filter(gr_unittest.TestCase): self.tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - + self.assertFloatTuplesAlmostEqual(expected_result, result_data) def test_iir_ccc_001(self): - src_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j, 6+6j, 7+7j, 8+8j) + src_data = ( + 1 + 1j, + 2 + 2j, + 3 + 3j, + 4 + 4j, + 5 + 5j, + 6 + 6j, + 7 + 7j, + 8 + 8j) expected_result = (4j, 12j, 24j, 40j, 60j, 84j, 112j, 144j) - fftaps = (2+2j,) + fftaps = (2 + 2j,) fbtaps = (0, 1) src = blocks.vector_source_c(src_data) op = filter.iir_filter_ccc(fftaps, fbtaps) @@ -226,17 +297,25 @@ class test_iir_filter(gr_unittest.TestCase): self.tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data) + self.assertFloatTuplesAlmostEqual(expected_result, result_data) def test_iir_ccc_002(self): - src_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j, 6+6j, 7+7j, 8+8j) + src_data = ( + 1 + 1j, + 2 + 2j, + 3 + 3j, + 4 + 4j, + 5 + 5j, + 6 + 6j, + 7 + 7j, + 8 + 8j) expected_result = (4j, 12j, 24j, 40j, 60j, 84j, 112j, 144j) src = blocks.vector_source_c(src_data) op = filter.iir_filter_ccc([1], [1]) dst = blocks.vector_sink_c() - fftaps = (2+2j,) + fftaps = (2 + 2j,) fbtaps = (0, 1) op.set_taps(fftaps, fbtaps) @@ -245,12 +324,20 @@ class test_iir_filter(gr_unittest.TestCase): self.tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data) + self.assertFloatTuplesAlmostEqual(expected_result, result_data) def test_iir_ccz_001(self): - src_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j, 6+6j, 7+7j, 8+8j) + src_data = ( + 1 + 1j, + 2 + 2j, + 3 + 3j, + 4 + 4j, + 5 + 5j, + 6 + 6j, + 7 + 7j, + 8 + 8j) expected_result = (4j, 12j, 24j, 40j, 60j, 84j, 112j, 144j) - fftaps = (2+2j,) + fftaps = (2 + 2j,) fbtaps = (0, 1) src = blocks.vector_source_c(src_data) op = filter.iir_filter_ccz(fftaps, fbtaps) @@ -261,17 +348,25 @@ class test_iir_filter(gr_unittest.TestCase): self.tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data) + self.assertFloatTuplesAlmostEqual(expected_result, result_data) def test_iir_ccz_002(self): - src_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j, 6+6j, 7+7j, 8+8j) + src_data = ( + 1 + 1j, + 2 + 2j, + 3 + 3j, + 4 + 4j, + 5 + 5j, + 6 + 6j, + 7 + 7j, + 8 + 8j) expected_result = (4j, 12j, 24j, 40j, 60j, 84j, 112j, 144j) src = blocks.vector_source_c(src_data) op = filter.iir_filter_ccz([1], [1]) dst = blocks.vector_sink_c() - fftaps = (2+2j,) + fftaps = (2 + 2j,) fbtaps = (0, 1) op.set_taps(fftaps, fbtaps) @@ -280,8 +375,8 @@ class test_iir_filter(gr_unittest.TestCase): self.tb.run() result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data) + self.assertFloatTuplesAlmostEqual(expected_result, result_data) + if __name__ == '__main__': gr_unittest.run(test_iir_filter) - diff --git a/gr-filter/python/filter/qa_interp_fir_filter.py b/gr-filter/python/filter/qa_interp_fir_filter.py index 032d38c073..8d775c1cd0 100644 --- a/gr-filter/python/filter/qa_interp_fir_filter.py +++ b/gr-filter/python/filter/qa_interp_fir_filter.py @@ -13,6 +13,7 @@ from gnuradio import gr, gr_unittest, filter, blocks import math + class test_interp_fir_filter(gr_unittest.TestCase): def setUp(self): @@ -25,13 +26,13 @@ class test_interp_fir_filter(gr_unittest.TestCase): taps = [1, 10, 100, 1000, 10000] src_data = (0, 2, 3, 5, 7, 11, 13, 17) interpolation = 3 - xr = (0,0,0, - 2,20,200,2003,20030, - 300,3005,30050, - 500,5007,50070, - 700,7011,70110, - 1100,11013,110130, - 1300,13017,130170) + xr = (0, 0, 0, + 2, 20, 200, 2003, 20030, + 300, 3005, 30050, + 500, 5007, 50070, + 700, 7011, 70110, + 1100, 11013, 110130, + 1300, 13017, 130170) expected_result = [float(x) for x in xr] src = blocks.vector_source_f(src_data) @@ -44,6 +45,6 @@ class test_interp_fir_filter(gr_unittest.TestCase): L = min(len(result_data), len(expected_result)) self.assertEqual(expected_result[0:L], result_data[0:L]) + if __name__ == '__main__': gr_unittest.run(test_interp_fir_filter) - diff --git a/gr-filter/python/filter/qa_pfb_arb_resampler.py b/gr-filter/python/filter/qa_pfb_arb_resampler.py index 151cc56979..62f8acbdcd 100644 --- a/gr-filter/python/filter/qa_pfb_arb_resampler.py +++ b/gr-filter/python/filter/qa_pfb_arb_resampler.py @@ -12,17 +12,20 @@ from gnuradio import gr, gr_unittest, filter, blocks import math + def sig_source_c(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x) for x in t] + y = [math.cos(2. * math.pi * freq * x) + + 1j * math.sin(2. * math.pi * freq * x) for x in t] return y + def sig_source_f(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.sin(2.*math.pi*freq*x) for x in t] + y = [math.sin(2. * math.pi * freq * x) for x in t] return y + class test_pfb_arb_resampler(gr_unittest.TestCase): def setUp(self): @@ -37,9 +40,13 @@ class test_pfb_arb_resampler(gr_unittest.TestCase): rrate = 2.3421 # 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) + taps = filter.firdes.low_pass_2( + nfilts, + nfilts * fs, + fs / 2, + fs / 10, + attenuation_dB=80, + window=filter.firdes.WIN_BLACKMAN_hARRIS) freq = 121.213 data = sig_source_f(fs, freq, 1, N) @@ -58,14 +65,16 @@ class test_pfb_arb_resampler(gr_unittest.TestCase): phase = pfb.phase_offset(freq, fs) # Create a timeline offset by the filter's group delay - t = [float(x) / (fs*rrate) for x in range(-delay, L-delay)] + t = [float(x) / (fs * rrate) for x in range(-delay, L - delay)] - # Data of the sinusoid at frequency freq with the delay and phase offset. - expected_data = [math.sin(2.*math.pi*freq*x+phase) for x in t] + # Data of the sinusoid at frequency freq with the delay and phase + # offset. + expected_data = [math.sin(2. * math.pi * freq * x + phase) for x in t] dst_data = snk.data() - self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 2) + self.assertFloatTuplesAlmostEqual( + expected_data[-Ntest:], dst_data[-Ntest:], 2) def test_ccf_000(self): N = 5000 # number of samples to use @@ -73,9 +82,13 @@ class test_pfb_arb_resampler(gr_unittest.TestCase): rrate = 2.4321 # 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) + taps = filter.firdes.low_pass_2( + nfilts, + nfilts * fs, + fs / 2, + fs / 10, + attenuation_dB=80, + window=filter.firdes.WIN_BLACKMAN_hARRIS) freq = 211.123 data = sig_source_c(fs, freq, 1, N) @@ -94,15 +107,29 @@ class test_pfb_arb_resampler(gr_unittest.TestCase): phase = pfb.phase_offset(freq, fs) # Create a timeline offset by the filter's group delay - t = [float(x) / (fs*rrate) for x in range(-delay, L-delay)] - - # Data of the sinusoid at frequency freq with the delay and phase offset. - expected_data = [math.cos(2.*math.pi*freq*x+phase) + \ - 1j*math.sin(2.*math.pi*freq*x+phase) for x in t] + t = [float(x) / (fs * rrate) for x in range(-delay, L - delay)] + + # Data of the sinusoid at frequency freq with the delay and phase + # offset. + expected_data = [ + math.cos( + 2. * + math.pi * + freq * + x + + phase) + + 1j * + math.sin( + 2. * + math.pi * + freq * + x + + phase) for x in t] dst_data = snk.data() - self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 2) + self.assertComplexTuplesAlmostEqual( + expected_data[-Ntest:], dst_data[-Ntest:], 2) def test_ccf_001(self): N = 50000 # number of samples to use @@ -110,9 +137,13 @@ class test_pfb_arb_resampler(gr_unittest.TestCase): rrate = 0.75 # resampling rate nfilts = 32 - taps = filter.firdes.low_pass_2(nfilts, nfilts*fs, fs / 4, fs / 10, - attenuation_dB=80, - window=filter.firdes.WIN_BLACKMAN_hARRIS) + taps = filter.firdes.low_pass_2( + nfilts, + nfilts * fs, + fs / 4, + fs / 10, + attenuation_dB=80, + window=filter.firdes.WIN_BLACKMAN_hARRIS) freq = 211.123 data = sig_source_c(fs, freq, 1, N) @@ -131,15 +162,29 @@ class test_pfb_arb_resampler(gr_unittest.TestCase): phase = pfb.phase_offset(freq, fs) # Create a timeline offset by the filter's group delay - t = [float(x) / (fs*rrate) for x in range(-delay, L-delay)] - - # Data of the sinusoid at frequency freq with the delay and phase offset. - expected_data = [math.cos(2.*math.pi*freq*x+phase) + \ - 1j*math.sin(2.*math.pi*freq*x+phase) for x in t] + t = [float(x) / (fs * rrate) for x in range(-delay, L - delay)] + + # Data of the sinusoid at frequency freq with the delay and phase + # offset. + expected_data = [ + math.cos( + 2. * + math.pi * + freq * + x + + phase) + + 1j * + math.sin( + 2. * + math.pi * + freq * + x + + phase) for x in t] dst_data = snk.data() - self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 2) + self.assertComplexTuplesAlmostEqual( + expected_data[-Ntest:], dst_data[-Ntest:], 2) def test_ccc_000(self): N = 5000 # number of samples to use @@ -147,9 +192,14 @@ class test_pfb_arb_resampler(gr_unittest.TestCase): rrate = 3.4321 # resampling rate nfilts = 32 - taps = filter.firdes.complex_band_pass_2(nfilts, nfilts*fs, 50, 400, fs / 10, - attenuation_dB=80, - window=filter.firdes.WIN_BLACKMAN_hARRIS) + taps = filter.firdes.complex_band_pass_2( + nfilts, + nfilts * fs, + 50, + 400, + fs / 10, + attenuation_dB=80, + window=filter.firdes.WIN_BLACKMAN_hARRIS) freq = 211.123 data = sig_source_c(fs, freq, 1, N) @@ -168,15 +218,29 @@ class test_pfb_arb_resampler(gr_unittest.TestCase): phase = pfb.phase_offset(freq, fs) # Create a timeline offset by the filter's group delay - t = [float(x) / (fs*rrate) for x in range(-delay, L-delay)] - - # Data of the sinusoid at frequency freq with the delay and phase offset. - expected_data = [math.cos(2.*math.pi*freq*x+phase) + \ - 1j*math.sin(2.*math.pi*freq*x+phase) for x in t] + t = [float(x) / (fs * rrate) for x in range(-delay, L - delay)] + + # Data of the sinusoid at frequency freq with the delay and phase + # offset. + expected_data = [ + math.cos( + 2. * + math.pi * + freq * + x + + phase) + + 1j * + math.sin( + 2. * + math.pi * + freq * + x + + phase) for x in t] dst_data = snk.data() - self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 2) + self.assertComplexTuplesAlmostEqual( + expected_data[-Ntest:], dst_data[-Ntest:], 2) def test_ccc_001(self): N = 50000 # number of samples to use @@ -184,9 +248,14 @@ class test_pfb_arb_resampler(gr_unittest.TestCase): rrate = 0.715 # resampling rate nfilts = 32 - taps = filter.firdes.complex_band_pass_2(nfilts, nfilts*fs, 50, 400, fs / 10, - attenuation_dB=80, - window=filter.firdes.WIN_BLACKMAN_hARRIS) + taps = filter.firdes.complex_band_pass_2( + nfilts, + nfilts * fs, + 50, + 400, + fs / 10, + attenuation_dB=80, + window=filter.firdes.WIN_BLACKMAN_hARRIS) freq = 211.123 data = sig_source_c(fs, freq, 1, N) @@ -205,15 +274,30 @@ class test_pfb_arb_resampler(gr_unittest.TestCase): phase = pfb.phase_offset(freq, fs) # Create a timeline offset by the filter's group delay - t = [float(x) / (fs*rrate) for x in range(-delay, L-delay)] - - # Data of the sinusoid at frequency freq with the delay and phase offset. - expected_data = [math.cos(2.*math.pi*freq*x+phase) + \ - 1j*math.sin(2.*math.pi*freq*x+phase) for x in t] + t = [float(x) / (fs * rrate) for x in range(-delay, L - delay)] + + # Data of the sinusoid at frequency freq with the delay and phase + # offset. + expected_data = [ + math.cos( + 2. * + math.pi * + freq * + x + + phase) + + 1j * + math.sin( + 2. * + math.pi * + freq * + x + + phase) for x in t] dst_data = snk.data() - self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 2) + self.assertComplexTuplesAlmostEqual( + expected_data[-Ntest:], dst_data[-Ntest:], 2) + if __name__ == '__main__': gr_unittest.run(test_pfb_arb_resampler) diff --git a/gr-filter/python/filter/qa_pfb_channelizer.py b/gr-filter/python/filter/qa_pfb_channelizer.py index 727c18a9a5..d09b1281bb 100644 --- a/gr-filter/python/filter/qa_pfb_channelizer.py +++ b/gr-filter/python/filter/qa_pfb_channelizer.py @@ -10,12 +10,14 @@ from gnuradio import gr, gr_unittest, filter, blocks, analog -import math, cmath +import math +import cmath + def sig_source_c(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x) for x in t] + y = [math.cos(2. * math.pi * freq * x) + + 1j * math.sin(2. * math.pi * freq * x) for x in t] return y @@ -31,7 +33,7 @@ class test_pfb_channelizer(gr_unittest.TestCase): # Baseband sampling rate. self.fs = 5000 # Input samp rate to channelizer. - self.ifs = self.M*self.fs + self.ifs = self.M * self.fs self.taps = filter.firdes.low_pass_2( 1, self.ifs, self.fs / 2, self.fs / 10, @@ -40,7 +42,6 @@ class test_pfb_channelizer(gr_unittest.TestCase): self.Ntest = 50 - def tearDown(self): self.tb = None @@ -74,9 +75,14 @@ class test_pfb_channelizer(gr_unittest.TestCase): signals = [] add = blocks.add_cc() for i in range(len(self.freqs)): - f = self.freqs[i] + i*self.fs - signals.append(analog.sig_source_c(self.ifs, analog.GR_SIN_WAVE, f, 1)) - tb.connect(signals[i], (add,i)) + f = self.freqs[i] + i * self.fs + signals.append( + analog.sig_source_c( + self.ifs, + analog.GR_SIN_WAVE, + f, + 1)) + tb.connect(signals[i], (add, i)) head = blocks.head(gr.sizeof_gr_complex, self.N) snk = blocks.vector_sink_c() tb.connect(add, head, snk) @@ -88,10 +94,10 @@ class test_pfb_channelizer(gr_unittest.TestCase): signals = list() add = blocks.add_cc() for i in range(len(self.freqs)): - f = self.freqs[i] + i*self.fs + f = self.freqs[i] + i * self.fs data = sig_source_c(self.ifs, f, 1, self.N) signals.append(blocks.vector_source_c(data)) - self.tb.connect(signals[i], (add,i)) + self.tb.connect(signals[i], (add, i)) #s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, self.M) @@ -122,18 +128,17 @@ class test_pfb_channelizer(gr_unittest.TestCase): received = [x / received[0] for x in received] self.assertComplexTuplesAlmostEqual(expected, received, 3) - def get_freq(self, data): freqs = [] for r1, r2 in zip(data[:-1], data[1:]): diff = cmath.phase(r1) - cmath.phase(r2) if diff > math.pi: - diff -= 2*math.pi + diff -= 2 * math.pi if diff < -math.pi: - diff += 2*math.pi + diff += 2 * math.pi freqs.append(diff) freq = float(sum(freqs)) / len(freqs) - freq /= 2*math.pi + freq /= 2 * math.pi return freq def get_expected_data(self, L): @@ -144,12 +149,19 @@ class test_pfb_channelizer(gr_unittest.TestCase): delay = int(delay) # Create a time scale that's delayed to match the filter delay - t = [float(x) / self.fs for x in range(delay, L+delay)] + t = [float(x) / self.fs for x in range(delay, L + delay)] # Create known data as complex sinusoids at the different baseband freqs # the different channel numbering is due to channelizer output order. - expected_data = [[math.cos(2.*math.pi*f*x) + - 1j*math.sin(2.*math.pi*f*x) for x in t] for f in self.freqs] + expected_data = [[math.cos(2. * + math.pi * + f * + x) + + 1j * + math.sin(2. * + math.pi * + f * + x) for x in t] for f in self.freqs] return expected_data diff --git a/gr-filter/python/filter/qa_pfb_decimator.py b/gr-filter/python/filter/qa_pfb_decimator.py index 7325b6620d..58150fa4cc 100644 --- a/gr-filter/python/filter/qa_pfb_decimator.py +++ b/gr-filter/python/filter/qa_pfb_decimator.py @@ -12,67 +12,82 @@ from gnuradio import gr, gr_unittest, filter, blocks import math + def sig_source_c(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x) for x in t] + y = [math.cos(2. * math.pi * freq * x) + + 1j * math.sin(2. * math.pi * freq * x) for x in t] return y + def run_test(tb, channel, fft_rotate, fft_filter): - N = 1000 # number of samples to use - M = 5 # Number of channels - fs = 5000.0 # baseband sampling rate - ifs = M*fs # input samp rate to decimator - - taps = filter.firdes.low_pass_2(1, ifs, fs / 2, fs / 10, - attenuation_dB=80, - window=filter.firdes.WIN_BLACKMAN_hARRIS) - - signals = list() - add = blocks.add_cc() - freqs = [-230., 121., 110., -513., 203.] - Mch = ((len(freqs)-1) // 2 + channel) % len(freqs) - for i in range(len(freqs)): - f = freqs[i] + (M // 2-M+i+1)*fs - data = sig_source_c(ifs, f, 1, N) - signals.append(blocks.vector_source_c(data)) - tb.connect(signals[i], (add,i)) - - s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, M) - pfb = filter.pfb_decimator_ccf(M, taps, channel, fft_rotate, fft_filter) - snk = blocks.vector_sink_c() - - tb.connect(add, s2ss) - for i in range(M): - tb.connect((s2ss,i), (pfb,i)) - tb.connect(pfb, snk) - tb.run() - - L = len(snk.data()) - - # Adjusted phase rotations for data - phase = [ 0.11058476216852586, - 4.5108246571401693, - 3.9739891674564594, - 2.2820531095511924, - 1.3782797467397869] - phase = phase[channel] - - # Filter delay is the normal delay of each arm - tpf = math.ceil(len(taps) / float(M)) - delay = -(tpf - 1.0) / 2.0 - delay = int(delay) - - # Create a time scale that's delayed to match the filter delay - t = [float(x) / fs for x in range(delay, L+delay)] - - # Create known data as complex sinusoids for the baseband freq - # of the extracted channel is due to decimator output order. - expected_data = [math.cos(2.*math.pi*freqs[Mch]*x+phase) + \ - 1j*math.sin(2.*math.pi*freqs[Mch]*x+phase) for x in t] - dst_data = snk.data() - - return (dst_data, expected_data) + N = 1000 # number of samples to use + M = 5 # Number of channels + fs = 5000.0 # baseband sampling rate + ifs = M * fs # input samp rate to decimator + + taps = filter.firdes.low_pass_2(1, ifs, fs / 2, fs / 10, + attenuation_dB=80, + window=filter.firdes.WIN_BLACKMAN_hARRIS) + + signals = list() + add = blocks.add_cc() + freqs = [-230., 121., 110., -513., 203.] + Mch = ((len(freqs) - 1) // 2 + channel) % len(freqs) + for i in range(len(freqs)): + f = freqs[i] + (M // 2 - M + i + 1) * fs + data = sig_source_c(ifs, f, 1, N) + signals.append(blocks.vector_source_c(data)) + tb.connect(signals[i], (add, i)) + + s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, M) + pfb = filter.pfb_decimator_ccf(M, taps, channel, fft_rotate, fft_filter) + snk = blocks.vector_sink_c() + + tb.connect(add, s2ss) + for i in range(M): + tb.connect((s2ss, i), (pfb, i)) + tb.connect(pfb, snk) + tb.run() + + L = len(snk.data()) + + # Adjusted phase rotations for data + phase = [0.11058476216852586, + 4.5108246571401693, + 3.9739891674564594, + 2.2820531095511924, + 1.3782797467397869] + phase = phase[channel] + + # Filter delay is the normal delay of each arm + tpf = math.ceil(len(taps) / float(M)) + delay = -(tpf - 1.0) / 2.0 + delay = int(delay) + + # Create a time scale that's delayed to match the filter delay + t = [float(x) / fs for x in range(delay, L + delay)] + + # Create known data as complex sinusoids for the baseband freq + # of the extracted channel is due to decimator output order. + expected_data = [ + math.cos( + 2. * + math.pi * + freqs[Mch] * + x + + phase) + + 1j * + math.sin( + 2. * + math.pi * + freqs[Mch] * + x + + phase) for x in t] + dst_data = snk.data() + + return (dst_data, expected_data) + class test_pfb_decimator(gr_unittest.TestCase): @@ -89,10 +104,14 @@ class test_pfb_decimator(gr_unittest.TestCase): dst_data2, expected_data2 = run_test(self.tb, 0, True, False) dst_data3, expected_data3 = run_test(self.tb, 0, True, True) - self.assertComplexTuplesAlmostEqual(expected_data0[-Ntest:], dst_data0[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data1[-Ntest:], dst_data1[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data2[-Ntest:], dst_data2[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data3[-Ntest:], dst_data3[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data0[-Ntest:], dst_data0[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data1[-Ntest:], dst_data1[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data2[-Ntest:], dst_data2[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data3[-Ntest:], dst_data3[-Ntest:], 4) def test_001(self): Ntest = 50 @@ -101,10 +120,14 @@ class test_pfb_decimator(gr_unittest.TestCase): dst_data2, expected_data2 = run_test(self.tb, 1, True, False) dst_data3, expected_data3 = run_test(self.tb, 1, True, True) - self.assertComplexTuplesAlmostEqual(expected_data0[-Ntest:], dst_data0[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data1[-Ntest:], dst_data1[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data2[-Ntest:], dst_data2[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data3[-Ntest:], dst_data3[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data0[-Ntest:], dst_data0[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data1[-Ntest:], dst_data1[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data2[-Ntest:], dst_data2[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data3[-Ntest:], dst_data3[-Ntest:], 4) def test_002(self): Ntest = 50 @@ -113,10 +136,14 @@ class test_pfb_decimator(gr_unittest.TestCase): dst_data2, expected_data2 = run_test(self.tb, 2, True, False) dst_data3, expected_data3 = run_test(self.tb, 2, True, True) - self.assertComplexTuplesAlmostEqual(expected_data0[-Ntest:], dst_data0[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data1[-Ntest:], dst_data1[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data2[-Ntest:], dst_data2[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data3[-Ntest:], dst_data3[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data0[-Ntest:], dst_data0[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data1[-Ntest:], dst_data1[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data2[-Ntest:], dst_data2[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data3[-Ntest:], dst_data3[-Ntest:], 4) def test_003(self): Ntest = 50 @@ -125,10 +152,14 @@ class test_pfb_decimator(gr_unittest.TestCase): dst_data2, expected_data2 = run_test(self.tb, 3, True, False) dst_data3, expected_data3 = run_test(self.tb, 3, True, True) - self.assertComplexTuplesAlmostEqual(expected_data0[-Ntest:], dst_data0[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data1[-Ntest:], dst_data1[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data2[-Ntest:], dst_data2[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data3[-Ntest:], dst_data3[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data0[-Ntest:], dst_data0[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data1[-Ntest:], dst_data1[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data2[-Ntest:], dst_data2[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data3[-Ntest:], dst_data3[-Ntest:], 4) def test_004(self): Ntest = 50 @@ -137,10 +168,15 @@ class test_pfb_decimator(gr_unittest.TestCase): dst_data2, expected_data2 = run_test(self.tb, 4, True, False) dst_data3, expected_data3 = run_test(self.tb, 4, True, True) - self.assertComplexTuplesAlmostEqual(expected_data0[-Ntest:], dst_data0[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data1[-Ntest:], dst_data1[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data2[-Ntest:], dst_data2[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected_data3[-Ntest:], dst_data3[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data0[-Ntest:], dst_data0[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data1[-Ntest:], dst_data1[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data2[-Ntest:], dst_data2[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data3[-Ntest:], dst_data3[-Ntest:], 4) + if __name__ == '__main__': gr_unittest.run(test_pfb_decimator) diff --git a/gr-filter/python/filter/qa_pfb_interpolator.py b/gr-filter/python/filter/qa_pfb_interpolator.py index 279f751f21..1003c4aced 100644 --- a/gr-filter/python/filter/qa_pfb_interpolator.py +++ b/gr-filter/python/filter/qa_pfb_interpolator.py @@ -13,12 +13,14 @@ from gnuradio import gr, gr_unittest, filter, blocks import math + def sig_source_c(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x) for x in t] + y = [math.cos(2. * math.pi * freq * x) + + 1j * math.sin(2. * math.pi * freq * x) for x in t] return y + class test_pfb_interpolator(gr_unittest.TestCase): def setUp(self): @@ -31,11 +33,15 @@ class test_pfb_interpolator(gr_unittest.TestCase): N = 1000 # number of samples to use M = 5 # Number of channels fs = 1000 # baseband sampling rate - ofs = M*fs # output samp rate of interpolator + ofs = M * fs # output samp rate of interpolator - taps = filter.firdes.low_pass_2(M, ofs, fs / 4, fs / 10, - attenuation_dB=80, - window=filter.firdes.WIN_BLACKMAN_hARRIS) + taps = filter.firdes.low_pass_2( + M, + ofs, + fs / 4, + fs / 10, + attenuation_dB=80, + window=filter.firdes.WIN_BLACKMAN_hARRIS) freq = 123.456 data = sig_source_c(fs, freq, 1, N) @@ -59,12 +65,26 @@ class test_pfb_interpolator(gr_unittest.TestCase): # Create known data as complex sinusoids for the baseband freq # of the extracted channel is due to decimator output order. - expected_data = [math.cos(2.*math.pi*freq*x+phase) + \ - 1j*math.sin(2.*math.pi*freq*x+phase) for x in t] + expected_data = [ + math.cos( + 2. * + math.pi * + freq * + x + + phase) + + 1j * + math.sin( + 2. * + math.pi * + freq * + x + + phase) for x in t] dst_data = snk.data() - self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual( + expected_data[-Ntest:], dst_data[-Ntest:], 4) + if __name__ == '__main__': gr_unittest.run(test_pfb_interpolator) diff --git a/gr-filter/python/filter/qa_pfb_synthesizer.py b/gr-filter/python/filter/qa_pfb_synthesizer.py index f55882b904..eb46bbe92e 100644 --- a/gr-filter/python/filter/qa_pfb_synthesizer.py +++ b/gr-filter/python/filter/qa_pfb_synthesizer.py @@ -13,12 +13,14 @@ from gnuradio import gr, gr_unittest, filter, blocks import math + def sig_source_c(samp_rate, freq, amp, N): t = [float(x) / samp_rate for x in range(N)] - y = [math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x) for x in t] + y = [math.cos(2. * math.pi * freq * x) + + 1j * math.sin(2. * math.pi * freq * x) for x in t] return y + class test_pfb_synthesizer(gr_unittest.TestCase): def setUp(self): @@ -31,11 +33,15 @@ class test_pfb_synthesizer(gr_unittest.TestCase): N = 10000 # number of samples to use M = 5 # Number of channels fs = 1000 # baseband sampling rate - ofs = M*fs # input samp rate to decimator + ofs = M * fs # input samp rate to decimator - taps = filter.firdes.low_pass_2(M, ofs, fs / 2, fs / 10, - attenuation_dB=80, - window=filter.firdes.WIN_BLACKMAN_hARRIS) + taps = filter.firdes.low_pass_2( + M, + ofs, + fs / 2, + fs / 10, + attenuation_dB=80, + window=filter.firdes.WIN_BLACKMAN_hARRIS) signals = list() freqs = [0, 100, 200, -200, -100] @@ -47,7 +53,7 @@ class test_pfb_synthesizer(gr_unittest.TestCase): snk = blocks.vector_sink_c() for i in range(M): - self.tb.connect(signals[i], (pfb,i)) + self.tb.connect(signals[i], (pfb, i)) self.tb.connect(pfb, snk) @@ -55,10 +61,10 @@ class test_pfb_synthesizer(gr_unittest.TestCase): # Adjusted phase rotations for data p0 = 0 - p1 = 2*math.pi*1.0/M - p2 = 2*math.pi*2.0/M - p3 = 2*math.pi*3.0/M - p4 = 2*math.pi*4.0/M + p1 = 2 * math.pi * 1.0 / M + p2 = 2 * math.pi * 2.0 / M + p3 = 2 * math.pi * 3.0 / M + p4 = 2 * math.pi * 4.0 / M Ntest = 1000 L = len(snk.data()) @@ -67,22 +73,23 @@ class test_pfb_synthesizer(gr_unittest.TestCase): # Create known data as sum of complex sinusoids at freqs # of the output channels. freqs = [-2200, -1100, 0, 1100, 2200] - expected_data = len(t)*[0,] + expected_data = len(t) * [0, ] for i in range(len(t)): - expected_data[i] = math.cos(2.*math.pi*freqs[0]*t[i] + p3) + \ - 1j*math.sin(2.*math.pi*freqs[0]*t[i] + p3) + \ - math.cos(2.*math.pi*freqs[1]*t[i] + p4) + \ - 1j*math.sin(2.*math.pi*freqs[1]*t[i] + p4) + \ - math.cos(2.*math.pi*freqs[2]*t[i] + p0) + \ - 1j*math.sin(2.*math.pi*freqs[2]*t[i] + p0) + \ - math.cos(2.*math.pi*freqs[3]*t[i] + p1) + \ - 1j*math.sin(2.*math.pi*freqs[3]*t[i] + p1) + \ - math.cos(2.*math.pi*freqs[4]*t[i] + p2) + \ - 1j*math.sin(2.*math.pi*freqs[4]*t[i] + p2) + expected_data[i] = math.cos(2. * math.pi * freqs[0] * t[i] + p3) + \ + 1j * math.sin(2. * math.pi * freqs[0] * t[i] + p3) + \ + math.cos(2. * math.pi * freqs[1] * t[i] + p4) + \ + 1j * math.sin(2. * math.pi * freqs[1] * t[i] + p4) + \ + math.cos(2. * math.pi * freqs[2] * t[i] + p0) + \ + 1j * math.sin(2. * math.pi * freqs[2] * t[i] + p0) + \ + math.cos(2. * math.pi * freqs[3] * t[i] + p1) + \ + 1j * math.sin(2. * math.pi * freqs[3] * t[i] + p1) + \ + math.cos(2. * math.pi * freqs[4] * t[i] + p2) + \ + 1j * math.sin(2. * math.pi * freqs[4] * t[i] + p2) dst_data = snk.data() - self.assertComplexTuplesAlmostEqual(expected_data[2000:2000+Ntest], - dst_data[2000:2000+Ntest], 4) + self.assertComplexTuplesAlmostEqual(expected_data[2000:2000 + Ntest], + dst_data[2000:2000 + Ntest], 4) + if __name__ == '__main__': gr_unittest.run(test_pfb_synthesizer) diff --git a/gr-filter/python/filter/qa_pm_remez.py b/gr-filter/python/filter/qa_pm_remez.py index 9bb4d4d6ee..8a2b397b17 100644 --- a/gr-filter/python/filter/qa_pm_remez.py +++ b/gr-filter/python/filter/qa_pm_remez.py @@ -10,22 +10,26 @@ from gnuradio import gr, gr_unittest, filter -import sys, math +import sys +import math # ---------------------------------------------------------------- # See optfir for an explanation of these. -def stopband_atten_to_dev (atten_db): + +def stopband_atten_to_dev(atten_db): """Convert a stopband attenuation in dB to an absolute value""" return 10**(-atten_db / 20) -def passband_ripple_to_dev (ripple_db): + +def passband_ripple_to_dev(ripple_db): """Convert passband ripple spec expressed in dB to an absolute value""" - return (10**(ripple_db / 20)-1) / (10**(ripple_db / 20)+1) + return (10**(ripple_db / 20) - 1) / (10**(ripple_db / 20) + 1) # ---------------------------------------------------------------- -def remezord (fcuts, mags, devs, fsamp = 2): + +def remezord(fcuts, mags, devs, fsamp=2): ''' FIR order estimator (lowpass, highpass, bandpass, mulitiband). ''' @@ -35,12 +39,12 @@ def remezord (fcuts, mags, devs, fsamp = 2): mags = mags[:] devs = devs[:] - for i in range (len (fcuts)): - fcuts[i] = float (fcuts[i]) / fsamp + for i in range(len(fcuts)): + fcuts[i] = float(fcuts[i]) / fsamp - nf = len (fcuts) - nm = len (mags) - nd = len (devs) + nf = len(fcuts) + nm = len(mags) + nd = len(devs) nbands = nm if nm != nd: @@ -49,7 +53,7 @@ def remezord (fcuts, mags, devs, fsamp = 2): if nf != 2 * (nbands - 1): raise ValueError("Length of f must be 2 * len (mags) - 2") - for i in range (len (mags)): + for i in range(len(mags)): if mags[i] != 0: # if not stopband, get relative deviation devs[i] = devs[i] / mags[i] @@ -59,50 +63,50 @@ def remezord (fcuts, mags, devs, fsamp = 2): n = 0 min_delta = 2 - for i in range (len (f1)): + for i in range(len(f1)): if f2[i] - f1[i] < min_delta: n = i min_delta = f2[i] - f1[i] if nbands == 2: # lowpass or highpass case (use formula) - l = lporder (f1[n], f2[n], devs[0], devs[1]) + l = lporder(f1[n], f2[n], devs[0], devs[1]) else: # bandpass or multipass case # try different lowpasses and take the worst one that # goes through the BP specs l = 0 - for i in range (1, nbands-1): - l1 = lporder (f1[i-1], f2[i-1], devs[i], devs[i-1]) - l2 = lporder (f1[i], f2[i], devs[i], devs[i+1]) - l = max (l, l1, l2) + for i in range(1, nbands - 1): + l1 = lporder(f1[i - 1], f2[i - 1], devs[i], devs[i - 1]) + l2 = lporder(f1[i], f2[i], devs[i], devs[i + 1]) + l = max(l, l1, l2) - n = int (math.ceil (l)) - 1 # need order, not length for remez + n = int(math.ceil(l)) - 1 # need order, not length for remez # cook up remez compatible result ff = [0] + fcuts + [1] - for i in range (1, len (ff) - 1): + for i in range(1, len(ff) - 1): ff[i] *= 2 aa = [] for a in mags: aa = aa + [a, a] - max_dev = max (devs) + max_dev = max(devs) wts = [1] * len(devs) - for i in range (len (wts)): + for i in range(len(wts)): wts[i] = max_dev / devs[i] return (n, ff, aa, wts) -def lporder (freq1, freq2, delta_p, delta_s): +def lporder(freq1, freq2, delta_p, delta_s): ''' FIR lowpass filter length estimator. ''' - df = abs (freq2 - freq1) - ddp = math.log10 (delta_p) - dds = math.log10 (delta_s) + df = abs(freq2 - freq1) + ddp = math.log10(delta_p) + dds = math.log10(delta_s) a1 = 5.309e-3 a2 = 7.114e-2 @@ -119,13 +123,14 @@ def lporder (freq1, freq2, delta_p, delta_s): t3 = a4 * ddp * ddp t4 = a5 * ddp - dinf=((t1 + t2 + a3) * dds) + (t3 + t4 + a6) + dinf = ((t1 + t2 + a3) * dds) + (t3 + t4 + a6) ff = b1 + b2 * (ddp - dds) n = dinf / df - ff * df + 1 return n # ---------------------------------------------------------------- + class test_pm_remez(gr_unittest.TestCase): def setUp(self): @@ -150,26 +155,27 @@ class test_pm_remez(gr_unittest.TestCase): new_taps = filter.pm_remez(n + 2, fo, ao, w, "bandpass") known_taps = (-0.0008370135734511828, -0.0006622211673134374, - 0.0008501079576365787, 0.003059609130249229, - 0.003202235537205373, -0.001000899296974219, - -0.007589728680590891, -0.009790921118281865, - -0.001524210202628562, 0.014373535837200111, - 0.02392881326993834, 0.011798133085019008, - -0.021954446348997188, -0.05293436740264934, - -0.04375787096766848, 0.028038890498420392, - 0.14612655590172896, 0.25738578419108626, - 0.302967004188747, 0.25738578419108626, - 0.14612655590172896, 0.028038890498420392, - -0.04375787096766848, -0.05293436740264934, - -0.021954446348997188, 0.011798133085019008, - 0.02392881326993834, 0.014373535837200111, - -0.001524210202628562, -0.009790921118281865, - -0.007589728680590891, -0.001000899296974219, - 0.003202235537205373, 0.003059609130249229, - 0.0008501079576365787, -0.0006622211673134374, - -0.0008370135734511828) + 0.0008501079576365787, 0.003059609130249229, + 0.003202235537205373, -0.001000899296974219, + -0.007589728680590891, -0.009790921118281865, + -0.001524210202628562, 0.014373535837200111, + 0.02392881326993834, 0.011798133085019008, + -0.021954446348997188, -0.05293436740264934, + -0.04375787096766848, 0.028038890498420392, + 0.14612655590172896, 0.25738578419108626, + 0.302967004188747, 0.25738578419108626, + 0.14612655590172896, 0.028038890498420392, + -0.04375787096766848, -0.05293436740264934, + -0.021954446348997188, 0.011798133085019008, + 0.02392881326993834, 0.014373535837200111, + -0.001524210202628562, -0.009790921118281865, + -0.007589728680590891, -0.001000899296974219, + 0.003202235537205373, 0.003059609130249229, + 0.0008501079576365787, -0.0006622211673134374, + -0.0008370135734511828) self.assertFloatTuplesAlmostEqual(known_taps, new_taps, 5) + if __name__ == '__main__': gr_unittest.run(test_pm_remez) diff --git a/gr-filter/python/filter/qa_rational_resampler.py b/gr-filter/python/filter/qa_rational_resampler.py index 7cc75f9cc3..bd4122d93d 100644 --- a/gr-filter/python/filter/qa_rational_resampler.py +++ b/gr-filter/python/filter/qa_rational_resampler.py @@ -34,6 +34,7 @@ def reference_dec_filter(src_data, decim, taps): tb = None return result_data + def reference_interp_filter(src_data, interp, taps): tb = gr.top_block() src = blocks.vector_source_f(src_data) @@ -45,6 +46,7 @@ def reference_interp_filter(src_data, interp, taps): tb = None return result_data + def reference_interp_dec_filter(src_data, interp, decim, taps): tb = gr.top_block() src = blocks.vector_source_f(src_data) @@ -66,10 +68,9 @@ class test_rational_resampler (gr_unittest.TestCase): def tearDown(self): pass - def test_000_1_to_1(self): taps = (-4, 5) - src_data = (234, -4, 23, -56, 45, 98, -23, -7) + src_data = (234, -4, 23, -56, 45, 98, -23, -7) xr = (1186, -112, 339, -460, -167, 582) expected_result = [float(x) for x in xr] @@ -87,13 +88,13 @@ class test_rational_resampler (gr_unittest.TestCase): taps = [1, 10, 100, 1000, 10000] src_data = (0, 2, 3, 5, 7, 11, 13, 17) interpolation = 3 - xr = (2,20,200,2003,20030, - 300,3005,30050, - 500,5007,50070, - 700,7011,70110, - 1100,11013,110130, - 1300,13017,130170, - 1700.0,17000.0,170000.0, 0.0) + xr = (2, 20, 200, 2003, 20030, + 300, 3005, 30050, + 500, 5007, 50070, + 700, 7011, 70110, + 1100, 11013, 110130, + 1300, 13017, 130170, + 1700.0, 17000.0, 170000.0, 0.0) expected_result = [float(x) for x in xr] tb = gr.top_block() @@ -111,7 +112,8 @@ class test_rational_resampler (gr_unittest.TestCase): src_data = random_floats(10000) interpolation = 3 - expected_result = reference_interp_filter(src_data, interpolation, taps) + expected_result = reference_interp_filter( + src_data, interpolation, taps) tb = gr.top_block() src = blocks.vector_source_f(src_data) @@ -123,8 +125,8 @@ class test_rational_resampler (gr_unittest.TestCase): result_data = dst.data() N = 1000 - offset = len(taps)-1 - self.assertEqual(expected_result[offset:offset+N], result_data[0:N]) + offset = len(taps) - 1 + self.assertEqual(expected_result[offset:offset + N], result_data[0:N]) def xtest_003_interp(self): taps = random_floats(9) @@ -143,9 +145,9 @@ class test_rational_resampler (gr_unittest.TestCase): result_data = dst.data() N = 10 - offset = 10#len(taps)-1 - print(expected_result[100+offset:100+offset+N]) - print(result_data[100:100+N]) + offset = 10 # len(taps)-1 + print(expected_result[100 + offset:100 + offset + N]) + print(result_data[100:100 + N]) #self.assertEqual(expected_result[offset:offset+N], result_data[0:N]) # FIXME disabled. Triggers hang on SuSE 10.0 @@ -157,11 +159,12 @@ class test_rational_resampler (gr_unittest.TestCase): random.seed(0) # we want reproducibility for ntaps in range(1, MAX_TAPS + 1): - for decim in range(1, MAX_DECIM+1): - for ilen in range(ntaps + decim, ntaps + OUTPUT_LEN*decim): + for decim in range(1, MAX_DECIM + 1): + for ilen in range(ntaps + decim, ntaps + OUTPUT_LEN * decim): src_data = random_floats(ilen) taps = random_floats(ntaps) - expected_result = reference_dec_filter(src_data, decim, taps) + expected_result = reference_dec_filter( + src_data, decim, taps) tb = gr.top_block() src = blocks.vector_source_f(src_data) @@ -176,13 +179,16 @@ class test_rational_resampler (gr_unittest.TestCase): L2 = len(expected_result) L = min(L1, L2) if False: - sys.stderr.write('delta = %2d: ntaps = %d decim = %d ilen = %d\n' % (L2 - L1, ntaps, decim, ilen)) - sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' % - (len(result_data), len(expected_result))) + sys.stderr.write( + 'delta = %2d: ntaps = %d decim = %d ilen = %d\n' % + (L2 - L1, ntaps, decim, ilen)) + sys.stderr.write( + ' len(result_data) = %d len(expected_result) = %d\n' % + (len(result_data), len(expected_result))) self.assertEqual(expected_result[0:L], result_data[0:L]) - # FIXME disabled. Triggers hang on SuSE 10.0 + def xtest_005_interp_random_vals(self): MAX_TAPS = 9 MAX_INTERP = 7 @@ -191,11 +197,12 @@ class test_rational_resampler (gr_unittest.TestCase): random.seed(0) # we want reproducibility for ntaps in range(1, MAX_TAPS + 1): - for interp in range(1, MAX_INTERP+1): + for interp in range(1, MAX_INTERP + 1): for ilen in range(ntaps, ntaps + INPUT_LEN): src_data = random_floats(ilen) taps = random_floats(ntaps) - expected_result = reference_interp_filter(src_data, interp, taps) + expected_result = reference_interp_filter( + src_data, interp, taps) tb = gr.top_block() src = blocks.vector_source_f(src_data) @@ -208,14 +215,17 @@ class test_rational_resampler (gr_unittest.TestCase): L1 = len(result_data) L2 = len(expected_result) L = min(L1, L2) - #if True or abs(L1-L2) > 1: + # if True or abs(L1-L2) > 1: if False: - sys.stderr.write('delta = %2d: ntaps = %d interp = %d ilen = %d\n' % (L2 - L1, ntaps, interp, ilen)) - #sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' % + sys.stderr.write( + 'delta = %2d: ntaps = %d interp = %d ilen = %d\n' % + (L2 - L1, ntaps, interp, ilen)) + # sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' % # (len(result_data), len(expected_result))) #self.assertEqual(expected_result[0:L], result_data[0:L]) # FIXME check first ntaps+1 answers - self.assertEqual(expected_result[ntaps+1:L], result_data[ntaps+1:L]) + self.assertEqual( + expected_result[ntaps + 1:L], result_data[ntaps + 1:L]) def test_006_interp_decim(self): taps = random_floats(31) @@ -223,7 +233,8 @@ class test_rational_resampler (gr_unittest.TestCase): interp = 3 decimation = 2 - expected_result = reference_interp_dec_filter(src_data, interp, decimation, taps) + expected_result = reference_interp_dec_filter( + src_data, interp, decimation, taps) tb = gr.top_block() src = blocks.vector_source_f(src_data) @@ -236,7 +247,8 @@ class test_rational_resampler (gr_unittest.TestCase): N = 1000 offset = len(taps) // 2 - self.assertFloatTuplesAlmostEqual(expected_result[offset:offset+N], result_data[0:N], 5) + self.assertFloatTuplesAlmostEqual( + expected_result[offset:offset + N], result_data[0:N], 5) if __name__ == '__main__': diff --git a/gr-filter/python/filter/qa_single_pole_iir.py b/gr-filter/python/filter/qa_single_pole_iir.py index b6d88ff458..8d7a7c5eba 100644 --- a/gr-filter/python/filter/qa_single_pole_iir.py +++ b/gr-filter/python/filter/qa_single_pole_iir.py @@ -11,12 +11,13 @@ from gnuradio import gr, gr_unittest, filter, blocks + class test_single_pole_iir_filter(gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test_ff_001(self): @@ -32,7 +33,13 @@ class test_single_pole_iir_filter(gr_unittest.TestCase): def test_ff_002(self): src_data = (0, 1000, 2000, 3000, 4000, 5000) - expected_result = (0, 125, 359.375, 689.453125, 1103.271484, 1590.36255) + expected_result = ( + 0, + 125, + 359.375, + 689.453125, + 1103.271484, + 1590.36255) src = blocks.vector_source_f(src_data) op = filter.single_pole_iir_filter_ff(0.125) dst = blocks.vector_sink_f() @@ -47,7 +54,7 @@ class test_single_pole_iir_filter(gr_unittest.TestCase): expected_result = (0, 125, 250, 484.375, 718.75, 1048.828125) src = blocks.vector_source_f(src_data) s2p = blocks.stream_to_vector(gr.sizeof_float, block_size) - op = filter.single_pole_iir_filter_ff (0.125, block_size) + op = filter.single_pole_iir_filter_ff(0.125, block_size) p2s = blocks.vector_to_stream(gr.sizeof_float, block_size) dst = blocks.vector_sink_f() self.tb.connect(src, s2p, op, p2s, dst) @@ -56,7 +63,13 @@ class test_single_pole_iir_filter(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual(expected_result, result_data, 3) def test_cc_001(self): - src_data = (0+0j, 1000+1000j, 2000+2000j, 3000+3000j, 4000+4000j, 5000+5000j) + src_data = ( + 0 + 0j, + 1000 + 1000j, + 2000 + 2000j, + 3000 + 3000j, + 4000 + 4000j, + 5000 + 5000j) expected_result = src_data src = blocks.vector_source_c(src_data) op = filter.single_pole_iir_filter_cc(1.0) @@ -67,11 +80,18 @@ class test_single_pole_iir_filter(gr_unittest.TestCase): self.assertComplexTuplesAlmostEqual(expected_result, result_data) def test_cc_002(self): - src_data = (complex(0,0), complex(1000,-1000), complex(2000,-2000), - complex(3000,-3000), complex(4000,-4000), complex(5000,-5000)) - expected_result = (complex(0,0), complex(125,-125), complex(359.375,-359.375), - complex(689.453125,-689.453125), complex(1103.271484,-1103.271484), - complex(1590.36255,-1590.36255)) + src_data = (complex(0, 0), complex(1000, - + 1000), complex(2000, - + 2000), complex(3000, - + 3000), complex(4000, - + 4000), complex(5000, - + 5000)) + expected_result = (complex(0, 0), complex(125, - + 125), complex(359.375, - + 359.375), complex(689.453125, - + 689.453125), complex(1103.271484, - + 1103.271484), complex(1590.36255, - + 1590.36255)) src = blocks.vector_source_c(src_data) op = filter.single_pole_iir_filter_cc(0.125) dst = blocks.vector_sink_c() @@ -82,11 +102,18 @@ class test_single_pole_iir_filter(gr_unittest.TestCase): def test_cc_003(self): block_size = 2 - src_data = (complex(0,0), complex(1000,-1000), complex(2000,-2000), - complex(3000,-3000), complex(4000,-4000), complex(5000,-5000)) - expected_result = (complex(0,0), complex(125,-125), complex(250,-250), - complex(484.375,-484.375), complex(718.75,-718.75), - complex(1048.828125,-1048.828125)) + src_data = (complex(0, 0), complex(1000, - + 1000), complex(2000, - + 2000), complex(3000, - + 3000), complex(4000, - + 4000), complex(5000, - + 5000)) + expected_result = (complex(0, 0), complex(125, - + 125), complex(250, - + 250), complex(484.375, - + 484.375), complex(718.75, - + 718.75), complex(1048.828125, - + 1048.828125)) src = blocks.vector_source_c(src_data) s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, block_size) op = filter.single_pole_iir_filter_cc(0.125, block_size) @@ -97,6 +124,6 @@ class test_single_pole_iir_filter(gr_unittest.TestCase): result_data = dst.data() self.assertComplexTuplesAlmostEqual(expected_result, result_data, 3) + if __name__ == '__main__': gr_unittest.run(test_single_pole_iir_filter) - diff --git a/gr-qtgui/python/qtgui/qa_qtgui.py b/gr-qtgui/python/qtgui/qa_qtgui.py index 7e1d65f010..d33884d3b4 100644 --- a/gr-qtgui/python/qtgui/qa_qtgui.py +++ b/gr-qtgui/python/qtgui/qa_qtgui.py @@ -11,12 +11,13 @@ from gnuradio import gr, gr_unittest, qtgui + class test_qtgui(gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None # Tests to make sure we can instantiate the sink. @@ -77,5 +78,6 @@ class test_qtgui(gr_unittest.TestCase): def test14(self): self.qtsnk = qtgui.eye_sink_c(1024, 1, 1, None) + if __name__ == '__main__': gr_unittest.run(test_qtgui) diff --git a/gr-trellis/python/trellis/qa_trellis.py b/gr-trellis/python/trellis/qa_trellis.py index fcd2f2d871..d020d1a86e 100644 --- a/gr-trellis/python/trellis/qa_trellis.py +++ b/gr-trellis/python/trellis/qa_trellis.py @@ -17,7 +17,7 @@ from gnuradio import gr, gr_unittest, trellis, digital, analog, blocks fsm_args = {"awgn1o2_4": [2, 4, 4, [0, 2, 0, 2, 1, 3, 1, 3], [0, 3, 3, 0, 1, 2, 2, 1], - ], + ], "rep2": [2, 1, 4, [0, 0], [0, 3]], "nothing": [2, 1, 2, [0, 0], [0, 1]], } @@ -26,21 +26,25 @@ constells = {2: digital.constellation_bpsk(), 4: digital.constellation_qpsk(), } + class test_trellis (gr_unittest.TestCase): - def test_001_fsm (self): + def test_001_fsm(self): f = trellis.fsm(*fsm_args["awgn1o2_4"]) - self.assertEqual(fsm_args["awgn1o2_4"],[f.I(),f.S(),f.O(),f.NS(),f.OS()]) + self.assertEqual( + fsm_args["awgn1o2_4"], [ + f.I(), f.S(), f.O(), f.NS(), f.OS()]) - def test_002_fsm (self): + def test_002_fsm(self): f = trellis.fsm(*fsm_args["awgn1o2_4"]) g = trellis.fsm(f) - self.assertEqual((g.I(),g.S(),g.O(),g.NS(),g.OS()),(f.I(),f.S(),f.O(),f.NS(),f.OS())) + self.assertEqual((g.I(), g.S(), g.O(), g.NS(), g.OS()), + (f.I(), f.S(), f.O(), f.NS(), f.OS())) - def test_003_fsm (self): + def test_003_fsm(self): # FIXME: no file "awgn1o2_4.fsm" #f = trellis.fsm("awgn1o2_4.fsm") - #self.assertEqual(fsm_args["awgn1o2_4"],(f.I(),f.S(),f.O(),f.NS(),f.OS())) + # self.assertEqual(fsm_args["awgn1o2_4"],(f.I(),f.S(),f.O(),f.NS(),f.OS())) pass def test_004_fsm(self): @@ -48,12 +52,12 @@ class test_trellis (gr_unittest.TestCase): # Just checking that it initializes properly. f = trellis.fsm(*fsm_args["rep2"]) - def test_001_interleaver (self): + def test_001_interleaver(self): K = 5 - IN = [1,2,3,4,0] - DIN = [4,0,1,2,3] - i = trellis.interleaver(K,IN) - self.assertEqual((K,IN,DIN),(i.K(),i.INTER(),i.DEINTER())) + IN = [1, 2, 3, 4, 0] + DIN = [4, 0, 1, 2, 3] + i = trellis.interleaver(K, IN) + self.assertEqual((K, IN, DIN), (i.K(), i.INTER(), i.DEINTER())) def test_001_viterbi(self): """ @@ -74,6 +78,7 @@ class trellis_tb(gr.top_block): """ A simple top block for use testing gr-trellis. """ + def __init__(self, constellation, f, N0=0.25, seed=-666): """ constellation - a constellation object used for modulation. @@ -82,10 +87,12 @@ class trellis_tb(gr.top_block): seed - random seed """ super(trellis_tb, self).__init__() - # packet size in bits (make it multiple of 16 so it can be packed in a short) - packet_size = 1024*16 + # packet size in bits (make it multiple of 16 so it can be packed in a + # short) + packet_size = 1024 * 16 + # bits per FSM input symbol # bits per FSM input symbol - bitspersymbol = int(round(math.log(f.I()) / math.log(2))) # bits per FSM input symbol + bitspersymbol = int(round(math.log(f.I()) / math.log(2))) # packet size in trellis steps K = packet_size // bitspersymbol @@ -101,11 +108,14 @@ class trellis_tb(gr.top_block): # CHANNEL add = blocks.add_cc() - noise = analog.noise_source_c(analog.GR_GAUSSIAN,math.sqrt(N0 / 2),seed) + noise = analog.noise_source_c( + analog.GR_GAUSSIAN, math.sqrt( + N0 / 2), seed) # RX # data preprocessing to generate metrics for Viterbi - metrics = trellis.constellation_metrics_cf(constellation.base(), digital.TRELLIS_EUCLIDEAN) + metrics = trellis.constellation_metrics_cf( + constellation.base(), digital.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set. va = trellis.viterbi_s(f, K, 0, -1) # pack FSM input symbols to shorts @@ -113,10 +123,10 @@ class trellis_tb(gr.top_block): # check the output self.dst = blocks.check_lfsr_32k_s() - self.connect (src, src_head, s2fsmi, enc, mod) - self.connect (mod, (add, 0)) - self.connect (noise, (add, 1)) - self.connect (add, metrics, va, fsmi2s, self.dst) + self.connect(src, src_head, s2fsmi, enc, mod) + self.connect(mod, (add, 0)) + self.connect(noise, (add, 1)) + self.connect(add, metrics, va, fsmi2s, self.dst) if __name__ == '__main__': diff --git a/gr-uhd/python/uhd/qa_uhd.py b/gr-uhd/python/uhd/qa_uhd.py index 0c9eee7a67..d87ab77c42 100644 --- a/gr-uhd/python/uhd/qa_uhd.py +++ b/gr-uhd/python/uhd/qa_uhd.py @@ -11,6 +11,7 @@ from gnuradio import gr, gr_unittest, uhd + class test_uhd(gr_unittest.TestCase): def setUp(self): @@ -19,18 +20,18 @@ class test_uhd(gr_unittest.TestCase): def tearDown(self): self.tb = None - def test_000_nop (self): + def test_000_nop(self): """Just see if we can import the module... They may not have a UHD device connected, etc. Don't try to run anything""" pass - def test_time_spec_t (self): + def test_time_spec_t(self): seconds = 42.0 time = uhd.time_spec_t(seconds) - twice_time = time + time; - zero_time = time - time; - self.assertEqual(time.get_real_secs() * 2, seconds * 2 ) - self.assertEqual(time.get_real_secs() - time.get_real_secs() , 0.0) + twice_time = time + time + zero_time = time - time + self.assertEqual(time.get_real_secs() * 2, seconds * 2) + self.assertEqual(time.get_real_secs() - time.get_real_secs(), 0.0) def test_stream_args_channel_foo(self): """ @@ -46,5 +47,6 @@ class test_uhd(gr_unittest.TestCase): self.assertEqual(sa.channels[0], 1) self.assertEqual(sa.channels[1], 0) + if __name__ == '__main__': gr_unittest.run(test_uhd) diff --git a/gr-video-sdl/python/video_sdl/qa_video_sdl.py b/gr-video-sdl/python/video_sdl/qa_video_sdl.py index bb9504c4cd..3127c8f834 100644 --- a/gr-video-sdl/python/video_sdl/qa_video_sdl.py +++ b/gr-video-sdl/python/video_sdl/qa_video_sdl.py @@ -11,18 +11,20 @@ from gnuradio import gr, gr_unittest, video_sdl + class test_video_sdl (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_000_nop (self): + def test_000_nop(self): """Just see if we can import the module... They may not have video drivers, etc. Don't try to run anything""" pass + if __name__ == '__main__': gr_unittest.run(test_video_sdl) diff --git a/gr-vocoder/python/vocoder/qa_alaw_vocoder.py b/gr-vocoder/python/vocoder/qa_alaw_vocoder.py index 4c04184ccf..221e097684 100644 --- a/gr-vocoder/python/vocoder/qa_alaw_vocoder.py +++ b/gr-vocoder/python/vocoder/qa_alaw_vocoder.py @@ -11,17 +11,18 @@ from gnuradio import gr, gr_unittest, vocoder, blocks + class test_alaw_vocoder (gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test001_module_load (self): - data = (8,24,40,56,72,88,104,120,136,152,168,184, - 200,216,232,248,264,280,296,312,328,344) + def test001_module_load(self): + data = (8, 24, 40, 56, 72, 88, 104, 120, 136, 152, 168, 184, + 200, 216, 232, 248, 264, 280, 296, 312, 328, 344) src = blocks.vector_source_s(data) enc = vocoder.alaw_encode_sb() dec = vocoder.alaw_decode_bs() diff --git a/gr-vocoder/python/vocoder/qa_codec2_vocoder.py b/gr-vocoder/python/vocoder/qa_codec2_vocoder.py index 19c0917d12..8048b3828e 100644 --- a/gr-vocoder/python/vocoder/qa_codec2_vocoder.py +++ b/gr-vocoder/python/vocoder/qa_codec2_vocoder.py @@ -12,12 +12,13 @@ from gnuradio import gr, gr_unittest, vocoder, blocks from gnuradio.vocoder import codec2 + class test_codec2_vocoder (gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None def test001_mode_2400_encoder(self): @@ -26,12 +27,12 @@ class test_codec2_vocoder (gr_unittest.TestCase): # to 2400 bit/s enc = vocoder.codec2_encode_sp(codec2.MODE_2400) samples_per_frame = enc.relative_rate_d() - data = samples_per_frame*(100,200,300,400,500,600,700,800) + data = samples_per_frame * (100, 200, 300, 400, 500, 600, 700, 800) src = blocks.vector_source_s(data) snk = blocks.vector_sink_b(vlen=48) - expected_length = ((len(data) * 16)*2400)//128000 - self.tb.connect(src,enc,snk) + expected_length = ((len(data) * 16) * 2400) // 128000 + self.tb.connect(src, enc, snk) self.tb.run() result = snk.data() self.assertEqual(expected_length, len(result)) @@ -40,12 +41,12 @@ class test_codec2_vocoder (gr_unittest.TestCase): enc = vocoder.codec2_encode_sp(codec2.MODE_1600) samples_per_frame = enc.relative_rate_d() bits_per_frame = enc.output_signature().sizeof_stream_item(0) - data = samples_per_frame*(100,200,300,400,500,600,700,800) + data = samples_per_frame * (100, 200, 300, 400, 500, 600, 700, 800) src = blocks.vector_source_s(data) snk = blocks.vector_sink_b(vlen=bits_per_frame) - expected_length = ((len(data) * 16)*1600)//128000 - self.tb.connect(src,enc,snk) + expected_length = ((len(data) * 16) * 1600) // 128000 + self.tb.connect(src, enc, snk) self.tb.run() result = snk.data() self.assertEqual(expected_length, len(result)) @@ -54,15 +55,16 @@ class test_codec2_vocoder (gr_unittest.TestCase): enc = vocoder.codec2_encode_sp(codec2.MODE_1400) samples_per_frame = enc.relative_rate_d() bits_per_frame = enc.output_signature().sizeof_stream_item(0) - data = samples_per_frame*(100,200,300,400,500,600,700,800) + data = samples_per_frame * (100, 200, 300, 400, 500, 600, 700, 800) src = blocks.vector_source_s(data) snk = blocks.vector_sink_b(vlen=bits_per_frame) - expected_length = ((len(data) * 16)*1400)//128000 - self.tb.connect(src,enc,snk) + expected_length = ((len(data) * 16) * 1400) // 128000 + self.tb.connect(src, enc, snk) self.tb.run() result = snk.data() self.assertEqual(expected_length, len(result)) + if __name__ == '__main__': gr_unittest.run(test_codec2_vocoder) diff --git a/gr-vocoder/python/vocoder/qa_cvsd_vocoder.py b/gr-vocoder/python/vocoder/qa_cvsd_vocoder.py index c70eb9682d..de5ac9f999 100644 --- a/gr-vocoder/python/vocoder/qa_cvsd_vocoder.py +++ b/gr-vocoder/python/vocoder/qa_cvsd_vocoder.py @@ -12,21 +12,21 @@ from gnuradio import gr, gr_unittest, vocoder, blocks, filter from gnuradio.vocoder import cvsd + class test_cvsd_vocoder (gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test001_module_load (self): + def test001_module_load(self): raw_enc = vocoder.cvsd_encode_sb() raw_dec = vocoder.cvsd_decode_bs() hb_enc = cvsd.cvsd_encode_fb() hb_dec = cvsd.cvsd_decode_bf() - """ Disable for now def test01(self): sample_rate = 8000 @@ -109,5 +109,6 @@ class test_cvsd_vocoder (gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual (expected_data, sink.data(), 5) """ + if __name__ == '__main__': gr_unittest.run(test_cvsd_vocoder) diff --git a/gr-vocoder/python/vocoder/qa_g721_vocoder.py b/gr-vocoder/python/vocoder/qa_g721_vocoder.py index 307275a464..e18f920cfe 100644 --- a/gr-vocoder/python/vocoder/qa_g721_vocoder.py +++ b/gr-vocoder/python/vocoder/qa_g721_vocoder.py @@ -11,17 +11,18 @@ from gnuradio import gr, gr_unittest, vocoder, blocks + class test_g721_vocoder (gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test001_module_load (self): - data = (8,24,36,52,56,64,76,88,104,124,132,148,172, - 196,220,244,280,320,372,416,468,524,580,648) + def test001_module_load(self): + data = (8, 24, 36, 52, 56, 64, 76, 88, 104, 124, 132, 148, 172, + 196, 220, 244, 280, 320, 372, 416, 468, 524, 580, 648) src = blocks.vector_source_s(data) enc = vocoder.g721_encode_sb() dec = vocoder.g721_decode_bs() @@ -31,5 +32,6 @@ class test_g721_vocoder (gr_unittest.TestCase): actual_result = snk.data() self.assertEqual(list(data), actual_result) + if __name__ == '__main__': gr_unittest.run(test_g721_vocoder) diff --git a/gr-vocoder/python/vocoder/qa_g723_24_vocoder.py b/gr-vocoder/python/vocoder/qa_g723_24_vocoder.py index 4be87fdd80..a8f081e103 100644 --- a/gr-vocoder/python/vocoder/qa_g723_24_vocoder.py +++ b/gr-vocoder/python/vocoder/qa_g723_24_vocoder.py @@ -11,16 +11,17 @@ from gnuradio import gr, gr_unittest, vocoder, blocks + class test_g723_24_vocoder (gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test001_module_load (self): - data = (0,16,36,40,68,104,148,220,320,512) + def test001_module_load(self): + data = (0, 16, 36, 40, 68, 104, 148, 220, 320, 512) src = blocks.vector_source_s(data) enc = vocoder.g723_24_encode_sb() dec = vocoder.g723_24_decode_bs() @@ -30,5 +31,6 @@ class test_g723_24_vocoder (gr_unittest.TestCase): actual_result = snk.data() self.assertEqual(list(data), actual_result) + if __name__ == '__main__': gr_unittest.run(test_g723_24_vocoder) diff --git a/gr-vocoder/python/vocoder/qa_g723_40_vocoder.py b/gr-vocoder/python/vocoder/qa_g723_40_vocoder.py index 6a6b42169e..621d2ebf99 100644 --- a/gr-vocoder/python/vocoder/qa_g723_40_vocoder.py +++ b/gr-vocoder/python/vocoder/qa_g723_40_vocoder.py @@ -11,16 +11,17 @@ from gnuradio import gr, gr_unittest, vocoder, blocks + class test_g723_40_vocoder (gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test001_module_load (self): - data = (0,8,36,72,100,152,228,316,404,528) + def test001_module_load(self): + data = (0, 8, 36, 72, 100, 152, 228, 316, 404, 528) src = blocks.vector_source_s(data) enc = vocoder.g723_40_encode_sb() dec = vocoder.g723_40_decode_bs() @@ -30,5 +31,6 @@ class test_g723_40_vocoder (gr_unittest.TestCase): actual_result = snk.data() self.assertEqual(list(data), actual_result) + if __name__ == '__main__': gr_unittest.run(test_g723_40_vocoder) diff --git a/gr-vocoder/python/vocoder/qa_gsm_full_rate.py b/gr-vocoder/python/vocoder/qa_gsm_full_rate.py index c29cb2ad9d..0c4cd046ea 100644 --- a/gr-vocoder/python/vocoder/qa_gsm_full_rate.py +++ b/gr-vocoder/python/vocoder/qa_gsm_full_rate.py @@ -11,30 +11,31 @@ from gnuradio import gr, gr_unittest, vocoder, blocks + class test_gsm_vocoder (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test001_module_load (self): - data = 20*(100,200,300,400,500,600,700,800) - expected_data = [0,0,360,304,256,720,600,504,200,144,128,464, - 376,384,680,576,440,264,176,176,640,520,480, - 464,384,288,432,296,328,760,624,504,176,96,96, - 416,312,360,808,672,216,104,136,504,376,448, - 720,608,296,304,176,336,576,456,560,512,320, - 216,344,264,456,672,576,488,192,80,152,424, - 368,552,688,560,280,200,104,256,520,464,608, - 488,184,104,16,472,456,360,696,568,208,136,88, - 376,480,456,616,472,232,224,264,320,512,624, - 632,520,176,80,192,304,400,592,664,552,248,152, - 144,336,440,520,616,664,304,176,80,536,448,376, - 680,600,240,168,112,408,488,472,608,480,240,232, - 208,288,480,600,616,520,176,88,184,296,392,584, - 656,552,248,160,144,336,432,512,608,664] + def test001_module_load(self): + data = 20 * (100, 200, 300, 400, 500, 600, 700, 800) + expected_data = [0, 0, 360, 304, 256, 720, 600, 504, 200, 144, 128, 464, + 376, 384, 680, 576, 440, 264, 176, 176, 640, 520, 480, + 464, 384, 288, 432, 296, 328, 760, 624, 504, 176, 96, 96, + 416, 312, 360, 808, 672, 216, 104, 136, 504, 376, 448, + 720, 608, 296, 304, 176, 336, 576, 456, 560, 512, 320, + 216, 344, 264, 456, 672, 576, 488, 192, 80, 152, 424, + 368, 552, 688, 560, 280, 200, 104, 256, 520, 464, 608, + 488, 184, 104, 16, 472, 456, 360, 696, 568, 208, 136, 88, + 376, 480, 456, 616, 472, 232, 224, 264, 320, 512, 624, + 632, 520, 176, 80, 192, 304, 400, 592, 664, 552, 248, 152, + 144, 336, 440, 520, 616, 664, 304, 176, 80, 536, 448, 376, + 680, 600, 240, 168, 112, 408, 488, 472, 608, 480, 240, 232, + 208, 288, 480, 600, 616, 520, 176, 88, 184, 296, 392, 584, + 656, 552, 248, 160, 144, 336, 432, 512, 608, 664] src = blocks.vector_source_s(data) enc = vocoder.gsm_fr_encode_sp() dec = vocoder.gsm_fr_decode_ps() @@ -44,5 +45,6 @@ class test_gsm_vocoder (gr_unittest.TestCase): actual_result = snk.data() self.assertEqual(expected_data, actual_result) + if __name__ == '__main__': gr_unittest.run(test_gsm_vocoder) diff --git a/gr-vocoder/python/vocoder/qa_ulaw_vocoder.py b/gr-vocoder/python/vocoder/qa_ulaw_vocoder.py index ceaafb2931..151ad4bfb7 100644 --- a/gr-vocoder/python/vocoder/qa_ulaw_vocoder.py +++ b/gr-vocoder/python/vocoder/qa_ulaw_vocoder.py @@ -11,17 +11,18 @@ from gnuradio import gr, gr_unittest, vocoder, blocks + class test_ulaw_vocoder (gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test001_module_load (self): - data = (8,24,40,56,72,88,104,120,132,148,164,180, - 196,212,228,244,260,276,292,308,324,340) + def test001_module_load(self): + data = (8, 24, 40, 56, 72, 88, 104, 120, 132, 148, 164, 180, + 196, 212, 228, 244, 260, 276, 292, 308, 324, 340) src = blocks.vector_source_s(data) enc = vocoder.ulaw_encode_sb() dec = vocoder.ulaw_decode_bs() @@ -31,5 +32,6 @@ class test_ulaw_vocoder (gr_unittest.TestCase): actual_result = snk.data() self.assertEqual(list(data), actual_result) + if __name__ == '__main__': gr_unittest.run(test_ulaw_vocoder) diff --git a/gr-wavelet/python/wavelet/qa_classify.py b/gr-wavelet/python/wavelet/qa_classify.py index e2c2ad03d4..6bb83c5c84 100644 --- a/gr-wavelet/python/wavelet/qa_classify.py +++ b/gr-wavelet/python/wavelet/qa_classify.py @@ -12,11 +12,13 @@ import numpy from gnuradio import gr, gr_unittest, wavelet, analog, blocks import copy -#import pygsl.wavelet as wavelet # FIXME: pygsl not checked for in config +# import pygsl.wavelet as wavelet # FIXME: pygsl not checked for in config import math + def sqr(x): - return x*x + return x * x + def np2(k): m = 0 @@ -147,8 +149,8 @@ class test_classify(gr_unittest.TestCase): scl = 1.0 / sqr(dwav[0]) k = 1 for e in range(len(wvps)): - wvps[e] = scl*sqr(dwav[k:k+(0o1<<e)]).sum() - k += 0o1<<e + wvps[e] = scl * sqr(dwav[k:k + (0o1 << e)]).sum() + k += 0o1 << e src = blocks.vector_source_f(src_data, False, len(src_data)) kon = wavelet.wvps_ff(len(src_data)) @@ -161,11 +163,12 @@ class test_classify(gr_unittest.TestCase): snk_data = dst.data() sum = 0 - for (u,v) in zip(snk_data, wvps): + for (u, v) in zip(snk_data, wvps): w = u - v sum += w * w sum /= float(len(snk_data)) assert sum < 1e-6 + if __name__ == '__main__': - gr_unittest.run(test_classify) + gr_unittest.run(test_classify) diff --git a/gr-zeromq/python/zeromq/qa_zeromq_pub.py b/gr-zeromq/python/zeromq/qa_zeromq_pub.py index 5b40426f8f..2c324b102c 100644 --- a/gr-zeromq/python/zeromq/qa_zeromq_pub.py +++ b/gr-zeromq/python/zeromq/qa_zeromq_pub.py @@ -15,20 +15,22 @@ from gnuradio import blocks, zeromq from gnuradio import eng_notation import threading + class qa_zeromq_pub (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.tb = None - def test_001 (self): + def test_001(self): vlen = 10 self.rx_data = None - src_data = list(range(vlen))*100 + src_data = list(range(vlen)) * 100 src = blocks.vector_source_f(src_data, False, vlen) - zeromq_pub_sink = zeromq.pub_sink(gr.sizeof_float, vlen, "tcp://127.0.0.1:0") + zeromq_pub_sink = zeromq.pub_sink( + gr.sizeof_float, vlen, "tcp://127.0.0.1:0") address = zeromq_pub_sink.last_endpoint() self.tb.connect(src, zeromq_pub_sink) self.probe_manager = zeromq.probe_manager() @@ -42,7 +44,7 @@ class qa_zeromq_pub (gr_unittest.TestCase): self.assertFalse(zmq_pull_t.is_alive()) self.assertFloatTuplesAlmostEqual(self.rx_data, src_data) - def recv_data (self, data): + def recv_data(self, data): self.rx_data = data diff --git a/gr-zeromq/python/zeromq/qa_zeromq_pubsub.py b/gr-zeromq/python/zeromq/qa_zeromq_pubsub.py index 44a936ec46..caacdbc5e4 100644 --- a/gr-zeromq/python/zeromq/qa_zeromq_pubsub.py +++ b/gr-zeromq/python/zeromq/qa_zeromq_pubsub.py @@ -15,6 +15,7 @@ from gnuradio import blocks, zeromq import pmt import time + def make_tag(key, value, offset, srcid=None): tag = gr.tag_t() tag.key = pmt.string_to_symbol(key) @@ -24,27 +25,31 @@ def make_tag(key, value, offset, srcid=None): tag.srcid = pmt.to_pmt(srcid) return tag + def compare_tags(a, b): return a.offset == b.offset and pmt.equal(a.key, b.key) and \ - pmt.equal(a.value, b.value) and pmt.equal(a.srcid, b.srcid) + pmt.equal(a.value, b.value) and pmt.equal(a.srcid, b.srcid) + class qa_zeromq_pubsub (gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.send_tb = gr.top_block() self.recv_tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.send_tb = None self.recv_tb = None - def test_001 (self): + def test_001(self): vlen = 10 - src_data = list(range(vlen))*100 + src_data = list(range(vlen)) * 100 src = blocks.vector_source_f(src_data, False, vlen) - zeromq_pub_sink = zeromq.pub_sink(gr.sizeof_float, vlen, "tcp://127.0.0.1:0", 0) + zeromq_pub_sink = zeromq.pub_sink( + gr.sizeof_float, vlen, "tcp://127.0.0.1:0", 0) address = zeromq_pub_sink.last_endpoint() - zeromq_sub_source = zeromq.sub_source(gr.sizeof_float, vlen, address, 0) + zeromq_sub_source = zeromq.sub_source( + gr.sizeof_float, vlen, address, 0) sink = blocks.vector_sink_f(vlen) self.send_tb.connect(src, zeromq_pub_sink) self.recv_tb.connect(zeromq_sub_source, sink) @@ -58,17 +63,25 @@ class qa_zeromq_pubsub (gr_unittest.TestCase): self.send_tb.wait() self.assertFloatTuplesAlmostEqual(sink.data(), src_data) - def test_002 (self): + def test_002(self): # same as test_001, but insert a tag and set key filter vlen = 10 - src_data = list(range(vlen))*100 + src_data = list(range(vlen)) * 100 - src_tags = tuple([make_tag('key', 'val', 0, 'src'), make_tag('key', 'val', 1, 'src')]) + src_tags = tuple([make_tag('key', 'val', 0, 'src'), + make_tag('key', 'val', 1, 'src')]) src = blocks.vector_source_f(src_data, False, vlen, tags=src_tags) - zeromq_pub_sink = zeromq.pub_sink(gr.sizeof_float, vlen, "tcp://127.0.0.1:0", 0, pass_tags=True, key="filter_key") + zeromq_pub_sink = zeromq.pub_sink( + gr.sizeof_float, + vlen, + "tcp://127.0.0.1:0", + 0, + pass_tags=True, + key="filter_key") address = zeromq_pub_sink.last_endpoint() - zeromq_sub_source = zeromq.sub_source(gr.sizeof_float, vlen, address, 0, pass_tags=True, key="filter_key") + zeromq_sub_source = zeromq.sub_source( + gr.sizeof_float, vlen, address, 0, pass_tags=True, key="filter_key") sink = blocks.vector_sink_f(vlen) self.send_tb.connect(src, zeromq_pub_sink) self.recv_tb.connect(zeromq_sub_source, sink) @@ -93,5 +106,6 @@ class qa_zeromq_pubsub (gr_unittest.TestCase): for in_tag, out_tag in zip(src_tags, rx_tags): self.assertTrue(compare_tags(in_tag, out_tag)) + if __name__ == '__main__': gr_unittest.run(qa_zeromq_pubsub) diff --git a/gr-zeromq/python/zeromq/qa_zeromq_pull_msg_source.py b/gr-zeromq/python/zeromq/qa_zeromq_pull_msg_source.py index 4ffc90800f..0a2e541acf 100644 --- a/gr-zeromq/python/zeromq/qa_zeromq_pull_msg_source.py +++ b/gr-zeromq/python/zeromq/qa_zeromq_pull_msg_source.py @@ -15,6 +15,7 @@ import zmq from gnuradio import gr, gr_unittest, blocks, zeromq import pmt + class qa_zeromq_pull_msg_source(gr_unittest.TestCase): """Unit tests for ZMQ PULL Message Source block""" @@ -24,10 +25,12 @@ class qa_zeromq_pull_msg_source(gr_unittest.TestCase): self.zmq_sock = self.context.socket(zmq.PUSH) port = self.zmq_sock.bind_to_random_port(addr) - self.zeromq_pull_msg_source = zeromq.pull_msg_source(('%s:%s' % (addr, port)), 100) + self.zeromq_pull_msg_source = zeromq.pull_msg_source( + ('%s:%s' % (addr, port)), 100) self.message_debug = blocks.message_debug() self.tb = gr.top_block() - self.tb.msg_connect((self.zeromq_pull_msg_source, 'out'), (self.message_debug, 'store')) + self.tb.msg_connect( + (self.zeromq_pull_msg_source, 'out'), (self.message_debug, 'store')) self.tb.start() time.sleep(0.1) @@ -57,5 +60,6 @@ class qa_zeromq_pull_msg_source(gr_unittest.TestCase): time.sleep(0.1) self.assertEqual(0, self.message_debug.num_messages()) + if __name__ == '__main__': gr_unittest.run(qa_zeromq_pull_msg_source) diff --git a/gr-zeromq/python/zeromq/qa_zeromq_pushpull.py b/gr-zeromq/python/zeromq/qa_zeromq_pushpull.py index e99a06e1a6..9ffc8cdfa5 100644 --- a/gr-zeromq/python/zeromq/qa_zeromq_pushpull.py +++ b/gr-zeromq/python/zeromq/qa_zeromq_pushpull.py @@ -12,23 +12,26 @@ from gnuradio import gr, gr_unittest, blocks, zeromq import time + class qa_zeromq_pushpull (gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.send_tb = gr.top_block() self.recv_tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.send_tb = None self.recv_tb = None - def test_001 (self): + def test_001(self): vlen = 10 - src_data = list(range(vlen))*100 + src_data = list(range(vlen)) * 100 src = blocks.vector_source_f(src_data, False, vlen) - zeromq_push_sink = zeromq.push_sink(gr.sizeof_float, vlen, "tcp://127.0.0.1:0") + zeromq_push_sink = zeromq.push_sink( + gr.sizeof_float, vlen, "tcp://127.0.0.1:0") address = zeromq_push_sink.last_endpoint() - zeromq_pull_source = zeromq.pull_source(gr.sizeof_float, vlen, address, 0) + zeromq_pull_source = zeromq.pull_source( + gr.sizeof_float, vlen, address, 0) sink = blocks.vector_sink_f(vlen) self.send_tb.connect(src, zeromq_push_sink) self.recv_tb.connect(zeromq_pull_source, sink) @@ -42,5 +45,6 @@ class qa_zeromq_pushpull (gr_unittest.TestCase): self.send_tb.wait() self.assertFloatTuplesAlmostEqual(sink.data(), src_data) + if __name__ == '__main__': gr_unittest.run(qa_zeromq_pushpull) diff --git a/gr-zeromq/python/zeromq/qa_zeromq_req_msg_source.py b/gr-zeromq/python/zeromq/qa_zeromq_req_msg_source.py index af075e6b38..61759c289b 100644 --- a/gr-zeromq/python/zeromq/qa_zeromq_req_msg_source.py +++ b/gr-zeromq/python/zeromq/qa_zeromq_req_msg_source.py @@ -16,6 +16,7 @@ import zmq from gnuradio import gr, gr_unittest, blocks, zeromq import pmt + class qa_zeromq_req_msg_source(gr_unittest.TestCase): """Unit tests for ZMQ REQ Message Source block""" @@ -25,10 +26,12 @@ class qa_zeromq_req_msg_source(gr_unittest.TestCase): self.zmq_sock = self.context.socket(zmq.REP) port = self.zmq_sock.bind_to_random_port(addr) - self.zeromq_req_msg_source = zeromq.req_msg_source(('%s:%s' % (addr, port)), 100) + self.zeromq_req_msg_source = zeromq.req_msg_source( + ('%s:%s' % (addr, port)), 100) self.message_debug = blocks.message_debug() self.tb = gr.top_block() - self.tb.msg_connect((self.zeromq_req_msg_source, 'out'), (self.message_debug, 'store')) + self.tb.msg_connect( + (self.zeromq_req_msg_source, 'out'), (self.message_debug, 'store')) self.tb.start() @@ -72,17 +75,22 @@ class qa_zeromq_req_msg_source(gr_unittest.TestCase): time.sleep(0.1) self.assertEqual(len(msgs), self.message_debug.num_messages()) for index, msg in enumerate(msgs): - self.assertTrue(pmt.equal(msg, self.message_debug.get_message(index))) + self.assertTrue( + pmt.equal( + msg, + self.message_debug.get_message(index))) def test_invalid_pmt(self): """Test receiving of invalid PMT messages""" self.recv_request() - #Do not use pmt.serialize_str here as we don't want a valid PMT message + # Do not use pmt.serialize_str here as we don't want a valid PMT + # message self.zmq_sock.send_string('test_invalid_pmt') time.sleep(0.1) self.assertEqual(0, self.message_debug.num_messages()) + if __name__ == '__main__': gr_unittest.run(qa_zeromq_req_msg_source) diff --git a/gr-zeromq/python/zeromq/qa_zeromq_reqrep.py b/gr-zeromq/python/zeromq/qa_zeromq_reqrep.py index 8e5e8b5f94..703102e124 100644 --- a/gr-zeromq/python/zeromq/qa_zeromq_reqrep.py +++ b/gr-zeromq/python/zeromq/qa_zeromq_reqrep.py @@ -15,23 +15,26 @@ from gnuradio import blocks, zeromq from gnuradio import eng_notation import time + class qa_zeromq_reqrep (gr_unittest.TestCase): - def setUp (self): + def setUp(self): self.send_tb = gr.top_block() self.recv_tb = gr.top_block() - def tearDown (self): + def tearDown(self): self.send_tb = None self.recv_tb = None - def test_001 (self): + def test_001(self): vlen = 10 - src_data = list(range(vlen))*100 + src_data = list(range(vlen)) * 100 src = blocks.vector_source_f(src_data, False, vlen) - zeromq_rep_sink = zeromq.rep_sink(gr.sizeof_float, vlen, "tcp://127.0.0.1:0", 0) + zeromq_rep_sink = zeromq.rep_sink( + gr.sizeof_float, vlen, "tcp://127.0.0.1:0", 0) address = zeromq_rep_sink.last_endpoint() - zeromq_req_source = zeromq.req_source(gr.sizeof_float, vlen, address, 0) + zeromq_req_source = zeromq.req_source( + gr.sizeof_float, vlen, address, 0) sink = blocks.vector_sink_f(vlen) self.send_tb.connect(src, zeromq_rep_sink) self.recv_tb.connect(zeromq_req_source, sink) @@ -45,5 +48,6 @@ class qa_zeromq_reqrep (gr_unittest.TestCase): self.send_tb.wait() self.assertFloatTuplesAlmostEqual(sink.data(), src_data) + if __name__ == '__main__': gr_unittest.run(qa_zeromq_reqrep) diff --git a/gr-zeromq/python/zeromq/qa_zeromq_sub.py b/gr-zeromq/python/zeromq/qa_zeromq_sub.py index 9e82420c24..ba08c92464 100755 --- a/gr-zeromq/python/zeromq/qa_zeromq_sub.py +++ b/gr-zeromq/python/zeromq/qa_zeromq_sub.py @@ -17,24 +17,26 @@ import numpy import time import zmq + class qa_zeromq_sub (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() self.zmq_context = zmq.Context() self.pub_socket = self.zmq_context.socket(zmq.PUB) self.pub_socket.bind("tcp://127.0.0.1:0") self._address = self.pub_socket.getsockopt(zmq.LAST_ENDPOINT).decode() - def tearDown (self): + def tearDown(self): self.pub_socket.close() self.zmq_context.term() self.tb = None - def test_001 (self): + def test_001(self): vlen = 10 - src_data = numpy.array(list(range(vlen))*100, 'float32') - zeromq_sub_source = zeromq.sub_source(gr.sizeof_float, vlen, self._address) + src_data = numpy.array(list(range(vlen)) * 100, 'float32') + zeromq_sub_source = zeromq.sub_source( + gr.sizeof_float, vlen, self._address) sink = blocks.vector_sink_f(vlen) self.tb.connect(zeromq_sub_source, sink) @@ -46,12 +48,24 @@ class qa_zeromq_sub (gr_unittest.TestCase): self.tb.wait() self.assertFloatTuplesAlmostEqual(sink.data(), src_data) - def test_002 (self): + def test_002(self): vlen = 10 # Construct multipart source data to publish - raw_data = [numpy.array(range(vlen), 'float32')*100, numpy.array(range(vlen, 2*vlen), 'float32')*100] + raw_data = [ + numpy.array( + range(vlen), + 'float32') * + 100, + numpy.array( + range( + vlen, + 2 * + vlen), + 'float32') * + 100] src_data = [a.tostring() for a in raw_data] - zeromq_sub_source = zeromq.sub_source(gr.sizeof_float, vlen, self._address) + zeromq_sub_source = zeromq.sub_source( + gr.sizeof_float, vlen, self._address) sink = blocks.vector_sink_f(vlen) self.tb.connect(zeromq_sub_source, sink) @@ -66,16 +80,28 @@ class qa_zeromq_sub (gr_unittest.TestCase): expected_data = numpy.concatenate(raw_data) self.assertFloatTuplesAlmostEqual(sink.data(), expected_data) - def test_003 (self): + def test_003(self): # Check that message is received when correct key is used # Construct multipart source data to publish vlen = 10 - raw_data = [numpy.array(range(vlen), 'float32')*100, numpy.array(range(vlen, 2*vlen), 'float32')*100] + raw_data = [ + numpy.array( + range(vlen), + 'float32') * + 100, + numpy.array( + range( + vlen, + 2 * + vlen), + 'float32') * + 100] src_data = [a.tostring() for a in raw_data] src_data = [b"filter_key"] + src_data - zeromq_sub_source = zeromq.sub_source(gr.sizeof_float, vlen, self._address, key="filter_key") + zeromq_sub_source = zeromq.sub_source( + gr.sizeof_float, vlen, self._address, key="filter_key") sink = blocks.vector_sink_f(vlen) self.tb.connect(zeromq_sub_source, sink) @@ -90,15 +116,27 @@ class qa_zeromq_sub (gr_unittest.TestCase): expected_data = numpy.concatenate(raw_data) self.assertFloatTuplesAlmostEqual(sink.data(), expected_data) - def test_004 (self): + def test_004(self): # Test that no message is received when wrong key is used vlen = 10 - raw_data = [numpy.array(range(vlen), 'float32')*100, numpy.array(range(vlen, 2*vlen), 'float32')*100] + raw_data = [ + numpy.array( + range(vlen), + 'float32') * + 100, + numpy.array( + range( + vlen, + 2 * + vlen), + 'float32') * + 100] src_data = [a.tostring() for a in raw_data] src_data = [b"filter_key"] + src_data - zeromq_sub_source = zeromq.sub_source(gr.sizeof_float, vlen, self._address, key="wrong_filter_key") + zeromq_sub_source = zeromq.sub_source( + gr.sizeof_float, vlen, self._address, key="wrong_filter_key") sink = blocks.vector_sink_f(vlen) self.tb.connect(zeromq_sub_source, sink) @@ -109,7 +147,8 @@ class qa_zeromq_sub (gr_unittest.TestCase): self.tb.stop() self.tb.wait() - assert( len(sink.data()) == 0 ) + assert(len(sink.data()) == 0) + if __name__ == '__main__': gr_unittest.run(qa_zeromq_sub) diff --git a/gr-zeromq/python/zeromq/qa_zeromq_sub_msg_source.py b/gr-zeromq/python/zeromq/qa_zeromq_sub_msg_source.py index 145483f6ad..3c98396087 100644 --- a/gr-zeromq/python/zeromq/qa_zeromq_sub_msg_source.py +++ b/gr-zeromq/python/zeromq/qa_zeromq_sub_msg_source.py @@ -15,6 +15,7 @@ import zmq from gnuradio import gr, gr_unittest, blocks, zeromq import pmt + class qa_zeromq_sub_msg_source(gr_unittest.TestCase): """Unit tests for ZMQ SUB Message Source block""" @@ -24,10 +25,12 @@ class qa_zeromq_sub_msg_source(gr_unittest.TestCase): self.zmq_sock = self.context.socket(zmq.PUB) port = self.zmq_sock.bind_to_random_port(addr) - self.zeromq_sub_msg_source = zeromq.sub_msg_source(('%s:%s' % (addr, port)), 100) + self.zeromq_sub_msg_source = zeromq.sub_msg_source( + ('%s:%s' % (addr, port)), 100) self.message_debug = blocks.message_debug() self.tb = gr.top_block() - self.tb.msg_connect((self.zeromq_sub_msg_source, 'out'), (self.message_debug, 'store')) + self.tb.msg_connect( + (self.zeromq_sub_msg_source, 'out'), (self.message_debug, 'store')) self.tb.start() time.sleep(0.1) @@ -57,5 +60,6 @@ class qa_zeromq_sub_msg_source(gr_unittest.TestCase): time.sleep(0.1) self.assertEqual(0, self.message_debug.num_messages()) + if __name__ == '__main__': gr_unittest.run(qa_zeromq_sub_msg_source) |