Re: Correction: 2D FFt [message #7281 is a reply to message #7254] |
Wed, 23 October 1996 00:00   |
Graeme K Harkness
Messages: 3 Registered: August 1996
|
Junior Member |
|
|
Walid Atia wrote:
>
> Hi,
>
> I just realized that FFT(data,-1) takes the FFT of an array of up to 7
> dimensions. What confused me was that when I plotted, say, the FFT of a
> gaussian, I got values only near the sides. However, the FFT of a
> gaussian is a gaussian, so I thought that the FFT routine must not be
> working correctly for my array. Just in case anyone out there is
> interested, the problem lies in the way IDL stores the FFT data. The
> edges are taken as 0 frequency, rather than the more intuitively obvious
> center to be zero. A simple shift in the FFT'd image solves the
> problem, and yields the expected results. The code which illustrates
> this is:
>
> x=shift(dist(201),100,100) 'create an array of r-values
> z=exp(-(x/10)^2) 'gaussian with spot size (1/e) of 10.
> shade_surf,z 'plot the gaussian
> Fz=FFT(z,-1) 'take the FFT of z--note that Fz is now of complex type
> shade_surf,abs(Fz) 'this will give the wrong picture!
> Fzfix=shift(Fz,100,100) 'correct the transform so that the center of the
> image is at zero frequency
> shade_surf,abs(Fzfix) 'the FFT of a gaussian is a gaussian.
> IFz=FFT(Fz,1) 'take the inverse fft.
> shade_surf,IFz 'gives the original data, as expected.
>
> Does anyone know of a more direct (and elegant) way of performing this
> transform? And why does IDL store the 2D transform this way--doesn't
> the usual 2D transform treat the center of the array as zero frequency,
> so as to get a symmetrical function given a symmetrical image?
>
> Hope someone besides myself found this useful!
>
> Walid
Walid,
I'm pretty sure that this re-arrangement of the frequency space is
related
to the methods used to do Fast Fourier Transforms in general (but it's
been
a long time since I studied this stuff :-)
I have a couple of routines (FFT1D and FFT2D) which take the Fourier
transforms and return you the re-ordered data (with zero frequency at
the
centre). They do use the standard IDL routines and then re-order
afterwards
so they aren't the most efficient things ever but they work very well.
(I suppose if you wanted very efficient code you wouldn't be using the
FFTs
in IDL anyway since I'd bet you could call an external function in
FORTRAN
(or something) to do it much faster!)
If you'd like a copy of these, then drop me an e-mail and I'll forward
them
on to you. If more people would like them I can post them if you like.
Cheers,
Graeme
............................................................ ..........
-----------------------------------------------
| Graeme K Harkness |
| Department of Physics & Applied Physics |
| University of Strathclyde |
| GLASGOW G4 0NG UK |
| Tel: +44-141-552 4400 x3354 |
| Fax: +44-141-552 2891 |
| graeme@phys.strath.ac.uk |
-----------------------------------------------
|
|
|