.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/communications/information/plot_04_shannon_hartley_capacity.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 or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_communications_information_plot_04_shannon_hartley_capacity.py: The Shannon-Hartley capacity of a noisy band-limited channel ============================================================ In "Communication in the presence of noise" (1949) Shannon proved that a channel of bandwidth :math:`B` with white Gaussian noise and signal-to-noise ratio :math:`S/N` can carry :math:`C = B\log_2(1 + S/N)` bits per second with arbitrarily small error (:func:`~engineeringkit.communications.shannon_capacity`), and no more. Writing :math:`S/N = (E_b/N_0)(C/B)` gives the minimum energy per bit for a given spectral efficiency. As bandwidth becomes unlimited the minimum tends to :math:`\ln 2`, or -1.59 dB, the *Shannon limit*. .. GENERATED FROM PYTHON SOURCE LINES 15-20 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from engineeringkit.communications import db, shannon_capacity, spectral_efficiency .. GENERATED FROM PYTHON SOURCE LINES 21-23 A telephone line and a Wi-Fi channel ------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 23-28 .. code-block:: Python for name, B, snr_db in [("telephone", 3.1e3, 35), ("Wi-Fi 20 MHz", 20e6, 25)]: C = float(shannon_capacity(B, 10 ** (snr_db / 10))) print(f"{name:14s}: C = {C / 1e3:9.1f} kbit/s, {float(spectral_efficiency(C, B)):.2f} bit/s/Hz") .. rst-class:: sphx-glr-script-out .. code-block:: none telephone : C = 36.0 kbit/s, 11.63 bit/s/Hz Wi-Fi 20 MHz : C = 166187.5 kbit/s, 8.31 bit/s/Hz .. GENERATED FROM PYTHON SOURCE LINES 29-34 The minimum Eb/N0 for each spectral efficiency ---------------------------------------------- On the boundary :math:`\eta = \log_2(1 + \eta E_b/N_0)`, so :math:`E_b/N_0 = (2^\eta - 1)/\eta`. .. GENERATED FROM PYTHON SOURCE LINES 34-51 .. code-block:: Python eta = np.logspace(-3, np.log10(10), 200) ebn0_min = (2**eta - 1) / eta assert np.allclose(shannon_capacity(1.0, eta * ebn0_min), eta) print(f"Shannon limit as eta -> 0: {float(db(ebn0_min[0])):.3f} dB (ln 2 = {float(db(np.log(2))):.3f} dB)") fig, axes = plt.subplots(1, 2, figsize=(9, 3.6)) snr = np.linspace(-10, 40, 200) axes[0].plot(snr, shannon_capacity(1.0, 10 ** (snr / 10))) axes[0].set(xlabel="S/N [dB]", ylabel="C / B [bit/s/Hz]", title="Capacity grows ~1 bit per 3 dB") axes[1].semilogy(db(ebn0_min), eta) axes[1].axvline(float(db(np.log(2))), color="gray", ls="--", label="-1.59 dB") axes[1].fill_betweenx(eta, db(ebn0_min), -2, color="C3", alpha=0.15, label="impossible") axes[1].set(xlim=(-2, 15), xlabel="$E_b/N_0$ [dB]", ylabel="spectral efficiency [bit/s/Hz]") axes[1].legend() fig.tight_layout() plt.show() .. image-sg:: /api/gallery/communications/information/images/sphx_glr_plot_04_shannon_hartley_capacity_001.png :alt: Capacity grows ~1 bit per 3 dB :srcset: /api/gallery/communications/information/images/sphx_glr_plot_04_shannon_hartley_capacity_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Shannon limit as eta -> 0: -1.590 dB (ln 2 = -1.592 dB) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.267 seconds) .. _sphx_glr_download_api_gallery_communications_information_plot_04_shannon_hartley_capacity.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/communications/information/plot_04_shannon_hartley_capacity.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_shannon_hartley_capacity.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_shannon_hartley_capacity.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_shannon_hartley_capacity.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_