1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
|
.. _ref-wavelets:
.. currentmodule:: pywt
========
Wavelets
========
Wavelet ``families()``
----------------------
.. autofunction:: families
Built-in wavelets - ``wavelist()``
----------------------------------
.. autofunction:: wavelist
Custom discrete wavelets are also supported through the
:class:`Wavelet` object constructor as described below.
``Wavelet`` object
------------------
.. class:: Wavelet(name[, filter_bank=None])
Describes properties of a discrete wavelet identified by the specified
wavelet ``name``. For continuous wavelets see :class:`pywt.ContinuousWavelet`
instead. In order to use a built-in wavelet the ``name`` parameter must be a
valid wavelet name from the :func:`pywt.wavelist` list.
Custom Wavelet objects can be created by passing a user-defined filters set
with the ``filter_bank`` parameter.
:param name: Wavelet name
:param filter_bank: Use a user supplied filter bank instead of a built-in :class:`Wavelet`.
The filter bank object can be a list of four filters coefficients or an object
with :attr:`~Wavelet.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
:ref:`using custom wavelets <custom-wavelets>` for more information.
**Example:**
.. sourcecode:: python
>>> import pywt
>>> wavelet = pywt.Wavelet('db1')
.. attribute:: name
Wavelet name.
.. attribute:: short_name
Short wavelet name.
.. attribute:: dec_lo
Decomposition filter values.
.. attribute:: dec_hi
Decomposition filter values.
.. attribute:: rec_lo
Reconstruction filter values.
.. attribute:: rec_hi
Reconstruction filter values.
.. attribute:: dec_len
Decomposition filter length.
.. attribute:: rec_len
Reconstruction filter length.
.. attribute:: filter_bank
Returns filters list for the current wavelet in the following order::
[dec_lo, dec_hi, rec_lo, rec_hi]
.. attribute:: 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]]
.. attribute:: short_family_name
Wavelet short family name
.. attribute:: family_name
Wavelet family name
.. attribute:: orthogonal
Set if wavelet is orthogonal
.. attribute:: biorthogonal
Set if wavelet is biorthogonal
.. attribute:: symmetry
``asymmetric``, ``near symmetric``, ``symmetric``
.. attribute:: vanishing_moments_psi
Number of vanishing moments for the wavelet function
.. attribute:: vanishing_moments_phi
Number of vanishing moments for the scaling function
**Example:**
.. sourcecode:: python
>>> 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()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. method:: Wavelet.wavefun(level)
.. versionchanged:: 0.2
The time (space) localisation of approximation function points was
added.
The :meth:`~Wavelet.wavefun` method can be used to calculate approximations of
scaling function (``phi``) and wavelet function (``psi``) at the given level
of refinement.
For :attr:`orthogonal <Wavelet.orthogonal>` wavelets returns approximations of
scaling function and wavelet function with corresponding x-grid coordinates::
[phi, psi, x] = wavelet.wavefun(level)
**Example:**
.. sourcecode:: python
>>> import pywt
>>> wavelet = pywt.Wavelet('db2')
>>> phi, psi, x = wavelet.wavefun(level=5)
For other (:attr:`biorthogonal <Wavelet.biorthogonal>` but not
:attr:`orthogonal <Wavelet.orthogonal>`) wavelets returns approximations of
scaling and wavelet function both for decomposition and reconstruction and
corresponding x-grid coordinates::
[phi_d, psi_d, phi_r, psi_r, x] = wavelet.wavefun(level)
**Example:**
.. sourcecode:: python
>>> import pywt
>>> wavelet = pywt.Wavelet('bior3.5')
>>> phi_d, psi_d, phi_r, psi_r, x = wavelet.wavefun(level=5)
.. See also plots of Daubechies and Symlets wavelet families generated using
the :meth:`~Wavelet.wavefun` function:
- `db.png`_
- `sym.png`_
.. seealso::
You can find live examples of :meth:`~Wavelet.wavefun` usage and
images of all the built-in wavelets on the
`Wavelet Properties Browser <http://wavelets.pybytes.com>`_ 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:
.. _custom-wavelets:
Using custom wavelets
---------------------
PyWavelets comes with a :func:`long list <pywt.wavelist>` of the most popular
wavelets built-in 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 :attr:`~Wavelet.filter_bank` attribute as a
``filter_bank`` argument to the :class:`Wavelet` constructor.
.. compound::
The filters list, either in a form of a simple Python list or returned via
the :attr:`~Wavelet.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 :attr:`~Wavelet.filter_bank` attribute of the
:class:`Wavelet` class.
The Wavelet object created in this way is a standard :class:`Wavelet` instance.
The following example illustrates the way of creating custom Wavelet objects
from plain Python lists of filter coefficients and a *filter bank-like* object.
**Example:**
.. sourcecode:: python
>>> 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:: ContinuousWavelet(name, dtype=np.float64)
Describes properties of a continuous wavelet identified by the specified wavelet ``name``.
In order to use a built-in wavelet the ``name`` parameter must be a valid
wavelet name from the :func:`pywt.wavelist` list.
:param name: Wavelet name
:param dtype: numpy.dtype to use for the wavelet. Can be numpy.float64 or numpy.float32.
**Example:**
.. sourcecode:: python
>>> import pywt
>>> wavelet = pywt.ContinuousWavelet('gaus1')
.. attribute:: name
Continuous Wavelet name.
.. attribute:: short_family_name
Wavelet short family name
.. attribute:: family_name
Wavelet family name
.. attribute:: orthogonal
Set if wavelet is orthogonal
.. attribute:: biorthogonal
Set if wavelet is biorthogonal
.. attribute:: complex_cwt
Returns if wavelet is complex
.. attribute:: lower_bound
Set the lower bound of the effective support
.. attribute:: upper_bound
Set the upper bound of the effective support
.. attribute:: center_frequency
Set the center frequency for the shan, fbsp and cmor wavelets
.. attribute:: bandwidth_frequency
Set the bandwidth frequency for the shan, fbsp and cmor wavelets
.. attribute:: fbsp_order
Set the order for the fbsp wavelet
.. attribute:: symmetry
``asymmetric``, ``near symmetric``, ``symmetric``, ``anti-symmetric``
**Example:**
.. sourcecode:: python
>>> import pywt
>>> wavelet = pywt.ContinuousWavelet('gaus1')
>>> print(wavelet)
ContinuousWavelet gaus1
Family name: Gaussian
Short name: gaus
Symmetry: anti-symmetric
DWT: False
CWT: True
Complex CWT: False
Approximating wavelet functions - ``ContinuousWavelet.wavefun()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. method:: ContinuousWavelet.wavefun(level, length = None)
The :meth:`~ContinuousWavelet.wavefun` method can be used to calculate approximations of
scaling function (``psi``) with grid (``x``). The vector length is set by ``length``.
The vector length can also be defined by ``2**level`` if ``length`` is not set.
For :attr:`complex_cwt <ContinuousWavelet.complex_cwt>` wavelets returns a complex approximations of
wavelet function with corresponding x-grid coordinates::
[psi, x] = wavelet.wavefun(level)
**Example:**
.. sourcecode:: python
>>> import pywt
>>> wavelet = pywt.ContinuousWavelet('gaus1')
>>> psi, x = wavelet.wavefun(level=5)
Approximating wavelet functions - ``ContinuousWavelet.wavefun()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. method:: DiscreteContinuousWavelet(name, [filter_bank = None])
The :meth:`~DiscreteContinuousWavelet` returns a
Wavelet or a ContinuousWavelet object depending on the given name.
**Example:**
.. sourcecode:: python
>>> 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: anti-symmetric
DWT: False
CWT: True
Complex CWT: False
|