octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #33581] Error in fftshift's documentation


From: anonymous
Subject: [Octave-bug-tracker] [bug #33581] Error in fftshift's documentation
Date: Thu, 16 Jun 2011 19:38:16 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1

URL:
  <http://savannah.gnu.org/bugs/?33581>

                 Summary: Error in fftshift's documentation
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Thu 16 Jun 2011 07:38:16 PM UTC
                Category: None
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Documentation
                  Status: None
             Assigned to: None
         Originator Name: Miguel Bazdresch
        Originator Email: address@hidden
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 3.4.0
        Operating System: GNU/Linux

    _______________________________________________________

Details:

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
-verbatim

(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 ];
-verbatim

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/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]