.. 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_Phase_examples_plot_phase_example_1.py: ======================= Phase basic functions ======================= This example shows how to use the Phase functions .. code-block:: python # import matplotlib # matplotlib.use('TkAgg') import matplotlib.pyplot as plt from os.path import join, isdir import seaborn as sns from phase_utils import * sns.set() sns.set_context('paper') Parameters .. code-block:: python fs = 256 tmax = 0.7 data_dirpath = join('pySAB', 'sample_data') if isdir('pySAB') else join('..', '..', 'pySAB', 'sample_data') Load the example EEG signal and visualize it .. code-block:: python x = np.fromfile(join(data_dirpath, 'rec_042_chan_EEG_Cp1-Cp2_trial_1_2048Hz.dat')) f = plt.figure() ax = f.add_subplot(111) plt.plot(np.linspace(0, tmax, len(x)), x) plt.autoscale(axis='x', tight=True) ax.set(title='Raw signal', xlabel='Time (s)', ylabel='Amplitude') .. image:: /auto_examples/Phase_examples/images/sphx_glr_plot_phase_example_1_001.png :class: sphx-glr-single-img Filter the signal in the alpha band ``bp_filter_1d()`` allows to visualize the bode diagram of the filter .. code-block:: python x_alpha, _ = bp_filter_1d(x, fs, ftype='elliptic', wn=2 / fs * np.array([8, 12]), order=3, do_plot=1) .. image:: /auto_examples/Phase_examples/images/sphx_glr_plot_phase_example_1_002.png :class: sphx-glr-single-img Plot the analytical signal .. code-block:: python plot_analytical_signal(x_alpha, fs) .. image:: /auto_examples/Phase_examples/images/sphx_glr_plot_phase_example_1_003.png :class: sphx-glr-single-img Compute the robust phase estimation .. code-block:: python compute_robust_estimation(x, fs, fmin=8, fmax=12, f_tolerance=0.1, noise_tolerance=1, n_monte_carlo=20, do_fplot=0, do_plot=1) .. image:: /auto_examples/Phase_examples/images/sphx_glr_plot_phase_example_1_004.png :class: sphx-glr-single-img **Total running time of the script:** ( 0 minutes 0.428 seconds) .. _sphx_glr_download_auto_examples_Phase_examples_plot_phase_example_1.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_phase_example_1.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_phase_example_1.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_