diff options
author | Martin Braun | 2013-02-26 13:44:12 +0100 |
---|---|---|
committer | Martin Braun | 2013-02-26 13:44:12 +0100 |
commit | 7bb8c89e224e7b2c9ddbc5b4f50c79ffb0da2557 (patch) | |
tree | aec6e881cdd825c39a084ce7aa16a87c045a4fae /gr-blocks/python | |
parent | d7766c2c8d12bbfaf29b83cfea5ff95475b45d86 (diff) | |
parent | a54dc5bab6cc38513e9732be9f5c2670145b160f (diff) | |
download | gnuradio-7bb8c89e224e7b2c9ddbc5b4f50c79ffb0da2557.tar.gz gnuradio-7bb8c89e224e7b2c9ddbc5b4f50c79ffb0da2557.tar.bz2 gnuradio-7bb8c89e224e7b2c9ddbc5b4f50c79ffb0da2557.zip |
Merge branch 'master' of git://github.com/gnuradio/gnuradio into grmodtool
Diffstat (limited to 'gr-blocks/python')
-rwxr-xr-x | gr-blocks/python/qa_delay.py | 65 | ||||
-rw-r--r-- | gr-blocks/python/qa_file_metadata.py | 4 | ||||
-rwxr-xr-x | gr-blocks/python/qa_packed_to_unpacked.py | 344 | ||||
-rw-r--r-- | gr-blocks/python/qa_peak_detector2.py | 58 | ||||
-rwxr-xr-x | gr-blocks/python/qa_regenerate.py | 90 | ||||
-rw-r--r-- | gr-blocks/python/qa_rms.py | 83 | ||||
-rwxr-xr-x | gr-blocks/python/qa_stretch.py | 67 | ||||
-rw-r--r-- | gr-blocks/python/qa_threshold.py | 54 | ||||
-rwxr-xr-x | gr-blocks/python/qa_throttle.py | 39 |
9 files changed, 802 insertions, 2 deletions
diff --git a/gr-blocks/python/qa_delay.py b/gr-blocks/python/qa_delay.py new file mode 100755 index 000000000..031cadb2d --- /dev/null +++ b/gr-blocks/python/qa_delay.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,2010,2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_delay(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_000(self): + delta_t = 0 + tb = self.tb + src_data = [float(x) for x in range(0, 100)] + expected_result = tuple(delta_t*[0.0] + src_data) + + src = gr.vector_source_f(src_data) + op = blocks.delay(gr.sizeof_float, delta_t) + dst = gr.vector_sink_f() + + tb.connect(src, op, dst) + tb.run() + dst_data = dst.data() + self.assertEqual(expected_result, dst_data) + + def test_010(self): + delta_t = 10 + tb = self.tb + src_data = [float(x) for x in range(0, 100)] + expected_result = tuple(delta_t*[0.0] + src_data) + + src = gr.vector_source_f(src_data) + op = blocks.delay(gr.sizeof_float, delta_t) + dst = gr.vector_sink_f() + + tb.connect(src, op, dst) + tb.run() + dst_data = dst.data() + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_delay, "test_delay.xml") diff --git a/gr-blocks/python/qa_file_metadata.py b/gr-blocks/python/qa_file_metadata.py index 29ed0d1c8..c7826b1d3 100644 --- a/gr-blocks/python/qa_file_metadata.py +++ b/gr-blocks/python/qa_file_metadata.py @@ -28,8 +28,8 @@ import os, math def sig_source_c(samp_rate, freq, amp, N): t = map(lambda x: float(x)/samp_rate, xrange(N)) - y = map(lambda x: math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x), t) + y = map(lambda x: amp*math.cos(2.*math.pi*freq*x) + \ + 1j*amp*math.sin(2.*math.pi*freq*x), t) return y class test_file_metadata(gr_unittest.TestCase): diff --git a/gr-blocks/python/qa_packed_to_unpacked.py b/gr-blocks/python/qa_packed_to_unpacked.py new file mode 100755 index 000000000..d84f5dbd3 --- /dev/null +++ b/gr-blocks/python/qa_packed_to_unpacked.py @@ -0,0 +1,344 @@ +#!/usr/bin/env python +# +# Copyright 2005,2007,2010,2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks +import random + +class test_packing(gr_unittest.TestCase): + + def setUp(self): + 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 = gr.vector_source_b(src_data, False) + op = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_002(self): + src_data = (0x80,) + expected_results = (0,0,0,0,0,0,0,1) + src = gr.vector_source_b(src_data, False) + op = blocks.packed_to_unpacked_bb(1, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_003(self): + src_data = (0x11,) + expected_results = (4, 2) + src = gr.vector_source_b(src_data, False) + op = blocks.packed_to_unpacked_bb(3, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_004(self): + src_data = (0x11,) + expected_results = (0, 4) + src = gr.vector_source_b(src_data, False) + op = blocks.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + 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) + expected_results = (0x82, 0x5a) + src = gr.vector_source_b(src_data, False) + op = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + 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) + expected_results = (0x82, 0x5a) + src = gr.vector_source_b(src_data, False) + op = blocks.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_007(self): + src_data = (4, 2, 0,0,0) + expected_results = (0x11,) + src = gr.vector_source_b(src_data, False) + op = blocks.unpacked_to_packed_bb(3, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_008(self): + src_data = (0, 4, 2,0,0) + expected_results = (0x11,) + src = gr.vector_source_b(src_data,False) + op = blocks.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_009(self): + random.seed(0) + src_data = [] + for i in xrange(202): + src_data.append((random.randint(0,255))) + src_data = tuple(src_data) + expected_results = src_data + + src = gr.vector_source_b(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results[0:201], dst.data()) + + def test_010(self): + random.seed(0) + src_data = [] + for i in xrange(56): + src_data.append((random.randint(0,255))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_b(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_bb(7, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_bb(7, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results[0:201], dst.data()) + + def test_011(self): + random.seed(0) + src_data = [] + for i in xrange(56): + src_data.append((random.randint(0,255))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.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 = gr.vector_sink_b() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results[0:201], dst.data()) + + + # tests on shorts + def test_100a(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**15,2**15-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_s(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ss(1, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_ss(1, gr.GR_MSB_FIRST) + dst = gr.vector_sink_s() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_100b(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**15,2**15-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_s(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ss(1, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_ss(1, gr.GR_LSB_FIRST) + dst = gr.vector_sink_s() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_101a(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**15,2**15-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_s(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ss(8, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_ss(8, gr.GR_MSB_FIRST) + dst = gr.vector_sink_s() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_101b(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**15,2**15-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_s(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ss(8, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_ss(8, gr.GR_LSB_FIRST) + dst = gr.vector_sink_s() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + + # tests on ints + def test_200a(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**31,2**31-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_i(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ii(1, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_ii(1, gr.GR_MSB_FIRST) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_200b(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**31,2**31-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_i(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ii(1, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_ii(1, gr.GR_LSB_FIRST) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_201a(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**31,2**31-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_i(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ii(8, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_ii(8, gr.GR_MSB_FIRST) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_201b(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**31,2**31-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_i(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ii(8, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_ii(8, gr.GR_LSB_FIRST) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + +if __name__ == '__main__': + gr_unittest.run(test_packing, "test_packing.xml") + diff --git a/gr-blocks/python/qa_peak_detector2.py b/gr-blocks/python/qa_peak_detector2.py new file mode 100644 index 000000000..4b864e4d7 --- /dev/null +++ b/gr-blocks/python/qa_peak_detector2.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# +# Copyright 2007,2010,2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_peak_detector2(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_regen1(self): + tb = self.tb + + data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] + + expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + + src = gr.vector_source_f(data, False) + regen = blocks.peak_detector2_fb() + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + print dst_data + + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_peak_detector2, "test_peak_detector2.xml") diff --git a/gr-blocks/python/qa_regenerate.py b/gr-blocks/python/qa_regenerate.py new file mode 100755 index 000000000..a57eeba2b --- /dev/null +++ b/gr-blocks/python/qa_regenerate.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# +# Copyright 2007,2010,2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_regenerate(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_regen1(self): + tb = self.tb + + data = [0, 0, 0, + 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) + + + src = gr.vector_source_b(data, False) + regen = blocks.regenerate_bb(5, 2) + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + + def test_regen2(self): + tb = self.tb + + 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[99] = 1 + expected_result[109] = 1 + expected_result[119] = 1 + expected_result[129] = 1 + + src = gr.vector_source_b(data, False) + regen = blocks.regenerate_bb(10, 3) + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run () + + dst_data = dst.data() + + self.assertEqual(tuple(expected_result), dst_data) + + +if __name__ == '__main__': + gr_unittest.run(test_regenerate, "test_regenerate.xml") diff --git a/gr-blocks/python/qa_rms.py b/gr-blocks/python/qa_rms.py new file mode 100644 index 000000000..f3386668a --- /dev/null +++ b/gr-blocks/python/qa_rms.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks +import math + +def sig_source_f(samp_rate, freq, amp, N): + t = map(lambda x: float(x)/samp_rate, xrange(N)) + y = map(lambda x: amp*math.cos(2.*math.pi*freq*x), t) + return y + +def sig_source_c(samp_rate, freq, amp, N): + t = map(lambda x: float(x)/samp_rate, xrange(N)) + y = map(lambda x: amp*math.cos(2.*math.pi*freq*x) + \ + 1j*amp*math.sin(2.*math.pi*freq*x), t) + return y + +class test_rms(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_ff(self): + amp = 2 + src_data = sig_source_f(1, 0.01, amp, 200) + N = 750000 + + expected_data = amp/math.sqrt(2.0) + + src = gr.vector_source_f(src_data, True) + head = gr.head(gr.sizeof_float, N) + op = blocks.rms_ff(0.0001) + dst = gr.vector_sink_f() + + self.tb.connect(src, head, op, dst) + self.tb.run() + + dst_data = dst.data() + self.assertAlmostEqual(dst_data[-1], expected_data, 4) + + def test_cf(self): + amp = 4 + src_data = sig_source_c(1, 0.01, amp, 200) + N = 750000 + + expected_data = amp + + src = gr.vector_source_c(src_data, True) + head = gr.head(gr.sizeof_gr_complex, N) + op = blocks.rms_cf(0.0001) + dst = gr.vector_sink_f() + + self.tb.connect(src, head, op, dst) + self.tb.run() + + dst_data = dst.data() + self.assertAlmostEqual(dst_data[-1], expected_data, 4) + +if __name__ == '__main__': + gr_unittest.run(test_rms, "test_rms.xml") diff --git a/gr-blocks/python/qa_stretch.py b/gr-blocks/python/qa_stretch.py new file mode 100755 index 000000000..013d878a8 --- /dev/null +++ b/gr-blocks/python/qa_stretch.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_stretch(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_stretch_01(self): + tb = self.tb + + data = 10*[1,] + data0 = map(lambda x: x/20.0, data) + data1 = map(lambda x: x/10.0, data) + + expected_result0 = 10*[0.05,] + expected_result1 = 10*[0.1,] + + src0 = gr.vector_source_f(data0, False) + src1 = gr.vector_source_f(data1, False) + inter = gr.streams_to_vector(gr.sizeof_float, 2) + op = blocks.stretch_ff(0.1, 2) + deinter = gr.vector_to_streams(gr.sizeof_float, 2) + dst0 = gr.vector_sink_f() + dst1 = gr.vector_sink_f() + + 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.run() + + dst0_data = dst0.data() + dst1_data = dst1.data() + + self.assertFloatTuplesAlmostEqual(expected_result0, dst0_data, 4) + self.assertFloatTuplesAlmostEqual(expected_result1, dst1_data, 4) + +if __name__ == '__main__': + gr_unittest.run(test_stretch, "test_stretch.xml") diff --git a/gr-blocks/python/qa_threshold.py b/gr-blocks/python/qa_threshold.py new file mode 100644 index 000000000..f91af739a --- /dev/null +++ b/gr-blocks/python/qa_threshold.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_threshold(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_01(self): + tb = self.tb + + data = [0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2] + + expected_result = (0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1) + + src = gr.vector_source_f(data, False) + op = blocks.threshold_ff(1, 1) + dst = gr.vector_sink_f() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_threshold, "test_threshold.xml") diff --git a/gr-blocks/python/qa_throttle.py b/gr-blocks/python/qa_throttle.py new file mode 100755 index 000000000..5d462f2c9 --- /dev/null +++ b/gr-blocks/python/qa_throttle.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_throttle(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_01(self): + # Test that we can make the block + op = blocks.throttle(gr.sizeof_gr_complex, 1) + +if __name__ == '__main__': + gr_unittest.run(test_throttle, "test_throttle.xml") |