
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/plot_sin.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_plot_sin.py>`
        to download the full example code.

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

.. _sphx_glr_auto_examples_plot_sin.py:


Approximate a noisy signal
--------------------------

Here we add noise to a sinusoidal signal and approximate it.

.. GENERATED FROM PYTHON SOURCE LINES 7-31



.. image-sg:: /auto_examples/images/sphx_glr_plot_sin_001.png
   :alt: plot sin
   :srcset: /auto_examples/images/sphx_glr_plot_sin_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np
    import splinebox

    # Number of control points/knots
    M = 40
    # Number of data points
    N = 100

    x = np.linspace(0, 15, N)
    values = np.sin(x) + np.random.rand(N) / 3

    basis_function = splinebox.B3()
    spline = splinebox.Spline(M, basis_function, closed=False)
    spline.fit(values)

    ts = np.linspace(0, M - 1, 1000)
    spline_y = spline.eval(ts)
    spline_x = np.linspace(x.min(), x.max(), len(ts))

    plt.scatter(x, values, color="orange")
    plt.plot(spline_x, spline_y)
    plt.show()


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

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


.. _sphx_glr_download_auto_examples_plot_sin.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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