The function implement the 1D sequency(Walsh) ordered fast Walsh-Hadamard transform which can be used in signal processing, pattern recongnition and Genetic alogorithms.
This algorithm uses a Cooley-Tukey type signal flow graph and is implemented in N log2 N additions and subtractions. Data sequence length must be an integer power of 2.
The inverse transform is the same as the forward transform except for the multiplication factor N. This can be easily achieved by deleting the last line i.e. x=inv(N)*x;
x=[1 2 1 1];
Dr. Gylson Thomas (2020). Fast Walsh-Hadamard Transform (https://www.mathworks.com/matlabcentral/fileexchange/6879-fast-walsh-hadamard-transform), MATLAB Central File Exchange. Retrieved .
As of R2008b, Matlab's Signal Processing toolbox has the functions "fwht" and "ifwht" for the Fast Walsh-Hadamard (aka Hadamard) Transform, and you can choose among three different orderings. This builtin code doesn't work on very large vectors though, whereas I know it is possible to operate on these large vectors because a friend gave me some mex code that does just that. I haven't compared with the file posted here.
The code was good but the file name & function command name has to be same.
The Hadamard transform is useful outside of signal processing, too, so it is unfortunate that this nice little function requires the Signal Processing Toolbox. However, the need is only a three-line function:
function R = bitrevorder(X)
% rearrange vector X to reverse bit order, upto max 2^k size <= length(X)
[f,e] = log2(length(X));
I = dec2bin(0:pow2(0.5,e)-1);
R = X(bin2dec(I(:,e-1:-1:1))+1);
If you save it under the filename bitrevorder.m, FWHT works without the signal processing toolbox. If you change the first few lines of FWHT to
x = bitrevorder(data);
N = length(x);
k1 = N; k2 = 1; k3 = N/2;
for i1=1:log2(N) %Iteration stage
the input data vector will be truncated to the largest power of two size, not exceeding the length of data, so you need not worry about odd lengths.
i'm interested to know more bout the natural ordered hadamard transforms. could u give us more info?
how to get fwht from wht?
How can know the full detail of the algorithm of Fast Walsh Hadamard transformation?
Excellent compact implementation
As per the 9th review comment, in order to avoid signal processing toolbox, the bitrevorder function is also incorporated along with the main source code.
Shorcut for determining Inverse FWHT
A correction in example and reference is added
sequency ordered Walsh transform is the most common in use similar to FFT.