How can I plot a matplotlib.mlab spectrogram while keeping the frequency and time values?

765 views Asked by At

I'm trying to plot a colour map and I need to use mlab.specgram() to perform a cross-correlation of two functions in the frequency domain, so I can't use pyplot.specgram(). I used pyplot.imshow in order to plot a colour map of the cross-correlation, but as a result the axes are just index numbers rather than the actual time values corresponding to the power shown in the colour map.

I've tried to change the labels using xticks()/yticks() and the extent argument, but all it does is show me a small portion of my colour map instead of changing the labels.

Is there a way for me the change the scale of my axes to match the actual frequency and time?

For reference:

# My spectrograms:
spec_H1, freqs, t = mlab.specgram(H_filt, NFFT=NFFT, Fs=fs, noverlap=NOVL, mode=mode) 
spec_L1, freqs, t = mlab.specgram(L_filt, NFFT=NFFT, Fs=fs, noverlap=NOVL, mode=mode)

# The cross-correlation:
X = np.real(spec_H1 * np.conj(spec_L1))

# The figure:
plt.figure(figsize=(10,10))
plt.imshow(abs(X), cmap = 'jet')
plt.colorbar() 
plt.ylim(0,200)
plt.xlim(0,500)

The figure

As you can see, for example, the time axis (x) should run from 0 to 4 seconds, but it's sampled such that it runs from 0 to 500. How do I change this?

0

There are 0 answers