|
Math::WalshTransform.pm - Fast Hadamard and Walsh Transforms |
Math::WalshTransform.pm - Fast Hadamard and Walsh Transforms
use Math::WalshTransform; @f = (1.618, 2.718, 3.142, 4.669); # must be power-of-two long @FH1 = &fht(@f); # Hadamard transform @fh1 = &fhtinv(@FH1); # or @FW2 = &fwt(@f); # Walsh transform @fw2 = &fwtinv(@FW2); @FH2 = &walsh2hadamard(@FW2);
@PS = &power_spectrum(@f);
import Math::WalshTransform qw(:ALL);
@whats_going_on = &biggest(9,&fwt(&sublist(\@time_series,-16)));
@EVENT1 = &fwt(&sublist(\@time_series,478,16));
@EVENT2 = &fwt(&sublist(\@time_series,2316,16));
@EVENT3 = &fwt(&sublist(\@time_series,3261,16));
$EVENT1[$[]=0.0; $EVENT2[$[]=0.0; $EVENT3[$[]=0.0; # ignore constant
@EVENT1 = &normalise(@EVENT1); # ignore scale
@EVENT2 = &normalise(@EVENT2);
@EVENT3 = &normalise(@EVENT3);
@TYPICAL_EVENT = &average(\@EVENT1, \@EVENT2, \@EVENT3);
...
@NOW = &fwt(&sublist(\@time_series,-16));
$NOW[$[] = 0.0;
@NOW = &normalise(@NOW);
if (&distance(\@NOW, \@TYPICAL_EVENT) < .28) { &get_worried(); }
These routines implement fast Hadamard and Walsh Transforms and their inverse transforms.
Also included are routines for converting a Hadamard to a Walsh transform and vice versa, for calculating the Logical Convolution of two lists, or the Logical Autocorrelation of a list, and for calculating the Walsh Power Spectrum - in short, almost everything you ever wanted to do with a Walsh Transform.
Intelligible speech can be reconstructed by transforming blocks of, say, 64 samples, deleting all but the several largest transform components, and inverse-transforming; in other words, these transforms extract from a time-series the most significant things that are going on. They should be useful for noticing important things, for example in software that monitors time-series data such as system or network administration data, share-price, currency, ecological, opinion poll, process management data, and so on.
As from version 1.10, Math::WalshTransform uses C routines to perform the transforms. This runs 25 to 30 times faster than previous versions.
Not yet included are multi-dimensional Hadamard and Walsh Transforms, conversion between Logical and Arithmetic Autocorrelation Functions, or conversion between the Walsh Power Spectrum and the Fourier Power Spectrum.
Version 1.12
Routines which take just one array as argument expect the array itself; those which take more than one array expect a list of references.
The following routines are not exported by default, but are exported under the ALL tag, so if you need them you should:
import Math::WalshTransform qw(:ALL);
The Hadamard matrix is a square array of plus and minus ones, whose rows and columns are orthogonal to each other. Hence, the product of the matrix and its tranpose is the identity matrix times a constant N which is equal to the order of the matrix. If N is a power of two, symmetrical Hadamard matrices can be defined recursively:
| 1 1 |
Had = | |
2 | 1 -1 |
| Had Had |
| N N |
Had = | |
2N | Had -Had |
| N N |
Each row of the Hadamard matrix corresponds to a Hadamard Function Had(j,k) where j = 0...N-1
The Walsh matrix is derived from the Hadamard matrix by rearranging the rows so that the number of sign-changes is in increasing order. Each row of the Walsh matrix corresponds to a Walsh Function Wal(j,k) where j = 0...N-1
The one-dimensional Hadamard transform pair is defined by
F(j) = (1/N) * Sigma f(k)*Had(j,k) f(j) = Sigma F(k)*Had(j,k)
and the one-dimensional Walsh transform pair is defined by
F(j) = (1/N) * Sigma f(k)*Wal(j,k) f(j) = Sigma F(k)*Wal(j,k)
The two transforms are equivalent, and conversion between them only involves rearranging the order of the components. Since the Walsh functions are in order of increasing number of sign-changes, the Walsh transform is more Fourier-like, and for that reason is used more often, although it does use several per-cent more CPU time.
Because all the matrix elements are either 1 or -1, these transforms involve almost no multiplications and are computationally very efficient.
The Logical (or Dyadic) Convolution of two arrays x and y is defined by
z(k) = (1/N) * Sigma x(k^j)*y(j)
where the ^ is used in its Perl sense, to mean bitwise exclusive-or. There exists a Logical (or Dyadic) Convolution Theorem, analogous to the normal case, that the Walsh transform of the logical convolution of two sequences is the product of their Walsh transforms, and that the Walsh transform of the product of two sequences is the logical convolution of their Walsh transforms.
Likewise there exists a Logical Wiener-Khintchine Theorem, stating that the Walsh Power Spectrum is the Walsh transform of the Logical Autocorrelation Function.
There exist linear transformations converting between Logical Convolution and the normal Arithmetic Convolution, and between the Walsh Power Spectrum and the normal Fourier Power Spectrum.
Peter J Billam, www.pjb.com.au/comp/contact.html
Walsh Spectrometry, a form of spectral analysis well suited to binary computation, J. E. Gibbs, National Physical Lab, Teddington, Middlesex, England, unpublished, 1967
Hadamard transform image encoding, W. K. Pratt, J. Kane and H. C. Andrews, Proc. IEEE, Vol. 57, Jan 1969, pp. 58-68
Walsh function generation, D. A. Swick, IEEE Transactions on Information Theory (Corresp.), Vol. IT-15 part 1, Jan 1969, p. 167
Computation of the Hadamard transform and the R-transform in ordered form, L. J. Ulman, IEEE Trans. Comput. (Corresp.), Vol. C-19, Apr 1970, pp. 359-360
Computation of the Fast Hadamard Transform, Ying Shum and Ronald Elliot, Proc. Symp. Appl. Walsh Functions, Washington D.C., 1972, pp. 177-180
Logical Convolution and Discrete Walsh and Fourier Power Spectra, Guener Robinson, IEEE Transactions on Audio and Electroacoustics, Vol. AU-20 No. 4, October 1972, pp. 271-280
Speech processing with Walsh-Hadamard Transforms, Ying Shum, Ronald Elliot and Owen Brown, IEEE Transactions on Audio and Electroacoustics, Vol. AU-21 No. 3, June 1973, pp. 174-179
See also http://www.pjb.com.au/, http://www.pjb.com.au/comp/walshtransform.html, http://www.pjb.com.au/comp/evol.html, Math::Evol, http://www.pjb.com.au/comp/clui.html, Term::Clui, http://www.pjb.com.au/comp/tea.html, Crypt::Tea, http://mathworld.wolfram.com/WalshTransform.html, perl(1).
|
Math::WalshTransform.pm - Fast Hadamard and Walsh Transforms |