Serie: Music
python
28 righe
· Aggiornato 2026-02-03
test01.py
Music/test01.py
import numpy as np
import librosa
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
# Step 1: Load audio
y, sr = librosa.load('performances/performance1.wav')
# Step 2: Extract MFCCs (Mel Frequency Cepstral Coefficients)
mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13) # shape: (13, time frames)
# Step 3: Transpose to shape (time frames, 13)
mfccs_T = mfccs.T
# Step 4: Apply PCA
pca = PCA(n_components=2) # reduce to 2D
mfccs_pca = pca.fit_transform(mfccs_T) # shape: (time frames, 2)
# Step 5: Plot PCA result
plt.figure(figsize=(10, 5))
plt.plot(mfccs_pca[:, 0], label='Principal Component 1')
plt.plot(mfccs_pca[:, 1], label='Principal Component 2')
plt.xlabel('Time Frame')
plt.ylabel('PCA Value')
plt.title('PCA of MFCCs')
plt.legend()
plt.grid(True)
plt.show()
Articoli correlati
Music
python
Aggiornato 2026-02-03
essentia.py
essentia.py — python source code from the Music learning materials (Music/essentia.py).
Leggi l'articolo →
Music
python
Aggiornato 2026-02-03
ex01.py
ex01.py — python source code from the Music learning materials (Music/ex01.py).
Leggi l'articolo →
Music
python
Aggiornato 2026-02-03
extract_midi_notes.py
extract_midi_notes.py — python source code from the Music learning materials (Music/extract_midi_notes.py).
Leggi l'articolo →
Music
python
Aggiornato 2026-02-03
getMidiNotes.py
getMidiNotes.py — python source code from the Music learning materials (Music/getMidiNotes.py).
Leggi l'articolo →
Music
python
Aggiornato 2026-02-03
markovchain_v2.py
markovchain_v2.py — python source code from the Music learning materials (Music/markovchain_v2.py).
Leggi l'articolo →
Music
python
Aggiornato 2026-02-03
musc5211.py
musc5211.py — python source code from the Music learning materials (Music/musc5211.py).
Leggi l'articolo →