New to the signal analysis I’m trying to calculate and plot a spectrogram for a given signal to find it’s cyclic frequency over time. But I’m having a hard time with scipy.signal.ShortTimeFFT function.
I currently have this:
x, fs = librosa.load("audio_file.wav", sr=none)
SFT = scipy.signal.ShortTimeFFT(x, hop=hop_size, fs=fs, scale_to='psd')
Sxx = SFT.spectrogram(x)
freq= SFT.f
time = np.arrange(Sxx.shape[1]) * SFT.delta_t
fig, ax = plot.subplots(fig=(6,4))
ax.pccolormesh(time, freq, Sxx)
plt.show()
I’m having a hard time understanding how to correctly calculate my time array as it’s a file of 30 seconds but the time array maximun value goes beyond 30 seconds depending on my hop_size value.
I also came across the function ‘scipy.signal.spectrogram’ but saw it was legacy?
However I tried it and it returns directly a correct time array, but why doesn’t it start from 0?
alpha, t, Sxx = signal.spectrogram(x, fs, window="hann")
New to all of this so still learning. Thanks!
By BacTEria is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.