.. 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_4_3_2_reassigned_spectrogram.py: ======================================================== Comparison of a Spectrogram and a Reassigned Spectrogram ======================================================== This example compares the spectrogram and the reassigned spectrogram of a hybrid signal (containing sinusoidal, constant and linear frequency modulations), against its ideal time-frequency characteristics. Figure 4.34 from the tutorial. .. image:: /auto_examples/images/sphx_glr_plot_4_3_2_reassigned_spectrogram_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/tftb/envs/latest/lib/python3.7/site-packages/tftb/processing/reassigned.py:542: ComplexWarning: Casting complex values to real discards the imaginary part rtfr[int(jcolhat), int(icolhat) - 1] += tfr[jcol, icol] /home/docs/checkouts/readthedocs.org/user_builds/tftb/envs/latest/lib/python3.7/site-packages/numpy/ma/core.py:2786: ComplexWarning: Casting complex values to real discards the imaginary part order=order, subok=True, ndmin=ndmin) | .. code-block:: default from tftb.generators import fmsin, fmhyp from tftb.processing import ideal_tfr, reassigned_spectrogram, Spectrogram import numpy as np import matplotlib.pyplot as plt n_points = 128 sig1, if1 = fmsin(n_points, 0.15, 0.45, 100, 1, 0.4, -1) sig2, if2 = fmhyp(n_points, [1, .5], [32, 0.05]) sig = sig1 + sig2 ideal, t, f = ideal_tfr(np.vstack((if1, if2))) _, re_spec, _ = reassigned_spectrogram(sig) spec, t3, f3 = Spectrogram(sig).run() # Ideal tfr plt.subplot(221) plt.contour(t, f, ideal, 1) plt.grid(True) plt.gca().set_xticklabels([]) plt.title("Ideal time-frequency distro") plt.ylabel('Normalized Frequency') # Spectrogram plt.subplot(222) plt.contour(t3, f3[:64], spec[:64, :]) plt.grid(True) plt.gca().set_xticklabels([]) plt.title("Spectrogram") # Reassigned Spectrogram plt.subplot(212) f = np.linspace(0, 0.5, 64) plt.contour(np.arange(128), f, re_spec[:64, :]) plt.grid(True) plt.title("Reassigned Spectrogram") plt.xlabel('Time') plt.ylabel('Normalized Frequency') plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 2.149 seconds) .. _sphx_glr_download_auto_examples_plot_4_3_2_reassigned_spectrogram.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_4_3_2_reassigned_spectrogram.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_4_3_2_reassigned_spectrogram.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_