Skip to content

Commit 36d7b26

Browse files
committed
Update tests & correct typos.
1 parent 26fd8ea commit 36d7b26

File tree

5 files changed

+60
-48
lines changed

5 files changed

+60
-48
lines changed

commpy/channels.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ def uncorr_rayleigh_fading(self, dtype):
416416
def expo_corr_rayleigh_fading(self, t, r):
417417
""" Set the fading parameters to a complex correlated Rayleigh channel following the exponential model.
418418
419-
See: S. L. Loyka, « Channel capacity of MIMO architecture using the exponential correlation matrix », IEEE
420-
Commun. Lett., vol. 5, nᵒ 9, p. 369371, sept. 2001.
419+
See: S. L. Loyka, "Channel capacity if MIMO architecture using the exponential correlation matrix ", IEEE
420+
Commun. Lett., vol.5, n. 9, p. 369-371, sept. 2001.
421421
422422
Parameters
423423
----------
@@ -470,8 +470,8 @@ def uncorr_rician_fading(self, mean, k_factor):
470470
def expo_corr_rician_fading(self, mean, k_factor, t, r):
471471
""" Set the fading parameters to a complex correlated rician channel following the exponential model.
472472
473-
See: S. L. Loyka, « Channel capacity of MIMO architecture using the exponential correlation matrix », IEEE
474-
Commun. Lett., vol. 5, nᵒ 9, p. 369371, sept. 2001.
473+
See: S. L. Loyka, "Channel capacity if MIMO architecture using the exponential correlation matrix ", IEEE
474+
Commun. Lett., vol.5, n. 9, p. 369-371, sept. 2001.
475475
476476
mean and correlation matricies will be scaled to fit the required k-factor.
477477

commpy/links.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from __future__ import division # Python 2 compatibility
1616

1717
import numpy as np
18+
1819
from commpy.channels import MIMOFlatChannel
1920

2021
__all__ = ['link_performance', 'linkModel']
@@ -80,7 +81,7 @@ def link_performance(link_model, SNRs, send_max, err_min, send_chunk=None, code_
8081
received_msg[receive_size * i:receive_size * (i+1)] = \
8182
link_model.receive(channel_output[i], link_model.channel.channel_gains[i], link_model.constellation)
8283
else:
83-
received_msg = channel_output
84+
received_msg = link_model.receive(channel_output, link_model.channel.channel_gains, link_model.constellation)
8485
# Count errors
8586
bit_err += (msg != received_msg).sum() # Remove MIMO padding
8687
bit_send += send_chunk

commpy/tests/test_channels.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ def check_chan_gain(mod, chan):
7777
# Test with Rayleigh fading
7878
chan.fading_param = (0, 1)
7979
check_chan_gain(mod, chan)
80-
assert_allclose(absolute(chan.channel_gains.mean()), 0, atol=1e-2,
80+
assert_allclose(absolute(chan.channel_gains.mean()), 0, atol=2e-2,
8181
err_msg='Wrong channel mean with real channel')
8282
assert_allclose(chan.channel_gains.var(), 1, atol=0.2,
8383
err_msg='Wrong channel variance with real channel')
8484

8585
# Test with rician fading
8686
chan.fading_param = (sqrt(2 / 3), 1 / 3)
8787
check_chan_gain(mod, chan)
88-
assert_allclose(chan.channel_gains.mean(), sqrt(2 / 3), atol=1e-2,
88+
assert_allclose(chan.channel_gains.mean(), sqrt(2 / 3), atol=2e-2,
8989
err_msg='Wrong channel mean with real channel')
9090
assert_allclose(chan.channel_gains.var(), 1 / 3, atol=0.2,
9191
err_msg='Wrong channel variance with real channel')
@@ -105,15 +105,15 @@ def check_chan_gain(mod, chan):
105105
# Test with Rayleigh fading
106106
chan.fading_param = (0j, 1)
107107
check_chan_gain(mod, chan)
108-
assert_allclose(absolute(chan.channel_gains.mean()), 0, atol=1e-2,
108+
assert_allclose(absolute(chan.channel_gains.mean()), 0, atol=2e-2,
109109
err_msg='Wrong channel mean with real channel')
110110
assert_allclose(chan.channel_gains.var(), 1, atol=0.2,
111111
err_msg='Wrong channel variance with real channel')
112112

113113
# Test with rician fading
114114
chan.fading_param = (0.5 + 0.5j, 0.5)
115115
check_chan_gain(mod, chan)
116-
assert_allclose(absolute(chan.channel_gains.mean()), sqrt(0.5), atol=1e-2,
116+
assert_allclose(absolute(chan.channel_gains.mean()), sqrt(0.5), atol=2e-2,
117117
err_msg='Wrong channel mean with real channel')
118118
assert_allclose(chan.channel_gains.var(), 0.5, atol=0.2,
119119
err_msg='Wrong channel variance with real channel')

commpy/tests/test_links.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Authors: Bastien Trotobas <bastien.trotobas@gmail.com>
2+
# License: BSD 3-Clause
3+
4+
from __future__ import division # Python 2 compatibility
5+
6+
from numpy import arange, sqrt, log10
7+
from numpy.random import seed
8+
from numpy.testing import run_module_suite, assert_allclose, dec
9+
from scipy.special import erfc
10+
11+
from commpy.channels import MIMOFlatChannel, SISOFlatChannel
12+
from commpy.links import link_performance, linkModel
13+
from commpy.modulation import QAMModem, kbest
14+
15+
16+
@dec.slow
17+
def test_link_performance():
18+
# Apply link_performance to SISO QPSK and AWGN channel
19+
QPSK = QAMModem(4)
20+
21+
def receiver(y, h, constellation):
22+
return QPSK.demodulate(y, 'hard')
23+
model = linkModel(QPSK.modulate, SISOFlatChannel(fading_param=(1 + 0j, 0)), receiver,
24+
QPSK.num_bits_symbol, QPSK.constellation, QPSK.Es)
25+
26+
BERs = link_performance(model, range(0, 9, 2), 600e4, 600)
27+
desired = erfc(sqrt(10**(arange(0, 9, 2) / 10) / 2)) / 2
28+
assert_allclose(BERs, desired, rtol=0.25,
29+
err_msg='Wrong performance for SISO QPSK and AWGN channel')
30+
31+
# Apply link_performance to MIMO 16QAM and 4x4 Rayleigh channel
32+
QAM16 = QAMModem(16)
33+
RayleighChannel = MIMOFlatChannel(4, 4)
34+
RayleighChannel.uncorr_rayleigh_fading(complex)
35+
36+
def receiver(y, h, constellation):
37+
return QAM16.demodulate(kbest(y, h, constellation, 16), 'hard')
38+
model = linkModel(QAM16.modulate, RayleighChannel, receiver,
39+
QAM16.num_bits_symbol, QAM16.constellation, QAM16.Es)
40+
SNRs = arange(0, 21, 5) + 10 * log10(QAM16.num_bits_symbol)
41+
42+
BERs = link_performance(model, SNRs, 600e4, 600)
43+
desired = (2e-1, 1e-1, 3e-2, 2e-3, 4e-5) # From reference
44+
assert_allclose(BERs, desired, rtol=1.25,
45+
err_msg='Wrong performance for MIMO 16QAM and 4x4 Rayleigh channel')
46+
47+
48+
if __name__ == "__main__":
49+
seed(17121996)
50+
run_module_suite()

commpy/tests/test_utilities.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)