I am trying to analyze the frequencies of a song at certain points of time held inside an array.
I am using the scipy.signal.spectrogram function to generate those frequencies. the length of the song is 2:44, or 164 seconds, and the sampling rate of the scipy.wavfile read is 44100.
When I use spectrogram:
f, t, Sxx= signal.spectrogram(data[:, 1], sr)
The length of f is really small, 129 elements. t is longer, at 32322, but still a long shot away from the 7240320 sampling windows in the original wavfile.read.
(data[:, 1] is the right channel of the audio data)
Advertisement
Answer
The length of the f the default nperseg
of the stft
256 divided by 2 (only the positive side of the frequency scale) + 1 (frequency 0).
The number of samples in time is achieved by
t.size = len(data[:, 1]) / nperseg * (1 + noverlap)
where noverlap
is 256/8=32
.