Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. import tkinter
  2. from scipy.io import wavfile
  3. from scipy.signal import spectrogram, lfilter, freqz, tf2zpk
  4. from scipy.stats import pearsonr
  5. import soundfile as sf
  6. import matplotlib.pyplot as plt
  7. import numpy as np
  8.  
  9.  
  10. s, fs = sf.read('sa1.wav')
  11. t = np.arange(s.size) / fs
  12.  
  13. f, t, sgr = spectrogram(s, fs,nperseg=400, noverlap=240, nfft= 511)
  14. sgr_log = 10 * np.log10(sgr+1e-20)
  15. plt.figure(figsize=(9, 3))
  16. plt.pcolormesh(t, f, sgr_log)
  17. plt.gca().set_xlabel('Čas [s]')
  18. plt.gca().set_ylabel('Frekvence [Hz]')
  19. cbar = plt.colorbar()
  20. cbar.set_label('Spektralní hustota výkonu [dB]', rotation=270, labelpad=15)
  21. plt.tight_layout()
  22. plt.savefig('yourfile.pdf')
  23. matrix = np.zeros((16,331))
  24. for a in range(331):
  25. for c in range (0,16,1):
  26. matrix[0,a] = matrix[0,a] + sgr_log[c,a]
  27. for c in range (16,32,1):
  28. matrix[1,a] = matrix[1,a] + sgr_log[c,a]
  29. for c in range (32,48,1):
  30. matrix[2,a] = matrix[2,a] + sgr_log[c,a]
  31. for c in range (48,64,1):
  32. matrix[3,a] = matrix[3,a] + sgr_log[c,a]
  33. for c in range (64,80,1):
  34. matrix[4,a] = matrix[4,a] + sgr_log[c,a]
  35. for c in range (80,96,1):
  36. matrix[5,a] = matrix[5,a] + sgr_log[c,a]
  37. for c in range (96,112,1):
  38. matrix[6,a] = matrix[6,a] + sgr_log[c,a]
  39. for c in range (112,128):
  40. matrix[7,a] = matrix[7,a] + sgr_log[c,a]
  41. for c in range (128,144,1):
  42. matrix[8,a] = matrix[8,a] + sgr_log[c,a]
  43. for c in range (144,160):
  44. matrix[9,a] = matrix[9,a] + sgr_log[c,a]
  45. for c in range (160,176):
  46. matrix[10,a] = matrix[10,a] + sgr_log[c,a]
  47. for c in range (176,192):
  48. matrix[11,a] = matrix[11,a] + sgr_log[c,a]
  49. for c in range (192,208):
  50. matrix[12,a] = matrix[12,a] + sgr_log[c,a]
  51. for c in range (208,224):
  52. matrix[13,a] = matrix[13,a] + sgr_log[c,a]
  53. for c in range (224,240):
  54. matrix[14,a] = matrix[14,a] + sgr_log[c,a]
  55. for c in range (240,256):
  56. matrix[15,a] = matrix[15,a] + sgr_log[c,a]
  57. print(matrix.shape)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement