import os
if os.getenv("CUDA_VISIBLE_DEVICES") is None:
= 0 # Use "" to use the CPU
gpu_num "CUDA_VISIBLE_DEVICES"] = f"{gpu_num}"
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' os.environ[
Hello Sionna!
In this post, basic implemenation of the Sionna library is discussed.
try:
import sionna
except ImportError as e:
# Install Sionna if package is not already installed
import os
"pip install sionna")
os.system(import sionna
# IPython "magic function" for inline plots
%matplotlib inline
import matplotlib.pyplot as plt
= 1000 # Number of symbols we want to generate
batch_size = 4 # 16-QAM has four bits per symbol
num_bits_per_symbol = sionna.utils.BinarySource()
binary_source = binary_source([batch_size, num_bits_per_symbol])
b b
<tf.Tensor: shape=(1000, 4), dtype=float32, numpy=
array([[1., 0., 0., 1.],
[0., 1., 0., 1.],
[1., 1., 1., 0.],
...,
[1., 0., 1., 1.],
[0., 0., 1., 1.],
[1., 0., 0., 1.]], dtype=float32)>
= sionna.mapping.Constellation("qam", num_bits_per_symbol)
constellation ; constellation.show()
= sionna.mapping.Mapper(constellation=constellation)
mapper = mapper(b)
x 10] x[:
<tf.Tensor: shape=(10, 1), dtype=complex64, numpy=
array([[-0.3162278+0.9486833j],
[ 0.3162278-0.9486833j],
[-0.9486833-0.3162278j],
[-0.9486833+0.9486833j],
[ 0.3162278+0.3162278j],
[-0.3162278-0.3162278j],
[-0.3162278+0.9486833j],
[ 0.3162278+0.9486833j],
[ 0.9486833-0.3162278j],
[ 0.3162278-0.3162278j]], dtype=complex64)>
= sionna.channel.AWGN()
awgn = 15 # Desired Eb/No in dB
ebno_db = sionna.utils.ebnodb2no(ebno_db, num_bits_per_symbol, coderate=1)
no = awgn([x, no])
y
# Visualize the received signal
import matplotlib.pyplot as plt
import numpy as np
= plt.figure(figsize=(7,7))
fig = fig.add_subplot(111)
ax ;
plt.scatter(np.real(y), np.imag(y))"equal", adjustable="box")
ax.set_aspect("Real Part")
plt.xlabel("Imaginary Part")
plt.ylabel(True, which="both", axis="both")
plt.grid("Received Symbols"); plt.title(