2D FFT help [message #32451] |
Tue, 08 October 2002 07:58 |
Randall Skelton
Messages: 169 Registered: October 2000
|
Senior Member |
|
|
Greetings all,
I am trying to perform a multi-dimensional FFT in IDL. I thought I had
this figured out (example 1) but I am now feeling (example 2) that this
isn't quite right. Can someone please help me overcome my misconception?
;========================================================
; Example 1: Quick 2D FFT testing - square in a plane
a = fltarr(128,128) ; 2^n sized array
a[62:66,62:66] = 1 ; NB: this is a square, not a circle
; Plot the input
surface, a
; Shift the array (element 0 must contains the zero frequency component)
a_shifted = shift(a, -1*64, -1*64)
; Perform the FFT
b = fft(a_shifted, /double)
; Shift the array (correct element 0 being the zero frequency component)
b_fixed = shift(b, -1*64, -1*64)
; Plot the result
surface, b_fixed
;========================================================
; Example 2: Diagonal
cov = fltarr(128,128) ; 2^n sized array
cov[indgen(128),indgen(128)] = 1 ; diagonal
; Plot the input
surface, cov
; Shift the array (element 0 must contains the zero frequency component)
cov_shifted = shift(cov, -1*64, -1*64)
; Perform the FFT
spec_cov = fft(cov_shifted, /double)
; Shift the array (correct element 0 being the zero frequency component)
spec_fixed = shift(spec_cov, -1*64, -1*64)
; Plot the result
surface, spec_fixed
So, in the first case, the answer looks correct and is a slight deviation
from the standard textbook example of the FFT of a cylinder. In the second
case, however, the results looks to be rotated by 90 degrees in the plane,
i.e. I think the result and input should look identical. Can someone
explain what I have done wrong? I am also somewhat troubled by the spike
currently at (0,0)?
Any and all help is greatly appreciated!
Cheers,
Randall
|
|
|