[Top][All Lists]

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

Re: fftshift help in octave 2.1.35, incorrect?

From: Mirek Kwasniak
Subject: Re: fftshift help in octave 2.1.35, incorrect?
Date: Sun, 14 Apr 2002 08:57:12 +0200
User-agent: Mutt/1.3.28i

On Sat, Apr 13, 2002 at 03:40:58PM -0500, Hugo van der Merwe wrote:
>  - Function File:  fftshift (V)
>      Perform a shift of the vector V, for use with the `fft' and `ifft'
>      functions, in order the move the frequency 0 to the center of the
>      vector or matrix.
>      If V is a vector of E elements corresponding to E time samples
>      spaced of Dt each, then `fftshift (fft (V))' corresponds to
>      frequencies
>           f = linspace (-E/(4*Dt), (E/2-1)/(2*Dt), E)

Yes, it's a bug :)

> The way I understand the fourier transform, I would believe that the
> highest frequency you would get out of an fft would be half the sampling 
> frequency. E.g. if you sample at 44.1kHz, from an fft you should get a 
> spectrum from -22.05kHz to nearly 22.05kHz.


> I would suggest
>   samplerate = 1/Dt
>   f = -samplerate/2 : samplerate/E : samplerate/2-samplerate/E

Non-interger step in loop is a classical bug (see any beginners book for
programming) :(

I always use a formula:

  f = (-E/2:E/2-1)/E/Dt

I assume that E is even (i don't know how calculate it if E is odd).

> In terms of linspace, Dt and E this would be
>   f = linspace (-1/(2*Dt), 1/(2*Dt)-1/(E*Dt), E)
> but that is ugly.

It depends on linspace implementation. I tested some examples, it gives same
results as my formula, but ...

because it doesn't use exact value of samplerate for steps, sometimes you can
get rounding errors (ie. 0 ~= 0).


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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