FFT Exasperation [message #40060] |
Sun, 11 July 2004 15:12 |
jamiesmyth_uni
Messages: 6 Registered: May 2004
|
Junior Member |
|
|
Hi all,
Can someone please walk me through the IDL FFT function with regards to
the code below. In particular can someone explain why, 'Method 1' has
problems with n={1023, 1022, 1021} but works fine for 1020, 1024? I
thought I understood FFTs well enough but here I am with 3 different
texts getting more confused by the minute about the difference between
the math on the page and the code in my head... At this point, I'm not
even sure I understand why the two shifts in 'Method 2' are required.
The only think that I do know is that all my texts agree that a top-hat
function ought to transform to a pure sinc function. Something is
obviously getting lost between theory and practice.
Many thanks for the insight,
Jamie
=== CODE ===
pro FftTest
; Create a sinc function in IDL starting with a rectangular
; modulation function.
!p.multi=[3,1,3]
n = 1024 ; number of points
w = 50 ; width of box
a = dblarr(n)
a[(n/2-1)-w:(n/2-1)+w] = 1 ; rectangular function
plot, a, ytitle='a', /xstyle
; Method 1
idx = where(findgen(n) mod 2 ne 1)
a1 = a
a1[idx] = -a1[idx]
a1_ft = fft(a1)
a1_ft[idx] = -a1_ft[idx] ; sinc function
plot, a1_ft, ytitle='a1_ft', /xstyle
; Method 2
a2 = a
n_ft = (n/2L) + 1L
a2 = shift(a2, -1 * (n_ft-1)) ; Shift the data
a2_ft = fft(a2, /double) ; Take fft
a2_ft = shift(a2_ft, -1 * (n_ft-1)) ; Shift the data
plot, a2_ft, ytitle='a2_ft', /xstyle
End
|
|
|