Skip to content

Instantly share code, notes, and snippets.

@masterdezign
Forked from vi/dct.hs
Created December 5, 2015 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masterdezign/63f8eae05f7722e205ff to your computer and use it in GitHub Desktop.
Save masterdezign/63f8eae05f7722e205ff to your computer and use it in GitHub Desktop.
Simple command-line Discrete Cosine Transform in Haskell
-- "cabal install vector-fftw split"
import qualified Numeric.FFT.Vector.Unnormalized as FFT
import Data.Vector (fromList, toList)
import Data.List.Split (splitOneOf)
import Data.List (intersperse)
import Control.Monad (forever)
import Control.Arrow ((>>>))
main = forever $
getLine -- read a line
>>=( splitOneOf " \t" -- | split it to chunks on whitespace
>>> map read -- | | convert them to a list of Doubles
>>> fromList -- | | | convert the list to Vector
>>> FFT.run FFT.dct2 -- | | | | DCT
>>> toList -- | | | convert the resulting Vector back to list
>>> map show -- | | convert each Double back to String
>>> intersperse " " -- | put " " between all chunks
>>> concat -- | make one happy string from chunks and " "s
>>> putStrLn ) -- output it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment