Thread Subject: About FFT and Even Function

Subject: About FFT and Even Function

From: Oscar

Date: 1 Nov, 2009 05:42:02

Message: 1 of 9

Hello everyone,

I have a doubt about FFT function on Matlab. I know when I have an even and real function its FFT give only real values. But, when I calculate, for example, the FFT of a cosine function result real and imaginary values. I think I making a mistake on my interpretation of this result. Anyone can help me please :)

Thanks and sorry for my english!!!

Subject: About FFT and Even Function

From: dbd

Date: 1 Nov, 2009 05:56:41

Message: 2 of 9

On Oct 31, 10:42 pm, "Oscar " <oscarodrig...@yahoo.es> wrote:
> Hello everyone,
>
> I have a doubt about FFT function on Matlab. I know when I have an even and real function its FFT give only real values. But, when I calculate, for example, the FFT of a cosine function result real and imaginary values. I think I making a mistake on my interpretation of this result. Anyone can help me please :)
>
> Thanks and sorry for my english!!!

There are often mistakes made confusing 'symmetry' with 'fft-
evenness'. For examples, compare the difference between Matlab's
'symmetric' and 'periodic' forms of window functions. Use the windows
as the real signals to be transformed.

A good reference is fred harris' paper on windows. Look at the first
column of page 173. The paper is available a number of places. One is:

http://www.utdallas.edu/~cpb021000/EE%204361/Great%20DSP%20Papers/Harris%20on%20Windows.pdf

Dale B. Dalrymple

Subject: About FFT and Even Function

From: Nasser M. Abbasi

Date: 1 Nov, 2009 07:11:25

Message: 3 of 9


"Oscar " <oscarodrigo3k@yahoo.es> wrote in message
news:hcj73a$b5$1@fred.mathworks.com...
> Hello everyone,
>
> I have a doubt about FFT function on Matlab. I know when I have an even
> and real function its FFT give only real values. But, when I calculate,
> for example, the FFT of a cosine function result real and imaginary
> values. I think I making a mistake on my interpretation of this result.
> Anyone can help me please :)
>
> Thanks and sorry for my english!!!

If the data sequence itself is real and even (i.e. x[n]=x[N-n]) where N is
the sample points, then the discrete fourier transform (which fft is an
implementation of) should result in all real values. i.e. g[k] for k=1..N
should be real values.

Is this the case with your sampled data?

--Nasser

Subject: About FFT and Even Function

From: dbd

Date: 1 Nov, 2009 15:37:33

Message: 4 of 9

On Oct 31, 11:11 pm, "Nasser M. Abbasi" <n...@12000.org> wrote:
> ...
> If the data sequence itself is real and even (i.e. x[n]=x[N-n]) where N is
> ...
> --Nasser

Let's try that:

>> % Nassar's formula, N = 6, x[n] = x[N-n] for n=1:N-1
>> fft([1 2 3 2 1 0])'
ans =
   9.0000
  -2.0000 + 3.4641i
        0
   1.0000
        0
  -2.0000 - 3.4641i
>> % "FFT-even" version, N = 6, x[n] = x[N-n+1] for n=2:N
>> fft([0 1 2 3 2 1])'
ans =
     9
    -4
     0
    -1
     0
    -4
>>

Dale B. Dalrymple

Subject: About FFT and Even Function

From: Nasser M. Abbasi

Date: 1 Nov, 2009 16:52:20

Message: 5 of 9


"dbd" <dbd@ieee.org> wrote in message
news:a220a52b-a008-4b16-acc7-0656a03275b3@w37g2000prg.googlegroups.com...
> On Oct 31, 11:11 pm, "Nasser M. Abbasi" <n...@12000.org> wrote:
>> ...
>> If the data sequence itself is real and even (i.e. x[n]=x[N-n]) where N
>> is
>> ...
>> --Nasser
>
> Let's try that:
>

>>> % Nassar's formula, N = 6, x[n] = x[N-n] for n=1:N-1
>>> fft([1 2 3 2 1 0])'
> ans =
> 9.0000
> -2.0000 + 3.4641i
> 0
> 1.0000
> 0
> -2.0000 - 3.4641i

Ofcourse, I said above n=1:N-1 which is clearly wrong (the number of points
is N now N-1 points), I meant to write n=0:N-1 to make it N points. I made a
typo starting it from 1 not 0.

May be now you can try my formula? ;) but watch for the index.

--Nasser

Subject: About FFT and Even Function

From: Oscar

Date: 1 Nov, 2009 16:58:01

Message: 6 of 9

dbd <dbd@ieee.org> wrote in message <a220a52b-a008-4b16-acc7-0656a03275b3@w37g2000prg.googlegroups.com>...
> On Oct 31, 11:11 pm, "Nasser M. Abbasi" <n...@12000.org> wrote:
> > ...
> > If the data sequence itself is real and even (i.e. x[n]=x[N-n]) where N is
> > ...
> > --Nasser
>
> Let's try that:
>
> >> % Nassar's formula, N = 6, x[n] = x[N-n] for n=1:N-1
> >> fft([1 2 3 2 1 0])'
> ans =
> 9.0000
> -2.0000 + 3.4641i
> 0
> 1.0000
> 0
> -2.0000 - 3.4641i
> >> % "FFT-even" version, N = 6, x[n] = x[N-n+1] for n=2:N
> >> fft([0 1 2 3 2 1])'
> ans =
> 9
> -4
> 0
> -1
> 0
> -4
> >>
>
> Dale B. Dalrymple


ohhh!! Thank you for your help!!!!, :)

Subject: About FFT and Even Function

From: dbd

Date: 1 Nov, 2009 17:37:16

Message: 7 of 9

