-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathqa_resource_demapper_cc.py
executable file
·75 lines (63 loc) · 2.68 KB
/
qa_resource_demapper_cc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2016 Johannes Demel.
#
# This 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.
#
# This software 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 this software; 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
from gnuradio import blocks
import gfdm_python as gfdm
from pygfdm.mapping import get_subcarrier_map
from pygfdm.utils import get_random_qpsk
import numpy as np
class qa_resource_demapper_cc(gr_unittest.TestCase):
def setUp(self):
self.tb = gr.top_block()
def tearDown(self):
self.tb = None
def test_001_timeslot_first(self):
timeslots = 9
subcarriers = 32
active_subcarriers = 20
subcarrier_map = get_subcarrier_map(subcarriers, active_subcarriers)
data = get_random_qpsk(10 * timeslots * active_subcarriers)
src = blocks.vector_source_c(data)
mapper = gfdm.resource_mapper_cc(timeslots, subcarriers, active_subcarriers, subcarrier_map, True)
demapper = gfdm.resource_demapper_cc(timeslots, subcarriers, active_subcarriers, subcarrier_map, True)
snk = blocks.vector_sink_c()
self.tb.connect(src, mapper, demapper, snk)
self.tb.run()
# check data
res = np.array(snk.data())
self.assertComplexTuplesAlmostEqual(data, res)
def test_002_subcarrier_first(self):
timeslots = 9
subcarriers = 32
active_subcarriers = 20
subcarrier_map = get_subcarrier_map(subcarriers, active_subcarriers)
data = get_random_qpsk(10 * timeslots * active_subcarriers)
src = blocks.vector_source_c(data)
mapper = gfdm.resource_mapper_cc(timeslots, subcarriers, active_subcarriers, subcarrier_map, False)
demapper = gfdm.resource_demapper_cc(timeslots, subcarriers, active_subcarriers, subcarrier_map, False)
snk = blocks.vector_sink_c()
self.tb.connect(src, mapper, demapper, snk)
self.tb.run()
# check data
res = np.array(snk.data())
self.assertComplexTuplesAlmostEqual(data, res)
if __name__ == '__main__':
gr_unittest.run(qa_resource_demapper_cc, "qa_resource_demapper_cc.xml")