[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Incorrect fftshift documentation
From: |
John W. Eaton |
Subject: |
Incorrect fftshift documentation |
Date: |
Thu, 16 Jun 2011 15:31:00 -0400 |
Will you please submit a bug report about this issue so it won't be
lost or forgotten?
https://savannah.gnu.org/bugs/?func=additem&group=octave
Thanks,
jwe
On 16-Jun-2011, Miguel Bazdresch wrote:
| 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.
|
| --
| Miguel Bazdresch