On Nov 1, 8:52 am, "Nasser M. Abbasi" <n...@12000.org> wrote:
> "dbd" <d...@ieee.org> wrote in message
>
> news:a220a52b-a008-4b16-acc7-0656a03275b3@w37g2000prg.googlegroups.com...
>
>
>
> > On Oct 31, 11:11 pm, "Nasser M. Abbasi" <n...@12000.org> wrote:
> >> ...
> >> If the data sequence itself is real and even (i.e. x[n]=x[N-n]) where N
> >> is
> >> ...
> >> --Nasser
>
> > Let's try that:
>
> >>> % Nassar's formula, N = 6, x[n] = x[N-n] for n=1:N-1
> >>> fft([1 2 3 2 1 0])'
> > ans =
> > 9.0000
> > -2.0000 + 3.4641i
> > 0
> > 1.0000
> > 0
> > -2.0000 - 3.4641i
>
> Ofcourse, I said above n=1:N-1 which is clearly wrong (the number of points
> is N now N-1 points), I meant to write n=0:N-1 to make it N points. I made a
> typo starting it from 1 not 0.
>
> May be now you can try my formula? ;) but watch for the index.

No, Matlab indices start at 1. I applied your formula to 1:N-1 because
it doesn't work for N, but I did fft a set of N values. (These are
samples of a triangular waveform.)

Anyway, did you mean something like this?

>> fft([0 1 2 3 2 1 0])'
ans =
   9.0000
  -4.5489 + 2.1906i
   0.1920 - 0.2408i
  -0.1431 + 0.6270i
  -0.1431 - 0.6270i
   0.1920 + 0.2408i
  -4.5489 - 2.1906i
>>

These are not real. The point is that symmetry is not the same as "fft-
evenness".

>
> --Nasser

Dale B. Dalrymple

Subject: About FFT and Even Function

From: Nasser M. Abbasi

Date: 1 Nov, 2009 19:19:26

Message: 8 of 9


"dbd" <dbd@ieee.org> wrote in message
news:e605aa13-a63b-4032-8b9d-039cdd5efa7a@b36g2000prf.googlegroups.com...
>

> No, Matlab indices start at 1.

Thanks for letting me know that, I'll have to remember that.

>I applied your formula to 1:N-1 because
> it doesn't work for N, but I did fft a set of N values. (These are
> samples of a triangular waveform.)
>
> Anyway, did you mean something like this?
>
>>> fft([0 1 2 3 2 1 0])'
> ans =
> 9.0000
> -4.5489 + 2.1906i
> 0.1920 - 0.2408i
> -0.1431 + 0.6270i
> -0.1431 - 0.6270i
> 0.1920 + 0.2408i
> -4.5489 - 2.1906i
>>>
>


No, that is not what I mean. In the above, you have N=7, but "my formula"
said

x(n)=x(N-n) for n=0..N-1 which means x(7) is not valid part of the
sequence since 7 is more than 7-1 which is 6. So the sequence should have
been

x(0)=x(7) (n=0 case)
x(1)=x(6) (n=1 case)
x(2)=x(5) (n=2 case)
x(3)=x(4) (n=3 case)

So, assume, using your numbers, that x(0)=0, x(1)=1, x(2)=2, x(3)=3 one
gets

x(0)=0
x(1)=1
x(2)=2
x(3)=3
x(4)=3
x(5)=2
x(6)=1 and you STOP here, since n goes only up to N-1 whichis 6.

So now the x sequence is [0,1,2,3,3,2,1]

EDU>> fft([0 1 2 3 3 2 1])

ans =

   12.0000 -5.0489 -0.3080 -0.6431 -0.6431 -0.3080 -5.0489


So, I guess Nasser's formula works after all? ;)

--Nasser

Subject: About FFT and Even Function

From: dbd

Date: 1 Nov, 2009 23:11:04

Message: 9 of 9

On Nov 1, 11:19 am, "Nasser M. Abbasi" <n...@12000.org> wrote:
...
> ...
> No, that is not what I mean. In the above, you have N=7, but "my formula"
> said
>
> x(n)=x(N-n) for n=0..N-1 which means x(7) is not valid part of the

No. Your first post did not say n=0...N-1. In fact, you chose 1 to N
for the fft indices.

> sequence since 7 is more than 7-1 which is 6. So the sequence should have
> been
>
> x(0)=x(7) (n=0 case)
> x(1)=x(6) (n=1 case)
> x(2)=x(5) (n=2 case)
> x(3)=x(4) (n=3 case)
>
> So, assume, using your numbers, that x(0)=0, x(1)=1, x(2)=2, x(3)=3 one
> gets
>
> x(0)=0
> x(1)=1
> x(2)=2
> x(3)=3
> x(4)=3
> x(5)=2
> x(6)=1 and you STOP here, since n goes only up to N-1 whichis 6.
>
> So now the x sequence is [0,1,2,3,3,2,1]
>
> EDU>> fft([0 1 2 3 3 2 1])
>
> ans =
>
> 12.0000 -5.0489 -0.3080 -0.6431 -0.6431 -0.3080 -5.0489
>
> So, I guess Nasser's formula works after all? ;)

No Nasser, this is a Matlab group. There is no x(0). That is broken
here. :(

You gave 1 to N as the indices of the fft in your original post. That
was the thing you got right at first. :)

Your follow-up posts are different from the content of your original
post. This demonstrates that "There are often mistakes made" as I
originally posted to Oscar. Thank you for the extended
demonstration. :)

>
> --Nasser

Dale B. Dalrymple

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
even function Oscar 1 Nov, 2009 01:44:06
fft Oscar 1 Nov, 2009 01:44:05
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com