Reputation: 43619
I have:
frequencies, times, spectrogram = signal.spectrogram(
samples, sample_rate, nperseg=nperseg, window=signal.hann(nperseg), noverlap=noverlap, mode='magnitude')
I have nperseg=320
and noverlap=80
, with a sample_rate=16000
.
I had 232800
samples.
However, my spectrogram.shape
is now (161, 969)
. So that's 161 frequency bins with 969 time segments. How was that 969 calculated?
Upvotes: 0
Views: 1447
Reputation: 43619
time_per_segment_ms = 20
nperseg = int(sample_rate * 0.001 * time_per_segment_ms)
overlap = nperseg // 4
seconds_per_segment = (nperseg - overlap) / sample_rate
ms_per_segment = int(seconds_per_segment * 1000)
That about does it
Upvotes: 1