How does nufft function work in matlab?

I am trying to understand how to use nufft function. For this, I started by comparing the results of the fft and nufft transforms of a Gaussian to see if they yield the same result. I find that for a spacing in t space that is not unity, they yield different results. The exmple in MATLAB for nufft also has unit spacing between the t coordinates. Does nufft function not work for non-unit spacing? This would be a problem for me since the next step is to get the fourier transform of a gaussian with different spacings in the t space, i.e, dt varies for each element.
Thank you.
tmax = 12;
n = 2^11;
tau = 1; % Width of the gaussian pulse
dt = 2*tmax/n;
t = (-tmax:dt:tmax-dt);
fmax = 1/(2*dt);
df = 2*fmax/n;
f = -fmax:df:fmax-df;
Pulse = exp(-(t/tau).^2);
%Pulse = sin(t/tau);
fftPulse = ifftshift(fft(Pulse));
subplot(2,1,1)
plot(t,Pulse)
subplot(2,1,2)
plot(f,abs(fftPulse)); hold on;
nufftPulse = ifftshift(nufft(Pulse,t));
plot(f,abs(nufftPulse))

댓글 수: 4

dpb
dpb 2021년 3월 2일
Of course they're not the same when t is not uniformly sampled; see the "More About" section and the references for what it means.
I'll agree the examples are somewhat limited in their utility for understanding -- the first is simply a gap in the time vector; the sampling rate is uniform.
If you do not sample with a uniform sample rate, however, then the waveform frequency is modified when you generate the time vector as well -- we would have to see what you're generating with the time-varying sample rate.
What need to compare would be the same signal sample uniformly and nonuniformly; the nufft analysis should be able to account for the latter and reproduce closely the correct frequencies.
Thank you. I think I figured out the right code to yield the same results. We need to scale the frequencies differently when using nufft. This is a direct result of its definition.
Once again, thank you so much.
tmax = 20;
n = 2^11;
tau = 0.5;
dt = 2*tmax/n;
t = (-tmax:dt:tmax-dt);
fmax = 1/(2*dt);
df = 2*fmax/n;
f = (-fmax:df:fmax-df);
Pulse = exp(-(t/tau).^2);
%Pulse = sin(t/tau);
fftPulse = ifftshift(fft(Pulse));
subplot(2,1,1)
plot(t,Pulse)
xlabel('t');ylabel('f(t)')
subplot(2,1,2)
plot(f,abs(fftPulse)); hold on;
nufftPulse = (nufft(Pulse,t*2)); % The 2 factor here and next line allows us to make the freqency range [0-2]
plot((f+fmax)*dt*2,abs(nufftPulse)) % PLEASE NOTE THAT WE HAVE TO SCALE AND SHIFT
xlabel('\nu');ylabel('f(\nu)')
evelyn
evelyn 2024년 6월 29일
how to define the new time index, like 't*2', you mention?

댓글을 달려면 로그인하십시오.

답변 (1개)

Paul
Paul 2024년 6월 29일

0 개 추천

To get fft and nufft to yield the same results ....
tmax = 12;
n = 2^11;
tau = 1; % Width of the gaussian pulse
dt = 2*tmax/n;
t = (-tmax:dt:tmax-dt);
fmax = 1/(2*dt);
df = 2*fmax/n;
f = -fmax:df:fmax-df;
Pulse = exp(-(t/tau).^2);
%fftPulse = ifftshift(fft(Pulse));
fftPulse = fftshift(fft(ifftshift(Pulse)));
nufftPulse = nufft(Pulse,t,f);
figure
subplot(2,1,1)
% plot the phase of the transform instead of the original signal
%plot(t,Pulse)
plot(f,angle(fftPulse),f,angle(nufftPulse));
subplot(2,1,2)
plot(f,abs(fftPulse)); hold on;
plot(f,abs(nufftPulse))
The hair on the angle plot is just numerical noise that results from taking the angle of complex number that has very small magnitude. At low frquencies where the magnitude isn't small we see that the angle is essentially zero as would be expected.

질문:

2021년 3월 2일

답변:

2024년 6월 29일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by