diff options
-rwxr-xr-x | gr-filter/python/qa_channel_model.py | 21 | ||||
-rwxr-xr-x | gr-filter/python/qa_fractional_interpolator.py | 56 |
2 files changed, 72 insertions, 5 deletions
diff --git a/gr-filter/python/qa_channel_model.py b/gr-filter/python/qa_channel_model.py index d908f83f7..7f1c61b4e 100755 --- a/gr-filter/python/qa_channel_model.py +++ b/gr-filter/python/qa_channel_model.py @@ -22,6 +22,7 @@ from gnuradio import gr, gr_unittest import filter_swig as filter +import math class test_channel_model(gr_unittest.TestCase): @@ -31,13 +32,29 @@ class test_channel_model(gr_unittest.TestCase): def tearDown(self): self.tb = None - def test_000_make(self): + def test_000(self): + N = 1000 # number of samples to use + fs = 1000 # baseband sampling rate + freq = 100 + + signal = gr.sig_source_c(fs, gr.GR_SIN_WAVE, freq, 1) + head = gr.head(gr.sizeof_gr_complex, N) op = filter.channel_model(0.0, 0.0, 1.0, [1,], 0) + snk = gr.vector_sink_c() + snk1 = gr.vector_sink_c() + op.set_noise_voltage(0.0) op.set_frequency_offset(0.0) op.set_taps([1,]) op.set_timing_offset(1.0) - + self.tb.connect(signal, head, op, snk) + self.tb.connect(op, snk1) + 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_channel_model, "test_channel_model.xml") diff --git a/gr-filter/python/qa_fractional_interpolator.py b/gr-filter/python/qa_fractional_interpolator.py index 74dae5d85..9e0f685d8 100755 --- a/gr-filter/python/qa_fractional_interpolator.py +++ b/gr-filter/python/qa_fractional_interpolator.py @@ -22,6 +22,7 @@ from gnuradio import gr, gr_unittest import filter_swig as filter +import math class test_fractional_resampler(gr_unittest.TestCase): @@ -31,9 +32,58 @@ class test_fractional_resampler(gr_unittest.TestCase): def tearDown(self): self.tb = None - def test_000_make(self): - op = filter.fractional_interpolator_ff(0.0, 1.0) - op2 = filter.fractional_interpolator_cc(0.0, 1.0) + def test_001_ff(self): + N = 10000 # number of samples to use + fs = 1000 # baseband sampling rate + rrate = 1.123 # resampling rate + + freq = 10 + signal = gr.sig_source_f(fs, gr.GR_SIN_WAVE, freq, 1) + head = gr.head(gr.sizeof_float, N) + op = filter.fractional_interpolator_ff(0, rrate) + snk = gr.vector_sink_f() + + self.tb.connect(signal, head, op, snk) + self.tb.run() + + Ntest = 5000 + L = len(snk.data()) + t = map(lambda x: float(x)/(fs/rrate), xrange(L)) + + phase = 0.1884 + expected_data = map(lambda x: math.sin(2.*math.pi*freq*x+phase), t) + + dst_data = snk.data() + + self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3) + + + def test_002_cc(self): + N = 10000 # number of samples to use + fs = 1000 # baseband sampling rate + rrate = 1.123 # resampling rate + + freq = 10 + signal = gr.sig_source_c(fs, gr.GR_SIN_WAVE, freq, 1) + head = gr.head(gr.sizeof_gr_complex, N) + op = filter.fractional_interpolator_cc(0.0, rrate) + snk = gr.vector_sink_c() + + self.tb.connect(signal, head, op, snk) + self.tb.run() + + Ntest = 5000 + L = len(snk.data()) + t = map(lambda x: float(x)/(fs/rrate), xrange(L)) + + phase = 0.1884 + expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \ + 1j*math.sin(2.*math.pi*freq*x+phase), t) + + dst_data = snk.data() + + self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3) + if __name__ == '__main__': gr_unittest.run(test_fractional_resampler, "test_fractional_resampler.xml") |