{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os, random\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport IPython.display as ipd\nimport librosa\nfrom scipy.fft import fft, ifft\n\nimport warnings\nwarnings.simplefilter('ignore')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-21T21:26:27.858247Z","iopub.execute_input":"2022-02-21T21:26:27.858674Z","iopub.status.idle":"2022-02-21T21:26:27.863372Z","shell.execute_reply.started":"2022-02-21T21:26:27.858643Z","shell.execute_reply":"2022-02-21T21:26:27.862520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Get a random audio file","metadata":{}},{"cell_type":"code","source":"AUDIO_DIR = '../input/birdclef-2022/train_audio'\nfolder = random.choice(os.listdir(AUDIO_DIR))\nfile   = random.choice(os.listdir(f'{AUDIO_DIR}/{folder}'))","metadata":{"execution":{"iopub.status.busy":"2022-02-21T21:18:11.994015Z","iopub.execute_input":"2022-02-21T21:18:11.994995Z","iopub.status.idle":"2022-02-21T21:18:13.504322Z","shell.execute_reply.started":"2022-02-21T21:18:11.994937Z","shell.execute_reply":"2022-02-21T21:18:13.503384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y, sr = librosa.load(f'{AUDIO_DIR}/{folder}/{file}')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(y)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T21:36:51.611288Z","iopub.execute_input":"2022-02-21T21:36:51.612319Z","iopub.status.idle":"2022-02-21T21:36:51.619608Z","shell.execute_reply.started":"2022-02-21T21:36:51.612266Z","shell.execute_reply":"2022-02-21T21:36:51.618901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(sr)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T21:36:51.979690Z","iopub.execute_input":"2022-02-21T21:36:51.980002Z","iopub.status.idle":"2022-02-21T21:36:51.985119Z","shell.execute_reply.started":"2022-02-21T21:36:51.979974Z","shell.execute_reply":"2022-02-21T21:36:51.984313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Play the selected audio file","metadata":{}},{"cell_type":"code","source":"ipd.Audio(y, rate=sr)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T21:18:56.216748Z","iopub.execute_input":"2022-02-21T21:18:56.217247Z","iopub.status.idle":"2022-02-21T21:18:56.277378Z","shell.execute_reply.started":"2022-02-21T21:18:56.217199Z","shell.execute_reply":"2022-02-21T21:18:56.274845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plot the audio timeseries","metadata":{}},{"cell_type":"code","source":"plt.plot(y, c=plt.cm.get_cmap('tab10', 10)(np.random.randint(10)), linewidth=1);","metadata":{"execution":{"iopub.status.busy":"2022-02-21T21:22:19.227814Z","iopub.execute_input":"2022-02-21T21:22:19.228240Z","iopub.status.idle":"2022-02-21T21:22:19.619889Z","shell.execute_reply.started":"2022-02-21T21:22:19.228209Z","shell.execute_reply":"2022-02-21T21:22:19.619013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Fast Fourier Transform (fft)","metadata":{}},{"cell_type":"code","source":"# real part\nplt.plot(fft(y).real, c=plt.cm.get_cmap('tab10', 10)(np.random.randint(10)), linewidth=1);","metadata":{"execution":{"iopub.status.busy":"2022-02-21T21:34:35.931917Z","iopub.execute_input":"2022-02-21T21:34:35.932202Z","iopub.status.idle":"2022-02-21T21:34:36.484010Z","shell.execute_reply.started":"2022-02-21T21:34:35.932172Z","shell.execute_reply":"2022-02-21T21:34:36.482932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# imaginary part\nplt.plot(fft(y).imag, c=plt.cm.get_cmap('tab10', 10)(np.random.randint(10)), linewidth=1);","metadata":{"execution":{"iopub.status.busy":"2022-02-21T21:35:31.639212Z","iopub.execute_input":"2022-02-21T21:35:31.639691Z","iopub.status.idle":"2022-02-21T21:35:32.245763Z","shell.execute_reply.started":"2022-02-21T21:35:31.639652Z","shell.execute_reply":"2022-02-21T21:35:32.244759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Inverse Fourier Transform","metadata":{}},{"cell_type":"code","source":"plt.plot(ifft(fft(y)), c=plt.cm.get_cmap('tab10', 10)(np.random.randint(10)), linewidth=1);","metadata":{"execution":{"iopub.status.busy":"2022-02-21T21:37:11.911583Z","iopub.execute_input":"2022-02-21T21:37:11.912054Z","iopub.status.idle":"2022-02-21T21:37:12.981681Z","shell.execute_reply.started":"2022-02-21T21:37:11.912021Z","shell.execute_reply":"2022-02-21T21:37:12.980848Z"},"trusted":true},"execution_count":null,"outputs":[]}]}