Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to set precision in CWT, increase default to 12 #570

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pywt/_cwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def next_fast_len(n):
return 2**ceil(np.log2(n))


def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1):
def cwt(data, scales, wavelet, sampling_period=1., method='conv',
precision=12, axis=-1):
OverLordGoldDragon marked this conversation as resolved.
Show resolved Hide resolved
"""
cwt(data, scales, wavelet)

Expand Down Expand Up @@ -67,6 +68,11 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1):
The ``fft`` method is ``O(N * log2(N))`` with
``N = len(scale) + len(data) - 1``. It is well suited for large size
signals but slightly slower than ``conv`` on small ones.
precision: int, optional
Length of wavelet (2 ** precision) used to compute the CWT. Greater
will increase resolution, especially for higher scales, but will
compute a bit slower. Too low will distort coefficients and their
norms, with a zipper-like effect; recommended >= 12.
axis: int, optional
Axis over which to compute the CWT. If not given, the last axis is
used.
Expand Down Expand Up @@ -122,7 +128,7 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1):

dt_out = dt_cplx if wavelet.complex_cwt else dt
out = np.empty((np.size(scales),) + data.shape, dtype=dt_out)
precision = 10

int_psi, x = integrate_wavelet(wavelet, precision=precision)
int_psi = np.conj(int_psi) if wavelet.complex_cwt else int_psi

Expand Down