.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/fourier_transform.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_examples_fourier_transform.py: Fourier transform ================= The graph Fourier transform :meth:`pygsp.graphs.Graph.gft` transforms a signal from the vertex domain to the spectral domain. The smoother the signal (see :meth:`pygsp.graphs.Graph.dirichlet_energy`), the lower in the frequencies its energy is concentrated. .. GENERATED FROM PYTHON SOURCE LINES 10-48 .. image-sg:: /examples/images/sphx_glr_fourier_transform_001.png :alt: $x^T L x = 0.30$, $x^T L x = 1.55$, $x^T L x = 5.43$ :srcset: /examples/images/sphx_glr_fourier_transform_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np from matplotlib import pyplot as plt import pygsp as pg G = pg.graphs.Sensor(seed=42) G.compute_fourier_basis() scales = [10, 3, 0] limit = 0.44 fig, axes = plt.subplots(2, len(scales), figsize=(12, 4)) fig.subplots_adjust(hspace=0.5) x0 = np.random.default_rng(1).normal(size=G.N) for i, scale in enumerate(scales): g = pg.filters.Heat(G, scale) x = g.filter(x0).squeeze() x /= np.linalg.norm(x) x_hat = G.gft(x).squeeze() assert np.all((-limit < x) & (x < limit)) G.plot(x, limits=[-limit, limit], ax=axes[0, i]) axes[0, i].set_axis_off() axes[0, i].set_title(f"$x^T L x = {G.dirichlet_energy(x):.2f}$") axes[1, i].plot(G.e, np.abs(x_hat), ".-") axes[1, i].set_xticks(range(0, 16, 4)) axes[1, i].set_xlabel(r"graph frequency $\lambda$") axes[1, i].set_ylim(-0.05, 0.95) axes[1, 0].set_ylabel(r"frequency content $\hat{x}(\lambda)$") # axes[0, 0].set_title(r'$x$: signal in the vertex domain') # axes[1, 0].set_title(r'$\hat{x}$: signal in the spectral domain') fig.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.458 seconds) **Estimated memory usage:** 160 MB .. _sphx_glr_download_examples_fourier_transform.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: fourier_transform.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: fourier_transform.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: fourier_transform.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_