Advertisement
Danila_lipatov

basic_example_spectrum_python

Dec 14th, 2023 (edited)
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. """
  2. If it will be helpful, please like this post
  3. """
  4. Fs = 1024
  5. sampling_rate = 100 #signal freq
  6. N = int(Fs / sampling_rate) #number of samples
  7. t_step = 1 / Fs
  8. t = np.linspace(0, (N - 1) * t_step, N) #time interval
  9. freq = Fs / N #freq step
  10. f = np.linspace(0, (N - 1) * freq, N) # freq interval
  11.  
  12. data = np.sin(2 * np.pi * sampling_rate * t)
  13. fureir = scipy.fft.fft(data)
  14. fureier_abs = abs(fureir / N)
  15. data_spec = f[0 : int(N / 2 + 1)]
  16. furier_abs_plot = 2 * fureier_abs[0 : int(N / 2 + 1)]
  17. fureier_abs[0] /= 2
  18. fig, [ax1, ax2] = plt.subplots(nrows=2, ncols=1)
  19. ax1.plot(t, data)
  20. ax2.plot(data_spec, furier_abs_plot)
  21. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement