Last active
February 8, 2021 14:19
-
-
Save SuperShinyEyes/02c5e5336ca74b30ed12c0b0b386f4e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import matplotlib.pyplot as plt | |
import soundfile as sf | |
import librosa | |
plt.rcParams['font.family'] = 'serif' | |
plt.rcParams['font.serif'] = 'Ubuntu' | |
plt.rcParams['font.monospace'] = 'Ubuntu Mono' | |
plt.rcParams['font.size'] = 10 | |
plt.rcParams['axes.labelsize'] = 10 # Time and Hz, i.e. labels | |
plt.rcParams['axes.labelweight'] = 'bold' | |
plt.rcParams['xtick.labelsize'] = 15 # Time(x) tick values | |
plt.rcParams['ytick.labelsize'] = 15 # Hz(y) tick values | |
plt.rcParams['legend.fontsize'] = 17 | |
plt.rcParams['figure.titlesize'] = 10 | |
plt.rcParams['axes.titlesize'] = 14 # Title font | |
#--------------------------------------------------- | |
# Plot amplitudes | |
fig, axarr = plt.subplots(3, 3, figsize=(17, 8)) | |
fig.suptitle("15 sec & 3 sec & 1.5 sec", fontsize=16) | |
length = 5 # sec | |
#---------------------------------------------------- | |
# Reference | |
ref, sr = sf.read("adele/test/11 Someone Like You.wav", 44100*15, ) | |
axarr[0,0].plot(ref[:44100*length], 'b') | |
axarr[0,1].plot(ref[:44100*length//5], 'b') | |
axarr[0,2].plot(ref[:44100*length//10], 'b') | |
axarr[0,2].legend(['Reference'], loc=1) | |
#---------------------------------------------------- | |
# Damaged | |
y, sr = librosa.core.load("adele/test/4410/11 Someone Like You.wav", sr=None) | |
axarr[1,0].plot(y[:4410*length], 'r') | |
axarr[1,1].plot(y[:4410*length//5], 'r') | |
axarr[1,2].plot(y[:4410*length//10], 'r') | |
axarr[1,2].legend(['Damaged'], loc=1) | |
#---------------------------------------------------- | |
# Decoded | |
decoded, sr = librosa.core.load("adele/test/decoded/11 Someone Like You.mp3", sr=None) | |
axarr[2,0].plot(decoded[:44100*length], 'g') | |
axarr[2,1].plot(decoded[:44100*length//5], 'g') | |
axarr[2,2].plot(decoded[:44100*length//10], 'g') | |
axarr[2,2].legend(['Decoded'], loc=1) | |
#---------------------------------------------------- | |
# Fine-tune figure; hide x ticks for top plots and y ticks for right plots | |
plt.setp([a.get_xticklabels() for a in axarr[0, :]], visible=False) | |
plt.setp([a.get_yticklabels() for a in axarr[:, 1]], visible=False) | |
# Tight layout often produces nice results | |
# but requires the title to be spaced accordingly | |
fig.tight_layout() | |
fig.subplots_adjust(top=0.92) |
Author
SuperShinyEyes
commented
Feb 8, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment