FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > DSP

DSP comp.dsp newsgroup, mailing list

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-20-2007, 02:01 PM
patrickjennings
Guest
 
Posts: n/a
Default Strange FFT Behavior in MATLAB

I think we can all agree that FFT { x*(n) } = X*(N-k), or the FFT of th
conj of x(n) is the conj of the reversed version of the FFT of x(n).

But in MATLAB if a= [1+2j 3+4j 5+6j 7+8j] then

fft(conj(a)) = [16+20j -8+0j -4-4j 0-8j]

and

conj(fliplr(fft(a))) = [-8+0j -4-4j 0-8j 16+20j]

Any ideas? Another engineer and I spent most of a day looking at th
model before finding the fundamental problem.


Cheers

/Patrick



Reply With Quote
  #2 (permalink)  
Old 09-20-2007, 04:04 PM
fatnbafan
Guest
 
Posts: n/a
Default Re: Strange FFT Behavior in MATLAB

This is due to the fact that MATLAB index starts at 1 while when you say

FFT{x*(n)} = X*(N-k),

you are assuming that k = 0,...,N-1.

Note that when you do X(N-k) when k = 0, the first sample is X(N), whic
is the same as X(0). However, if you use fliplr, this is no longer true.

HTH,

>I think we can all agree that FFT { x*(n) } = X*(N-k), or the FFT of the
>conj of x(n) is the conj of the reversed version of the FFT of x(n).
>
>But in MATLAB if a= [1+2j 3+4j 5+6j 7+8j] then
>
>fft(conj(a)) = [16+20j -8+0j -4-4j 0-8j]
>
>and
>
>conj(fliplr(fft(a))) = [-8+0j -4-4j 0-8j 16+20j]
>
>Any ideas? Another engineer and I spent most of a day looking at the
>model before finding the fundamental problem.
>
>
>Cheers
>
>/Patrick
>
>
>
>

Reply With Quote
  #3 (permalink)  
Old 09-20-2007, 04:19 PM
Andor
Guest
 
Posts: n/a
Default Re: Strange FFT Behavior in MATLAB

Patrick wrote:
> I think we can all agree that FFT { x*(n) } = X*(N-k), or the FFT of the
> conj of x(n) is the conj of the reversed version of the FFT of x(n).


It's not exactly the reversed version. Your formula is correct, you
just have to look at it closer. Consider

X[k] := DFT{ x[n] }
X1[k] := DFT{ x*[n] }

So for k=0 you get

X1[0] = X*[N-0] = X*[N]. However, this index is beyond the limit
(indices go from k=0,1,...N-1), so X*[N] is in fact X*[0] (all indices
are modulo N). If you write it out you get

(X1[0], X1[1], ... , X1[N-1]) = (X*[0], X*[N-1], ...., X*[1]).

Presumably Matlab's 1-based indexing doesn't make this matter any
easier.

> But in MATLAB if a= [1+2j 3+4j 5+6j 7+8j] then
>
> fft(conj(a)) = [16+20j -8+0j -4-4j 0-8j]
>
> and
>
> conj(fliplr(fft(a))) = [-8+0j -4-4j 0-8j 16+20j]


For that a, I get

X = fft(a) = [16+20j -8 -4-4j -8j]
X1 = fft(conj(a)) = [16-20j 8j -4+4j -8 ]

which is just what the formula says.

> Any ideas? Another engineer and I spent most of a day looking at the
> model before finding the fundamental problem.


No wonder. If I were to look all day at a model*, I would never find
any problems!

Regards,
Andor

*Favourite model to look at: Claudia.

Reply With Quote
  #4 (permalink)  
Old 09-20-2007, 06:14 PM
patrickjennings
Guest
 
Posts: n/a
Default Re: Strange FFT Behavior in MATLAB

Ah ha! X(N-k) isn't a "reversal" of X, it's a circular shift... that wa
a silly mistake, thanks for the quick answers all. If anyone is ever i
Dallas, TX beers are owed.

Cheers.

/ptj

>Patrick wrote:
>> I think we can all agree that FFT { x*(n) } = X*(N-k), or the FFT o

the
>> conj of x(n) is the conj of the reversed version of the FFT of x(n).

