Phase-shift keying

import matplotlib.pyplot as plt
import numpy as np

import sdr

%config InlineBackend.print_figure_kwargs = {"facecolor" : "w"}
%matplotlib inline
# %matplotlib widget

sdr.plot.use_style()

In the sdr library, phase-shift keying modulation is available in the sdr.PSK class.

def analyze_psk(psk, esn0):
    # Generate random decimal symbols
    s = np.random.randint(0, psk.order, 100_000)

    # Modulate decimal symbols to complex symbols
    x = psk.map_symbols(s)

    # Add AWGN to complex symbols to achieve desired Es/N0
    snr = sdr.esn0_to_snr(esn0, sps=1)
    x_hat = sdr.awgn(x, snr)

    plt.figure()
    plt.subplot(1, 2, 1)
    sdr.plot.symbol_map(psk.symbol_map, limits=(-2, 2))
    plt.subplot(1, 2, 2)
    sdr.plot.constellation(x_hat, persistence=True, bins=150, limits=(-2, 2))
    plt.title(f"Constellation at {esn0} dB $E_s/N_0$")
    plt.suptitle(f"{psk.order}-PSK constellation")
    plt.show()

    y = psk.modulate(s)
    # h_srrc = sdr.root_raised_cosine(0.1, 6, sps)
    # tx_mf = sdr.Interpolator(sps, h_srrc)
    # y = tx_mf(x)

    plt.figure()
    sdr.plot.time_domain(y[0:1000])
    plt.show()

Constellations

BPSK

bpsk = sdr.PSK(2, sps=10, pulse_shape="srrc")
analyze_psk(bpsk, 6)
../../_images/02e831c2abbe2fc2956b8d0be5f54e14cd2950b2e0bd25ce97a4a2039a21f1ad.png ../../_images/e8b4868c7408607dcd0dbbc4d6590f6e11876eacbcbcb7d1af281f4ad71460f8.png

QPSK

qpsk = sdr.PSK(4, phase_offset=45, sps=10, pulse_shape="srrc")
analyze_psk(qpsk, 9)
../../_images/852ae391fc5011272d7ea659f4d5d2e44b530ad497e11602d177c92a52a27cd1.png ../../_images/f3d46971baf13ae8ebd89c4f180d03ff484a94da0688791b115ff756160cdf68.png

8-PSK

psk8 = sdr.PSK(8, sps=10, pulse_shape="srrc")
analyze_psk(psk8, 12)
../../_images/25861eef504f7bfada2a8bbbe31f28e4818a39e0c6d193937bb0cee24f6bbf13.png ../../_images/e7ba5ee462b925e1d3b4026e2ecb91003642ee5ffb6d477e39a8844f3ef5648d.png

16-PSK

psk16 = sdr.PSK(16, sps=10, pulse_shape="srrc")
analyze_psk(psk16, 18)
../../_images/5fdef9e6805adacdeb0a06360873943663d009b23675cca1326e312ec0fdbdc5.png ../../_images/49bd2d18c5dc533ba0e1b931115fe16a82d8ed1d956c2b62d64f3a374ac438d9.png

Error rate curves

def error_rates(psk, ebn0):
    esn0 = sdr.ebn0_to_esn0(ebn0, psk.bps)
    snr = sdr.esn0_to_snr(esn0)

    ber = sdr.ErrorRate()
    ser = sdr.ErrorRate()

    for i in range(snr.size):
        s = np.random.randint(0, psk.order, int(1e6))
        a = psk.map_symbols(s)
        a_tilde = sdr.awgn(a, snr[i])
        s_hat, a_hat = psk.decide_symbols(a_tilde)

        ber.add(ebn0[i], sdr.unpack(s, psk.bps), sdr.unpack(s_hat, psk.bps))
        ser.add(esn0[i], s, s_hat)

    return ber, ser
ebn0 = np.linspace(-2, 10, 20)

bpsk_ber, bpsk_ser = error_rates(bpsk, ebn0)
qpsk_ber, qpsk_ser = error_rates(qpsk, ebn0)
psk8_ber, psk8_ser = error_rates(psk8, ebn0)
psk16_ber, psk16_ser = error_rates(psk16, ebn0)

