.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/foundations/plot_05_information_rates.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_foundations_plot_05_information_rates.py: Information rates of QAM ======================== The mutual information :math:`I(X; Y)` of a constellation over AWGN is the rate a receiver that decodes symbols can achieve; the generalised mutual information (GMI) is the rate of a bit-interleaved receiver that decodes bits independently, the usual coded-modulation receiver. Both stay below the Shannon capacity :math:`\log_2(1 + \mathrm{SNR})` and saturate at :math:`\log_2 M`; with Gray labels the gap between them is small. The curves are computed by Gauss–Hermite quadrature (:func:`comnum.theory_mi`, :func:`comnum.theory_gmi`); the markers are Monte Carlo estimates on 100 000 noisy 16-QAM symbols (:func:`comnum.information_rates`). .. GENERATED FROM PYTHON SOURCE LINES 16-57 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import comnum from comnum.plot import BACKGROUND, GREY, ORANGE snr = np.arange(-5.0, 30.5, 1.0) fig, ax = plt.subplots() ax.plot(snr, np.log2(1 + comnum.db2lin(snr)), color=GREY, linewidth=1.4, label="Shannon capacity") for m in [4, 16, 64]: mi = [comnum.theory_mi(m, s, "qam") for s in snr] gmi = [comnum.theory_gmi(m, s, "qam") for s in snr] (line,) = ax.plot(snr, mi, label=f"{m}-QAM, MI") ax.plot(snr, gmi, color=line.get_color(), linestyle="--", linewidth=1.4, label=f"{m}-QAM, GMI") # Monte Carlo estimates for 16-QAM c = comnum.Constellation("qam", 16).normalized() est = [] for i, s in enumerate(snr[::3]): rng = comnum.Rng.stream(11, "mi", i, 0) idx, x = comnum.symbols(c, 100_000, rng) est.append(comnum.information_rates(comnum.awgn(x, s, rng), idx, c)) ax.plot( snr[::3], [e["mi"] for e in est], "o", color=ORANGE, markeredgecolor=BACKGROUND, label="16-QAM, MI simulated", ) ax.set( xlabel="SNR $E_s/N_0$ (dB)", ylabel="bits per symbol", xlim=(-5, 30), ylim=(0, 7), title="Information rates over AWGN", ) ax.legend(ncol=2, loc="lower right") fig.tight_layout() .. image-sg:: /auto_examples/foundations/images/sphx_glr_plot_05_information_rates_001.png :alt: Information rates over AWGN :srcset: /auto_examples/foundations/images/sphx_glr_plot_05_information_rates_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-61 The gap to capacity at 3.5 bits per symbol, which needs an SNR of 10 log10(2^3.5 - 1) = 10.13 dB: 16-QAM, close to saturation, is 1.4 dB away; 64-QAM 0.7 dB (what remains is the shaping gap of uniform square constellations). .. GENERATED FROM PYTHON SOURCE LINES 61-70 .. code-block:: Python target = 3.5 for m in [16, 64]: lo, hi = 0.0, 30.0 for _ in range(50): mid = (lo + hi) / 2 lo, hi = (lo, mid) if comnum.theory_mi(m, mid, "qam") > target else (mid, hi) print( f"{m}-QAM reaches {target} bits/symbol at {lo:.2f} dB (capacity: {comnum.lin2db(2**target - 1):.2f} dB)" ) .. rst-class:: sphx-glr-script-out .. code-block:: none 16-QAM reaches 3.5 bits/symbol at 11.57 dB (capacity: 10.13 dB) 64-QAM reaches 3.5 bits/symbol at 10.84 dB (capacity: 10.13 dB) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 14.690 seconds) .. _sphx_glr_download_auto_examples_foundations_plot_05_information_rates.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_05_information_rates.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_05_information_rates.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_05_information_rates.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_