vault backup: 2023-12-12 18:22:47
This commit is contained in:
27
00. Inbox/使用 librosa 做 FFT.md
Normal file
27
00. Inbox/使用 librosa 做 FFT.md
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
n_fft=2048
|
||||
ft = np.abs(librosa.stft(y[:n_fft], hop_length=n_fft+l))
|
||||
plt.plot(ft)
|
||||
plt.title('Spectrum')
|
||||
plt.xlabel('Frequency Bin')
|
||||
plt.ylabel('Amp1itude')
|
||||
```
|
||||
|
||||
output e.g.:
|
||||
![[Pasted image 20231212180917.png]]
|
||||
|
||||
這時候 Y 軸是 amplitude,可以使用 `librosa.amplitude_to_db()` 來把 amplitude 轉為 db。
|
||||
|
||||
```python
|
||||
import librosa.display
|
||||
spec = np.abs(librosa.stft(y, hop_1ength=512))
|
||||
spec = librosa.amplitude_to_db(spec, ref=np.max)
|
||||
librosa.display.specshow(spec, sr=sr, x_axis='time', y_axis='log')
|
||||
p1t.colorbar(format='%+2.0f dB')
|
||||
plt.title( 'Spectrogram')
|
||||
```
|
||||
|
||||
Output:
|
||||
![[Pasted image 20231212181543.png]]
|
||||
13
00. Inbox/使用 librosa 做 mel spectrogram.md
Normal file
13
00. Inbox/使用 librosa 做 mel spectrogram.md
Normal file
@@ -0,0 +1,13 @@
|
||||
由於人類會對低頻低音高的片段更感興趣,所以會對通過 FFT 變換得到的 Amplitude 和 Frequency。
|
||||
[[Mel spectrogram]] 和 spectrogram 的差別就是 mel spectrogram 的頻率是 mel scale 變換後的頻率(你可以想像把Spectrogram整體往下壓)
|
||||
|
||||
```python
|
||||
mel_spect = librosa.feature.melspectrogram(y=y, sr=sr, n fft=2048, hop_Iength=1024)
|
||||
mel_spect = librosa.power_to_db(mel_spect, ref=np.max)
|
||||
librosa.display.specshow(mel_spect, y_axis='mel', fmax=8000, x_axis='time')
|
||||
plt.title('Mel Spectrogram')
|
||||
p1t.colorbar(format='%+2.0f dB')
|
||||
```
|
||||
|
||||
Output:
|
||||
![[Pasted image 20231212181946.png]]
|
||||
Reference in New Issue
Block a user