I am not Fat
I am not Fat

Reputation: 447

Why is the plot in librosa different?

I am currently trying using librosa to perform stfft, such that the parameter resembles a stfft process from a different framework (Kaldi).

The audio file is fash-b-an251

Kaldi does it using a sample frequency of 16 KHz, window_size = 400 (25ms), hop_length=160 (10ms).

The spectrogram extracted from this looks like this:

enter image description here I then tried to do the same using librosa:

import numpy as np
import sys
import librosa
import os
import scipy
import matplotlib.pyplot as plt
from matplotlib import cm


#   Input parameter
#   relative_path_to_file


if len(sys.argv) < 1:
    print "Missing Arguments!"
    print "python spectogram_librosa.py path_to_audio_file"
    sys.exit()

path = sys.argv[1]
abs_path = os.path.abspath(path)
spectogram_dnn = "/home/user/dnn/spectogram"

if not os.path.exists(spectogram_dnn):
    print "spectogram_dnn folder didn't exist!"
    os.makedirs(spectogram_dnn)
    print "Created!"

y,sr = librosa.load(abs_path,sr=16000)
D = librosa.logamplitude(np.abs(librosa.core.stft(y, win_length=400, hop_length=160, window=scipy.signal.hanning,center=False)), ref_power=np.max)
librosa.display.specshow(D,sr=16000,hop_length=160, x_axis='time', y_axis='log', cmap=cm.jet)
plt.colorbar(format='%+2.0f dB')
plt.title('Log power spectrogram')
plt.show()
raw_input()
sys.exit()

Which is basically taken from here:

In which i've modified the stfft function such that it fits my parameters.. Problems is that is creates an entirely different plot..

enter image description here

So.. What am I doing wrong in librosa?.. Why is this plot so much different, from the one created in kaldi.

Am I missing something?

Upvotes: 4

Views: 2257

Answers (1)

vegancheese
vegancheese

Reputation: 59

It has to do with the Hz scale. The one in the first image is linear while the one in the second image is logarithmic. You can fix it by either changing the scale in either of the images to match the other.

Upvotes: 1

Related Questions