nufft wrong result ?
Afficher commentaires plus anciens
% my code :
% Create 256 not equally spaced time points between 1 and 1000 :
n=256;
t=sort(randperm(1000,n)');
% I received a column of 256 points with first and last points :
% t(1), t(n)
% I want the first point to be 0 :
t=t-t(1);
% Take values of x=sin(2*pi*0.025*t) on the 256 time points :
x=sin(2*pi*0.025*t);
% Pretend that these 256 values are my samples that i took in non equally
% spaced time points, without knowing the frequency and want to use
% nufft to calculate f of the sin (f=0.025) :
F=nufft(x,t,(0:n-1)/n);
% plot abs of F, over frequency bins with fresolution=1/T
% were T is the total time of sampling, t(256) :
T=t(256);
fresolution=1/T;
plot((0:n-1)/T,abs(F)/2*n)
% receiving wrong answer (f=0.006)
Réponse acceptée
Plus de réponses (3)
Kraka Doros
le 8 Mai 2022
Modifié(e) : Kraka Doros
le 8 Mai 2022
0 votes
1 commentaire
Paul
le 8 Mai 2022
I'm afraid I can't help with this. Have you looked at the doc page for nufft()? It shows the equation used to compute the nufft that should be very straightforward to implement in Matlab. I'm sure that there are lots of issues to consider wrt to precision and efficiency, but maybe the simple approach would be suitable for your application.
Kraka Doros
le 9 Mai 2022
Modifié(e) : Kraka Doros
le 9 Mai 2022
0 votes
2 commentaires
Example data from original question
n=256;
rng(100);
t = sort(randperm(1000,n)');
% I received a column of 256 points with first and last points :
% t(1), t(n)
% I want the first point to be 0 :
t = t-t(1);
% Take values of x=sin(2*pi*0.025*t) on the 256 time points :
x = sin(2*pi*0.025*t);
Take the nufft of the sequence
f = (0:n-1)/n;
F = nufft(x,t,f);
Implenment the nufft using the defining sum for the nufft() doc page
F1 = zeros(n,1);
for kk = 1:numel(f)
for jj = 1:n
F1(kk) = F1(kk) + x(jj)*exp(-1j*2*pi*t(jj)*f(kk));
end
end
Compare the results
figure
subplot(211);
plot(real(F1-F),'-x');
subplot(212);
plot(imag(F1-F),'-o');
Not surprised that they are not the same because Matlab's actual algoriithm for sure won't be an implementation of that double loop. I suspect that at some point this simple approach will break down. But this at least gets you somewhere. In principal, it can be be implemented in the Symbolic Math Toolbox using vpa math as well. Hope it helps.
Kraka Doros
le 10 Mai 2022
Modifié(e) : Kraka Doros
le 10 Mai 2022
Kraka Doros
le 14 Mai 2022
Modifié(e) : Kraka Doros
le 14 Mai 2022
0 votes
Catégories
En savoir plus sur Fourier Analysis and Filtering dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







