packages feed

hsignal 0.2.7.1 → 0.2.7.2

raw patch · 7 files changed

+107/−95 lines, 7 filesdep +vectordep ~hmatrixdep ~hmatrix-gsldep ~hmatrix-gsl-statsPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: vector

Dependency ranges changed: hmatrix, hmatrix-gsl, hmatrix-gsl-stats, hstatistics

API changes (from Hackage documentation)

- Numeric.Signal.Multichannel: instance Binary (Multichannel (Complex Double))
- Numeric.Signal.Multichannel: instance Binary (Multichannel (Complex Float))
- Numeric.Signal.Multichannel: instance Binary (Multichannel Double)
- Numeric.Signal.Multichannel: instance Binary (Multichannel Float)
+ Numeric.Signal.Multichannel: instance Data.Binary.Class.Binary (Numeric.Signal.Multichannel.Multichannel (Data.Complex.Complex GHC.Types.Double))
+ Numeric.Signal.Multichannel: instance Data.Binary.Class.Binary (Numeric.Signal.Multichannel.Multichannel (Data.Complex.Complex GHC.Types.Float))
+ Numeric.Signal.Multichannel: instance Data.Binary.Class.Binary (Numeric.Signal.Multichannel.Multichannel GHC.Types.Double)
+ Numeric.Signal.Multichannel: instance Data.Binary.Class.Binary (Numeric.Signal.Multichannel.Multichannel GHC.Types.Float)
- Numeric.Signal: filter :: Filterable a => Vector a -> Vector a -> Int -> Vector a -> Vector a
+ Numeric.Signal: filter :: (Filterable a) => Vector a -> Vector a -> Int -> Vector a -> Vector a
- Numeric.Signal.Multichannel: readMultichannel :: Binary (Multichannel a) => FilePath -> IO (Multichannel a)
+ Numeric.Signal.Multichannel: readMultichannel :: (Binary (Multichannel a)) => FilePath -> IO (Multichannel a)
- Numeric.Signal.Multichannel: writeMultichannel :: Binary (Multichannel a) => FilePath -> Multichannel a -> IO ()
+ Numeric.Signal.Multichannel: writeMultichannel :: (Binary (Multichannel a)) => FilePath -> Multichannel a -> IO ()

Files

