Created
May 16, 2011 16:32
-
-
Save petermarks/974785 to your computer and use it in GitHub Desktop.
Visualizer
This file contains 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
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