PDA

View Full Version : Problems with FFT


brian0918
Feb16-05, 11:56 AM
This is part of my senior project. Please help! I'm trying to use a code to FFT a real, even set of data, but the results are not real and even as would be expected.

The code I'm using is availabe here (http://www.koders.com/c++/fid1C48DD8DBB45CA4B87C9A38DAFC532E793443862.aspx) (and fft.h (http://www.koders.com/c/fid52CE41F3A31157362D33C32AB2DBEDBBE68D78D9.aspx) andintl.h (http://www.koders.com/c/fidB64062339509A55058571EB7378153A9A2151D38.aspx?s =intl.h))

When I run RealFFT with the following 16 numbers for the Real input and nothing for the Imag input, I get these results:

Real input:
0.969647
-1.28744
0.0863155
0.19462
1.06651
0.490905
0.469052
-0.728912
-0.728912
0.469052
0.490905
1.06651
0.19462
0.0863155
-1.28744
0.969647

Real output:
2.52139
-0.37157
-2.72877
4.38382
1.74303
2.06953
0.687978
0.712455

Imag output:
1.19209e-007
0.0739102
1.13029
-2.92917
-1.74303
-3.09727
-1.66093
-3.58175

Any help? I've tried a different FFT code and the same thing happens. Help!! :cry:

Davorak
Feb16-05, 04:27 PM
Is there some reason you can not use matlab, mathematica, or mathcad for their built in FFT?

brian0918
Feb16-05, 04:49 PM
Everything has to be automated and separate, so I need to use code. This FFT is just a small part of the whole code.

FredGarvin
Feb16-05, 05:17 PM
I did a quick FFT using Excel on your data and, short of having sign issues with the imaginary output, your numbers are exactly the same that I got.


2.521395
-0.371567052707447-7.39092820943204E-002i
-2.72876745822043-1.13029248975726i
4.38381766777983+2.92917331814368i
1.7430325+1.7430325i
2.06953109891377+3.09727216864978i
0.687977458220434+1.66092451024274i
0.712454286013861+3.58174956841178i
0
0.712454286013851-3.58174956841177i
0.687977458220432-1.66092451024274i
2.06953109891376-3.09727216864978i
1.7430325-1.7430325i
4.38381766777983-2.92917331814369i
-2.72876745822043+1.13029248975726i
-0.371567052707448+7.39092820943208E-002i

brian0918
Feb16-05, 05:24 PM
The data is real and even though, isn't it? So, shouldn't the result also be real and even?

Hurkyl
Feb16-05, 05:30 PM
Nope.

Though, IIRC, the imaginary parts can be computed from the real parts, so the real parts are all you actually need when the input is real.

Atrus
Feb16-05, 05:40 PM
It should be real only if input sequence is symmetrical around t = 0. But you assume causal sequence (with FFT), so data is shifted and phase delay is introduced, by which you get imaginary component of spectrum...

At least, that's off top of my head. Could be wrong...

brian0918
Feb16-05, 06:05 PM
So how would I go about inputting data so that it would be interpreted as being symmetrical around t=0? According to the text that created the code I used, it is even if the values at k and (N-k) are the same.

Atrus
Feb16-05, 06:16 PM
I just thought about what I wrote (I should do that BEFORE writing, right?). Well, since FFT (DFT) transform results with spectrum of periodic signal whose one period is the original sequence, it doesn't matter if the sequence is causal or not, FFT "percieves" it as periodic to + and - direction, hence the dicrete spectrum.

I've input the data in Matlab, and got the same results. Shifting the array results only in different phase frequency characteristic.

The seed of doubt in my mind is that I remember this: symmetrical real signals result in _linear_ phase characteristic, not by zero-phase...

Anyway, I'm ill and it's quite late here, so I'll try to think straight in the morning (at least, I'll try ;) )

shmoe
Feb17-05, 09:57 AM
According to the text that created the code I used, it is even if the values at k and (N-k) are the same.

I think you're mixing up the indicies somehow. If your data set is indexed starting at zero and it's even, it will look like:

\left[x_0, x_1, x_2, x_3, x_4, x_5, x_6, x_7, x_8, x_7, x_6, x_5, x_ 4, x_ 3, x_2, x_1\right]

In this case the output will be real assuming the input is. Your data is not of this shape, so you can't expect the nice cancellation.