[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #33581] Error in fftshift's documentation
From: |
John W. Eaton |
Subject: |
[Octave-bug-tracker] [bug #33581] Error in fftshift's documentation |
Date: |
Sat, 18 Jun 2011 14:59:41 +0000 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.19) Gecko/20110430 Iceweasel/3.5.19 (like Firefox/3.5.19) |
Follow-up Comment #2, bug #33581 (project octave):
I think the text box ate some of your comments because of mismatched verbatim
tags. Here is what I think is the full text, reconstructed from the email
notification I received:
I believe there could be a mistake in fftshift's documentation. It is claimed
that, after fftshift, the analog frequency vector is
f = ((1:N) - ceil(N/2)) / N / Dt
where N is the number of samples and Dt is the time resolution.
Consider the case N = 6 and Dt = 1. The digital frequencies are
> fk = (0:5)/N
ans =
0.00000 0.16667 0.33333 0.50000 0.66667 0.83333
(The corresponding analog frequencies are the same, since Dt=1). As expected,
we see the Nyquist frequency (0.5). fftshift will arrange things so that the
FFT value corresponding to this frequency is aliased to -0.5. However, the
formula for f in fftshift's documentation produces:
> f = ((1:6) - ceil(6/2)) / 6
f =
-0.33333 -0.16667 0.00000 0.16667 0.33333 0.50000
This is incorrect, the 0.5 term was not aliased. The error can be
verified graphically by running:
x=fft(cos(2*pi/3*(0:5)));
f=((1:6)-ceil(6/2))/6;
stem(f,abs(fftshift(x)));
where it will be clear that the spectrum is not symmetric around 0Hz. (See
also http://www.mathworks.com/matlabcentral/newsreader/view_thread/172590)
(By the way, the documented formula is correct for odd N). I believe a
correct
formula for the frequencies is
f = [ -(ceil((N-1)/2):-1:1)*df 0 (1:floor((N-1)/2))*df ];
where df=1/Dt. It may be expressed more succinctly, but I believe it is more
didactic expressed this way.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?33581>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/