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

Copyright(c) Justin Le 2019
LicenseBSD3
Maintainerjustin@jle.im
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Numeric.EMD

Contents

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, Floating a, Ord a) => EMDOpts v (n + 1) 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, Floating a, Ord a, MonadIO m) => EMDOpts v (n + 1) 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, Floating a, Ord a, Applicative m) => (SiftResult v (n + 1) a -> m r) -> EMDOpts v (n + 1) 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 

Fields

Instances
Eq (v a) => Eq (EMD v n a) Source # 
Instance details

Defined 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 details

Defined in Numeric.EMD

Methods

compare :: 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 details

Defined in Numeric.EMD

Methods

showsPrec :: 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 details

Defined in Numeric.EMD

Associated Types

type Rep (EMD v n a) :: Type -> Type #

Methods

from :: 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 details

Defined in Numeric.EMD

Methods

put :: 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 details

Defined in Numeric.EMD

Methods

rnf :: EMD v n a -> () #

type Rep (EMD v n a) Source # 
Instance details

Defined in Numeric.EMD

type Rep (EMD v n a) = D1 (MetaData "EMD" "Numeric.EMD" "emd-0.2.0.0-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))))

Configuration

data EMDOpts v n a Source #

Options for EMD composition.

Constructors

EO 

Fields

Instances
Generic (EMDOpts v n a) Source # 
Instance details

Defined in Numeric.EMD.Internal

Associated Types

type Rep (EMDOpts v n a) :: Type -> Type #

Methods

from :: EMDOpts v n a -> Rep (EMDOpts v n a) x #

to :: Rep (EMDOpts v n a) x -> EMDOpts v n a #

(Vector v a, Fractional a, Ord a) => Default (EMDOpts v n a) Source #

Since: 0.1.3.0

Instance details

Defined in Numeric.EMD

Methods

def :: EMDOpts v n a #

type Rep (EMDOpts v n a) Source # 
Instance details

Defined in Numeric.EMD.Internal

type Rep (EMDOpts v n a) = D1 (MetaData "EMDOpts" "Numeric.EMD.Internal" "emd-0.2.0.0-inplace" False) (C1 (MetaCons "EO" PrefixI True) (S1 (MetaSel (Just "eoSifter") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Sifter v n a)) :*: (S1 (MetaSel (Just "eoSplineEnd") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (SplineEnd a)) :*: S1 (MetaSel (Just "eoBoundaryHandler") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe BoundaryHandler)))))

defaultEO :: (Vector v a, Fractional a, Ord a) => EMDOpts v n a Source #

Default EMDOpts

Note: If you immediately use this and set eoSifter, then v will be ambiguous. Explicitly set v with type applications to appease GHC

defaultEO @(Data.Vector.Vector)
   { eoSifter = scTimes 100
   }

data BoundaryHandler Source #

Boundary conditions for splines.

Constructors

BHClamp

Clamp envelope at end points (Matlab implementation)

BHSymmetric

Extend boundaries symmetrically

Instances
Eq BoundaryHandler Source # 
Instance details

Defined in Numeric.EMD.Internal

Ord BoundaryHandler Source # 
Instance details

Defined in Numeric.EMD.Internal

Show BoundaryHandler Source # 
Instance details

Defined in Numeric.EMD.Internal

Generic BoundaryHandler Source # 
Instance details

Defined in Numeric.EMD.Internal

Associated Types

type Rep BoundaryHandler :: Type -> Type #

Binary BoundaryHandler Source #

Since: 0.1.3.0

Instance details

Defined in Numeric.EMD.Internal

type Rep BoundaryHandler Source # 
Instance details

Defined in Numeric.EMD.Internal

type Rep BoundaryHandler = D1 (MetaData "BoundaryHandler" "Numeric.EMD.Internal" "emd-0.2.0.0-inplace" False) (C1 (MetaCons "BHClamp" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "BHSymmetric" PrefixI False) (U1 :: Type -> Type))

data Sifter v n a Source #

A sift stopping condition.

It is a Pipe consumer that takes single sift step results upstream and terminates with '()' as soon as it is satisfied with the latest sift step.

Use combinators like siftOr and siftAnd to combine sifters, and the various sifters in Numeric.EMD.Sift to create sifters from commonly established ones or new ones from scratch.

Since: 0.2.0.0

Instances
(Vector v a, Fractional a, Ord a) => Default (Sifter v n a) Source #

Since: 0.1.3.0

Instance details

Defined in Numeric.EMD.Sift

Methods

def :: Sifter v n a #

defaultSifter :: (Vector v a, Fractional a, Ord a) => Sifter v n a Source #

Default Sifter

defaultSifter = siftStdDev 0.3 siftOr siftTimes 50

R package uses siftTimes 20, Matlab uses no limit

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 details

Defined in Numeric.EMD.Internal.Spline

Methods

(==) :: SplineEnd a -> SplineEnd a -> Bool #

(/=) :: SplineEnd a -> SplineEnd a -> Bool #

Ord a => Ord (SplineEnd a) Source # 
Instance details

Defined in Numeric.EMD.Internal.Spline

Show a => Show (SplineEnd a) Source # 
Instance details

Defined in Numeric.EMD.Internal.Spline

Generic (SplineEnd a) Source # 
Instance details

Defined in Numeric.EMD.Internal.Spline

Associated Types

type Rep (SplineEnd a) :: Type -> Type #

Methods

from :: 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 details

Defined in Numeric.EMD.Internal.Spline

Methods

put :: SplineEnd a -> Put #

get :: Get (SplineEnd a) #

putList :: [SplineEnd a] -> Put #

type Rep (SplineEnd a) Source # 
Instance details

Defined in Numeric.EMD.Internal.Spline

type Rep (SplineEnd a) = D1 (MetaData "SplineEnd" "Numeric.EMD.Internal.Spline" "emd-0.2.0.0-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 :: forall v n a. (Vector v a, KnownNat n, Floating a, Ord a) => EMDOpts v (n + 1) 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.

Orphan instances

(Vector v a, Fractional a, Ord a) => Default (EMDOpts v n a) Source #

Since: 0.1.3.0

Instance details

Methods

def :: EMDOpts v n a #