0
$\begingroup$

I'm attempting to make use of wavelet scattering to analyse my signal samples.

The example IQ Wav file I am using is as follows: https://www.dropbox.com/s/dd6fr4va4alpazj/move_x_movedist_1_speed_25k_sample_6.wav?dl=0

Currently, following a guide from the Kymatio documentation, I have the following code:

import scipy.io.wavfile
import numpy as np
import matplotlib.pyplot as plt
from kymatio.numpy import Scattering1D

path = r"move_x_movedist_1_speed_25k_sample_6.wav"

# Read in the sample WAV file
fs, x = scipy.io.wavfile.read(path)
x = x.T
print(fs)
# Once the recording is in memory, we normalise it to +1/-1
x = x / np.max(np.abs(x))
print(x)
# Set up parameters for the scattering transform
## number of samples, T
N = x.shape[-1]
print(N)
## Averaging scale as power of 2, 2**J, for averaging
## scattering scale of 2**6 = 64 samples
J = 6
## No. of wavelets per octave (resolve frequencies at
## a resolution of 1/16 octaves)
Q = 16
# Create object to compute scattering transform
scattering = Scattering1D(J, N, Q)
# Compute scattering transform of our signal sample
Sx = scattering(x)
# Extract meta information to identify scattering coefficients
meta = scattering.meta()
# Zeroth-order
order0 = np.where(meta['order'] == 0)
# First-order
order1 = np.where(meta['order'] == 1)
# Second-order
order2 = np.where(meta['order'] == 2)

#%%
# Plot original signal
plt.figure(figsize=(8, 2))
plt.plot(x)
plt.title('Original Signal')
plt.show()

# Plot zeroth-order scattering coefficient (average of
# original signal at scale 2**J)
plt.figure(figsize=(8,8))
plt.subplot(3, 1, 1)
plt.plot(Sx[order0][0])
plt.title('Zeroth-Order Scattering')
# Plot first-order scattering coefficient (arrange
# along time and log-frequency)
plt.subplot(3, 1, 2)
plt.imshow(Sx[order1], aspect='auto')
plt.title('First-order scattering')
# Plot second-order scattering coefficient (arranged
# along time but has two log-frequency indicies -- one
# first- and one second-order frequency. Both are mixed
# along the vertical axis)
plt.subplot(3, 1, 3)
plt.imshow(Sx[order2], aspect='auto')
plt.title('Second-order scattering')
plt.show()

The print statements for the sample rate, the normalised X (data) and the number of samples are as follows:

2000000
[[-0.65671316  0.40170009]
 [-0.67349608  0.50152572]
 [-0.62685266  0.54555362]
 ...
 [-0.59829991 -0.11006975]
 [-0.64930253 -0.03116827]
 [-0.6619442   0.05557977]]
2

There seems to be 2 samples as the main signal was split up into chunks of 2s using pydub's make_chunks and exporting them as wav format. The sample rate is 2MHz as these recordings are of RF signals stored in IQ WAV files.

However, the problem here is that I am getting the following error, from which I read seems to potentially be an issue with my J value (averaging scale):

Traceback (most recent call last): File "analyse.py", line 38, in scattering = Scattering1D(J, T, Q) File "C:\Users\xwb18152\AppData\Roaming\Python\Python38\site-packages\kymatio\scattering1d\frontend\numpy_frontend.py", line 19, in init ScatteringBase1D.build(self) File "C:\Users\xwb18152\AppData\Roaming\Python\Python38\site-packages\kymatio\scattering1d\frontend\base_frontend.py", line 55, in build min_to_pad = compute_minimum_support_to_pad( File "C:\Users\xwb18152\AppData\Roaming\Python\Python38\site-packages\kymatio\scattering1d\utils.py", line 125, in compute_minimum_support_to_pad _, _, _, t_max_phi = scattering_filter_factory( File "C:\Users\xwb18152\AppData\Roaming\Python\Python38\site-packages\kymatio\scattering1d\filter_bank.py", line 676, in scattering_filter_factory psi_f[0] = morlet_1d( File "C:\Users\xwb18152\AppData\Roaming\Python\Python38\site-packages\kymatio\scattering1d\filter_bank.py", line 135, in morlet_1d morlet_f *= get_normalizing_factor(morlet_f, normalize=normalize) File "C:\Users\xwb18152\AppData\Roaming\Python\Python38\site-packages\kymatio\scattering1d\filter_bank.py", line 157, in get_normalizing_factor raise ValueError('Zero division error is very likely to occur, ' + ValueError: Zero division error is very likely to occur, aborting computations now.

Any help would be appreciated to understand what's going on!

EDIT: I can get to "the next step" if I use Q=1,J=1, however I get the following warning:

warnings.warn('Signal support is too small to avoid border effects'

And when trying to plot I get the error:

File "analyse.py", line 100, in <module>
    plt.imshow(Sx[order1], aspect='auto')
    [....]      
    raise TypeError("Invalid shape {} for image data"
TypeError: Invalid shape (2, 3, 1) for image data
$\endgroup$
1
  • $\begingroup$ Updated the OP with some recent attempts! $\endgroup$
    – rshah
    Mar 14, 2022 at 12:22

1 Answer 1

1
$\begingroup$

Latest release is incomplete. Use dev

pip install git+https://github.com/kymatio/kymatio.git@dev

or latest stable branch with all functionality

pip install git+https://github.com/kymatio/kymatio.git@refs/pull/674/head

And when trying to plot I get the error:

is due to

There seems to be 2 samples as the main signal was split up

so an option is to iterate over the batch axis (0) and plot one by one.

$\endgroup$
10
  • $\begingroup$ I used the second option (all functionality latest stable) and running the code gives the error AssertionError: must have at least 3 filters in filterbank (got 1) $\endgroup$
    – rshah
    Mar 14, 2022 at 13:44
  • $\begingroup$ Increasing Q to 3 gives the error: ValueError: max() arg is an empty sequence $\endgroup$
    – rshah
    Mar 14, 2022 at 13:47
  • 1
    $\begingroup$ @rshah I do not reproduce your errors. Running your code gave different errors, so I edited the working version into your question. Data loads batches into axis 1, but must be axis 0 as mentioned (also in docs). $\endgroup$ Mar 14, 2022 at 16:21
  • 1
    $\begingroup$ @rshah That's right. And, they're here in help(Scattering1D). Unfortunately there aren't built-in visuals (or examples) for properly visualizing the second order; the true structure is shown here under "CWT, second order". $\endgroup$ Mar 15, 2022 at 14:27
  • 1
    $\begingroup$ @rshah That's expanding the scope of the question, but briefly, order0 and order1 are fully proper, order2 is "unrolled". $\endgroup$ Mar 15, 2022 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.