Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news.glorb.com!postnews.google.com!e10g2000prf.googlegroups.com!not-for-mail
From: Greg Heath <heath@alumni.brown.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: FFT acting strangely...
Date: Sat, 1 Mar 2008 02:08:59 -0800 (PST)
Organization: http://groups.google.com
Lines: 62
Message-ID: <836016d0-e755-4cf0-8a70-78794d79b5a8@e10g2000prf.googlegroups.com>
References: <fq9o0h$o6s$1@fred.mathworks.com> <f187d8bb-5e73-491c-94ae-56d64264cfbe@p25g2000hsf.googlegroups.com> 
NNTP-Posting-Host: 172.162.187.131
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1204366139 12159 127.0.0.1 (1 Mar 2008 10:08:59 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sat, 1 Mar 2008 10:08:59 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: e10g2000prf.googlegroups.com; posting-host=172.162.187.131; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 
Xref: news.mathworks.com comp.soft-sys.matlab:454736


On Feb 29, 3:51 pm, "Michael Stachowsky" <mstachow...@gmail.com>
wrote:
> Ah, sorry.  Fs = 1000;
>
> I discovered my problem: it was one of aliasing.  I had
> mistyped the example data.
>
> But I came upon another issue.  This may stem from my lack
> of familiarity with FFT, but, how do I make the proper array
> of frequencies for my analysis?

It depends on whether you have an odd or an even number of points.

dt = 1/Fs           % Time sample spacing
T = N*dt            % FFT imposed periodicity
t = 0: dt: T-dt;    % t = (0:N-1)*dt;

df = 1/T            % Frequency sample spacing
Fs = N*df           % FFT imposed periodicity
f  = 0: df: Fs-df   % f = (0:N-1)*df;

f0 = 50;
x = 0.7*sin(2*pi*50*t);
X = fft(x);         % Defined on unipolar frequency interval [0,Fs-df]
Xb = fftshift(X);   % Defined on bipolar frequency interval  [-?,+?]

The bipolar frequency range depends on whether N is odd or even

Q = ceil((N+1)/2)
P = N+1-Q            % P = floor((N+1)/2)
fQ = (Q-1)*df        % Maximum negative frequency
fP = (P-1)*df        % Maximum positive frequency

Then

f = 0: df: fP+fQ;    % Unipolar, used with X
fb = f - fQ;
fb = -fQ: df : fP;   % Bipolar, used with Xb

Notice that when N is even

fNyquist = fQ > fP

So MATLAB's fftshift puts the Nyquist frequency in the
negative part of the spectrum.


> This is going to be used in an experiment with reasonably
> strict accuracy controls (at least +/- 0.1Hz), and my FFT
> analysis gave me 120.12Hz when I gave it a 120Hz sine wave...

Since

df = 1/T = 1/(N*dt) = Fs/N,

There are 2 ways to decrease df.


Hope this helps.

Greg