nufft wrong result ?
古いコメントを表示
% 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)
採用された回答
その他の回答 (3 件)
Kraka Doros
2022 年 5 月 8 日
編集済み: Kraka Doros
2022 年 5 月 8 日
0 投票
1 件のコメント
Paul
2022 年 5 月 8 日
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
2022 年 5 月 9 日
編集済み: Kraka Doros
2022 年 5 月 9 日
0 投票
2 件のコメント
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
2022 年 5 月 10 日
編集済み: Kraka Doros
2022 年 5 月 10 日
Kraka Doros
2022 年 5 月 14 日
編集済み: Kraka Doros
2022 年 5 月 14 日
0 投票
カテゴリ
ヘルプ センター および File Exchange で Fourier Analysis and Filtering についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







