emd-0.1.8.1: Empirical Mode Decomposition and Hilbert-Huang Transform

Copyright (c) Justin Le 2018 BSD3 justin@jle.im experimental non-portable None Haskell2010

Numeric.EMD

Description

Empirical Mode Decomposition in pure Haskell.

Main interface is emd, with defaultEO. A tracing version that outputs a log to stdout is also available, as emdTrace. This can be used to help track down a specific IMF that might be taking more time than desired.

This package uses "sized vectors" as its main interface, to ensure:

1. The resulting EMD contains IMFs that are all the same length as the input vector
2. We provide a vector of size of at least one.

There are many functions to convert unsized vectors to sized vectors in Data.Vector.Sized and associated modules, including toSized (for when you know the size at compile-time) and withSized (for when you don't).

Synopsis

# Empirical Mode Decomposition

emd :: (Vector v a, KnownNat n, Fractional a, Ord a) => EMDOpts a -> Vector v (n + 1) a -> EMD v (n + 1) a Source #

EMD decomposition of a given time series with a given sifting stop condition.

Takes a sized vector to ensure that:

1. The resulting EMD contains IMFs that are all the same length as the input vector
2. We provide a vector of size of at least one.

emdTrace :: (Vector v a, KnownNat n, Fractional a, Ord a, MonadIO m) => EMDOpts a -> Vector v (n + 1) a -> m (EMD v (n + 1) a) Source #

emd, but tracing results to stdout as IMFs are found. Useful for debugging to see how long each step is taking.

emd' :: (Vector v a, KnownNat n, Fractional a, Ord a, Applicative m) => (SiftResult v (n + 1) a -> m r) -> EMDOpts a -> Vector v (n + 1) a -> m (EMD v (n + 1) a) Source #

emd with a callback for each found IMF.

iemd :: (Vector v a, Num a) => EMD v n a -> Vector v n a Source #

Collapse an EMD back into its original time series. Should be a left-inverse to emd: using iemd on the result of emd should give back the original vector.

Since: 0.1.5.0

data EMD v n a Source #

An EMD v n a is an Empirical Mode Decomposition of a time series with n items of type a stored in a vector v.

The component-wise sum of emdIMFs and emdResidual should yield exactly the original series (see iemd).

Constructors

 EMD FieldsemdIMFs :: ![Vector v n a] emdResidual :: !(Vector v n a)
Instances
 Eq (v a) => Eq (EMD v n a) Source # Instance detailsDefined in Numeric.EMD Methods(==) :: EMD v n a -> EMD v n a -> Bool #(/=) :: EMD v n a -> EMD v n a -> Bool # Ord (v a) => Ord (EMD v n a) Source # Instance detailsDefined in Numeric.EMD Methodscompare :: EMD v n a -> EMD v n a -> Ordering #(<) :: EMD v n a -> EMD v n a -> Bool #(<=) :: EMD v n a -> EMD v n a -> Bool #(>) :: EMD v n a -> EMD v n a -> Bool #(>=) :: EMD v n a -> EMD v n a -> Bool #max :: EMD v n a -> EMD v n a -> EMD v n a #min :: EMD v n a -> EMD v n a -> EMD v n a # Show (v a) => Show (EMD v n a) Source # Instance detailsDefined in Numeric.EMD MethodsshowsPrec :: Int -> EMD v n a -> ShowS #show :: EMD v n a -> String #showList :: [EMD v n a] -> ShowS # Generic (EMD v n a) Source # Instance detailsDefined in Numeric.EMD Associated Typestype Rep (EMD v n a) :: Type -> Type # Methodsfrom :: EMD v n a -> Rep (EMD v n a) x #to :: Rep (EMD v n a) x -> EMD v n a # (Vector v a, KnownNat n, Binary (v a)) => Binary (EMD v n a) Source # Since: 0.1.3.0 Instance detailsDefined in Numeric.EMD Methodsput :: EMD v n a -> Put #get :: Get (EMD v n a) #putList :: [EMD v n a] -> Put # NFData (v a) => NFData (EMD v n a) Source # Since: 0.1.5.0 Instance detailsDefined in Numeric.EMD Methodsrnf :: EMD v n a -> () # type Rep (EMD v n a) Source # Instance detailsDefined in Numeric.EMD type Rep (EMD v n a) = D1 (MetaData "EMD" "Numeric.EMD" "emd-0.1.8.1-inplace" False) (C1 (MetaCons "EMD" PrefixI True) (S1 (MetaSel (Just "emdIMFs") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 [Vector v n a]) :*: S1 (MetaSel (Just "emdResidual") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Vector v n a))))

data EMDOpts a Source #

Options for EMD composition.

Constructors

 EO FieldseoSiftCondition :: SiftCondition astop condition for siftingeoSplineEnd :: SplineEnd aend conditions for envelope splineseoBoundaryHandler :: Maybe BoundaryHandlerprocess for handling boundary
Instances
 Eq a => Eq (EMDOpts a) Source # Instance detailsDefined in Numeric.EMD Methods(==) :: EMDOpts a -> EMDOpts a -> Bool #(/=) :: EMDOpts a -> EMDOpts a -> Bool # Ord a => Ord (EMDOpts a) Source # Instance detailsDefined in Numeric.EMD Methodscompare :: EMDOpts a -> EMDOpts a -> Ordering #(<) :: EMDOpts a -> EMDOpts a -> Bool #(<=) :: EMDOpts a -> EMDOpts a -> Bool #(>) :: EMDOpts a -> EMDOpts a -> Bool #(>=) :: EMDOpts a -> EMDOpts a -> Bool #max :: EMDOpts a -> EMDOpts a -> EMDOpts a #min :: EMDOpts a -> EMDOpts a -> EMDOpts a # Show a => Show (EMDOpts a) Source # Instance detailsDefined in Numeric.EMD MethodsshowsPrec :: Int -> EMDOpts a -> ShowS #show :: EMDOpts a -> String #showList :: [EMDOpts a] -> ShowS # Source # Instance detailsDefined in Numeric.EMD Associated Typestype Rep (EMDOpts a) :: Type -> Type # Methodsfrom :: EMDOpts a -> Rep (EMDOpts a) x #to :: Rep (EMDOpts a) x -> EMDOpts a # Binary a => Binary (EMDOpts a) Source # Since: 0.1.3.0 Instance detailsDefined in Numeric.EMD Methodsput :: EMDOpts a -> Put #get :: Get (EMDOpts a) #putList :: [EMDOpts a] -> Put # Fractional a => Default (EMDOpts a) Source # Since: 0.1.3.0 Instance detailsDefined in Numeric.EMD Methodsdef :: EMDOpts a # type Rep (EMDOpts a) Source # Instance detailsDefined in Numeric.EMD type Rep (EMDOpts a) = D1 (MetaData "EMDOpts" "Numeric.EMD" "emd-0.1.8.1-inplace" False) (C1 (MetaCons "EO" PrefixI True) (S1 (MetaSel (Just "eoSiftCondition") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (SiftCondition a)) :*: (S1 (MetaSel (Just "eoSplineEnd") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (SplineEnd a)) :*: S1 (MetaSel (Just "eoBoundaryHandler") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe BoundaryHandler)))))

Default EMDOpts

Constructors

 BHClamp Clamp envelope at end points (Matlab implementation) BHSymmetric Extend boundaries symmetrically
Instances
 Source # Instance detailsDefined in Numeric.EMD Methods Source # Instance detailsDefined in Numeric.EMD Methods Source # Instance detailsDefined in Numeric.EMD MethodsshowList :: [BoundaryHandler] -> ShowS # Source # Instance detailsDefined in Numeric.EMD Associated Typestype Rep BoundaryHandler :: Type -> Type # Methods Source # Since: 0.1.3.0 Instance detailsDefined in Numeric.EMD MethodsputList :: [BoundaryHandler] -> Put # Source # Instance detailsDefined in Numeric.EMD type Rep BoundaryHandler = D1 (MetaData "BoundaryHandler" "Numeric.EMD" "emd-0.1.8.1-inplace" False) (C1 (MetaCons "BHClamp" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "BHSymmetric" PrefixI False) (U1 :: Type -> Type))

data SiftCondition a Source #

Stop conditions for sifting process

Data type is lazy in its fields, so this infinite data type:

nTimes n = SCTimes n SCOr nTimes (n + 1)


will be treated identically as:

nTimes = SCTimes


Constructors

 SCStdDev !a Stop using standard SD method SCTimes !Int Stop after a fixed number of sifting iterations SCOr (SiftCondition a) (SiftCondition a) One or the other SCAnd (SiftCondition a) (SiftCondition a) Stop when both conditions are met
Instances
 Eq a => Eq (SiftCondition a) Source # Instance detailsDefined in Numeric.EMD Methods(==) :: SiftCondition a -> SiftCondition a -> Bool #(/=) :: SiftCondition a -> SiftCondition a -> Bool # Ord a => Ord (SiftCondition a) Source # Instance detailsDefined in Numeric.EMD Methods(<) :: SiftCondition a -> SiftCondition a -> Bool #(<=) :: SiftCondition a -> SiftCondition a -> Bool #(>) :: SiftCondition a -> SiftCondition a -> Bool #(>=) :: SiftCondition a -> SiftCondition a -> Bool #max :: SiftCondition a -> SiftCondition a -> SiftCondition a #min :: SiftCondition a -> SiftCondition a -> SiftCondition a # Show a => Show (SiftCondition a) Source # Instance detailsDefined in Numeric.EMD MethodsshowsPrec :: Int -> SiftCondition a -> ShowS #show :: SiftCondition a -> String #showList :: [SiftCondition a] -> ShowS # Source # Instance detailsDefined in Numeric.EMD Associated Typestype Rep (SiftCondition a) :: Type -> Type # Methodsfrom :: SiftCondition a -> Rep (SiftCondition a) x #to :: Rep (SiftCondition a) x -> SiftCondition a # Binary a => Binary (SiftCondition a) Source # Since: 0.1.3.0 Instance detailsDefined in Numeric.EMD Methodsput :: SiftCondition a -> Put #get :: Get (SiftCondition a) #putList :: [SiftCondition a] -> Put # Source # Since: 0.1.3.0 Instance detailsDefined in Numeric.EMD Methods type Rep (SiftCondition a) Source # Instance detailsDefined in Numeric.EMD type Rep (SiftCondition a) = D1 (MetaData "SiftCondition" "Numeric.EMD" "emd-0.1.8.1-inplace" False) ((C1 (MetaCons "SCStdDev" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a)) :+: C1 (MetaCons "SCTimes" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int))) :+: (C1 (MetaCons "SCOr" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (SiftCondition a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (SiftCondition a))) :+: C1 (MetaCons "SCAnd" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (SiftCondition a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (SiftCondition a)))))

Default SiftCondition

data SplineEnd a Source #

End condition for spline

Constructors

 SENotAKnot "Not-a-knot" condition: third derivatives are continuous at endpoints. Default for matlab spline. SENatural "Natural" condition: curve becomes a straight line at endpoints. SEClamped a a "Clamped" condition: Slope of curves at endpoints are explicitly given.Since: 0.1.2.0
Instances
 Eq a => Eq (SplineEnd a) Source # Instance detailsDefined in Numeric.EMD.Internal.Spline Methods(==) :: SplineEnd a -> SplineEnd a -> Bool #(/=) :: SplineEnd a -> SplineEnd a -> Bool # Ord a => Ord (SplineEnd a) Source # Instance detailsDefined in Numeric.EMD.Internal.Spline Methodscompare :: SplineEnd a -> SplineEnd a -> Ordering #(<) :: SplineEnd a -> SplineEnd a -> Bool #(<=) :: SplineEnd a -> SplineEnd a -> Bool #(>) :: SplineEnd a -> SplineEnd a -> Bool #(>=) :: SplineEnd a -> SplineEnd a -> Bool #max :: SplineEnd a -> SplineEnd a -> SplineEnd a #min :: SplineEnd a -> SplineEnd a -> SplineEnd a # Show a => Show (SplineEnd a) Source # Instance detailsDefined in Numeric.EMD.Internal.Spline MethodsshowsPrec :: Int -> SplineEnd a -> ShowS #show :: SplineEnd a -> String #showList :: [SplineEnd a] -> ShowS # Source # Instance detailsDefined in Numeric.EMD.Internal.Spline Associated Typestype Rep (SplineEnd a) :: Type -> Type # Methodsfrom :: SplineEnd a -> Rep (SplineEnd a) x #to :: Rep (SplineEnd a) x -> SplineEnd a # Binary a => Binary (SplineEnd a) Source # Since: 0.1.3.0 Instance detailsDefined in Numeric.EMD.Internal.Spline Methodsput :: SplineEnd a -> Put #get :: Get (SplineEnd a) #putList :: [SplineEnd a] -> Put # type Rep (SplineEnd a) Source # Instance detailsDefined in Numeric.EMD.Internal.Spline type Rep (SplineEnd a) = D1 (MetaData "SplineEnd" "Numeric.EMD.Internal.Spline" "emd-0.1.8.1-inplace" False) (C1 (MetaCons "SENotAKnot" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "SENatural" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "SEClamped" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))))

# Internal

sift :: (Vector v a, KnownNat n, Fractional a, Ord a) => EMDOpts a -> Vector v (n + 1) a -> SiftResult v (n + 1) a Source #

Iterated sifting process, used to produce either an IMF or a residual.

data SiftResult v n a Source #

The result of a sifting operation. Each sift either yields a residual, or a new IMF.

Constructors

 SRResidual !(Vector v n a) SRIMF !(Vector v n a) !Int number of sifting iterations

envelopes :: (Vector v a, KnownNat n, Fractional a, Ord a) => SplineEnd a -> Maybe BoundaryHandler -> Vector v (n + 1) a -> Maybe (Vector v (n + 1) a, Vector v (n + 1) a) Source #

Returns cubic splines of local minimums and maximums. Returns Nothing if there are not enough local minimum or maximums to create the splines.