CHANGES view
@@ -133,3 +133,6 @@  0.2.7.1: 		added gsl dependencies to cabal file++0.2.7.2:+		update for hmatrix 0.17
hsignal.cabal view
@@ -1,5 +1,5 @@ Name:               hsignal-Version:            0.2.7.1+Version:            0.2.7.2 License:            BSD3 License-file:       LICENSE Copyright:          (c) A.V.H. McPhail 2010, 2011, 2014, 2015@@ -39,11 +39,12 @@     Build-Depends:      base >= 4 && < 5,                         mtl > 2,                          array,+                        vector,                         bytestring, storable-complex, binary,-                        hmatrix >= 0.16.0.3,-                        hmatrix-gsl >= 0.16,-                        hmatrix-gsl-stats >= 0.2,-                        hstatistics >= 0.2.5.1+                        hmatrix >= 0.17,+                        hmatrix-gsl >= 0.17,+                        hmatrix-gsl-stats >= 0.4,+                        hstatistics >= 0.2.5.3      Extensions:         ForeignFunctionInterface 
lib/Numeric/Signal.hs view
@@ -3,7 +3,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Numeric.Signal--- Copyright   :  (c) Alexander Vivian Hugh McPhail 2010, 2014+-- Copyright   :  (c) Alexander Vivian Hugh McPhail 2010, 2014, 2015 -- License     :  BSD3 -- -- Maintainer  :  haskell.vivian.mcphail <at> gmail <dot> com@@ -54,6 +54,8 @@ --import Data.Packed(Container(..)) import Numeric.LinearAlgebra +import qualified Data.Vector.Generic as GV + import qualified Numeric.GSL.Fourier as F  import Prelude hiding(filter)@@ -67,11 +69,11 @@        -> Int   -- ^ sampling rate        -> Vector a     -- ^ input signal        -> Vector a     -- ^ output signal-filter b a s v = let len = dim v+filter b a s v = let len = size v                      w = min s len                      start = (negate . fromList . reverse . toList . subVector 0 w) v                      finish = (negate . fromList . reverse . toList . subVector (len-w) w) v-                     v' = join [start,v,finish]+                     v' = vjoin [start,v,finish]                  in subVector s len $ S.filter_ b a v'  -----------------------------------------------------------------------------@@ -146,7 +148,7 @@                        grid = interpolate f' m' $ map (\x -> (fromIntegral x)/(fromIntegral gn)) [0..(gn-1)]                        grid' = map (\x -> x :+ 0) grid                        b = S.fromDouble $ fst $ fromComplex $ F.ifft $ double $ fromList $ grid' ++ (reverse (drop 1 grid'))-                       b' = join [subVector ((dim b)-mid-1) (mid+1) b, subVector 1 (mid+1) b] +                       b' = vjoin [subVector ((size b)-mid-1) (mid+1) b, subVector 1 (mid+1) b]                     in b' * w  floor_zero x@@ -225,16 +227,16 @@ detrend :: Int             -- ^ window size         -> Vector Double   -- ^ data to be detrended         -> Vector Double   -- ^ detrended data-detrend w v = let windows = dim v `div` w-                  re = dim v - (windows * w)+detrend w v = let windows = size v `div` w+                  re = size v - (windows * w)                   re' = if re == 0 then [] else [re]                   ws = takesV ((replicate windows w) ++ re') 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)]) v+                  windows' = (size v - (w `div` 2)) `div` w+                  ws' = takesV (((w `div` 2):(replicate windows' w)) ++ [size v - (w `div` 2) - (windows' * w)]) v                   ds' = map detrend' ws'-              in (join ds + join ds') / 2 -    where detrend' x = let ln = dim x+              in (vjoin ds + vjoin ds') / 2 +    where detrend' x = let ln = size x                            t = linspace ln (1.0,fromIntegral ln)                            (c0,c1,_,_,_,_) = linear t x                        in x - (scale c1 t + scalar c0)@@ -243,7 +245,7 @@  -- | resize the vector to length n by resampling resize :: S.Filterable a => Int -> Vector a -> Vector a-resize n v = S.downsample_ (dim v `div` n) v+resize n v = S.downsample_ (size v `div` n) v  ----------------------------------------------------------------------------- @@ -264,7 +266,7 @@                  -> Vector a -- ^ time series                  -> Vector a -- ^ result cross_correlation l x y = let (sx,sy,r) = S.cross_covariance_ l x y-                          in mapVector (/ (sx*sy)) r+                          in GV.map(/ (sx*sy)) r  -- | compute the cross spectrum cross_spectrum :: (S.Filterable a, Double ~ DoubleOf a) =>@@ -291,7 +293,7 @@                  -> Vector a -- ^ time series                  -> Vector a -- ^ result auto_correlation l v = let (var,r) = auto_covariance l v-                          in mapVector (/ var) r+                          in GV.map(/ var) r  ----------------------------------------------------------------------------- 
lib/Numeric/Signal/EEG/BDF.hs view
@@ -1,7 +1,7 @@ -----------------------------------------------------------------------------
 -- |
 -- Module      :  Numeric.Signal.EEG.BDF
--- Copyright   :  (c) Alexander Vivian Hugh McPhail 2010, 2014
+-- Copyright   :  (c) Alexander Vivian Hugh McPhail 2010, 2014, 2015
 -- License     :  BSD3
 --
 -- Maintainer  :  haskell.vivian.mcphail <at> gmail <dot> com
@@ -25,7 +25,7 @@ import Data.Word
 import Data.Bits
 --import Data.Array.Storable
-import Data.Packed.Vector
+import Numeric.LinearAlgebra.Data
 
 import qualified Numeric.Signal.Multichannel as M
 
@@ -195,7 +195,7 @@                    -- let v = rotate d
                    -- lift $ putStrLn $ "vectors: " ++ (show $ length v)
                    -- lift $ putStrLn $ "slices: " ++ (show $ length $ head v)
-                   return $! map join $! rotate_ d
+                   return $! map vjoin $! rotate_ d
     where rotate_ []            = []
           rotate_ xs@((_:[]):_) = [concat xs]
           rotate_ ((x:xs):xss)  = (x : (map head xss)) : (rotate_ (xs : (map tail xss)))
lib/Numeric/Signal/Internal.hs view
@@ -4,7 +4,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Numeric.Signal.Internal--- Copyright   :  (c) Alexander Vivian Hugh McPhail 2010, 2014+-- Copyright   :  (c) Alexander Vivian Hugh McPhail 2010, 2014, 2015 -- License     :  BSD3 -- -- Maintainer  :  haskell.vivian.mcphail <at> gmail <dot> com@@ -23,11 +23,9 @@                 hilbert                 ) where -import Data.Packed.Development(createVector,vec,app1,app2,app3,app4)---import Data.Packed.Vector import Numeric.LinearAlgebra+import Numeric.LinearAlgebra.Devel ---import Numeric.LinearAlgebra.Algorithms --import Numeric.LinearAlgebra.Linear  import qualified Numeric.GSL.Fourier as F@@ -42,6 +40,12 @@  ----------------------------------------------------------------------------- +infixl 1 #+a # b = applyRaw a b+{-# INLINE (#) #-}++-----------------------------------------------------------------------------+ type PD = Ptr Double                             type PC = Ptr (Complex Double)                   type PF = Ptr Float@@ -98,8 +102,8 @@ --    convolve = convolve_vector_double  convolve_vector_double c a = unsafePerformIO $ do-                             r <- createVector (dim a)-                             app3 signal_vector_double_convolve vec c vec a vec r "signalDoubleConvolve"+                             r <- createVector (size a)+                             signal_vector_double_convolve # c # a # r #| "signalDoubleConvolve"                              return r  foreign import ccall "signal-aux.h vector_double_convolve" signal_vector_double_convolve :: CInt -> PD -> CInt -> PD -> CInt -> PD -> IO CInt@@ -109,8 +113,8 @@ --    convolve = convolve_vector_double  convolve_vector_float c a = unsafePerformIO $ do-                             r <- createVector (dim a)-                             app3 signal_vector_float_convolve vec c vec a vec r "signalFloatConvolve"+                             r <- createVector (size a)+                             signal_vector_float_convolve # c # a # r #| "signalFloatConvolve"                              return r  foreign import ccall "signal-aux.h vector_float_convolve" signal_vector_float_convolve :: CInt -> PF -> CInt -> PF -> CInt -> PF -> IO CInt@@ -122,8 +126,8 @@ --    convolve = convolve_vector_complex  convolve_vector_complex c a = unsafePerformIO $ do-                              r <- createVector (dim a)-                              app3 signal_vector_complex_convolve vec c vec a vec r "signalComplexConvolve"+                              r <- createVector (size a)+                              signal_vector_complex_convolve # c # a # r #| "signalComplexConvolve"                               return r  foreign import ccall "signal-aux.h vector_complex_convolve" signal_vector_complex_convolve :: CInt -> PC -> CInt -> PC -> CInt -> PC -> IO CInt@@ -165,8 +169,8 @@        -> Vector Double -- ^ input signal        -> Vector Double -- ^ output signal filterD l k v = unsafePerformIO $ do-               r <- createVector (dim v)-               app4 signal_filter_double vec l vec k vec v vec r "signalFilter"+               r <- createVector (size v)+               signal_filter_double # l # k # v # r #| "signalFilter"                return r  foreign import ccall "signal-aux.h filter_double" signal_filter_double :: CInt -> PD -> CInt -> PD -> CInt -> PD -> CInt -> PD -> IO CInt@@ -177,8 +181,8 @@        -> Vector Float -- ^ input signal        -> Vector Float -- ^ output signal filterF l k v = unsafePerformIO $ do-               r <- createVector (dim v)-               app4 signal_filter_float vec l vec k vec v vec r "signalFilter"+               r <- createVector (size v)+               signal_filter_float # l # k # v # r #| "signalFilter"                return r  foreign import ccall "signal-aux.h filter_float" signal_filter_float :: CInt -> PF -> CInt -> PF -> CInt -> PF -> CInt -> PF -> IO CInt@@ -190,7 +194,7 @@ hilbert v = unsafePerformIO $ do             let r = complex v             -- could use (complex v) to make a complex vector in haskell rather than C-            app1 signal_hilbert vec r "hilbert"+            signal_hilbert # r #| "hilbert"             return r  foreign import ccall "signal-aux.h hilbert" signal_hilbert :: CInt -> PC -> IO CInt@@ -202,8 +206,8 @@        -> Vector Double  -- ^ input signal        -> Vector Double  -- ^ power density   pwelch w v = unsafePerformIO $ do-             let r = constant 0.0 ((w `div` 2) + 1)-             app2 (signal_pwelch $ fromIntegral w) vec (complex v) vec r "pwelch"+             let r = konst 0.0 ((w `div` 2) + 1)+             (signal_pwelch $ fromIntegral w) # (complex v) # r #| "pwelch"              return r  foreign import ccall "signal-aux.h pwelch" signal_pwelch :: CInt -> CInt -> PC -> CInt -> PD -> IO CInt@@ -214,10 +218,10 @@ hammingD :: Int           -- ^ length         -> Vector Double -- ^ the Hamming coeffficents hammingD l -    | l == 1          = constant 1.0 1+    | l == 1          = konst 1.0 1     | otherwise       = unsafePerformIO $ do                         r <- createVector l-                        app1 signal_hamming_double vec r "Hamming"+                        signal_hamming_double # r #| "Hamming"                         return r  foreign import ccall "signal-aux.h hamming_double" signal_hamming_double :: CInt -> PD -> IO CInt@@ -226,10 +230,10 @@ hammingF :: Int           -- ^ length         -> Vector Float -- ^ the Hamming coeffficents hammingF l -    | l == 1          = constant 1.0 1+    | l == 1          = konst 1.0 1     | otherwise       = unsafePerformIO $ do                         r <- createVector l-                        app1 signal_hamming_float vec r "Hamming"+                        signal_hamming_float # r #| "Hamming"                         return r  foreign import ccall "signal-aux.h hamming_float" signal_hamming_float :: CInt -> PF -> IO CInt@@ -252,13 +256,13 @@       -> Vector a       -- ^ pole coefficients       -> Vector a       -- ^ points (between 0 and 2*pi)       -> Vector a       -- ^ response-freqz b a w = let k = max (dim b) (dim a)+freqz b a w = let k = max (size b) (size a)                   hb = polyEval_ (postpad b k) (exp (scale (0 :+ 1) ((complex $ double w))))                   ha = polyEval_ (postpad a k) (exp (scale (0 :+ 1) ((complex $ double w))))               in complex_power_ (hb / ha) -postpad v n = let d = dim v-              in if d < n then join [v,(constant 0.0 (n-d))]+postpad v n = let d = size v+              in if d < n then vjoin [v,(konst 0.0 (n-d))]               else v  -----------------------------------------------------------------------------@@ -268,8 +272,8 @@          -> Vector (Complex Double) -- ^ the points at which to be evaluated          -> Vector (Complex Double) -- ^ the values polyEval c z = unsafePerformIO $ do-               r <- createVector (dim z)-               app3 signal_real_poly_complex_eval vec c vec z vec r "polyEval"+               r <- createVector (size z)+               signal_real_poly_complex_eval # c # z # r #| "polyEval"                return r  foreign import ccall "signal-aux.h real_poly_complex_eval" signal_real_poly_complex_eval :: CInt -> PD -> CInt -> PC -> CInt -> PC -> IO CInt@@ -280,8 +284,8 @@ complex_powerD :: Vector (Complex Double) -- ^ input               -> Vector Double           -- ^ output complex_powerD v = unsafePerformIO $ do-                  r <- createVector (dim v)-                  app2 signal_complex_power_double vec v vec r "complex_power"+                  r <- createVector (size v)+                  signal_complex_power_double # v # r #| "complex_power"                   return r  foreign import ccall "signal-aux.h complex_power_double" signal_complex_power_double :: CInt -> PC -> CInt -> PD -> IO CInt@@ -290,8 +294,8 @@ complex_powerF :: Vector (Complex Double) -- ^ input               -> Vector Float             -- ^ output complex_powerF v = unsafePerformIO $ do-                  r <- createVector (dim v)-                  app2 signal_complex_power_float vec v vec r "complex_power"+                  r <- createVector (size v)+                  signal_complex_power_float # v # r #| "complex_power"                   return r  foreign import ccall "signal-aux.h complex_power_float" signal_complex_power_float :: CInt -> PC -> CInt -> PF -> IO CInt@@ -301,8 +305,8 @@ -- | resample, take one sample every n samples in the original downsampleD :: Int -> Vector Double -> Vector Double downsampleD n v = unsafePerformIO $ do-               r <- createVector (dim v `div` n)-               app2 (signal_downsample_double $ fromIntegral n) vec v vec r "downsample"+               r <- createVector (size v `div` n)+               (signal_downsample_double $ fromIntegral n) # v # r #| "downsample"                return r  foreign import ccall "signal-aux.h downsample_double" signal_downsample_double :: CInt -> CInt -> PD -> CInt -> PD -> IO CInt@@ -310,8 +314,8 @@ -- | resample, take one sample every n samples in the original downsampleF :: Int -> Vector Float -> Vector Float downsampleF n v = unsafePerformIO $ do-               r <- createVector (dim v `div` n)-               app2 (signal_downsample_float $ fromIntegral n) vec v vec r "downsample"+               r <- createVector (size v `div` n)+               (signal_downsample_float $ fromIntegral n) # v # r #| "downsample"                return r  foreign import ccall "signal-aux.h downsample_float" signal_downsample_float :: CInt -> CInt -> PF -> CInt -> PF -> IO CInt@@ -321,8 +325,8 @@ -- | the difference between consecutive elements of a vector derivD :: Vector Double -> Vector Double derivD v = unsafePerformIO $ do-          r <- createVector (dim v - 1)-          app2 (signal_diff_double) vec v vec r "diff"+          r <- createVector (size v - 1)+          (signal_diff_double) # v # r #| "diff"           return r  foreign import ccall "signal-aux.h vector_diff_double" signal_diff_double :: CInt -> PD -> CInt -> PD -> IO CInt@@ -330,8 +334,8 @@ -- | the difference between consecutive elements of a vector derivF :: Vector Float -> Vector Float derivF v = unsafePerformIO $ do-          r <- createVector (dim v - 1)-          app2 (signal_diff_float) vec v vec r "diff"+          r <- createVector (size v - 1)+          (signal_diff_float) # v # r #| "diff"           return r  foreign import ccall "signal-aux.h vector_diff_float" signal_diff_float :: CInt -> PF -> CInt -> PF -> IO CInt@@ -341,8 +345,8 @@ -- | unwrap the phase of signal (input expected to be within (-pi,pi) unwrapD :: Vector Double -> Vector Double unwrapD v = unsafePerformIO $ do-           r <- createVector $ dim v-           app2 signal_unwrap_double vec v vec r "unwrap"+           r <- createVector $ size v+           signal_unwrap_double # v # r #| "unwrap"            return r  foreign import ccall "signal-aux.h unwrap_double" signal_unwrap_double :: CInt -> PD -> CInt -> PD -> IO CInt@@ -350,8 +354,8 @@ -- | unwrap the phase of signal (input expected to be within (-pi,pi) unwrapF :: Vector Float -> Vector Float unwrapF v = unsafePerformIO $ do-           r <- createVector $ dim v-           app2 signal_unwrap_float vec v vec r "unwrap"+           r <- createVector $ size v+           signal_unwrap_float # v # r #| "unwrap"            return r  foreign import ccall "signal-aux.h unwrap_float" signal_unwrap_float :: CInt -> PF -> CInt -> PF -> IO CInt@@ -364,7 +368,7 @@                            r <- createVector (2*l)                            alloca $ \sx ->                                 alloca $ \sy -> do-                                 app3 (signal_cross_covariance_double (fromIntegral l) sx sy) vec x vec y vec r "cross_covariance"+                                 (signal_cross_covariance_double (fromIntegral l) sx sy) # x # y # r #| "cross_covariance"                                  sx' <- peek sx                                  sy' <- peek sy                                  return (sx',sy',r)@@ -379,7 +383,7 @@                            r <- createVector (2*l)                            alloca $ \sx ->                                 alloca $ \sy -> do-                                 app3 (signal_cross_covariance_float (fromIntegral l) sx sy) vec x vec y vec r "cross_covariance"+                                 (signal_cross_covariance_float (fromIntegral l) sx sy) # x # y # r #| "cross_covariance"                                  sx' <- peek sx                                  sy' <- peek sy                                  return (sx',sy',r)@@ -392,14 +396,14 @@  cumSumD :: Vector Double -> Vector Double cumSumD v = unsafePerformIO $ do-              r <- createVector (dim v)-              app2 signal_cum_sum_double vec v vec r "cumSumD"+              r <- createVector (size v)+              signal_cum_sum_double # v # r #| "cumSumD"               return r  cumSumF :: Vector Float -> Vector Float cumSumF v = unsafePerformIO $ do-              r <- createVector (dim v)-              app2 signal_cum_sum_float vec v vec r "cumSumF"+              r <- createVector (size v)+              signal_cum_sum_float # v # r #| "cumSumF"               return r  foreign import ccall "signal-aux.h cum_sum_double"
lib/Numeric/Signal/Multichannel.hs view
@@ -6,7 +6,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Numeric.Signal.Multichannel--- Copyright   :  (c) Alexander Vivian Hugh McPhail 2010, 2014+-- Copyright   :  (c) Alexander Vivian Hugh McPhail 2010, 2014, 2015 -- License     :  BSD3 -- -- Maintainer  :  haskell.vivian.mcphail <at> gmail <dot> com@@ -59,8 +59,10 @@  import Foreign.Storable -import Numeric.LinearAlgebra+import Numeric.LinearAlgebra hiding(range) +import qualified Data.Vector.Generic as GV+ --import qualified Numeric.GSL.Fourier as F  import qualified Numeric.GSL.Histogram as H@@ -78,7 +80,7 @@  instance (Binary a, Storable a) => Binary (Vector a) where     put v = do-            let d = dim v+            let d = GV.length v             put d             mapM_ (\i -> put $ v @> i) [0..(d-1)]     get = do@@ -114,7 +116,7 @@                               put f                               put $! fmap convert d         where convert v = let (mi,ma) = (minElement v,maxElement v)-                              v' = mapVector (\x -> round $ (x - mi)/(ma - mi) * (fromIntegral (maxBound :: Word64))) v+                              v' = GV.map (\x -> round $ (x - mi)/(ma - mi) * (fromIntegral (maxBound :: Word64))) v                           in (mi,ma,v' :: Vector Word64)       get = do@@ -126,7 +128,7 @@           f <- get           (d :: I.Array Int (Double,Double,Vector Word64)) <- get           return $! (MC s p c l de f (seq d (fmap convert) d))-              where convert (mi,ma,v) = mapVector (\x -> ((fromIntegral x)) / (fromIntegral (maxBound :: Word64)) * (ma - mi) + mi) v+              where convert (mi,ma,v) = GV.map (\x -> ((fromIntegral x)) / (fromIntegral (maxBound :: Word64)) * (ma - mi) + mi) v  instance Binary (Multichannel Float) where     put (MC s p c l de f d) = do@@ -138,7 +140,7 @@                               put f                               put $! fmap convert d         where convert v = let (mi,ma) = (minElement v,maxElement v)-                              v' = mapVector (\x -> round $ (x - mi)/(ma - mi) * (fromIntegral (maxBound :: Word64))) v+                              v' = GV.map (\x -> round $ (x - mi)/(ma - mi) * (fromIntegral (maxBound :: Word64))) v                           in (mi,ma,v' :: Vector Word64)       get = do@@ -150,7 +152,7 @@           f <- get           (d :: I.Array Int (Float,Float,Vector Word32)) <- get           return $! (MC s p c l de f (seq d (fmap convert) d))-              where convert (mi,ma,v) = mapVector (\x -> ((fromIntegral x)) / (fromIntegral (maxBound :: Word32)) * (ma - mi) + mi) v+              where convert (mi,ma,v) = GV.map (\x -> ((fromIntegral x)) / (fromIntegral (maxBound :: Word32)) * (ma - mi) + mi) v  instance Binary (Multichannel (Complex Double)) where     put (MC s p c l de f d) = do@@ -162,7 +164,7 @@                               put f                               put $! fmap ((\(r,j) -> (convert r, convert j)) . fromComplex) d         where convert v = let (mi,ma) = (minElement v,maxElement v)-                              v' = mapVector (\x -> round $ (x - mi)/(ma - mi) * (fromIntegral (maxBound :: Word64))) v+                              v' = GV.map (\x -> round $ (x - mi)/(ma - mi) * (fromIntegral (maxBound :: Word64))) v                           in (mi,ma,v' :: Vector Word64)       get = do@@ -174,7 +176,7 @@           f <- get           (d :: I.Array Int ((Double,Double,Vector Word64),(Double,Double,Vector Word64))) <- get           return $! (MC s p c l de f (seq d (fmap (\(r,j) -> toComplex (convert r,convert j)) d)))-              where convert (mi,ma,v) = mapVector (\x -> ((fromIntegral x)) / (fromIntegral (maxBound :: Word64)) * (ma - mi) + mi) v+              where convert (mi,ma,v) = GV.map (\x -> ((fromIntegral x)) / (fromIntegral (maxBound :: Word64)) * (ma - mi) + mi) v   @@ -188,7 +190,7 @@                               put f                               put $! fmap ((\(r,j) -> (convert r, convert j)) . fromComplex) d         where convert v = let (mi,ma) = (minElement v,maxElement v)-                              v' = mapVector (\x -> round $ (x - mi)/(ma - mi) * (fromIntegral (maxBound :: Word32))) v+                              v' = GV.map (\x -> round $ (x - mi)/(ma - mi) * (fromIntegral (maxBound :: Word32))) v                           in (mi,ma,v' :: Vector Word32)       get = do@@ -200,7 +202,7 @@           f <- get           (d :: I.Array Int ((Float,Float,Vector Word32),(Float,Float,Vector Word32))) <- get           return $! (MC s p c l de f (seq d (fmap (\(r,j) -> toComplex (convert r,convert j)) d)))-              where convert (mi,ma,v) = mapVector (\x -> ((fromIntegral x)) / (fromIntegral (maxBound :: Word32)) * (ma - mi) + mi) v+              where convert (mi,ma,v) = GV.map (\x -> ((fromIntegral x)) / (fromIntegral (maxBound :: Word32)) * (ma - mi) + mi) v   @@ -221,7 +223,7 @@                    -> [Vector a]        -- ^ data                    -> Multichannel a    -- ^ datatype createMultichannel s p d = let c = length d-                 in MC s p c (dim $ head d) False Nothing (I.listArray (1,c) d)+                 in MC s p c (GV.length $ head d) False Nothing (I.listArray (1,c) d)  -- | the sampling rate sampling_rate :: Multichannel a -> Int@@ -291,7 +293,7 @@                 -> Multichannel a              -- ^ input data                 -> Multichannel b              -- ^ output data mapConcurrently f (MC sr p c _ de fi d) = let d' = mapArrayConcurrently f d-                                          in MC sr p c (dim $ d' I.! 1) de fi d'+                                          in MC sr p c (GV.length $ d' I.! 1) de fi d'  -- | map a function mapMC :: Storable b @@ -299,7 +301,7 @@       -> Multichannel a                        -- ^ input data       -> Multichannel b                        -- ^ output data mapMC f (MC sr p c _ de fi d) = let d' = fmap f d-                                in MC sr p c (dim $ d' I.! 1) de fi d'+                                in MC sr p c (GV.length $ d' I.! 1) de fi d'                                      ----------------------------------------------------------------------------- 
lib/Numeric/Signal/Noise.hs view
@@ -6,7 +6,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Numeric.Signal.Noise--- Copyright   :  (c) Alexander Vivian Hugh McPhail 2010, 2014+-- Copyright   :  (c) Alexander Vivian Hugh McPhail 2010, 2014, 2015 -- License     :  BSD3 -- -- Maintainer  :  haskell.vivian.mcphail <at> gmail <dot> com@@ -45,9 +45,9 @@  --import Foreign.Storable +import Numeric.LinearAlgebra -import Numeric.Container-import Numeric.LinearAlgebra()+import qualified Data.Vector.Generic as GV  import qualified Numeric.GSL.Fourier as F @@ -80,14 +80,14 @@                              r = fromIntegral r'                              pre_x = linspace c' (0::Double,c-1)                              post_x = linspace c' (c,1)-                             freq_x = mapVector (/c) $ join [pre_x,post_x]+                             freq_x = GV.map (/c) $ vjoin [pre_x,post_x]                              u = fromRows (replicate (2*r') freq_x)                              pre_y = linspace r' (0::Double,r-1)                              post_y = linspace r' (r,1)-                             freq_y = mapVector (/c) $ join [pre_y,post_y]+                             freq_y = GV.map (/c) $ vjoin [pre_y,post_y]                              v = fromColumns (replicate (2*c') freq_y)-                             s_f = liftMatrix (mapVector (**(b/2))) ((u**2) + (v**2))-                             s_f' = liftMatrix (mapVector (\x -> if isInfinite x then 0 else x)) s_f+                             s_f = cmap (**(b/2)) ((u**2) + (v**2))+                             s_f' = cmap (\x -> if isInfinite x then 0 else x) s_f                              phi = reshape (2*c') (randomVector s Uniform (4*r'*c'))                          in subMatrix (1,1) (r',c') $ fst $ fromComplex $ fromRows $ map F.ifft $ toRows $ ((complex $ s_f'**0.5) * (toComplex (cos(2*pi*phi),sin(2*pi*phi)))) @@ -102,9 +102,9 @@     -> Vector Double  pinkNoise b s r = let pre = linspace s (0::Double,fromIntegral (s-1))                       post = linspace s (fromIntegral s,1)-                      freq = join [pre/(fromIntegral s),post/(fromIntegral s)]-                      s_f = mapVector (**(b/2)) (freq**2) -                      s_f' = mapVector (\x -> if isInfinite x then 0 else x) s_f+                      freq = vjoin [pre/(fromIntegral s),post/(fromIntegral s)]+                      s_f = GV.map (**(b/2)) (freq**2) +                      s_f' = GV.map (\x -> if isInfinite x then 0 else x) s_f                       phi = randomVector r Uniform (2*s)                   in subVector 0 s $ fst $ fromComplex $ F.ifft ((complex $ s_f'**0.5) * (toComplex (cos(2*pi*phi),sin(2*pi*phi)))) @@ -112,7 +112,7 @@ powerNoise :: Vector Double   -- ^ the power spectrum            -> Int             -- ^ random seed            -> Vector Double-powerNoise psd r = let ln = dim psd-                       freq = join [fromList [0],psd, (fromList . reverse . tail . toList) psd]+powerNoise psd r = let ln = GV.length psd+                       freq = vjoin [fromList [0],psd, (fromList . reverse . tail . toList) psd]                        phi = randomVector r Uniform (2*ln)                    in (fromIntegral ln) * (subVector 0 (ln-1) $ fst $ fromComplex $ F.ifft ((complex $ freq) * (toComplex (cos(2*pi*phi),sin(2*pi*phi)))))