Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- def stft(x, L, overlap, window):
- opoints = int(L*overlap)
- X = np.array([np.abs(np.fft.fft(window*x[i:i+L])[:L//2])
- for i in range(0,len(x)-L,opoints)])
- return X
- t = np.linspace(0, 5, 11025*5)
- xf = np.linspace(0, 2000, 11025*5)
- w = 2*np.pi*xf
- x = np.sin(w*t)
- f = np.linspace(0, 11025, 1024)
- window = np.hanning(1024)
- stft = stft(x,1024,0.5,window)
- plt.imshow(stft[:1024//2].T, cmap = plt.get_cmap('gist_yarg'), origin='lower', aspect='auto',
- interpolation='nearest', extent=(0,5, 0,11025/2))
- plt.xlabel("Time [s]")
- plt.ylabel("Frequency [Hz]")
- plt.show()
Add Comment
Please, Sign In to add comment