.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/signal_processing/plot_signal_processing_benchmark.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_signal_processing_plot_signal_processing_benchmark.py: Aliasing before reconstruction ============================== A 70 Hz cosine sampled at 100 Hz is indistinguishable from a 30 Hz cosine. Checking the samples demonstrates why filtering after sampling cannot recover the original frequency. .. GENERATED FROM PYTHON SOURCE LINES 9-29 .. image-sg:: /api/gallery/signal_processing/images/sphx_glr_plot_signal_processing_benchmark_001.png :alt: plot signal processing benchmark :srcset: /api/gallery/signal_processing/images/sphx_glr_plot_signal_processing_benchmark_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from engineeringkit.signal_processing import alias_frequency fs, frequency = 100, 70 t = np.arange(20) / fs alias = alias_frequency(frequency, fs) assert np.isclose(alias, 30) np.testing.assert_allclose(np.cos(2 * np.pi * frequency * t), np.cos(2 * np.pi * alias * t), atol=1e-13) fine = np.linspace(0, t[-1], 2001) fig, ax = plt.subplots() ax.plot(fine, np.cos(2 * np.pi * frequency * fine), label="70 Hz") ax.plot(fine, np.cos(2 * np.pi * alias * fine), linestyle="--", label="30 Hz alias") ax.plot(t, np.cos(2 * np.pi * frequency * t), "ko", label="samples") ax.set(xlabel="time [s]", ylabel="amplitude") ax.legend() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.100 seconds) .. _sphx_glr_download_api_gallery_signal_processing_plot_signal_processing_benchmark.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/signal_processing/plot_signal_processing_benchmark.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_signal_processing_benchmark.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_signal_processing_benchmark.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_signal_processing_benchmark.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_