-
-
Notifications
You must be signed in to change notification settings - Fork 532
Enhance _cwt.py by introducing a configurable hop size parameter #804
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
base: main
Are you sure you want to change the base?
Changes from 16 commits
4edcc2c
9a8bf1a
ad41521
6b7d7f1
3c9289b
0a53e69
6776f98
82a4ef0
81cd1bb
dc93c83
a8a9aee
f607aa0
5cda18e
6f4e57a
099f895
7282d9f
20838a7
d986733
5eed6aa
8189d35
85482d4
bd5134b
ce87862
fc90fec
20d2af4
f6fa074
84c3fcb
f4231a1
fe2a9f3
fef6593
f5640ae
368f272
9c2b414
00fb8d4
c7da227
79acb20
8996c80
746d569
0f0ffc6
e88ed4b
82bda67
4a8d3c2
78e8763
295e263
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,9 +24,9 @@ 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, hop_size=1, sampling_period=1., method='conv', axis=-1): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please move the new keyword to the end of the signature? It's not backwards-compatible to add a new keyword in the middle. That would break calls like Also, please add it as
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The examples and tests then need to be updated for that change.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| """ | ||
| cwt(data, scales, wavelet) | ||
| cwt(data, scales, wavelet, hop_size) | ||
|
rgommers marked this conversation as resolved.
Outdated
|
||
|
|
||
| One dimensional Continuous Wavelet Transform. | ||
|
|
||
|
|
@@ -41,6 +41,14 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1): | |
| ``sampling_period`` is given in seconds. | ||
| wavelet : Wavelet object or name | ||
| Wavelet to use | ||
| hop_size : int | ||
| Specifies the down-sampling factor applied on temporal axis during the transform. | ||
| The output is sampled every hop_size samples, rather than at every consecutive sample. | ||
| For example: | ||
| A signal of length 1024 yields 1024 output samples when hop_size=1; | ||
| 512 output samples when hop_size=2; | ||
| 256 output samples when hop_size=4. | ||
| hop_size must be a positive integer (≥1). | ||
| sampling_period : float | ||
| Sampling period for the frequencies output (optional). | ||
| The values computed for ``coefs`` are independent of the choice of | ||
|
|
@@ -73,7 +81,7 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1): | |
|
|
||
| Notes | ||
| ----- | ||
| Size of coefficients arrays depends on the length of the input array and | ||
| Size of coefficients arrays depends on the length of the input array, the given hop_size and | ||
|
rgommers marked this conversation as resolved.
Outdated
|
||
| the length of given scales. | ||
|
|
||
| Examples | ||
|
|
@@ -83,7 +91,7 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1): | |
| >>> import matplotlib.pyplot as plt | ||
| >>> x = np.arange(512) | ||
| >>> y = np.sin(2*np.pi*x/32) | ||
| >>> coef, freqs=pywt.cwt(y,np.arange(1,129),'gaus1') | ||
| >>> coef, freqs=pywt.cwt(y,np.arange(1,129),1,'gaus1') | ||
| >>> plt.matshow(coef) | ||
| >>> plt.show() | ||
|
|
||
|
|
@@ -93,7 +101,7 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1): | |
| >>> t = np.linspace(-1, 1, 200, endpoint=False) | ||
| >>> sig = np.cos(2 * np.pi * 7 * t) + np.real(np.exp(-7*(t-0.4)**2)*np.exp(1j*2*np.pi*2*(t-0.4))) | ||
| >>> widths = np.arange(1, 31) | ||
| >>> cwtmatr, freqs = pywt.cwt(sig, widths, 'mexh') | ||
| >>> cwtmatr, freqs = pywt.cwt(sig, widths, 2, 'mexh') | ||
| >>> plt.imshow(cwtmatr, extent=[-1, 1, 1, 31], cmap='PRGn', aspect='auto', | ||
| ... vmax=abs(cwtmatr).max(), vmin=-abs(cwtmatr).max()) | ||
| >>> plt.show() | ||
|
|
@@ -114,7 +122,8 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1): | |
| raise AxisError("axis must be a scalar.") | ||
|
|
||
| dt_out = dt_cplx if wavelet.complex_cwt else dt | ||
| out = np.empty((np.size(scales),) + data.shape, dtype=dt_out) | ||
| data_sampled = data[..., ::hop_size] | ||
| out = np.empty((np.size(scales),) + data_sampled.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 | ||
|
|
@@ -187,7 +196,7 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1): | |
| # restore original data shape and axis position | ||
| coef = coef.reshape(data_shape_pre) | ||
| coef = coef.swapaxes(axis, -1) | ||
| out[i, ...] = coef | ||
| out[i, ...] = coef[..., ::hop_size] | ||
|
|
||
| frequencies = scale2frequency(wavelet, scales, precision) | ||
| if np.isscalar(frequencies): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.