Wavelet Transform

Extend data

This function should be used in dwt() and uwt() to extend the length of data to power of two. cwt() use it as internal function.

mlpy.extend(x, method='reflection', length='powerof2')

Extend the 1D numpy array x beyond its original length.

Input

  • x - [1D numpy array] data
  • method - [string] indicates which extension method to use (‘reflection’, ‘periodic’, ‘zeros’)
  • length - [string] indicates how to determinate the length of the extended data (‘powerof2’, ‘double’)

Output

  • xext - [1D numpy array] extended version of x

Example

>>> import numpy as np
>>> import mlpy
>>> a = np.array([1,2,3,4,5])
>>> mlpy.extend(a, method='periodic', length='powerof2')
array([1, 2, 3, 4, 5, 1, 2, 3])    

New in version 2.0.6.

Discrete Wavelet Transform

Discrete Wavelet Transform based on the GSL DWT [Gsldwt].

mlpy.dwt(x, wf, k)

Discrete Wavelet Tranform

Input

  • x - [1D numpy array float] data (the length is restricted to powers of two)
  • wf - [string] wavelet type (‘d’: daubechies, ‘h’: haar, ‘b’: bspline)
  • k - [integer] member of the wavelet family
    • daubechies: k = 4, 6, ..., 20 with k even
    • haar: the only valid choice of k is k = 2
    • bspline: k = 103, 105, 202, 204, 206, 208, 301, 303, 305 307, 309

Output

  • X - [1D numpy array float] discrete wavelet transform
mlpy.idwt(X, wf, k)

Inverse Discrete Wavelet Tranform

Input

  • X - [1D numpy array float] data
  • wf - [string] wavelet type (‘d’: daubechies, ‘h’: haar, ‘b’: bspline)
  • k - [integer] member of the wavelet family
    • daubechies: k = 4, 6, ..., 20 with k even
    • haar: the only valid choice of k is k = 2
    • bspline: k = 103, 105, 202, 204, 206, 208, 301, 303, 305 307, 309

Output

  • x - [1D numpy array float]

Undecimated Wavelet Transform

Undecimated Wavelet Transform based on the “wavelets” R package.

mlpy.uwt(x, wf, k, levels=0)

Undecimated Wavelet Tranform

Input

  • x - [1D numpy array float] data (the length is restricted to powers of two)

  • wf - [string] wavelet type (‘d’: daubechies, ‘h’: haar, ‘b’: bspline)

  • k - [integer] member of the wavelet family

    • daubechies: k = 4, 6, ..., 20 with k even
    • haar: the only valid choice of k is k = 2
    • bspline: k = 103, 105, 202, 204, 206, 208, 301, 303, 305 307, 309
  • levels - [integer] level of the decomposition (J).

    If levels = 0 this is the value J such that the length of X is at least as great as the length of the level J wavelet filter, but less than the length of the level J+1 wavelet filter. Thus, j <= log_2((n-1)/(l-1)+1), where n is the length of x

Output

  • X - [2D numpy array float] (2J * len(x)) undecimated wavelet transform

    Data:

    [[wavelet coefficients W_1]
     [wavelet coefficients W_2]
                   :
     [wavelet coefficients W_J]
     [scaling coefficients V_1]
     [scaling coefficients V_2]
                  :
     [scaling coefficients V_J]]
mlpy.iuwt(X, wf, k)

Inverse Undecimated Wavelet Tranform

Input

  • X - [2D numpy array float] data
  • wf - [string] wavelet type (‘d’: daubechies, ‘h’: haar, ‘b’: bspline)
  • k - [integer] member of the wavelet family
    • daubechies: k = 4, 6, ..., 20 with k even
    • haar: the only valid choice of k is k = 2
    • bspline: k = 103, 105, 202, 204, 206, 208, 301, 303, 305 307, 309

Output

  • x - [1D numpy array float]

New in version 2.0.2.

Continuous Wavelet Transform

Continuous Wavelet Transform based on [Torrence98].

mlpy.cwt(x, dt, dj, wf='dog', p=2, extmethod='none', extlength='powerof2')

Continuous Wavelet Tranform.

Input

  • x - [1D numpy array float] data
  • dt - [float] time step
  • dj - [float] scale resolution (smaller values of dj give finer resolution)
  • wf - [string] wavelet function (‘morlet’, ‘paul’, ‘dog’)
  • p - [float] wavelet function parameter
  • extmethod - [string] indicates which extension method to use (‘none’, ‘reflection’, ‘periodic’, ‘zeros’)
  • extlength - [string] indicates how to determinate the length of the extended data (‘powerof2’, ‘double’)

Output

  • X, scales - (scales x angularfreq) [2D numpy array complex], scales [1D numpy array float]
mlpy.icwt(X, dt, dj, wf='dog', p=2, recf=True)

Inverse Continuous Wavelet Tranform.

Input

  • X - (scales x angularfreq) [2D numpy array complex]

  • dt - [float] time step

  • dj - [float] scale resolution (smaller values of dt give finer resolution)

  • wf - [string] wavelet function (‘morlet’, ‘paul’, ‘dog’)

  • p - [int] wavelet function parameter

    • morlet: 2, 4, 6
    • paul: 2, 4, 6
    • dog: 2, 6, 10
  • recf - [bool] use the reconstruction factor (Cdelta*psi_0(0))

Output

  • x - [1D numpy array float]

Other functions

See [Torrence98].

mlpy.angularfreq(N, dt)

Compute angular frequencies.

Input

  • N - [integer] number of data samples
  • dt - [float] time step

Output

  • angular frequencies - [1D numpy array float]
mlpy.scales(N, dj, dt, s0)

Compute scales.

Input

  • N - [integer] number of data samples
  • dj - [float] scale resolution
  • dt - [float] time step

Output

  • scales - [1D numpy array float]
mlpy.compute_s0(dt, p, wf)

Compute s0.

Input

  • dt - [float] time step
  • p - [float] omega0 (‘morlet’) or order (‘paul’, ‘dog’)
  • wf - [string] wavelet function (‘morlet’, ‘paul’, ‘dog’)

Output

  • s0 - [float]
[Torrence98](1, 2) C Torrence and G P Compo. Practical Guide to Wavelet Analysis
[Gsldwt]Gnu Scientific Library, http://www.gnu.org/software/gsl/

Table Of Contents

Previous topic

Tutorial

Next topic

Imputing

This Page