|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "id": "5d998359", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "import scipy\n", |
| 11 | + "import scipy.io\n", |
| 12 | + "import IPython.display\n", |
| 13 | + "import numpy as np\n", |
| 14 | + "import librosa\n", |
| 15 | + "\n", |
| 16 | + "import matplotlib.pyplot as plt" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "code", |
| 21 | + "execution_count": null, |
| 22 | + "id": "1f7443a8", |
| 23 | + "metadata": {}, |
| 24 | + "outputs": [], |
| 25 | + "source": [ |
| 26 | + "#Example to load mat file (first 40 seconds)\n", |
| 27 | + "#file = scipy.io.loadmat('../DATA/beethoven_40sec.mat')\n", |
| 28 | + "#sound = file[\"y\"][0] # data\n", |
| 29 | + "#T = int(file[\"T\"][0][0]) # length in seconds\n", |
| 30 | + "#FS = int(file[\"FS\"][0][0]) #sample frequency\n", |
| 31 | + "#samples = T*FS\n", |
| 32 | + "#t = np.arange(samples)" |
| 33 | + ] |
| 34 | + }, |
| 35 | + { |
| 36 | + "cell_type": "code", |
| 37 | + "execution_count": null, |
| 38 | + "id": "db4ff4da", |
| 39 | + "metadata": {}, |
| 40 | + "outputs": [], |
| 41 | + "source": [ |
| 42 | + "#original mp3 file\n", |
| 43 | + "FS = 24000\n", |
| 44 | + "y, sr = librosa.load('../DATA/beethoven.mp3', sr=FS)" |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + "cell_type": "code", |
| 49 | + "execution_count": null, |
| 50 | + "id": "510e4bd3", |
| 51 | + "metadata": {}, |
| 52 | + "outputs": [], |
| 53 | + "source": [ |
| 54 | + "plt.figure(figsize=(20,5))\n", |
| 55 | + "plt.plot(y)\n", |
| 56 | + "\n", |
| 57 | + "#for \"mat\" file use command\n", |
| 58 | + "#plt.plot(t, sound)" |
| 59 | + ] |
| 60 | + }, |
| 61 | + { |
| 62 | + "cell_type": "code", |
| 63 | + "execution_count": null, |
| 64 | + "id": "697e8139", |
| 65 | + "metadata": {}, |
| 66 | + "outputs": [], |
| 67 | + "source": [ |
| 68 | + "IPython.display.Audio(y, rate=FS)\n", |
| 69 | + "\n", |
| 70 | + "#For mat file use command \n", |
| 71 | + "#IPython.display.Audio(sound, rate=FS)" |
| 72 | + ] |
| 73 | + }, |
| 74 | + { |
| 75 | + "cell_type": "code", |
| 76 | + "execution_count": null, |
| 77 | + "id": "72d27077", |
| 78 | + "metadata": {}, |
| 79 | + "outputs": [], |
| 80 | + "source": [ |
| 81 | + "plt.rcParams[\"figure.figsize\"] = (20,5)\n", |
| 82 | + "plt.specgram(y, NFFT=8192, Fs=FS, noverlap=2048)\n", |
| 83 | + "plt.colorbar()" |
| 84 | + ] |
| 85 | + } |
| 86 | + ], |
| 87 | + "metadata": { |
| 88 | + "kernelspec": { |
| 89 | + "display_name": "Python 3 (ipykernel)", |
| 90 | + "language": "python", |
| 91 | + "name": "python3" |
| 92 | + }, |
| 93 | + "language_info": { |
| 94 | + "codemirror_mode": { |
| 95 | + "name": "ipython", |
| 96 | + "version": 3 |
| 97 | + }, |
| 98 | + "file_extension": ".py", |
| 99 | + "mimetype": "text/x-python", |
| 100 | + "name": "python", |
| 101 | + "nbconvert_exporter": "python", |
| 102 | + "pygments_lexer": "ipython3", |
| 103 | + "version": "3.8.12" |
| 104 | + } |
| 105 | + }, |
| 106 | + "nbformat": 4, |
| 107 | + "nbformat_minor": 5 |
| 108 | +} |
0 commit comments