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/c18d5d82e541a1a8632187b61947723183a7ecf53e1235d9ff8b93cecf4ab61a.png ../../_images/5f00c9d110d6d1f5d6de1a8b7324facb308c1bc5fbd0b56c1284db5976b4526e.png

QPSK

qpsk = sdr.PSK(4, phase_offset=45, sps=10, pulse_shape="srrc")
analyze_psk(qpsk, 9)
../../_images/942a10c9943fa95b2fcedf68e9682bc59bb5132f13ab0b041ac4dc20cae7cc11.png ../../_images/27d74b134c837150a89f4923481dc2e7c142377a3ed6ba6d2871054e487f5800.png

8-PSK

psk8 = sdr.PSK(8, sps=10, pulse_shape="srrc")
analyze_psk(psk8, 12)
../../_images/154c0a52e5e5ce29b246113e870be88bc1797b04cf9d31849962b1d72dff38a1.png ../../_images/a45fa2b55d67d069c5dcdaf081bb8f46addbcf72776ed47060945a1b223c0093.png

16-PSK

psk16 = sdr.PSK(16, sps=10, pulse_shape="srrc")
analyze_psk(psk16, 18)
../../_images/e8b1624c842cc7769364784f43553ab2a5a467722f4feb589c1c8e8cf51b66d5.png ../../_images/4695e4a9508621b48ac6f45c07f9b6deaf1aaea6d1d55e523dc55cc6f4598d77.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/4950811dabea3a8b73807be998204b43a0860209cf8884c620d33226868343a1.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/1f65548ee65f4becfbef84efccff2344df57fa3ace8bd88d171b39293ade5ece.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/ef95e98cc9d540fef2cb885cf891a6214a924212783a68073e9eeecafa64ac9e.png

Last update: Jun 15, 2024