.. only:: html .. 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_comodulogram.py: Comodulogram ------------ This example creates an artificial signal with phase-amplitude coupling (PAC) and computes comodulograms with several methods. A comodulogram shows the estimated PAC metric on a grid of frequency bands. .. code-block:: default import numpy as np import matplotlib.pyplot as plt from pactools import Comodulogram, REFERENCES from pactools import simulate_pac Let's first create an artificial signal with PAC. .. code-block:: default fs = 200. # Hz high_fq = 50.0 # Hz low_fq = 5.0 # Hz low_fq_width = 1.0 # Hz n_points = 10000 noise_level = 0.4 signal = simulate_pac(n_points=n_points, fs=fs, high_fq=high_fq, low_fq=low_fq, low_fq_width=low_fq_width, noise_level=noise_level, random_state=0) Then, let's define the range of low frequency, and the list of methods used .. code-block:: default low_fq_range = np.linspace(1, 10, 50) methods = [ 'ozkurt', 'canolty', 'tort', 'penny', 'vanwijk', 'duprelatour', 'colgin', 'sigl', 'bispectrum' ] To compute the comodulogram, we need to instanciate a `Comodulogram` object, then call the method `fit`. The method `plot` draws the results on the given subplot axes. .. code-block:: default # Define the subplots where the comodulogram will be plotted n_lines = 3 n_columns = int(np.ceil(len(methods) / float(n_lines))) fig, axs = plt.subplots( n_lines, n_columns, figsize=(4 * n_columns, 3 * n_lines)) axs = axs.ravel() # Compute the comodulograms and plot them for ax, method in zip(axs, methods): print('%s... ' % (method, )) estimator = Comodulogram(fs=fs, low_fq_range=low_fq_range, low_fq_width=low_fq_width, method=method, progress_bar=False) estimator.fit(signal) estimator.plot(titles=[REFERENCES[method]], axs=[ax]) plt.show() .. image:: /auto_examples/images/sphx_glr_plot_comodulogram_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ozkurt... canolty... tort... penny... vanwijk... duprelatour... colgin... sigl... bispectrum... /home/tom/work/github/pactools/examples/plot_comodulogram.py:62: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 13.248 seconds) .. _sphx_glr_download_auto_examples_plot_comodulogram.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_comodulogram.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_comodulogram.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_