Bit error rate curves

plt.figure()
ebn0 = np.linspace(-2, 10, 200)
sdr.plot.ber(ebn0, bpsk.ber(ebn0), label="BPSK theoretical")
sdr.plot.ber(ebn0, qpsk.ber(ebn0), label="QPSK theoretical")
sdr.plot.ber(ebn0, psk8.ber(ebn0), label="8-PSK theoretical")
sdr.plot.ber(ebn0, psk16.ber(ebn0), label="16-PSK theoretical")
plt.gca().set_prop_cycle(None)
sdr.plot.ber(*bpsk_ber.error_rates(), linestyle="none", marker=".", label="BPSK simulated")
sdr.plot.ber(*qpsk_ber.error_rates(), linestyle="none", marker=".", label="QPSK simulated")
sdr.plot.ber(*psk8_ber.error_rates(), linestyle="none", marker=".", label="8-PSK simulated")
sdr.plot.ber(*psk16_ber.error_rates(), linestyle="none", marker=".", label="16-PSK simulated")
plt.ylim(1e-6, 1e0)
plt.title("Bit error rate curves for PSK modulation in AWGN")
plt.show()
../../_images/b8e71366ca6d6729996158b9042ac9865966b59bab439797bd7da598d612c0c7.png

Symbol error rate curves

plt.figure()
esn0 = np.linspace(-4, 16, 200)
sdr.plot.ser(esn0, bpsk.ser(esn0), label="BPSK theoretical")
sdr.plot.ser(esn0, qpsk.ser(esn0), label="QPSK theoretical")
sdr.plot.ser(esn0, psk8.ser(esn0), label="8-PSK theoretical")
sdr.plot.ser(esn0, psk16.ser(esn0), label="16-PSK theoretical")
plt.gca().set_prop_cycle(None)
sdr.plot.ser(*bpsk_ser.error_rates(), linestyle="none", marker=".", label="BPSK simulated")
sdr.plot.ser(*qpsk_ser.error_rates(), linestyle="none", marker=".", label="QPSK simulated")
sdr.plot.ser(*psk8_ser.error_rates(), linestyle="none", marker=".", label="8-PSK simulated")
sdr.plot.ser(*psk16_ser.error_rates(), linestyle="none", marker=".", label="16-PSK simulated")
plt.ylim(1e-6, 1e0)
plt.title("Symbol error rate curves for PSK modulation in AWGN")
plt.show()
../../_images/60d3e7a3d98ff97c5a460519ac4d228b289cd5da1c0612eedf24b2cb91512437.png

Symbol mapping

The mapping of decimal symbols to complex symbols is important. Ideally, adjacent symbol errors only result in 1 bit error. This is generally accomplished using a Gray code (the default in :class:sdr.PSK).

psk8_bin = sdr.PSK(8, symbol_labels="bin")
psk8_gray = sdr.PSK(8, symbol_labels="gray")
plt.figure()
plt.subplot(1, 2, 1)
sdr.plot.symbol_map(psk8_bin.symbol_map, limits=(-2, 2))
plt.title(f"Symbol map for binary coded 8-PSK")
plt.subplot(1, 2, 2)
sdr.plot.symbol_map(psk8_gray.symbol_map, limits=(-2, 2))
plt.title(f"Symbol map for gray coded 8-PSK")
plt.show()
../../_images/d29f96a16e88f226afd4150685e5e7d707eb70c9e83f5acb6f39357002bec90f.png

Since adjacent symbol errors can lead to multiple bit errors, binary-coded 8-PSK has worse bit error performance.

plt.figure()
ebn0 = np.linspace(-2, 10, 200)
sdr.plot.ber(ebn0, sdr.PSK(8, symbol_labels="bin").ber(ebn0), label="8-PSK w/ binary code")
sdr.plot.ber(ebn0, sdr.PSK(8, symbol_labels="gray").ber(ebn0), label="8-PSK w/ gray code")
plt.title("Bit error rate curves for 8-PSK modulation in AWGN")
plt.show()
../../_images/53580547e952d6b4c9d82a22307d1aae0f508f2451f98c20b2b2aa277d6bf270.png

Last update: May 18, 2024