from pylab import*
# short
pxx, freqs, bins, im=specgram(data,NFFT=N,Fs=wf.getframerate(), noverlap=0, window=hammingWindow)
axis([0, length, 0, wf.getframerate()/2])
show()
I can make a spectrogram with a code like this, but what should I do if I want you to write it down in a file with numerical data?
python
pxx
has a spectrogram, freqs
has a frequency, and bins
has a time, so you can save them to a file in an easy-to-use format.
To plot them: np=numpy
, plt=matplotlib.pyplot
W,T=np.meshgrid(bins, freq)
plt.pcolormesh(W,T,pxx)
I think this specgram
is matplotlib.pyplot.specgram, but since this is for illustration purposes only, it may be appropriate for scipy.signal.spectrogram.As you can see in the sample,
f,t,Sxx=signal.spectrogram(x,fs)
plt.pcolormesh(t,f,Sxx)
You can see it in
© 2024 OneMinuteCode. All rights reserved.