Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- def d_idft(coef):
- N = len(coef)
- x = np.zeros(N, dtype='complex128')
- for n in range(N):
- for k in range(N):
- x[n] += 1j * k * coef[k] * np.exp(1j * (2 * np.pi / N) * n * k)
- x *= (2 * np.pi / N ** 2)
- return x
- t = np.linspace(0, 1, 128)
- x = np.cos(2 * np.pi * t)
- coef = np.fft.fft(x)
- xd = np.diff(x) # x[n] - x[n - 1]
- xd_est = d_idft(coef)
- plt.plot(xd)
- plt.plot(xd_est.real)
- plt.show()
- plt.plot(t, xd_est.imag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement