Advertisement
Guest User

Untitled

a guest
Sep 10th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4.  
  5. def d_idft(coef):
  6.     N = len(coef)
  7.     x = np.zeros(N, dtype='complex128')
  8.     for n in range(N):
  9.         for k in range(N):
  10.             x[n] += 1j * k * coef[k] * np.exp(1j * (2 * np.pi / N) * n * k)
  11.     x *= (2 * np.pi / N ** 2)
  12.     return x
  13.  
  14. t = np.linspace(0, 1, 128)
  15. x = np.cos(2 * np.pi * t)
  16.  
  17. coef = np.fft.fft(x)
  18. xd     = np.diff(x)  # x[n] - x[n - 1]
  19. xd_est = d_idft(coef)
  20.  
  21. plt.plot(xd)
  22. plt.plot(xd_est.real)
  23. plt.show()
  24. plt.plot(t, xd_est.imag)
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement