I have applied following codes to create spectogram plot
from scipy import signal
import matplotlib.pyplot as plt
import numpy as np
# Define the signal
Fs = 1e4 # Sampling Frequency
# Sin wave with Amplite 1 unit, 50Hz, for duration 0-5 seconds
N1 = (1e5)/2
time1 = np.arange(N1) / float(Fs)
x1 = 1*np.sin(2*np.pi*50*time1)
# Sin wave with Amplite 0.008 units, 100Hz, for duration 5-10 seconds
time2 = np.arange(N1,2*N1) / float(Fs)
x2 = 0.008*np.sin(2*np.pi*100*time2)
# Concatenate above two waves
T =np.concatenate((time1,time2))
Y =np.concatenate((x1,x2))
# Plot the waves
plt.plot(T , Y)
plt.title('Time Data')
plt.ylabel('Amplitude')
plt.xlabel('Time [sec]')
plt.show()
# spectrogram
freq_axis, time_axis, Sxx = signal.spectrogram(Y, Fs)
# Plot the spectrogram
plt.pcolormesh(time_axis, freq_axis, Sxx)
plt.title('Spectrogram')
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.xlim(0,10)
plt.ylim(0,200)
plt.show()
The results of the spectogram plot are as such:
In this plot, it seems that, the dominant frequencies are 37Hz to 75Hz from 0-5sec (yellow region). However, in the signal created, the only dominant freq. is 50 Hz from 0-5sec.
Also, the signal with 0.008 units amplitude, 100Hz created for duration 5-10 sec, cannot be identified.
Can somebody please let me know where am I going wrong?
Also, is there any way out to depict a colour bar just besides the plot window of the spectrogram so that the amplitude values corresponding to the colour can be seen?
