diff --git a/CH01/CH01_SEC04_2_Cement.ipynb b/CH01/CH01_SEC04_2_Cement.ipynb index 41c43f4..3118afc 100644 --- a/CH01/CH01_SEC04_2_Cement.ipynb +++ b/CH01/CH01_SEC04_2_Cement.ipynb @@ -51,7 +51,7 @@ "# x = regress(b,A)\n", "\n", "# Alternative 2:\n", - "x = np.linalg.pinv(A)*b" + "x = np.linalg.pinv(A)@b" ] }, { diff --git a/CH02/CH02_SEC04_2_SpectrogramBeethoven.ipynb b/CH02/CH02_SEC04_2_SpectrogramBeethoven.ipynb new file mode 100644 index 0000000..940a075 --- /dev/null +++ b/CH02/CH02_SEC04_2_SpectrogramBeethoven.ipynb @@ -0,0 +1,108 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "5d998359", + "metadata": {}, + "outputs": [], + "source": [ + "import scipy\n", + "import scipy.io\n", + "import IPython.display\n", + "import numpy as np\n", + "import librosa\n", + "\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1f7443a8", + "metadata": {}, + "outputs": [], + "source": [ + "#Example to load mat file (first 40 seconds)\n", + "#file = scipy.io.loadmat('../DATA/beethoven_40sec.mat')\n", + "#sound = file[\"y\"][0] # data\n", + "#T = int(file[\"T\"][0][0]) # length in seconds\n", + "#FS = int(file[\"FS\"][0][0]) #sample frequency\n", + "#samples = T*FS\n", + "#t = np.arange(samples)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "db4ff4da", + "metadata": {}, + "outputs": [], + "source": [ + "#original mp3 file\n", + "FS = 24000\n", + "y, sr = librosa.load('../DATA/beethoven.mp3', sr=FS)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "510e4bd3", + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure(figsize=(20,5))\n", + "plt.plot(y)\n", + "\n", + "#for \"mat\" file use command\n", + "#plt.plot(t, sound)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "697e8139", + "metadata": {}, + "outputs": [], + "source": [ + "IPython.display.Audio(y, rate=FS)\n", + "\n", + "#For mat file use command \n", + "#IPython.display.Audio(sound, rate=FS)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "72d27077", + "metadata": {}, + "outputs": [], + "source": [ + "plt.rcParams[\"figure.figsize\"] = (20,5)\n", + "plt.specgram(y, NFFT=8192, Fs=FS, noverlap=2048)\n", + "plt.colorbar()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}