Wavelets¶
Wavelet families()
¶

pywt.
families
(short=True)¶ Returns a list of available builtin wavelet families.
Currently the builtin families are:
 Haar (
haar
)  Daubechies (
db
)  Symlets (
sym
)  Coiflets (
coif
)  Biorthogonal (
bior
)  Reverse biorthogonal (
rbio
)  “Discrete” FIR approximation of Meyer wavelet (
dmey
)  Gaussian wavelets (
gaus
)  Mexican hat wavelet (
mexh
)  Morlet wavelet (
morl
)  Complex Gaussian wavelets (
cgau
)  Shannon wavelets (
shan
)  Frequency BSpline wavelets (
fbsp
)  Complex Morlet wavelets (
cmor
)
Parameters:  short : bool, optional
Use short names (default: True).
Returns:  families : list
List of available wavelet families.
Examples
>>> import pywt >>> pywt.families() ['haar', 'db', 'sym', 'coif', 'bior', 'rbio', 'dmey', 'gaus', 'mexh', 'morl', 'cgau', 'shan', 'fbsp', 'cmor'] >>> pywt.families(short=False) ['Haar', 'Daubechies', 'Symlets', 'Coiflets', 'Biorthogonal', 'Reverse biorthogonal', 'Discrete Meyer (FIR Approximation)', 'Gaussian', 'Mexican hat wavelet', 'Morlet wavelet', 'Complex Gaussian wavelets', 'Shannon wavelets', 'Frequency BSpline wavelets', 'Complex Morlet wavelets']
 Haar (
Builtin wavelets  wavelist()
¶

pywt.
wavelist
(family=None, kind='all')¶ Returns list of available wavelet names for the given family name.
Parameters:  family : str, optional
Short family name. If the family name is None (default) then names of all the builtin wavelets are returned. Otherwise the function returns names of wavelets that belong to the given family. Valid names are:
'haar', 'db', 'sym', 'coif', 'bior', 'rbio', 'dmey', 'gaus', 'mexh', 'morl', 'cgau', 'shan', 'fbsp', 'cmor'
 kind : {‘all’, ‘continuous’, ‘discrete’}, optional
Whether to return only wavelet names of discrete or continuous wavelets, or all wavelets. Default is
'all'
. Ignored iffamily
is specified.
Returns:  wavelist : list of str
List of available wavelet names.
Examples
>>> import pywt >>> pywt.wavelist('coif') ['coif1', 'coif2', 'coif3', 'coif4', 'coif5', 'coif6', 'coif7', ... >>> pywt.wavelist(kind='continuous') ['cgau1', 'cgau2', 'cgau3', 'cgau4', 'cgau5', 'cgau6', 'cgau7', ...
Custom discrete wavelets are also supported through the
Wavelet
object constructor as described below.
Wavelet
object¶

class
pywt.
Wavelet
(name[, filter_bank=None])¶ Describes properties of a discrete wavelet identified by the specified wavelet
name
. For continuous wavelets seepywt.ContinuousWavelet
instead. In order to use a builtin wavelet thename
parameter must be a valid wavelet name from thepywt.wavelist()
list.Custom Wavelet objects can be created by passing a userdefined filters set with the
filter_bank
parameter.Parameters:  name – Wavelet name
 filter_bank – Use a user supplied filter bank instead of a builtin
Wavelet
.
The filter bank object can be a list of four filters coefficients or an object with
filter_bank
attribute, which returns a list of such filters in the following order:[dec_lo, dec_hi, rec_lo, rec_hi]
Wavelet objects can also be used as a base filter banks. See section on using custom wavelets for more information.
Example:
>>> import pywt >>> wavelet = pywt.Wavelet('db1')

name
¶ Wavelet name.

short_name
¶ Short wavelet name.

dec_lo
¶ Decomposition filter values.

dec_hi
¶ Decomposition filter values.

rec_lo
¶ Reconstruction filter values.

rec_hi
¶ Reconstruction filter values.

dec_len
¶ Decomposition filter length.

rec_len
¶ Reconstruction filter length.

filter_bank
¶ Returns filters list for the current wavelet in the following order:
[dec_lo, dec_hi, rec_lo, rec_hi]

inverse_filter_bank
¶ Returns list of reverse wavelet filters coefficients. The mapping from the
filter_coeffs
list is as follows:[rec_lo[::1], rec_hi[::1], dec_lo[::1], dec_hi[::1]]

short_family_name
¶ Wavelet short family name

family_name
¶ Wavelet family name

orthogonal
¶ Set if wavelet is orthogonal

biorthogonal
¶ Set if wavelet is biorthogonal

symmetry
¶ asymmetric
,near symmetric
,symmetric

vanishing_moments_psi
¶ Number of vanishing moments for the wavelet function

vanishing_moments_phi
¶ Number of vanishing moments for the scaling function
Example:
>>> def format_array(arr): ... return "[%s]" % ", ".join(["%.14f" % x for x in arr]) >>> import pywt >>> wavelet = pywt.Wavelet('db1') >>> print(wavelet) Wavelet db1 Family name: Daubechies Short name: db Filters length: 2 Orthogonal: True Biorthogonal: True Symmetry: asymmetric DWT: True CWT: False >>> print(format_array(wavelet.dec_lo), format_array(wavelet.dec_hi)) [0.70710678118655, 0.70710678118655] [0.70710678118655, 0.70710678118655] >>> print(format_array(wavelet.rec_lo), format_array(wavelet.rec_hi)) [0.70710678118655, 0.70710678118655] [0.70710678118655, 0.70710678118655]
Approximating wavelet and scaling functions  Wavelet.wavefun()
¶

Wavelet.
wavefun
(level)¶ Changed in version 0.2: The time (space) localisation of approximation function points was added.
The
wavefun()
method can be used to calculate approximations of scaling function (phi
) and wavelet function (psi
) at the given level of refinement.For
orthogonal
wavelets returns approximations of scaling function and wavelet function with corresponding xgrid coordinates:[phi, psi, x] = wavelet.wavefun(level)
Example:
>>> import pywt >>> wavelet = pywt.Wavelet('db2') >>> phi, psi, x = wavelet.wavefun(level=5)
For other (
biorthogonal
but notorthogonal
) wavelets returns approximations of scaling and wavelet function both for decomposition and reconstruction and corresponding xgrid coordinates:[phi_d, psi_d, phi_r, psi_r, x] = wavelet.wavefun(level)
Example:
>>> import pywt >>> wavelet = pywt.Wavelet('bior3.5') >>> phi_d, psi_d, phi_r, psi_r, x = wavelet.wavefun(level=5)
See also
You can find live examples of
wavefun()
usage and images of all the builtin wavelets on the Wavelet Properties Browser page. However, this website is no longer actively maintained and does not include every wavelet present in PyWavelets. The precision of the wavelet coefficients at that site is also lower than those included in PyWavelets.
Using custom wavelets¶
PyWavelets comes with a long list
of the most popular
wavelets builtin and ready to use. If you need to use a specific wavelet which
is not included in the list it is very easy to do so. Just pass a list of four
filters or an object with a filter_bank
attribute as a
filter_bank
argument to the Wavelet
constructor.
The filters list, either in a form of a simple Python list or returned via
the filter_bank
attribute, must be in the following order:
 lowpass decomposition filter
 highpass decomposition filter
 lowpass reconstruction filter
 highpass reconstruction filter
just as for the filter_bank
attribute of the
Wavelet
class.
The Wavelet object created in this way is a standard Wavelet
instance.
The following example illustrates the way of creating custom Wavelet objects from plain Python lists of filter coefficients and a filter banklike object.
Example:
>>> import pywt, math >>> c = math.sqrt(2)/2 >>> dec_lo, dec_hi, rec_lo, rec_hi = [c, c], [c, c], [c, c], [c, c] >>> filter_bank = [dec_lo, dec_hi, rec_lo, rec_hi] >>> myWavelet = pywt.Wavelet(name="myHaarWavelet", filter_bank=filter_bank) >>> >>> class HaarFilterBank(object): ... @property ... def filter_bank(self): ... c = math.sqrt(2)/2 ... dec_lo, dec_hi, rec_lo, rec_hi = [c, c], [c, c], [c, c], [c, c] ... return [dec_lo, dec_hi, rec_lo, rec_hi] >>> filter_bank = HaarFilterBank() >>> myOtherWavelet = pywt.Wavelet(name="myHaarWavelet", filter_bank=filter_bank)
ContinuousWavelet
object¶

class
pywt.
ContinuousWavelet
(name, dtype=np.float64)¶ Describes properties of a continuous wavelet identified by the specified wavelet
name
. In order to use a builtin wavelet thename
parameter must be a valid wavelet name from thepywt.wavelist()
list.Parameters:  name – Wavelet name
 dtype – numpy.dtype to use for the wavelet. Can be numpy.float64 or numpy.float32.
Example:
>>> import pywt >>> wavelet = pywt.ContinuousWavelet('gaus1')

name
¶ Continuous Wavelet name.

short_family_name
¶ Wavelet short family name

family_name
¶ Wavelet family name

orthogonal
¶ Set if wavelet is orthogonal

biorthogonal
¶ Set if wavelet is biorthogonal

complex_cwt
¶ Returns if wavelet is complex

lower_bound
¶ Set the lower bound of the effective support

upper_bound
¶ Set the upper bound of the effective support

center_frequency
¶ Set the center frequency for the shan, fbsp and cmor wavelets

bandwidth_frequency
¶ Set the bandwidth frequency for the shan, fbsp and cmor wavelets

fbsp_order
¶ Set the order for the fbsp wavelet

symmetry
¶ asymmetric
,near symmetric
,symmetric
,antisymmetric
Example:
>>> import pywt >>> wavelet = pywt.ContinuousWavelet('gaus1') >>> print(wavelet) ContinuousWavelet gaus1 Family name: Gaussian Short name: gaus Symmetry: antisymmetric DWT: False CWT: True Complex CWT: False
Approximating wavelet functions  ContinuousWavelet.wavefun()
¶

ContinuousWavelet.
wavefun
(level, length = None)¶ The
wavefun()
method can be used to calculate approximations of scaling function (psi
) with grid (x
). The vector length is set bylength
. The vector length can also be defined by2**level
iflength
is not set.For
complex_cwt
wavelets returns a complex approximations of wavelet function with corresponding xgrid coordinates:[psi, x] = wavelet.wavefun(level)
Example:
>>> import pywt >>> wavelet = pywt.ContinuousWavelet('gaus1') >>> psi, x = wavelet.wavefun(level=5)
Approximating wavelet functions  ContinuousWavelet.wavefun()
¶

pywt.
DiscreteContinuousWavelet
(name[, filter_bank = None])¶  The
DiscreteContinuousWavelet()
returns a  Wavelet or a ContinuousWavelet object depending on the given name.
Example:
>>> import pywt >>> wavelet = pywt.DiscreteContinuousWavelet('db1') >>> print(wavelet) Wavelet db1 Family name: Daubechies Short name: db Filters length: 2 Orthogonal: True Biorthogonal: True Symmetry: asymmetric DWT: True CWT: False >>> wavelet = pywt.DiscreteContinuousWavelet('gaus1') >>> print(wavelet) ContinuousWavelet gaus1 Family name: Gaussian Short name: gaus Symmetry: antisymmetric DWT: False CWT: True Complex CWT: False
 The