>
>It's not exactly the reversed version. Your formula is correct, you
>just have to look at it closer. Consider
>
>X[k] := DFT{ x[n] }
>X1[k] := DFT{ x*[n] }
>
>So for k=0 you get
>
>X1[0] = X*[N-0] = X*[N]. However, this index is beyond the limit
>(indices go from k=0,1,...N-1), so X*[N] is in fact X*[0] (all indices
>are modulo N). If you write it out you get
>
>(X1[0], X1[1], ... , X1[N-1]) = (X*[0], X*[N-1], ...., X*[1]).
>
>Presumably Matlab's 1-based indexing doesn't make this matter any
>easier.
>
>> But in MATLAB if a= [1+2j 3+4j 5+6j 7+8j] then
>>
>> fft(conj(a)) = [16+20j -8+0j -4-4j 0-8j]
>>
>> and
>>
>> conj(fliplr(fft(a))) = [-8+0j -4-4j 0-8j 16+20j]

>
>For that a, I get
>
>X = fft(a) = [16+20j -8 -4-4j -8j]
>X1 = fft(conj(a)) = [16-20j 8j -4+4j -8 ]
>
>which is just what the formula says.
>
>> Any ideas? Another engineer and I spent most of a day looking at the
>> model before finding the fundamental problem.

>
>No wonder. If I were to look all day at a model*, I would never find
>any problems!
>
>Regards,
>Andor
>
>*Favourite model to look at: Claudia.
>
>

Reply With Quote
  #5 (permalink)  
Old 09-20-2007, 06:56 PM
robert bristow-johnson
Guest
 
Posts: n/a
Default Re: Strange FFT Behavior in MATLAB

On Sep 20, 8:01 am, "patrickjennings" <patrick.t.jenni...@gmail.com>
wrote:
> I think we can all agree that FFT { x*(n) } = X*(N-k),


actually the folks at The Math Works do not agree. as fatnbafan said,
MATLAB is hard-wired or hard-coded so that the indices of all arrays
begin with 1, not 0 as it should for the DFT or FFT.

so in MATLAB, if N=length(x); y = conj(x); X = fft(x); Y = =
fft(y); then

Y(k+1) = conj( X(mod(N-k+1, N)) ); % for 0 <= k < N

or stated so elegantly that it's amazing we all don't just sing the
praises of MATLAB,

Y(k) = conj( X(mod(N-k+2, N) ); % for 1 <= k <= N

gee, isn't that elegant?

r b-j

> or the FFT of the
> conj of x(n) is the conj of the reversed version of the FFT of x(n).
>
> But in MATLAB if a= [1+2j 3+4j 5+6j 7+8j] then
>
> fft(conj(a)) = [16+20j -8+0j -4-4j 0-8j]
>
> and
>
> conj(fliplr(fft(a))) = [-8+0j -4-4j 0-8j 16+20j]
>
> Any ideas? Another engineer and I spent most of a day looking at the
> model before finding the fundamental problem.
>
> Cheers
>
> /Patrick



Reply With Quote
  #6 (permalink)  
Old 09-20-2007, 07:10 PM
Scott Seidman
Guest
 
Posts: n/a
Default Re: Strange FFT Behavior in MATLAB

robert bristow-johnson <[email protected]> wrote in
news:[email protected] ups.com:

> actually the folks at The Math Works do not agree. as fatnbafan said,
> MATLAB is hard-wired or hard-coded so that the indices of all arrays
> begin with 1, not 0 as it should for the DFT or FFT.



It's an index-- just a conceptual place holder, not a definition. X(1),
in a ones indexed language, merely points to the first memory location in
array X.

Most likely the ones indexing in Matlab has its roots in Fortran.

Aside from having to remember what language you're working in and getting
bitten every now and again when moving back and forth between languages,
it really isn't that problematic.


> Y(k) = conj( X(mod(N-k+2, N) ); % for 1 <= k <= N
>
> gee, isn't that elegant?


As compared to what? If you're comparing to finding and downloading the
c implemenation of fftw, compiling it, linking to it, then figuring out
which of the many arcane fftw routines you need to be calling, and then
figuring out what arcane pattern your returned arrays are in, maybe
creating complex variable types from two doubles, and then first doing
your elegant zero-indexed circular shift, its a veritable tango. If
you're talking about doing the same in some zero-indexed matlab clone,
probably not as elegant.


--
Scott
Reverse name to reply
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Block RAM strange behavior, address off by one M. Hamed FPGA 11 04-18-2007 11:53 PM
ISE 6.2i strange behavior sjulhes FPGA 3 11-18-2005 05:28 PM
A strange behavior Marco FPGA 2 09-02-2005 08:30 AM
strange behavior in lpm_counter pjjones FPGA 1 10-21-2004 09:03 PM
Strange synthesis behavior from Quartus II 2.2 Prashant FPGA 4 09-30-2003 04:55 AM


All times are GMT +1. The time now is 01:52 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved