forked from dynamicslab/databook_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/dylewsky/Data_Driven_Scie…
…nce_Python_Demos Merge to local branch
- Loading branch information
Showing
2 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |