Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. # Python code
  2.  
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5.  
  6. dur = 20
  7. fs = 1024
  8. freq = np.arange(1, 500, 1)
  9. t1 = np.arange(0, dur, 1/fs)
  10. x1 = np.sum([np.sin(2*np.pi*f*t1) for f in freq], axis=0)
  11.  
  12. nfft = 1024
  13. X1 = np.fft.fft(x1, nfft)[:nfft//2]
  14. f1 = np.arange(0, nfft//2) * fs / nfft
  15.  
  16. plt.figure()
  17. plt.title('Baseline FFT Output')
  18. plt.plot(f1, np.abs(X1))
  19. plt.grid()
  20. plt.xlim([0, nfft/2])
  21. plt.show()
  22.  
  23. step = 10
  24. x2 = x1[::step] # some kind of downsampling??
  25. fs2 = fs/10
  26.  
  27. nfft = 1024
  28. X2 = np.fft.fft(x2, nfft)[:nfft//2]
  29. f2 = np.arange(0, nfft//2) * fs2 / nfft
  30.  
  31. plt.figure(figsize=(10,5))
  32. plt.title('New FFT Output')
  33. plt.plot(f2, np.abs(X2) / nfft)
  34. plt.xlabel('Hz')
  35. plt.grid()
  36. plt.xlim([0, 18])
  37. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement