Guest User

Untitled

a guest
Nov 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import wave
  2. import numpy as np
  3. import scipy
  4.  
  5. import matplotlib.pyplot as plt
  6.  
  7. wr = wave.open('/home/volta/Dokumenty/predmety/zns/programy/zvuk/youparse/piano/18.wav', 'r')
  8.  
  9. sz = 44100 # Read and process 1 second at a time.
  10. data = np.fromstring(wr.readframes(-1), dtype=np.int16)
  11.  
  12.  
  13. previous = 0
  14. sample_rate = 22050
  15. for i in range(1,int(len(data)/sample_rate)):
  16. print(i)
  17. plt.figure(1)
  18.  
  19. #plt.plot(data[previous:i*sample_rate])
  20. #plt.show()
  21. dataFFT = abs(np.fft.rfft(data[previous:i*sample_rate]))
  22.  
  23. #b = plt.subplot(212)
  24. #b.set_xscale('log')
  25. #plt.plot(dataFFT)
  26. #plt.show()
  27. previous += sample_rate
  28.  
  29. '''plt.figure(1)
  30. a = plt.subplot(211)
  31. #r = 2**16/2
  32. r = 2**15
  33. a.set_ylim([-r, r])
  34. a.set_xlabel('time [s]')
  35. a.set_ylabel('sample value [-]')
  36. x = np.arange(44100)/(44100)
  37. print(len(x))
  38. print(len(left))
  39. plt.plot(x, data )
  40. plt.show()
  41.  
  42. b = plt.subplot(212)
  43. b.set_xscale('log')
  44. b.set_xlabel('frequency [Hz]')
  45. b.set_ylabel('|amplitude|')
  46. plt.plot(FFT)
  47. plt.show()
  48. plt.savefig('sample-graph.png')
  49. '''
Add Comment
Please, Sign In to add comment