spyrit.misc.walsh_hadamard.fwalsh_G
- spyrit.misc.walsh_hadamard.fwalsh_G(x, ind=True)[source]
Fast Walsh G-transform of the signal x
- Args:
x(np.ndarray): signals of shape (*,n), where n+1 must be a power of two.ind(bool, optional): True for sequency (default).ind(list, optional): permutation indices. This is faster than True when repeating the sequency-ordered transform multilple times.- Returns:
np.ndarray: G-transformed signal of shape (*,n).
- Example:
Example 1: Walsh-ordered G-transform of a signal of length 7
>>> import spyrit.misc.walsh_hadamard as wh >>> import numpy as np >>> x = np.array([1, 3, 0, -1, 7, 5, 1]) >>> s = wh.fwalsh_G(x) >>> print(s) [ -8 -2 -2 -16 8 6 -2]
Example 2: Permuted fast G-transform
>>> import numpy as np >>> import spyrit.misc.walsh_hadamard as wh >>> x = np.array([1, 3, 0, -1, 7, 5, 1]) >>> ind = [1, 0, 3, 2, 7, 4, 5, 6] >>> y = wh.fwalsh_G(x, ind) >>> print(y) [ 16 -16 -2 8 -8 6 -2]
Example 3: Repeating the Walsh-ordered G-transform using input indices is faster
>>> import timeit >>> x = np.random.rand(100,2**12-1) >>> t = timeit.timeit(lambda: wh.fwalsh_G(x), number=100) >>> print(f"No indices as inputs (10x): {t:.3f} seconds") No indices as inputs (10x): ... seconds >>> ind = wh.sequency_perm_ind(x.shape[-1]+1) >>> t = timeit.timeit(lambda: wh.fwalsh_G(x,ind), number=100) >>> print(f"With indices as inputs (10x): {t:.3f} seconds") With indices as inputs (10x): ... seconds
Example 4: Comparison with G-transform via matrix-vector product
>>> import numpy as np >>> import spyrit.misc.walsh_hadamard as wh >>> x = np.array([3, 0, -1, 7, 5, 1, -2]) >>> y1 = wh.fwalsh_G(x) >>> y2 = wh.walsh_G(x) >>> print(f"Diff = {np.linalg.norm(y1-y2)}") Diff = 0.0