Last active
December 5, 2015 18:27
-
-
Save vi/52fc73b08c560eab0676 to your computer and use it in GitHub Desktop.
Simple command-line Discrete Cosine Transform in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- "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