spyrit.misc.walsh_hadamard.fwalsh_G
- spyrit.misc.walsh_hadamard.fwalsh_G(x, ind=True)[source]
Fast Walsh G-transform of x
- Args:
x(np.ndarray): n-by-1 signal. n+1 should be a power of two.ind(bool, optional): True for sequency (default)ind(list, optional): permutation indices. This is faster than Truewhen repeating the sequency-ordered transform multilple times.
- Returns:
np.ndarray: n-by-1 S-transformed signal
- 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)
- 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)
- Example 3:
Repeating the Walsh-ordered G-transform using input indices is faster
>>> import timeit >>> x = np.random.rand(2**12-1,1) >>> t = timeit.timeit(lambda: wh.fwalsh_G(x), number=10) >>> print(f"No indices as inputs (10x): {t:.3f} seconds") >>> ind = wh.sequency_perm_ind(len(x)+1) >>> t = timeit.timeit(lambda: wh.fwalsh_G(x,ind), number=10) >>> print(f"With indices as inputs (10x): {t:.3f} 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)}")