.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "signal_processor/plot_3_gaussian.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_3_gaussian.py: Gaussian Apodization ^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 7-25 In this example, we will use the :py:class:`~mrsimulator.signal_processor.apodization.Gaussian` class to perform a Gaussian convolution on an example dataset. The function used for this apodization is defined as follows .. math:: f(x) = e^{-2 \pi^2 \sigma^2 x^2} where :math:`\sigma` is the standard deviation of the Gaussian function and is parameterized by the full width as half maximum (FWHM) as .. math:: \sigma = \frac{\text{FWHM}}{2\sqrt{2\ln 2}} Below we import the necessary modules sphinx_gallery_thumbnail_number = 1 .. GENERATED FROM PYTHON SOURCE LINES 25-29 .. code-block:: default import csdmpy as cp import numpy as np from mrsimulator import signal_processor as sp .. GENERATED FROM PYTHON SOURCE LINES 30-35 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.apodization.Gaussian` object sandwiched between two Fourier transformations. .. GENERATED FROM PYTHON SOURCE LINES 35-43 .. code-block:: default processor = sp.SignalProcessor( operations=[ sp.IFFT(), sp.apodization.Gaussian(FWHM="75 Hz"), sp.FFT(), ] ) .. GENERATED FROM PYTHON SOURCE LINES 44-47 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 0 Hz. .. GENERATED FROM PYTHON SOURCE LINES 47-54 .. code-block:: default test_data = np.zeros(500) test_data[250] = 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 55-58 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 58-60 .. code-block:: default processed_dataset = processor.apply_operations(dataset=csdm_object).real .. GENERATED FROM PYTHON SOURCE LINES 61-63 To see the results of the Gaussian apodization, we create a simple plot using the ``matplotlib`` library. .. GENERATED FROM PYTHON SOURCE LINES 63-72 .. 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_title("Before") ax[1].plot(processed_dataset.real, color="black", linewidth=1) ax[1].set_title("After") plt.tight_layout() plt.show() .. image-sg:: /signal_processor/images/sphx_glr_plot_3_gaussian_001.png :alt: Before, After :srcset: /signal_processor/images/sphx_glr_plot_3_gaussian_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.387 seconds) .. _sphx_glr_download_signal_processor_plot_3_gaussian.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_3_gaussian.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_3_gaussian.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_