pro fft_rearrange_test

Num=26
KMax=Num/2
a=findgen(13)+KMax
b=findgen(KMax)
subn=[a,b]
subm=subn

a=findgen(num,num)
x_fft=fft(a)

x_fft_re=complexarr(num,num)
x_fft_re_re=complexarr(num,num)
x_fft_low=complexarr(num,num)
x_fft_high=complexarr(num,num)
x_fft_re_simple=complexarr(num,num)

;Rearrange FFT the hard way
for n=0,num-1 do begin
    for m=0,num-1 do begin
        x_fft_re(subn(n),subm(m))=x_fft(n,m)
    endfor
endfor
;Rearrange FFT the easy way
x_fft_re_simple=shift(X_Fft,KMax,KMax)
x_fft_re_simple(KMax,KMax)=0
;Filter out the DC offset
low_pass=x_fft_re
low_pass(KMax,KMax)=0

;Undo Rearrange the Hard way
for n=0,num-1 do begin
    for m=0,num-1 do begin
        x_fft_re_re(n,m)=x_fft_re(subn(n),subm(m)) 
        x_fft_low(n,m)=low_pass(subn(n),subm(m))
  endfor
endfor
;Undo Rearrange the Easy Way
x_fft_simple=shift(X_fft_re_simple,-Kmax,-Kmax)

;Invert the fft

ainv=fft(x_fft_re_re,/inverse)
alow=fft(x_fft_low,/inverse)
alowsimple=fft(x_fft_simple,/inverse)

set_plot,'x'

plot,a
stop
oplot,ainv
oplot,alow
oplot,alowsimple
stop
end

