D Rayner
D Rayner

Reputation: 55

signal.spectrogram find maximum frequency for given segment

After calling scipy.signal.spectrogram is it possible to determine the strengths of different frequencies for a given segment?

i.e. after executing the following:

fs, data = wavfile.read(waveFile)    

sampleFreqs, segmentTimes, sxx= signal.spectrogram(data, fs, nperseg=256, noverlap=128, nfft=512, window=('hamming'))

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12,4))    
ax1.pcolormesh((len(segmentTimes)*segmentTimes/segmentTimes[-1]), sampleFreqs, 10*np.log10(sxx))
ax1.set_title('Spectrogram');
ax1.set_xlabel('Segment')
ax1.set_ylabel('Frequency')

which produces a spectrogram such as this.

Can I find out from sxx what the strongest frequency is for the 10th segment, for example?

Cheers, David

Upvotes: 4

Views: 2244

Answers (1)

Paul Panzer
Paul Panzer

Reputation: 53029

Have a look at numpy.argmax. Your data look clean enough, so that should work, no filtering required.

Upvotes: 4

Related Questions