From 510273cfa184c11696cae570bbc205467c5d0d84 Mon Sep 17 00:00:00 2001 From: Matthew Reeves Date: Sun, 30 Aug 2020 14:28:54 -0700 Subject: [PATCH 1/2] Change the element-wise multiply operator to the matrix multiply operator. --- CH01/CH01_SEC04_2_Cement.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CH01/CH01_SEC04_2_Cement.ipynb b/CH01/CH01_SEC04_2_Cement.ipynb index 80378d2..8f88771 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" ] }, { From 29132afa280656aed8b70211f5a19624674f73e6 Mon Sep 17 00:00:00 2001 From: Dmitri Grigoriev Date: Thu, 28 Oct 2021 09:01:29 +0200 Subject: [PATCH 2/2] Add implementation of spectogram (Beethoven and mp3) for Chapter 2 --- CH02/CH02_SEC04_2_SpectrogramBeethoven.ipynb | 108 +++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 CH02/CH02_SEC04_2_SpectrogramBeethoven.ipynb 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 +}