Closed dtsonov closed 6 years ago
Yes, the documentation is not great, and I'm not sure I'll have time to address that any time soon. One thing: it's strange that you're subtracting 0.5 from your data. The reason I do that in the example is to get data that lies in the range [-0.5, 0.5]. Your data don't lie between 0 and 1, so I can't see any reason why you'd want to subtract 0.5.
Also, if you plot f vs x, you'll see that your data is effectively a straight line... I wouldn't expect an fft to pull out meaningful frequency information from a non-periodic signal.
When you plot your input data, you use plot.plot(data)
. That is not your input data: your input data is plt.plot(x, f)
Here's how you can approximate the input data for an NFFT by doing a round-trip: note that it takes a LOT of frequencies to get a close approximation: this is because the effective Nyquist frequency is very large when data are not equally spaced.
import nfft
import numpy as np
import matplotlib.pyplot as plt
x = 100 * np.random.rand(1000)
f = np.sin(x / 10)
N = 1000000
k = -N / 2 + np.arange(N)
f_hat = nfft.nfft_adjoint(x, f, N)
f_reconstructed = nfft.nfft(x, f_hat) / N
plt.plot(x, f, '.', color='blue')
plt.plot(x, f_reconstructed, '.', color='red')
Hello, I installed NFFT and tried forward and backward transform, as is shown on the examples. After backward transform the input data I got is very different from the original input data. Probably I'm not using the transform correctly. Would some one help with it. Here is my code: