Advertisement
SamirBaghirzada

Untitled

Dec 5th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as pl
  3. from scipy.fftpack import fft, ifft, fftfreq
  4.  
  5. ######################################################################################################
  6. SAMPLE_RATE = 1024
  7. WINDOW_SIZE = 1024
  8. N = 1024
  9. fr1 = 50 #frequency 1
  10. fr2 = 80 #frequency 2
  11. freq = np.absolute(fftfreq(N))*WINDOW_SIZE
  12.  
  13. ######################################################################################################
  14. t = np.linspace(0,1,SAMPLE_RATE)[:WINDOW_SIZE]
  15. sine_wave = np.sin(fr1*2*np.pi*t) + 0.5*np.sin(fr2*2*np.pi*t)
  16. sine_wave_hamming = sine_wave*np.hamming(WINDOW_SIZE)
  17. sine_wave_hanning = sine_wave*np.hanning(WINDOW_SIZE)
  18.  
  19. ######################################################################################################
  20. sine_wavefft = np.absolute(fft(sine_wave,N))/WINDOW_SIZE*2
  21. sine_wave_hammingfft = np.absolute(fft(sine_wave_hamming,N))/WINDOW_SIZE*2
  22. sine_wave_hanningfft = np.absolute(fft(sine_wave_hanning,N))/WINDOW_SIZE*2
  23.  
  24.  
  25. ######################################################################################################
  26. pl.subplot(3,1,1)
  27. pl.xlabel("Freq")
  28. pl.ylabel("Amplitude")
  29. pl.grid()
  30. pl.plot(freq, sine_wavefft)
  31.  
  32.  
  33. pl.subplot(3,1,2)
  34. pl.xlabel("Freq")
  35. pl.ylabel("Amplitude")
  36. pl.grid()
  37. pl.plot(freq, sine_wave_hammingfft)
  38.  
  39.  
  40. pl.subplot(3,1,3)
  41. pl.xlabel("Freq")
  42. pl.ylabel("Amplitude")
  43. pl.grid()
  44. pl.plot(freq, sine_wave_hanningfft)
  45.  
  46. ######################################################################################################
  47. pl.tight_layout()
  48. pl.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement