“Hello, world!”

Import Sionna:

[1]:
importosifos.getenv("CUDA_VISIBLE_DEVICES")isNone:gpu_num=0# Use "" to use the CPUos.environ["CUDA_VISIBLE_DEVICES"]=f"{gpu_num}"os.environ['TF_CPP_MIN_LOG_LEVEL']='3'# Import Sionnatry:importsionna.phyexceptImportErrorase:importsysif'google.colab'insys.modules:# Install Sionna in Google Colabprint("Installing Sionna and restarting the runtime. Please run the cell again.")os.system("pip install sionna")os.kill(os.getpid(),5)else:raisee# IPython "magic function" for inline plots%matplotlib inlineimportmatplotlib.pyplotasplt

Let us first create aBinarySource to generate a random batch of bit vectors that we can map to constellation symbols:

[2]:
batch_size=1000# Number of symbols we want to generatenum_bits_per_symbol=4# 16-QAM has four bits per symbolbinary_source=sionna.phy.mapping.BinarySource()b=binary_source([batch_size,num_bits_per_symbol])b
[2]:
<tf.Tensor: shape=(1000, 4), dtype=float32, numpy=array([[0., 0., 0., 0.],       [1., 1., 1., 1.],       [0., 1., 1., 1.],       ...,       [1., 1., 1., 1.],       [1., 1., 1., 0.],       [0., 1., 1., 0.]], dtype=float32)>

Next, let us create aConstellation and visualize it:

[3]:
constellation=sionna.phy.mapping.Constellation("qam",num_bits_per_symbol)constellation.show();
../../_images/phy_tutorials_Hello_World_6_0.png

We now need aMapper that maps each row of b to the constellation symbols according to the bit labeling shown above.

[4]:
mapper=sionna.phy.mapping.Mapper(constellation=constellation)x=mapper(b)x[:10]
[4]:
<tf.Tensor: shape=(10, 1), dtype=complex64, numpy=array([[ 0.31622776+0.31622776j],       [-0.94868326-0.94868326j],       [ 0.94868326-0.94868326j],       [-0.31622776+0.94868326j],       [ 0.94868326-0.31622776j],       [ 0.94868326+0.31622776j],       [ 0.31622776-0.31622776j],       [-0.31622776-0.31622776j],       [-0.31622776-0.94868326j],       [-0.31622776-0.31622776j]], dtype=complex64)>

Let us now make things a bit more interesting a send our symbols over andAWGN channel:

[5]:
awgn=sionna.phy.channel.AWGN()ebno_db=15# Desired Eb/No in dBno=sionna.phy.utils.ebnodb2no(ebno_db,num_bits_per_symbol,coderate=1)y=awgn(x,no)# Visualize the received signalimportmatplotlib.pyplotaspltimportnumpyasnpfig=plt.figure(figsize=(7,7))ax=fig.add_subplot(111)plt.scatter(np.real(y),np.imag(y));ax.set_aspect("equal",adjustable="box")plt.xlabel("Real Part")plt.ylabel("Imaginary Part")plt.grid(True,which="both",axis="both")plt.title("Received Symbols");
../../_images/phy_tutorials_Hello_World_10_0.png