.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/data_transform/_05_gaussian_smoothing.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_data_transform__05_gaussian_smoothing.py: Gaussian Smoothing ================== A common low-pass filtering technique is Gaussian smoothing, which applies a Gaussian window to the data with a moving average. We provide a class based implementation of Gaussian smoothing in the :class:`~mobgap.data_transform.GaussianFilter` class. .. GENERATED FROM PYTHON SOURCE LINES 9-14 .. code-block:: Python import matplotlib.pyplot as plt from mobgap.data import LabExampleDataset from mobgap.data_transform import GaussianFilter .. GENERATED FROM PYTHON SOURCE LINES 15-17 Loading some example data ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 17-26 .. code-block:: Python example_data = LabExampleDataset() ha_example_data = example_data.get_subset(cohort="HA") single_test = ha_example_data.get_subset( participant_id="002", test="Test5", trial="Trial2" ) data = single_test.data_ss data.head() .. raw:: html
acc_x acc_y acc_z gyr_x gyr_y gyr_z
time
2020-08-21 10:30:50.479000092+00:00 9.257165 0.031602 -2.604847 -0.1608 0.2119 -0.3052
2020-08-21 10:30:50.489000082+00:00 9.268460 0.017997 -2.594873 -0.2712 -0.0757 -0.4693
2020-08-21 10:30:50.499000072+00:00 9.272030 0.040954 -2.617060 0.1157 -0.0892 -0.2648
2020-08-21 10:30:50.509000063+00:00 9.262215 0.046100 -2.615381 -0.0091 -0.2005 -0.3278
2020-08-21 10:30:50.519000052+00:00 9.267278 0.070575 -2.585830 0.0524 -0.2733 -0.0965


.. GENERATED FROM PYTHON SOURCE LINES 27-33 Applying the Gaussian filter ---------------------------- We need to specify the standard deviation of the Gaussian window. Note, that we need to specify the standard deviation in seconds to make the parameters of the filter independent of the sampling rate of the data. It will be converted to samples internally. .. GENERATED FROM PYTHON SOURCE LINES 33-39 .. code-block:: Python gaussian_filter = GaussianFilter(sigma_s=0.1) gaussian_filter.filter(data, sampling_rate_hz=single_test.sampling_rate_hz) filtered_data = gaussian_filter.filtered_data_ filtered_data.head() .. raw:: html
acc_x acc_y acc_z gyr_x gyr_y gyr_z
time
2020-08-21 10:30:50.479000092+00:00 9.257966 0.049992 -2.595191 0.290325 0.183090 -0.257459
2020-08-21 10:30:50.489000082+00:00 9.257946 0.050103 -2.595061 0.293245 0.185868 -0.257351
2020-08-21 10:30:50.499000072+00:00 9.257907 0.050325 -2.594804 0.299015 0.191387 -0.257147
2020-08-21 10:30:50.509000063+00:00 9.257853 0.050657 -2.594423 0.307482 0.199569 -0.256873
2020-08-21 10:30:50.519000052+00:00 9.257789 0.051097 -2.593921 0.318430 0.210298 -0.256555


.. GENERATED FROM PYTHON SOURCE LINES 40-42 We can also access the standard deviation in samples that was calculated from the provided sigma_s and the sampling rate. .. GENERATED FROM PYTHON SOURCE LINES 42-44 .. code-block:: Python gaussian_filter.sigma_samples_ .. rst-class:: sphx-glr-script-out .. code-block:: none 10.0 .. GENERATED FROM PYTHON SOURCE LINES 45-46 We will plot the filtered data together with the original data. .. GENERATED FROM PYTHON SOURCE LINES 46-55 .. code-block:: Python fig, axs = plt.subplots(3, 1, sharex=True) for ax, col in zip(axs, ["gyr_x", "gyr_y", "gyr_z"]): ax.set_title(col) data[col].plot(ax=ax, label="Original") filtered_data[col].plot(ax=ax, label="CWT-filtered") axs[0].set_xlim(data.index[300], data.index[500]) axs[0].legend() fig.show() .. image-sg:: /auto_examples/data_transform/images/sphx_glr__05_gaussian_smoothing_001.png :alt: gyr_x, gyr_y, gyr_z :srcset: /auto_examples/data_transform/images/sphx_glr__05_gaussian_smoothing_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.266 seconds) **Estimated memory usage:** 80 MB .. _sphx_glr_download_auto_examples_data_transform__05_gaussian_smoothing.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: _05_gaussian_smoothing.ipynb <_05_gaussian_smoothing.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: _05_gaussian_smoothing.py <_05_gaussian_smoothing.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: _05_gaussian_smoothing.zip <_05_gaussian_smoothing.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_