Skip to content

Commit 88341ec

Browse files
committed
Correct typos
1 parent aea4244 commit 88341ec

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

commpy/channels.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -402,26 +402,20 @@ def _update_corr_KBSM(self, betat, betar):
402402
"""
403403

404404
if betar < 0 or betat < 0:
405-
raise ValueError("beta must be positif ")
405+
raise ValueError("beta must be positif")
406406

407-
# Creation or Er and Et
408-
Er = array([[exp(abs(m - n)) for m in range(self.nb_rx)] for n in range(self.nb_rx)])
409-
Et = array([[exp(abs(m - n)) for m in range(self.nb_tx)] for n in range(self.nb_tx)])
407+
# Create Er and Et
408+
Er = array([[exp(-betar * abs(m - n)) for m in range(self.nb_rx)] for n in range(self.nb_rx)])
409+
Et = array([[exp(-betat * abs(m - n)) for m in range(self.nb_tx)] for n in range(self.nb_tx)])
410410

411-
# Compute gain to the keep K-factor
412-
NLOS_before = trace(self.fading_param[1]) * trace(self.fading_param[2])
413-
NLOS_after = trace(self.fading_param[1] * Et) * trace(self.fading_param[2] * Er)
411+
# Updating of correlation matrices
412+
self.fading_param = self.fading_param[0], self.fading_param[1] * Et, self.fading_param[2] * Er
414413

415-
alpha = NLOS_before / NLOS_after
416-
417-
# updating of correlation matrices
418-
self.fading_param = self.fading_param[0], alpha * self.fading_param[1] * Et, self.fading_param[2] * Er
419-
420-
421-
def specularH(self, thetar, dr, thetat, dt):
414+
def specular_compo(self, thetat, dt, thetar, dr):
422415

423416
"""
424-
Calculate the specular components of H the channel gain as in [1].
417+
Calculate the specular components of the channel gain as in [1].
418+
425419
ref: [1] Lee M. Garth, Peter J. Smith, Mansoor Shafi, "Exact Symbol Error Probabilities for SVD Transmission
426420
of BPSK Data over Fading Channels", IEEE 2005.
427421
@@ -450,12 +444,12 @@ def specularH(self, thetar, dr, thetat, dt):
450444
If dt or dr are negative.
451445
452446
"""
453-
if dr < 0 or dt < 0 :
447+
if dr < 0 or dt < 0:
454448
raise ValueError("the distance must be positive ")
455-
H = zeros((self.nb_rx,self.nb_tx),dtype=complex)
449+
H = zeros((self.nb_rx, self.nb_tx), dtype=complex)
456450
for n in range(self.nb_rx):
457451
for m in range(self.nb_tx):
458-
H[n,m] = exp(1j*2*pi*(n*dr*cos(thetar)-m*dt*cos(thetat)))
452+
H[n, m] = exp(1j * 2 * pi * (n * dr * cos(thetar) - m * dt * cos(thetat)))
459453
return H
460454

461455
@property
@@ -497,8 +491,8 @@ def expo_corr_rayleigh_fading(self, t, r, betat=0, betar=0):
497491
ref: [1] S. L. Loyka, "Channel capacity if MIMO architecture using the exponential correlation matrix ", IEEE
498492
Commun. Lett., vol.5, n. 9, p. 369-371, sept. 2001.
499493
500-
[2] S. Wu, C. Wang, E. M. Aggoune, et M. M. Alwakeel, "A novel Kronecker-based stochastic model for massive
501-
MIMO channels", in 2015 IEEE/CIC International Conference on Communications in China (ICCC), 2015, p. 1‑6.
494+
[2] S. Wu, C. Wang, E. M. Aggoune, et M. M. Alwakeel,"A novel Kronecker-based stochastic model for massive
495+
MIMO channels", in 2015 IEEE/CIC International Conference on Communications in China (ICCC), 2015, p. 1-6
502496
503497
504498
Parameters
@@ -570,8 +564,8 @@ def expo_corr_rician_fading(self, mean, k_factor, t, r, betat=0, betar=0):
570564
ref: [1] S. L. Loyka, "Channel capacity if MIMO architecture using the exponential correlation matrix ", IEEE
571565
Commun. Lett., vol.5, n. 9, p. 369-371, sept. 2001.
572566
573-
[2] S. Wu, C. Wang, E. M. Aggoune, et M. M. Alwakeel, "A novel Kronecker-based stochastic model for massive
574-
MIMO channels", in 2015 IEEE/CIC International Conference on Communications in China (ICCC), 2015, p. 1‑6.
567+
[2] S. Wu, C. Wang, E. M. Aggoune, et M. M. Alwakeel,"A novel Kronecker-based stochastic model for massive
568+
MIMO channels", in 2015 IEEE/CIC International Conference on Communications in China (ICCC), 2015, p. 1-6
575569
576570
577571
mean and correlation matricies will be scaled to fit the required k-factor. The k-factor is also preserved is

commpy/tests/test_channels.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33

44
from __future__ import division, print_function # Python 2 compatibility
55

6-
from commpy.channels import SISOFlatChannel, MIMOFlatChannel
7-
from commpy.utilities import signal_power
6+
from math import cos
7+
88
from numpy import ones, inf, sqrt, array, identity, zeros, dot, trace, einsum, absolute, exp, pi, fromiter, kron, \
9-
zeros_like
9+
zeros_like, empty
1010
from numpy.random import seed, choice, randn
1111
from numpy.testing import run_module_suite, assert_raises, assert_equal, assert_allclose, \
1212
assert_array_equal, dec
1313

14+
from commpy.channels import SISOFlatChannel, MIMOFlatChannel
15+
from commpy.utilities import signal_power
16+
1417

1518
class TestSISOFlatChannel:
1619
msg_length = 100000
@@ -372,49 +375,52 @@ def check_correlation(chan, Rt, Rr):
372375
assert_allclose(chan.k_factor, 10,
373376
err_msg='Wrong k-factor with uncorrelated rician fading')
374377

375-
chan.expo_corr_rayleigh_fading(exp(-0.2j*pi), exp(-0.1j*pi))
378+
chan.expo_corr_rayleigh_fading(exp(-0.2j * pi), exp(-0.1j * pi))
376379
check_chan_gain(mod, chan)
377380
assert_allclose(chan.k_factor, 0,
378381
err_msg='Wrong k-factor with correlated Rayleigh fading')
379-
Rt, Rr = expo_correlation(exp(-0.2j*pi), exp(-0.1j*pi))
382+
Rt, Rr = expo_correlation(exp(-0.2j * pi), exp(-0.1j * pi))
380383
check_correlation(chan, Rt, Rr)
381384

382385
mean = randn(nb_rx, nb_tx) + randn(nb_rx, nb_tx) * 1j
383-
chan.expo_corr_rician_fading(mean, 10, exp(-0.1j*pi), exp(-0.2j*pi))
386+
chan.expo_corr_rician_fading(mean, 10, exp(-0.1j * pi), exp(-0.2j * pi))
384387
check_chan_gain(mod, chan)
385388
assert_allclose(chan.k_factor, 10,
386389
err_msg='Wrong k-factor with correlated rician fading')
387390

388391
# Test with beta > 0
389-
chan.expo_corr_rayleigh_fading(exp(-0.2j*pi), exp(-0.1j*pi), 1, 0.5)
392+
chan.expo_corr_rayleigh_fading(exp(-0.2j * pi), exp(-0.1j * pi), 1, 0.5)
390393
check_chan_gain(mod, chan)
391394
assert_allclose(chan.k_factor, 0,
392395
err_msg='Wrong k-factor with correlated Rayleigh fading')
393-
Rt, Rr = expo_correlation(exp(-0.2j*pi), exp(-0.1j*pi))
394-
# ET ER, et version chapea de R
395-
Er = array([[exp(abs(m - n)) for m in range(nb_rx)] for n in range(nb_rx)])
396-
Et = array([[exp(abs(m - n)) for m in range(nb_tx)] for n in range(nb_tx)])
397-
398-
Rr = chan.fading_param[1] * Er
399-
Rt = chan.fading_param[2] * Et
400-
401-
check_correlation(chan, Rt, Rr)
402396

403397
mean = randn(nb_rx, nb_tx) + randn(nb_rx, nb_tx) * 1j
404-
chan.expo_corr_rician_fading(mean, 5, exp(-0.1j*pi), exp(-0.2j*pi), 3, 2)
398+
chan.expo_corr_rician_fading(mean, 5, exp(-0.1j * pi), exp(-0.2j * pi), 3, 2)
405399
check_chan_gain(mod, chan)
406400
assert_allclose(chan.k_factor, 5,
407401
err_msg='Wrong k-factor with correlated rician fading')
408402

409-
# Test specularH
410-
with assert_raises(ValueError):
411-
chan.specularH(0,-1,0,1)
412403

413-
mean = chan.specularH(0,0.1,0.5,1)
414-
chan.expo_corr_rician_fading(mean, 5, exp(-0.1j*pi), exp(-0.2j*pi), 3, 2)
415-
check_chan_gain(mod, chan)
416-
assert_allclose(chan.k_factor, 5,
417-
err_msg='Wrong k-factor with correlated rician fading')
404+
class TestMIMOSpectular(MIMOTestCase):
405+
def __init__(self):
406+
super(TestMIMOSpectular, self).__init__()
407+
408+
def do(self, nb_tx, nb_rx):
409+
chan = MIMOFlatChannel(nb_tx, nb_rx, 0)
410+
411+
# Text raising of ValueError
412+
with assert_raises(ValueError):
413+
chan.specular_compo(0, -1, 0, 1)
414+
with assert_raises(ValueError):
415+
chan.specular_compo(0, 1, 0, -1)
416+
417+
# Test the result
418+
desired = empty((nb_rx, nb_tx), dtype=complex)
419+
for n in range(nb_rx):
420+
for m in range(nb_tx):
421+
desired[n, m] = exp(1j * 2 * pi * (n * 1 * cos(0.5) - m * 0.1 * cos(2)))
422+
assert_allclose(chan.specular_compo(2, 0.1, 0.5, 1), desired, rtol=0.02,
423+
err_msg='Wrong specular component')
418424

419425

420426
@dec.slow

0 commit comments

Comments
 (0)