.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/communications/decibels/plot_01_bell_decibel.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_decibels_plot_01_bell_decibel.py: The decibel: the Bell System's transmission unit ================================================ Early telephone engineers measured loss in "miles of standard cable", a unit that depended on frequency. In 1924 the Bell System replaced it with the *transmission unit*, ten times the base-ten logarithm of a power ratio, and in 1929 W. H. Martin named it the decibel. Logarithms turn the products of gains and losses along a line into sums, so a long chain of amplifiers and cables can be budgeted by addition. :func:`~engineeringkit.communications.db`, :func:`~engineeringkit.communications.dbm` and their inverses convert both ways. .. GENERATED FROM PYTHON SOURCE LINES 15-20 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from engineeringkit.communications import db, dbm, from_db, from_dbm .. GENERATED FROM PYTHON SOURCE LINES 21-25 Products become sums -------------------- A 1 mW source feeds a chain of cable sections (loss) and repeaters (gain). .. GENERATED FROM PYTHON SOURCE LINES 25-32 .. code-block:: Python stages = [("cable", 0.05), ("repeater", 40.0), ("cable", 0.02), ("repeater", 25.0), ("cable", 0.1)] linear = 1e-3 * np.prod([g for _, g in stages]) in_db = float(dbm(1e-3)) + sum(float(db(g)) for _, g in stages) print(f"linear product: {linear:.4e} W, decibel sum: {in_db:.2f} dBm -> {float(from_dbm(in_db)):.4e} W") assert np.isclose(from_dbm(in_db), linear) .. rst-class:: sphx-glr-script-out .. code-block:: none linear product: 1.0000e-04 W, decibel sum: -10.00 dBm -> 1.0000e-04 W .. GENERATED FROM PYTHON SOURCE LINES 33-35 Reference points worth memorising --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-50 .. code-block:: Python for ratio in [2, 10, 100, 0.5]: print(f"x{ratio:<5} = {float(db(ratio)):+6.2f} dB") assert np.isclose(from_db(3.0103), 2, rtol=1e-4) level = [float(dbm(1e-3))] for _, g in stages: level.append(level[-1] + float(db(g))) fig, ax = plt.subplots(figsize=(6.5, 3.5)) ax.step(range(len(level)), level, where="post") ax.set_xticks(range(len(level)), ["source"] + [name for name, _ in stages], rotation=30) ax.set(ylabel="signal level [dBm]", title="A decibel level diagram") fig.tight_layout() plt.show() .. image-sg:: /api/gallery/communications/decibels/images/sphx_glr_plot_01_bell_decibel_001.png :alt: A decibel level diagram :srcset: /api/gallery/communications/decibels/images/sphx_glr_plot_01_bell_decibel_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none x2 = +3.01 dB x10 = +10.00 dB x100 = +20.00 dB x0.5 = -3.01 dB .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.092 seconds) .. _sphx_glr_download_api_gallery_communications_decibels_plot_01_bell_decibel.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/decibels/plot_01_bell_decibel.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_bell_decibel.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_bell_decibel.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_bell_decibel.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_