17.01.2013 Views

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Fast in-place Walsh-Hadamard Transform (click this to go back to the index)<br />

Type : wavelet transform<br />

References : Posted by Timo H Tossavainen<br />

Notes :<br />

IIRC, They're also called walsh-hadamard transforms.<br />

Basically like Fourier, but the basis functions are squarewaves with different sequencies.<br />

I did this for a transform data compression study a while back.<br />

Here's some <strong>code</strong> 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,<br />

IIRC.<br />

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)<br />

Code :<br />

void inline wht_bfly (long& a, long& b)<br />

{<br />

long tmp = a;<br />

a += b;<br />

b = tmp - b;<br />

}<br />

// just a integer log2<br />

int inline l2 (long x)<br />

{<br />

int l2;<br />

for (l2 = 0; x > 0; x >>=1)<br />

{<br />

++ l2;<br />

}<br />

}<br />

return (l2);<br />

////////////////////////////////////////////<br />

// Fast in-place Walsh-Hadamard Transform //<br />

////////////////////////////////////////////<br />

void FWHT (std::vector& data)<br />

{<br />

const int log2 = l2 (data.size()) - 1;<br />

for (int i = 0; i < log2; ++i)<br />

{<br />

for (int j = 0; j < (1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!