Skip to content

Instantly share code, notes, and snippets.

@petermarks
Created May 16, 2011 16:32
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 petermarks/974785 to your computer and use it in GitHub Desktop.
Save petermarks/974785 to your computer and use it in GitHub Desktop.
Visualizer
module Visualiser where
import Numeric.FFT
import Data.Complex
test :: [Complex Double]
test = concat $ replicate 16 (replicate 8 1.0 ++ replicate 8 (-1.0))
freqs :: [Complex Double] -> [Double]
freqs samples = take (n `div` 2) . map (/ fromIntegral n) . map magnitude $ fft samples
where n = length samples
groupBins :: Int -> [Double] -> [Double]
groupBins i xs = map (/ fromIntegral binSize) . map sum $ chunksOf binSize xs
where binSize = length xs `div` i
chunksOf :: Int -> [a] -> [[a]]
chunksOf k = go
where
go t = case splitAt k t of
(a,b) | null a -> []
| otherwise -> a : go b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment