.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "csi/deformation_tutorial.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_csi_deformation_tutorial.py: CSI Augmentation.deformation Tutorial ============================================================== .. GENERATED FROM PYTHON SOURCE LINES 7-10 .. code-block:: Python # !pip install pysensing .. GENERATED FROM PYTHON SOURCE LINES 11-13 In this tutorial, we will be implementing a simple csi.augmentation.deformation tutorial using the pysensing library. .. GENERATED FROM PYTHON SOURCE LINES 13-21 .. code-block:: Python import sys sys.path.append('../..') import pysensing.csi.augmentation.deformation as deformation import pysensing.csi.dataset.get_dataloader as load_data import matplotlib.pyplot as plt import numpy as np from scipy import signal .. GENERATED FROM PYTHON SOURCE LINES 22-24 Load the data ----------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 24-69 .. code-block:: Python # Define the plot function def plot_csi_heatmap(csi_data): """ Plot WiFi CSI heatmap. """ data_shape = csi_data.shape if len(data_shape) == 2: csi_to_plot = csi_data elif len(data_shape) > 2: csi_to_plot = csi_data.reshape(-1, data_shape[-1]) else: raise ValueError("The input data should have at least 2 dimensions.") plt.figure(figsize=(15, 8)) plt.imshow(csi_to_plot, aspect='auto', cmap='viridis') plt.colorbar(label='CSI Amplitude') plt.title('WiFi CSI Heatmap') plt.xlabel('Time Index') plt.ylabel('Subcarrier Index / Flattened Antenna-Subcarrier Index') plt.show() def plot_spec(csi): _, _, csi_spectrogram = signal.stft(csi, window='hann', nperseg=256, noverlap=128) specgram = np.abs(csi_spectrogram) plt.figure(figsize=(10,5)) plt.imshow(specgram.squeeze(), aspect='auto', origin='lower', cmap='inferno') plt.colorbar(label='CSI Amplitude') plt.xlabel('Time (s)') plt.ylabel('Frequency (Hz)') # Load the data _, test_loader = load_data.load_classification_dataset('UT_HAR',batch_size=1) example_csi_data_list = [] for data in test_loader: data, label = data example_csi_data_list.append(data) example_csi_data = np.concatenate(example_csi_data_list, axis=-1) plot_csi_heatmap(example_csi_data) .. image-sg:: /csi/images/sphx_glr_deformation_tutorial_001.png :alt: WiFi CSI Heatmap :srcset: /csi/images/sphx_glr_deformation_tutorial_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /data1/msc/zyj/yunjiao_csi/1028/yunjiao_csi/tutorials/csi_source/data/csi using dataset: UT-HAR DATA .. GENERATED FROM PYTHON SOURCE LINES 70-73 1. time stretching ------------------------ Use time stretching augmentation .. GENERATED FROM PYTHON SOURCE LINES 73-79 .. code-block:: Python csi_process = deformation.time_stretching(stretch_rate=0.4) reduced_csi_data = csi_process(example_csi_data) plot_csi_heatmap(reduced_csi_data) .. image-sg:: /csi/images/sphx_glr_deformation_tutorial_002.png :alt: WiFi CSI Heatmap :srcset: /csi/images/sphx_glr_deformation_tutorial_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 80-83 2. spectrum scaling ------------------------ Use spectrum scaling augmentation .. GENERATED FROM PYTHON SOURCE LINES 83-90 .. code-block:: Python csi_process = deformation.spectrum_scaling(scale_factor=4) reduced_csi_data = csi_process(example_csi_data) plot_spec(example_csi_data.squeeze()[2]) plot_spec(reduced_csi_data.squeeze()[2]) plot_csi_heatmap(reduced_csi_data) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /csi/images/sphx_glr_deformation_tutorial_003.png :alt: deformation tutorial :srcset: /csi/images/sphx_glr_deformation_tutorial_003.png :class: sphx-glr-multi-img * .. image-sg:: /csi/images/sphx_glr_deformation_tutorial_004.png :alt: deformation tutorial :srcset: /csi/images/sphx_glr_deformation_tutorial_004.png :class: sphx-glr-multi-img * .. image-sg:: /csi/images/sphx_glr_deformation_tutorial_005.png :alt: WiFi CSI Heatmap :srcset: /csi/images/sphx_glr_deformation_tutorial_005.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 91-94 3. spectrum shifting ------------------------ Use spectrum shifting augmentation .. GENERATED FROM PYTHON SOURCE LINES 94-102 .. code-block:: Python csi_process = deformation.spectrum_shifting(shift_min=0, shift_max=0.5) reduced_csi_data = csi_process(example_csi_data) plot_spec(example_csi_data.squeeze()[2]) plot_spec(reduced_csi_data.squeeze()[2]) plot_csi_heatmap(reduced_csi_data) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /csi/images/sphx_glr_deformation_tutorial_006.png :alt: deformation tutorial :srcset: /csi/images/sphx_glr_deformation_tutorial_006.png :class: sphx-glr-multi-img * .. image-sg:: /csi/images/sphx_glr_deformation_tutorial_007.png :alt: deformation tutorial :srcset: /csi/images/sphx_glr_deformation_tutorial_007.png :class: sphx-glr-multi-img * .. image-sg:: /csi/images/sphx_glr_deformation_tutorial_008.png :alt: WiFi CSI Heatmap :srcset: /csi/images/sphx_glr_deformation_tutorial_008.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 103-104 And that's it. We're done with our CSI augmentation.deformation tutorials. Thanks for reading. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.620 seconds) .. _sphx_glr_download_csi_deformation_tutorial.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: deformation_tutorial.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: deformation_tutorial.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_