.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "signal_processor/plot_1_polynomial.py" .. LINE NUMBERS ARE GIVEN BELOW. .. 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_signal_processor_plot_1_polynomial.py: Polynomial Offset ^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 7-12 In this example, we will use the :py:class:`~mrsimulator.signal_processor.baseline.Polynomial` class to offset the baseline of a dataset by a polynomial function. Below we import the necessary modules .. GENERATED FROM PYTHON SOURCE LINES 12-17 .. code-block:: default import csdmpy as cp import numpy as np from mrsimulator import signal_processor as sp .. GENERATED FROM PYTHON SOURCE LINES 19-27 First we create ``processor``, an instance of the :py:class:`~mrsimulator.signal_processor.SignalProcessor` class. The required attribute of the SignalProcessor class, *operations*, is a list of operations to which we add a :py:class:`~mrsimulator.signal_processor.baseline.Polynomial` object. The required argument for the polynomial offset is *polynomial_dictionary* which is a Python dict defining the polynomial coefficients. An arbitrary number of coefficients may be passed. .. GENERATED FROM PYTHON SOURCE LINES 27-33 .. code-block:: default processor = sp.SignalProcessor( operations=[ sp.baseline.Polynomial(polynomial_dictionary={"c0": 0.2, "c2": 0.00001}) ] ) .. GENERATED FROM PYTHON SOURCE LINES 34-43 Here the applied offset will be the following function .. math:: f(x) = 0.00001 \cdot x^2 + 0.2 Next we create a CSDM object with a test dataset which our signal processor will operate on. Here, the dataset spans 500 Hz with a delta function centered at 100 Hz. .. GENERATED FROM PYTHON SOURCE LINES 43-50 .. code-block:: default test_data = np.zeros(500) test_data[350] = 1 csdm_object = cp.CSDM( dependent_variables=[cp.as_dependent_variable(test_data)], dimensions=[cp.LinearDimension(count=500, increment="1 Hz", complex_fft=True)], ) .. GENERATED FROM PYTHON SOURCE LINES 51-54 Now to apply the processor to the CSDM object, use the :py:meth:`~mrsimulator.signal_processor.SignalProcessor.apply_operations` method as follows .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: default processed_dataset = processor.apply_operations(dataset=csdm_object.copy()).real .. GENERATED FROM PYTHON SOURCE LINES 57-59 To see the results of the exponential apodization, we create a simple plot using the ``matplotlib`` library. .. GENERATED FROM PYTHON SOURCE LINES 59-70 .. code-block:: default import matplotlib.pyplot as plt fig, ax = plt.subplots(1, 2, figsize=(8, 3.5), subplot_kw={"projection": "csdm"}) ax[0].plot(csdm_object, color="black", linewidth=1) ax[0].set(ylim=(-0.1, 1.5)) ax[0].set_title("Before") ax[1].plot(processed_dataset.real, color="black", linewidth=1) ax[1].set(ylim=(-0.1, 1.5)) ax[1].set_title("After") plt.tight_layout() plt.show() .. image-sg:: /signal_processor/images/sphx_glr_plot_1_polynomial_001.png :alt: Before, After :srcset: /signal_processor/images/sphx_glr_plot_1_polynomial_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.374 seconds) .. _sphx_glr_download_signal_processor_plot_1_polynomial.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_1_polynomial.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_1_polynomial.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_