First Simulation#
This tutorial guides you through running a simple communication simulation using comnumpy. You will create a basic QAM communication chain, transmit symbols through an AWGN channel, and evaluate the Symbol Error Rate (SER).
Prerequisites#
Make sure you have installed:
numpy
matplotlib
comnumpy
Step 1: Import Libraries and Define Parameters#
First, import the necessary libraries and define simulation parameters:
import numpy as np
import matplotlib.pyplot as plt
from comnumpy.core import Sequential, Recorder
from comnumpy.core.generators import SymbolGenerator
from comnumpy.core.mappers import SymbolMapper
from comnumpy.core.channels import AWGN
from comnumpy.core.utils import get_alphabet
from comnumpy.core.metrics import compute_ser
img_dir = "../../docs/getting_started/img/"
# parameters
M = 4 # Modulation order (4-QAM)
N = 1000 # Number of symbols
alphabet = get_alphabet("QAM", M)
snr_dB = 10 # Signal-to-Noise Ratio in dB
Step 2: Define Communication Chain#
Define the communication chain using the Sequential class, including symbol generation, mapping, and channel:
# define a communication chain
chain = Sequential([
SymbolGenerator(M),
Recorder(name="data_tx"),
SymbolMapper(alphabet),
AWGN(value=snr_dB, unit="snr_dB", name="awgn_channel"),
])
# test chain
y = chain(N)
Step 3: Run the Chain and Evaluate Performance#
Run the chain and compute the SER to assess system performance:
# estimate performance
data_tx = chain["data_tx"].get_data()
ser = compute_ser(data_tx, y)
print(f"SER = {ser}")
Step 4: Visualize the Received Constellation#
Finally, plot the received symbols to visualize the effect of noise on the constellation:
# plot signals
plt.scatter(np.real(y), np.imag(y))
plt.title("Received Constellation Diagram")
plt.xlabel("In-phase")
plt.ylabel("Quadrature")
plt.grid(True)

Next Steps#
Now that you’ve completed your first simulation, consider exploring:
OFDM and MIMO tutorials for advanced communication techniques.
The full comnumpy documentation for detailed API reference.
Experimenting by changing modulation orders, SNR, and channel models.