From d34e8b53092802c4eb94134d6c073b5aa76ad7bb Mon Sep 17 00:00:00 2001 From: Felix Tarkoey Date: Mon, 19 Oct 2020 16:21:14 +0200 Subject: [PATCH 1/2] Linear interpolation of sampling values instead of taking precomputed sample nearby --- pywt/_cwt.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pywt/_cwt.py b/pywt/_cwt.py index a47cf9885..5997c31c6 100644 --- a/pywt/_cwt.py +++ b/pywt/_cwt.py @@ -146,12 +146,11 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1): data = data.reshape((-1, data.shape[-1])) for i, scale in enumerate(scales): - step = x[1] - x[0] - j = np.arange(scale * (x[-1] - x[0]) + 1) / (scale * step) - j = j.astype(int) # floor - if j[-1] >= int_psi.size: - j = np.extract(j < int_psi.size, j) - int_psi_scale = int_psi[j][::-1] + step = 1.0 / scale + xs = np.arange(x[0], x[-1]+0.1*step, step) + if xs[-1] >= x[-1]: + xs = xs[:-1] + int_psi_scale = np.interp(xs, x, int_psi)[::-1] if method == 'conv': if data.ndim == 1: From 8932bbf9db6ebd1461c0df4548a5747d94e31335 Mon Sep 17 00:00:00 2001 From: Felix Tarkoey Date: Mon, 9 Nov 2020 16:59:31 +0100 Subject: [PATCH 2/2] Upper bound of wavelet is now a valid sampling instant; reduce probability that largest sampling instant exceeds wavelet upper bound --- pywt/_cwt.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pywt/_cwt.py b/pywt/_cwt.py index 5997c31c6..ad4f48790 100644 --- a/pywt/_cwt.py +++ b/pywt/_cwt.py @@ -146,10 +146,12 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1): data = data.reshape((-1, data.shape[-1])) for i, scale in enumerate(scales): + # Determine scale-dependent sampling instants step = 1.0 / scale - xs = np.arange(x[0], x[-1]+0.1*step, step) - if xs[-1] >= x[-1]: + xs = np.arange(x[0], x[-1]+0.01*step, step) + if xs[-1] > x[-1]: xs = xs[:-1] + # Approximate values by linear interpolation int_psi_scale = np.interp(xs, x, int_psi)[::-1] if method == 'conv':