-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmfcc_plot.py
More file actions
39 lines (28 loc) · 1.03 KB
/
mfcc_plot.py
File metadata and controls
39 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python
import librosa
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.patches as mpatches
"""
This script will create mfccs from a file, and then plot them with 'time' on the x axis
and the value of the mfcc on the y axis. Different mfccs are shown in different colors,
that way we can show multiple dimensions on the same plot.
"""
file_path = "NIPS4B_BIRD_CHALLENGE_TRAIN_TEST_WAV/train/nips4b_birds_trainfile015.wav"
y, sr = librosa.load(file_path)
freq_min = 500
freq_max = 8000
num_mfccs = 13
mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=num_mfccs, fmin=freq_min, fmax=freq_max)
num_rows, num_cols = mfccs.shape
t = range(0, num_cols)
colors = cm.rainbow(np.linspace(0, 1, num_rows))
patches = []
for i in range(0, num_mfccs):
patch = mpatches.Patch(color=colors[i], label='mfcc #{0:01d}'.format(i))
patches.append(patch)
plt.legend(handles=patches, loc='center right')
for i in range(1, num_rows):
plt.plot(t, mfccs[i], color=colors[i], linewidth=3)
plt.show()