root / gnuradio-core / src / python / gnuradio / gr / qa_dc_blocker.py @ 4c589268
History | View | Annotate | Download (3.5 kB)
| 1 | #!/usr/bin/env python
|
|---|---|
| 2 | #
|
| 3 | # Copyright 2011 Free Software Foundation, Inc.
|
| 4 | #
|
| 5 | # This file is part of GNU Radio
|
| 6 | #
|
| 7 | # GNU Radio is free software; you can redistribute it and/or modify
|
| 8 | # it under the terms of the GNU General Public License as published by
|
| 9 | # the Free Software Foundation; either version 3, or (at your option)
|
| 10 | # any later version.
|
| 11 | #
|
| 12 | # GNU Radio is distributed in the hope that it will be useful,
|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 | # GNU General Public License for more details.
|
| 16 | #
|
| 17 | # You should have received a copy of the GNU General Public License
|
| 18 | # along with GNU Radio; see the file COPYING. If not, write to
|
| 19 | # the Free Software Foundation, Inc., 51 Franklin Street,
|
| 20 | # Boston, MA 02110-1301, USA.
|
| 21 | #
|
| 22 | |
| 23 | from gnuradio import gr, gr_unittest |
| 24 | |
| 25 | class test_dc_blocker(gr_unittest.TestCase): |
| 26 | |
| 27 | def setUp (self): |
| 28 | self.tb = gr.top_block ()
|
| 29 | |
| 30 | def tearDown (self): |
| 31 | self.tb = None |
| 32 | |
| 33 | def test_001(self): |
| 34 | ''' Test impulse response - long form, cc '''
|
| 35 | src_data = [1,] + 100*[0,] |
| 36 | expected_result = ((-0.02072429656982422+0j), (-0.02081298828125+0j), |
| 37 | (0.979156494140625+0j), (-0.02081298828125+0j), |
| 38 | (-0.02072429656982422+0j)) |
| 39 | |
| 40 | src = gr.vector_source_c(src_data) |
| 41 | op = gr.dc_blocker_cc(32, True) |
| 42 | dst = gr.vector_sink_c() |
| 43 | |
| 44 | self.tb.connect (src, op, dst)
|
| 45 | self.tb.run()
|
| 46 | |
| 47 | # only test samples around 2D-2
|
| 48 | result_data = dst.data()[60:65] |
| 49 | self.assertComplexTuplesAlmostEqual (expected_result, result_data)
|
| 50 | |
| 51 | def test_002(self): |
| 52 | ''' Test impulse response - short form, cc '''
|
| 53 | src_data = [1,] + 100*[0,] |
| 54 | expected_result = ((-0.029296875+0j), (-0.0302734375+0j), |
| 55 | (0.96875+0j), (-0.0302734375+0j), |
| 56 | (-0.029296875+0j)) |
| 57 | |
| 58 | src = gr.vector_source_c(src_data) |
| 59 | op = gr.dc_blocker_cc(32, False) |
| 60 | dst = gr.vector_sink_c() |
| 61 | |
| 62 | self.tb.connect (src, op, dst)
|
| 63 | self.tb.run()
|
| 64 | |
| 65 | # only test samples around D-1
|
| 66 | result_data = dst.data()[29:34] |
| 67 | self.assertComplexTuplesAlmostEqual (expected_result, result_data)
|
| 68 | |
| 69 | |
| 70 | def test_003(self): |
| 71 | ''' Test impulse response - long form, ff '''
|
| 72 | src_data = [1,] + 100*[0,] |
| 73 | expected_result = ((-0.02072429656982422), (-0.02081298828125), |
| 74 | (0.979156494140625), (-0.02081298828125), |
| 75 | (-0.02072429656982422))
|
| 76 | |
| 77 | src = gr.vector_source_f(src_data) |
| 78 | op = gr.dc_blocker_ff(32, True) |
| 79 | dst = gr.vector_sink_f() |
| 80 | |
| 81 | self.tb.connect (src, op, dst)
|
| 82 | self.tb.run()
|
| 83 | |
| 84 | # only test samples around 2D-2
|
| 85 | result_data = dst.data()[60:65] |
| 86 | self.assertFloatTuplesAlmostEqual (expected_result, result_data)
|
| 87 | |
| 88 | def test_004(self): |
| 89 | ''' Test impulse response - short form, ff '''
|
| 90 | src_data = [1,] + 100*[0,] |
| 91 | expected_result = ((-0.029296875), (-0.0302734375), |
| 92 | (0.96875), (-0.0302734375), |
| 93 | (-0.029296875))
|
| 94 | |
| 95 | src = gr.vector_source_f(src_data) |
| 96 | op = gr.dc_blocker_ff(32, False) |
| 97 | dst = gr.vector_sink_f() |
| 98 | |
| 99 | self.tb.connect (src, op, dst)
|
| 100 | self.tb.run()
|
| 101 | |
| 102 | # only test samples around D-1
|
| 103 | result_data = dst.data()[29:34] |
| 104 | self.assertFloatTuplesAlmostEqual (expected_result, result_data)
|
| 105 | |
| 106 | if __name__ == '__main__': |
| 107 | gr_unittest.run(test_dc_blocker, "test_dc_blocker.xml")
|
| 108 |