Fast in-place Walsh-Hadamard Transform

Type : wavelet transform
References : Posted by Timo H Tossavainen
Notes :
IIRC, They're also called walsh-hadamard transforms.
Basically like Fourier, but the basis functions are squarewaves with different sequencies.
I did this for a transform data compression study a while back.
Here's some code to do a walsh hadamard transform on long ints in-place (you need to divide by n to get transform) the order is bit-reversed at output, IIRC.
The inverse transform is the same as the forward transform (expects bit-reversed input). i.e. x = 1/n * FWHT(FWHT(x)) (x is a vector)
Code :
void inline wht_bfly (long& a, long& b)
{
        long tmp = a;
        a += b;
        b = tmp - b;
}

// just a integer log2
int inline l2 (long x)
{
        int l2;
        for (l2 = 0; x > 0; x >>=1)
        {
                ++ l2;
        }

        return (l2);
}

////////////////////////////////////////////
// Fast in-place Walsh-Hadamard Transform //
////////////////////////////////////////////

void FWHT (std::vector& data)
{
  const int log2 = l2 (data.size()) - 1;
  for (int i = 0; i < log2; ++i)
  {
    for (int j = 0; j < (1 << log2); j += 1 << (i+1))
    {
       for (int k = 0; k < (1<<i); ++k)
       {
           wht_bfly (data [j + k], data [j + k + (1<<i)]);
       }
    }
  }
}

Comments
from : i_arslan[AT]gmx[DOT]net
comment : How can i implement this code in matlab ?

from : Noor98z[AT]hotmail[DOT]com
comment : Need an Implemtation of Walsh Transform Matlab Code

from : ambadarneh[AT]hotmail[DOT]com
comment : well sir nice work ,but how can i get the code in MATLAB . could you help me please. thank you yours sicerly Ala' Badarneh Jordan University of Science & Technology Biomedical Engineering Department

from : msalharbi[AT]hotmail[DOT]com
comment : Noor98z@hotmail.com .... need implementation of walsh transform Matlab code and me need.

from : fahira10[AT]hotmail[DOT]com
comment : Dear sir, your job is amazing! I was just searching for a WHT program but I did not find any Matlab command for that. Is there a way to implement that code in Matlab? Best regards

from : z_xf[AT]sdu[DOT]edu[DOT]cn
comment : nice work ,but how can i get the code in MATLAB . could you help me please.thank you! yours sicerly zhang

from : (1< - ??????????????????????
comment : What is symbols "(1<" in C++; I dont know this symbols. Please help me.

from : beeka at beeka dot org
comment : You might want to look at the page source. This shows the "(1<" was trying to be "(1 << i)" (I hope the browser leaves that one alone): for (int k = 0; k < (1 << i); ++k) { wht_bfly (data [j + k], data [j + k + (1 << i)]); }

from : bcreado[AT]hotmail[DOT]com
comment : well sir nice work ,but how can i get the code in MATLAB . could you help me please

from : anonymous
comment : Hello, I just thought I would let you know that I do not want MatLab code for this. Thank you.

from : tired_of_morons[AT]gmail[DOT]com
comment : FOR CRYING OUT LOUD!! IMPLEMENT IT YOURSELF IN MATLAB! OR MAYBE, JUST MAYBE, IF YOU REQUEST FOR MATLAB CODE TEN TIMES MORE, YOU'LL GET IT... NOT! "Most people are amazing. Just not in a positive sense..." - unknown

from : nobody[AT]nowhere[DOT]com
comment : What the hell is MATLAB anyway?

from : scoofy[AT]inf[DOT]elte[DOT]hu
comment : MATLAB guys: Have you ever tried the google search "fast walsh hadamard matlab"? If yes, look at the first link.

from : debonair_swathi[AT]yahoo[DOT]co[DOT]in
comment : i need program in c to generate a hadamard matrix of any order

from : debonair_swathi[AT]yahoo[DOT]co[DOT]in
comment : sir i need program in c to get the walsh matrix of any order to use as a coding tecchnique in CDMA .can u email it to me

from : bob[AT]yahoob[DOT]com
comment : If you can't convert a few lines of 'c' into to another language, then you must be mad, or lazy, or both.

from : anonymous
comment : Lend a hand and they grab your shoulder...