Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. def logarytm(x):
  2. for i in range(0, x.size):
  3. if x[i] != 0:
  4. x[i] = log(x[i])
  5. return x
  6.  
  7. T = 1
  8. Fs = 10000
  9. t = arange(0,T,1/Fs)
  10.  
  11. #Tworzymy wykresy
  12. fig,ax = subplots(10, 4, figsize=(20,50))
  13.  
  14. #Generujemy sygnał
  15. y = sin(2*pi*999.5*t)
  16. ax[0,0].plot(t,y)
  17. ax[0,0].set_title('Oryginalny sygnał')
  18. ax[0,0].set_xlim(0,0.01)
  19.  
  20. #Obliczamy jego FFT
  21. Y = fft.fft(y)
  22. f = linspace(0,Fs,Y.size)
  23. ax[0,2].plot(f,abs(Y))
  24. ax[0,2].set_title('FFT sygnału')
  25. ax[0,2].set_xlim(990,1010)
  26. ax[0,3].plot(f,logarytm(abs(Y)))
  27.  
  28. ########################## BARTLETT ##########################
  29. h = bartlett(y.size)
  30. ax[1,0].plot(t,h)
  31. ax[1,0].set_title('Bartlett')
  32.  
  33. ny = h * y
  34. Y = fft.fft(ny)
  35. f = linspace(0,Fs,Y.size)
  36. H = fft.fft(h)
  37. ax[1,1].plot(f, logarytm(abs(H)))
  38. ax[1,1].set_title('FFT Bartlett')
  39. ax[1,2].plot(f,abs(Y))
  40. ax[1,2].set_xlim(990,1010)
  41. ax[1,3].plot(f,logarytm(abs(Y)))
  42.  
  43. ########################## BLACKMAN ##########################
  44. h = blackman(y.size)
  45. ax[2,0].plot(t,h)
  46. ax[2,0].set_title('Blackman')
  47.  
  48. ny = h * y
  49. Y = fft.fft(ny)
  50. f = linspace(0,Fs,Y.size)
  51. H = fft.fft(h)
  52. ax[2,1].plot(f, logarytm(abs(H)))
  53. ax[2,1].set_title('FFT Blackman')
  54. ax[2,2].plot(f,abs(Y))
  55. ax[2,2].set_xlim(990,1010)
  56. ax[2,3].plot(f,logarytm(abs(Y)))
  57.  
  58. ########################## HAMMING ##########################
  59. h = hamming(y.size)
  60. ax[3,0].plot(t,h)
  61. ax[3,0].set_title('Hamming')
  62.  
  63. ny = h * y
  64. Y = fft.fft(ny)
  65. f = linspace(0,Fs,Y.size)
  66. H = fft.fft(h)
  67. ax[3,1].plot(f, logarytm(abs(H)))
  68. ax[3,1].set_title('FFT Hamming')
  69. ax[3,2].plot(f,abs(Y))
  70. ax[3,2].set_xlim(990,1010)
  71. ax[3,3].plot(f,logarytm(abs(Y)))
  72.  
  73. ########################## HANNING ##########################
  74. h = hanning(y.size)
  75. ax[4,0].plot(t,h)
  76. ax[4,0].set_title('Hanning')
  77.  
  78. ny = h * y
  79. Y = fft.fft(ny)
  80. f = linspace(0,Fs,Y.size)
  81. H = fft.fft(h)
  82. ax[4,1].plot(f, logarytm(abs(H)))
  83. ax[4,1].set_title('FFT Hanning')
  84. ax[4,2].plot(f,abs(Y))
  85. ax[4,2].set_xlim(990,1010)
  86. ax[4,3].plot(f,logarytm(abs(Y)))
  87.  
  88. ########################## KAISER ##########################
  89. ks = [0, 5, 6, 8.6, 14]
  90.  
  91. for i in range(0, 5):
  92. h = kaiser(y.size, ks[i])
  93. ax[5 + i, 0].plot(t,h)
  94. ax[5 + i, 0].set_title('Kaiser %.1f' % (ks[i]))
  95.  
  96. ny = h * y
  97. Y = fft.fft(ny)
  98. f = linspace(0,Fs,Y.size)
  99. H = fft.fft(h)
  100. ax[5 + i, 1].plot(f, logarytm(abs(H)))
  101. ax[5 + i, 1].set_title('FFT Kaiser %.1f' % (ks[i]))
  102. ax[5 + i, 2].plot(f,abs(Y))
  103. ax[5 + i, 2].set_xlim(990,1010)
  104. ax[5 + i, 3].plot(f,logarytm(abs(Y)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement