0
$\begingroup$

I have a short term fourier transform plot that I plot using matplotlib's pcolormesh() function: stft

If I zoom in the plot, I see this: stft_zoomed

Now, I want the plot to just show the zoomed-in range on the y-axis - till 4 or 3 kHz. Is there any way to do this without having to manually zoom in? I want to do a comparison for multiple waveforms in the frequency range as this is my passband in the passband filter I apply on the data.

Here is the code I use to compute and plot the stft:

sampleFreq, segmentTimes, stftX = sp.stft(filteredY, fs)
segmentTimes += (1.5 / 1000)
plt.pcolormesh(segmentTimes, sampleFreq, np.abs(stftX), shading='gouraud')
plt.ylabel("Frequency (Hz)")
plt.xlabel("Time (s)")
plt.title("Sort Term FFT")
plt.show()

I add 1.5 to the segmentTimes because I trim my original data from 1.5 to 2.5 ms, and for some reason, if I don't add 1.5 here, the stft starts from 0.0 s. And the division by 1000 is for conversion to seconds from milliseconds.

Also, sampleFreq and segmentTimes are simple lists but stftX is a list of lists.

$\endgroup$
0
$\begingroup$

Use matplotlib.pyplot's axis() function as follows:

# show section based on bandpass filter cut-off frequencies
plt.title("Zoomed Short Term Fourier Transform")
plt.xlabel("Time (s)")
plt.ylabel("Frequency Magnitude")
plt.pcolormesh(self.segment_times, self.sample_freq, self.abs_stft, shading='gouraud')
plt.axis([self.segment_times[0], self.segment_times[-1], high_pass, low_pass])

plt.show()

where high_pass and low_pass are the frequency cut-offs within which you want to display the y-axis data.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.