function a = SolveHaar(y)
% y is n-by-n and n is a power of 2.
% a is an n-vector that solves Hn*a = y where
% Hn is the nxn Haar matrix.
n = length(y);
if n==1
a = y;
else
yAve = (y(1:2:n) + y(2:2:n))/2;
yDiff = (y(1:2:n) - y(2:2:n))/2;
a = [ SolveHaar(yAve) ; yDiff];
end