public
Last active

Visualizer

  • Download Gist
Visualizer.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.