|
3 | 3 |
|
4 | 4 | from __future__ import division, print_function # Python 2 compatibility |
5 | 5 |
|
6 | | -from commpy.channels import SISOFlatChannel, MIMOFlatChannel |
7 | | -from commpy.utilities import signal_power |
| 6 | +from math import cos |
| 7 | + |
8 | 8 | from numpy import ones, inf, sqrt, array, identity, zeros, dot, trace, einsum, absolute, exp, pi, fromiter, kron, \ |
9 | | - zeros_like |
| 9 | + zeros_like, empty |
10 | 10 | from numpy.random import seed, choice, randn |
11 | 11 | from numpy.testing import run_module_suite, assert_raises, assert_equal, assert_allclose, \ |
12 | 12 | assert_array_equal, dec |
13 | 13 |
|
| 14 | +from commpy.channels import SISOFlatChannel, MIMOFlatChannel |
| 15 | +from commpy.utilities import signal_power |
| 16 | + |
14 | 17 |
|
15 | 18 | class TestSISOFlatChannel: |
16 | 19 | msg_length = 100000 |
@@ -372,49 +375,52 @@ def check_correlation(chan, Rt, Rr): |
372 | 375 | assert_allclose(chan.k_factor, 10, |
373 | 376 | err_msg='Wrong k-factor with uncorrelated rician fading') |
374 | 377 |
|
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)) |
376 | 379 | check_chan_gain(mod, chan) |
377 | 380 | assert_allclose(chan.k_factor, 0, |
378 | 381 | 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)) |
380 | 383 | check_correlation(chan, Rt, Rr) |
381 | 384 |
|
382 | 385 | 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)) |
384 | 387 | check_chan_gain(mod, chan) |
385 | 388 | assert_allclose(chan.k_factor, 10, |
386 | 389 | err_msg='Wrong k-factor with correlated rician fading') |
387 | 390 |
|
388 | 391 | # 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) |
390 | 393 | check_chan_gain(mod, chan) |
391 | 394 | assert_allclose(chan.k_factor, 0, |
392 | 395 | 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) |
402 | 396 |
|
403 | 397 | 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) |
405 | 399 | check_chan_gain(mod, chan) |
406 | 400 | assert_allclose(chan.k_factor, 5, |
407 | 401 | err_msg='Wrong k-factor with correlated rician fading') |
408 | 402 |
|
409 | | - # Test specularH |
410 | | - with assert_raises(ValueError): |
411 | | - chan.specularH(0,-1,0,1) |
412 | 403 |
|
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') |
418 | 424 |
|
419 | 425 |
|
420 | 426 | @dec.slow |
|
0 commit comments