Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news.glorb.com!postnews.google.com!f47g2000hsd.googlegroups.com!not-for-mail
From: "Steven G. Johnson" <stevenj@alum.mit.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: FFT acting strangely...
Date: Fri, 29 Feb 2008 13:54:44 -0800 (PST)
Organization: http://groups.google.com
Lines: 31
Message-ID: <c0cd5b17-43c2-412d-a52d-4551066f33b0@f47g2000hsd.googlegroups.com>
References: <fq9o0h$o6s$1@fred.mathworks.com> <f187d8bb-5e73-491c-94ae-56d64264cfbe@p25g2000hsf.googlegroups.com> 
NNTP-Posting-Host: 18.87.0.80
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1204322085 31987 127.0.0.1 (29 Feb 2008 21:54:45 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 29 Feb 2008 21:54:45 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: f47g2000hsd.googlegroups.com; posting-host=18.87.0.80; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; 
	rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:454703


On Feb 29, 4:16 pm, Rune Allnor <all...@tele.ntnu.no> wrote:
> You don't. The array of frequencies is given implicitly as
>
> fv = (0:N-1)/N*Fs
>
> where N is the length of the data sequence fed to the FFT
> and Fs is the sampling frequency.

Both you and Randy gave this answer, which is the "obvious" choice if
you look at the DFT definition, but in most circumstances this is a
very bad definition for the array of frequencies.

Because of aliasing, the frequencies are ambiguous.  However, if you
assume that your data are band-limited up to the Nyquist frequency,
then the correct array of frequencies (assuming even N) is:

fv = [0:N/2,-N/2+1:-1]/N*Fs

Another way of looking at it is that, by choosing the frequency
aliasing (adding any multiple of N to any of the integers in the [...]
array), you are specifying a trigonometric interpolation in between
your sampling points.  The frequencies I gave above correspond to the
minimal-slope interpolation (except for the N/2 Nyquist frequency,
which has to be handled specially if you really care about it), which
is usually the best choice.

(If the data are real, then the second half of the spectrum is
redundant and you might as well only plot for [0:N/2].)

Regards,
Steven G. Johnson