Why I get an assertion error in this example
a-z-e-r-i-l-a opened this issue · comments
I have a signal r which was evaluated(sampled) at time t and the sampling frequency is not constant. The data are:
r = np.array([119.78410766, 119.76753142, 117.62636578, 103.44442714,
100.20643576, 100.07845224, 100.8635375 , 105.7013656 ,
115.19253386, 118.8410111 , 119.56967806, 119.49016405,
115.673267 , 102.86539977, 100.18330076, 100.19053755,
100.96717742, 104.64258496, 112.76883508, 118.42145725,
119.46248759])
t = np.array([-408.60214685, -367.98645179, -326.11763398, -283.30427476,
-240.51508415, -198.71111261, -158.2850487 , -118.96667683,
-79.99044514, -40.53604325, 0. , 41.86292241,
84.76209664, 127.57962255, 169.0752062 , 209.26407576,
248.94525408, 288.63548604, 328.64737256, 369.17828499,
410.49942551])
plt.plot(t, r, label='data')
plt.legend()
In the t variable the distance between each sampling instance is between 39 to 42 and not constant and this made the fft inaccurate for me.
When I use nfft however, I get the following assertion error but I am not sure what my mistake is in using the nfft package.
from nfft import nfft
f = nfft(z, r)
AssertionError Traceback (most recent call last)
in
1 from nfft import nfft
----> 2 f = nfft(z, r)~/.local/share/virtualenvs/tf-tRAPLeXL/lib/python3.6/site-packages/nfft/core.py in nfft(x, f_hat, sigma, tol, m, kernel, use_fft, truncated)
123
124 N = len(f_hat)
--> 125 assert N % 2 == 0
126
127 sigma = int(sigma)AssertionError:
So I noticed the problem was that the number of samples was not a power of 2.