Analiza konstrukcija na dinamička opterećenja
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from numpy.fft import fft, fftshift
  4. plt.clf()
  5. fs = 10 # sampling frequency
  6. dt = 1 / fs
  7. t = np.arange(0, 5, dt) # start, end, step
  8. y = np.cos(2 * np.pi * 1 * t)
  9. t1 = np.arange(0, 5, dt / 1000) # start, end, step
  10. y1 = np.cos(2 * np.pi * 9 * t1)
  11. N = len(y)
  12. fig, axs = plt.subplots(2, num=1)
  13. axs[0].plot(t, y, ':')
  14. axs[0].stem(t, y, '.')
  15. axs[0].set_xlabel('t [s]')
  16. axs[0].set_ylabel('y')
  17. axs[0].grid()
  18. axs[0].plot(t1, y1, 'r')
  19. Y = fftshift(fft(y) / N)
  20. df = fs / len(Y)
  21. f = np.arange(-fs / 2, fs / 2, df)
  22. axs[1].stem(f, np.abs(Y))
  23. axs[1].set_xlabel('f [Hz]')
  24. axs[1].set_ylabel('Y abs')
  25. axs[1].grid()
  26. # axs[1].stem(f, Y.real)
  27. # axs[1].set_xlabel('f [Hz]')
  28. # axs[1].set_ylabel('Y real')
  29. # axs[1].grid()
  30. # axs[2].stem(f, Y.imag)
  31. # axs[2].set_xlabel('f [Hz]')
  32. # axs[2].set_ylabel('Y imag')
  33. # axs[2].grid()
  34. plt.show()