Fast Fourier transform: Difference between revisions

Content deleted Content added
Rdm (talk | contribs)
Rdm (talk | contribs)
Line 4: Line 4:
=={{header|J}}==
=={{header|J}}==


Based on [[j:Essays/FFT]], with some simplifications, sacrificing accuracy not visible here for clarity:
From [[j:Essays/FFT]]:


<lang j>cube =: ($~ q:@#) :. ,
<lang j>cube =: $~ q:@#
roots =: +@]^:(0>[) (_1^2%]) ^ i.@-: NB. The elegant version, but less accurate
roots =: +@]^:(0>[) (_1^2%]) ^ i.@-:
rou =: [: (, j.) [: (, (j.~%:0.5) , |."1&.:+.@|.@}.) [: ^@o.@:j. i.@(%&8) % -: NB. roots of unity
rou =: [: j./ 2 1 o./ o.@(% #)@i.@-:
floop =: 4 : 'for_r. i.#$x do. (y=.{."1 y) ] x=.(+/x) ,&,:"r (-/x)*y end.'
floop =: 4 : 'for_r. i.#$x do. (y=.{."1 y) ] x=.(+/x) ,&,:"r (-/x)*y end.'
fft =: ( ] floop&.cube rou@#) f. :. ifft
fft =: ( ] floop&.cube rou@#) f. :. ifft