Hello, I generated a spectrogram with plt.specgram, but for some reason I have some mirroring happening. Also, I would like to rotate the spectrogram 90 degrees to the right together with the axis (frequency on x axis and time on y axis). I attached the screenshot of the spectrogram. Any suggestion is welcomed. Thank you
The snipet
plt.rcParams[‘figure.figsize’] = [18, 8]
plt.rcParams.update({‘font.size’: 18})
dt = 0.0833 #Sampling interval of 0.0833 seconds (12Hz) - 1/12=0.0833.
t = np.arange(0,t1,dt)
x = df[“Rotation (RPM)”]
fs = 1/dt
##Plotting the Spectrogram
plt.specgram(x, NFFT=1024, Fs=1/dt, noverlap=10, cmap=‘twilight’, vmin= 0.001, alpha = 1)
plt.colorbar()
plt.xlabel(“Time (seconds)”)
plt.ylabel(“Frequency (Hz)”)
plt.show()
I also generated this vertical spectrogram (same data)
with this snipet:
x = df[“Rotation (RPM)”]
sample_rate = 1/dt
fft_size =1024
halfFftLength = fft_size >> 1
num_rows = len(x) // fft_size # // is an integer division which rounds down
spectrogram = np.zeros((num_rows, fft_size))
for i in range(num_rows):
spectrogram[i,:] = 10np.log10(np.abs(np.fft.fftshift(np.fft.fft(x[ifft_size:(i+1)*fft_size])))**2)
plt.imshow(spectrogram, aspect=‘auto’, extent = [sample_rate/-2,sample_rate/2, len(x)/sample_rate, 0],
cmap=‘twilight’, interpolation=‘nearest’, origin=‘upper’, alpha=0.8, vmin=0)
#np.rot90(spectrogram)
set_xlim=(0,6)
plt.colorbar()
plt.xlabel(“Frequency [Hz]”)
plt.ylabel(“Time [s]”)
plt.show()
How can I plot only the positive side from 0 to 6Hz? Thank you

