.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_2_2_1_time_freq_localization.py: =============================================== Time and Frequency Localization Characteristics =============================================== Generate a signal that has localized characteristics in both time and frequency and compute the following estimates: * time center * time duration * frequency center * frequency spreading Example 2.1 from the tutorial. .. image:: /auto_examples/images/sphx_glr_plot_2_2_1_time_freq_localization_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Time Center: 127.00000000000001 Time Duration: 32.0 Frequency Center: 0.24901960784313726 Frequency Spreading: 0.07009643234823573 | .. code-block:: default from tftb.generators import fmlin, amgauss from tftb.processing import loctime, locfreq import numpy as np import matplotlib.pyplot as plt # generate signal signal = fmlin(256)[0] * amgauss(256) plt.subplot(211), plt.plot(np.real(signal)) plt.xlim(0, 256) plt.xlabel('Time') plt.ylabel('Real part') plt.title('Signal') plt.grid() fsig = np.fft.fftshift(np.abs(np.fft.fft(signal)) ** 2) plt.subplot(212), plt.plot(np.linspace(0, 0.5, 256), fsig) plt.xlabel('Normalized frequency') plt.ylabel('Squared modulus') plt.title('Spectrum') plt.grid() plt.subplots_adjust(hspace=0.5) plt.show() tm, T = loctime(signal) print("Time Center: {}".format(tm)) print("Time Duration: {}".format(T)) num, B = locfreq(signal) print("Frequency Center: {}".format(num)) print("Frequency Spreading: {}".format(B)) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.240 seconds) .. _sphx_glr_download_auto_examples_plot_2_2_1_time_freq_localization.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_2_2_1_time_freq_localization.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_2_2_1_time_freq_localization.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_