Skip to content

Commit bf3b123

Browse files
committed
DOC: refine CWT normalization explanation
1 parent 2a55f79 commit bf3b123

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

doc/source/ref/cwt.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,35 @@ scales. The right column are the corresponding Fourier power spectra of each
231231
filter.. For scales 1 and 2 it can be seen that aliasing due to violation of
232232
the Nyquist limit occurs.
233233

234+
235+
Normalization with ``sampling_period``
236+
--------------------------------------
237+
238+
The ``sampling_period`` argument changes only the reported frequencies
239+
(``scale2frequency(...)/sampling_period``). It does not rescale the CWT
240+
coefficients themselves.
241+
242+
This can be confusing when comparing against a hand-written approximation to
243+
the continuous-time definition,
244+
245+
.. math::
246+
247+
W_x(a, b) = \frac{1}{\sqrt{a}}\int x(t)\,\psi^*\left(\frac{t-b}{a}\right)\,dt.
248+
249+
For sampled data ``t_n = n\,dt``, a direct Riemann-sum approximation is
250+
251+
.. math::
252+
253+
W_x(a, b) \approx \frac{dt}{\sqrt{a}}\sum_n x[n]\,\psi^*\left(\frac{n\,dt-b}{a}\right).
254+
255+
So a manual discrete convolution written in physical time includes the ``dt``
256+
factor from the integral approximation. If the scale is
257+
parameterized in seconds (``a_sec = a*dt``), then
258+
``dt/sqrt(a_sec) = sqrt(dt)/sqrt(a)``. Relative to a purely
259+
sample-index-based implementation with scale ``a`` in samples, this appears as
260+
an additional amplitude factor of ``sqrt(dt)`` (equivalently
261+
``1/sqrt(fs)`` with ``fs = 1/dt``).
262+
234263
.. _Converting frequency:
235264

236265
Converting frequency to scale for ``cwt``

pywt/_cwt.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1,
8181
Size of coefficients arrays depends on the length of the input array and
8282
the length of given scales.
8383
84+
The coefficients are independent of ``sampling_period``. The
85+
``sampling_period`` parameter only affects the values returned in
86+
``frequencies``.
87+
88+
When comparing against a direct numerical approximation of the
89+
continuous-time CWT integral, keep in mind that a sampled implementation in
90+
physical time introduces a ``dt`` factor from the Riemann sum. Depending on
91+
the normalization used in a manual calculation, this can appear as an
92+
additional amplitude factor of ``sqrt(dt)`` (equivalently ``1/sqrt(fs)``).
93+
8494
Examples
8595
--------
8696
>>> import pywt

0 commit comments

Comments
 (0)