Analiza konstrukcija na dinamička opterećenja
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dial.py 832B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import matplotlib.pyplot as plt
  2. import mplcursors
  3. import numpy as np
  4. from numpy.fft import fft
  5. from scipy.io import wavfile
  6. def PowerSpectrum(y):
  7. Y = np.abs(fft(y))
  8. PS = Y[0:len(Y) // 2]
  9. df = fs / len(Y)
  10. f = np.arange(0, len(PS)) * df
  11. return f, PS
  12. plt.clf()
  13. fs, data = wavfile.read('dial.wav')
  14. fig, axs = plt.subplots(2, num=1)
  15. y = data[:, 0]
  16. dt = 1 / fs
  17. t = np.arange(0, len(y)) * dt
  18. axs[0].plot(t, y)
  19. axs[0].set_xlabel('t [s]')
  20. axs[0].set_ylabel('y')
  21. limits = [0.1, 0.45, 0.8, 1.2]
  22. ss = limits[2]
  23. se = limits[3]
  24. to = t[(t > ss) & (t < se)]
  25. yo = y[(t > ss) & (t < se)]
  26. axs[0].plot(to, yo)
  27. f, PS = PowerSpectrum(y)
  28. fo, PSo = PowerSpectrum(yo)
  29. axs[1].plot(f, PS)
  30. axs[1].set_xlabel('f [Hz]')
  31. axs[1].set_ylabel('Y abs')
  32. axs[1].set_xlim(0, 1500)
  33. axs[1].plot(fo, PSo)
  34. mplcursors.cursor()
  35. plt.show()