Can we have a very simple and clear comparison example on the functions fft and nufft works?
Ältere Kommentare anzeigen
My task here is to compare standard fft and nufft results for a given reference function. The difference of this question from previously asked ones is to relate data with the terms 'sampling frequency' and 'sampling intervals' which both are changing for the nonuniformly spaced case. In other words, I am using a second sampling frequency to uneven the time samples.
Thank you in advance.
fs=1e3; %sampling frequency for the uniform samples
ts=1/fs; %sampling interval for the uniform samples
f0 = 200; %signal frequency under test to be observed at the spectrum output.
timeDataUnif=[0:ts:1000*ts]; %uniform time samples
timeDataNunif=[0:ts:750*ts (750*ts+ts/2):ts/2:1000*ts]; % nonuniform samples for the same time period with twice the sampling frequency
nData1=length(timeDataUnif);
nData2=length(timeDataNunif);
sigDataUnif=sin(2.*pi.*f0.*timeDataUnif) +0.01.*rand(1,nData1);
sigDataUnif=sigDataUnif-sum(sigDataUnif)/nData1; %optionally removing the DC component
fSigData=fftshift(fft(sigDataUnif)); %spectrum of the uniform samples
freqDataUnif=[0:nData1-1]./(nData1-1).*fs-fs/2; %uniform frequency samples
freqDataNunif=[0:nData2-1]./(nData2-1).*(2.*fs)-fs; %uniform frequency grids for twice fs.
sigDataNunif=2*sin(2.*pi.*f0.*timeDataNunif) +0.01.*rand(1,nData2);
nufSigData=fftshift(nufft(sigDataNunif,timeDataNunif));
figure;
subplot(411),plot(timeDataUnif,'k.');hold on;
subplot(411),plot(timeDataNunif,'r.');title('uniform and nonuniform samples of 1 second time interval');xlabel('sample number');axis tight;grid on;grid minor;
subplot(412),plot(timeDataUnif,sigDataUnif,'k');hold on;title('different samples of the same function');
subplot(413),plot(freqDataUnif,abs(fSigData),'k');hold on;axis tight;V=axis;axis([V(1) V(2) -20 V(4)]); grid on;grid minor;
subplot(412),plot(timeDataNunif,sigDataNunif,'r--');hold on;title('FFT of the uniform samples');
subplot(414),plot(freqDataNunif,abs(nufSigData),'k');title('NUFFT of the nonuniform samples');grid on;grid minor;
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Fourier Analysis and Filtering finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

