[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Incorrect fftshift documentation
From: |
Miguel Bazdresch |
Subject: |
Incorrect fftshift documentation |
Date: |
Thu, 16 Jun 2011 14:26:35 -0500 |
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
- Incorrect fftshift documentation,
Miguel Bazdresch <=