Guest User

Untitled

a guest
Oct 24th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. def stft(x, L, overlap, window):
  5. opoints = int(L*overlap)
  6. X = np.array([np.abs(np.fft.fft(window*x[i:i+L])[:L//2])
  7. for i in range(0,len(x)-L,opoints)])
  8. return X
  9.  
  10. t = np.linspace(0, 5, 11025*5)
  11.  
  12. xf = np.linspace(0, 2000, 11025*5)
  13. w = 2*np.pi*xf
  14. x = np.sin(w*t)
  15.  
  16. f = np.linspace(0, 11025, 1024)
  17.  
  18. window = np.hanning(1024)
  19.  
  20. stft = stft(x,1024,0.5,window)
  21.  
  22. plt.imshow(stft[:1024//2].T, cmap = plt.get_cmap('gist_yarg'), origin='lower', aspect='auto',
  23. interpolation='nearest', extent=(0,5, 0,11025/2))
  24.  
  25. plt.xlabel("Time [s]")
  26. plt.ylabel("Frequency [Hz]")
  27. plt.show()
Add Comment
Please, Sign In to add comment