import numpy as np import matplotlib.pyplot as plt sample_rate = 1e6 # Generate tone plus noise t = np.arange(1024*1000)/sample_rate # time vector f = 50e3 # freq of tone x = np.sin(2*np.pi*f*t) # simulate the signal above, or use your own signal fft_size = 1024 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,:] = 10*np.log10(np.abs(np.fft.fftshift(np.fft.fft(x[i*fft_size:(i+1)*fft_size])))**2) plt.imshow(spectrogram, aspect='auto', extent = [sample_rate/-2/1e6, sample_rate/2/1e6, len(x)/sample_rate, 0]) plt.xlabel("Frequency [MHz]") plt.ylabel("Time [s]") plt.show()