0a8619ecf57eb68021e6aef48aefdc8cfa0795ed,examples/1d/plot_real_signal.py,,,#,40

Before Change



m = np.max(np.abs(x_f))
x = x_f / m
x = x.reshape((1, -1))

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// We are now ready to set up the parameters for the scattering transform.
// First, the number of samples, `T`, is given by the size of our input `x`.
// The averaging scale is specified as a power of two, `2**J`. Here, we set
// `J = 6` to get an averaging, or maximum, scattering scale of `2**6 = 64`
// samples. Finally, we set the number of wavelets per octave, `Q`, to `16`.
// This lets us resolve frequencies at a resolution of `1/16` octaves.

T = x.shape[-1]
J = 6
Q = 16

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Finally, we are able to create the object which computes our scattering
// transform, `scattering`.

scattering = Scattering1D(J, T, Q, frontend="numpy")

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Compute and display the scattering coefficients
// -----------------------------------------------
// Computing the scattering transform of a PyTorch Tensor is achieved using the
// `forward()` method of the `Scattering1D` class. The output is another Tensor
// of shape `(B, C, T)`. Here, `B` is the same as for the input `x`, but `C` is
// the number of scattering coefficient outputs, and `T` is the number of
// samples along the time axis. This is typically much smaller than the number
// of input samples since the scattering transform performs an average in time
// and subsamples the result to save memory.

Sx = scattering(x)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// To display the scattering coefficients, we must first identify which belong
// to each order (zeroth, first, or second). We do this by extracting the `meta`
// information from the scattering object and constructing masks for each order.

meta = compute_meta_scattering(J, Q)
order0 = np.where(meta["order"] == 0)
order1 = np.where(meta["order"] == 1)
order2 = np.where(meta["order"] == 2)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// First, we plot the original signal `x`. Note that we have to index it as
// `x[0,0,:]` to convert it to a one-dimensional array and convert it to a
// numpy array using the `numpy()` method.

plt.figure(figsize=(8, 2))
plt.plot(np.squeeze(x))
plt.title("Original signal")

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// We now plot the zeroth-order scattering coefficient, which is simply an
// average of the original signal at the scale `2**J`.

plt.figure(figsize=(8, 2))
plt.plot(np.squeeze(Sx[order0,:]).ravel())
plt.title("Scattering Order 0")

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

After Change



plt.figure(figsize=(8, 2))
plt.imshow(Sx[order1], aspect="auto")
plt.title("First-order scattering")

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Finally, we plot the second-order scattering coefficients. These are also
// organized aling time, but has two log-frequency indices: one first-order
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 3

Instances


Project Name: kymatio/kymatio
Commit Name: 0a8619ecf57eb68021e6aef48aefdc8cfa0795ed
Time: 2020-02-18
Author: janden@flatironinstitute.org
File Name: examples/1d/plot_real_signal.py
Class Name:
Method Name:


Project Name: scikit-image/scikit-image
Commit Name: 4cef9aff929623188f11778db030ac933a910792
Time: 2018-09-12
Author: devel@sciunto.org
File Name: doc/examples/data/plot_general.py
Class Name:
Method Name:


Project Name: scikit-image/scikit-image
Commit Name: 4cef9aff929623188f11778db030ac933a910792
Time: 2018-09-12
Author: devel@sciunto.org
File Name: doc/examples/data/plot_scientific.py
Class Name:
Method Name: