.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_tukey.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_plot_tukey.py: Tukey Filter - 2D Fault ============================================================================================================ Generate a Tukey window :return: [description] :rtype: [type] .. GENERATED FROM PYTHON SOURCE LINES 9-55 .. image-sg:: /auto_examples/images/sphx_glr_plot_tukey_001.png :alt: Tukey Window (alpha=0.4) :srcset: /auto_examples/images/sphx_glr_plot_tukey_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib.pyplot as plt def tukey_window(N, alpha=0.5): """ Genera una ventana Tukey. Parámetros: - N: Longitud de la ventana. - alpha: Parámetro de apertura (0 para una ventana rectangular, 1 para una ventana Hann). Retorna: - Ventana Tukey. """ if alpha <= 0: return np.ones(N) elif alpha >= 1: return np.hanning(N) else: x = np.linspace(0, 1, N, endpoint=False) w = np.ones_like(x) # Aplica la parte de la ventana Hann first_condition = x < alpha / 2 last_condition = x >= 1 - alpha / 2 w[first_condition] = 0.5 * (1 + np.cos(2 * np.pi / alpha * (x[first_condition] - alpha / 2))) w[last_condition] = 0.5 * (1 + np.cos(2 * np.pi / alpha * (x[last_condition] - 1 + alpha / 2))) # Ajusta los valores para que no alcancen completamente cero al comienzo y al final w[first_condition] = 0.5 + 0.5 * w[first_condition] w[last_condition] = 0 + 1 * w[last_condition] return w # Ejemplo de uso N = 100 alpha = 0.4 tukey = tukey_window(N, alpha) # Visualización de la ventana Tukey plt.plot(tukey) plt.title(f'Tukey Window (alpha={alpha})') plt.xlabel('Muestras') plt.ylabel('Amplitud') plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.064 seconds) .. _sphx_glr_download_auto_examples_plot_tukey.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_tukey.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_tukey.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_