From 703e4b2531cd88fec6c9d24e9d035310ced4cfa8 Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Mon, 11 Nov 2013 02:42:11 -0600 Subject: [PATCH] Use hmatrix to generate random input with Gaussian distribution. --- LowPass.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/LowPass.hs b/LowPass.hs index 7ac0c0f..a8acb0a 100644 --- a/LowPass.hs +++ b/LowPass.hs @@ -8,8 +8,10 @@ import Data.List as L import Data.Vector.Storable as V import Data.Vector.Storable.Mutable as MV import Numeric.LinearAlgebra as LA +import Numeric.GSL.Fourier as LA import Control.Applicative +import Data.Complex import System.Random import System.Time import Text.Printf @@ -49,13 +51,15 @@ convolve kernel input = V.generate osize $ \j -> rkernel <.> V.slice j ksize inp main :: IO () main = do let isize = 2000000 - (input, inputTime) <- time $ V.fromListN isize . randoms <$> newStdGen + seed <- randomIO + (input, inputTime) <- time $ return $ LA.randomVector seed Gaussian isize (_, kernelTime) <- time $ return lowPassKernel (result, resultTime) <- time $ return $ convolve lowPassKernel input - V.mapM_ (printf "%0.6f\n") $ V.slice 0 50 result - printf "Input Time: %0.6f seconds\n" $ inputTime - printf "Kernel Time: %0.6f seconds\n" $ kernelTime - printf "Result Time: %0.6f seconds\n" $ resultTime + V.mapM_ (printf "%10.6f\n") $ V.slice 0 50 result + --V.mapM_ (printf "%10.6f\n") $ V.map magnitude $ LA.fft $ V.map (:+0) result + printf "Input Time: %8.6f seconds\n" $ inputTime + printf "Kernel Time: %8.6f seconds\n" $ kernelTime + printf "Result Time: %8.6f seconds\n" $ resultTime time :: IO a -> IO (a, Double) time f = do