Skip to content

Commit 4122c7c

Browse files
ENH: allow user to set precision in CWT, increase default to 12 (#570)
Co-authored-by: Ralf Gommers <ralf.gommers@gmail.com>
1 parent 7f4f74a commit 4122c7c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

pywt/_cwt.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ def next_fast_len(n):
2424
return 2**ceil(np.log2(n))
2525

2626

27-
def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1):
27+
def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1,
28+
*, precision=12):
2829
"""
29-
cwt(data, scales, wavelet)
30-
3130
One dimensional Continuous Wavelet Transform.
3231
3332
Parameters
@@ -60,6 +59,12 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1):
6059
axis: int, optional
6160
Axis over which to compute the CWT. If not given, the last axis is
6261
used.
62+
precision: int, optional
63+
Length of wavelet (``2 ** precision``) used to compute the CWT. Greater
64+
will increase resolution, especially for higher scales, but will
65+
compute a bit slower. Too low will distort coefficients and their
66+
norms, with a zipper-like effect. The default is 12, it's recommended
67+
to use >=12.
6368
6469
Returns
6570
-------
@@ -116,7 +121,7 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1):
116121

117122
dt_out = dt_cplx if wavelet.complex_cwt else dt
118123
out = np.empty((np.size(scales),) + data.shape, dtype=dt_out)
119-
precision = 10
124+
120125
int_psi, x = integrate_wavelet(wavelet, precision=precision)
121126
int_psi = np.conj(int_psi) if wavelet.complex_cwt else int_psi
122127

pywt/tests/test_matlab_compatibility_cwt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def _load_matlab_result_psi(wavelet):
149149

150150
def _check_accuracy(data, w, scales, coefs, wavelet, epsilon):
151151
# PyWavelets result
152-
coefs_pywt, freq = pywt.cwt(data, scales, w)
152+
coefs_pywt, freq = pywt.cwt(data, scales, w, precision=10)
153153

154154
# coefs from Matlab are from R2012a which is missing the complex conjugate
155155
# as shown in Eq. 2 of Torrence and Compo. We take the complex conjugate of

0 commit comments

Comments
 (0)