Reputation: 23
I am plotting the spectrogram for the electric field data. However the plot does not give the correct logarithmic y axis.
I have tried using specgram function in both matplotlib as well as scipy signal. However I am unable to get the correct logarithmic axis. I have also tried using librosa.
fig3, ax3 = plt.subplots()
# Compute the spectrogram
f, t, Sxx = signal.spectrogram(e_mfa_new[:, 2], fs)
Sxx_db = 10 * np.log10(Sxx)
# Plot the spectrogram
plt.pcolormesh(t, f, Sxx_db)
plt.yscale('log')
plt.colorbar()
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.show()
# Compute STFT
S = librosa.stft(e_mfa_new[:, 2])
# Convert amplitude to dB
S_db = librosa.amplitude_to_db(abs(S), ref=np.max)
# Plot spectrogram
fig, ax = plt.subplots()
img = librosa.display.specshow(S_db, x_axis='time', y_axis='log', ax=ax)
fig.colorbar(img, ax=ax)
# plt.title('Spectrogram')
plt.show()
If I am setting the y scale as log I get something of this form
The correct plot should of this form
Upvotes: 0
Views: 16