packages feed

hsignal 0.1.0.2 → 0.1.0.3

raw patch · 5 files changed

+114/−7 lines, 5 filesdep +arraydep +hstatistics

Dependencies added: array, hstatistics

Files

CHANGES view
@@ -3,3 +3,6 @@  0.1.0.2: 		updated to reflect hmatrix 0.9.3.0++0.1.0.3:+		added Numeric.Signal.Multichannel
configure.hs view
@@ -18,7 +18,7 @@ -}  import System-import System.Directory(createDirectoryIfMissing)+import System.Directory(createDirectoryIfMissing,getCurrentDirectory) import Data.List(isPrefixOf, intercalate) import Distribution.Simple.LocalBuildInfo import Distribution.Simple.Configure@@ -96,6 +96,9 @@           cs x   = x  main = do+    dir <- getCurrentDirectory+    putStrLn $ "Current directory: " ++ dir+     putStr "Checking foreign libraries..."      args <- getArgs
hsignal.cabal view
@@ -1,5 +1,5 @@ Name:               hsignal-Version:            0.1.0.2+Version:            0.1.0.3 License:            GPL License-file:       LICENSE Author:             Alexander Vivian Hugh McPhail@@ -9,25 +9,28 @@ Synopsis:           Signal processing Description:        Purely functional interface to signal processing based on hmatrix Category:           Math-tested-with:        GHC ==6.10.4+tested-with:        GHC ==6.12.1 -cabal-version:      >=1.2+cabal-version:      >=1.8  build-type:         Custom  extra-source-files: configure configure.hs README INSTALL CHANGES-extra-tmp-files:    hmatrix.buildinfo+extra-tmp-files:    hsignal.buildinfo  library      Build-Depends:      base >= 3 && < 5,                         storable-complex, haskell98,-                        hmatrix >= 0.9.3+                        hmatrix >= 0.9.3,+                        hstatistics,+                        array      Extensions:         ForeignFunctionInterface      hs-source-dirs:     lib     Exposed-modules:    Numeric.Signal+                        Numeric.Signal.Multichannel     other-modules:      Numeric.Signal.Internal     C-sources:          lib/Numeric/Signal/signal-aux.c @@ -36,6 +39,7 @@     ghc-options:        -Wall -fno-warn-missing-signatures                               -fno-warn-orphans                               -fno-warn-unused-binds+                        -threaded      if os(OSX)         extra-lib-dirs: /opt/local/lib/
lib/Numeric/Signal.hs view
@@ -19,13 +19,16 @@                        fir,standard_fir,broadband_fir,                        freqzF,freqzN,                        filter,broadband_filter,-                       analytic_signal,analytic_power,analytic_phase+                       analytic_signal,analytic_power,analytic_phase,+                       detrend                 ) where  -----------------------------------------------------------------------------  import qualified Numeric.Signal.Internal as S +import Numeric.GSL.Fitting.Linear+  import Complex  import qualified Data.List as L@@ -196,5 +199,23 @@ analytic_phase :: Vector (Complex Double) -> Vector Double analytic_phase v = let (r,c) = fromComplex v                    in vectorZipR ATan2 c r++-----------------------------------------------------------------------------++-- | remove a linear trend from data+detrend :: Int             -- ^ window size+        -> Vector Double   -- ^ data to be detrended+        -> Vector Double   -- ^ detrended data+detrend w v = let windows = dim v `div` w+                  ws = takesV ((replicate windows w) ++ [dim v - (windows * w) + 1]) v+                  ds = map detrend' ws+                  windows' = (dim v - (w `div` 2)) `div` w+                  ws' = takesV (((w `div` 2):(replicate windows w)) ++ [dim v - (w `div` 2) - (windows' * w) + 1]) v+                  ds' = map detrend' ws'+              in (join ds + join ds') / 2+    where detrend' x = let ln = dim x+                           y = linspace ln (1.0,fromIntegral ln)+                           (c0,c1,_,_,_,_) = linear x y+                       in x - c0 - c1 * x  -----------------------------------------------------------------------------
+ lib/Numeric/Signal/Multichannel.hs view
@@ -0,0 +1,76 @@+{-# OPTIONS_GHC -fglasgow-exts #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Numeric.Signal.Multichannel+-- Copyright   :  (c) Alexander Vivian Hugh McPhail 2010+-- License     :  GPL-style+--+-- Maintainer  :  haskell.vivian.mcphail <at> gmail <dot> com+-- Stability   :  provisional+-- Portability :  uses Concurrency+--+-- Signal processing functions, multichannel datatype+--+-- link with '-threaded' and run with +RTS Nn, where n is the number of CPUs+--+-----------------------------------------------------------------------------++module Numeric.Signal.Multichannel (+                       Multichannel,+                       mapConcurrently+                ) where++-----------------------------------------------------------------------------++--import qualified Numeric.Signal as S++--import Complex++import qualified Data.Array.IArray as I++import Control.Concurrent+import Control.Concurrent.MVar++import System.IO.Unsafe(unsafePerformIO)++--import qualified Data.List as L++import Data.Packed.Vector+--import Data.Packed(Container(..))++import Foreign.Storable+--import Numeric.GSL.Vector++--import Numeric.LinearAlgebra.Algorithms++--import qualified Numeric.GSL.Fourier as F++--import Prelude hiding(filter)++-----------------------------------------------------------------------------++data Multichannel a = MC {+                          _sampling_rate :: Int -- ^ sampling rate+                          , _precision   :: Int -- ^ bits of precision+                          , _channels    :: Int -- ^ number of channels+                          , _length      :: Int -- ^ length in samples+                          , _data        :: I.Array Int (Vector a) -- ^ data+                         }++-----------------------------------------------------------------------------+++-- | map a function executed concurrently+mapConcurrently :: Storable b => Multichannel a  -- ^ input data+                -> (Vector a -> Vector b)        -- ^ the function to be mapped+                -> Multichannel b                -- ^ output data+mapConcurrently (MC sr p c _ d) f = unsafePerformIO $ do+                                    results <- newMVar []+                                    mapM_ (forkIO . applyFunction results f) $ I.assocs d+                                    vectors <- takeMVar results+                                    return $ MC sr p c (dim $ snd $ head vectors) (I.array (1,c) vectors)+    where applyFunction results f' (i,e) = do+                                          let o = f' e+                                          modifyMVar_ results (\x -> return ((i,o):x))+                                    +-----------------------------------------------------------------------------