Fast Fourier transform: Difference between revisions
Content added Content deleted
(→{{header|ALGOL 68}}: replace array SLICE operator with array DICE operator... simpler.) |
|||
Line 360: | Line 360: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<lang haskell>import |
<lang haskell>import Data.Complex |
||
import Data.Array |
|||
import Data.Complex |
|||
-- Cooley-Tukey |
-- Cooley-Tukey |
||
Line 369: | Line 367: | ||
fft xs = zipWith (+) ys ts ++ zipWith (-) ys ts |
fft xs = zipWith (+) ys ts ++ zipWith (-) ys ts |
||
where n = length xs |
where n = length xs |
||
ys = fft evens |
|||
zs = fft odds |
|||
(evens, odds) = split xs |
|||
split [] = ([], []) |
|||
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) |
exp' k n = cis $ -2 * pi * (fromIntegral k) / (fromIntegral n) |
||
⚫ | |||
main = |
|||
⚫ | |||
forM_ res print</lang> |
|||
And the output: |
And the output: |