-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualize features.py
97 lines (74 loc) · 2.67 KB
/
visualize features.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 3 10:33:12 2019
@author: Mountassir Youssef
"""
import numpy as np
import librosa
import matplotlib.pyplot as plt
import os
from glob import glob
import librosa.display
from extract_features import extract_features
#files retrieval
EXT = "*.wav"
directory= "C:/Users/Mountassir Youssef/Desktop/PJE/Data/test"
direc = [file
for path, subdir, files in os.walk(directory)
for file in glob(os.path.join(path, EXT))]
#load the files and extract features
for i in range(len(direc)):
y, sr = librosa.load(direc[i])
S, ph = librosa.magphase(librosa.stft(y))
S_mel = librosa.feature.melspectrogram(y=y, sr=sr)
dictio = extract_features(y, sr)
# les chroma
plt.subplot(7,2,1)
librosa.display.specshow(dictio['f1'],y_axis='chroma', x_axis='time')
plt.title('chroma stft')
plt.subplot(7,2,2)
librosa.display.specshow(dictio['f2'],y_axis='chroma', x_axis='time')
plt.title('chroma cqt')
plt.subplot(7,2,3)
librosa.display.specshow(dictio['f3'],y_axis='chroma', x_axis='time')
plt.title('chroma cens')
#mel spectogramm
plt.subplot(7,2,4)
librosa.display.specshow(librosa.power_to_db(S_mel,ref=np.max),y_axis='mel',x_axis='time')
plt.title('MEL spectogramm')
#mfcc
plt.subplot(7,2,5)
librosa.display.specshow(dictio['f4'],x_axis='time')
plt.title('MFCC')
#rms
plt.subplot(7,2,6)
plt.semilogy(dictio['f5'].T, label='RMS Energy')
plt.title('RMS energy')
#log power spectogramm
plt.subplot(7,2,7)
librosa.display.specshow(librosa.amplitude_to_db(S, ref=np.max),y_axis='log', x_axis='time')
plt.title('log power spectogramm')
#spectral centroid
plt.subplot(7,2,8)
plt.semilogy(dictio['f6'].T, label='Spectral centroid')
plt.title('Spectral centroid')
#spectral bandwidth
plt.subplot(7,2,9)
plt.semilogy(dictio['f7'].T, label='Spectral bandwidth')
plt.title('Spectral bandwidth')
#spectral contrast
plt.subplot(7,2,10)
librosa.display.specshow(dictio['f8'], x_axis='time')
plt.title('Spectral contrast')
#rolloff
plt.subplot(7,2,11)
plt.semilogy(dictio['f10'].T, label='Roll-off frequency')
plt.title('roll off')
#quadratic polynome
plt.subplot(7,2,12)
plt.plot(dictio['f11'][2], label='order=2', alpha=0.8)
plt.title('quadratic poly')
#tonal centroid
plt.subplot(7,2,13)
librosa.display.specshow(dictio['f12'], y_axis='tonnetz')
plt.title('tonal centroid')