function xt=fwhtrv(x,blksiz) % xt = FWHTRV (x,blksiz) recursively calculates the Walsh-Hadamard transform % with results in bit-reversed order % % x: data to transform, as a row vector % blksiz: block size for x (defaults to 1) % % length(x)/blksiz is 2^(order of the transform) % elements x(1), x(2),..., x(blksiz) taken as first block % elements x(blksiz+1), ..., x(2*blksiz) taken as second block % % output explained (xb(j)=jth block of xb): % first block of xt: xb(1)+xb(2)+xb(3)+xb(4)... % second block of xt: xb(1)-xb(2)+xb(3)-xb(4)... % third block of xt: xb(1)+xb(2)-xb(3)-xb(4)... % fourth block of xt: xb(1)-xb(2)-xb(3)+xb(4)... % error(nargchk(1,2,nargin)); if (nargin == 1) blksiz=1; end lenx=length(x); blocks=lenx/blksiz; curord=floor(log2(blocks)); if (curord <= 0) xt=x; return else half=lenx/2; x1=x(1:half); x2=x((half+1):lenx); xt1=fwhtrv(x1,blksiz); xt2=fwhtrv(x2,blksiz); xt=[xt1+xt2 xt1-xt2]; return end