packages feed

hsignal 0.1.0.4 → 0.1.0.5

raw patch · 4 files changed

+71/−34 lines, 4 filesdep +ghc-binary

Dependencies added: ghc-binary

Files

CHANGES view
@@ -9,3 +9,6 @@  0.1.0.4: 		added Numeric.Signal.EEG++0.1.0.5:+		fixed stack overflow in loadBDF by making [Double] -> Vector Double step strict
hsignal.cabal view
@@ -1,8 +1,8 @@ Name:               hsignal-Version:            0.1.0.4+Version:            0.1.0.5 License:            GPL License-file:       LICENSE-Author:             Alexander Vivian Hugh McPhail+Author:             Vivian McPhail Maintainer:         haskell.vivian.mcphail <at> gmail <dot> com Stability:          provisional Homepage:           http://code.haskell.org/hsignal@@ -26,7 +26,8 @@                         storable-complex, haskell98, mtl, bytestring,                         hmatrix >= 0.9.3,                         hstatistics >= 0.1.0.5,-                        array+                        array,+                        ghc-binary      Extensions:         ForeignFunctionInterface 
lib/Numeric/Signal/EEG/BDF.hs view
@@ -108,28 +108,28 @@           deriving(Eq,Ord,Show)
 
 data BDF = BDF {
-                id_ :: Word8
-                , type_ :: String
-                , subject :: String
-                , recording :: String
-                , date :: Date
-                , time :: Time
-                , head_bytes :: Int
-                , data_version :: String
-                , num_records :: Int
-                , duration :: Int
-                , channels :: Int
-                , chan_labels :: [String]
-                , tran_type :: [String]
-                , dimensions :: [String]
-                , phys_min :: [Int]
-                , phys_max :: [Int]
-                , dig_min :: [Int]
-                , dig_max :: [Int]
-                , prefilter :: [String]
-                , samples :: [Int]
-                , reserved :: [String]
-                , data_ :: [Vector Double]
+                id_ :: !Word8
+                , type_ :: !String
+                , subject :: !String
+                , recording :: !String
+                , date :: !Date
+                , time :: !Time
+                , head_bytes :: !Int
+                , data_version :: !String
+                , num_records :: !Int
+                , duration :: !Int
+                , channels :: !Int
+                , chan_labels :: ![String]
+                , tran_type :: ![String]
+                , dimensions :: ![String]
+                , phys_min :: ![Int]
+                , phys_max :: ![Int]
+                , dig_min :: ![Int]
+                , dig_max :: ![Int]
+                , prefilter :: ![String]
+                , samples :: ![Int]
+                , reserved :: ![String]
+                , data_ :: ![Vector Double]
                } --deriving(Show)
 
 getString :: Int -> BSM String
@@ -164,7 +164,7 @@ --reverseBits w = foldl setBit 0 . foldl ((++) . \b -> if testBit w b then [9-b] else []) [] [1..8]
 reverseBits w = foldr (\b r -> if not $ testBit w b then setBit r (7-b) else r) 0 [0..7]
 
---get24Bit :: BSM Word32
+get24Bit :: (Int -> Double) -> BSM Double
 get24Bit f = do
              b1 <- getN 1
              b2 <- getN 1
@@ -173,24 +173,30 @@              return $ f $ (to32 b3) `shiftL` 16 .|. (to32 b2) `shiftL` 8 .|. (to32 b1)
     where to32 = fromIntegral {- . reverseBits -} . BS.head
 
---readRecord :: Int -> BSM [Word32]
+readRecord :: (Int -> Double) -> Int -> BSM (Vector Double)
 readRecord f s = do
                  m <- replicateM s $ get24Bit f
-                 return $ fromList m
---readRecordBlock :: [(Int,Int)] -> BSM [[Word32]]
+                 return $! fromList m
+
+readRecordBlock :: (Int -> Int -> Double) -> [(Int,Int)] -> BSM [Vector Double]
 readRecordBlock f ss = mapM (\(i,s) -> readRecord (f i) s) ss
 
 convert :: [Int] -> [Int] -> [Int] -> [Int] -> Int -> Int -> Double
 convert p_min p_max d_min d_max i = \x -> (fromIntegral x) - (fromIntegral (d_min !! i))*(fromIntegral ((p_max !! i) - (p_min !! i)))/(fromIntegral ((d_max !! i) - (d_min !! i)))
 
---readData :: Int -> [Int] -> BSM [[Word32]]
+readData :: (Int -> Int -> Double) -> Int -> [(Int,Int)] -> BSM [Vector Double]
 readData _ 0     _  = error "readData, zeroth record requested"
-readData f 1     ss = readRecordBlock f ss
+readData f 1     ss = do
+                      lift $ putStrLn $ "data record: 1"
+                      readRecordBlock f ss
 readData f (n+1) ss = do
+                      lift $ putStrLn $ "data record: " ++ show (n+1)
                       bs <- readRecordBlock f ss
                       ds <- readData f n ss
-                      return $ zipWith (\x y -> join [x,y]) bs ds
+                      let result = zipWith (\x y -> join [x,y]) bs ds
+                      return $ result
 
+
 readBDF :: BSM (Maybe BDF)
 readBDF = do
           id_' <- getN 1
@@ -227,7 +233,7 @@                             prefilter' <- replicateM channels' $ getString 80
                             samples' <- replicateM channels' $ getInt 8
                             reserved' <- replicateM channels' $ getString 32
-                            data_' <- readData (convert phys_min' phys_max' dig_min' dig_max') num_records' (zip [1..] samples')
+                            data_' <- readData (convert phys_min' phys_max' dig_min' dig_max') num_records' (zip [0..] samples')
                             return $ Just $ BDF {
                                                  id_ = BS.head id_'
                                                  , type_ = type_'
lib/Numeric/Signal/Multichannel.hs view
@@ -16,7 +16,7 @@ -----------------------------------------------------------------------------  module Numeric.Signal.Multichannel (-                       Multichannel,+                       Multichannel,readMultichannel,writeMultichannel,                        fromList,                        sampling_rate,precision,channels,                        getChannel,getChannels,@@ -41,6 +41,8 @@ import Data.Packed.Vector hiding(fromList) --import Data.Packed(Container(..)) +import Data.Binary+ import Foreign.Storable --import Numeric.GSL.Vector @@ -60,6 +62,31 @@                           , _length      :: Int -- ^ length in samples                           , _data        :: I.Array Int (Vector a) -- ^ data                          }++-----------------------------------------------------------------------------++instance Binary (Multichannel Double) where+    put (MC s p c l d) = do+                         put s+                         put p+                         put c+                         put l+                         put d+    get = do+          s <- get+          p <- get+          c <- get+          l <- get+          d <- get+          return (MC s p c l d)++-----------------------------------------------------------------------------++readMultichannel :: FilePath -> IO (Multichannel Double)+readMultichannel = decodeFile++writeMultichannel :: FilePath -> Multichannel Double -> IO ()+writeMultichannel = encodeFile  -----------------------------------------------------------------------------