Fast Fourier transform: Difference between revisions

(→‎{{header|ALGOL 68}}: replace array SLICE operator with array DICE operator... simpler.)
Line 360:
 
=={{header|Haskell}}==
<lang haskell>import ControlData.MonadComplex
import Data.Array
import Data.Complex
 
-- Cooley-Tukey
Line 369 ⟶ 367:
fft xs = zipWith (+) ys ts ++ zipWith (-) ys ts
where n = length xs
xs'ys = listArrayfft (1,n) xsevens
yszs = fft $odds map (xs'!) [1,3..n]
zs(evens, odds) = fftsplit $ map (xs'!) [2,4..n]
tssplit [] = zipWith (\z k -> (exp' k n) * z) zs[], [0..(n `div` 2])-1]
split [x] = ([x], [])
split (x:y:xs) = (x:xt, y:yt) where (xt, yt) = split xs
ts = zipWith (\z k -> exp' k n * z) zs [0..]
exp' k n = cis $ -2 * pi * (fromIntegral k) / (fromIntegral n)
main = mapM_ print do let res =$ fft [1,1,1,1,0,0,0,0]</lang>
main =
do let res = fft [1,1,1,1,0,0,0,0]
forM_ res print</lang>
 
And the output:
Anonymous user