%% Walsh-Hadamard Transform of a Signal
% This example shows a simple input signal and its Walsh-Hadamard transform.

x = [19 -1 11 -9 -7 13 -15 5];
y = fwht(x)

%
% y contains nonzero values at locations 0, 1, 3, and 6. Form the Walsh functions with the sequency values 0, 1, 3, and 6 to recreate x.

w0 = [1 1 1 1 1 1 1 1];
w1 = [1 1 1 1 -1 -1 -1 -1];
w3 = [1 1 -1 -1 1 1 -1 -1];
w6 = [1 -1 1 -1 -1 1 -1 1];
w = y(0+1)*w0 + y(1+1)*w1 + y(3+1)*w3 + y(6+1)*w6

%
% Obtain the same result by extracting the nonzero values and Walsh functions programmatically.

ww = fwht(eye(length(y)))*length(y)
nz = find(y);
w = sum(y(nz)'.*ww(nz,:))

% Copyright 2015 The MathWorks, Inc.