MaFaulDa Dataset Demonstration¶
Cloning the damavand repository¶
In [ ]:
Copied!
!git clone https://github.com/pydamavand/damavand
!git clone https://github.com/pydamavand/damavand
Cloning into 'damavand'... remote: Enumerating objects: 263, done. remote: Counting objects: 100% (263/263), done. remote: Compressing objects: 100% (197/197), done. remote: Total 263 (delta 132), reused 196 (delta 65), pack-reused 0 (from 0) Receiving objects: 100% (263/263), 6.62 MiB | 13.62 MiB/s, done. Resolving deltas: 100% (132/132), done.
In [2]:
Copied!
!pip install -r damavand/requirements.txt
!pip install -r damavand/requirements.txt
Collecting certifi==2024.7.4 (from -r damavand/requirements.txt (line 1)) Downloading certifi-2024.7.4-py3-none-any.whl.metadata (2.2 kB) Collecting charset-normalizer==3.3.2 (from -r damavand/requirements.txt (line 2)) Downloading charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (33 kB) Collecting idna==3.7 (from -r damavand/requirements.txt (line 3)) Downloading idna-3.7-py3-none-any.whl.metadata (9.9 kB) Collecting numpy==1.26.4 (from -r damavand/requirements.txt (line 4)) Downloading numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.0/61.0 kB 2.7 MB/s eta 0:00:00 Collecting pandas==2.1.4 (from -r damavand/requirements.txt (line 5)) Downloading pandas-2.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (18 kB) Requirement already satisfied: python-dateutil==2.9.0.post0 in /usr/local/lib/python3.11/dist-packages (from -r damavand/requirements.txt (line 6)) (2.9.0.post0) Collecting pytz==2024.1 (from -r damavand/requirements.txt (line 7)) Downloading pytz-2024.1-py2.py3-none-any.whl.metadata (22 kB) Collecting rarfile==4.2 (from -r damavand/requirements.txt (line 8)) Downloading rarfile-4.2-py3-none-any.whl.metadata (4.4 kB) Requirement already satisfied: requests==2.32.3 in /usr/local/lib/python3.11/dist-packages (from -r damavand/requirements.txt (line 9)) (2.32.3) Collecting scipy==1.13.1 (from -r damavand/requirements.txt (line 10)) Downloading scipy-1.13.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (60 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.6/60.6 kB 2.9 MB/s eta 0:00:00 Collecting six==1.16.0 (from -r damavand/requirements.txt (line 11)) Downloading six-1.16.0-py2.py3-none-any.whl.metadata (1.8 kB) Collecting tzdata==2024.1 (from -r damavand/requirements.txt (line 12)) Downloading tzdata-2024.1-py2.py3-none-any.whl.metadata (1.4 kB) Collecting urllib3==2.2.2 (from -r damavand/requirements.txt (line 13)) Downloading urllib3-2.2.2-py3-none-any.whl.metadata (6.4 kB) Downloading certifi-2024.7.4-py3-none-any.whl (162 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 163.0/163.0 kB 6.0 MB/s eta 0:00:00 Downloading charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (140 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 140.3/140.3 kB 4.6 MB/s eta 0:00:00 Downloading idna-3.7-py3-none-any.whl (66 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 66.8/66.8 kB 4.7 MB/s eta 0:00:00 Downloading numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.3/18.3 MB 88.8 MB/s eta 0:00:00 Downloading pandas-2.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.2 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.2/12.2 MB 102.0 MB/s eta 0:00:00 Downloading pytz-2024.1-py2.py3-none-any.whl (505 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 505.5/505.5 kB 31.1 MB/s eta 0:00:00 Downloading rarfile-4.2-py3-none-any.whl (29 kB) Downloading scipy-1.13.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (38.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 38.6/38.6 MB 17.9 MB/s eta 0:00:00 Downloading six-1.16.0-py2.py3-none-any.whl (11 kB) Downloading tzdata-2024.1-py2.py3-none-any.whl (345 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 345.4/345.4 kB 17.1 MB/s eta 0:00:00 Downloading urllib3-2.2.2-py3-none-any.whl (121 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 121.4/121.4 kB 9.2 MB/s eta 0:00:00 Installing collected packages: pytz, urllib3, tzdata, six, rarfile, numpy, idna, charset-normalizer, certifi, scipy, pandas Attempting uninstall: pytz Found existing installation: pytz 2025.2 Uninstalling pytz-2025.2: Successfully uninstalled pytz-2025.2 Attempting uninstall: urllib3 Found existing installation: urllib3 2.5.0 Uninstalling urllib3-2.5.0: Successfully uninstalled urllib3-2.5.0 Attempting uninstall: tzdata Found existing installation: tzdata 2025.2 Uninstalling tzdata-2025.2: Successfully uninstalled tzdata-2025.2 Attempting uninstall: six Found existing installation: six 1.17.0 Uninstalling six-1.17.0: Successfully uninstalled six-1.17.0 Attempting uninstall: numpy Found existing installation: numpy 2.0.2 Uninstalling numpy-2.0.2: Successfully uninstalled numpy-2.0.2 Attempting uninstall: idna Found existing installation: idna 3.10 Uninstalling idna-3.10: Successfully uninstalled idna-3.10 Attempting uninstall: charset-normalizer Found existing installation: charset-normalizer 3.4.2 Uninstalling charset-normalizer-3.4.2: Successfully uninstalled charset-normalizer-3.4.2 Attempting uninstall: certifi Found existing installation: certifi 2025.7.14 Uninstalling certifi-2025.7.14: Successfully uninstalled certifi-2025.7.14 Attempting uninstall: scipy Found existing installation: scipy 1.16.0 Uninstalling scipy-1.16.0: Successfully uninstalled scipy-1.16.0 Attempting uninstall: pandas Found existing installation: pandas 2.2.2 Uninstalling pandas-2.2.2: Successfully uninstalled pandas-2.2.2 ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. google-colab 1.0.0 requires pandas==2.2.2, but you have pandas 2.1.4 which is incompatible. opencv-python 4.12.0.88 requires numpy<2.3.0,>=2; python_version >= "3.9", but you have numpy 1.26.4 which is incompatible. opencv-python-headless 4.12.0.88 requires numpy<2.3.0,>=2; python_version >= "3.9", but you have numpy 1.26.4 which is incompatible. opencv-contrib-python 4.12.0.88 requires numpy<2.3.0,>=2; python_version >= "3.9", but you have numpy 1.26.4 which is incompatible. plotnine 0.14.5 requires pandas>=2.2.0, but you have pandas 2.1.4 which is incompatible. tsfresh 0.21.0 requires scipy>=1.14.0; python_version >= "3.10", but you have scipy 1.13.1 which is incompatible. thinc 8.3.6 requires numpy<3.0.0,>=2.0.0, but you have numpy 1.26.4 which is incompatible. xarray 2025.7.1 requires pandas>=2.2, but you have pandas 2.1.4 which is incompatible. mizani 0.13.5 requires pandas>=2.2.0, but you have pandas 2.1.4 which is incompatible. Successfully installed certifi-2024.7.4 charset-normalizer-3.3.2 idna-3.7 numpy-1.26.4 pandas-2.1.4 pytz-2024.1 rarfile-4.2 scipy-1.13.1 six-1.16.0 tzdata-2024.1 urllib3-2.2.2
Importings¶
In [1]:
Copied!
from damavand.damavand.datasets.downloaders import read_addresses, MaFaulDaDownloader
from damavand.damavand.datasets.digestors import MaFauldDa
from damavand.damavand.signal_processing.transformations import *
from damavand.damavand.signal_processing.feature_extraction import *
from damavand.damavand.utils import *
import os
import pandas as pd
import numpy as np
from damavand.damavand.datasets.downloaders import read_addresses, MaFaulDaDownloader
from damavand.damavand.datasets.digestors import MaFauldDa
from damavand.damavand.signal_processing.transformations import *
from damavand.damavand.signal_processing.feature_extraction import *
from damavand.damavand.utils import *
import os
import pandas as pd
import numpy as np
Instantiating a downloader object¶
In [2]:
Copied!
addresses = read_addresses()
downloader = MaFaulDaDownloader({key: addresses['MaFaulDa'][key] for key in ['normal.zip', 'imbalance.zip']})
downloader.download_extract('mafaulda_zip_files/', 'mafaulda/')
addresses = read_addresses()
downloader = MaFaulDaDownloader({key: addresses['MaFaulDa'][key] for key in ['normal.zip', 'imbalance.zip']})
downloader.download_extract('mafaulda_zip_files/', 'mafaulda/')
Downloading: normal.zip Downloading: imbalance.zip Extracting: normal.zip Extracting: imbalance.zip
Instantiating a digestor object¶
In [3]:
Copied!
mafaulda = MaFauldDa('mafaulda/', os.listdir('mafaulda/'), channels = [2])
mining_params = {
'win_len': 50000,
'hop_len': 50000
}
mafaulda.mine(mining_params)
mafaulda = MaFauldDa('mafaulda/', os.listdir('mafaulda/'), channels = [2])
mining_params = {
'win_len': 50000,
'hop_len': 50000
}
mafaulda.mine(mining_params)
Aggregating data over the third channel¶
In [4]:
Copied!
df = pd.concat(mafaulda.data[2]).reset_index(drop = True)
df
df = pd.concat(mafaulda.data[2]).reset_index(drop = True)
df
Out[4]:
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ... | 49992 | 49993 | 49994 | 49995 | 49996 | 49997 | 49998 | 49999 | state | severity | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | -0.769800 | 0.148490 | -0.444640 | -0.173230 | -0.061578 | -0.561010 | 0.245860 | -0.681590 | 0.283750 | -0.558160 | ... | -0.22701 | -0.679750 | 0.081710 | -0.79798 | 0.16689 | -0.780670 | -0.096885 | -0.505490 | imbalance | 25g |
1 | -0.396390 | -0.084910 | -0.706400 | 0.098014 | -0.841570 | 0.102120 | -0.591070 | -0.107300 | -0.308920 | -0.391270 | ... | 0.15224 | 0.782750 | 0.366870 | 0.45279 | 0.63565 | 0.035932 | 0.801350 | -0.068741 | imbalance | 25g |
2 | 0.722450 | -0.069506 | 0.381250 | 0.151030 | 0.075812 | 0.530700 | -0.086285 | 0.769020 | -0.080516 | 0.756980 | ... | -1.20120 | -0.258320 | -1.213800 | -0.41387 | -0.99852 | -0.755430 | -0.634810 | -1.101700 | imbalance | 25g |
3 | -0.359160 | -1.285900 | -0.362660 | -1.271400 | -0.643180 | -0.767570 | -0.732520 | -0.547600 | -1.075200 | -0.298390 | ... | 0.70043 | 1.234100 | 0.529770 | 1.34420 | 0.42482 | 1.233200 | 0.657640 | 0.931680 | imbalance | 25g |
4 | 1.061400 | 0.727540 | 1.370700 | 0.536410 | 1.378800 | 0.673500 | 1.267900 | 0.823470 | 0.929870 | 1.101900 | ... | -0.69956 | -0.993960 | -0.940630 | -0.66817 | -1.35880 | -0.389490 | -1.312700 | -0.372960 | imbalance | 25g |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
1905 | -0.029689 | 0.148640 | -0.349120 | 0.342740 | -0.351850 | 0.340670 | -0.284620 | 0.096903 | 0.110810 | -0.026946 | ... | -0.18006 | 0.186760 | 0.040866 | -0.10206 | 0.31797 | -0.285560 | 0.445120 | -0.277080 | normal | _ |
1906 | 0.358070 | -0.107990 | 0.142550 | 0.164280 | -0.129200 | 0.408630 | -0.306600 | 0.481290 | -0.260050 | 0.322450 | ... | -0.42628 | 0.417400 | -0.364720 | 0.26404 | -0.12011 | -0.061874 | 0.209820 | -0.326420 | normal | _ |
1907 | 0.408730 | -0.454570 | 0.397690 | -0.295990 | 0.192650 | -0.014766 | -0.134890 | 0.289990 | -0.393890 | 0.454840 | ... | -0.27756 | 0.095386 | -0.642190 | 0.29521 | -0.71886 | 0.263110 | -0.439650 | 0.039742 | normal | _ |
1908 | -0.113390 | -0.273610 | 0.240340 | -0.373970 | 0.405140 | -0.375480 | 0.324690 | -0.205440 | 0.054960 | 0.064024 | ... | 0.16796 | -0.095137 | -0.121100 | 0.22238 | -0.31794 | 0.381740 | -0.369100 | 0.364300 | normal | _ |
1909 | -0.188880 | 0.155550 | 0.032046 | -0.168030 | 0.299780 | -0.286990 | 0.388050 | -0.355930 | 0.284460 | -0.112620 | ... | 0.39862 | -0.323430 | 0.202300 | -0.02139 | -0.02897 | 0.245700 | -0.351000 | 0.417440 | normal | _ |
1910 rows × 50002 columns
In [5]:
Copied!
signals, metadata = df.iloc[:, : -2], df.iloc[:, -2 :]
signals
signals, metadata = df.iloc[:, : -2], df.iloc[:, -2 :]
signals
Out[5]:
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ... | 49990 | 49991 | 49992 | 49993 | 49994 | 49995 | 49996 | 49997 | 49998 | 49999 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | -0.769800 | 0.148490 | -0.444640 | -0.173230 | -0.061578 | -0.561010 | 0.245860 | -0.681590 | 0.283750 | -0.558160 | ... | -0.53685 | -0.28361 | -0.22701 | -0.679750 | 0.081710 | -0.79798 | 0.16689 | -0.780670 | -0.096885 | -0.505490 |
1 | -0.396390 | -0.084910 | -0.706400 | 0.098014 | -0.841570 | 0.102120 | -0.591070 | -0.107300 | -0.308920 | -0.391270 | ... | 0.15249 | 0.97625 | 0.15224 | 0.782750 | 0.366870 | 0.45279 | 0.63565 | 0.035932 | 0.801350 | -0.068741 |
2 | 0.722450 | -0.069506 | 0.381250 | 0.151030 | 0.075812 | 0.530700 | -0.086285 | 0.769020 | -0.080516 | 0.756980 | ... | -0.94616 | -0.37918 | -1.20120 | -0.258320 | -1.213800 | -0.41387 | -0.99852 | -0.755430 | -0.634810 | -1.101700 |
3 | -0.359160 | -1.285900 | -0.362660 | -1.271400 | -0.643180 | -0.767570 | -0.732520 | -0.547600 | -1.075200 | -0.298390 | ... | 1.09670 | 0.96135 | 0.70043 | 1.234100 | 0.529770 | 1.34420 | 0.42482 | 1.233200 | 0.657640 | 0.931680 |
4 | 1.061400 | 0.727540 | 1.370700 | 0.536410 | 1.378800 | 0.673500 | 1.267900 | 0.823470 | 0.929870 | 1.101900 | ... | -0.49750 | -1.44260 | -0.69956 | -0.993960 | -0.940630 | -0.66817 | -1.35880 | -0.389490 | -1.312700 | -0.372960 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
1905 | -0.029689 | 0.148640 | -0.349120 | 0.342740 | -0.351850 | 0.340670 | -0.284620 | 0.096903 | 0.110810 | -0.026946 | ... | -0.31529 | 0.40178 | -0.18006 | 0.186760 | 0.040866 | -0.10206 | 0.31797 | -0.285560 | 0.445120 | -0.277080 |
1906 | 0.358070 | -0.107990 | 0.142550 | 0.164280 | -0.129200 | 0.408630 | -0.306600 | 0.481290 | -0.260050 | 0.322450 | ... | -0.18523 | 0.36920 | -0.42628 | 0.417400 | -0.364720 | 0.26404 | -0.12011 | -0.061874 | 0.209820 | -0.326420 |
1907 | 0.408730 | -0.454570 | 0.397690 | -0.295990 | 0.192650 | -0.014766 | -0.134890 | 0.289990 | -0.393890 | 0.454840 | ... | 0.14742 | -0.28190 | -0.27756 | 0.095386 | -0.642190 | 0.29521 | -0.71886 | 0.263110 | -0.439650 | 0.039742 |
1908 | -0.113390 | -0.273610 | 0.240340 | -0.373970 | 0.405140 | -0.375480 | 0.324690 | -0.205440 | 0.054960 | 0.064024 | ... | 0.34270 | -0.35081 | 0.16796 | -0.095137 | -0.121100 | 0.22238 | -0.31794 | 0.381740 | -0.369100 | 0.364300 |
1909 | -0.188880 | 0.155550 | 0.032046 | -0.168030 | 0.299780 | -0.286990 | 0.388050 | -0.355930 | 0.284460 | -0.112620 | ... | 0.38898 | -0.48163 | 0.39862 | -0.323430 | 0.202300 | -0.02139 | -0.02897 | 0.245700 | -0.351000 | 0.417440 |
1910 rows × 50000 columns
In [6]:
Copied!
metadata
metadata
Out[6]:
state | severity | |
---|---|---|
0 | imbalance | 25g |
1 | imbalance | 25g |
2 | imbalance | 25g |
3 | imbalance | 25g |
4 | imbalance | 25g |
... | ... | ... |
1905 | normal | _ |
1906 | normal | _ |
1907 | normal | _ |
1908 | normal | _ |
1909 | normal | _ |
1910 rows × 2 columns
In [7]:
Copied!
metadata['comb'] = metadata['state'] + '_' + metadata['severity']
metadata['comb'].value_counts()
metadata['comb'] = metadata['state'] + '_' + metadata['severity']
metadata['comb'].value_counts()
Out[7]:
count | |
---|---|
comb | |
imbalance_6g | 245 |
imbalance_20g | 245 |
normal__ | 245 |
imbalance_15g | 240 |
imbalance_10g | 240 |
imbalance_25g | 235 |
imbalance_30g | 235 |
imbalance_35g | 225 |
Signal Processing¶
Envelope Extraction¶
In [8]:
Copied!
signals_env = env(signals)
signals_env.shape
signals_env = env(signals)
signals_env.shape
Out[8]:
(1910, 50000)
FFT¶
In [9]:
Copied!
# Defenition of a window (to avoid leakage error) and a bandpass frequency filter (to both avoid aliasing and DC-component removal)
window = scipy.signal.windows.hann(signals_env.shape[1])
freq_filter = scipy.signal.butter(25, [5, 24500], 'bandpass', fs = 51200, output='sos')
# Defenition of a window (to avoid leakage error) and a bandpass frequency filter (to both avoid aliasing and DC-component removal)
window = scipy.signal.windows.hann(signals_env.shape[1])
freq_filter = scipy.signal.butter(25, [5, 24500], 'bandpass', fs = 51200, output='sos')
In [10]:
Copied!
signals_env_fft = fft(signals_env, freq_filter = freq_filter, window = window)
signals_env_fft.shape
signals_env_fft = fft(signals_env, freq_filter = freq_filter, window = window)
signals_env_fft.shape
Out[10]:
(1910, 25000)
ZoomedFFT¶
In [11]:
Copied!
signals_env_ZoomedFFT = zoomed_fft(signals_env, 0, 1000, 2000, 51200, freq_filter = freq_filter, window = window)
signals_env_ZoomedFFT.shape
signals_env_ZoomedFFT = zoomed_fft(signals_env, 0, 1000, 2000, 51200, freq_filter = freq_filter, window = window)
signals_env_ZoomedFFT.shape
Out[11]:
(1910, 2000)
STFT¶
In [12]:
Copied!
# Defenition of a window (to avoid leakage error) and a bandpass frequency filter (to both avoid aliasing and DC-component removal)
STFT_window = scipy.signal.windows.hann(2048)
STFT_freq_filter = scipy.signal.butter(25, [5, 24500], 'bandpass', fs = 51200, output='sos')
# Defenition of a window (to avoid leakage error) and a bandpass frequency filter (to both avoid aliasing and DC-component removal)
STFT_window = scipy.signal.windows.hann(2048)
STFT_freq_filter = scipy.signal.butter(25, [5, 24500], 'bandpass', fs = 51200, output='sos')
In [13]:
Copied!
signals_env_STFT = stft(signals_env, 2048, 1000, STFT_freq_filter, STFT_window)
signals_env_STFT.shape
signals_env_STFT = stft(signals_env, 2048, 1000, STFT_freq_filter, STFT_window)
signals_env_STFT.shape
Out[13]:
(1910, 48, 1024)
Statistical Features¶
In [14]:
Copied!
# Defining the feature-set to be extracted
features = {'mean': (np.mean, (), {}), 'var': (np.var, (), {}), 'rms': (rms, (), {})}
# Defining the feature-set to be extracted
features = {'mean': (np.mean, (), {}), 'var': (np.var, (), {}), 'rms': (rms, (), {})}
In [14]:
Copied!
In [15]:
Copied!
# Extracting the desired feature-set from time-domain signals
features_df = feature_extractor(signals, features)
features_df
# Extracting the desired feature-set from time-domain signals
features_df = feature_extractor(signals, features)
features_df
Out[15]:
mean | var | rms | |
---|---|---|---|
0 | -0.012679 | 0.527956 | 0.726716 |
1 | 0.011876 | 0.529248 | 0.727591 |
2 | -0.009493 | 0.528195 | 0.726832 |
3 | 0.005920 | 0.526064 | 0.725327 |
4 | -0.001124 | 0.519390 | 0.720688 |
... | ... | ... | ... |
1905 | -0.001377 | 0.096043 | 0.309910 |
1906 | 0.000114 | 0.095341 | 0.308773 |
1907 | -0.001045 | 0.096605 | 0.310816 |
1908 | 0.000556 | 0.094486 | 0.307386 |
1909 | -0.000644 | 0.096400 | 0.310484 |
1910 rows × 3 columns
Visualization¶
In [16]:
Copied!
import seaborn as sns
from matplotlib import pyplot as plt
sns.set()
fig, axes = plt.subplots(4, 1, figsize = (16, 10))
sns.lineplot(ax=axes[0], x=range(len(signals.iloc[0,:])), y = signals.iloc[0,:])
axes[0].set_title("Original Time Signal")
axes[0].set_ylabel("Amplitude")
axes[0].set_xlabel("sample")
axes[0].set_xlim(0, 12000)
sns.lineplot(ax=axes[1], x=range(len(signals_env.iloc[0,:])), y = signals_env.iloc[0, :])
axes[1].set_title("Envelope")
axes[1].set_ylabel("Amplitude")
axes[1].set_xlabel("sample")
axes[1].set_xlim(0, 12000)
sns.lineplot(ax=axes[2], x = fft_freq_axis(50000, 51200), y = signals_env_fft.iloc[0, :])
axes[2].set_title("FFT")
axes[2].set_ylabel("Amplitude")
axes[2].set_xlabel("Frequency (Hz)")
axes[2].set_xlim(0, 6000)
sns.lineplot(ax=axes[3], x = zoomed_fft_freq_axis(0, 1000, 2000), y = signals_env_ZoomedFFT.iloc[0, :])
axes[3].set_title("Zoomed FFT")
axes[3].set_ylabel("Amplitude")
axes[3].set_xlabel("Frequency (Hz)")
axes[3].set_xlim(0, 1000)
plt.subplots_adjust(hspace = 0.75)
fig.show()
import seaborn as sns
from matplotlib import pyplot as plt
sns.set()
fig, axes = plt.subplots(4, 1, figsize = (16, 10))
sns.lineplot(ax=axes[0], x=range(len(signals.iloc[0,:])), y = signals.iloc[0,:])
axes[0].set_title("Original Time Signal")
axes[0].set_ylabel("Amplitude")
axes[0].set_xlabel("sample")
axes[0].set_xlim(0, 12000)
sns.lineplot(ax=axes[1], x=range(len(signals_env.iloc[0,:])), y = signals_env.iloc[0, :])
axes[1].set_title("Envelope")
axes[1].set_ylabel("Amplitude")
axes[1].set_xlabel("sample")
axes[1].set_xlim(0, 12000)
sns.lineplot(ax=axes[2], x = fft_freq_axis(50000, 51200), y = signals_env_fft.iloc[0, :])
axes[2].set_title("FFT")
axes[2].set_ylabel("Amplitude")
axes[2].set_xlabel("Frequency (Hz)")
axes[2].set_xlim(0, 6000)
sns.lineplot(ax=axes[3], x = zoomed_fft_freq_axis(0, 1000, 2000), y = signals_env_ZoomedFFT.iloc[0, :])
axes[3].set_title("Zoomed FFT")
axes[3].set_ylabel("Amplitude")
axes[3].set_xlabel("Frequency (Hz)")
axes[3].set_xlim(0, 1000)
plt.subplots_adjust(hspace = 0.75)
fig.show()
In [17]:
Copied!
t = np.linspace(0, 50000/52600, 48)
f = fft_freq_axis(2048, 51200)
fig, ax = plt.subplots(figsize = (16, 8))
ax = sns.heatmap(signals_env_STFT[0, :, :], xticklabels = np.round(f, decimals = 2), yticklabels = np.round(t, decimals = 2), annot = False, cbar = False)
ax.set(xlabel = 'Frequency (Hz)', ylabel = 'Time (sec)')
ax.set_title('STFT')
ax.set_xticks(ax.get_xticks()[::20])
ax.set_yticks(ax.get_yticks()[::5])
fig.show()
t = np.linspace(0, 50000/52600, 48)
f = fft_freq_axis(2048, 51200)
fig, ax = plt.subplots(figsize = (16, 8))
ax = sns.heatmap(signals_env_STFT[0, :, :], xticklabels = np.round(f, decimals = 2), yticklabels = np.round(t, decimals = 2), annot = False, cbar = False)
ax.set(xlabel = 'Frequency (Hz)', ylabel = 'Time (sec)')
ax.set_title('STFT')
ax.set_xticks(ax.get_xticks()[::20])
ax.set_yticks(ax.get_yticks()[::5])
fig.show()