Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- #%%
- L = 10000 # Length of Signals
- F = 100 # Frame location
- N = 16 # Frame Size = DFT Sample Count
- #%%
- P = np.zeros(L) # Position
- D = np.zeros(L) # Difference
- for n in range(L):
- P[n] = 1.2 + 0.3 * n + 0.045 * n * n
- P[F - 1] = 42069
- for n in range(1, L):
- D[n] = P[n] - P[n-1]
- #%%
- x = P[F:F+N]
- y = D[F:F+N]
- X = np.fft.fft(x) / N
- Y = np.fft.fft(y) / N
- #%%
- Z = np.zeros(N, dtype=complex)
- C = (x[N-1] - P[F-1]) / N
- for k in range(N):
- Z[k] = X[k] * (1 - np.exp(-1j * (2.0 * np.pi / N) * k)) + C
- # coef = coef * (1 - np.exp(-1j * 2 * np.pi / N * np.arange(N)))
- #%%
- for n in range( N ):
- print("%2d %10.6f %10.6f %10.6f %10.6f" % \
- (n, Y[n].real, Y[n].imag, Z[n].real, Z[n].imag ))
- print(np.sum(np.abs(Y - Z))) # just use this
- #%%
- fig, axes = plt.subplots(1, 2, figsize=(14, 6))
- axes[0].plot(x)
- axes[1].plot(y)
- axes[0].annotate("x[n]", fontsize=20, xy=(.85, .05), xycoords='axes fraction')
- axes[1].annotate("x'[n]", fontsize=20, xy=(.85, .05), xycoords='axes fraction')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement