Advertisement
Guest User

Untitled

a guest
Sep 13th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. #%%
  5. L = 10000  # Length of Signals
  6. F = 100    # Frame location
  7. N = 16     # Frame Size = DFT Sample Count
  8. #%%
  9. P = np.zeros(L)  # Position
  10. D = np.zeros(L)  # Difference
  11.  
  12. for n in range(L):
  13.     P[n] = 1.2 + 0.3 * n + 0.045 * n * n
  14. P[F - 1] = 42069
  15.  
  16. for n in range(1, L):
  17.     D[n] = P[n] - P[n-1]
  18. #%%
  19. x = P[F:F+N]
  20. y = D[F:F+N]
  21.  
  22. X = np.fft.fft(x) / N
  23. Y = np.fft.fft(y) / N
  24. #%%
  25. Z = np.zeros(N, dtype=complex)
  26. C = (x[N-1] - P[F-1]) / N
  27.  
  28. for k in range(N):
  29.     Z[k] = X[k] * (1 - np.exp(-1j * (2.0 * np.pi / N) * k)) + C
  30. #   coef = coef * (1 - np.exp(-1j * 2 * np.pi / N * np.arange(N)))
  31. #%%
  32. for n in range( N ):
  33.     print("%2d %10.6f %10.6f   %10.6f %10.6f" % \
  34.           (n, Y[n].real, Y[n].imag, Z[n].real, Z[n].imag ))
  35. print(np.sum(np.abs(Y - Z)))  # just use this
  36. #%%
  37. fig, axes = plt.subplots(1, 2, figsize=(14, 6))
  38. axes[0].plot(x)
  39. axes[1].plot(y)
  40. axes[0].annotate("x[n]",  fontsize=20, xy=(.85, .05), xycoords='axes fraction')
  41. axes[1].annotate("x'[n]", fontsize=20, xy=(.85, .05), xycoords='axes fraction')
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement