diff options
author | Ben Reynwar <ben@reynwar.net> | 2013-04-02 23:04:08 -0700 |
---|---|---|
committer | Ben Reynwar <ben@reynwar.net> | 2013-04-02 23:04:08 -0700 |
commit | c6dbde23b256a41b3d92cb4ad6b63287095d53c7 (patch) | |
tree | 71db12ea2e1667770c22568dcdf5e0857d5f1e59 /gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py | |
parent | 22b70d0889ef3c51e27a31ee18d153093a55cbb8 (diff) | |
parent | 98758cbfa9a2aff714952d19e773bc370dfa2185 (diff) |
Merged next into uninstalled import branch.
Diffstat (limited to 'gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py')
-rwxr-xr-x | gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py b/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py new file mode 100755 index 0000000000..56cd7a617e --- /dev/null +++ b/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py @@ -0,0 +1,186 @@ +#!/usr/bin/env python +# Copyright 2012,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, digital, blocks +import pmt + +class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001_t (self): + """ + pretty simple (the carrier allocation is not a practical OFDM configuration!) + """ + fft_len = 6 + tx_symbols = (1, 2, 3) + # ^ this gets mapped to the DC carrier because occupied_carriers[0][0] == 0 + pilot_symbols = ((1j,),) + occupied_carriers = ((0, 1, 2),) + pilot_carriers = ((3,),) + sync_word = (range(fft_len),) + expected_result = tuple(sync_word[0] + [1j, 0, 0, 1, 2, 3]) + # ^ DC carrier + tag_name = "len" + tag = gr.gr_tag_t() + tag.offset = 0 + tag.key = pmt.string_to_symbol(tag_name) + tag.value = pmt.from_long(len(tx_symbols)) + src = blocks.vector_source_c(tx_symbols, False, 1, (tag,)) + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + occupied_carriers, + pilot_carriers, + pilot_symbols, sync_word, + tag_name) + sink = blocks.vector_sink_c(fft_len) + self.tb.connect(src, alloc, sink) + self.tb.run () + self.assertEqual(sink.data(), expected_result) + + def test_001_t2 (self): + """ + pretty simple (same as before, but odd fft len) + """ + fft_len = 5 + tx_symbols = (1, 2, 3) + # ^ this gets mapped to the DC carrier because occupied_carriers[0][0] == 0 + occupied_carriers = ((0, 1, 2),) + pilot_carriers = ((-2,),) + pilot_symbols = ((1j,),) + expected_result = (1j, 0, 1, 2, 3) + # ^ DC carrier + tag_name = "len" + tag = gr.gr_tag_t() + tag.offset = 0 + tag.key = pmt.string_to_symbol(tag_name) + tag.value = pmt.from_long(len(tx_symbols)) + src = blocks.vector_source_c(tx_symbols, False, 1, (tag,)) + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + occupied_carriers, + pilot_carriers, + pilot_symbols, (), + tag_name) + sink = blocks.vector_sink_c(fft_len) + self.tb.connect(src, alloc, sink) + self.tb.run () + self.assertEqual(sink.data(), expected_result) + + def test_002_t (self): + """ + same, but using negative carrier indices + """ + fft_len = 6 + tx_symbols = (1, 2, 3) + pilot_symbols = ((1j,),) + occupied_carriers = ((-1, 1, 2),) + pilot_carriers = ((3,),) + expected_result = (1j, 0, 1, 0, 2, 3) + tag_name = "len" + tag = gr.gr_tag_t() + tag.offset = 0 + tag.key = pmt.string_to_symbol(tag_name) + tag.value = pmt.from_long(len(tx_symbols)) + src = blocks.vector_source_c(tx_symbols, False, 1, (tag,)) + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + occupied_carriers, + pilot_carriers, + pilot_symbols, (), + tag_name) + sink = blocks.vector_sink_c(fft_len) + self.tb.connect(src, alloc, sink) + self.tb.run () + self.assertEqual(sink.data(), expected_result) + + def test_003_t (self): + """ + more advanced: + - 6 symbols per carrier + - 2 pilots per carrier + - have enough data for nearly 3 OFDM symbols + - send that twice + - add some random tags + - don't shift + """ + tx_symbols = 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 = (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 + tag_name = "len" + tag1 = gr.gr_tag_t() + tag1.offset = 0 + tag1.key = pmt.string_to_symbol(tag_name) + tag1.value = pmt.from_long(len(tx_symbols)) + tag2 = gr.gr_tag_t() + tag2.offset = len(tx_symbols) + tag2.key = pmt.string_to_symbol(tag_name) + tag2.value = pmt.from_long(len(tx_symbols)) + testtag1 = gr.gr_tag_t() + testtag1.offset = 0 + testtag1.key = pmt.string_to_symbol('tag1') + testtag1.value = pmt.from_long(0) + testtag2 = gr.gr_tag_t() + testtag2.offset = 7 # On the 2nd OFDM symbol + testtag2.key = pmt.string_to_symbol('tag2') + testtag2.value = pmt.from_long(0) + testtag3 = gr.gr_tag_t() + 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.gr_tag_t() + testtag4.offset = 2*len(tx_symbols)-1 # Last OFDM symbol of packet 2 + testtag4.key = pmt.string_to_symbol('tag4') + testtag4.value = pmt.from_long(0) + src = blocks.vector_source_c(tx_symbols * 2, False, 1, + (tag1, tag2, testtag1, testtag2, testtag3, testtag4)) + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + occupied_carriers, + pilot_carriers, + pilot_symbols, (), + tag_name, + False) + sink = blocks.vector_sink_c(fft_len) + self.tb.connect(src, alloc, sink) + self.tb.run () + self.assertEqual(sink.data(), expected_result * 2) + 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) + if key in tags_found.keys(): + tags_found[key] = True + self.assertEqual(correct_offsets[key], tag.offset) + if key == tag_name: + self.assertTrue(tag.offset == 0 or tag.offset == 3) + self.assertTrue(pmt.to_long(tag.value) == 3) + self.assertTrue(all(tags_found.values())) + + +if __name__ == '__main__': + gr_unittest.run(qa_digital_carrier_allocator_cvc, "qa_digital_carrier_allocator_cvc.xml") + |