.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "csi/denoising_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_denoising_tutorial.py: CSI Preprocessing.denoising 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.preprocessing.denoising tutorial using the pysensing library. .. GENERATED FROM PYTHON SOURCE LINES 13-20 .. code-block:: Python import sys sys.path.append('../..') import pysensing.csi.preprocessing.denoising as denoising import pysensing.csi.dataset.get_dataloader as load_data import matplotlib.pyplot as plt import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 21-23 Load the data ----------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 23-59 .. 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() # 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_denoising_tutorial_001.png :alt: WiFi CSI Heatmap :srcset: /csi/images/sphx_glr_denoising_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 60-63 1. lowpass filter ------------------------ Use lowpass filter denoising .. GENERATED FROM PYTHON SOURCE LINES 63-69 .. code-block:: Python wifi_csi_filter = denoising.lowpass_filter(20, 500) filtered_csi_data = wifi_csi_filter(example_csi_data) plot_csi_heatmap(filtered_csi_data) .. image-sg:: /csi/images/sphx_glr_denoising_tutorial_002.png :alt: WiFi CSI Heatmap :srcset: /csi/images/sphx_glr_denoising_tutorial_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 70-73 2. bandpass filter ------------------------ Use bandpass filter denoising .. GENERATED FROM PYTHON SOURCE LINES 73-78 .. code-block:: Python wifi_csi_filter = denoising.bandpass_filter(0.1, 30, 500) filtered_csi_data = wifi_csi_filter(example_csi_data) plot_csi_heatmap(filtered_csi_data) .. image-sg:: /csi/images/sphx_glr_denoising_tutorial_003.png :alt: WiFi CSI Heatmap :srcset: /csi/images/sphx_glr_denoising_tutorial_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 79-82 3. elliptic filter ------------------------ Use elliptic filter denoising .. GENERATED FROM PYTHON SOURCE LINES 82-87 .. code-block:: Python wifi_csi_filter = denoising.elliptic_filter(cutoff_freq=20, passband_ripple=0.5, stopband_attenuation=60, sample_rate=500) filtered_csi_data = wifi_csi_filter(example_csi_data) plot_csi_heatmap(filtered_csi_data) .. image-sg:: /csi/images/sphx_glr_denoising_tutorial_004.png :alt: WiFi CSI Heatmap :srcset: /csi/images/sphx_glr_denoising_tutorial_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 88-91 4. dwt filter ------------------------ Use dwt filter denoising .. GENERATED FROM PYTHON SOURCE LINES 91-96 .. code-block:: Python dwt_filter = denoising.dwt(wavelet='db4', level=2, threshold_ratio=0.4) filtered_csi_data = dwt_filter(example_csi_data) plot_csi_heatmap(filtered_csi_data) .. image-sg:: /csi/images/sphx_glr_denoising_tutorial_005.png :alt: WiFi CSI Heatmap :srcset: /csi/images/sphx_glr_denoising_tutorial_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 97-100 5. stft filter ------------------------ Use stft filter denoising .. GENERATED FROM PYTHON SOURCE LINES 100-106 .. code-block:: Python stft_filter = denoising.stft(window='hann', nperseg=256, noverlap=128, threshold_ratio=0.4) filtered_csi_data = stft_filter(example_csi_data) plot_csi_heatmap(filtered_csi_data) .. image-sg:: /csi/images/sphx_glr_denoising_tutorial_006.png :alt: WiFi CSI Heatmap :srcset: /csi/images/sphx_glr_denoising_tutorial_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 107-110 6. pca filter ------------------------ Use pca denoising .. GENERATED FROM PYTHON SOURCE LINES 110-115 .. code-block:: Python pca_filter = denoising.pca(n_components=3, dimension_to_filter=0) reduced_csi_data = pca_filter(example_csi_data.squeeze()) plot_csi_heatmap(reduced_csi_data) .. image-sg:: /csi/images/sphx_glr_denoising_tutorial_007.png :alt: WiFi CSI Heatmap :srcset: /csi/images/sphx_glr_denoising_tutorial_007.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 116-117 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 9.327 seconds) .. _sphx_glr_download_csi_denoising_tutorial.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: denoising_tutorial.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: denoising_tutorial.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_