{"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\nimport librosa, librosa.display\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport IPython.display as ipd\nfrom scipy.signal import bessel, freqz, lfilter","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:34.957269Z","iopub.execute_input":"2022-04-10T09:43:34.957572Z","iopub.status.idle":"2022-04-10T09:43:34.963881Z","shell.execute_reply.started":"2022-04-10T09:43:34.957541Z","shell.execute_reply":"2022-04-10T09:43:34.962853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_FOLDER = '../input/birdclef-2022/'\nassert os.path.isdir(BASE_FOLDER) == True","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:34.965445Z","iopub.execute_input":"2022-04-10T09:43:34.966134Z","iopub.status.idle":"2022-04-10T09:43:35.001369Z","shell.execute_reply.started":"2022-04-10T09:43:34.966086Z","shell.execute_reply":"2022-04-10T09:43:35.000481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df= pd.read_csv(os.path.join(BASE_FOLDER,'train_metadata.csv'))\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:35.003024Z","iopub.execute_input":"2022-04-10T09:43:35.003346Z","iopub.status.idle":"2022-04-10T09:43:35.077211Z","shell.execute_reply.started":"2022-04-10T09:43:35.003305Z","shell.execute_reply":"2022-04-10T09:43:35.076484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_melspectroram(signal, name):\n    spectrogram = librosa.amplitude_to_db(librosa.stft(signal))\n    plt.figure(figsize=(20,10))\n    librosa.display.specshow(spectrogram, y_axis='log')\n    plt.colorbar(format='+2.0f dB')\n    plt.title(f'Spectrogram for {name}')\n    plt.xlabel('ts')\n    plt.show()   ","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:35.079202Z","iopub.execute_input":"2022-04-10T09:43:35.079609Z","iopub.status.idle":"2022-04-10T09:43:35.085333Z","shell.execute_reply.started":"2022-04-10T09:43:35.079562Z","shell.execute_reply":"2022-04-10T09:43:35.084585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_soundwave(data, name):\n    plt.figure(figsize=(14, 5))\n    plt.xlabel('ts')\n    plt.title(f'Graphic wave for {name}')\n    librosa.display.waveshow(data)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:35.086775Z","iopub.execute_input":"2022-04-10T09:43:35.087045Z","iopub.status.idle":"2022-04-10T09:43:35.099223Z","shell.execute_reply.started":"2022-04-10T09:43:35.08701Z","shell.execute_reply":"2022-04-10T09:43:35.098349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def filter_highpass(cutoff, fs, order=5):\n    nyq = fs * 0.5\n    normal_cutoff = cutoff / nyq\n    b, a = bessel(order, normal_cutoff, btype='high', analog=False)\n    return b, a\n\ndef bessel_highpass_filter(data, cutoff, fs, order=5):\n    b,a = filter_highpass(cutoff, fs, order)\n    y  = lfilter(b, a, data)\n    return y      ","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:35.101018Z","iopub.execute_input":"2022-04-10T09:43:35.101587Z","iopub.status.idle":"2022-04-10T09:43:35.108823Z","shell.execute_reply.started":"2022-04-10T09:43:35.101539Z","shell.execute_reply":"2022-04-10T09:43:35.108095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Train src data","metadata":{}},{"cell_type":"code","source":"FILE_EXAMPLE = os.path.join(BASE_FOLDER, 'train_audio', 'afrsil1/XC125458.ogg')\nassert os.path.isfile(FILE_EXAMPLE) == True","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:35.110968Z","iopub.execute_input":"2022-04-10T09:43:35.111769Z","iopub.status.idle":"2022-04-10T09:43:35.120886Z","shell.execute_reply.started":"2022-04-10T09:43:35.11174Z","shell.execute_reply":"2022-04-10T09:43:35.119934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"src_data_example, sr_example = librosa.load(FILE_EXAMPLE)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:35.12319Z","iopub.execute_input":"2022-04-10T09:43:35.12378Z","iopub.status.idle":"2022-04-10T09:43:35.434753Z","shell.execute_reply.started":"2022-04-10T09:43:35.12374Z","shell.execute_reply":"2022-04-10T09:43:35.434011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_soundwave(src_data_example, FILE_EXAMPLE)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:35.436019Z","iopub.execute_input":"2022-04-10T09:43:35.436387Z","iopub.status.idle":"2022-04-10T09:43:35.985974Z","shell.execute_reply.started":"2022-04-10T09:43:35.436348Z","shell.execute_reply":"2022-04-10T09:43:35.985219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_melspectroram(src_data_example, FILE_EXAMPLE)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:35.988478Z","iopub.execute_input":"2022-04-10T09:43:35.988829Z","iopub.status.idle":"2022-04-10T09:43:36.929342Z","shell.execute_reply.started":"2022-04-10T09:43:35.988787Z","shell.execute_reply":"2022-04-10T09:43:36.928652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ipd.Audio(src_data_example, rate=sr_example)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:36.930481Z","iopub.execute_input":"2022-04-10T09:43:36.931211Z","iopub.status.idle":"2022-04-10T09:43:36.953809Z","shell.execute_reply.started":"2022-04-10T09:43:36.93117Z","shell.execute_reply":"2022-04-10T09:43:36.95303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Filtered train data","metadata":{}},{"cell_type":"markdown","source":"#### Filter Paramaters( use bessel filter)\n","metadata":{}},{"cell_type":"code","source":"order = 6\nfs = 30.0       \ncutoff = 3.667","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:36.9552Z","iopub.execute_input":"2022-04-10T09:43:36.955765Z","iopub.status.idle":"2022-04-10T09:43:36.960652Z","shell.execute_reply.started":"2022-04-10T09:43:36.955722Z","shell.execute_reply":"2022-04-10T09:43:36.959742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_filtered = bessel_highpass_filter(src_data_example, cutoff, fs, order)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:36.962138Z","iopub.execute_input":"2022-04-10T09:43:36.962393Z","iopub.status.idle":"2022-04-10T09:43:36.982035Z","shell.execute_reply.started":"2022-04-10T09:43:36.962362Z","shell.execute_reply":"2022-04-10T09:43:36.981142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_soundwave(data_filtered, f'filterd {FILE_EXAMPLE}')","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:36.983416Z","iopub.execute_input":"2022-04-10T09:43:36.984189Z","iopub.status.idle":"2022-04-10T09:43:37.432802Z","shell.execute_reply.started":"2022-04-10T09:43:36.984126Z","shell.execute_reply":"2022-04-10T09:43:37.43198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" plot_melspectroram(data_filtered, f'filtered {FILE_EXAMPLE}')","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:37.43436Z","iopub.execute_input":"2022-04-10T09:43:37.434641Z","iopub.status.idle":"2022-04-10T09:43:38.078775Z","shell.execute_reply.started":"2022-04-10T09:43:37.434602Z","shell.execute_reply":"2022-04-10T09:43:38.077993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ipd.Audio(data_filtered, rate=sr_example)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T09:43:38.080329Z","iopub.execute_input":"2022-04-10T09:43:38.080804Z","iopub.status.idle":"2022-04-10T09:43:38.100997Z","shell.execute_reply.started":"2022-04-10T09:43:38.080755Z","shell.execute_reply":"2022-04-10T09:43:38.100126Z"},"trusted":true},"execution_count":null,"outputs":[]}]}