Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: FFT,IFFT, and NDFT,NFFT
Date: Mon, 6 Jul 2009 20:47:01 +0000 (UTC)
Organization: Uofc
Lines: 106
Message-ID: <h2tns4$a1h$1@fred.mathworks.com>
References: <h25v6u$5ia$1@fred.mathworks.com> <6ced5282-e4f9-4712-9546-158d71c222b0@j14g2000vbp.googlegroups.com> <e104f561-edaa-4505-84c2-cf6bcfb49179@s31g2000yqs.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246913221 10289 172.30.248.35 (6 Jul 2009 20:47:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 6 Jul 2009 20:47:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1662491
Xref: news.mathworks.com comp.soft-sys.matlab:553232


Greg <heath@alumni.brown.edu> wrote in message <e104f561-edaa-4505-84c2-cf6bcfb49179@s31g2000yqs.googlegroups.com>...
> On Jun 28, 12:33 pm, Greg <he...@alumni.brown.edu> wrote:
> > On Jun 27, 4:25 pm, "guj " <gulatiaks...@gmail.com> wrote:
> -----SNIP
> > function   [XFT,XLS,NMSEFT,NMSELS] = DFTgh1(x,t,f)
> >
> > % function [XFT,XLS,NMSEFT,NMSELS] = DFTgh1(x,t,f)
> > %
> > % Modification of AJ Johnson's dft for nonuniform sampling
> > %
> > % Computes XFT (Discrete Fourier Transform) at frequencies
> > % given in f, given samples x taken at times t:
> > %
> > % XFT(f) = sum(k=1,N){ dts(k) *x(k) * exp(-2*pi*j*t(k)*f) }
> > %        = W *(x.*dts)
> > %
> > % where dts is a symmetrized modification of diff(t).
> > %
> > % Also computes the Least-Squared-Error Spectrum at
> > % frequencies given in f, given samples x taken at
> > % times t:
> > %
> > % XLS(f) = (W'\x)./dfs;
> > %
> > % where dfs is a symmetrized modification of diff(f).
> > %
> > % NMSEFT is the normalized mean-square-error of reconstucting
> > % x from X using the Inverse Fourier Transform formula. If
> > % mean(x) = 0, then the MSE is unnormalized.
> 
> Correction:
> 
> If   mean(x) = x, i.e., x is constant, then the MSE is unnormalized.
> 
> 
> > % NMSELS is the normalized mean-square-error of reconstucting
> > % x from X using Least Squares. If mean(x) = 0, then the MSE
> > % is unnormalized.
> 
> Correction:
> 
> If   mean(x) = x, i.e., x is constant, then the MSE is unnormalized.
> 
> > % For comparison with MATLAB'sFFTwhen the spacing is uniform,
> > % double the end values x(1) and x(end) and divide X by dt0 =
> > % mean(diff(t))
> 
> -----SNIP
> 
> Hope this helps.
> 
> Greg


What are your comments on the code below:
FFT is giving the same result as DFT for Non uniform sampling. I am curious to know the difference between NDFT and DFT ...Notation


clear
dt=.01;
N=101;
func=sin([0:N-1]/4);
f=1/dt/N/2*[-N:2:N-2];

figure(1)
clf
subplot(3,1,1)
plot(dt*[0:N-1],func)
subplot(3,1,2)
plot(f,fftshift(abs(fft(func))))
k=1:N;
n=1:N;
DFT=exp(-i*2*pi*((k(:)-1)*(n-1)/N));
subplot(3,1,3)
plot(f,fftshift(abs(DFT*func(:))))

z=round(rand(1,N));
temp1=func;
temp2=z.*func;
lives=find(z~=0);
func=temp2(lives);
DFT=DFT(:,lives);

figure(2)
clf
subplot(3,1,1)
plot(dt*[0:N-1],temp1,dt*[0:N-1],temp2)
subplot(3,1,2)
plot(f,fftshift(abs(fft(temp2))))
subplot(3,1,3)
plot(f,fftshift(abs(DFT*func(:))))

Here is NDFT, algorithm

freq=(-N/2):(N/2-1);  f_hat=a;
      f=zeros(M,1);
      for k=1:N
        f=f+f_hat(k).*exp(-2*pi*i*x*freq(k));
      end;
So question is Which one is right for Non uniform sampling..Is matlab DFT formula (which i have taken from help) is same as FFT and can handle only fixed sample...what factor in DFT algorithm constraining it for fixed sampling.

In DFT, algorithm we are multiplying our Coefficient with twiddle factor, that twiddle factor is equally spaced ...is that the constrain...

twiddle factor= exp(-2*pi*i*k*n/N)   ..IN this when we divide it by N, we only mean to normalise it..isnt it..also 2pi is my sampling frequency ...

All these doubts are there because of the code which i have written above and i am dubious why its giving same result as fft ..Also what FFT do when it incur a irregular sampling....although it give wrong result but what is its working on such kind of input