Simulation of an AWGN baseband transmission

This example emulates a real valued baseband transmission, including bit generation, mapping, pulseshaping, matched filtering, decision, demapping and ber counting.

The channel is emulated as AWGN channel with adjustable SNR.

Load required packages

[20]:
import numpy as np
try:
    # if you installed skcomm with pypi
    import skcomm  as skc
except:
    # if you like to use skcomm directly from source.
    # Please note: If you want to import skcomm into your file using this snippet, you must ensure that the file is on a directional level below skcomm.
    import sys, os
    current_parent_folder = os.path.abspath('..')
    sys.path.append(os.path.join(current_parent_folder))
    import skcomm as skc

Simulation parameters

[21]:
symbol_rate = 10.0
n_bits = 2**15
constellation = np.asarray([-3,3])
pulseshape = 'rrc'
roll_off = 0.1
snr = 20

Transmitter

[22]:
# Tx
sig_tx = skc.signal.Signal(n_dims=1)
sig_tx.generate_bits(n_bits=n_bits,seed=1)
sig_tx.symbol_rate = symbol_rate
# generate constellation (symbol alphabet)
sig_tx.constellation = constellation
# mapping
sig_tx.mapper()
# pulseshaping
upsampling = 15.0
sig_tx.pulseshaper(upsampling=upsampling,pulseshape=pulseshape,roll_off=roll_off)
sig_tx.plot_signal(boundaries=[0,int(upsampling*20)])
sig_tx.plot_eye(boundaries=[0,int(upsampling*1000)])
_ = sig_tx.plot_spectrum(scale='logNorm', resolution_bw=symbol_rate/100)
../_images/example_notebooks_sim_baseband_7_0.png
../_images/example_notebooks_sim_baseband_7_1.png
../_images/example_notebooks_sim_baseband_7_2.png

Channel

[23]:

# channel sig_tx.set_snr(snr_dB=snr) sig_tx.plot_signal(boundaries=[0,int(upsampling*20)]) sig_tx.plot_eye(histogram=True) _ = sig_tx.plot_spectrum(scale='logNorm',resolution_bw=symbol_rate/100)
../_images/example_notebooks_sim_baseband_9_0.png
../_images/example_notebooks_sim_baseband_9_1.png
../_images/example_notebooks_sim_baseband_9_2.png

Receiver

[24]:

# Rx sig_rx = sig_tx.copy() sig_rx.samples[0] = skc.filters.raised_cosine_filter(sig_rx.samples[0], sample_rate=sig_rx.sample_rate[0], symbol_rate=sig_rx.symbol_rate[0], roll_off=0.1, root_raised=True).real # sig_rx.samples[0] = skc.filters.ideal_lp(sig_rx.samples[0], 0.1)['samples_out'].real sig_rx.plot_signal(boundaries=[0,int(upsampling*20)]) sig_rx.plot_eye(histogram=True) sig_rx.plot_spectrum(scale='logNorm',resolution_bw=symbol_rate/100) # smpling sig_rx.samples[0] = sig_rx.samples[0][::15] sig_rx.plot_constellation(tit='Constallation after decimation') sig_rx.decision() sig_rx.plot_constellation(tit='Constallation after decision') sig_rx.demapper() ber = skc.rx.count_errors(sig_tx.bits[0], sig_rx.samples[0]) print(f"Bit error rate = {ber['ber']:.2e}")
../_images/example_notebooks_sim_baseband_11_0.png
../_images/example_notebooks_sim_baseband_11_1.png
../_images/example_notebooks_sim_baseband_11_2.png
Ignoring fixed y limits to fulfill fixed data aspect with adjustable data limits.
../_images/example_notebooks_sim_baseband_11_4.png
Ignoring fixed y limits to fulfill fixed data aspect with adjustable data limits.
../_images/example_notebooks_sim_baseband_11_6.png
Bit error rate = 0.00e+00