
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/detect/plot_oscillation_detection.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_detect_plot_oscillation_detection.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_detect_plot_oscillation_detection.py:


=====================================================
Oscillation detection using linear predictive coding
=====================================================

Identifies if a signal contains one or more oscillatory components, based on a method described by Sharma et al.

.. GENERATED FROM PYTHON SOURCE LINES 9-53



.. rst-class:: sphx-glr-horizontal


    *

      .. image-sg:: /auto_examples/detect/images/sphx_glr_plot_oscillation_detection_001.png
         :alt: Signal, Power Spectral Density, LPC Roots in z-plane
         :srcset: /auto_examples/detect/images/sphx_glr_plot_oscillation_detection_001.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /auto_examples/detect/images/sphx_glr_plot_oscillation_detection_002.png
         :alt: Correlation coefficient, Normalized FFT magnitude spectrum, Power Spectral Density
         :srcset: /auto_examples/detect/images/sphx_glr_plot_oscillation_detection_002.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /auto_examples/detect/images/sphx_glr_plot_oscillation_detection_003.png
         :alt: frequency regions where oscillation detected
         :srcset: /auto_examples/detect/images/sphx_glr_plot_oscillation_detection_003.png
         :class: sphx-glr-multi-img





.. code-block:: Python


    import os

    import matplotlib.pyplot as plt
    import numpy as np
    import pandas as pd

    from indsl.detect.oscillation_detector import helper_oscillation_detector, oscillation_detector


    # brownian noise wave signal
    base_path = "" if __name__ == "__main__" else os.path.dirname(__file__)
    data = pd.read_csv(os.path.join(base_path, "../../datasets/data/brownian_noise_wave.csv"), index_col=0).squeeze(
        "columns"
    )

    # convert str to datetime
    data.index = pd.to_datetime(data.index)

    # call oscillation detector function
    results = oscillation_detector(data)

    # output dictionary
    dict_output = helper_oscillation_detector(data)

    # plot the results
    fig, ax = plt.subplots(1, 1, figsize=[10, 5])

    ax.plot(
        results.index,
        results.values,
        color="blue",
        linestyle="dashed",
        linewidth=1,
        markersize=1,
        marker=".",
    )

    ax.set_xlabel("freq (Hz)")
    ax.set_ylabel("detection (1: detected, 0: no detection)")
    ax.set_title("frequency regions where oscillation detected")
    ax.plot(results.index[np.where(results.values == 1)], 1, "go", markersize=8, alpha=0.5)

    plt.show()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.739 seconds)


.. _sphx_glr_download_auto_examples_detect_plot_oscillation_detection.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_oscillation_detection.ipynb <plot_oscillation_detection.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_oscillation_detection.py <plot_oscillation_detection.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_oscillation_detection.zip <plot_oscillation_detection.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
