-
Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathtest_multiprocess_links.py
101 lines (71 loc) · 3.67 KB
/
test_multiprocess_links.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Authors: CommPy contributors
# License: BSD 3-Clause
from __future__ import division # Python 2 compatibility
from numpy import arange, sqrt, log10
from numpy.random import seed
from numpy.testing import run_module_suite, assert_allclose, dec
from scipy.special import erfc
from commpy.channels import MIMOFlatChannel, SISOFlatChannel
from commpy.modulation import QAMModem, kbest
from commpy.multiprocess_links import LinkModel, Wifi80211
# from commpy.tests.test_multiprocess_links_support import QPSK, receiver
QPSK = QAMModem(4)
def receiver(y, h, constellation, noise_var):
return QPSK.demodulate(y, 'hard')
QAM16 = QAMModem(16)
def receiver16(y, h, constellation, noise_var):
return QAM16.demodulate(kbest(y, h, constellation, 16), 'hard')
@dec.slow
def test_link_performance():
# Set seed
seed(17121996)
# Apply link_performance to SISO QPSK and AWGN channel
model = LinkModel(QPSK.modulate, SISOFlatChannel(fading_param=(1 + 0j, 0)), receiver,
QPSK.num_bits_symbol, QPSK.constellation, QPSK.Es)
BERs = model.link_performance(range(0, 9, 2), 600e4, 600)
desired = erfc(sqrt(10 ** (arange(0, 9, 2) / 10) / 2)) / 2
assert_allclose(BERs, desired, rtol=0.25,
err_msg='Wrong performance for SISO QPSK and AWGN channel')
full_metrics = model.link_performance_full_metrics(range(0, 9, 2), 1000, 600)
assert_allclose(full_metrics[0], desired, rtol=0.25,
err_msg='Wrong performance for SISO QPSK and AWGN channel')
# Apply link_performance to MIMO 16QAM and 4x4 Rayleigh channel
RayleighChannel = MIMOFlatChannel(4, 4)
RayleighChannel.uncorr_rayleigh_fading(complex)
model = LinkModel(QAM16.modulate, RayleighChannel, receiver16,
QAM16.num_bits_symbol, QAM16.constellation, QAM16.Es)
SNRs = arange(0, 21, 5) + 10 * log10(QAM16.num_bits_symbol)
BERs = model.link_performance(SNRs, 600e4, 600)
desired = (2e-1, 1e-1, 3e-2, 2e-3, 4e-5) # From reference
assert_allclose(BERs, desired, rtol=1.25,
err_msg='Wrong performance for MIMO 16QAM and 4x4 Rayleigh channel')
full_metrics = model.link_performance_full_metrics(SNRs, 1000, 600)
assert_allclose(full_metrics[0], desired, rtol=1.25,
err_msg='Wrong performance for MIMO 16QAM and 4x4 Rayleigh channel')
@dec.slow
def test_wifi80211_siso_channel():
seed(17121996)
wifi80211 = Wifi80211(1, number_of_processes=1)
BERs = wifi80211.link_performance(SISOFlatChannel(fading_param=(1 + 0j, 0)), range(0, 9, 2), 10 ** 4, 600)[0]
desired = (0.548, 0.508, 0.59, 0.81, 0.18) # From previous tests
# for i, val in enumerate(desired):
# print((BERs[i] - val) / val)
assert_allclose(BERs, desired, rtol=0.3,
err_msg='Wrong performance for SISO QPSK and AWGN channel')
wifi80211 = Wifi80211(3)
modem = wifi80211.get_modem()
def receiver_mimo_wifi3(y, h, constellation, noise_var):
return modem.demodulate(kbest(y, h, constellation, 16), 'hard')
@dec.slow
def test_wifi80211_mimo_channel():
seed(17121996)
# Apply link_performance to MIMO 16QAM and 4x4 Rayleigh channel
RayleighChannel = MIMOFlatChannel(4, 4)
RayleighChannel.uncorr_rayleigh_fading(complex)
BERs = wifi80211.link_performance(RayleighChannel, arange(0, 21, 5) + 10 * log10(modem.num_bits_symbol), 10 ** 4,
600, receiver=receiver_mimo_wifi3)[0]
desired = (0.535, 0.508, 0.521, 0.554, 0.475) # From previous test
assert_allclose(BERs, desired, rtol=1.25,
err_msg='Wrong performance for MIMO 16QAM and 4x4 Rayleigh channel')
if __name__ == "__main__":
run_module_suite()