comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: FFT help
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: FFT help [message #41616] Fri, 05 November 2004 10:47
R.G.Stockwell is currently offline  R.G.Stockwell
Messages: 163
Registered: October 2004
Senior Member
"IDLmastertobe" <shi_lee@hotmail.com> wrote in message
news:26d23fcf09dce26228fc67cf81ec832f@localhost.talkaboutpro gramming.com...
> Hey, I am experiencing problem using fft function. Since FFT function
> provides the fourier transform of a certain input, for example,
> 8*cos(!PI*x/6), I would expect an amplitude of 4 at 2 shifted frequencies,
> namely -!PI/6 and PI/6. However after I recieved data from the FFT, I
> recieved some amplitudes close to 2 at some random locations, can anyone
> explain to me why it happened? Thanks for your time.

You quite probably did not sample the frequencies exactly at -!pi/6.
The other peaks are probably sidelobes.
I suggest reading several books about signal processing and spectral
analysis.
A great book to start with is Brighams "FFT and its applications"


Also, check out the following code

freq = 11
len = 100
amp = 8
t = findgen(len)
signal = amp*cos(2*!pi*freq*t/len)

ampspe = abs(fft(signal))
You will find your peak = 4 for the frequencies at freq/len.

Note that positive freqs come first in the fft, followed by the negative
freqs.

Cheers,
bob
Re: FFT help [message #41617 is a reply to message #41616] Fri, 05 November 2004 07:31 Go to previous message
Timm Weitkamp is currently offline  Timm Weitkamp
Messages: 66
Registered: August 2002
Member
Today at 08:43 -0600, Kenneth Bowman wrote:

> [...]
>
> This function
>
> COS(!PI*x/6.0)
>
> is only a small part of a complete cosine wave and has a jump
> discontinuity at the ends. (Try plotting it.)

Mhm, but the discontinuity can be avoided if you use a grid that takes an
integer number of periods of your function, for example:

IDL> x = findgen(120)
IDL> y = 8 * cos(2*!pi*x/6)
IDL> ft = fft(y)
IDL> plot, abs(ft)

The result is pretty much what the original poster expected to get: two
peaks with values of exactly 4, at positions of 20 (=120/6) and 100 (the
mirrored peak -- see the online help for FFT for how the frequencies are
ordered in the output of FFT) on the frequency axis.

Good luck
Timm

--
Timm Weitkamp <http://people.web.psi.ch/weitkamp>
Re: FFT help [message #41618 is a reply to message #41617] Fri, 05 November 2004 06:43 Go to previous message
K. Bowman is currently offline  K. Bowman
Messages: 330
Registered: May 2000
Senior Member
In article
<26d23fcf09dce26228fc67cf81ec832f@localhost.talkaboutprogramming.com>,
"IDLmastertobe" <shi_lee@hotmail.com> wrote:

> Hey, I am experiencing problem using fft function. Since FFT function
> provides the fourier transform of a certain input, for example,
> 8*cos(!PI*x/6), I would expect an amplitude of 4 at 2 shifted frequencies,
> namely -!PI/6 and PI/6. However after I recieved data from the FFT, I
> recieved some amplitudes close to 2 at some random locations, can anyone
> explain to me why it happened? Thanks for your time.
>

This function

COS(!PI*x/6.0)

is only a small part of a complete cosine wave and has a jump
discontinuity at the ends. (Try plotting it.)

Perhaps you mean

IDL> x = findgen(16)/16.0
IDL> xx = fft(8.0*cos(6.0*!pi*x))
IDL> for i = 0, 15 do print, xx[i]
( 1.66889e-07, 0.00000)
( 9.40551e-07, 2.41026e-07)
( -1.35589e-07, 6.01780e-07)
( 4.00000, 6.09532e-07)
( -3.99355e-07, 2.98023e-08)
( -2.53313e-07, 1.34857e-08)
( 1.59439e-07, -5.38710e-08)
( -4.56263e-07, -2.95416e-07)
( 5.84122e-07, -0.00000)
( -4.56263e-07, 2.95416e-07)
( 1.59439e-07, 5.38710e-08)
( -2.53313e-07, -1.34857e-08)
( -3.99355e-07, -2.98023e-08)
( 4.00000, -6.09532e-07)
( -1.35589e-07, -6.01780e-07)
( 9.40551e-07, -2.41026e-07)

Ken Bowman
Re: FFT help [message #41620 is a reply to message #41618] Fri, 05 November 2004 06:23 Go to previous message
Norbert Hahn is currently offline  Norbert Hahn
Messages: 46
Registered: May 2003
Member
"IDLmastertobe" <shi_lee@hotmail.com> wrote:

> Hey, I am experiencing problem using fft function. Since FFT function
> provides the fourier transform of a certain input, for example,
> 8*cos(!PI*x/6),

First of all, this is a function. Please supply the min and max
values of x.

> I would expect an amplitude of 4 at 2 shifted frequencies,
> namely -!PI/6 and PI/6.

This should occur for an infinite number of values.

> However after I recieved data from the FFT, I
> recieved some amplitudes close to 2 at some random locations, can anyone
> explain to me why it happened? Thanks for your time.

I tried to check with the following code:

x=findgen(1000)/10
y = 8*cos(x)
plot, y
z = fft(y)
plot, abs(z)
print, max(abs(z))
; 3.32737

I get a distribution with peaks at x=1 and x=998 and a maximum of 3.32737.
Next I used 10,000 numbers and looked at
plot, [abs(z[0:20]),abs(z[9979:9999])]

Two peaks with 3.94421 as maximum values. So it approaches 4 as you expected.

HTH
Norbert
Re: FFT help [message #41621 is a reply to message #41620] Fri, 05 November 2004 06:21 Go to previous message
Randall  Skelton is currently offline  Randall Skelton
Messages: 31
Registered: October 2004
Member
Can you post a quick example with some IDL code that shows your
problem? There are plenty of example of using an FFT in the newsgroup
if you search:

http://groups-beta.google.com/group/comp.lang.idl-pvwave

Alternatively, see the notes below:

http://cimss.ssec.wisc.edu/~paulv/fft/fft_comparison.html
Cheers,
Randall
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: About Image Formats
Next Topic: Re: IDL PET/CT Viewer and Analysis package

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:56:36 PDT 2025

Total time taken to generate the page: 0.00373 seconds