summaryrefslogtreecommitdiff
path: root/gr-blocks
diff options
context:
space:
mode:
Diffstat (limited to 'gr-blocks')
-rw-r--r--gr-blocks/examples/ctrlport/simple_copy.grc50
-rw-r--r--gr-blocks/python/blocks/qa_moving_average.py65
2 files changed, 66 insertions, 49 deletions
diff --git a/gr-blocks/examples/ctrlport/simple_copy.grc b/gr-blocks/examples/ctrlport/simple_copy.grc
index a52c350ded..f61c6cd18a 100644
--- a/gr-blocks/examples/ctrlport/simple_copy.grc
+++ b/gr-blocks/examples/ctrlport/simple_copy.grc
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
-<?grc format='1' created='3.7.11'?>
+<?grc format='1' created='3.7.12'?>
<flow_graph>
<timestamp>Sat Mar 16 22:03:14 2013</timestamp>
<block>
@@ -393,48 +393,6 @@ to enable/disablethis block</value>
</param>
</block>
<block>
- <key>epy_block</key>
- <param>
- <key>alias</key>
- <value></value>
- </param>
- <param>
- <key>_io_cache</key>
- <value>('Null Msg Source', 'blk', [], [], [('fake_output', 'message', 1)], '', [])</value>
- </param>
- <param>
- <key>_source_code</key>
- <value># Block that doesn't do anything, just used to get a msg input port on another block exposed to ControlPort
-from gnuradio import gr
-import pmt
-class blk(gr.basic_block):
- def __init__(self):
- gr.basic_block.__init__(self,name='Null Msg Source',in_sig=[],out_sig=[])
- self.message_port_register_out(pmt.intern("fake_output"))
-</value>
- </param>
- <param>
- <key>comment</key>
- <value></value>
- </param>
- <param>
- <key>_enabled</key>
- <value>True</value>
- </param>
- <param>
- <key>_coordinate</key>
- <value>(357, 218)</value>
- </param>
- <param>
- <key>_rotation</key>
- <value>0</value>
- </param>
- <param>
- <key>id</key>
- <value>epy_block_0</value>
- </param>
- </block>
- <block>
<key>note</key>
<param>
<key>alias</key>
@@ -861,10 +819,4 @@ python simple_copy_controller.py 127.0.0.1 &lt;PORT&gt; true</value>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
- <connection>
- <source_block_id>epy_block_0</source_block_id>
- <sink_block_id>blocks_copy_0</sink_block_id>
- <source_key>fake_output</source_key>
- <sink_key>en</sink_key>
- </connection>
</flow_graph>
diff --git a/gr-blocks/python/blocks/qa_moving_average.py b/gr-blocks/python/blocks/qa_moving_average.py
index 2c58805925..53b240fe7f 100644
--- a/gr-blocks/python/blocks/qa_moving_average.py
+++ b/gr-blocks/python/blocks/qa_moving_average.py
@@ -45,6 +45,10 @@ class test_moving_average(gr_unittest.TestCase):
def tearDown(self):
self.tb = None
+ # These tests will always pass and are therefore useless. 100 random numbers [-1,1) are
+ # getting summed up and scaled with 0.001. Then, an assertion verifies a result near 0,
+ # which is the case even if the block is malfunctioning.
+
def test_01(self):
tb = self.tb
@@ -87,5 +91,66 @@ 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
+
+ def test_03(self):
+ tb = self.tb
+
+ N = 10000 # number of samples
+ history = 100 # num of samples to average
+ data = make_random_float_tuple(N, 1) # generate random data
+
+ # pythonic MA filter
+ data_padded = (history-1)*[0.0]+list(data) # history
+ expected_result = []
+ moving_sum = sum(data_padded[:history-1])
+ for i in range(N):
+ moving_sum += data_padded[i+history-1]
+ expected_result.append(moving_sum)
+ moving_sum -= data_padded[i]
+
+ src = blocks.vector_source_f(data, False)
+ op = blocks.moving_average_ff(history, 1)
+ dst = blocks.vector_sink_f()
+
+ tb.connect(src, op)
+ tb.connect(op, dst)
+ tb.run()
+
+ dst_data = dst.data()
+
+ # make sure result is close to zero
+ self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 4)
+
+ def test_04(self):
+ tb = self.tb
+
+ N = 10000 # number of samples
+ history = 100 # num of samples to average
+ data = make_random_complex_tuple(N, 1) # generate random data
+
+ # pythonic MA filter
+ data_padded = (history-1)*[0.0+1j*0.0]+list(data) # history
+ expected_result = []
+ moving_sum = sum(data_padded[:history-1])
+ for i in range(N):
+ 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)
+ 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.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4)
+
+
if __name__ == '__main__':
gr_unittest.run(test_moving_average, "test_moving_average.xml")